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" |
11 #include "base/json/json_writer.h" | 11 #include "base/json/json_writer.h" |
12 #include "base/string_util.h" | 12 #include "base/string_util.h" |
13 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
14 #include "base/values.h" | 14 #include "base/values.h" |
15 #include "chrome/browser/browser.h" | 15 #include "chrome/browser/browser.h" |
16 #include "chrome/browser/browser_list.h" | 16 #include "chrome/browser/browser_list.h" |
17 #if defined(OS_MACOSX) | 17 #if defined(OS_MACOSX) |
18 #include "chrome/browser/cocoa/html_dialog_window_controller_cppsafe.h" | 18 #include "chrome/browser/cocoa/html_dialog_window_controller_cppsafe.h" |
19 #endif | 19 #endif |
20 #include "chrome/browser/dom_ui/dom_ui_util.h" | 20 #include "chrome/browser/dom_ui/dom_ui_util.h" |
21 #include "chrome/browser/platform_util.h" | 21 #include "chrome/browser/platform_util.h" |
22 #include "chrome/browser/prefs/pref_service.h" | 22 #include "chrome/browser/prefs/pref_service.h" |
23 #include "chrome/browser/profile.h" | 23 #include "chrome/browser/profile.h" |
24 #include "chrome/browser/renderer_host/render_view_host.h" | 24 #include "chrome/browser/renderer_host/render_view_host.h" |
25 #include "chrome/browser/sync/profile_sync_service.h" | 25 #include "chrome/browser/sync/profile_sync_service.h" |
26 #include "chrome/browser/sync/syncable/model_type.h" | |
27 #include "chrome/browser/tab_contents/tab_contents.h" | 26 #include "chrome/browser/tab_contents/tab_contents.h" |
28 #include "chrome/common/net/gaia/google_service_auth_error.h" | 27 #include "chrome/common/net/gaia/google_service_auth_error.h" |
29 #include "chrome/common/pref_names.h" | 28 #include "chrome/common/pref_names.h" |
30 #include "gfx/font.h" | 29 #include "gfx/font.h" |
31 #include "grit/locale_settings.h" | 30 #include "grit/locale_settings.h" |
32 | 31 |
33 // XPath expression for finding specific iframes. | 32 // XPath expression for finding specific iframes. |
34 static const wchar_t* kLoginIFrameXPath = L"//iframe[@id='login']"; | 33 static const wchar_t* kLoginIFrameXPath = L"//iframe[@id='login']"; |
35 static const wchar_t* kChooseDataTypesIFrameXPath = | 34 static const wchar_t* kChooseDataTypesIFrameXPath = |
36 L"//iframe[@id='choose_data_types']"; | 35 L"//iframe[@id='configure']"; |
| 36 static const wchar_t* kPassphraseIFrameXPath = |
| 37 L"//iframe[@id='passphrase']"; |
37 static const wchar_t* kDoneIframeXPath = L"//iframe[@id='done']"; | 38 static const wchar_t* kDoneIframeXPath = L"//iframe[@id='done']"; |
38 | 39 |
39 void FlowHandler::RegisterMessages() { | 40 void FlowHandler::RegisterMessages() { |
40 dom_ui_->RegisterMessageCallback("SubmitAuth", | 41 dom_ui_->RegisterMessageCallback("SubmitAuth", |
41 NewCallback(this, &FlowHandler::HandleSubmitAuth)); | 42 NewCallback(this, &FlowHandler::HandleSubmitAuth)); |
42 dom_ui_->RegisterMessageCallback("ChooseDataTypes", | 43 dom_ui_->RegisterMessageCallback("Configure", |
43 NewCallback(this, &FlowHandler::HandleChooseDataTypes)); | 44 NewCallback(this, &FlowHandler::HandleConfigure)); |
| 45 dom_ui_->RegisterMessageCallback("Passphrase", |
| 46 NewCallback(this, &FlowHandler::HandlePassphraseEntry)); |
44 } | 47 } |
45 | 48 |
46 static bool GetAuthData(const std::string& json, | 49 static bool GetAuthData(const std::string& json, |
47 std::string* username, | 50 std::string* username, |
48 std::string* password, | 51 std::string* password, |
49 std::string* captcha, | 52 std::string* captcha, |
50 std::string* access_code) { | 53 std::string* access_code) { |
51 scoped_ptr<Value> parsed_value(base::JSONReader::Read(json, false)); | 54 scoped_ptr<Value> parsed_value(base::JSONReader::Read(json, false)); |
52 if (!parsed_value.get() || !parsed_value->IsType(Value::TYPE_DICTIONARY)) | 55 if (!parsed_value.get() || !parsed_value->IsType(Value::TYPE_DICTIONARY)) |
53 return false; | 56 return false; |
54 | 57 |
55 DictionaryValue* result = static_cast<DictionaryValue*>(parsed_value.get()); | 58 DictionaryValue* result = static_cast<DictionaryValue*>(parsed_value.get()); |
56 if (!result->GetString("user", username) || | 59 if (!result->GetString("user", username) || |
57 !result->GetString("pass", password) || | 60 !result->GetString("pass", password) || |
58 !result->GetString("captcha", captcha) || | 61 !result->GetString("captcha", captcha) || |
59 !result->GetString("access_code", access_code)) { | 62 !result->GetString("access_code", access_code)) { |
60 return false; | 63 return false; |
61 } | 64 } |
62 return true; | 65 return true; |
63 } | 66 } |
64 | 67 |
65 static bool GetDataTypeChoiceData(const std::string& json, | 68 static bool GetPassphrase(const std::string& json, std::string* passphrase) { |
66 bool* sync_everything, syncable::ModelTypeSet* data_types) { | |
67 scoped_ptr<Value> parsed_value(base::JSONReader::Read(json, false)); | 69 scoped_ptr<Value> parsed_value(base::JSONReader::Read(json, false)); |
68 if (!parsed_value.get() || !parsed_value->IsType(Value::TYPE_DICTIONARY)) | 70 if (!parsed_value.get() || !parsed_value->IsType(Value::TYPE_DICTIONARY)) |
69 return false; | 71 return false; |
70 | 72 |
71 DictionaryValue* result = static_cast<DictionaryValue*>(parsed_value.get()); | 73 DictionaryValue* result = static_cast<DictionaryValue*>(parsed_value.get()); |
72 if (!result->GetBoolean("keepEverythingSynced", sync_everything)) | 74 return result->GetString("passphrase", passphrase); |
| 75 } |
| 76 |
| 77 static bool GetConfiguration(const std::string& json, |
| 78 SyncConfiguration* config) { |
| 79 scoped_ptr<Value> parsed_value(base::JSONReader::Read(json, false)); |
| 80 if (!parsed_value.get() || !parsed_value->IsType(Value::TYPE_DICTIONARY)) |
| 81 return false; |
| 82 |
| 83 DictionaryValue* result = static_cast<DictionaryValue*>(parsed_value.get()); |
| 84 if (!result->GetBoolean("keepEverythingSynced", &config->sync_everything)) |
73 return false; | 85 return false; |
74 | 86 |
75 // These values need to be kept in sync with where they are written in | 87 // These values need to be kept in sync with where they are written in |
76 // choose_datatypes.html. | 88 // choose_datatypes.html. |
77 bool sync_bookmarks; | 89 bool sync_bookmarks; |
78 if (!result->GetBoolean("syncBookmarks", &sync_bookmarks)) | 90 if (!result->GetBoolean("syncBookmarks", &sync_bookmarks)) |
79 return false; | 91 return false; |
80 if (sync_bookmarks) | 92 if (sync_bookmarks) |
81 data_types->insert(syncable::BOOKMARKS); | 93 config->data_types.insert(syncable::BOOKMARKS); |
82 | 94 |
83 bool sync_preferences; | 95 bool sync_preferences; |
84 if (!result->GetBoolean("syncPreferences", &sync_preferences)) | 96 if (!result->GetBoolean("syncPreferences", &sync_preferences)) |
85 return false; | 97 return false; |
86 if (sync_preferences) | 98 if (sync_preferences) |
87 data_types->insert(syncable::PREFERENCES); | 99 config->data_types.insert(syncable::PREFERENCES); |
88 | 100 |
89 bool sync_themes; | 101 bool sync_themes; |
90 if (!result->GetBoolean("syncThemes", &sync_themes)) | 102 if (!result->GetBoolean("syncThemes", &sync_themes)) |
91 return false; | 103 return false; |
92 if (sync_themes) | 104 if (sync_themes) |
93 data_types->insert(syncable::THEMES); | 105 config->data_types.insert(syncable::THEMES); |
94 | 106 |
95 bool sync_passwords; | 107 bool sync_passwords; |
96 if (!result->GetBoolean("syncPasswords", &sync_passwords)) | 108 if (!result->GetBoolean("syncPasswords", &sync_passwords)) |
97 return false; | 109 return false; |
98 if (sync_passwords) | 110 if (sync_passwords) |
99 data_types->insert(syncable::PASSWORDS); | 111 config->data_types.insert(syncable::PASSWORDS); |
100 | 112 |
101 bool sync_autofill; | 113 bool sync_autofill; |
102 if (!result->GetBoolean("syncAutofill", &sync_autofill)) | 114 if (!result->GetBoolean("syncAutofill", &sync_autofill)) |
103 return false; | 115 return false; |
104 if (sync_autofill) | 116 if (sync_autofill) |
105 data_types->insert(syncable::AUTOFILL); | 117 config->data_types.insert(syncable::AUTOFILL); |
106 | 118 |
107 bool sync_extensions; | 119 bool sync_extensions; |
108 if (!result->GetBoolean("syncExtensions", &sync_extensions)) | 120 if (!result->GetBoolean("syncExtensions", &sync_extensions)) |
109 return false; | 121 return false; |
110 if (sync_extensions) | 122 if (sync_extensions) |
111 data_types->insert(syncable::EXTENSIONS); | 123 config->data_types.insert(syncable::EXTENSIONS); |
112 | 124 |
113 bool sync_typed_urls; | 125 bool sync_typed_urls; |
114 if (!result->GetBoolean("syncTypedUrls", &sync_typed_urls)) | 126 if (!result->GetBoolean("syncTypedUrls", &sync_typed_urls)) |
115 return false; | 127 return false; |
116 if (sync_typed_urls) | 128 if (sync_typed_urls) |
117 data_types->insert(syncable::TYPED_URLS); | 129 config->data_types.insert(syncable::TYPED_URLS); |
118 | 130 |
119 bool sync_apps; | 131 bool sync_apps; |
120 if (!result->GetBoolean("syncApps", &sync_apps)) | 132 if (!result->GetBoolean("syncApps", &sync_apps)) |
121 return false; | 133 return false; |
122 if (sync_apps) | 134 if (sync_apps) |
123 data_types->insert(syncable::APPS); | 135 config->data_types.insert(syncable::APPS); |
| 136 |
| 137 // Encyption settings. |
| 138 if (!result->GetBoolean("usePassphrase", &config->use_secondary_passphrase)) |
| 139 return false; |
124 | 140 |
125 return true; | 141 return true; |
126 } | 142 } |
127 | 143 |
128 void FlowHandler::HandleSubmitAuth(const ListValue* args) { | 144 void FlowHandler::HandleSubmitAuth(const ListValue* args) { |
129 std::string json(dom_ui_util::GetJsonResponseFromFirstArgumentInList(args)); | 145 std::string json(dom_ui_util::GetJsonResponseFromFirstArgumentInList(args)); |
130 std::string username, password, captcha, access_code; | 146 std::string username, password, captcha, access_code; |
131 if (json.empty()) | 147 if (json.empty()) |
132 return; | 148 return; |
133 | 149 |
134 if (!GetAuthData(json, &username, &password, &captcha, &access_code)) { | 150 if (!GetAuthData(json, &username, &password, &captcha, &access_code)) { |
135 // The page sent us something that we didn't understand. | 151 // The page sent us something that we didn't understand. |
136 // This probably indicates a programming error. | 152 // This probably indicates a programming error. |
137 NOTREACHED(); | 153 NOTREACHED(); |
138 return; | 154 return; |
139 } | 155 } |
140 | 156 |
141 if (flow_) | 157 if (flow_) |
142 flow_->OnUserSubmittedAuth(username, password, captcha, access_code); | 158 flow_->OnUserSubmittedAuth(username, password, captcha, access_code); |
143 } | 159 } |
144 | 160 |
145 void FlowHandler::HandleChooseDataTypes(const ListValue* args) { | 161 void FlowHandler::HandleConfigure(const ListValue* args) { |
146 std::string json(dom_ui_util::GetJsonResponseFromFirstArgumentInList(args)); | 162 std::string json(dom_ui_util::GetJsonResponseFromFirstArgumentInList(args)); |
147 bool sync_everything; | 163 SyncConfiguration configuration; |
148 syncable::ModelTypeSet chosen_types; | 164 |
149 if (json.empty()) | 165 if (json.empty()) |
150 return; | 166 return; |
151 | 167 |
152 if (!GetDataTypeChoiceData(json, &sync_everything, &chosen_types)) { | 168 if (!GetConfiguration(json, &configuration)) { |
153 // The page sent us something that we didn't understand. | 169 // The page sent us something that we didn't understand. |
154 // This probably indicates a programming error. | 170 // This probably indicates a programming error. |
155 NOTREACHED(); | 171 NOTREACHED(); |
156 return; | 172 return; |
157 } | 173 } |
158 | 174 |
159 DCHECK(flow_); | 175 DCHECK(flow_); |
160 flow_->OnUserChoseDataTypes(sync_everything, chosen_types); | 176 flow_->OnUserConfigured(configuration); |
161 | 177 |
162 return; | 178 return; |
163 } | 179 } |
164 | 180 |
| 181 void FlowHandler::HandlePassphraseEntry(const ListValue* args) { |
| 182 std::string json(dom_ui_util::GetJsonResponseFromFirstArgumentInList(args)); |
| 183 |
| 184 if (json.empty()) |
| 185 return; |
| 186 |
| 187 std::string passphrase; |
| 188 if (!GetPassphrase(json, &passphrase)) { |
| 189 // Couldn't understand what the page sent. Indicates a programming error. |
| 190 NOTREACHED(); |
| 191 return; |
| 192 } |
| 193 |
| 194 DCHECK(flow_); |
| 195 flow_->OnPassphraseEntry(passphrase); |
| 196 } |
| 197 |
165 // Called by SyncSetupFlow::Advance. | 198 // Called by SyncSetupFlow::Advance. |
166 void FlowHandler::ShowGaiaLogin(const DictionaryValue& args) { | 199 void FlowHandler::ShowGaiaLogin(const DictionaryValue& args) { |
167 // Whenever you start a wizard, you pass in an arg so it starts on the right | 200 // Whenever you start a wizard, you pass in an arg so it starts on the right |
168 // iframe (see setup_flow.html's showTheRightIframe() method). But when you | 201 // iframe (see setup_flow.html's showTheRightIframe() method). But when you |
169 // transition from one flow to another, you have to explicitly call the JS | 202 // transition from one flow to another, you have to explicitly call the JS |
170 // function to show the next iframe. | 203 // function to show the next iframe. |
171 // So if you ever made a wizard that involved a gaia login as not the first | 204 // So if you ever made a wizard that involved a gaia login as not the first |
172 // frame, this call would be necessary to ensure that this method actually | 205 // frame, this call would be necessary to ensure that this method actually |
173 // shows the gaia login. | 206 // shows the gaia login. |
174 if (dom_ui_) | 207 if (dom_ui_) |
175 dom_ui_->CallJavascriptFunction(L"showGaiaLoginIframe"); | 208 dom_ui_->CallJavascriptFunction(L"showGaiaLoginIframe"); |
176 | 209 |
177 std::string json; | 210 std::string json; |
178 base::JSONWriter::Write(&args, false, &json); | 211 base::JSONWriter::Write(&args, false, &json); |
179 std::wstring javascript = std::wstring(L"showGaiaLogin") + | 212 std::wstring javascript = std::wstring(L"showGaiaLogin") + |
180 L"(" + UTF8ToWide(json) + L");"; | 213 L"(" + UTF8ToWide(json) + L");"; |
181 ExecuteJavascriptInIFrame(kLoginIFrameXPath, javascript); | 214 ExecuteJavascriptInIFrame(kLoginIFrameXPath, javascript); |
182 } | 215 } |
183 | 216 |
184 void FlowHandler::ShowGaiaSuccessAndClose() { | 217 void FlowHandler::ShowGaiaSuccessAndClose() { |
185 ExecuteJavascriptInIFrame(kLoginIFrameXPath, L"showGaiaSuccessAndClose();"); | 218 ExecuteJavascriptInIFrame(kLoginIFrameXPath, L"showGaiaSuccessAndClose();"); |
186 } | 219 } |
187 | 220 |
188 void FlowHandler::ShowGaiaSuccessAndSettingUp() { | 221 void FlowHandler::ShowGaiaSuccessAndSettingUp() { |
189 ExecuteJavascriptInIFrame(kLoginIFrameXPath, | 222 ExecuteJavascriptInIFrame(kLoginIFrameXPath, |
190 L"showGaiaSuccessAndSettingUp();"); | 223 L"showGaiaSuccessAndSettingUp();"); |
191 } | 224 } |
192 | 225 |
193 // Called by SyncSetupFlow::Advance. | 226 // Called by SyncSetupFlow::Advance. |
194 void FlowHandler::ShowChooseDataTypes(const DictionaryValue& args) { | 227 void FlowHandler::ShowConfigure(const DictionaryValue& args) { |
195 // If you're starting the wizard at the Choose Data Types screen (i.e. from | 228 // If you're starting the wizard at the configure screen (i.e. from |
196 // "Customize Sync"), this will be redundant. However, if you're coming from | 229 // "Customize Sync"), this will be redundant. However, if you're coming from |
197 // another wizard state, this will make sure Choose Data Types is on top. | 230 // another wizard state, this will make sure Choose Data Types is on top. |
198 if (dom_ui_) | 231 if (dom_ui_) |
199 dom_ui_->CallJavascriptFunction(L"showChooseDataTypes"); | 232 dom_ui_->CallJavascriptFunction(L"showConfigure"); |
200 | 233 |
201 std::string json; | 234 std::string json; |
202 base::JSONWriter::Write(&args, false, &json); | 235 base::JSONWriter::Write(&args, false, &json); |
203 std::wstring javascript = std::wstring(L"setCheckboxesAndErrors") + | 236 std::wstring javascript = std::wstring(L"initializeConfigureDialog") + |
204 L"(" + UTF8ToWide(json) + L");"; | 237 L"(" + UTF8ToWide(json) + L");"; |
205 ExecuteJavascriptInIFrame(kChooseDataTypesIFrameXPath, javascript); | 238 ExecuteJavascriptInIFrame(kChooseDataTypesIFrameXPath, javascript); |
206 } | 239 } |
207 | 240 |
| 241 void FlowHandler::ShowPassphraseEntry(const DictionaryValue& args) { |
| 242 if (dom_ui_) |
| 243 dom_ui_->CallJavascriptFunction(L"showPassphrase"); |
| 244 |
| 245 std::string json; |
| 246 base::JSONWriter::Write(&args, false, &json); |
| 247 std::wstring script = std::wstring(L"setupPassphraseDialog") + |
| 248 L"(" + UTF8ToWide(json) + L");"; |
| 249 ExecuteJavascriptInIFrame(kPassphraseIFrameXPath, script); |
| 250 } |
| 251 |
| 252 void FlowHandler::ShowSettingUp() { |
| 253 if (dom_ui_) |
| 254 dom_ui_->CallJavascriptFunction(L"showSettingUp"); |
| 255 } |
| 256 |
208 void FlowHandler::ShowSetupDone(const std::wstring& user) { | 257 void FlowHandler::ShowSetupDone(const std::wstring& user) { |
209 StringValue synced_to_string(l10n_util::GetStringFUTF8( | 258 StringValue synced_to_string(l10n_util::GetStringFUTF8( |
210 IDS_SYNC_NTP_SYNCED_TO, WideToUTF16Hack(user))); | 259 IDS_SYNC_NTP_SYNCED_TO, WideToUTF16Hack(user))); |
211 std::string json; | 260 std::string json; |
212 base::JSONWriter::Write(&synced_to_string, false, &json); | 261 base::JSONWriter::Write(&synced_to_string, false, &json); |
213 std::wstring javascript = std::wstring(L"setSyncedToUser") + | 262 std::wstring javascript = std::wstring(L"setSyncedToUser") + |
214 L"(" + UTF8ToWide(json) + L");"; | 263 L"(" + UTF8ToWide(json) + L");"; |
215 ExecuteJavascriptInIFrame(kDoneIframeXPath, javascript); | 264 ExecuteJavascriptInIFrame(kDoneIframeXPath, javascript); |
216 | 265 |
217 if (dom_ui_) | 266 if (dom_ui_) |
(...skipping 23 matching lines...) Expand all Loading... |
241 const std::string& args, | 290 const std::string& args, |
242 SyncSetupFlowContainer* container, | 291 SyncSetupFlowContainer* container, |
243 ProfileSyncService* service) | 292 ProfileSyncService* service) |
244 : container_(container), | 293 : container_(container), |
245 dialog_start_args_(args), | 294 dialog_start_args_(args), |
246 current_state_(start_state), | 295 current_state_(start_state), |
247 end_state_(end_state), | 296 end_state_(end_state), |
248 login_start_time_(base::TimeTicks::Now()), | 297 login_start_time_(base::TimeTicks::Now()), |
249 flow_handler_(new FlowHandler()), | 298 flow_handler_(new FlowHandler()), |
250 owns_flow_handler_(true), | 299 owns_flow_handler_(true), |
| 300 configuration_pending_(false), |
251 service_(service), | 301 service_(service), |
252 html_dialog_window_(NULL) { | 302 html_dialog_window_(NULL) { |
253 flow_handler_->set_flow(this); | 303 flow_handler_->set_flow(this); |
254 } | 304 } |
255 | 305 |
256 SyncSetupFlow::~SyncSetupFlow() { | 306 SyncSetupFlow::~SyncSetupFlow() { |
257 flow_handler_->set_flow(NULL); | 307 flow_handler_->set_flow(NULL); |
258 if (owns_flow_handler_) { | 308 if (owns_flow_handler_) { |
259 delete flow_handler_; | 309 delete flow_handler_; |
260 } | 310 } |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 // Record the state at which the user cancelled the signon dialog. | 348 // Record the state at which the user cancelled the signon dialog. |
299 switch (current_state_) { | 349 switch (current_state_) { |
300 case SyncSetupWizard::GAIA_LOGIN: | 350 case SyncSetupWizard::GAIA_LOGIN: |
301 ProfileSyncService::SyncEvent( | 351 ProfileSyncService::SyncEvent( |
302 ProfileSyncService::CANCEL_FROM_SIGNON_WITHOUT_AUTH); | 352 ProfileSyncService::CANCEL_FROM_SIGNON_WITHOUT_AUTH); |
303 break; | 353 break; |
304 case SyncSetupWizard::GAIA_SUCCESS: | 354 case SyncSetupWizard::GAIA_SUCCESS: |
305 ProfileSyncService::SyncEvent( | 355 ProfileSyncService::SyncEvent( |
306 ProfileSyncService::CANCEL_DURING_SIGNON); | 356 ProfileSyncService::CANCEL_DURING_SIGNON); |
307 break; | 357 break; |
308 case SyncSetupWizard::CHOOSE_DATA_TYPES: | 358 case SyncSetupWizard::CONFIGURE: |
| 359 case SyncSetupWizard::ENTER_PASSPHRASE: |
| 360 case SyncSetupWizard::SETTING_UP: |
309 ProfileSyncService::SyncEvent( | 361 ProfileSyncService::SyncEvent( |
310 ProfileSyncService::CANCEL_FROM_CHOOSE_DATA_TYPES); | 362 ProfileSyncService::CANCEL_DURING_CONFIGURE); |
311 break; | 363 break; |
312 case SyncSetupWizard::DONE_FIRST_TIME: | 364 case SyncSetupWizard::DONE_FIRST_TIME: |
313 case SyncSetupWizard::DONE: | 365 case SyncSetupWizard::DONE: |
314 // TODO(sync): rename this histogram; it's tracking authorization AND | 366 // TODO(sync): rename this histogram; it's tracking authorization AND |
315 // initial sync download time. | 367 // initial sync download time. |
316 UMA_HISTOGRAM_MEDIUM_TIMES("Sync.UserPerceivedAuthorizationTime", | 368 UMA_HISTOGRAM_MEDIUM_TIMES("Sync.UserPerceivedAuthorizationTime", |
317 base::TimeTicks::Now() - login_start_time_); | 369 base::TimeTicks::Now() - login_start_time_); |
318 break; | 370 break; |
319 default: | 371 default: |
320 break; | 372 break; |
(...skipping 16 matching lines...) Expand all Loading... |
337 string16 user(service->GetAuthenticatedUsername()); | 389 string16 user(service->GetAuthenticatedUsername()); |
338 args->SetString("user", user); | 390 args->SetString("user", user); |
339 args->SetInteger("error", 0); | 391 args->SetInteger("error", 0); |
340 args->SetBoolean("editable_user", user.empty()); | 392 args->SetBoolean("editable_user", user.empty()); |
341 } | 393 } |
342 | 394 |
343 args->SetString("captchaUrl", error.captcha().image_url.spec()); | 395 args->SetString("captchaUrl", error.captcha().image_url.spec()); |
344 } | 396 } |
345 | 397 |
346 // static | 398 // static |
347 void SyncSetupFlow::GetArgsForChooseDataTypes(ProfileSyncService* service, | 399 void SyncSetupFlow::GetArgsForConfigure(ProfileSyncService* service, |
348 DictionaryValue* args) { | 400 DictionaryValue* args) { |
349 args->SetString("iframeToShow", "choose_data_types"); | 401 args->SetString("iframeToShow", "configure"); |
| 402 |
| 403 // By default start on the data types tab. |
| 404 args->SetString("initialTab", "data-type"); |
| 405 |
350 args->SetBoolean("keepEverythingSynced", | 406 args->SetBoolean("keepEverythingSynced", |
351 service->profile()->GetPrefs()->GetBoolean(prefs::kKeepEverythingSynced)); | 407 service->profile()->GetPrefs()->GetBoolean(prefs::kKeepEverythingSynced)); |
352 | 408 |
353 // Bookmarks, Preferences, and Themes are launched for good, there's no | 409 // Bookmarks, Preferences, and Themes are launched for good, there's no |
354 // going back now. Check if the other data types are registered though. | 410 // going back now. Check if the other data types are registered though. |
355 syncable::ModelTypeSet registered_types; | 411 syncable::ModelTypeSet registered_types; |
356 service->GetRegisteredDataTypes(®istered_types); | 412 service->GetRegisteredDataTypes(®istered_types); |
357 args->SetBoolean("passwordsRegistered", | 413 args->SetBoolean("passwordsRegistered", |
358 registered_types.count(syncable::PASSWORDS) > 0); | 414 registered_types.count(syncable::PASSWORDS) > 0); |
359 args->SetBoolean("autofillRegistered", | 415 args->SetBoolean("autofillRegistered", |
(...skipping 17 matching lines...) Expand all Loading... |
377 args->SetBoolean("syncAutofill", | 433 args->SetBoolean("syncAutofill", |
378 service->profile()->GetPrefs()->GetBoolean(prefs::kSyncAutofill)); | 434 service->profile()->GetPrefs()->GetBoolean(prefs::kSyncAutofill)); |
379 args->SetBoolean("syncExtensions", | 435 args->SetBoolean("syncExtensions", |
380 service->profile()->GetPrefs()->GetBoolean(prefs::kSyncExtensions)); | 436 service->profile()->GetPrefs()->GetBoolean(prefs::kSyncExtensions)); |
381 args->SetBoolean("syncSessions", | 437 args->SetBoolean("syncSessions", |
382 service->profile()->GetPrefs()->GetBoolean(prefs::kSyncSessions)); | 438 service->profile()->GetPrefs()->GetBoolean(prefs::kSyncSessions)); |
383 args->SetBoolean("syncTypedUrls", | 439 args->SetBoolean("syncTypedUrls", |
384 service->profile()->GetPrefs()->GetBoolean(prefs::kSyncTypedUrls)); | 440 service->profile()->GetPrefs()->GetBoolean(prefs::kSyncTypedUrls)); |
385 args->SetBoolean("syncApps", | 441 args->SetBoolean("syncApps", |
386 service->profile()->GetPrefs()->GetBoolean(prefs::kSyncApps)); | 442 service->profile()->GetPrefs()->GetBoolean(prefs::kSyncApps)); |
| 443 |
| 444 // Load the parameters for the encryption tab. |
| 445 args->SetBoolean("usePassphrase", service->IsUsingSecondaryPassphrase()); |
387 } | 446 } |
388 | 447 |
389 void SyncSetupFlow::GetDOMMessageHandlers( | 448 void SyncSetupFlow::GetDOMMessageHandlers( |
390 std::vector<DOMMessageHandler*>* handlers) const { | 449 std::vector<DOMMessageHandler*>* handlers) const { |
391 handlers->push_back(flow_handler_); | 450 handlers->push_back(flow_handler_); |
392 // We don't own flow_handler_ anymore, but it sticks around until at least | 451 // We don't own flow_handler_ anymore, but it sticks around until at least |
393 // right after OnDialogClosed() is called (and this object is destroyed). | 452 // right after OnDialogClosed() is called (and this object is destroyed). |
394 owns_flow_handler_ = false; | 453 owns_flow_handler_ = false; |
395 } | 454 } |
396 | 455 |
| 456 // Returns true if the flow should advance to |state| based on |current_state_|. |
397 bool SyncSetupFlow::ShouldAdvance(SyncSetupWizard::State state) { | 457 bool SyncSetupFlow::ShouldAdvance(SyncSetupWizard::State state) { |
398 switch (state) { | 458 switch (state) { |
399 case SyncSetupWizard::GAIA_LOGIN: | 459 case SyncSetupWizard::GAIA_LOGIN: |
400 return current_state_ == SyncSetupWizard::FATAL_ERROR || | 460 return current_state_ == SyncSetupWizard::FATAL_ERROR || |
401 current_state_ == SyncSetupWizard::GAIA_LOGIN; | 461 current_state_ == SyncSetupWizard::GAIA_LOGIN; |
402 case SyncSetupWizard::GAIA_SUCCESS: | 462 case SyncSetupWizard::GAIA_SUCCESS: |
403 return current_state_ == SyncSetupWizard::GAIA_LOGIN; | 463 return current_state_ == SyncSetupWizard::GAIA_LOGIN; |
404 case SyncSetupWizard::CHOOSE_DATA_TYPES: | 464 case SyncSetupWizard::CONFIGURE: |
405 return current_state_ == SyncSetupWizard::GAIA_SUCCESS; | 465 return current_state_ == SyncSetupWizard::GAIA_SUCCESS; |
| 466 case SyncSetupWizard::CREATE_PASSPHRASE: |
| 467 return current_state_ == SyncSetupWizard::CONFIGURE; |
406 case SyncSetupWizard::SETUP_ABORTED_BY_PENDING_CLEAR: | 468 case SyncSetupWizard::SETUP_ABORTED_BY_PENDING_CLEAR: |
407 return current_state_ == SyncSetupWizard::CHOOSE_DATA_TYPES; | 469 return current_state_ == SyncSetupWizard::CONFIGURE; |
| 470 case SyncSetupWizard::SETTING_UP: |
| 471 return current_state_ == SyncSetupWizard::CONFIGURE || |
| 472 current_state_ == SyncSetupWizard::CREATE_PASSPHRASE; |
408 case SyncSetupWizard::FATAL_ERROR: | 473 case SyncSetupWizard::FATAL_ERROR: |
409 return true; // You can always hit the panic button. | 474 return true; // You can always hit the panic button. |
410 case SyncSetupWizard::DONE_FIRST_TIME: | 475 case SyncSetupWizard::DONE_FIRST_TIME: |
411 case SyncSetupWizard::DONE: | 476 case SyncSetupWizard::DONE: |
412 return current_state_ == SyncSetupWizard::CHOOSE_DATA_TYPES; | 477 return current_state_ == SyncSetupWizard::SETTING_UP; |
413 default: | 478 default: |
414 NOTREACHED() << "Unhandled State: " << state; | 479 NOTREACHED() << "Unhandled State: " << state; |
415 return false; | 480 return false; |
416 } | 481 } |
417 } | 482 } |
418 | 483 |
419 void SyncSetupFlow::Advance(SyncSetupWizard::State advance_state) { | 484 void SyncSetupFlow::Advance(SyncSetupWizard::State advance_state) { |
420 if (!ShouldAdvance(advance_state)) | 485 if (!ShouldAdvance(advance_state)) { |
| 486 LOG(WARNING) << "Invalid state change from " |
| 487 << current_state_ << " to " << advance_state; |
421 return; | 488 return; |
| 489 } |
422 | 490 |
423 switch (advance_state) { | 491 switch (advance_state) { |
424 case SyncSetupWizard::GAIA_LOGIN: { | 492 case SyncSetupWizard::GAIA_LOGIN: { |
425 DictionaryValue args; | 493 DictionaryValue args; |
426 SyncSetupFlow::GetArgsForGaiaLogin(service_, &args); | 494 SyncSetupFlow::GetArgsForGaiaLogin(service_, &args); |
427 flow_handler_->ShowGaiaLogin(args); | 495 flow_handler_->ShowGaiaLogin(args); |
428 break; | 496 break; |
429 } | 497 } |
430 case SyncSetupWizard::GAIA_SUCCESS: | 498 case SyncSetupWizard::GAIA_SUCCESS: |
431 if (end_state_ == SyncSetupWizard::GAIA_SUCCESS) { | 499 if (end_state_ == SyncSetupWizard::GAIA_SUCCESS) { |
432 flow_handler_->ShowGaiaSuccessAndClose(); | 500 flow_handler_->ShowGaiaSuccessAndClose(); |
433 break; | 501 break; |
434 } | 502 } |
435 advance_state = SyncSetupWizard::CHOOSE_DATA_TYPES; | 503 advance_state = SyncSetupWizard::CONFIGURE; |
436 // Fall through. | 504 // Fall through. |
437 case SyncSetupWizard::CHOOSE_DATA_TYPES: { | 505 case SyncSetupWizard::CONFIGURE: { |
438 DictionaryValue args; | 506 DictionaryValue args; |
439 SyncSetupFlow::GetArgsForChooseDataTypes(service_, &args); | 507 SyncSetupFlow::GetArgsForConfigure(service_, &args); |
440 flow_handler_->ShowChooseDataTypes(args); | 508 args.SetString("initialTab", "data-type"); |
| 509 flow_handler_->ShowConfigure(args); |
| 510 break; |
| 511 } |
| 512 case SyncSetupWizard::CREATE_PASSPHRASE: { |
| 513 DictionaryValue args; |
| 514 args.SetString("mode", "new"); |
| 515 flow_handler_->ShowPassphraseEntry(args); |
| 516 break; |
| 517 } |
| 518 case SyncSetupWizard::ENTER_PASSPHRASE: { |
| 519 DictionaryValue args; |
| 520 if (service_->IsUsingSecondaryPassphrase()) |
| 521 args.SetString("mode", "enter"); |
| 522 else |
| 523 args.SetString("mode", "gaia"); |
| 524 flow_handler_->ShowPassphraseEntry(args); |
441 break; | 525 break; |
442 } | 526 } |
443 case SyncSetupWizard::SETUP_ABORTED_BY_PENDING_CLEAR: { | 527 case SyncSetupWizard::SETUP_ABORTED_BY_PENDING_CLEAR: { |
444 DictionaryValue args; | 528 DictionaryValue args; |
445 SyncSetupFlow::GetArgsForChooseDataTypes(service_, &args); | 529 SyncSetupFlow::GetArgsForConfigure(service_, &args); |
446 args.SetBoolean("was_aborted", true); | 530 args.SetBoolean("was_aborted", true); |
447 flow_handler_->ShowChooseDataTypes(args); | 531 flow_handler_->ShowConfigure(args); |
| 532 break; |
| 533 } |
| 534 case SyncSetupWizard::SETTING_UP: { |
| 535 flow_handler_->ShowSettingUp(); |
448 break; | 536 break; |
449 } | 537 } |
450 case SyncSetupWizard::FATAL_ERROR: { | 538 case SyncSetupWizard::FATAL_ERROR: { |
451 // This shows the user the "Could not connect to server" error. | 539 // This shows the user the "Could not connect to server" error. |
452 // TODO(sync): Update this error messaging. | 540 // TODO(sync): Update this error messaging. |
453 DictionaryValue args; | 541 DictionaryValue args; |
454 SyncSetupFlow::GetArgsForGaiaLogin(service_, &args); | 542 SyncSetupFlow::GetArgsForGaiaLogin(service_, &args); |
455 args.SetInteger("error", GoogleServiceAuthError::CONNECTION_FAILED); | 543 args.SetInteger("error", GoogleServiceAuthError::CONNECTION_FAILED); |
456 flow_handler_->ShowGaiaLogin(args); | 544 flow_handler_->ShowGaiaLogin(args); |
457 break; | 545 break; |
(...skipping 27 matching lines...) Expand all Loading... |
485 | 573 |
486 // static | 574 // static |
487 SyncSetupFlow* SyncSetupFlow::Run(ProfileSyncService* service, | 575 SyncSetupFlow* SyncSetupFlow::Run(ProfileSyncService* service, |
488 SyncSetupFlowContainer* container, | 576 SyncSetupFlowContainer* container, |
489 SyncSetupWizard::State start, | 577 SyncSetupWizard::State start, |
490 SyncSetupWizard::State end, | 578 SyncSetupWizard::State end, |
491 gfx::NativeWindow parent_window) { | 579 gfx::NativeWindow parent_window) { |
492 DictionaryValue args; | 580 DictionaryValue args; |
493 if (start == SyncSetupWizard::GAIA_LOGIN) | 581 if (start == SyncSetupWizard::GAIA_LOGIN) |
494 SyncSetupFlow::GetArgsForGaiaLogin(service, &args); | 582 SyncSetupFlow::GetArgsForGaiaLogin(service, &args); |
495 else if (start == SyncSetupWizard::CHOOSE_DATA_TYPES) | 583 else if (start == SyncSetupWizard::CONFIGURE) |
496 SyncSetupFlow::GetArgsForChooseDataTypes(service, &args); | 584 SyncSetupFlow::GetArgsForConfigure(service, &args); |
497 std::string json_args; | 585 std::string json_args; |
498 base::JSONWriter::Write(&args, false, &json_args); | 586 base::JSONWriter::Write(&args, false, &json_args); |
499 | 587 |
500 SyncSetupFlow* flow = new SyncSetupFlow(start, end, json_args, | 588 SyncSetupFlow* flow = new SyncSetupFlow(start, end, json_args, |
501 container, service); | 589 container, service); |
502 #if defined(OS_MACOSX) | 590 #if defined(OS_MACOSX) |
503 // TODO(akalin): Figure out a cleaner way to do this than to have this | 591 // TODO(akalin): Figure out a cleaner way to do this than to have this |
504 // gross per-OS behavior, i.e. have a cross-platform ShowHtmlDialog() | 592 // gross per-OS behavior, i.e. have a cross-platform ShowHtmlDialog() |
505 // function that is not tied to a browser instance. Note that if we do | 593 // function that is not tied to a browser instance. Note that if we do |
506 // that, we'll have to fix sync_setup_wizard_unittest.cc as it relies on | 594 // that, we'll have to fix sync_setup_wizard_unittest.cc as it relies on |
507 // being able to intercept ShowHtmlDialog() calls. | 595 // being able to intercept ShowHtmlDialog() calls. |
508 flow->html_dialog_window_ = | 596 flow->html_dialog_window_ = |
509 html_dialog_window_controller::ShowHtmlDialog( | 597 html_dialog_window_controller::ShowHtmlDialog( |
510 flow, service->profile()); | 598 flow, service->profile()); |
511 #else | 599 #else |
512 Browser* b = BrowserList::GetLastActive(); | 600 Browser* b = BrowserList::GetLastActive(); |
513 if (b) { | 601 if (b) { |
514 b->BrowserShowHtmlDialog(flow, parent_window); | 602 b->BrowserShowHtmlDialog(flow, parent_window); |
515 } else { | 603 } else { |
516 delete flow; | 604 delete flow; |
517 return NULL; | 605 return NULL; |
518 } | 606 } |
519 #endif // defined(OS_MACOSX) | 607 #endif // defined(OS_MACOSX) |
520 return flow; | 608 return flow; |
521 } | 609 } |
| 610 |
| 611 void SyncSetupFlow::OnUserSubmittedAuth(const std::string& username, |
| 612 const std::string& password, |
| 613 const std::string& captcha, |
| 614 const std::string& access_code) { |
| 615 service_->OnUserSubmittedAuth(username, password, captcha, access_code); |
| 616 } |
| 617 |
| 618 void SyncSetupFlow::OnUserConfigured(const SyncConfiguration& configuration) { |
| 619 // Store the configuration in case we need more information. |
| 620 configuration_ = configuration; |
| 621 configuration_pending_ = true; |
| 622 |
| 623 // If the user is activating secondary passphrase for the first time, |
| 624 // we need to prompt them to enter one. |
| 625 if (configuration.use_secondary_passphrase && |
| 626 !service_->IsUsingSecondaryPassphrase()) { |
| 627 Advance(SyncSetupWizard::CREATE_PASSPHRASE); |
| 628 return; |
| 629 } |
| 630 |
| 631 OnConfigurationComplete(); |
| 632 } |
| 633 |
| 634 void SyncSetupFlow::OnConfigurationComplete() { |
| 635 if (!configuration_pending_) |
| 636 return; |
| 637 |
| 638 // Go to the "loading..." screen." |
| 639 Advance(SyncSetupWizard::SETTING_UP); |
| 640 |
| 641 // If we are activating the passphrase, we need to have one supplied. |
| 642 DCHECK(service_->IsUsingSecondaryPassphrase() || |
| 643 !configuration_.use_secondary_passphrase || |
| 644 configuration_.secondary_passphrase.length() > 0); |
| 645 |
| 646 if (configuration_.use_secondary_passphrase && |
| 647 !service_->IsUsingSecondaryPassphrase()) |
| 648 service_->SetSecondaryPassphrase(configuration_.secondary_passphrase); |
| 649 |
| 650 service_->OnUserChoseDatatypes(configuration_.sync_everything, |
| 651 configuration_.data_types); |
| 652 |
| 653 configuration_pending_ = false; |
| 654 } |
| 655 |
| 656 void SyncSetupFlow::OnPassphraseEntry(const std::string& passphrase) { |
| 657 if (configuration_pending_) { |
| 658 configuration_.secondary_passphrase = passphrase; |
| 659 OnConfigurationComplete(); |
| 660 } |
| 661 } |
OLD | NEW |