0c5f3f5914a2b39f8d9b0b0d47a7b25d95e61cb9
[platform/framework/web/crosswalk.git] / src / chrome / browser / google / google_util.h
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 //
5 // Some Google related utility functions.
6
7 #ifndef CHROME_BROWSER_GOOGLE_GOOGLE_UTIL_H__
8 #define CHROME_BROWSER_GOOGLE_GOOGLE_UTIL_H__
9
10 #include <string>
11
12 #include "base/basictypes.h"
13
14 class GURL;
15 class Profile;
16
17 // This namespace provides various helpers around handling Google-related URLs
18 // and state relating to Google Chrome distributions (such as RLZ).
19 namespace google_util {
20
21 // True iff |str| contains a "q=" query parameter with a non-empty value.
22 // |str| should be a query or a hash fragment, without the ? or # (as
23 // returned by GURL::query() or GURL::ref().
24 bool HasGoogleSearchQueryParam(const std::string& str);
25
26 // The query key that identifies a Google Extended API request for Instant.
27 const char kInstantExtendedAPIParam[] = "espv";
28
29 GURL LinkDoctorBaseURL();
30 void SetMockLinkDoctorBaseURLForTesting();
31
32 // Adds the Google locale string to the URL (e.g., hl=en-US).  This does not
33 // check to see if the param already exists.
34 GURL AppendGoogleLocaleParam(const GURL& url);
35
36 // String version of AppendGoogleLocaleParam.
37 std::string StringAppendGoogleLocaleParam(const std::string& url);
38
39 // Adds the Google TLD string for the given profile to the URL (e.g., sd=com).
40 // This does not check to see if the param already exists.
41 GURL AppendGoogleTLDParam(Profile* profile, const GURL& url);
42
43 // Returns in |brand| the brand code or distribution tag that has been
44 // assigned to a partner. Returns false if the information is not available.
45 bool GetBrand(std::string* brand);
46
47 // Returns in |brand| the reactivation brand code or distribution tag
48 // that has been assigned to a partner for reactivating a dormant chrome
49 // install. Returns false if the information is not available.
50 bool GetReactivationBrand(std::string* brand);
51
52 // Returns the Google base URL specified on the command line, if it exists.
53 // This performs some fixup and sanity-checking to ensure that the resulting URL
54 // is valid and has no query or ref.
55 GURL CommandLineGoogleBaseURL();
56
57 // Returns true if a Google base URL was specified on the command line and |url|
58 // begins with that base URL.  This uses a simple string equality check.
59 bool StartsWithCommandLineGoogleBaseURL(const GURL& url);
60
61 // WARNING: The following IsGoogleXXX() functions use heuristics to rule out
62 // "obviously false" answers.  They do NOT guarantee that the string in question
63 // is actually on a Google-owned domain, just that it looks plausible.  If you
64 // need to restrict some behavior to only happen on Google's officially-owned
65 // domains, use TransportSecurityState::IsGooglePinnedProperty() instead.
66
67 // Designate whether or not a URL checking function also checks for specific
68 // subdomains, or only "www" and empty subdomains.
69 enum SubdomainPermission {
70   ALLOW_SUBDOMAIN,
71   DISALLOW_SUBDOMAIN,
72 };
73
74 // Designate whether or not a URL checking function also checks for standard
75 // ports (80 for http, 443 for https), or if it allows all port numbers.
76 enum PortPermission {
77   ALLOW_NON_STANDARD_PORTS,
78   DISALLOW_NON_STANDARD_PORTS,
79 };
80
81 // True if |host| is "[www.]google.<TLD>" with a valid TLD. If
82 // |subdomain_permission| is ALLOW_SUBDOMAIN, we check against host
83 // "*.google.<TLD>" instead.
84 //
85 // If the Google base URL has been overridden on the command line, this function
86 // will also return true for any URL whose hostname exactly matches the hostname
87 // of the URL specified on the command line.  In this case,
88 // |subdomain_permission| is ignored.
89 bool IsGoogleHostname(const std::string& host,
90                       SubdomainPermission subdomain_permission);
91
92 // True if |url| is a valid URL with a host that returns true for
93 // IsGoogleHostname(), and an HTTP or HTTPS scheme.  If |port_permission| is
94 // DISALLOW_NON_STANDARD_PORTS, this also requires |url| to use the standard
95 // port for its scheme (80 for HTTP, 443 for HTTPS).
96 //
97 // Note that this only checks for google.<TLD> domains, but not other Google
98 // properties. There is code in variations_http_header_provider.cc that checks
99 // for additional Google properties, which can be moved here if more callers
100 // are interested in this in the future.
101 bool IsGoogleDomainUrl(const GURL& url,
102                        SubdomainPermission subdomain_permission,
103                        PortPermission port_permission);
104
105 // True if |url| represents a valid Google home page URL.
106 bool IsGoogleHomePageUrl(const GURL& url);
107
108 // True if |url| represents a valid Google search URL.
109 bool IsGoogleSearchUrl(const GURL& url);
110
111 // True if a build is strictly organic, according to its brand code.
112 bool IsOrganic(const std::string& brand);
113
114 // True if a build should run as organic during first run. This uses
115 // a slightly different set of brand codes from the standard IsOrganic
116 // method.
117 bool IsOrganicFirstRun(const std::string& brand);
118
119 // True if |brand| is an internet cafe brand code.
120 bool IsInternetCafeBrandCode(const std::string& brand);
121
122 // This class is meant to be used only from test code, and sets the brand
123 // code returned by the function GetBrand() above while the object exists.
124 class BrandForTesting {
125  public:
126   explicit BrandForTesting(const std::string& brand);
127   ~BrandForTesting();
128
129  private:
130   std::string brand_;
131   DISALLOW_COPY_AND_ASSIGN(BrandForTesting);
132 };
133
134 }  // namespace google_util
135
136 #endif  // CHROME_BROWSER_GOOGLE_GOOGLE_UTIL_H__