Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / google_apis / gaia / gaia_urls.cc
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 #include "google_apis/gaia/gaia_urls.h"
6
7 #include "base/command_line.h"
8 #include "base/logging.h"
9 #include "google_apis/gaia/gaia_switches.h"
10 #include "google_apis/google_api_keys.h"
11
12 namespace {
13
14 // Gaia service constants
15 const char kDefaultGaiaUrl[] = "https://accounts.google.com";
16 const char kDefaultGoogleApisBaseUrl[] = "https://www.googleapis.com";
17
18 // API calls from accounts.google.com
19 const char kClientLoginUrlSuffix[] = "ClientLogin";
20 const char kServiceLoginUrlSuffix[] = "ServiceLogin";
21 const char kServiceLoginAuthUrlSuffix[] = "ServiceLoginAuth";
22 const char kServiceLogoutUrlSuffix[] = "Logout";
23 const char kIssueAuthTokenUrlSuffix[] = "IssueAuthToken";
24 const char kGetUserInfoUrlSuffix[] = "GetUserInfo";
25 const char kTokenAuthUrlSuffix[] = "TokenAuth";
26 const char kMergeSessionUrlSuffix[] = "MergeSession";
27 const char kOAuthGetAccessTokenUrlSuffix[] = "OAuthGetAccessToken";
28 const char kOAuthWrapBridgeUrlSuffix[] = "OAuthWrapBridge";
29 const char kOAuth1LoginUrlSuffix[] = "OAuthLogin";
30 const char kOAuthRevokeTokenUrlSuffix[] = "AuthSubRevokeToken";
31 const char kListAccountsSuffix[] = "ListAccounts?json=standard";
32 const char kEmbeddedSigninSuffix[] = "EmbeddedSignIn";
33 const char kAddAccountSuffix[] = "AddSession";
34 const char kGetCheckConnectionInfoSuffix[] = "GetCheckConnectionInfo";
35
36 // API calls from accounts.google.com (LSO)
37 const char kGetOAuthTokenUrlSuffix[] = "o/oauth/GetOAuthToken/";
38 const char kClientLoginToOAuth2UrlSuffix[] = "o/oauth2/programmatic_auth";
39 const char kOAuth2AuthUrlSuffix[] = "o/oauth2/auth";
40 const char kOAuth2RevokeUrlSuffix[] = "o/oauth2/revoke";
41 const char kOAuth2TokenUrlSuffix[] = "o/oauth2/token";
42
43 // API calls from www.googleapis.com
44 const char kOAuth2IssueTokenUrlSuffix[] = "oauth2/v2/IssueToken";
45 const char kOAuth2TokenInfoUrlSuffix[] = "oauth2/v2/tokeninfo";
46 const char kOAuthUserInfoUrlSuffix[] = "oauth2/v1/userinfo";
47
48 void GetSwitchValueWithDefault(const char* switch_value,
49                                const char* default_value,
50                                std::string* output_value) {
51   CommandLine* command_line = CommandLine::ForCurrentProcess();
52   if (command_line->HasSwitch(switch_value)) {
53     *output_value = command_line->GetSwitchValueASCII(switch_value);
54   } else {
55     *output_value = default_value;
56   }
57 }
58
59 GURL GetURLSwitchValueWithDefault(const char* switch_value,
60                                   const char* default_value) {
61   std::string string_value;
62   GetSwitchValueWithDefault(switch_value, default_value, &string_value);
63   const GURL result(string_value);
64   DCHECK(result.is_valid());
65   return result;
66 }
67
68
69 }  // namespace
70
71 GaiaUrls* GaiaUrls::GetInstance() {
72   return Singleton<GaiaUrls>::get();
73 }
74
75 GaiaUrls::GaiaUrls() {
76   gaia_url_ = GetURLSwitchValueWithDefault(switches::kGaiaUrl, kDefaultGaiaUrl);
77   lso_origin_url_ =
78       GetURLSwitchValueWithDefault(switches::kLsoUrl, kDefaultGaiaUrl);
79   google_apis_origin_url_ = GetURLSwitchValueWithDefault(
80       switches::kGoogleApisUrl, kDefaultGoogleApisBaseUrl);
81
82   captcha_base_url_ =
83       GURL("http://" + gaia_url_.host() +
84            (gaia_url_.has_port() ? ":" + gaia_url_.port() : ""));
85
86   oauth2_chrome_client_id_ =
87       google_apis::GetOAuth2ClientID(google_apis::CLIENT_MAIN);
88   oauth2_chrome_client_secret_ =
89       google_apis::GetOAuth2ClientSecret(google_apis::CLIENT_MAIN);
90
91   // URLs from accounts.google.com.
92   client_login_url_ = gaia_url_.Resolve(kClientLoginUrlSuffix);
93   service_login_url_ = gaia_url_.Resolve(kServiceLoginUrlSuffix);
94   service_login_auth_url_ = gaia_url_.Resolve(kServiceLoginAuthUrlSuffix);
95   service_logout_url_ = gaia_url_.Resolve(kServiceLogoutUrlSuffix);
96   issue_auth_token_url_ = gaia_url_.Resolve(kIssueAuthTokenUrlSuffix);
97   get_user_info_url_ = gaia_url_.Resolve(kGetUserInfoUrlSuffix);
98   token_auth_url_ = gaia_url_.Resolve(kTokenAuthUrlSuffix);
99   merge_session_url_ = gaia_url_.Resolve(kMergeSessionUrlSuffix);
100   oauth_get_access_token_url_ =
101       gaia_url_.Resolve(kOAuthGetAccessTokenUrlSuffix);
102   oauth_wrap_bridge_url_ = gaia_url_.Resolve(kOAuthWrapBridgeUrlSuffix);
103   oauth_revoke_token_url_ = gaia_url_.Resolve(kOAuthRevokeTokenUrlSuffix);
104   oauth1_login_url_ = gaia_url_.Resolve(kOAuth1LoginUrlSuffix);
105   list_accounts_url_ = gaia_url_.Resolve(kListAccountsSuffix);
106   embedded_signin_url_ = gaia_url_.Resolve(kEmbeddedSigninSuffix);
107   add_account_url_ = gaia_url_.Resolve(kAddAccountSuffix);
108   get_check_connection_info_url_ =
109       gaia_url_.Resolve(kGetCheckConnectionInfoSuffix);
110
111   // URLs from accounts.google.com (LSO).
112   get_oauth_token_url_ = lso_origin_url_.Resolve(kGetOAuthTokenUrlSuffix);
113   client_login_to_oauth2_url_ =
114       lso_origin_url_.Resolve(kClientLoginToOAuth2UrlSuffix);
115   oauth2_auth_url_ = lso_origin_url_.Resolve(kOAuth2AuthUrlSuffix);
116   oauth2_token_url_ = lso_origin_url_.Resolve(kOAuth2TokenUrlSuffix);
117   oauth2_revoke_url_ = lso_origin_url_.Resolve(kOAuth2RevokeUrlSuffix);
118
119   // URLs from www.googleapis.com.
120   oauth2_issue_token_url_ =
121       google_apis_origin_url_.Resolve(kOAuth2IssueTokenUrlSuffix);
122   oauth2_token_info_url_ =
123       google_apis_origin_url_.Resolve(kOAuth2TokenInfoUrlSuffix);
124   oauth_user_info_url_ =
125       google_apis_origin_url_.Resolve(kOAuthUserInfoUrlSuffix);
126
127   gaia_login_form_realm_ = gaia_url_;
128 }
129
130 GaiaUrls::~GaiaUrls() {
131 }
132
133 const GURL& GaiaUrls::gaia_url() const {
134   return gaia_url_;
135 }
136
137 const GURL& GaiaUrls::captcha_base_url() const {
138   return captcha_base_url_;
139 }
140
141 const GURL& GaiaUrls::client_login_url() const {
142   return client_login_url_;
143 }
144
145 const GURL& GaiaUrls::service_login_url() const {
146   return service_login_url_;
147 }
148
149 const GURL& GaiaUrls::service_login_auth_url() const {
150   return service_login_auth_url_;
151 }
152
153 const GURL& GaiaUrls::service_logout_url() const {
154   return service_logout_url_;
155 }
156
157 const GURL& GaiaUrls::issue_auth_token_url() const {
158   return issue_auth_token_url_;
159 }
160
161 const GURL& GaiaUrls::get_user_info_url() const {
162   return get_user_info_url_;
163 }
164
165 const GURL& GaiaUrls::token_auth_url() const {
166   return token_auth_url_;
167 }
168
169 const GURL& GaiaUrls::merge_session_url() const {
170   return merge_session_url_;
171 }
172
173 const GURL& GaiaUrls::get_oauth_token_url() const {
174   return get_oauth_token_url_;
175 }
176
177 const GURL& GaiaUrls::oauth_get_access_token_url() const {
178   return oauth_get_access_token_url_;
179 }
180
181 const GURL& GaiaUrls::oauth_wrap_bridge_url() const {
182   return oauth_wrap_bridge_url_;
183 }
184
185 const GURL& GaiaUrls::oauth_user_info_url() const {
186   return oauth_user_info_url_;
187 }
188
189 const GURL& GaiaUrls::oauth_revoke_token_url() const {
190   return oauth_revoke_token_url_;
191 }
192
193 const GURL& GaiaUrls::oauth1_login_url() const {
194   return oauth1_login_url_;
195 }
196
197 const GURL& GaiaUrls::list_accounts_url() const {
198   return list_accounts_url_;
199 }
200
201 const GURL& GaiaUrls::embedded_signin_url() const {
202   return embedded_signin_url_;
203 }
204
205 const GURL& GaiaUrls::add_account_url() const {
206   return add_account_url_;
207 }
208
209 const GURL& GaiaUrls::get_check_connection_info_url() const {
210   return get_check_connection_info_url_;
211 }
212
213 const std::string& GaiaUrls::oauth2_chrome_client_id() const {
214   return oauth2_chrome_client_id_;
215 }
216
217 const std::string& GaiaUrls::oauth2_chrome_client_secret() const {
218   return oauth2_chrome_client_secret_;
219 }
220
221 const GURL& GaiaUrls::client_login_to_oauth2_url() const {
222   return client_login_to_oauth2_url_;
223 }
224
225 const GURL& GaiaUrls::oauth2_auth_url() const {
226   return oauth2_auth_url_;
227 }
228
229 const GURL& GaiaUrls::oauth2_token_url() const {
230   return oauth2_token_url_;
231 }
232
233 const GURL& GaiaUrls::oauth2_issue_token_url() const {
234   return oauth2_issue_token_url_;
235 }
236
237 const GURL& GaiaUrls::oauth2_token_info_url() const {
238   return oauth2_token_info_url_;
239 }
240
241 const GURL& GaiaUrls::oauth2_revoke_url() const {
242   return oauth2_revoke_url_;
243 }
244
245 const GURL& GaiaUrls::gaia_login_form_realm() const {
246   return gaia_url_;
247 }