| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/webui/inline_login_ui.h" | 5 #include "chrome/browser/ui/webui/inline_login_ui.h" |
| 6 | 6 |
| 7 #include "base/atomic_sequence_num.h" |
| 7 #include "base/bind.h" | 8 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 9 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
| 11 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
| 12 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
| 13 #include "base/values.h" | 14 #include "base/values.h" |
| 14 #include "chrome/browser/browser_process.h" | 15 #include "chrome/browser/browser_process.h" |
| 15 #include "chrome/browser/extensions/tab_helper.h" | 16 #include "chrome/browser/extensions/tab_helper.h" |
| 16 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 } | 84 } |
| 84 | 85 |
| 85 virtual void OnOAuth2TokensFetchFailed() OVERRIDE { | 86 virtual void OnOAuth2TokensFetchFailed() OVERRIDE { |
| 86 LOG(ERROR) << "Failed to fetch oauth2 token with inline login."; | 87 LOG(ERROR) << "Failed to fetch oauth2 token with inline login."; |
| 87 web_ui_->CallJavascriptFunction("inline.login.handleOAuth2TokenFailure"); | 88 web_ui_->CallJavascriptFunction("inline.login.handleOAuth2TokenFailure"); |
| 88 } | 89 } |
| 89 | 90 |
| 90 private: | 91 private: |
| 91 content::WebUI* web_ui_; | 92 content::WebUI* web_ui_; |
| 92 }; | 93 }; |
| 93 #endif // OS_CHROMEOS | 94 #elif !defined(OS_ANDROID) |
| 95 // Global SequenceNumber used for generating unique webview partition IDs. |
| 96 base::StaticAtomicSequenceNumber next_partition_id; |
| 97 #endif |
| 94 | 98 |
| 95 class InlineLoginUIHandler : public content::WebUIMessageHandler { | 99 class InlineLoginUIHandler : public content::WebUIMessageHandler { |
| 96 public: | 100 public: |
| 97 explicit InlineLoginUIHandler(Profile* profile) | 101 explicit InlineLoginUIHandler(Profile* profile) |
| 98 : profile_(profile), weak_factory_(this), choose_what_to_sync_(false) {} | 102 : profile_(profile), weak_factory_(this), choose_what_to_sync_(false), |
| 103 partition_id_("") {} |
| 99 virtual ~InlineLoginUIHandler() {} | 104 virtual ~InlineLoginUIHandler() {} |
| 100 | 105 |
| 101 // content::WebUIMessageHandler overrides: | 106 // content::WebUIMessageHandler overrides: |
| 102 virtual void RegisterMessages() OVERRIDE { | 107 virtual void RegisterMessages() OVERRIDE { |
| 103 web_ui()->RegisterMessageCallback("initialize", | 108 web_ui()->RegisterMessageCallback("initialize", |
| 104 base::Bind(&InlineLoginUIHandler::HandleInitialize, | 109 base::Bind(&InlineLoginUIHandler::HandleInitialize, |
| 105 base::Unretained(this))); | 110 base::Unretained(this))); |
| 106 web_ui()->RegisterMessageCallback("completeLogin", | 111 web_ui()->RegisterMessageCallback("completeLogin", |
| 107 base::Bind(&InlineLoginUIHandler::HandleCompleteLogin, | 112 base::Bind(&InlineLoginUIHandler::HandleCompleteLogin, |
| 108 base::Unretained(this))); | 113 base::Unretained(this))); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 125 | 130 |
| 126 GaiaUrls* gaiaUrls = GaiaUrls::GetInstance(); | 131 GaiaUrls* gaiaUrls = GaiaUrls::GetInstance(); |
| 127 params.SetString("gaiaUrl", gaiaUrls->gaia_url().spec()); | 132 params.SetString("gaiaUrl", gaiaUrls->gaia_url().spec()); |
| 128 | 133 |
| 129 bool enable_inline = CommandLine::ForCurrentProcess()->HasSwitch( | 134 bool enable_inline = CommandLine::ForCurrentProcess()->HasSwitch( |
| 130 switches::kEnableInlineSignin); | 135 switches::kEnableInlineSignin); |
| 131 params.SetInteger("authMode", | 136 params.SetInteger("authMode", |
| 132 enable_inline ? kInlineAuthMode : kDefaultAuthMode); | 137 enable_inline ? kInlineAuthMode : kDefaultAuthMode); |
| 133 | 138 |
| 134 // Set parameters specific for inline signin flow. | 139 // Set parameters specific for inline signin flow. |
| 135 #if !defined(OS_CHROMEOS) | 140 #if !defined(OS_CHROMEOS) && !defined(OS_ANDROID) |
| 136 if (enable_inline) { | 141 if (enable_inline) { |
| 137 // Set continueUrl param for the inline sign in flow. It should point to | 142 // Set continueUrl param for the inline sign in flow. It should point to |
| 138 // the oauth2 auth code URL so that later we can grab the auth code from | 143 // the oauth2 auth code URL so that later we can grab the auth code from |
| 139 // the cookie jar of the embedded webview. | 144 // the cookie jar of the embedded webview. |
| 140 std::string scope = net::EscapeUrlEncodedData( | 145 std::string scope = net::EscapeUrlEncodedData( |
| 141 gaiaUrls->oauth1_login_scope(), true); | 146 gaiaUrls->oauth1_login_scope(), true); |
| 142 std::string client_id = net::EscapeUrlEncodedData( | 147 std::string client_id = net::EscapeUrlEncodedData( |
| 143 gaiaUrls->oauth2_chrome_client_id(), true); | 148 gaiaUrls->oauth2_chrome_client_id(), true); |
| 144 std::string encoded_continue_params = base::StringPrintf( | 149 std::string encoded_continue_params = base::StringPrintf( |
| 145 "?scope=%s&client_id=%s", scope.c_str(), client_id.c_str()); | 150 "?scope=%s&client_id=%s", scope.c_str(), client_id.c_str()); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 158 } | 163 } |
| 159 | 164 |
| 160 params.SetString("continueUrl", | 165 params.SetString("continueUrl", |
| 161 gaiaUrls->client_login_to_oauth2_url().Resolve( | 166 gaiaUrls->client_login_to_oauth2_url().Resolve( |
| 162 encoded_continue_params).spec()); | 167 encoded_continue_params).spec()); |
| 163 | 168 |
| 164 std::string email; | 169 std::string email; |
| 165 net::GetValueForKeyInQuery(current_url, "Email", &email); | 170 net::GetValueForKeyInQuery(current_url, "Email", &email); |
| 166 if (!email.empty()) | 171 if (!email.empty()) |
| 167 params.SetString("email", email); | 172 params.SetString("email", email); |
| 173 |
| 174 partition_id_ = |
| 175 "gaia-webview-" + base::IntToString(next_partition_id.GetNext()); |
| 176 params.SetString("partitionId", partition_id_); |
| 168 } | 177 } |
| 169 #endif | 178 #endif |
| 170 | 179 |
| 171 web_ui()->CallJavascriptFunction("inline.login.loadAuthExtension", params); | 180 web_ui()->CallJavascriptFunction("inline.login.loadAuthExtension", params); |
| 172 } | 181 } |
| 173 | 182 |
| 174 // JS callback: | 183 // JS callback: |
| 175 void HandleInitialize(const base::ListValue* args) { | 184 void HandleInitialize(const base::ListValue* args) { |
| 176 LoadAuthExtension(); | 185 LoadAuthExtension(); |
| 177 } | 186 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 193 NOTREACHED(); | 202 NOTREACHED(); |
| 194 return; | 203 return; |
| 195 } | 204 } |
| 196 dict->GetString("password", &password); | 205 dict->GetString("password", &password); |
| 197 dict->GetBoolean("chooseWhatToSync", &choose_what_to_sync_); | 206 dict->GetBoolean("chooseWhatToSync", &choose_what_to_sync_); |
| 198 | 207 |
| 199 content::WebContents* web_contents = web_ui()->GetWebContents(); | 208 content::WebContents* web_contents = web_ui()->GetWebContents(); |
| 200 content::StoragePartition* partition = | 209 content::StoragePartition* partition = |
| 201 content::BrowserContext::GetStoragePartitionForSite( | 210 content::BrowserContext::GetStoragePartitionForSite( |
| 202 web_contents->GetBrowserContext(), | 211 web_contents->GetBrowserContext(), |
| 203 GURL("chrome-guest://mfffpogegjflfpflabcdkioaeobkgjik/?")); | 212 GURL("chrome-guest://mfffpogegjflfpflabcdkioaeobkgjik/?" + |
| 213 partition_id_)); |
| 204 | 214 |
| 205 scoped_refptr<SigninManagerCookieHelper> cookie_helper( | 215 scoped_refptr<SigninManagerCookieHelper> cookie_helper( |
| 206 new SigninManagerCookieHelper(partition->GetURLRequestContext())); | 216 new SigninManagerCookieHelper(partition->GetURLRequestContext())); |
| 207 cookie_helper->StartFetchingCookiesOnUIThread( | 217 cookie_helper->StartFetchingCookiesOnUIThread( |
| 208 GURL(GaiaUrls::GetInstance()->client_login_to_oauth2_url()), | 218 GURL(GaiaUrls::GetInstance()->client_login_to_oauth2_url()), |
| 209 base::Bind(&InlineLoginUIHandler::OnGaiaCookiesFetched, | 219 base::Bind(&InlineLoginUIHandler::OnGaiaCookiesFetched, |
| 210 weak_factory_.GetWeakPtr(), email, password)); | 220 weak_factory_.GetWeakPtr(), email, password)); |
| 211 #endif | 221 #endif |
| 212 } | 222 } |
| 213 | 223 |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 tab_strip_model->ExecuteContextMenuCommand( | 312 tab_strip_model->ExecuteContextMenuCommand( |
| 303 index, TabStripModel::CommandCloseTab); | 313 index, TabStripModel::CommandCloseTab); |
| 304 } | 314 } |
| 305 } | 315 } |
| 306 } | 316 } |
| 307 } | 317 } |
| 308 | 318 |
| 309 Profile* profile_; | 319 Profile* profile_; |
| 310 base::WeakPtrFactory<InlineLoginUIHandler> weak_factory_; | 320 base::WeakPtrFactory<InlineLoginUIHandler> weak_factory_; |
| 311 bool choose_what_to_sync_; | 321 bool choose_what_to_sync_; |
| 322 // Partition id for the gaia webview; |
| 323 std::string partition_id_; |
| 312 | 324 |
| 313 #if defined(OS_CHROMEOS) | 325 #if defined(OS_CHROMEOS) |
| 314 scoped_ptr<chromeos::OAuth2TokenFetcher> oauth2_token_fetcher_; | 326 scoped_ptr<chromeos::OAuth2TokenFetcher> oauth2_token_fetcher_; |
| 315 scoped_ptr<InlineLoginUIOAuth2Delegate> oauth2_delegate_; | 327 scoped_ptr<InlineLoginUIOAuth2Delegate> oauth2_delegate_; |
| 316 #endif | 328 #endif |
| 317 | 329 |
| 318 DISALLOW_COPY_AND_ASSIGN(InlineLoginUIHandler); | 330 DISALLOW_COPY_AND_ASSIGN(InlineLoginUIHandler); |
| 319 }; | 331 }; |
| 320 | 332 |
| 321 } // namespace | 333 } // namespace |
| 322 | 334 |
| 323 InlineLoginUI::InlineLoginUI(content::WebUI* web_ui) | 335 InlineLoginUI::InlineLoginUI(content::WebUI* web_ui) |
| 324 : WebDialogUI(web_ui), | 336 : WebDialogUI(web_ui), |
| 325 auth_extension_(Profile::FromWebUI(web_ui)) { | 337 auth_extension_(Profile::FromWebUI(web_ui)) { |
| 326 Profile* profile = Profile::FromWebUI(web_ui); | 338 Profile* profile = Profile::FromWebUI(web_ui); |
| 327 content::WebUIDataSource::Add(profile, CreateWebUIDataSource()); | 339 content::WebUIDataSource::Add(profile, CreateWebUIDataSource()); |
| 328 | 340 |
| 329 web_ui->AddMessageHandler(new InlineLoginUIHandler(profile)); | 341 web_ui->AddMessageHandler(new InlineLoginUIHandler(profile)); |
| 330 // Required for intercepting extension function calls when the page is loaded | 342 // Required for intercepting extension function calls when the page is loaded |
| 331 // in a bubble (not a full tab, thus tab helpers are not registered | 343 // in a bubble (not a full tab, thus tab helpers are not registered |
| 332 // automatically). | 344 // automatically). |
| 333 extensions::TabHelper::CreateForWebContents(web_ui->GetWebContents()); | 345 extensions::TabHelper::CreateForWebContents(web_ui->GetWebContents()); |
| 334 } | 346 } |
| 335 | 347 |
| 336 InlineLoginUI::~InlineLoginUI() {} | 348 InlineLoginUI::~InlineLoginUI() {} |
| OLD | NEW |