OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/options/import_data_handler.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "base/strings/string16.h" | 13 #include "base/strings/string16.h" |
14 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
15 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
16 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
17 #include "base/threading/thread_restrictions.h" | 17 #include "base/threading/thread_restrictions.h" |
18 #include "base/values.h" | 18 #include "base/values.h" |
19 #include "chrome/browser/browser_process.h" | 19 #include "chrome/browser/browser_process.h" |
20 #include "chrome/browser/importer/external_process_importer_host.h" | 20 #include "chrome/browser/importer/external_process_importer_host.h" |
21 #include "chrome/browser/importer/importer_list.h" | 21 #include "chrome/browser/importer/importer_list.h" |
22 #include "chrome/browser/importer/importer_uma.h" | 22 #include "chrome/browser/importer/importer_uma.h" |
23 #include "chrome/browser/profiles/profile.h" | 23 #include "chrome/browser/profiles/profile.h" |
24 #include "chrome/browser/ui/browser_finder.h" | 24 #include "chrome/browser/ui/browser_finder.h" |
25 #include "chrome/browser/ui/browser_window.h" | |
26 #include "chrome/browser/ui/chrome_select_file_policy.h" | |
25 #include "content/public/browser/web_ui.h" | 27 #include "content/public/browser/web_ui.h" |
26 #include "grit/chromium_strings.h" | 28 #include "grit/chromium_strings.h" |
27 #include "grit/generated_resources.h" | 29 #include "grit/generated_resources.h" |
28 #include "ui/base/l10n/l10n_util.h" | 30 #include "ui/base/l10n/l10n_util.h" |
29 | 31 |
30 namespace options { | 32 namespace options { |
31 | 33 |
32 ImportDataHandler::ImportDataHandler() : importer_host_(NULL), | 34 ImportDataHandler::ImportDataHandler() : importer_host_(NULL), |
33 import_did_succeed_(false) { | 35 import_did_succeed_(false) { |
34 } | 36 } |
35 | 37 |
36 ImportDataHandler::~ImportDataHandler() { | 38 ImportDataHandler::~ImportDataHandler() { |
37 if (importer_list_.get()) | 39 if (importer_list_) |
38 importer_list_->set_observer(NULL); | 40 importer_list_->set_observer(NULL); |
39 | 41 |
40 if (importer_host_) | 42 if (importer_host_) |
41 importer_host_->set_observer(NULL); | 43 importer_host_->set_observer(NULL); |
44 | |
45 if (select_file_dialog_) | |
46 select_file_dialog_->ListenerDestroyed(); | |
42 } | 47 } |
43 | 48 |
44 void ImportDataHandler::GetLocalizedValues(DictionaryValue* localized_strings) { | 49 void ImportDataHandler::GetLocalizedValues(DictionaryValue* localized_strings) { |
45 DCHECK(localized_strings); | 50 DCHECK(localized_strings); |
46 | 51 |
47 static OptionsStringResource resources[] = { | 52 static OptionsStringResource resources[] = { |
48 { "importFromLabel", IDS_IMPORT_FROM_LABEL }, | 53 { "importFromLabel", IDS_IMPORT_FROM_LABEL }, |
49 { "importLoading", IDS_IMPORT_LOADING_PROFILES }, | 54 { "importLoading", IDS_IMPORT_LOADING_PROFILES }, |
50 { "importDescription", IDS_IMPORT_ITEMS_LABEL }, | 55 { "importDescription", IDS_IMPORT_ITEMS_LABEL }, |
51 { "importHistory", IDS_IMPORT_HISTORY_CHKBOX }, | 56 { "importHistory", IDS_IMPORT_HISTORY_CHKBOX }, |
52 { "importFavorites", IDS_IMPORT_FAVORITES_CHKBOX }, | 57 { "importFavorites", IDS_IMPORT_FAVORITES_CHKBOX }, |
53 { "importSearch", IDS_IMPORT_SEARCH_ENGINES_CHKBOX }, | 58 { "importSearch", IDS_IMPORT_SEARCH_ENGINES_CHKBOX }, |
54 { "importPasswords", IDS_IMPORT_PASSWORDS_CHKBOX }, | 59 { "importPasswords", IDS_IMPORT_PASSWORDS_CHKBOX }, |
60 { "importChooseFile", IDS_IMPORT_CHOOSE_FILE }, | |
55 { "importCommit", IDS_IMPORT_COMMIT }, | 61 { "importCommit", IDS_IMPORT_COMMIT }, |
56 { "noProfileFound", IDS_IMPORT_NO_PROFILE_FOUND }, | 62 { "noProfileFound", IDS_IMPORT_NO_PROFILE_FOUND }, |
57 { "importSucceeded", IDS_IMPORT_SUCCEEDED }, | 63 { "importSucceeded", IDS_IMPORT_SUCCEEDED }, |
58 { "findYourImportedBookmarks", IDS_IMPORT_FIND_YOUR_BOOKMARKS }, | 64 { "findYourImportedBookmarks", IDS_IMPORT_FIND_YOUR_BOOKMARKS }, |
59 { "macPasswordKeychain", IDS_IMPORT_PASSWORD_KEYCHAIN_WARNING }, | 65 { "macPasswordKeychain", IDS_IMPORT_PASSWORD_KEYCHAIN_WARNING }, |
60 }; | 66 }; |
61 | 67 |
62 RegisterStrings(localized_strings, resources, arraysize(resources)); | 68 RegisterStrings(localized_strings, resources, arraysize(resources)); |
63 RegisterTitle(localized_strings, "importDataOverlay", | 69 RegisterTitle(localized_strings, "importDataOverlay", |
64 IDS_IMPORT_SETTINGS_TITLE); | 70 IDS_IMPORT_SETTINGS_TITLE); |
65 } | 71 } |
66 | 72 |
67 void ImportDataHandler::InitializeHandler() { | 73 void ImportDataHandler::InitializeHandler() { |
68 importer_list_ = new ImporterList(); | 74 importer_list_ = new ImporterList(); |
69 importer_list_->DetectSourceProfiles( | 75 importer_list_->DetectSourceProfiles( |
70 g_browser_process->GetApplicationLocale(), this); | 76 g_browser_process->GetApplicationLocale(), this); |
71 } | 77 } |
72 | 78 |
73 void ImportDataHandler::RegisterMessages() { | 79 void ImportDataHandler::RegisterMessages() { |
74 web_ui()->RegisterMessageCallback("importData", | 80 web_ui()->RegisterMessageCallback( |
81 "importData", | |
75 base::Bind(&ImportDataHandler::ImportData, base::Unretained(this))); | 82 base::Bind(&ImportDataHandler::ImportData, base::Unretained(this))); |
83 web_ui()->RegisterMessageCallback( | |
84 "chooseBookmarksFile", | |
85 base::Bind(&ImportDataHandler::HandleChooseBookmarksFile, | |
86 base::Unretained(this))); | |
76 } | 87 } |
77 | 88 |
78 void ImportDataHandler::ImportData(const ListValue* args) { | 89 void ImportDataHandler::ImportData(const ListValue* args) { |
79 std::string string_value; | 90 std::string string_value; |
80 | 91 |
81 int browser_index; | 92 int browser_index; |
82 if (!args->GetString(0, &string_value) || | 93 if (!args->GetString(0, &string_value) || |
83 !base::StringToInt(string_value, &browser_index)) { | 94 !base::StringToInt(string_value, &browser_index)) { |
84 NOTREACHED(); | 95 NOTREACHED(); |
85 return; | 96 return; |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
172 // TODO(csilv): show progress detail in the web view. | 183 // TODO(csilv): show progress detail in the web view. |
173 } | 184 } |
174 | 185 |
175 void ImportDataHandler::ImportItemEnded(importer::ImportItem item) { | 186 void ImportDataHandler::ImportItemEnded(importer::ImportItem item) { |
176 // TODO(csilv): show progress detail in the web view. | 187 // TODO(csilv): show progress detail in the web view. |
177 import_did_succeed_ = true; | 188 import_did_succeed_ = true; |
178 } | 189 } |
179 | 190 |
180 void ImportDataHandler::ImportEnded() { | 191 void ImportDataHandler::ImportEnded() { |
181 importer_host_->set_observer(NULL); | 192 importer_host_->set_observer(NULL); |
182 importer_host_ = NULL; | 193 importer_host_ = NULL; |
gab
2013/09/17 22:06:00
I just realized that the same ImportDataHandler li
gab
2013/09/17 22:52:20
Handling this myself in https://codereview.chromiu
| |
183 | 194 |
184 if (import_did_succeed_) { | 195 if (import_did_succeed_) { |
185 web_ui()->CallJavascriptFunction("ImportDataOverlay.confirmSuccess"); | 196 web_ui()->CallJavascriptFunction("ImportDataOverlay.confirmSuccess"); |
186 } else { | 197 } else { |
187 base::FundamentalValue state(false); | 198 base::FundamentalValue state(false); |
188 web_ui()->CallJavascriptFunction("ImportDataOverlay.setImportingState", | 199 web_ui()->CallJavascriptFunction("ImportDataOverlay.setImportingState", |
189 state); | 200 state); |
190 web_ui()->CallJavascriptFunction("ImportDataOverlay.dismiss"); | 201 web_ui()->CallJavascriptFunction("ImportDataOverlay.dismiss"); |
191 } | 202 } |
192 } | 203 } |
193 | 204 |
205 void ImportDataHandler::FileSelected(const base::FilePath& path, | |
206 int index, | |
gab
2013/09/17 22:06:00
Comment out unused parameter, i.e.:
int /* index *
gab
2013/09/17 22:52:20
Handling this myself in https://codereview.chromiu
| |
207 void* params) { | |
gab
2013/09/17 22:06:00
Same for this parameter.
gab
2013/09/17 22:52:20
Handling this myself in https://codereview.chromiu
| |
208 base::FundamentalValue importing(true); | |
209 web_ui()->CallJavascriptFunction("ImportDataOverlay.setImportingState", | |
210 importing); | |
211 import_did_succeed_ = false; | |
212 | |
213 importer_host_ = new ExternalProcessImporterHost(); | |
gab
2013/09/17 22:06:00
Move 213-223 in a common method used by both this
gab
2013/09/17 22:52:20
Handling this myself in https://codereview.chromiu
| |
214 importer_host_->set_observer(this); | |
215 | |
216 importer::SourceProfile source_profile; | |
217 source_profile.importer_type = importer::TYPE_BOOKMARKS_FILE; | |
218 source_profile.source_path = path; | |
219 | |
220 Profile* profile = Profile::FromWebUI(web_ui()); | |
221 | |
222 importer_host_->StartImportSettings( | |
223 source_profile, profile, importer::FAVORITES, new ProfileWriter(profile)); | |
224 } | |
225 | |
226 void ImportDataHandler::HandleChooseBookmarksFile(const base::ListValue* args) { | |
227 DCHECK(args && args->empty()); | |
228 select_file_dialog_ = ui::SelectFileDialog::Create( | |
229 this, new ChromeSelectFilePolicy(web_ui()->GetWebContents())); | |
230 | |
231 ui::SelectFileDialog::FileTypeInfo file_type_info; | |
232 file_type_info.extensions.resize(1); | |
233 file_type_info.extensions[0].push_back(FILE_PATH_LITERAL("html")); | |
234 | |
235 Browser* browser = | |
236 chrome::FindBrowserWithWebContents(web_ui()->GetWebContents()); | |
237 | |
238 select_file_dialog_->SelectFile(ui::SelectFileDialog::SELECT_OPEN_FILE, | |
239 base::string16(), | |
240 base::FilePath(), | |
241 &file_type_info, | |
242 0, | |
243 base::FilePath::StringType(), | |
244 browser->window()->GetNativeWindow(), | |
245 NULL); | |
246 } | |
247 | |
194 } // namespace options | 248 } // namespace options |
OLD | NEW |