diff options
author | sargrass@google.com <sargrass@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-28 21:55:15 +0000 |
---|---|---|
committer | sargrass@google.com <sargrass@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-28 21:55:15 +0000 |
commit | 8e37a7c3177865b339724cac41ba5463b5b0b89e (patch) | |
tree | 5b83c636e22a691db6e9d1457777c0ebe596463b /chrome/browser/dom_ui | |
parent | 42dc0c200a52e7644f22156c4839ae414ae941d6 (diff) | |
download | chromium_src-8e37a7c3177865b339724cac41ba5463b5b0b89e.zip chromium_src-8e37a7c3177865b339724cac41ba5463b5b0b89e.tar.gz chromium_src-8e37a7c3177865b339724cac41ba5463b5b0b89e.tar.bz2 |
Stop Syncing Overlay and Import Data Overlay
BUG=48883
TEST=Exercise Personal Stuff page via --enabled-tabbed-options
Review URL: http://codereview.chromium.org/3038016
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@54032 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/dom_ui')
-rw-r--r-- | chrome/browser/dom_ui/clear_browser_data_handler.h | 1 | ||||
-rw-r--r-- | chrome/browser/dom_ui/import_data_handler.cc | 71 | ||||
-rw-r--r-- | chrome/browser/dom_ui/import_data_handler.h | 34 | ||||
-rw-r--r-- | chrome/browser/dom_ui/options_ui.cc | 4 | ||||
-rw-r--r-- | chrome/browser/dom_ui/personal_options_handler.cc | 32 | ||||
-rw-r--r-- | chrome/browser/dom_ui/personal_options_handler.h | 6 | ||||
-rw-r--r-- | chrome/browser/dom_ui/stop_syncing_handler.cc | 48 | ||||
-rw-r--r-- | chrome/browser/dom_ui/stop_syncing_handler.h | 28 |
8 files changed, 214 insertions, 10 deletions
diff --git a/chrome/browser/dom_ui/clear_browser_data_handler.h b/chrome/browser/dom_ui/clear_browser_data_handler.h index c5ff399..8345598 100644 --- a/chrome/browser/dom_ui/clear_browser_data_handler.h +++ b/chrome/browser/dom_ui/clear_browser_data_handler.h @@ -36,4 +36,3 @@ class ClearBrowserDataHandler : public OptionsPageUIHandler, }; #endif // CHROME_BROWSER_DOM_UI_CLEAR_BROWSER_DATA_HANDLER_H_ - diff --git a/chrome/browser/dom_ui/import_data_handler.cc b/chrome/browser/dom_ui/import_data_handler.cc new file mode 100644 index 0000000..dac2ee4 --- /dev/null +++ b/chrome/browser/dom_ui/import_data_handler.cc @@ -0,0 +1,71 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/dom_ui/import_data_handler.h" + +#include "app/l10n_util.h" +#include "base/basictypes.h" +#include "base/values.h" +#include "base/callback.h" +#include "grit/chromium_strings.h" +#include "grit/generated_resources.h" +#include "chrome/browser/importer/importer_data_types.h" + +ImportDataHandler::ImportDataHandler() { +} + +ImportDataHandler::~ImportDataHandler() { +} + +void ImportDataHandler::Initialize() { + importer_host_ = new ImporterHost(); + DetectSupportedBrowsers(); +} + +void ImportDataHandler::GetLocalizedValues( + DictionaryValue* localized_strings) { + DCHECK(localized_strings); + localized_strings->SetString(L"import_data_title", + l10n_util::GetString(IDS_IMPORT_SETTINGS_TITLE)); + localized_strings->SetString(L"import_from_label", + l10n_util::GetString(IDS_IMPORT_FROM_LABEL)); + localized_strings->SetString(L"import_commit", + l10n_util::GetString(IDS_IMPORT_COMMIT)); + localized_strings->SetString(L"import_description", + l10n_util::GetString(IDS_IMPORT_ITEMS_LABEL)); + localized_strings->SetString(L"import_favorites", + l10n_util::GetString(IDS_IMPORT_FAVORITES_CHKBOX)); + localized_strings->SetString(L"import_search", + l10n_util::GetString(IDS_IMPORT_SEARCH_ENGINES_CHKBOX)); + localized_strings->SetString(L"import_passwords", + l10n_util::GetString(IDS_IMPORT_PASSWORDS_CHKBOX)); + localized_strings->SetString(L"import_history", + l10n_util::GetString(IDS_IMPORT_HISTORY_CHKBOX)); +} + +void ImportDataHandler::RegisterMessages() { +} + +void ImportDataHandler::DetectSupportedBrowsers() { + ListValue supported_browsers; + int profiles_count = importer_host_->GetAvailableProfileCount(); + + if (profiles_count > 0) { + for (int i = 0; i < profiles_count; i++) { + std::wstring profile = importer_host_->GetSourceProfileNameAt(i); + DictionaryValue* entry = new DictionaryValue(); + entry->SetString(L"name", profile); + entry->SetInteger(L"index", i); + supported_browsers.Append(entry); + } + } else { + DictionaryValue* entry = new DictionaryValue(); + entry->SetString(L"name", l10n_util::GetString(IDS_IMPORT_FROM_LABEL)); + entry->SetInteger(L"index", 0); + supported_browsers.Append(entry); + } + + dom_ui_->CallJavascriptFunction( + L"ImportDataOverlay.updateSupportedBrowsers", supported_browsers); +} diff --git a/chrome/browser/dom_ui/import_data_handler.h b/chrome/browser/dom_ui/import_data_handler.h new file mode 100644 index 0000000..1e86fc6 --- /dev/null +++ b/chrome/browser/dom_ui/import_data_handler.h @@ -0,0 +1,34 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_DOM_UI_IMPORT_DATA_HANDLER_H_ +#define CHROME_BROWSER_DOM_UI_IMPORT_DATA_HANDLER_H_ + +#include "chrome/browser/dom_ui/options_ui.h" +#include "chrome/browser/importer/importer.h" + +// Chrome personal stuff import data overlay UI handler. +class ImportDataHandler : public OptionsPageUIHandler { + public: + ImportDataHandler(); + virtual ~ImportDataHandler(); + + virtual void Initialize(); + + // OptionsUIHandler implementation. + virtual void GetLocalizedValues(DictionaryValue* localized_strings); + + // DOMMessageHandler implementation. + virtual void RegisterMessages(); + + private: + void DetectSupportedBrowsers(); + + // Utility class that does the actual import. + scoped_refptr<ImporterHost> importer_host_; + + DISALLOW_COPY_AND_ASSIGN(ImportDataHandler); +}; + +#endif // CHROME_BROWSER_DOM_UI_IMPORT_DATA_HANDLER_H_ diff --git a/chrome/browser/dom_ui/options_ui.cc b/chrome/browser/dom_ui/options_ui.cc index 84d553d..8aa97de 100644 --- a/chrome/browser/dom_ui/options_ui.cc +++ b/chrome/browser/dom_ui/options_ui.cc @@ -25,8 +25,10 @@ #include "chrome/browser/dom_ui/content_settings_handler.h" #include "chrome/browser/dom_ui/core_options_handler.h" #include "chrome/browser/dom_ui/font_settings_handler.h" +#include "chrome/browser/dom_ui/import_data_handler.h" #include "chrome/browser/dom_ui/personal_options_handler.h" #include "chrome/browser/dom_ui/search_engine_manager_handler.h" +#include "chrome/browser/dom_ui/stop_syncing_handler.h" #include "chrome/browser/dom_ui/sync_options_handler.h" #include "chrome/browser/dom_ui/dom_ui_theme_source.h" #include "chrome/browser/metrics/user_metrics.h" @@ -133,6 +135,8 @@ OptionsUI::OptionsUI(TabContents* contents) : DOMUI(contents) { AddOptionsPageUIHandler(localized_strings, new FontSettingsHandler()); AddOptionsPageUIHandler(localized_strings, new PersonalOptionsHandler()); AddOptionsPageUIHandler(localized_strings, new SearchEngineManagerHandler()); + AddOptionsPageUIHandler(localized_strings, new ImportDataHandler()); + AddOptionsPageUIHandler(localized_strings, new StopSyncingHandler()); AddOptionsPageUIHandler(localized_strings, new SyncOptionsHandler()); #if defined(OS_CHROMEOS) AddOptionsPageUIHandler(localized_strings, diff --git a/chrome/browser/dom_ui/personal_options_handler.cc b/chrome/browser/dom_ui/personal_options_handler.cc index 1db6a8a..8e39ba5 100644 --- a/chrome/browser/dom_ui/personal_options_handler.cc +++ b/chrome/browser/dom_ui/personal_options_handler.cc @@ -32,11 +32,6 @@ PersonalOptionsHandler::~PersonalOptionsHandler() { void PersonalOptionsHandler::GetLocalizedValues( DictionaryValue* localized_strings) { - FilePath user_data_dir; - PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); - ProfileManager* profile_manager = g_browser_process->profile_manager(); - Profile* profile = profile_manager->GetDefaultProfile(user_data_dir); - ProfileSyncService* service = profile->GetProfileSyncService(); DCHECK(localized_strings); //Personal Stuff page @@ -47,10 +42,6 @@ void PersonalOptionsHandler::GetLocalizedValues( l10n_util::GetString(IDS_PRODUCT_NAME))); localized_strings->SetString(L"start_sync", l10n_util::GetString(IDS_SYNC_START_SYNC_BUTTON_LABEL)); - localized_strings->SetString(L"synced_to_user_with_time", - l10n_util::GetStringF(IDS_SYNC_ACCOUNT_SYNCED_TO_USER_WITH_TIME, - UTF16ToWide(service->GetAuthenticatedUsername()), - service->GetLastSyncedTimeString())); localized_strings->SetString(L"sync_customize", l10n_util::GetString(IDS_SYNC_CUSTOMIZE_BUTTON_LABEL)); localized_strings->SetString(L"stop_sync", @@ -103,3 +94,26 @@ void PersonalOptionsHandler::GetLocalizedValues( l10n_util::GetString(IDS_THEMES_DEFAULT_THEME_LABEL)); #endif } + +void PersonalOptionsHandler::RegisterMessages() { + DCHECK(dom_ui_); + dom_ui_->RegisterMessageCallback( + "getSyncStatus", + NewCallback(this,&PersonalOptionsHandler::SetSyncStatusUIString)); +} + +void PersonalOptionsHandler::SetSyncStatusUIString(const Value* value) { + DCHECK(dom_ui_); + + ProfileSyncService* service = dom_ui_->GetProfile()->GetProfileSyncService(); + if(service != NULL && ProfileSyncService::IsSyncEnabled()) { + scoped_ptr<Value> status_string(Value::CreateStringValue( + l10n_util::GetStringF(IDS_SYNC_ACCOUNT_SYNCED_TO_USER_WITH_TIME, + UTF16ToWide(service->GetAuthenticatedUsername()), + service->GetLastSyncedTimeString()))); + + dom_ui_->CallJavascriptFunction( + L"PersonalOptions.syncStatusCallback", + *(status_string.get())); + } +} diff --git a/chrome/browser/dom_ui/personal_options_handler.h b/chrome/browser/dom_ui/personal_options_handler.h index e667bf8..93f898d 100644 --- a/chrome/browser/dom_ui/personal_options_handler.h +++ b/chrome/browser/dom_ui/personal_options_handler.h @@ -7,6 +7,7 @@ #pragma once #include "chrome/browser/dom_ui/options_ui.h" +#include "chrome/browser/sync/profile_sync_service.h" // Chrome personal options page UI handler. class PersonalOptionsHandler : public OptionsPageUIHandler { @@ -17,7 +18,12 @@ class PersonalOptionsHandler : public OptionsPageUIHandler { // OptionsUIHandler implementation. virtual void GetLocalizedValues(DictionaryValue* localized_strings); + // DOMMessageHandler implementation. + virtual void RegisterMessages(); + private: + virtual void SetSyncStatusUIString(const Value* value); + DISALLOW_COPY_AND_ASSIGN(PersonalOptionsHandler); }; diff --git a/chrome/browser/dom_ui/stop_syncing_handler.cc b/chrome/browser/dom_ui/stop_syncing_handler.cc new file mode 100644 index 0000000..95df28f --- /dev/null +++ b/chrome/browser/dom_ui/stop_syncing_handler.cc @@ -0,0 +1,48 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/dom_ui/stop_syncing_handler.h" + +#include "app/l10n_util.h" +#include "base/basictypes.h" +#include "base/values.h" +#include "base/callback.h" +#include "grit/chromium_strings.h" +#include "grit/generated_resources.h" +#include "chrome/browser/sync/profile_sync_service.h" +#include "chrome/browser/profile.h" +#include "chrome/browser/profile_manager.h" + +StopSyncingHandler::StopSyncingHandler() { +} + +StopSyncingHandler::~StopSyncingHandler() { +} + +void StopSyncingHandler::GetLocalizedValues( + DictionaryValue* localized_strings) { + DCHECK(localized_strings); + localized_strings->SetString(L"stop_syncing_explanation", + l10n_util::GetStringF(IDS_SYNC_STOP_SYNCING_EXPLANATION_LABEL, + l10n_util::GetString(IDS_PRODUCT_NAME))); + localized_strings->SetString(L"stop_syncing_title", + l10n_util::GetString(IDS_SYNC_STOP_SYNCING_DIALOG_TITLE)); + localized_strings->SetString(L"stop_syncing_confirm", + l10n_util::GetString(IDS_SYNC_STOP_SYNCING_CONFIRM_BUTTON_LABEL)); +} + +void StopSyncingHandler::RegisterMessages() { + DCHECK(dom_ui_); + dom_ui_->RegisterMessageCallback("stopSyncing", + NewCallback(this, &StopSyncingHandler::StopSyncing)); +} + +void StopSyncingHandler::StopSyncing(const Value* value){ + DCHECK(dom_ui_); + ProfileSyncService* service = dom_ui_->GetProfile()->GetProfileSyncService(); + if(service != NULL && ProfileSyncService::IsSyncEnabled()) { + service->DisableForUser(); + ProfileSyncService::SyncEvent(ProfileSyncService::STOP_FROM_OPTIONS); + } +} diff --git a/chrome/browser/dom_ui/stop_syncing_handler.h b/chrome/browser/dom_ui/stop_syncing_handler.h new file mode 100644 index 0000000..f97132b --- /dev/null +++ b/chrome/browser/dom_ui/stop_syncing_handler.h @@ -0,0 +1,28 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_DOM_UI_STOP_SYNCING_HANDLER_H_ +#define CHROME_BROWSER_DOM_UI_STOP_SYNCING_HANDLER_H_ + +#include "chrome/browser/dom_ui/options_ui.h" + +// Chrome personal stuff stop syncing overlay UI handler. +class StopSyncingHandler : public OptionsPageUIHandler { + public: + StopSyncingHandler(); + virtual ~StopSyncingHandler(); + + // OptionsUIHandler implementation. + virtual void GetLocalizedValues(DictionaryValue* localized_strings); + + // DOMMessageHandler implementation. + virtual void RegisterMessages(); + + private: + void StopSyncing(const Value* value); + + DISALLOW_COPY_AND_ASSIGN(StopSyncingHandler); +}; + +#endif // CHROME_BROWSER_DOM_UI_STOP_SYNCING_HANDLER_H_ |