summaryrefslogtreecommitdiffstats
path: root/chrome/browser/dom_ui
diff options
context:
space:
mode:
authorcsilv@chromium.org <csilv@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-09-15 17:42:57 +0000
committercsilv@chromium.org <csilv@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-09-15 17:42:57 +0000
commitc3482e2107a6ad69db6d2c6de266f4ad4d27cc6b (patch)
treebdc559cb804dd086436d488b8bfb8f7c11ca4ded /chrome/browser/dom_ui
parent386c7350ed9b017020e84d4b1783c318e68418ab (diff)
downloadchromium_src-c3482e2107a6ad69db6d2c6de266f4ad4d27cc6b.zip
chromium_src-c3482e2107a6ad69db6d2c6de266f4ad4d27cc6b.tar.gz
chromium_src-c3482e2107a6ad69db6d2c6de266f4ad4d27cc6b.tar.bz2
dom-ui options: Import dialog improvements
- Fixed so that import window is setup correctly when invoked directly from a command. - Correctly enable/disable checkboxes based on what services are supported by a profile. - Changes to avoid relying on the exact order of checkboxes in the DOM. - Changes to use ExternalProcessImporterHost instead of ImporterHost (MacOS X). - Put ok/cancel buttons in a button strip. BUG=none TEST=verify Import dialog works properly via dom-ui (--enable-tabbed-options) Review URL: http://codereview.chromium.org/3363012 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@59514 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/dom_ui')
-rw-r--r--chrome/browser/dom_ui/import_data_handler.cc133
-rw-r--r--chrome/browser/dom_ui/import_data_handler.h11
2 files changed, 86 insertions, 58 deletions
diff --git a/chrome/browser/dom_ui/import_data_handler.cc b/chrome/browser/dom_ui/import_data_handler.cc
index e41fc21..0cf574c 100644
--- a/chrome/browser/dom_ui/import_data_handler.cc
+++ b/chrome/browser/dom_ui/import_data_handler.cc
@@ -8,6 +8,7 @@
#include "base/basictypes.h"
#include "base/scoped_ptr.h"
#include "base/string16.h"
+#include "base/string_number_conversions.h"
#include "base/string_util.h"
#include "base/utf_string_conversions.h"
#include "base/values.h"
@@ -18,17 +19,12 @@
#include "grit/generated_resources.h"
#include "chrome/browser/importer/importer_data_types.h"
-ImportDataHandler::ImportDataHandler() {
+ImportDataHandler::ImportDataHandler() : importer_host_(NULL) {
}
ImportDataHandler::~ImportDataHandler() {
- if (importer_host_ != NULL) {
+ if (importer_host_)
importer_host_->SetObserver(NULL);
- importer_host_ = NULL;
- }
-}
-
-void ImportDataHandler::Initialize() {
}
void ImportDataHandler::GetLocalizedValues(
@@ -54,80 +50,113 @@ void ImportDataHandler::GetLocalizedValues(
l10n_util::GetStringUTF16(IDS_IMPORT_NO_PROFILE_FOUND));
}
-void ImportDataHandler::RegisterMessages() {
- dom_ui_->RegisterMessageCallback(
- "loadImporter", NewCallback(this, &ImportDataHandler::LoadImporter));
- dom_ui_->RegisterMessageCallback(
- "importData", NewCallback(this, &ImportDataHandler::ImportData));
-}
-
-void ImportDataHandler::LoadImporter(const ListValue* args) {
- importer_host_ = new ImporterHost();
- DetectSupportedBrowsers();
-}
-
-void ImportDataHandler::DetectSupportedBrowsers() {
- ListValue supported_browsers;
- int profiles_count = importer_host_->GetAvailableProfileCount();
+void ImportDataHandler::Initialize() {
+ importer_list_.reset(new ImporterList);
+ importer_list_->DetectSourceProfiles();
+ int profiles_count = importer_list_->GetAvailableProfileCount();
+ ListValue browser_profiles;
if (profiles_count > 0) {
for (int i = 0; i < profiles_count; i++) {
- string16 profile =
- WideToUTF16Hack(importer_host_->GetSourceProfileNameAt(i));
- DictionaryValue* entry = new DictionaryValue();
- entry->SetString("name", profile);
- entry->SetInteger("index", i);
- supported_browsers.Append(entry);
+ const importer::ProfileInfo& source_profile =
+ importer_list_->GetSourceProfileInfoAt(i);
+ string16 browser_name = WideToUTF16Hack(source_profile.description);
+ uint16 browser_services = source_profile.services_supported;
+
+ DictionaryValue* browser_profile = new DictionaryValue();
+ browser_profile->SetString("name", browser_name);
+ browser_profile->SetInteger("index", i);
+ browser_profile->SetBoolean("history",
+ (browser_services & importer::HISTORY) != 0);
+ browser_profile->SetBoolean("favorites",
+ (browser_services & importer::FAVORITES) != 0);
+ browser_profile->SetBoolean("passwords",
+ (browser_services & importer::PASSWORDS) != 0);
+ browser_profile->SetBoolean("search",
+ (browser_services & importer::SEARCH_ENGINES) != 0);
+
+ browser_profiles.Append(browser_profile);
}
}
dom_ui_->CallJavascriptFunction(
L"options.ImportDataOverlay.updateSupportedBrowsers",
- supported_browsers);
+ browser_profiles);
+}
+
+void ImportDataHandler::RegisterMessages() {
+ dom_ui_->RegisterMessageCallback(
+ "importData", NewCallback(this, &ImportDataHandler::ImportData));
}
void ImportDataHandler::ImportData(const ListValue* args) {
- std::string string_value = WideToUTF8(ExtractStringValue(args));
- CHECK(!string_value.empty());
- int browser_index = string_value[0] - '0';
+ std::string string_value;
- uint16 items = importer::NONE;
- if (string_value[1] == '1') {
- items |= importer::FAVORITES;
+ int browser_index;
+ if (!args->GetString(0, &string_value) ||
+ !base::StringToInt(string_value, &browser_index)) {
+ NOTREACHED();
+ return;
}
- if (string_value[2] == '1') {
- items |= importer::SEARCH_ENGINES;
+
+ uint16 selected_items = importer::NONE;
+ if (args->GetString(1, &string_value) && string_value == "true") {
+ selected_items |= importer::HISTORY;
+ }
+ if (args->GetString(2, &string_value) && string_value == "true") {
+ selected_items |= importer::FAVORITES;
}
- if (string_value[3] == '1') {
- items |= importer::PASSWORDS;
+ if (args->GetString(3, &string_value) && string_value == "true") {
+ selected_items |= importer::PASSWORDS;
}
- if (string_value[4] == '1') {
- items |= importer::HISTORY;
+ if (args->GetString(4, &string_value) && string_value == "true") {
+ selected_items |= importer::SEARCH_ENGINES;
}
const ProfileInfo& source_profile =
- importer_host_->GetSourceProfileInfoAt(browser_index);
- Profile* profile = dom_ui_->GetProfile();
-
- FundamentalValue state(true);
- dom_ui_->CallJavascriptFunction(
- L"ImportDataOverlay.setImportingState", state);
-
- importer_host_->SetObserver(this);
- importer_host_->StartImportSettings(source_profile, profile, items,
- new ProfileWriter(profile), false);
+ importer_list_->GetSourceProfileInfoAt(browser_index);
+ uint16 supported_items = source_profile.services_supported;
+
+ uint16 import_services = (selected_items & supported_items);
+ if (import_services) {
+ FundamentalValue state(true);
+ dom_ui_->CallJavascriptFunction(
+ L"ImportDataOverlay.setImportingState", state);
+
+// TODO(csilv): Out-of-process import has only been qualified on MacOS X,
+// so we will only use it on that platform since it is required. Remove this
+// conditional logic once oop import is qualified for Linux/Windows.
+// http://crbug.com/22142
+#if defined(OS_MACOSX)
+ importer_host_ = new ExternalProcessImporterHost;
+#else
+ importer_host_ = new ImporterHost;
+#endif
+ importer_host_->SetObserver(this);
+ Profile* profile = dom_ui_->GetProfile();
+ importer_host_->StartImportSettings(source_profile, profile,
+ import_services,
+ new ProfileWriter(profile), false);
+ } else {
+ LOG(WARNING) << "There were no settings to import from '"
+ << source_profile.description << "'.";
+ }
}
void ImportDataHandler::ImportStarted() {
}
void ImportDataHandler::ImportItemStarted(importer::ImportItem item) {
+ // TODO(csilv): show progress detail in the web view.
}
void ImportDataHandler::ImportItemEnded(importer::ImportItem item) {
+ // TODO(csilv): show progress detail in the web view.
}
void ImportDataHandler::ImportEnded() {
- dom_ui_->CallJavascriptFunction(L"ImportDataOverlay.dismiss");
+ importer_host_->SetObserver(NULL);
importer_host_ = NULL;
+
+ dom_ui_->CallJavascriptFunction(L"ImportDataOverlay.dismiss");
}
diff --git a/chrome/browser/dom_ui/import_data_handler.h b/chrome/browser/dom_ui/import_data_handler.h
index 85bf9be..4f28d7b 100644
--- a/chrome/browser/dom_ui/import_data_handler.h
+++ b/chrome/browser/dom_ui/import_data_handler.h
@@ -15,28 +15,27 @@ class ImportDataHandler : public OptionsPageUIHandler,
ImportDataHandler();
virtual ~ImportDataHandler();
- virtual void Initialize();
-
// OptionsUIHandler implementation.
virtual void GetLocalizedValues(DictionaryValue* localized_strings);
+ virtual void Initialize();
// DOMMessageHandler implementation.
virtual void RegisterMessages();
private:
- void LoadImporter(const ListValue* args);
- void DetectSupportedBrowsers();
void ImportData(const ListValue* args);
- //Callback from ImporterHost. Close the Dialog.
+ // ImporterHost observer implementation.
virtual void ImportStarted();
virtual void ImportItemStarted(importer::ImportItem item);
virtual void ImportItemEnded(importer::ImportItem item);
virtual void ImportEnded();
+ scoped_ptr<ImporterList> importer_list_;
+
// If non-null it means importing is in progress. ImporterHost takes care
// of deleting itself when done import.
- scoped_refptr<ImporterHost> importer_host_;
+ ImporterHost* importer_host_; // weak
DISALLOW_COPY_AND_ASSIGN(ImportDataHandler);
};