| 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/values.h" | 9 #include "base/values.h" |
| 10 #include "chrome/browser/google/google_util.h" | 10 #include "chrome/browser/google/google_util.h" |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 { "cancelWarningHeader", IDS_SYNC_PASSPHRASE_CANCEL_WARNING_HEADER }, | 257 { "cancelWarningHeader", IDS_SYNC_PASSPHRASE_CANCEL_WARNING_HEADER }, |
| 258 { "cancelWarning", IDS_SYNC_PASSPHRASE_CANCEL_WARNING }, | 258 { "cancelWarning", IDS_SYNC_PASSPHRASE_CANCEL_WARNING }, |
| 259 { "yes", IDS_SYNC_PASSPHRASE_CANCEL_YES }, | 259 { "yes", IDS_SYNC_PASSPHRASE_CANCEL_YES }, |
| 260 { "no", IDS_SYNC_PASSPHRASE_CANCEL_NO }, | 260 { "no", IDS_SYNC_PASSPHRASE_CANCEL_NO }, |
| 261 { "sectionExplicitMessagePrefix", IDS_SYNC_PASSPHRASE_MSG_EXPLICIT_PREFIX }, | 261 { "sectionExplicitMessagePrefix", IDS_SYNC_PASSPHRASE_MSG_EXPLICIT_PREFIX }, |
| 262 { "sectionExplicitMessagePostfix", | 262 { "sectionExplicitMessagePostfix", |
| 263 IDS_SYNC_PASSPHRASE_MSG_EXPLICIT_POSTFIX }, | 263 IDS_SYNC_PASSPHRASE_MSG_EXPLICIT_POSTFIX }, |
| 264 { "encryptedDataTypesTitle", IDS_SYNC_ENCRYPTION_DATA_TYPES_TITLE }, | 264 { "encryptedDataTypesTitle", IDS_SYNC_ENCRYPTION_DATA_TYPES_TITLE }, |
| 265 { "encryptSensitiveOption", IDS_SYNC_ENCRYPT_SENSITIVE_DATA }, | 265 { "encryptSensitiveOption", IDS_SYNC_ENCRYPT_SENSITIVE_DATA }, |
| 266 { "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 } |
| 267 }; | 269 }; |
| 268 | 270 |
| 269 RegisterStrings(localized_strings, resources, arraysize(resources)); | 271 RegisterStrings(localized_strings, resources, arraysize(resources)); |
| 270 } | 272 } |
| 271 | 273 |
| 272 void SyncSetupHandler::Initialize() { | 274 void SyncSetupHandler::Initialize() { |
| 273 } | 275 } |
| 274 | 276 |
| 275 void SyncSetupHandler::RegisterMessages() { | 277 void SyncSetupHandler::RegisterMessages() { |
| 276 web_ui_->RegisterMessageCallback("SyncSetupDidClosePage", | 278 web_ui_->RegisterMessageCallback("SyncSetupDidClosePage", |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 331 | 333 |
| 332 void SyncSetupHandler::SetFlow(SyncSetupFlow* flow) { | 334 void SyncSetupHandler::SetFlow(SyncSetupFlow* flow) { |
| 333 flow_ = flow; | 335 flow_ = flow; |
| 334 } | 336 } |
| 335 | 337 |
| 336 void SyncSetupHandler::Focus() { | 338 void SyncSetupHandler::Focus() { |
| 337 static_cast<RenderViewHostDelegate*>(web_ui_->tab_contents())->Activate(); | 339 static_cast<RenderViewHostDelegate*>(web_ui_->tab_contents())->Activate(); |
| 338 } | 340 } |
| 339 | 341 |
| 340 void SyncSetupHandler::OnDidClosePage(const ListValue* args) { | 342 void SyncSetupHandler::OnDidClosePage(const ListValue* args) { |
| 341 if (flow_) { | 343 CloseSyncSetup(); |
| 342 flow_->OnDialogClosed(std::string()); | |
| 343 flow_ = NULL; | |
| 344 } | |
| 345 } | 344 } |
| 346 | 345 |
| 347 void SyncSetupHandler::HandleSubmitAuth(const ListValue* args) { | 346 void SyncSetupHandler::HandleSubmitAuth(const ListValue* args) { |
| 348 std::string json; | 347 std::string json; |
| 349 if (!args->GetString(0, &json)) { | 348 if (!args->GetString(0, &json)) { |
| 350 NOTREACHED() << "Could not read JSON argument"; | 349 NOTREACHED() << "Could not read JSON argument"; |
| 351 return; | 350 return; |
| 352 } | 351 } |
| 353 | 352 |
| 354 if (json.empty()) | 353 if (json.empty()) |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 409 DCHECK(flow_); | 408 DCHECK(flow_); |
| 410 flow_->OnPassphraseEntry(passphrase); | 409 flow_->OnPassphraseEntry(passphrase); |
| 411 } | 410 } |
| 412 | 411 |
| 413 void SyncSetupHandler::HandlePassphraseCancel(const ListValue* args) { | 412 void SyncSetupHandler::HandlePassphraseCancel(const ListValue* args) { |
| 414 DCHECK(flow_); | 413 DCHECK(flow_); |
| 415 flow_->OnPassphraseCancel(); | 414 flow_->OnPassphraseCancel(); |
| 416 } | 415 } |
| 417 | 416 |
| 418 void SyncSetupHandler::HandleAttachHandler(const ListValue* args) { | 417 void SyncSetupHandler::HandleAttachHandler(const ListValue* args) { |
| 418 OpenSyncSetup(); |
| 419 } |
| 420 |
| 421 void SyncSetupHandler::HandleShowErrorUI(const ListValue* args) { |
| 422 DCHECK(!flow_); |
| 423 |
| 424 ProfileSyncService* service = |
| 425 web_ui_->GetProfile()->GetProfileSyncService(); |
| 426 DCHECK(service); |
| 427 |
| 428 service->get_wizard().Step(SyncSetupWizard::NONFATAL_ERROR); |
| 429 |
| 430 // The SyncSetupFlow will set itself as the |flow_|. |
| 431 if (!service->get_wizard().AttachSyncSetupHandler(this)) { |
| 432 web_ui_->CallJavascriptFunction("OptionsPage.closeOverlay"); |
| 433 service->get_wizard().Focus(); |
| 434 } |
| 435 } |
| 436 |
| 437 void SyncSetupHandler::HandleShowSetupUI(const ListValue* args) { |
| 438 DCHECK(!flow_); |
| 439 ShowSetupUI(); |
| 440 } |
| 441 |
| 442 void SyncSetupHandler::CloseSyncSetup() { |
| 443 if (flow_) { |
| 444 flow_->OnDialogClosed(std::string()); |
| 445 flow_ = NULL; |
| 446 } |
| 447 } |
| 448 |
| 449 void SyncSetupHandler::OpenSyncSetup() { |
| 419 DCHECK(web_ui_); | 450 DCHECK(web_ui_); |
| 420 DCHECK(!flow_); | 451 DCHECK(!flow_); |
| 421 | 452 |
| 422 ProfileSyncService* service = web_ui_->GetProfile()->GetProfileSyncService(); | 453 ProfileSyncService* service = web_ui_->GetProfile()->GetProfileSyncService(); |
| 423 if (!service) { | 454 if (!service) { |
| 424 // If there's no sync service, the user tried to manually invoke a syncSetup | 455 // If there's no sync service, the user tried to manually invoke a syncSetup |
| 425 // URL, but sync features are disabled. We need to close the overlay for | 456 // URL, but sync features are disabled. We need to close the overlay for |
| 426 // this (rare) case. | 457 // this (rare) case. |
| 427 web_ui_->CallJavascriptFunction("OptionsPage.closeOverlay"); | 458 web_ui_->CallJavascriptFunction("OptionsPage.closeOverlay"); |
| 428 return; | 459 return; |
| 429 } | 460 } |
| 430 | 461 |
| 431 // If the wizard is not visible, step into the appropriate UI state. | 462 // If the wizard is not visible, step into the appropriate UI state. |
| 432 if (!service->get_wizard().IsVisible()) | 463 if (!service->get_wizard().IsVisible()) |
| 433 ShowSetupUI(); | 464 ShowSetupUI(); |
| 434 | 465 |
| 435 // The SyncSetupFlow will set itself as the |flow_|. | 466 // The SyncSetupFlow will set itself as the |flow_|. |
| 436 if (!service->get_wizard().AttachSyncSetupHandler(this)) { | 467 if (!service->get_wizard().AttachSyncSetupHandler(this)) { |
| 437 // If attach fails, a wizard is already activated and attached to a flow | 468 // If attach fails, a wizard is already activated and attached to a flow |
| 438 // handler. | 469 // handler. |
| 439 web_ui_->CallJavascriptFunction("OptionsPage.closeOverlay"); | 470 web_ui_->CallJavascriptFunction("OptionsPage.closeOverlay"); |
| 440 service->get_wizard().Focus(); | 471 service->get_wizard().Focus(); |
| 441 } | 472 } |
| 442 } | 473 } |
| 443 | |
| 444 void SyncSetupHandler::HandleShowErrorUI(const ListValue* args) { | |
| 445 DCHECK(!flow_); | |
| 446 | |
| 447 ProfileSyncService* service = | |
| 448 web_ui_->GetProfile()->GetProfileSyncService(); | |
| 449 DCHECK(service); | |
| 450 | |
| 451 service->get_wizard().Step(SyncSetupWizard::NONFATAL_ERROR); | |
| 452 | |
| 453 // The SyncSetupFlow will set itself as the |flow_|. | |
| 454 if (!service->get_wizard().AttachSyncSetupHandler(this)) { | |
| 455 web_ui_->CallJavascriptFunction("OptionsPage.closeOverlay"); | |
| 456 service->get_wizard().Focus(); | |
| 457 } | |
| 458 } | |
| 459 | |
| 460 void SyncSetupHandler::HandleShowSetupUI(const ListValue* args) { | |
| 461 DCHECK(!flow_); | |
| 462 ShowSetupUI(); | |
| 463 } | |
| OLD | NEW |