• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2010 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.browser;
18 
19 import android.net.Uri;
20 
21 /**
22  * Utility methods for Url manipulation
23  */
24 public class UrlUtils {
25     // Determine if this URI appears to be a Google property
isGoogleUri(Uri uri)26     /* package */ static boolean isGoogleUri(Uri uri) {
27         String scheme = uri.getScheme();
28         if (!"http".equals(scheme) && !"https".equals(scheme)) {
29             return false;
30         }
31 
32         String host = uri.getHost();
33         if (host == null) {
34             return false;
35         }
36         String[] hostComponents = host.split("\\.");
37         if (hostComponents.length < 2) {
38             return false;
39         }
40 
41         int googleComponent = hostComponents.length - 2;
42         String component = hostComponents[googleComponent];
43         if (!"google".equals(component)) {
44             if (hostComponents.length < 3 ||
45                 (!"co".equals(component) && !"com".equals(component))) {
46                 return false;
47             }
48             googleComponent = hostComponents.length - 3;
49             if (!"google".equals(hostComponents[googleComponent])) {
50                 return false;
51             }
52         }
53         return true;
54     }
55 }
56