OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/sync_setup_handler.h" | 5 #include "chrome/browser/ui/webui/sync_setup_handler.h" |
6 | 6 |
7 #include "base/json/json_reader.h" | 7 #include "base/json/json_reader.h" |
8 #include "base/json/json_writer.h" | 8 #include "base/json/json_writer.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 NewCallback(this, &SyncSetupHandler::HandleShowErrorUI)); | 294 NewCallback(this, &SyncSetupHandler::HandleShowErrorUI)); |
295 web_ui_->RegisterMessageCallback("SyncSetupShowSetupUI", | 295 web_ui_->RegisterMessageCallback("SyncSetupShowSetupUI", |
296 NewCallback(this, &SyncSetupHandler::HandleShowSetupUI)); | 296 NewCallback(this, &SyncSetupHandler::HandleShowSetupUI)); |
297 } | 297 } |
298 | 298 |
299 // Ideal(?) solution here would be to mimic the ClientLogin overlay. Since | 299 // Ideal(?) solution here would be to mimic the ClientLogin overlay. Since |
300 // this UI must render an external URL, that overlay cannot be used directly. | 300 // this UI must render an external URL, that overlay cannot be used directly. |
301 // The current implementation is functional, but fails asthetically. | 301 // The current implementation is functional, but fails asthetically. |
302 // TODO(rickcam): Bug 90711: Update UI for OAuth sign-in flow | 302 // TODO(rickcam): Bug 90711: Update UI for OAuth sign-in flow |
303 void SyncSetupHandler::ShowOAuthLogin() { | 303 void SyncSetupHandler::ShowOAuthLogin() { |
304 web_ui_->GetProfile()->GetProfileSyncService()->signin()->StartOAuthSignIn(); | 304 Profile* profile = |
| 305 Profile::FromBrowserContext(web_ui_->tab_contents()->browser_context()); |
| 306 profile->GetProfileSyncService()->signin()->StartOAuthSignIn(); |
305 } | 307 } |
306 | 308 |
307 void SyncSetupHandler::ShowGaiaLogin(const DictionaryValue& args) { | 309 void SyncSetupHandler::ShowGaiaLogin(const DictionaryValue& args) { |
308 StringValue page("login"); | 310 StringValue page("login"); |
309 web_ui_->CallJavascriptFunction( | 311 web_ui_->CallJavascriptFunction( |
310 "SyncSetupOverlay.showSyncSetupPage", page, args); | 312 "SyncSetupOverlay.showSyncSetupPage", page, args); |
311 } | 313 } |
312 | 314 |
313 void SyncSetupHandler::ShowGaiaSuccessAndClose() { | 315 void SyncSetupHandler::ShowGaiaSuccessAndClose() { |
314 web_ui_->CallJavascriptFunction("SyncSetupOverlay.showSuccessAndClose"); | 316 web_ui_->CallJavascriptFunction("SyncSetupOverlay.showSuccessAndClose"); |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
425 flow_->OnPassphraseCancel(); | 427 flow_->OnPassphraseCancel(); |
426 } | 428 } |
427 | 429 |
428 void SyncSetupHandler::HandleAttachHandler(const ListValue* args) { | 430 void SyncSetupHandler::HandleAttachHandler(const ListValue* args) { |
429 OpenSyncSetup(); | 431 OpenSyncSetup(); |
430 } | 432 } |
431 | 433 |
432 void SyncSetupHandler::HandleShowErrorUI(const ListValue* args) { | 434 void SyncSetupHandler::HandleShowErrorUI(const ListValue* args) { |
433 DCHECK(!flow_); | 435 DCHECK(!flow_); |
434 | 436 |
435 ProfileSyncService* service = | 437 Profile* profile = |
436 web_ui_->GetProfile()->GetProfileSyncService(); | 438 Profile::FromBrowserContext(web_ui_->tab_contents()->browser_context()); |
| 439 ProfileSyncService* service = profile->GetProfileSyncService(); |
437 DCHECK(service); | 440 DCHECK(service); |
438 | 441 |
439 service->get_wizard().Step(SyncSetupWizard::NONFATAL_ERROR); | 442 service->get_wizard().Step(SyncSetupWizard::NONFATAL_ERROR); |
440 | 443 |
441 // Show the Sync Setup page. | 444 // Show the Sync Setup page. |
442 if (service->get_wizard().IsVisible()) { | 445 if (service->get_wizard().IsVisible()) { |
443 service->get_wizard().Focus(); | 446 service->get_wizard().Focus(); |
444 } else { | 447 } else { |
445 StringValue page("syncSetup"); | 448 StringValue page("syncSetup"); |
446 web_ui_->CallJavascriptFunction("OptionsPage.navigateToPage", page); | 449 web_ui_->CallJavascriptFunction("OptionsPage.navigateToPage", page); |
447 } | 450 } |
448 } | 451 } |
449 | 452 |
450 void SyncSetupHandler::HandleShowSetupUI(const ListValue* args) { | 453 void SyncSetupHandler::HandleShowSetupUI(const ListValue* args) { |
451 DCHECK(!flow_); | 454 DCHECK(!flow_); |
452 ShowSetupUI(); | 455 ShowSetupUI(); |
453 } | 456 } |
454 | 457 |
455 void SyncSetupHandler::CloseSyncSetup() { | 458 void SyncSetupHandler::CloseSyncSetup() { |
456 if (flow_) { | 459 if (flow_) { |
457 flow_->OnDialogClosed(std::string()); | 460 flow_->OnDialogClosed(std::string()); |
458 flow_ = NULL; | 461 flow_ = NULL; |
459 } | 462 } |
460 } | 463 } |
461 | 464 |
462 void SyncSetupHandler::OpenSyncSetup() { | 465 void SyncSetupHandler::OpenSyncSetup() { |
463 DCHECK(web_ui_); | 466 DCHECK(web_ui_); |
464 DCHECK(!flow_); | 467 DCHECK(!flow_); |
465 | 468 |
466 ProfileSyncService* service = web_ui_->GetProfile()->GetProfileSyncService(); | 469 Profile* profile = |
| 470 Profile::FromBrowserContext(web_ui_->tab_contents()->browser_context()); |
| 471 ProfileSyncService* service = profile->GetProfileSyncService(); |
467 if (!service) { | 472 if (!service) { |
468 // If there's no sync service, the user tried to manually invoke a syncSetup | 473 // If there's no sync service, the user tried to manually invoke a syncSetup |
469 // URL, but sync features are disabled. We need to close the overlay for | 474 // URL, but sync features are disabled. We need to close the overlay for |
470 // this (rare) case. | 475 // this (rare) case. |
471 web_ui_->CallJavascriptFunction("OptionsPage.closeOverlay"); | 476 web_ui_->CallJavascriptFunction("OptionsPage.closeOverlay"); |
472 return; | 477 return; |
473 } | 478 } |
474 | 479 |
475 // If the wizard is not visible, step into the appropriate UI state. | 480 // If the wizard is not visible, step into the appropriate UI state. |
476 if (!service->get_wizard().IsVisible()) | 481 if (!service->get_wizard().IsVisible()) |
477 ShowSetupUI(); | 482 ShowSetupUI(); |
478 | 483 |
479 // The SyncSetupFlow will set itself as the |flow_|. | 484 // The SyncSetupFlow will set itself as the |flow_|. |
480 if (!service->get_wizard().AttachSyncSetupHandler(this)) { | 485 if (!service->get_wizard().AttachSyncSetupHandler(this)) { |
481 // If attach fails, a wizard is already activated and attached to a flow | 486 // If attach fails, a wizard is already activated and attached to a flow |
482 // handler. | 487 // handler. |
483 web_ui_->CallJavascriptFunction("OptionsPage.closeOverlay"); | 488 web_ui_->CallJavascriptFunction("OptionsPage.closeOverlay"); |
484 service->get_wizard().Focus(); | 489 service->get_wizard().Focus(); |
485 } | 490 } |
486 } | 491 } |
OLD | NEW |