OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/bind.h" | 7 #include "base/bind.h" |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 | 64 |
65 const char* kDataTypeNames[] = { | 65 const char* kDataTypeNames[] = { |
66 "apps", | 66 "apps", |
67 "autofill", | 67 "autofill", |
68 "bookmarks", | 68 "bookmarks", |
69 "extensions", | 69 "extensions", |
70 "passwords", | 70 "passwords", |
71 "preferences", | 71 "preferences", |
72 "sessions", | 72 "sessions", |
73 "themes", | 73 "themes", |
74 "typed_urls" | 74 "typedUrls" |
75 }; | 75 }; |
76 | 76 |
77 const syncable::ModelType kDataTypes[] = { | 77 const syncable::ModelType kDataTypes[] = { |
78 syncable::APPS, | 78 syncable::APPS, |
79 syncable::AUTOFILL, | 79 syncable::AUTOFILL, |
80 syncable::BOOKMARKS, | 80 syncable::BOOKMARKS, |
81 syncable::EXTENSIONS, | 81 syncable::EXTENSIONS, |
82 syncable::PASSWORDS, | 82 syncable::PASSWORDS, |
83 syncable::PREFERENCES, | 83 syncable::PREFERENCES, |
84 syncable::SESSIONS, | 84 syncable::SESSIONS, |
(...skipping 11 matching lines...) Expand all Loading... |
96 std::string* captcha, | 96 std::string* captcha, |
97 std::string* access_code) { | 97 std::string* access_code) { |
98 scoped_ptr<Value> parsed_value(base::JSONReader::Read(json)); | 98 scoped_ptr<Value> parsed_value(base::JSONReader::Read(json)); |
99 if (!parsed_value.get() || !parsed_value->IsType(Value::TYPE_DICTIONARY)) | 99 if (!parsed_value.get() || !parsed_value->IsType(Value::TYPE_DICTIONARY)) |
100 return false; | 100 return false; |
101 | 101 |
102 DictionaryValue* result = static_cast<DictionaryValue*>(parsed_value.get()); | 102 DictionaryValue* result = static_cast<DictionaryValue*>(parsed_value.get()); |
103 if (!result->GetString("user", username) || | 103 if (!result->GetString("user", username) || |
104 !result->GetString("pass", password) || | 104 !result->GetString("pass", password) || |
105 !result->GetString("captcha", captcha) || | 105 !result->GetString("captcha", captcha) || |
106 !result->GetString("access_code", access_code)) { | 106 !result->GetString("accessCode", access_code)) { |
107 return false; | 107 return false; |
108 } | 108 } |
109 return true; | 109 return true; |
110 } | 110 } |
111 | 111 |
112 bool GetConfiguration(const std::string& json, SyncConfigInfo* config) { | 112 bool GetConfiguration(const std::string& json, SyncConfigInfo* config) { |
113 scoped_ptr<Value> parsed_value(base::JSONReader::Read(json)); | 113 scoped_ptr<Value> parsed_value(base::JSONReader::Read(json)); |
114 DictionaryValue* result; | 114 DictionaryValue* result; |
115 if (!parsed_value.get() || !parsed_value->GetAsDictionary(&result)) { | 115 if (!parsed_value.get() || !parsed_value->GetAsDictionary(&result)) { |
116 DLOG(ERROR) << "GetConfiguration() not passed a Dictionary"; | 116 DLOG(ERROR) << "GetConfiguration() not passed a Dictionary"; |
117 return false; | 117 return false; |
118 } | 118 } |
119 | 119 |
120 if (!result->GetBoolean("syncAllDataTypes", &config->sync_everything)) { | 120 if (!result->GetBoolean("syncAllDataTypes", &config->sync_everything)) { |
121 DLOG(ERROR) << "GetConfiguration() not passed a syncAllDataTypes value"; | 121 DLOG(ERROR) << "GetConfiguration() not passed a syncAllDataTypes value"; |
122 return false; | 122 return false; |
123 } | 123 } |
124 | 124 |
125 for (size_t i = 0; i < arraysize(kDataTypeNames); ++i) { | 125 for (size_t i = 0; i < arraysize(kDataTypeNames); ++i) { |
126 std::string key_name = std::string("sync_") + kDataTypeNames[i]; | 126 std::string key_name = kDataTypeNames[i] + std::string("Synced"); |
127 bool sync_value; | 127 bool sync_value; |
128 if (!result->GetBoolean(key_name, &sync_value)) { | 128 if (!result->GetBoolean(key_name, &sync_value)) { |
129 DLOG(ERROR) << "GetConfiguration() not passed a value for " << key_name; | 129 DLOG(ERROR) << "GetConfiguration() not passed a value for " << key_name; |
130 return false; | 130 return false; |
131 } | 131 } |
132 if (sync_value) | 132 if (sync_value) |
133 config->data_types.Put(kDataTypes[i]); | 133 config->data_types.Put(kDataTypes[i]); |
134 } | 134 } |
135 | 135 |
136 // Encryption settings. | 136 // Encryption settings. |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
342 // SigninTracker. | 342 // SigninTracker. |
343 signin_tracker_.reset(); | 343 signin_tracker_.reset(); |
344 configuring_sync_ = true; | 344 configuring_sync_ = true; |
345 ProfileSyncService* service = GetSyncService(); | 345 ProfileSyncService* service = GetSyncService(); |
346 DCHECK(service->sync_initialized()) << | 346 DCHECK(service->sync_initialized()) << |
347 "Cannot configure sync until the sync backend is initialized"; | 347 "Cannot configure sync until the sync backend is initialized"; |
348 | 348 |
349 // Setup args for the sync configure screen: | 349 // Setup args for the sync configure screen: |
350 // showSyncEverythingPage: false to skip directly to the configure screen | 350 // showSyncEverythingPage: false to skip directly to the configure screen |
351 // syncAllDataTypes: true if the user wants to sync everything | 351 // syncAllDataTypes: true if the user wants to sync everything |
352 // <data_type>_registered: true if the associated data type is supported | 352 // <data_type>Registered: true if the associated data type is supported |
353 // sync_<data_type>: true if the user wants to sync that specific data type | 353 // <data_type>Synced: true if the user wants to sync that specific data type |
354 // encryptionEnabled: true if sync supports encryption | 354 // encryptionEnabled: true if sync supports encryption |
355 // encryptAllData: true if user wants to encrypt all data (not just | 355 // encryptAllData: true if user wants to encrypt all data (not just |
356 // passwords) | 356 // passwords) |
357 // usePassphrase: true if the data is encrypted with a secondary passphrase | 357 // usePassphrase: true if the data is encrypted with a secondary passphrase |
358 // show_passphrase: true if a passphrase is needed to decrypt the sync data | 358 // show_passphrase: true if a passphrase is needed to decrypt the sync data |
359 // TODO(atwilson): Convert all to unix_hacker style (http://crbug.com/119646). | |
360 DictionaryValue args; | 359 DictionaryValue args; |
361 | 360 |
362 // Tell the UI layer which data types are registered/enabled by the user. | 361 // Tell the UI layer which data types are registered/enabled by the user. |
363 const syncable::ModelTypeSet registered_types = | 362 const syncable::ModelTypeSet registered_types = |
364 service->GetRegisteredDataTypes(); | 363 service->GetRegisteredDataTypes(); |
365 const syncable::ModelTypeSet preferred_types = | 364 const syncable::ModelTypeSet preferred_types = |
366 service->GetPreferredDataTypes(); | 365 service->GetPreferredDataTypes(); |
367 for (size_t i = 0; i < kNumDataTypes; ++i) { | 366 for (size_t i = 0; i < kNumDataTypes; ++i) { |
368 const std::string key_name = kDataTypeNames[i]; | 367 const std::string key_name = kDataTypeNames[i]; |
369 args.SetBoolean(key_name + "_registered", | 368 args.SetBoolean(key_name + "Registered", |
370 registered_types.Has(kDataTypes[i])); | 369 registered_types.Has(kDataTypes[i])); |
371 args.SetBoolean("sync_" + key_name, preferred_types.Has(kDataTypes[i])); | 370 args.SetBoolean(key_name + "Synced", preferred_types.Has(kDataTypes[i])); |
372 } | 371 } |
373 browser_sync::SyncPrefs sync_prefs(GetProfile()->GetPrefs()); | 372 browser_sync::SyncPrefs sync_prefs(GetProfile()->GetPrefs()); |
374 args.SetBoolean("passphrase_failed", passphrase_failed); | 373 args.SetBoolean("passphraseFailed", passphrase_failed); |
375 args.SetBoolean("showSyncEverythingPage", !show_advanced); | 374 args.SetBoolean("showSyncEverythingPage", !show_advanced); |
376 args.SetBoolean("syncAllDataTypes", sync_prefs.HasKeepEverythingSynced()); | 375 args.SetBoolean("syncAllDataTypes", sync_prefs.HasKeepEverythingSynced()); |
377 args.SetBoolean("encryptAllData", service->EncryptEverythingEnabled()); | 376 args.SetBoolean("encryptAllData", service->EncryptEverythingEnabled()); |
378 args.SetBoolean("usePassphrase", service->IsUsingSecondaryPassphrase()); | 377 args.SetBoolean("usePassphrase", service->IsUsingSecondaryPassphrase()); |
379 // We call IsPassphraseRequired() here, instead of calling | 378 // We call IsPassphraseRequired() here, instead of calling |
380 // IsPassphraseRequiredForDecryption(), because we want to show the passphrase | 379 // IsPassphraseRequiredForDecryption(), because we want to show the passphrase |
381 // UI even if no encrypted data types are enabled. | 380 // UI even if no encrypted data types are enabled. |
382 args.SetBoolean("show_passphrase", service->IsPassphraseRequired()); | 381 args.SetBoolean("showPassphrase", service->IsPassphraseRequired()); |
383 | 382 |
384 StringValue page("configure"); | 383 StringValue page("configure"); |
385 web_ui()->CallJavascriptFunction( | 384 web_ui()->CallJavascriptFunction( |
386 "SyncSetupOverlay.showSyncSetupPage", page, args); | 385 "SyncSetupOverlay.showSyncSetupPage", page, args); |
387 } | 386 } |
388 | 387 |
389 void SyncSetupHandler::ConfigureSyncDone() { | 388 void SyncSetupHandler::ConfigureSyncDone() { |
390 StringValue page("done"); | 389 StringValue page("done"); |
391 web_ui()->CallJavascriptFunction( | 390 web_ui()->CallJavascriptFunction( |
392 "SyncSetupOverlay.showSyncSetupPage", page); | 391 "SyncSetupOverlay.showSyncSetupPage", page); |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
476 } else { | 475 } else { |
477 // Fresh login attempt - lock in the authenticated username if there is | 476 // Fresh login attempt - lock in the authenticated username if there is |
478 // one (don't let the user change it). | 477 // one (don't let the user change it). |
479 user = GetSignin()->GetAuthenticatedUsername(); | 478 user = GetSignin()->GetAuthenticatedUsername(); |
480 error = 0; | 479 error = 0; |
481 editable_user = user.empty(); | 480 editable_user = user.empty(); |
482 } | 481 } |
483 DictionaryValue args; | 482 DictionaryValue args; |
484 args.SetString("user", user); | 483 args.SetString("user", user); |
485 args.SetInteger("error", error); | 484 args.SetInteger("error", error); |
486 args.SetBoolean("editable_user", editable_user); | 485 args.SetBoolean("editableUser", editable_user); |
487 if (!error_message.empty()) | 486 if (!error_message.empty()) |
488 args.SetString("error_message", error_message); | 487 args.SetString("errorMessage", error_message); |
489 if (fatal_error) | 488 if (fatal_error) |
490 args.SetBoolean("fatalError", true); | 489 args.SetBoolean("fatalError", true); |
491 args.SetString("captchaUrl", captcha); | 490 args.SetString("captchaUrl", captcha); |
492 StringValue page("login"); | 491 StringValue page("login"); |
493 web_ui()->CallJavascriptFunction( | 492 web_ui()->CallJavascriptFunction( |
494 "SyncSetupOverlay.showSyncSetupPage", page, args); | 493 "SyncSetupOverlay.showSyncSetupPage", page, args); |
495 } | 494 } |
496 | 495 |
497 // TODO(kochi): Handle error conditions (timeout, other failures). | 496 // TODO(kochi): Handle error conditions (timeout, other failures). |
498 void SyncSetupHandler::DisplaySpinner() { | 497 void SyncSetupHandler::DisplaySpinner() { |
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
903 if (i != current_profile_index && AreUserNamesEqual( | 902 if (i != current_profile_index && AreUserNamesEqual( |
904 cache.GetUserNameOfProfileAtIndex(i), username_utf16)) { | 903 cache.GetUserNameOfProfileAtIndex(i), username_utf16)) { |
905 *error_message = l10n_util::GetStringUTF16( | 904 *error_message = l10n_util::GetStringUTF16( |
906 IDS_SYNC_USER_NAME_IN_USE_ERROR); | 905 IDS_SYNC_USER_NAME_IN_USE_ERROR); |
907 return false; | 906 return false; |
908 } | 907 } |
909 } | 908 } |
910 | 909 |
911 return true; | 910 return true; |
912 } | 911 } |
OLD | NEW |