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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 #endif // OS_CHROMEOS |
94 | 95 |
96 // Global SequenceNumber used for generating unique webview partition IDs. | |
97 static base::StaticAtomicSequenceNumber next_partition_id; | |
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) {} |
99 virtual ~InlineLoginUIHandler() {} | 103 virtual ~InlineLoginUIHandler() {} |
100 | 104 |
101 // content::WebUIMessageHandler overrides: | 105 // content::WebUIMessageHandler overrides: |
102 virtual void RegisterMessages() OVERRIDE { | 106 virtual void RegisterMessages() OVERRIDE { |
103 web_ui()->RegisterMessageCallback("initialize", | 107 web_ui()->RegisterMessageCallback("initialize", |
104 base::Bind(&InlineLoginUIHandler::HandleInitialize, | 108 base::Bind(&InlineLoginUIHandler::HandleInitialize, |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
158 } | 162 } |
159 | 163 |
160 params.SetString("continueUrl", | 164 params.SetString("continueUrl", |
161 gaiaUrls->client_login_to_oauth2_url().Resolve( | 165 gaiaUrls->client_login_to_oauth2_url().Resolve( |
162 encoded_continue_params).spec()); | 166 encoded_continue_params).spec()); |
163 | 167 |
164 std::string email; | 168 std::string email; |
165 net::GetValueForKeyInQuery(current_url, "Email", &email); | 169 net::GetValueForKeyInQuery(current_url, "Email", &email); |
166 if (!email.empty()) | 170 if (!email.empty()) |
167 params.SetString("email", email); | 171 params.SetString("email", email); |
172 | |
173 partition_id_ = | |
174 "gaia-webview-" + base::IntToString(next_partition_id.GetNext()); | |
175 params.SetString("partitionId", partition_id_); | |
168 } | 176 } |
169 #endif | 177 #endif |
170 | 178 |
171 web_ui()->CallJavascriptFunction("inline.login.loadAuthExtension", params); | 179 web_ui()->CallJavascriptFunction("inline.login.loadAuthExtension", params); |
172 } | 180 } |
173 | 181 |
174 // JS callback: | 182 // JS callback: |
175 void HandleInitialize(const base::ListValue* args) { | 183 void HandleInitialize(const base::ListValue* args) { |
176 LoadAuthExtension(); | 184 LoadAuthExtension(); |
177 } | 185 } |
(...skipping 15 matching lines...) Expand all Loading... | |
193 NOTREACHED(); | 201 NOTREACHED(); |
194 return; | 202 return; |
195 } | 203 } |
196 dict->GetString("password", &password); | 204 dict->GetString("password", &password); |
197 dict->GetBoolean("chooseWhatToSync", &choose_what_to_sync_); | 205 dict->GetBoolean("chooseWhatToSync", &choose_what_to_sync_); |
198 | 206 |
199 content::WebContents* web_contents = web_ui()->GetWebContents(); | 207 content::WebContents* web_contents = web_ui()->GetWebContents(); |
200 content::StoragePartition* partition = | 208 content::StoragePartition* partition = |
201 content::BrowserContext::GetStoragePartitionForSite( | 209 content::BrowserContext::GetStoragePartitionForSite( |
202 web_contents->GetBrowserContext(), | 210 web_contents->GetBrowserContext(), |
203 GURL("chrome-guest://mfffpogegjflfpflabcdkioaeobkgjik/?")); | 211 GURL("chrome-guest://mfffpogegjflfpflabcdkioaeobkgjik/?" + |
212 partition_id_)); | |
lazyboy
2013/11/04 21:08:29
nit: generally query params have "query=value" for
guohui
2013/11/05 14:35:36
i agree, but i thought currently ?partition_id is
Fady Samuel
2013/11/05 21:47:08
Yes, Hui is correct. See here:
https://code.goog
| |
204 | 213 |
205 scoped_refptr<SigninManagerCookieHelper> cookie_helper( | 214 scoped_refptr<SigninManagerCookieHelper> cookie_helper( |
206 new SigninManagerCookieHelper(partition->GetURLRequestContext())); | 215 new SigninManagerCookieHelper(partition->GetURLRequestContext())); |
207 cookie_helper->StartFetchingCookiesOnUIThread( | 216 cookie_helper->StartFetchingCookiesOnUIThread( |
208 GURL(GaiaUrls::GetInstance()->client_login_to_oauth2_url()), | 217 GURL(GaiaUrls::GetInstance()->client_login_to_oauth2_url()), |
209 base::Bind(&InlineLoginUIHandler::OnGaiaCookiesFetched, | 218 base::Bind(&InlineLoginUIHandler::OnGaiaCookiesFetched, |
210 weak_factory_.GetWeakPtr(), email, password)); | 219 weak_factory_.GetWeakPtr(), email, password)); |
211 #endif | 220 #endif |
212 } | 221 } |
213 | 222 |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
302 tab_strip_model->ExecuteContextMenuCommand( | 311 tab_strip_model->ExecuteContextMenuCommand( |
303 index, TabStripModel::CommandCloseTab); | 312 index, TabStripModel::CommandCloseTab); |
304 } | 313 } |
305 } | 314 } |
306 } | 315 } |
307 } | 316 } |
308 | 317 |
309 Profile* profile_; | 318 Profile* profile_; |
310 base::WeakPtrFactory<InlineLoginUIHandler> weak_factory_; | 319 base::WeakPtrFactory<InlineLoginUIHandler> weak_factory_; |
311 bool choose_what_to_sync_; | 320 bool choose_what_to_sync_; |
321 // Partition id for the gaia webview; | |
322 std::string partition_id_; | |
312 | 323 |
313 #if defined(OS_CHROMEOS) | 324 #if defined(OS_CHROMEOS) |
314 scoped_ptr<chromeos::OAuth2TokenFetcher> oauth2_token_fetcher_; | 325 scoped_ptr<chromeos::OAuth2TokenFetcher> oauth2_token_fetcher_; |
315 scoped_ptr<InlineLoginUIOAuth2Delegate> oauth2_delegate_; | 326 scoped_ptr<InlineLoginUIOAuth2Delegate> oauth2_delegate_; |
316 #endif | 327 #endif |
317 | 328 |
318 DISALLOW_COPY_AND_ASSIGN(InlineLoginUIHandler); | 329 DISALLOW_COPY_AND_ASSIGN(InlineLoginUIHandler); |
319 }; | 330 }; |
320 | 331 |
321 } // namespace | 332 } // namespace |
322 | 333 |
323 InlineLoginUI::InlineLoginUI(content::WebUI* web_ui) | 334 InlineLoginUI::InlineLoginUI(content::WebUI* web_ui) |
324 : WebDialogUI(web_ui), | 335 : WebDialogUI(web_ui), |
325 auth_extension_(Profile::FromWebUI(web_ui)) { | 336 auth_extension_(Profile::FromWebUI(web_ui)) { |
326 Profile* profile = Profile::FromWebUI(web_ui); | 337 Profile* profile = Profile::FromWebUI(web_ui); |
327 content::WebUIDataSource::Add(profile, CreateWebUIDataSource()); | 338 content::WebUIDataSource::Add(profile, CreateWebUIDataSource()); |
328 | 339 |
329 web_ui->AddMessageHandler(new InlineLoginUIHandler(profile)); | 340 web_ui->AddMessageHandler(new InlineLoginUIHandler(profile)); |
330 // Required for intercepting extension function calls when the page is loaded | 341 // 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 | 342 // in a bubble (not a full tab, thus tab helpers are not registered |
332 // automatically). | 343 // automatically). |
333 extensions::TabHelper::CreateForWebContents(web_ui->GetWebContents()); | 344 extensions::TabHelper::CreateForWebContents(web_ui->GetWebContents()); |
334 } | 345 } |
335 | 346 |
336 InlineLoginUI::~InlineLoginUI() {} | 347 InlineLoginUI::~InlineLoginUI() {} |
OLD | NEW |