| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/options/import_data_handler.h" | 5 #include "chrome/browser/ui/webui/settings/settings_import_data_handler.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| 11 | 11 |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/bind_helpers.h" | 13 #include "base/bind_helpers.h" |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/strings/string16.h" | 15 #include "base/strings/string16.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 26 #include "chrome/browser/ui/browser_finder.h" | 26 #include "chrome/browser/ui/browser_finder.h" |
| 27 #include "chrome/browser/ui/browser_window.h" | 27 #include "chrome/browser/ui/browser_window.h" |
| 28 #include "chrome/browser/ui/chrome_select_file_policy.h" | 28 #include "chrome/browser/ui/chrome_select_file_policy.h" |
| 29 #include "chrome/grit/chromium_strings.h" | 29 #include "chrome/grit/chromium_strings.h" |
| 30 #include "chrome/grit/generated_resources.h" | 30 #include "chrome/grit/generated_resources.h" |
| 31 #include "content/public/browser/browser_thread.h" | 31 #include "content/public/browser/browser_thread.h" |
| 32 #include "content/public/browser/web_ui.h" | 32 #include "content/public/browser/web_ui.h" |
| 33 | 33 |
| 34 using content::BrowserThread; | 34 using content::BrowserThread; |
| 35 | 35 |
| 36 namespace options { | 36 namespace settings { |
| 37 | 37 |
| 38 ImportDataHandler::ImportDataHandler() | 38 ImportDataHandler::ImportDataHandler() |
| 39 : importer_host_(NULL), | 39 : importer_host_(NULL), import_did_succeed_(false) { |
| 40 import_did_succeed_(false) { | |
| 41 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 40 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 42 } | 41 } |
| 43 | 42 |
| 44 ImportDataHandler::~ImportDataHandler() { | 43 ImportDataHandler::~ImportDataHandler() { |
| 45 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 44 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 46 | 45 |
| 47 if (importer_host_) | 46 if (importer_host_) |
| 48 importer_host_->set_observer(NULL); | 47 importer_host_->set_observer(NULL); |
| 49 | 48 |
| 50 if (select_file_dialog_.get()) | 49 if (select_file_dialog_.get()) |
| 51 select_file_dialog_->ListenerDestroyed(); | 50 select_file_dialog_->ListenerDestroyed(); |
| 52 } | 51 } |
| 53 | 52 |
| 54 void ImportDataHandler::GetLocalizedValues( | 53 void ImportDataHandler::InitializeDialog(const base::ListValue* args) { |
| 55 base::DictionaryValue* localized_strings) { | 54 AllowJavascript(); |
| 56 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
| 57 DCHECK(localized_strings); | |
| 58 | |
| 59 static OptionsStringResource resources[] = { | |
| 60 {"importFromLabel", IDS_IMPORT_FROM_LABEL}, | |
| 61 {"importLoading", IDS_IMPORT_LOADING_PROFILES}, | |
| 62 {"importDescription", IDS_IMPORT_ITEMS_LABEL}, | |
| 63 {"importHistory", IDS_IMPORT_HISTORY_CHKBOX}, | |
| 64 {"importFavorites", IDS_IMPORT_FAVORITES_CHKBOX}, | |
| 65 {"importSearch", IDS_IMPORT_SEARCH_ENGINES_CHKBOX}, | |
| 66 {"importPasswords", IDS_IMPORT_PASSWORDS_CHKBOX}, | |
| 67 {"importAutofillFormData", IDS_IMPORT_AUTOFILL_FORM_DATA_CHKBOX}, | |
| 68 {"importChooseFile", IDS_IMPORT_CHOOSE_FILE}, | |
| 69 {"importCommit", IDS_IMPORT_COMMIT}, | |
| 70 {"noProfileFound", IDS_IMPORT_NO_PROFILE_FOUND}, | |
| 71 {"importSucceeded", IDS_IMPORT_SUCCEEDED}, | |
| 72 {"findYourImportedBookmarks", IDS_IMPORT_FIND_YOUR_BOOKMARKS}, | |
| 73 }; | |
| 74 | |
| 75 RegisterStrings(localized_strings, resources, arraysize(resources)); | |
| 76 RegisterTitle(localized_strings, "importDataOverlay", | |
| 77 IDS_IMPORT_SETTINGS_TITLE); | |
| 78 } | |
| 79 | |
| 80 void ImportDataHandler::InitializeHandler() { | |
| 81 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
| 82 | 55 |
| 83 importer_list_.reset(new ImporterList()); | 56 importer_list_.reset(new ImporterList()); |
| 84 importer_list_->DetectSourceProfiles( | 57 importer_list_->DetectSourceProfiles( |
| 85 g_browser_process->GetApplicationLocale(), | 58 g_browser_process->GetApplicationLocale(), |
| 86 true, // include_interactive_profiles? | 59 true, // include_interactive_profiles? |
| 87 base::Bind(&ImportDataHandler::InitializePage, base::Unretained(this))); | 60 base::Bind(&ImportDataHandler::SendBrowserProfileData, |
| 61 base::Unretained(this))); |
| 88 } | 62 } |
| 89 | 63 |
| 90 void ImportDataHandler::RegisterMessages() { | 64 void ImportDataHandler::RegisterMessages() { |
| 91 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 65 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 92 | 66 |
| 93 web_ui()->RegisterMessageCallback( | 67 web_ui()->RegisterMessageCallback( |
| 68 "initializeImportDialog", |
| 69 base::Bind(&ImportDataHandler::InitializeDialog, base::Unretained(this))); |
| 70 web_ui()->RegisterMessageCallback( |
| 94 "importData", | 71 "importData", |
| 95 base::Bind(&ImportDataHandler::ImportData, base::Unretained(this))); | 72 base::Bind(&ImportDataHandler::ImportData, base::Unretained(this))); |
| 96 web_ui()->RegisterMessageCallback( | 73 web_ui()->RegisterMessageCallback( |
| 97 "chooseBookmarksFile", | 74 "chooseBookmarksFile", |
| 98 base::Bind(&ImportDataHandler::HandleChooseBookmarksFile, | 75 base::Bind(&ImportDataHandler::HandleChooseBookmarksFile, |
| 99 base::Unretained(this))); | 76 base::Unretained(this))); |
| 100 } | 77 } |
| 101 | 78 |
| 79 void ImportDataHandler::OnJavascriptDisallowed() { |
| 80 // Cancels outstanding profile list detections. |
| 81 importer_list_.reset(); |
| 82 |
| 83 // Stops listening to updates from any ongoing imports. |
| 84 if (importer_host_) |
| 85 importer_host_->set_observer(NULL); |
| 86 } |
| 87 |
| 102 void ImportDataHandler::StartImport( | 88 void ImportDataHandler::StartImport( |
| 103 const importer::SourceProfile& source_profile, | 89 const importer::SourceProfile& source_profile, |
| 104 uint16_t imported_items) { | 90 uint16_t imported_items) { |
| 105 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 91 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 106 | 92 |
| 107 if (!imported_items) | 93 if (!imported_items) |
| 108 return; | 94 return; |
| 109 | 95 |
| 110 // If another import is already ongoing, let it finish silently. | 96 // If another import is already ongoing, let it finish silently. |
| 111 if (importer_host_) | 97 if (importer_host_) |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 | 148 |
| 163 uint16_t imported_items = (selected_items & supported_items); | 149 uint16_t imported_items = (selected_items & supported_items); |
| 164 if (imported_items) { | 150 if (imported_items) { |
| 165 StartImport(source_profile, imported_items); | 151 StartImport(source_profile, imported_items); |
| 166 } else { | 152 } else { |
| 167 LOG(WARNING) << "There were no settings to import from '" | 153 LOG(WARNING) << "There were no settings to import from '" |
| 168 << source_profile.importer_name << "'."; | 154 << source_profile.importer_name << "'."; |
| 169 } | 155 } |
| 170 } | 156 } |
| 171 | 157 |
| 172 void ImportDataHandler::InitializePage() { | 158 void ImportDataHandler::SendBrowserProfileData() { |
| 173 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 159 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 174 | 160 |
| 175 base::ListValue browser_profiles; | 161 base::ListValue browser_profiles; |
| 176 for (size_t i = 0; i < importer_list_->count(); ++i) { | 162 for (size_t i = 0; i < importer_list_->count(); ++i) { |
| 177 const importer::SourceProfile& source_profile = | 163 const importer::SourceProfile& source_profile = |
| 178 importer_list_->GetSourceProfileAt(i); | 164 importer_list_->GetSourceProfileAt(i); |
| 179 uint16_t browser_services = source_profile.services_supported; | 165 uint16_t browser_services = source_profile.services_supported; |
| 180 | 166 |
| 181 std::unique_ptr<base::DictionaryValue> browser_profile( | 167 std::unique_ptr<base::DictionaryValue> browser_profile( |
| 182 new base::DictionaryValue()); | 168 new base::DictionaryValue()); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 select_file_dialog_->SelectFile(ui::SelectFileDialog::SELECT_OPEN_FILE, | 248 select_file_dialog_->SelectFile(ui::SelectFileDialog::SELECT_OPEN_FILE, |
| 263 base::string16(), | 249 base::string16(), |
| 264 base::FilePath(), | 250 base::FilePath(), |
| 265 &file_type_info, | 251 &file_type_info, |
| 266 0, | 252 0, |
| 267 base::FilePath::StringType(), | 253 base::FilePath::StringType(), |
| 268 browser->window()->GetNativeWindow(), | 254 browser->window()->GetNativeWindow(), |
| 269 NULL); | 255 NULL); |
| 270 } | 256 } |
| 271 | 257 |
| 272 } // namespace options | 258 } // namespace settings |
| OLD | NEW |