| 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/options/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/values.h" | 9 #include "base/values.h" |
| 10 #include "chrome/browser/google/google_util.h" | 10 #include "chrome/browser/google/google_util.h" |
| 11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 12 #include "chrome/browser/sync/profile_sync_service.h" | 12 #include "chrome/browser/sync/profile_sync_service.h" |
| 13 #include "chrome/browser/sync/sync_setup_flow.h" | 13 #include "chrome/browser/sync/sync_setup_flow.h" |
| 14 #include "chrome/common/url_constants.h" | 14 #include "chrome/common/url_constants.h" |
| 15 #include "content/browser/tab_contents/tab_contents.h" | 15 #include "content/browser/tab_contents/tab_contents.h" |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 SyncSetupHandler::SyncSetupHandler() : flow_(NULL) { | 150 SyncSetupHandler::SyncSetupHandler() : flow_(NULL) { |
| 151 } | 151 } |
| 152 | 152 |
| 153 SyncSetupHandler::~SyncSetupHandler() { | 153 SyncSetupHandler::~SyncSetupHandler() { |
| 154 // This case is hit when the user performs a back navigation. | 154 // This case is hit when the user performs a back navigation. |
| 155 if (flow_) | 155 if (flow_) |
| 156 flow_->OnDialogClosed(""); | 156 flow_->OnDialogClosed(""); |
| 157 } | 157 } |
| 158 | 158 |
| 159 void SyncSetupHandler::GetLocalizedValues(DictionaryValue* localized_strings) { | 159 void SyncSetupHandler::GetLocalizedValues(DictionaryValue* localized_strings) { |
| 160 GetStaticLocalizedValues(localized_strings); |
| 161 } |
| 162 |
| 163 void SyncSetupHandler::GetStaticLocalizedValues( |
| 164 DictionaryValue* localized_strings) { |
| 160 DCHECK(localized_strings); | 165 DCHECK(localized_strings); |
| 161 | 166 |
| 162 localized_strings->SetString( | 167 localized_strings->SetString( |
| 163 "invalidPasswordHelpURL", | 168 "invalidPasswordHelpURL", |
| 164 google_util::StringAppendGoogleLocaleParam(kInvalidPasswordHelpUrl)); | 169 google_util::StringAppendGoogleLocaleParam(kInvalidPasswordHelpUrl)); |
| 165 localized_strings->SetString( | 170 localized_strings->SetString( |
| 166 "cannotAccessAccountURL", | 171 "cannotAccessAccountURL", |
| 167 google_util::StringAppendGoogleLocaleParam(kCanNotAccessAccountUrl)); | 172 google_util::StringAppendGoogleLocaleParam(kCanNotAccessAccountUrl)); |
| 168 localized_strings->SetString( | 173 localized_strings->SetString( |
| 169 "createNewAccountURL", | 174 "createNewAccountURL", |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 { "cancelWarningHeader", IDS_SYNC_PASSPHRASE_CANCEL_WARNING_HEADER }, | 257 { "cancelWarningHeader", IDS_SYNC_PASSPHRASE_CANCEL_WARNING_HEADER }, |
| 253 { "cancelWarning", IDS_SYNC_PASSPHRASE_CANCEL_WARNING }, | 258 { "cancelWarning", IDS_SYNC_PASSPHRASE_CANCEL_WARNING }, |
| 254 { "yes", IDS_SYNC_PASSPHRASE_CANCEL_YES }, | 259 { "yes", IDS_SYNC_PASSPHRASE_CANCEL_YES }, |
| 255 { "no", IDS_SYNC_PASSPHRASE_CANCEL_NO }, | 260 { "no", IDS_SYNC_PASSPHRASE_CANCEL_NO }, |
| 256 { "sectionExplicitMessagePrefix", IDS_SYNC_PASSPHRASE_MSG_EXPLICIT_PREFIX }, | 261 { "sectionExplicitMessagePrefix", IDS_SYNC_PASSPHRASE_MSG_EXPLICIT_PREFIX }, |
| 257 { "sectionExplicitMessagePostfix", | 262 { "sectionExplicitMessagePostfix", |
| 258 IDS_SYNC_PASSPHRASE_MSG_EXPLICIT_POSTFIX }, | 263 IDS_SYNC_PASSPHRASE_MSG_EXPLICIT_POSTFIX }, |
| 259 { "encryptedDataTypesTitle", IDS_SYNC_ENCRYPTION_DATA_TYPES_TITLE }, | 264 { "encryptedDataTypesTitle", IDS_SYNC_ENCRYPTION_DATA_TYPES_TITLE }, |
| 260 { "encryptSensitiveOption", IDS_SYNC_ENCRYPT_SENSITIVE_DATA }, | 265 { "encryptSensitiveOption", IDS_SYNC_ENCRYPT_SENSITIVE_DATA }, |
| 261 { "encryptAllOption", IDS_SYNC_ENCRYPT_ALL_DATA }, | 266 { "encryptAllOption", IDS_SYNC_ENCRYPT_ALL_DATA }, |
| 267 { "encryptAllOption", IDS_SYNC_ENCRYPT_ALL_DATA }, |
| 268 { "statusNotConnected", IDS_SYNC_STATUS_NOT_CONNECTED } |
| 262 }; | 269 }; |
| 263 | 270 |
| 264 RegisterStrings(localized_strings, resources, arraysize(resources)); | 271 RegisterStrings(localized_strings, resources, arraysize(resources)); |
| 265 } | 272 } |
| 266 | 273 |
| 267 void SyncSetupHandler::Initialize() { | 274 void SyncSetupHandler::Initialize() { |
| 268 } | 275 } |
| 269 | 276 |
| 270 void SyncSetupHandler::RegisterMessages() { | 277 void SyncSetupHandler::RegisterMessages() { |
| 271 web_ui_->RegisterMessageCallback("SyncSetupDidClosePage", | 278 web_ui_->RegisterMessageCallback("SyncSetupDidClosePage", |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 326 | 333 |
| 327 void SyncSetupHandler::SetFlow(SyncSetupFlow* flow) { | 334 void SyncSetupHandler::SetFlow(SyncSetupFlow* flow) { |
| 328 flow_ = flow; | 335 flow_ = flow; |
| 329 } | 336 } |
| 330 | 337 |
| 331 void SyncSetupHandler::Focus() { | 338 void SyncSetupHandler::Focus() { |
| 332 static_cast<RenderViewHostDelegate*>(web_ui_->tab_contents())->Activate(); | 339 static_cast<RenderViewHostDelegate*>(web_ui_->tab_contents())->Activate(); |
| 333 } | 340 } |
| 334 | 341 |
| 335 void SyncSetupHandler::OnDidClosePage(const ListValue* args) { | 342 void SyncSetupHandler::OnDidClosePage(const ListValue* args) { |
| 336 if (flow_) { | 343 CloseSyncSetup(); |
| 337 flow_->OnDialogClosed(std::string()); | |
| 338 flow_ = NULL; | |
| 339 } | |
| 340 } | 344 } |
| 341 | 345 |
| 342 void SyncSetupHandler::HandleSubmitAuth(const ListValue* args) { | 346 void SyncSetupHandler::HandleSubmitAuth(const ListValue* args) { |
| 343 std::string json; | 347 std::string json; |
| 344 if (!args->GetString(0, &json)) { | 348 if (!args->GetString(0, &json)) { |
| 345 NOTREACHED() << "Could not read JSON argument"; | 349 NOTREACHED() << "Could not read JSON argument"; |
| 346 return; | 350 return; |
| 347 } | 351 } |
| 348 | 352 |
| 349 if (json.empty()) | 353 if (json.empty()) |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 404 DCHECK(flow_); | 408 DCHECK(flow_); |
| 405 flow_->OnPassphraseEntry(passphrase); | 409 flow_->OnPassphraseEntry(passphrase); |
| 406 } | 410 } |
| 407 | 411 |
| 408 void SyncSetupHandler::HandlePassphraseCancel(const ListValue* args) { | 412 void SyncSetupHandler::HandlePassphraseCancel(const ListValue* args) { |
| 409 DCHECK(flow_); | 413 DCHECK(flow_); |
| 410 flow_->OnPassphraseCancel(); | 414 flow_->OnPassphraseCancel(); |
| 411 } | 415 } |
| 412 | 416 |
| 413 void SyncSetupHandler::HandleAttachHandler(const ListValue* args) { | 417 void SyncSetupHandler::HandleAttachHandler(const ListValue* args) { |
| 414 DCHECK(web_ui_); | 418 OpenSyncSetup(); |
| 415 DCHECK(!flow_); | |
| 416 | |
| 417 ProfileSyncService* service = web_ui_->GetProfile()->GetProfileSyncService(); | |
| 418 if (!service) { | |
| 419 // If there's no sync service, the user tried to manually invoke a syncSetup | |
| 420 // URL, but sync features are disabled. We need to close the overlay for | |
| 421 // this (rare) case. | |
| 422 web_ui_->CallJavascriptFunction("OptionsPage.closeOverlay"); | |
| 423 return; | |
| 424 } | |
| 425 | |
| 426 // If the wizard is not visible, step into the appropriate UI state. | |
| 427 if (!service->get_wizard().IsVisible()) | |
| 428 HandleShowSetupUI(NULL); | |
| 429 | |
| 430 // The SyncSetupFlow will set itself as the |flow_|. | |
| 431 if (!service->get_wizard().AttachSyncSetupHandler(this)) { | |
| 432 // If attach fails, a wizard is already activated and attached to a flow | |
| 433 // handler. | |
| 434 web_ui_->CallJavascriptFunction("OptionsPage.closeOverlay"); | |
| 435 service->get_wizard().Focus(); | |
| 436 } | |
| 437 } | 419 } |
| 438 | 420 |
| 439 void SyncSetupHandler::HandleShowErrorUI(const ListValue* args) { | 421 void SyncSetupHandler::HandleShowErrorUI(const ListValue* args) { |
| 440 DCHECK(!flow_); | 422 DCHECK(!flow_); |
| 441 | 423 |
| 442 ProfileSyncService* service = | 424 ProfileSyncService* service = |
| 443 web_ui_->GetProfile()->GetProfileSyncService(); | 425 web_ui_->GetProfile()->GetProfileSyncService(); |
| 444 DCHECK(service); | 426 DCHECK(service); |
| 445 | 427 |
| 446 service->get_wizard().Step(SyncSetupWizard::NONFATAL_ERROR); | 428 service->get_wizard().Step(SyncSetupWizard::NONFATAL_ERROR); |
| 447 | 429 |
| 448 // The SyncSetupFlow will set itself as the |flow_|. | 430 // The SyncSetupFlow will set itself as the |flow_|. |
| 449 if (!service->get_wizard().AttachSyncSetupHandler(this)) { | 431 if (!service->get_wizard().AttachSyncSetupHandler(this)) { |
| 450 web_ui_->CallJavascriptFunction("OptionsPage.closeOverlay"); | 432 web_ui_->CallJavascriptFunction("OptionsPage.closeOverlay"); |
| 451 service->get_wizard().Focus(); | 433 service->get_wizard().Focus(); |
| 452 } | 434 } |
| 453 } | 435 } |
| 454 | 436 |
| 455 void SyncSetupHandler::HandleShowSetupUI(const ListValue* args) { | 437 void SyncSetupHandler::HandleShowSetupUI(const ListValue* args) { |
| 456 DCHECK(!flow_); | 438 DCHECK(!flow_); |
| 439 ShowSetupUI(); |
| 440 } |
| 457 | 441 |
| 458 ProfileSyncService* service = | 442 void SyncSetupHandler::CloseSyncSetup() { |
| 459 web_ui_->GetProfile()->GetProfileSyncService(); | 443 if (flow_) { |
| 460 DCHECK(service); | 444 flow_->OnDialogClosed(std::string()); |
| 445 flow_ = NULL; |
| 446 } |
| 447 } |
| 461 | 448 |
| 462 // If the wizard is already visible, focus it. | 449 void SyncSetupHandler::OpenSyncSetup() { |
| 463 if (service->get_wizard().IsVisible()) { | 450 DCHECK(web_ui_); |
| 451 DCHECK(!flow_); |
| 452 |
| 453 ProfileSyncService* service = web_ui_->GetProfile()->GetProfileSyncService(); |
| 454 if (!service) { |
| 455 // If there's no sync service, the user tried to manually invoke a syncSetup |
| 456 // URL, but sync features are disabled. We need to close the overlay for |
| 457 // this (rare) case. |
| 464 web_ui_->CallJavascriptFunction("OptionsPage.closeOverlay"); | 458 web_ui_->CallJavascriptFunction("OptionsPage.closeOverlay"); |
| 465 service->get_wizard().Focus(); | |
| 466 return; | 459 return; |
| 467 } | 460 } |
| 468 | 461 |
| 469 // The user is trying to manually load a syncSetup URL. We should bring up | 462 // If the wizard is not visible, step into the appropriate UI state. |
| 470 // either a login or a configure flow based on the state of sync. | 463 if (!service->get_wizard().IsVisible()) |
| 471 if (service->HasSyncSetupCompleted()) | 464 ShowSetupUI(); |
| 472 service->get_wizard().Step(SyncSetupWizard::CONFIGURE); | |
| 473 else | |
| 474 service->get_wizard().Step(SyncSetupWizard::GAIA_LOGIN); | |
| 475 | 465 |
| 476 // Show the Sync Setup page. | 466 // The SyncSetupFlow will set itself as the |flow_|. |
| 477 scoped_ptr<Value> page(Value::CreateStringValue("syncSetup")); | 467 if (!service->get_wizard().AttachSyncSetupHandler(this)) { |
| 478 web_ui_->CallJavascriptFunction("OptionsPage.navigateToPage", *page); | 468 // If attach fails, a wizard is already activated and attached to a flow |
| 469 // handler. |
| 470 web_ui_->CallJavascriptFunction("OptionsPage.closeOverlay"); |
| 471 service->get_wizard().Focus(); |
| 472 } |
| 479 } | 473 } |
| OLD | NEW |