Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(284)

Side by Side Diff: chrome/browser/ui/webui/inline_login_ui.cc

Issue 99913004: Add error handling to inline signin flow (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/sync/one_click_signin_helper.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/atomic_sequence_num.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "base/strings/string_number_conversions.h" 11 #include "base/strings/string_number_conversions.h"
12 #include "base/strings/string_util.h" 12 #include "base/strings/string_util.h"
13 #include "base/strings/stringprintf.h" 13 #include "base/strings/stringprintf.h"
14 #include "base/values.h" 14 #include "base/values.h"
15 #include "chrome/browser/browser_process.h" 15 #include "chrome/browser/browser_process.h"
16 #include "chrome/browser/extensions/tab_helper.h" 16 #include "chrome/browser/extensions/tab_helper.h"
17 #include "chrome/browser/profiles/profile.h" 17 #include "chrome/browser/profiles/profile.h"
18 #include "chrome/browser/signin/profile_oauth2_token_service.h" 18 #include "chrome/browser/signin/profile_oauth2_token_service.h"
19 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" 19 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
20 #include "chrome/browser/signin/signin_global_error.h" 20 #include "chrome/browser/signin/signin_global_error.h"
21 #include "chrome/browser/signin/signin_manager_cookie_helper.h" 21 #include "chrome/browser/signin/signin_manager_cookie_helper.h"
22 #include "chrome/browser/signin/signin_names_io_thread.h" 22 #include "chrome/browser/signin/signin_names_io_thread.h"
23 #include "chrome/browser/signin/signin_oauth_helper.h" 23 #include "chrome/browser/signin/signin_oauth_helper.h"
24 #include "chrome/browser/signin/signin_promo.h" 24 #include "chrome/browser/signin/signin_promo.h"
25 #include "chrome/browser/sync/profile_sync_service.h" 25 #include "chrome/browser/sync/profile_sync_service.h"
26 #include "chrome/browser/sync/profile_sync_service_factory.h" 26 #include "chrome/browser/sync/profile_sync_service_factory.h"
27 #include "chrome/browser/ui/browser_finder.h" 27 #include "chrome/browser/ui/browser_finder.h"
28 #include "chrome/browser/ui/sync/one_click_signin_helper.h"
28 #include "chrome/browser/ui/sync/one_click_signin_sync_starter.h" 29 #include "chrome/browser/ui/sync/one_click_signin_sync_starter.h"
29 #include "chrome/browser/ui/tabs/tab_strip_model.h" 30 #include "chrome/browser/ui/tabs/tab_strip_model.h"
30 #include "chrome/common/chrome_switches.h" 31 #include "chrome/common/chrome_switches.h"
31 #include "chrome/common/url_constants.h" 32 #include "chrome/common/url_constants.h"
32 #include "content/public/browser/storage_partition.h" 33 #include "content/public/browser/storage_partition.h"
33 #include "content/public/browser/web_contents.h" 34 #include "content/public/browser/web_contents.h"
34 #include "content/public/browser/web_ui.h" 35 #include "content/public/browser/web_ui.h"
35 #include "content/public/browser/web_ui_data_source.h" 36 #include "content/public/browser/web_ui_data_source.h"
36 #include "content/public/browser/web_ui_message_handler.h" 37 #include "content/public/browser/web_ui_message_handler.h"
37 #include "google_apis/gaia/gaia_switches.h" 38 #include "google_apis/gaia/gaia_switches.h"
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 string16 password; 201 string16 password;
201 if (!args->GetDictionary(0, &dict) || !dict || 202 if (!args->GetDictionary(0, &dict) || !dict ||
202 !dict->GetString("email", &email)) { 203 !dict->GetString("email", &email)) {
203 NOTREACHED(); 204 NOTREACHED();
204 return; 205 return;
205 } 206 }
206 dict->GetString("password", &password); 207 dict->GetString("password", &password);
207 dict->GetBoolean("chooseWhatToSync", &choose_what_to_sync_); 208 dict->GetBoolean("chooseWhatToSync", &choose_what_to_sync_);
208 209
209 content::WebContents* web_contents = web_ui()->GetWebContents(); 210 content::WebContents* web_contents = web_ui()->GetWebContents();
211 std::string error_msg;
212 OneClickSigninHelper::CanOffer(
213 web_contents, OneClickSigninHelper::CAN_OFFER_FOR_ALL,
214 UTF16ToASCII(email), &error_msg);
215 if (!error_msg.empty()) {
216 RedirectToNtpOrAppsPage(
217 web_contents, signin::GetSourceForPromoURL(web_contents->GetURL()));
218 Browser* browser = chrome::FindBrowserWithWebContents(web_contents);
219 OneClickSigninHelper::ShowSigninErrorBubble(browser, error_msg);
220 return;
221 }
222
210 content::StoragePartition* partition = 223 content::StoragePartition* partition =
211 content::BrowserContext::GetStoragePartitionForSite( 224 content::BrowserContext::GetStoragePartitionForSite(
212 web_contents->GetBrowserContext(), 225 web_contents->GetBrowserContext(),
213 GURL("chrome-guest://mfffpogegjflfpflabcdkioaeobkgjik/?" + 226 GURL("chrome-guest://mfffpogegjflfpflabcdkioaeobkgjik/?" +
214 partition_id_)); 227 partition_id_));
215 228
216 scoped_refptr<SigninManagerCookieHelper> cookie_helper( 229 scoped_refptr<SigninManagerCookieHelper> cookie_helper(
217 new SigninManagerCookieHelper(partition->GetURLRequestContext())); 230 new SigninManagerCookieHelper(partition->GetURLRequestContext()));
218 cookie_helper->StartFetchingCookiesOnUIThread( 231 cookie_helper->StartFetchingCookiesOnUIThread(
219 GURL(GaiaUrls::GetInstance()->client_login_to_oauth2_url()), 232 GURL(GaiaUrls::GetInstance()->client_login_to_oauth2_url()),
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 bool auto_close = signin::IsAutoCloseEnabledInURL(current_url); 294 bool auto_close = signin::IsAutoCloseEnabledInURL(current_url);
282 signin::Source source = signin::GetSourceForPromoURL(current_url); 295 signin::Source source = signin::GetSourceForPromoURL(current_url);
283 if (auto_close) { 296 if (auto_close) {
284 base::MessageLoop::current()->PostTask( 297 base::MessageLoop::current()->PostTask(
285 FROM_HERE, 298 FROM_HERE,
286 base::Bind( 299 base::Bind(
287 &InlineLoginUIHandler::CloseTab, weak_factory_.GetWeakPtr())); 300 &InlineLoginUIHandler::CloseTab, weak_factory_.GetWeakPtr()));
288 } else if (source != signin::SOURCE_UNKNOWN && 301 } else if (source != signin::SOURCE_UNKNOWN &&
289 source != signin::SOURCE_SETTINGS && 302 source != signin::SOURCE_SETTINGS &&
290 source != signin::SOURCE_WEBSTORE_INSTALL) { 303 source != signin::SOURCE_WEBSTORE_INSTALL) {
291 // Redirect to NTP/Apps page and display a confirmation bubble.
292 // TODO(guohui): should redirect to the given continue url for webstore 304 // TODO(guohui): should redirect to the given continue url for webstore
293 // install flows. 305 // install flows.
294 GURL url(source == signin::SOURCE_APPS_PAGE_LINK ? 306 RedirectToNtpOrAppsPage(contents, source);
295 chrome::kChromeUIAppsURL : chrome::kChromeUINewTabURL);
296 content::OpenURLParams params(url,
297 content::Referrer(),
298 CURRENT_TAB,
299 content::PAGE_TRANSITION_AUTO_TOPLEVEL,
300 false);
301 contents->OpenURL(params);
302 } 307 }
303 } 308 }
304 309
310 void RedirectToNtpOrAppsPage(content::WebContents* contents,
311 signin::Source source) {
312 VLOG(1) << "RedirectToNtpOrAppsPage";
313 GURL url(source == signin::SOURCE_APPS_PAGE_LINK ?
314 chrome::kChromeUIAppsURL : chrome::kChromeUINewTabURL);
315 content::OpenURLParams params(url,
316 content::Referrer(),
317 CURRENT_TAB,
318 content::PAGE_TRANSITION_AUTO_TOPLEVEL,
319 false);
320 contents->OpenURL(params);
321 }
Roger Tawa OOO till Jul 10th 2013/12/02 21:04:51 Should reuse function from OneClickSigninHelper, l
322
305 void CloseTab() { 323 void CloseTab() {
306 content::WebContents* tab = web_ui()->GetWebContents(); 324 content::WebContents* tab = web_ui()->GetWebContents();
307 Browser* browser = chrome::FindBrowserWithWebContents(tab); 325 Browser* browser = chrome::FindBrowserWithWebContents(tab);
308 if (browser) { 326 if (browser) {
309 TabStripModel* tab_strip_model = browser->tab_strip_model(); 327 TabStripModel* tab_strip_model = browser->tab_strip_model();
310 if (tab_strip_model) { 328 if (tab_strip_model) {
311 int index = tab_strip_model->GetIndexOfWebContents(tab); 329 int index = tab_strip_model->GetIndexOfWebContents(tab);
312 if (index != TabStripModel::kNoTab) { 330 if (index != TabStripModel::kNoTab) {
313 tab_strip_model->ExecuteContextMenuCommand( 331 tab_strip_model->ExecuteContextMenuCommand(
314 index, TabStripModel::CommandCloseTab); 332 index, TabStripModel::CommandCloseTab);
(...skipping 25 matching lines...) Expand all
340 content::WebUIDataSource::Add(profile, CreateWebUIDataSource()); 358 content::WebUIDataSource::Add(profile, CreateWebUIDataSource());
341 359
342 web_ui->AddMessageHandler(new InlineLoginUIHandler(profile)); 360 web_ui->AddMessageHandler(new InlineLoginUIHandler(profile));
343 // Required for intercepting extension function calls when the page is loaded 361 // Required for intercepting extension function calls when the page is loaded
344 // in a bubble (not a full tab, thus tab helpers are not registered 362 // in a bubble (not a full tab, thus tab helpers are not registered
345 // automatically). 363 // automatically).
346 extensions::TabHelper::CreateForWebContents(web_ui->GetWebContents()); 364 extensions::TabHelper::CreateForWebContents(web_ui->GetWebContents());
347 } 365 }
348 366
349 InlineLoginUI::~InlineLoginUI() {} 367 InlineLoginUI::~InlineLoginUI() {}
OLDNEW
« no previous file with comments | « chrome/browser/ui/sync/one_click_signin_helper.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698