| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/sync/sync_setup_flow.h" | 5 #include "chrome/browser/sync/sync_setup_flow.h" |
| 6 | 6 |
| 7 #include "app/gfx/font_util.h" | 7 #include "app/gfx/font_util.h" |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/histogram.h" | 9 #include "base/histogram.h" |
| 10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 NewCallback(this, &FlowHandler::HandleChooseDataTypes)); | 43 NewCallback(this, &FlowHandler::HandleChooseDataTypes)); |
| 44 } | 44 } |
| 45 | 45 |
| 46 static bool GetAuthData(const std::string& json, | 46 static bool GetAuthData(const std::string& json, |
| 47 std::string* username, std::string* password, std::string* captcha) { | 47 std::string* username, std::string* password, std::string* captcha) { |
| 48 scoped_ptr<Value> parsed_value(base::JSONReader::Read(json, false)); | 48 scoped_ptr<Value> parsed_value(base::JSONReader::Read(json, false)); |
| 49 if (!parsed_value.get() || !parsed_value->IsType(Value::TYPE_DICTIONARY)) | 49 if (!parsed_value.get() || !parsed_value->IsType(Value::TYPE_DICTIONARY)) |
| 50 return false; | 50 return false; |
| 51 | 51 |
| 52 DictionaryValue* result = static_cast<DictionaryValue*>(parsed_value.get()); | 52 DictionaryValue* result = static_cast<DictionaryValue*>(parsed_value.get()); |
| 53 if (!result->GetString(L"user", username) || | 53 if (!result->GetString("user", username) || |
| 54 !result->GetString(L"pass", password) || | 54 !result->GetString("pass", password) || |
| 55 !result->GetString(L"captcha", captcha)) { | 55 !result->GetString("captcha", captcha)) { |
| 56 return false; | 56 return false; |
| 57 } | 57 } |
| 58 return true; | 58 return true; |
| 59 } | 59 } |
| 60 | 60 |
| 61 static bool GetDataTypeChoiceData(const std::string& json, | 61 static bool GetDataTypeChoiceData(const std::string& json, |
| 62 bool* sync_everything, syncable::ModelTypeSet* data_types) { | 62 bool* sync_everything, syncable::ModelTypeSet* data_types) { |
| 63 scoped_ptr<Value> parsed_value(base::JSONReader::Read(json, false)); | 63 scoped_ptr<Value> parsed_value(base::JSONReader::Read(json, false)); |
| 64 if (!parsed_value.get() || !parsed_value->IsType(Value::TYPE_DICTIONARY)) | 64 if (!parsed_value.get() || !parsed_value->IsType(Value::TYPE_DICTIONARY)) |
| 65 return false; | 65 return false; |
| 66 | 66 |
| 67 DictionaryValue* result = static_cast<DictionaryValue*>(parsed_value.get()); | 67 DictionaryValue* result = static_cast<DictionaryValue*>(parsed_value.get()); |
| 68 if (!result->GetBoolean(L"keepEverythingSynced", sync_everything)) | 68 if (!result->GetBoolean("keepEverythingSynced", sync_everything)) |
| 69 return false; | 69 return false; |
| 70 | 70 |
| 71 // These values need to be kept in sync with where they are written in | 71 // These values need to be kept in sync with where they are written in |
| 72 // choose_datatypes.html. | 72 // choose_datatypes.html. |
| 73 bool sync_bookmarks; | 73 bool sync_bookmarks; |
| 74 if (!result->GetBoolean(L"syncBookmarks", &sync_bookmarks)) | 74 if (!result->GetBoolean("syncBookmarks", &sync_bookmarks)) |
| 75 return false; | 75 return false; |
| 76 if (sync_bookmarks) | 76 if (sync_bookmarks) |
| 77 data_types->insert(syncable::BOOKMARKS); | 77 data_types->insert(syncable::BOOKMARKS); |
| 78 | 78 |
| 79 bool sync_preferences; | 79 bool sync_preferences; |
| 80 if (!result->GetBoolean(L"syncPreferences", &sync_preferences)) | 80 if (!result->GetBoolean("syncPreferences", &sync_preferences)) |
| 81 return false; | 81 return false; |
| 82 if (sync_preferences) | 82 if (sync_preferences) |
| 83 data_types->insert(syncable::PREFERENCES); | 83 data_types->insert(syncable::PREFERENCES); |
| 84 | 84 |
| 85 bool sync_themes; | 85 bool sync_themes; |
| 86 if (!result->GetBoolean(L"syncThemes", &sync_themes)) | 86 if (!result->GetBoolean("syncThemes", &sync_themes)) |
| 87 return false; | 87 return false; |
| 88 if (sync_themes) | 88 if (sync_themes) |
| 89 data_types->insert(syncable::THEMES); | 89 data_types->insert(syncable::THEMES); |
| 90 | 90 |
| 91 bool sync_passwords; | 91 bool sync_passwords; |
| 92 if (!result->GetBoolean(L"syncPasswords", &sync_passwords)) | 92 if (!result->GetBoolean("syncPasswords", &sync_passwords)) |
| 93 return false; | 93 return false; |
| 94 if (sync_passwords) | 94 if (sync_passwords) |
| 95 data_types->insert(syncable::PASSWORDS); | 95 data_types->insert(syncable::PASSWORDS); |
| 96 | 96 |
| 97 bool sync_autofill; | 97 bool sync_autofill; |
| 98 if (!result->GetBoolean(L"syncAutofill", &sync_autofill)) | 98 if (!result->GetBoolean("syncAutofill", &sync_autofill)) |
| 99 return false; | 99 return false; |
| 100 if (sync_autofill) | 100 if (sync_autofill) |
| 101 data_types->insert(syncable::AUTOFILL); | 101 data_types->insert(syncable::AUTOFILL); |
| 102 | 102 |
| 103 bool sync_extensions; | 103 bool sync_extensions; |
| 104 if (!result->GetBoolean(L"syncExtensions", &sync_extensions)) | 104 if (!result->GetBoolean("syncExtensions", &sync_extensions)) |
| 105 return false; | 105 return false; |
| 106 if (sync_extensions) | 106 if (sync_extensions) |
| 107 data_types->insert(syncable::EXTENSIONS); | 107 data_types->insert(syncable::EXTENSIONS); |
| 108 | 108 |
| 109 bool sync_typed_urls; | 109 bool sync_typed_urls; |
| 110 if (!result->GetBoolean(L"syncTypedUrls", &sync_typed_urls)) | 110 if (!result->GetBoolean("syncTypedUrls", &sync_typed_urls)) |
| 111 return false; | 111 return false; |
| 112 if (sync_typed_urls) | 112 if (sync_typed_urls) |
| 113 data_types->insert(syncable::TYPED_URLS); | 113 data_types->insert(syncable::TYPED_URLS); |
| 114 | 114 |
| 115 return true; | 115 return true; |
| 116 } | 116 } |
| 117 | 117 |
| 118 void FlowHandler::HandleSubmitAuth(const Value* value) { | 118 void FlowHandler::HandleSubmitAuth(const Value* value) { |
| 119 std::string json(dom_ui_util::GetJsonResponseFromFirstArgumentInList(value)); | 119 std::string json(dom_ui_util::GetJsonResponseFromFirstArgumentInList(value)); |
| 120 std::string username, password, captcha; | 120 std::string username, password, captcha; |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 break; | 311 break; |
| 312 } | 312 } |
| 313 | 313 |
| 314 service_->OnUserCancelledDialog(); | 314 service_->OnUserCancelledDialog(); |
| 315 delete this; | 315 delete this; |
| 316 } | 316 } |
| 317 | 317 |
| 318 // static | 318 // static |
| 319 void SyncSetupFlow::GetArgsForGaiaLogin(const ProfileSyncService* service, | 319 void SyncSetupFlow::GetArgsForGaiaLogin(const ProfileSyncService* service, |
| 320 DictionaryValue* args) { | 320 DictionaryValue* args) { |
| 321 args->SetString(L"iframeToShow", "login"); | 321 args->SetString("iframeToShow", "login"); |
| 322 const GoogleServiceAuthError& error = service->GetAuthError(); | 322 const GoogleServiceAuthError& error = service->GetAuthError(); |
| 323 if (!service->last_attempted_user_email().empty()) { | 323 if (!service->last_attempted_user_email().empty()) { |
| 324 args->SetString(L"user", service->last_attempted_user_email()); | 324 args->SetString("user", service->last_attempted_user_email()); |
| 325 args->SetInteger(L"error", error.state()); | 325 args->SetInteger("error", error.state()); |
| 326 args->SetBoolean(L"editable_user", true); | 326 args->SetBoolean("editable_user", true); |
| 327 } else { | 327 } else { |
| 328 std::wstring user(UTF16ToWide(service->GetAuthenticatedUsername())); | 328 string16 user(service->GetAuthenticatedUsername()); |
| 329 args->SetString(L"user", user); | 329 args->SetString("user", user); |
| 330 args->SetInteger(L"error", 0); | 330 args->SetInteger("error", 0); |
| 331 args->SetBoolean(L"editable_user", user.empty()); | 331 args->SetBoolean("editable_user", user.empty()); |
| 332 } | 332 } |
| 333 | 333 |
| 334 args->SetString(L"captchaUrl", error.captcha().image_url.spec()); | 334 args->SetString("captchaUrl", error.captcha().image_url.spec()); |
| 335 } | 335 } |
| 336 | 336 |
| 337 // static | 337 // static |
| 338 void SyncSetupFlow::GetArgsForChooseDataTypes(ProfileSyncService* service, | 338 void SyncSetupFlow::GetArgsForChooseDataTypes(ProfileSyncService* service, |
| 339 DictionaryValue* args) { | 339 DictionaryValue* args) { |
| 340 args->SetString(L"iframeToShow", "choose_data_types"); | 340 args->SetString("iframeToShow", "choose_data_types"); |
| 341 args->SetBoolean(L"keepEverythingSynced", | 341 args->SetBoolean("keepEverythingSynced", |
| 342 service->profile()->GetPrefs()->GetBoolean(prefs::kKeepEverythingSynced)); | 342 service->profile()->GetPrefs()->GetBoolean(prefs::kKeepEverythingSynced)); |
| 343 | 343 |
| 344 // Bookmarks, Preferences, and Themes are launched for good, there's no | 344 // Bookmarks, Preferences, and Themes are launched for good, there's no |
| 345 // going back now. Check if the other data types are registered though. | 345 // going back now. Check if the other data types are registered though. |
| 346 syncable::ModelTypeSet registered_types; | 346 syncable::ModelTypeSet registered_types; |
| 347 service->GetRegisteredDataTypes(®istered_types); | 347 service->GetRegisteredDataTypes(®istered_types); |
| 348 args->SetBoolean(L"passwordsRegistered", | 348 args->SetBoolean("passwordsRegistered", |
| 349 registered_types.count(syncable::PASSWORDS) > 0); | 349 registered_types.count(syncable::PASSWORDS) > 0); |
| 350 args->SetBoolean(L"autofillRegistered", | 350 args->SetBoolean("autofillRegistered", |
| 351 registered_types.count(syncable::AUTOFILL) > 0); | 351 registered_types.count(syncable::AUTOFILL) > 0); |
| 352 args->SetBoolean(L"extensionsRegistered", | 352 args->SetBoolean("extensionsRegistered", |
| 353 registered_types.count(syncable::EXTENSIONS) > 0); | 353 registered_types.count(syncable::EXTENSIONS) > 0); |
| 354 args->SetBoolean(L"typedUrlsRegistered", | 354 args->SetBoolean("typedUrlsRegistered", |
| 355 registered_types.count(syncable::TYPED_URLS) > 0); | 355 registered_types.count(syncable::TYPED_URLS) > 0); |
| 356 | 356 |
| 357 args->SetBoolean(L"syncBookmarks", | 357 args->SetBoolean("syncBookmarks", |
| 358 service->profile()->GetPrefs()->GetBoolean(prefs::kSyncBookmarks)); | 358 service->profile()->GetPrefs()->GetBoolean(prefs::kSyncBookmarks)); |
| 359 args->SetBoolean(L"syncPreferences", | 359 args->SetBoolean("syncPreferences", |
| 360 service->profile()->GetPrefs()->GetBoolean(prefs::kSyncPreferences)); | 360 service->profile()->GetPrefs()->GetBoolean(prefs::kSyncPreferences)); |
| 361 args->SetBoolean(L"syncThemes", | 361 args->SetBoolean("syncThemes", |
| 362 service->profile()->GetPrefs()->GetBoolean(prefs::kSyncThemes)); | 362 service->profile()->GetPrefs()->GetBoolean(prefs::kSyncThemes)); |
| 363 args->SetBoolean(L"syncPasswords", | 363 args->SetBoolean("syncPasswords", |
| 364 service->profile()->GetPrefs()->GetBoolean(prefs::kSyncPasswords)); | 364 service->profile()->GetPrefs()->GetBoolean(prefs::kSyncPasswords)); |
| 365 args->SetBoolean(L"syncAutofill", | 365 args->SetBoolean("syncAutofill", |
| 366 service->profile()->GetPrefs()->GetBoolean(prefs::kSyncAutofill)); | 366 service->profile()->GetPrefs()->GetBoolean(prefs::kSyncAutofill)); |
| 367 args->SetBoolean(L"syncExtensions", | 367 args->SetBoolean("syncExtensions", |
| 368 service->profile()->GetPrefs()->GetBoolean(prefs::kSyncExtensions)); | 368 service->profile()->GetPrefs()->GetBoolean(prefs::kSyncExtensions)); |
| 369 args->SetBoolean(L"syncTypedUrls", | 369 args->SetBoolean("syncTypedUrls", |
| 370 service->profile()->GetPrefs()->GetBoolean(prefs::kSyncTypedUrls)); | 370 service->profile()->GetPrefs()->GetBoolean(prefs::kSyncTypedUrls)); |
| 371 } | 371 } |
| 372 | 372 |
| 373 void SyncSetupFlow::GetDOMMessageHandlers( | 373 void SyncSetupFlow::GetDOMMessageHandlers( |
| 374 std::vector<DOMMessageHandler*>* handlers) const { | 374 std::vector<DOMMessageHandler*>* handlers) const { |
| 375 handlers->push_back(flow_handler_); | 375 handlers->push_back(flow_handler_); |
| 376 // We don't own flow_handler_ anymore, but it sticks around until at least | 376 // We don't own flow_handler_ anymore, but it sticks around until at least |
| 377 // right after OnDialogClosed() is called (and this object is destroyed). | 377 // right after OnDialogClosed() is called (and this object is destroyed). |
| 378 owns_flow_handler_ = false; | 378 owns_flow_handler_ = false; |
| 379 } | 379 } |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 420 // Fall through. | 420 // Fall through. |
| 421 case SyncSetupWizard::CHOOSE_DATA_TYPES: { | 421 case SyncSetupWizard::CHOOSE_DATA_TYPES: { |
| 422 DictionaryValue args; | 422 DictionaryValue args; |
| 423 SyncSetupFlow::GetArgsForChooseDataTypes(service_, &args); | 423 SyncSetupFlow::GetArgsForChooseDataTypes(service_, &args); |
| 424 flow_handler_->ShowChooseDataTypes(args); | 424 flow_handler_->ShowChooseDataTypes(args); |
| 425 break; | 425 break; |
| 426 } | 426 } |
| 427 case SyncSetupWizard::SETUP_ABORTED_BY_PENDING_CLEAR: { | 427 case SyncSetupWizard::SETUP_ABORTED_BY_PENDING_CLEAR: { |
| 428 DictionaryValue args; | 428 DictionaryValue args; |
| 429 SyncSetupFlow::GetArgsForChooseDataTypes(service_, &args); | 429 SyncSetupFlow::GetArgsForChooseDataTypes(service_, &args); |
| 430 args.SetBoolean(L"was_aborted", true); | 430 args.SetBoolean("was_aborted", true); |
| 431 flow_handler_->ShowChooseDataTypes(args); | 431 flow_handler_->ShowChooseDataTypes(args); |
| 432 break; | 432 break; |
| 433 } | 433 } |
| 434 case SyncSetupWizard::FATAL_ERROR: { | 434 case SyncSetupWizard::FATAL_ERROR: { |
| 435 // This shows the user the "Could not connect to server" error. | 435 // This shows the user the "Could not connect to server" error. |
| 436 // TODO(sync): Update this error messaging. | 436 // TODO(sync): Update this error messaging. |
| 437 DictionaryValue args; | 437 DictionaryValue args; |
| 438 SyncSetupFlow::GetArgsForGaiaLogin(service_, &args); | 438 SyncSetupFlow::GetArgsForGaiaLogin(service_, &args); |
| 439 args.SetInteger(L"error", GoogleServiceAuthError::CONNECTION_FAILED); | 439 args.SetInteger("error", GoogleServiceAuthError::CONNECTION_FAILED); |
| 440 flow_handler_->ShowGaiaLogin(args); | 440 flow_handler_->ShowGaiaLogin(args); |
| 441 break; | 441 break; |
| 442 } | 442 } |
| 443 case SyncSetupWizard::DONE_FIRST_TIME: | 443 case SyncSetupWizard::DONE_FIRST_TIME: |
| 444 flow_handler_->ShowFirstTimeDone( | 444 flow_handler_->ShowFirstTimeDone( |
| 445 UTF16ToWide(service_->GetAuthenticatedUsername())); | 445 UTF16ToWide(service_->GetAuthenticatedUsername())); |
| 446 break; | 446 break; |
| 447 case SyncSetupWizard::DONE: | 447 case SyncSetupWizard::DONE: |
| 448 flow_handler_->ShowSetupDone( | 448 flow_handler_->ShowSetupDone( |
| 449 UTF16ToWide(service_->GetAuthenticatedUsername())); | 449 UTF16ToWide(service_->GetAuthenticatedUsername())); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 496 Browser* b = BrowserList::GetLastActive(); | 496 Browser* b = BrowserList::GetLastActive(); |
| 497 if (b) { | 497 if (b) { |
| 498 b->BrowserShowHtmlDialog(flow, parent_window); | 498 b->BrowserShowHtmlDialog(flow, parent_window); |
| 499 } else { | 499 } else { |
| 500 delete flow; | 500 delete flow; |
| 501 return NULL; | 501 return NULL; |
| 502 } | 502 } |
| 503 #endif // defined(OS_MACOSX) | 503 #endif // defined(OS_MACOSX) |
| 504 return flow; | 504 return flow; |
| 505 } | 505 } |
| OLD | NEW |