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