| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 #if defined(BROWSER_SYNC) | 5 #if defined(BROWSER_SYNC) |
| 6 | 6 |
| 7 #include "chrome/browser/sync/sync_setup_flow.h" | 7 #include "chrome/browser/sync/sync_setup_flow.h" |
| 8 | 8 |
| 9 #include "app/gfx/font.h" | 9 #include "app/gfx/font.h" |
| 10 #include "app/gfx/font_util.h" | 10 #include "app/gfx/font_util.h" |
| 11 #include "base/histogram.h" | 11 #include "base/histogram.h" |
| 12 #include "base/json_reader.h" | 12 #include "base/json/json_reader.h" |
| 13 #include "base/json_writer.h" | 13 #include "base/json/json_writer.h" |
| 14 #include "base/string_util.h" | 14 #include "base/string_util.h" |
| 15 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
| 16 #include "base/values.h" | 16 #include "base/values.h" |
| 17 #include "chrome/browser/browser.h" | 17 #include "chrome/browser/browser.h" |
| 18 #include "chrome/browser/browser_list.h" | 18 #include "chrome/browser/browser_list.h" |
| 19 #include "chrome/browser/renderer_host/render_view_host.h" | 19 #include "chrome/browser/renderer_host/render_view_host.h" |
| 20 #include "chrome/browser/sync/auth_error_state.h" | 20 #include "chrome/browser/sync/auth_error_state.h" |
| 21 #include "chrome/browser/sync/profile_sync_service.h" | 21 #include "chrome/browser/sync/profile_sync_service.h" |
| 22 #include "chrome/browser/tab_contents/tab_contents.h" | 22 #include "chrome/browser/tab_contents/tab_contents.h" |
| 23 #include "chrome/common/pref_names.h" | 23 #include "chrome/common/pref_names.h" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 52 | 52 |
| 53 void FlowHandler::RegisterMessages() { | 53 void FlowHandler::RegisterMessages() { |
| 54 dom_ui_->RegisterMessageCallback("SubmitAuth", | 54 dom_ui_->RegisterMessageCallback("SubmitAuth", |
| 55 NewCallback(this, &FlowHandler::HandleSubmitAuth)); | 55 NewCallback(this, &FlowHandler::HandleSubmitAuth)); |
| 56 dom_ui_->RegisterMessageCallback("SubmitMergeAndSync", | 56 dom_ui_->RegisterMessageCallback("SubmitMergeAndSync", |
| 57 NewCallback(this, &FlowHandler::HandleSubmitMergeAndSync)); | 57 NewCallback(this, &FlowHandler::HandleSubmitMergeAndSync)); |
| 58 } | 58 } |
| 59 | 59 |
| 60 static bool GetUsernameAndPassword(const std::string& json, | 60 static bool GetUsernameAndPassword(const std::string& json, |
| 61 std::string* username, std::string* password) { | 61 std::string* username, std::string* password) { |
| 62 scoped_ptr<Value> parsed_value(JSONReader::Read(json, false)); | 62 scoped_ptr<Value> parsed_value(base::JSONReader::Read(json, false)); |
| 63 if (!parsed_value.get() || !parsed_value->IsType(Value::TYPE_DICTIONARY)) | 63 if (!parsed_value.get() || !parsed_value->IsType(Value::TYPE_DICTIONARY)) |
| 64 return false; | 64 return false; |
| 65 | 65 |
| 66 DictionaryValue* result = static_cast<DictionaryValue*>(parsed_value.get()); | 66 DictionaryValue* result = static_cast<DictionaryValue*>(parsed_value.get()); |
| 67 if (!result->GetString(L"user", username) || | 67 if (!result->GetString(L"user", username) || |
| 68 !result->GetString(L"pass", password)) { | 68 !result->GetString(L"pass", password)) { |
| 69 return false; | 69 return false; |
| 70 } | 70 } |
| 71 return true; | 71 return true; |
| 72 } | 72 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 89 } | 89 } |
| 90 | 90 |
| 91 void FlowHandler::HandleSubmitMergeAndSync(const Value* value) { | 91 void FlowHandler::HandleSubmitMergeAndSync(const Value* value) { |
| 92 if (flow_) | 92 if (flow_) |
| 93 flow_->OnUserAcceptedMergeAndSync(); | 93 flow_->OnUserAcceptedMergeAndSync(); |
| 94 } | 94 } |
| 95 | 95 |
| 96 // Called by SyncSetupFlow::Advance. | 96 // Called by SyncSetupFlow::Advance. |
| 97 void FlowHandler::ShowGaiaLogin(const DictionaryValue& args) { | 97 void FlowHandler::ShowGaiaLogin(const DictionaryValue& args) { |
| 98 std::string json; | 98 std::string json; |
| 99 JSONWriter::Write(&args, false, &json); | 99 base::JSONWriter::Write(&args, false, &json); |
| 100 std::wstring javascript = std::wstring(L"showGaiaLogin") + | 100 std::wstring javascript = std::wstring(L"showGaiaLogin") + |
| 101 L"(" + UTF8ToWide(json) + L");"; | 101 L"(" + UTF8ToWide(json) + L");"; |
| 102 ExecuteJavascriptInIFrame(kLoginIFrameXPath, javascript); | 102 ExecuteJavascriptInIFrame(kLoginIFrameXPath, javascript); |
| 103 } | 103 } |
| 104 | 104 |
| 105 void FlowHandler::ShowGaiaSuccessAndClose() { | 105 void FlowHandler::ShowGaiaSuccessAndClose() { |
| 106 ExecuteJavascriptInIFrame(kLoginIFrameXPath, L"showGaiaSuccessAndClose();"); | 106 ExecuteJavascriptInIFrame(kLoginIFrameXPath, L"showGaiaSuccessAndClose();"); |
| 107 } | 107 } |
| 108 | 108 |
| 109 void FlowHandler::ShowGaiaSuccessAndSettingUp() { | 109 void FlowHandler::ShowGaiaSuccessAndSettingUp() { |
| 110 ExecuteJavascriptInIFrame(kLoginIFrameXPath, | 110 ExecuteJavascriptInIFrame(kLoginIFrameXPath, |
| 111 L"showGaiaSuccessAndSettingUp();"); | 111 L"showGaiaSuccessAndSettingUp();"); |
| 112 } | 112 } |
| 113 | 113 |
| 114 void FlowHandler::ShowMergeAndSync() { | 114 void FlowHandler::ShowMergeAndSync() { |
| 115 if (dom_ui_) // NULL during testing. | 115 if (dom_ui_) // NULL during testing. |
| 116 dom_ui_->CallJavascriptFunction(L"showMergeAndSync"); | 116 dom_ui_->CallJavascriptFunction(L"showMergeAndSync"); |
| 117 } | 117 } |
| 118 | 118 |
| 119 void FlowHandler::ShowSetupDone(const std::wstring& user) { | 119 void FlowHandler::ShowSetupDone(const std::wstring& user) { |
| 120 StringValue synced_to_string(WideToUTF8(l10n_util::GetStringF( | 120 StringValue synced_to_string(WideToUTF8(l10n_util::GetStringF( |
| 121 IDS_SYNC_NTP_SYNCED_TO, user))); | 121 IDS_SYNC_NTP_SYNCED_TO, user))); |
| 122 std::string json; | 122 std::string json; |
| 123 JSONWriter::Write(&synced_to_string, false, &json); | 123 base::JSONWriter::Write(&synced_to_string, false, &json); |
| 124 std::wstring javascript = std::wstring(L"setSyncedToUser") + | 124 std::wstring javascript = std::wstring(L"setSyncedToUser") + |
| 125 L"(" + UTF8ToWide(json) + L");"; | 125 L"(" + UTF8ToWide(json) + L");"; |
| 126 ExecuteJavascriptInIFrame(kDoneIframeXPath, javascript); | 126 ExecuteJavascriptInIFrame(kDoneIframeXPath, javascript); |
| 127 | 127 |
| 128 if (dom_ui_) | 128 if (dom_ui_) |
| 129 dom_ui_->CallJavascriptFunction(L"showSetupDone", synced_to_string); | 129 dom_ui_->CallJavascriptFunction(L"showSetupDone", synced_to_string); |
| 130 } | 130 } |
| 131 | 131 |
| 132 void FlowHandler::ShowFirstTimeDone(const std::wstring& user) { | 132 void FlowHandler::ShowFirstTimeDone(const std::wstring& user) { |
| 133 ExecuteJavascriptInIFrame(kDoneIframeXPath, | 133 ExecuteJavascriptInIFrame(kDoneIframeXPath, |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 | 280 |
| 281 // static | 281 // static |
| 282 SyncSetupFlow* SyncSetupFlow::Run(ProfileSyncService* service, | 282 SyncSetupFlow* SyncSetupFlow::Run(ProfileSyncService* service, |
| 283 SyncSetupFlowContainer* container, | 283 SyncSetupFlowContainer* container, |
| 284 SyncSetupWizard::State start, | 284 SyncSetupWizard::State start, |
| 285 SyncSetupWizard::State end) { | 285 SyncSetupWizard::State end) { |
| 286 DictionaryValue args; | 286 DictionaryValue args; |
| 287 if (start == SyncSetupWizard::GAIA_LOGIN) | 287 if (start == SyncSetupWizard::GAIA_LOGIN) |
| 288 SyncSetupFlow::GetArgsForGaiaLogin(service, &args); | 288 SyncSetupFlow::GetArgsForGaiaLogin(service, &args); |
| 289 std::string json_args; | 289 std::string json_args; |
| 290 JSONWriter::Write(&args, false, &json_args); | 290 base::JSONWriter::Write(&args, false, &json_args); |
| 291 | 291 |
| 292 Browser* b = BrowserList::GetLastActive(); | 292 Browser* b = BrowserList::GetLastActive(); |
| 293 if (!b) | 293 if (!b) |
| 294 return NULL; | 294 return NULL; |
| 295 | 295 |
| 296 FlowHandler* handler = new FlowHandler(); | 296 FlowHandler* handler = new FlowHandler(); |
| 297 SyncSetupFlow* flow = new SyncSetupFlow(start, end, json_args, | 297 SyncSetupFlow* flow = new SyncSetupFlow(start, end, json_args, |
| 298 container, handler, service); | 298 container, handler, service); |
| 299 handler->set_flow(flow); | 299 handler->set_flow(flow); |
| 300 b->BrowserShowHtmlDialog(flow, NULL); | 300 b->BrowserShowHtmlDialog(flow, NULL); |
| 301 return flow; | 301 return flow; |
| 302 } | 302 } |
| 303 | 303 |
| 304 #endif // defined(BROWSER_SYNC) | 304 #endif // defined(BROWSER_SYNC) |
| OLD | NEW |