Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(588)

Side by Side Diff: chrome/browser/ui/webui/options/import_data_handler.cc

Issue 22332003: Add option to import from bookmarks html file to "Import Bookmarks..." dialog. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rm debug code Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 }; 65 };
60 66
61 RegisterStrings(localized_strings, resources, arraysize(resources)); 67 RegisterStrings(localized_strings, resources, arraysize(resources));
62 RegisterTitle(localized_strings, "importDataOverlay", 68 RegisterTitle(localized_strings, "importDataOverlay",
63 IDS_IMPORT_SETTINGS_TITLE); 69 IDS_IMPORT_SETTINGS_TITLE);
64 } 70 }
65 71
66 void ImportDataHandler::InitializeHandler() { 72 void ImportDataHandler::InitializeHandler() {
67 importer_list_ = new ImporterList(); 73 importer_list_ = new ImporterList();
68 importer_list_->DetectSourceProfiles( 74 importer_list_->DetectSourceProfiles(
69 g_browser_process->GetApplicationLocale(), this); 75 g_browser_process->GetApplicationLocale(), this);
70 } 76 }
71 77
72 void ImportDataHandler::RegisterMessages() { 78 void ImportDataHandler::RegisterMessages() {
73 web_ui()->RegisterMessageCallback("importData", 79 web_ui()->RegisterMessageCallback(
80 "importData",
74 base::Bind(&ImportDataHandler::ImportData, base::Unretained(this))); 81 base::Bind(&ImportDataHandler::ImportData, base::Unretained(this)));
82 web_ui()->RegisterMessageCallback(
83 "chooseBookmarksFile",
84 base::Bind(&ImportDataHandler::HandleChooseBookmarksFile,
85 base::Unretained(this)));
75 } 86 }
76 87
77 void ImportDataHandler::ImportData(const ListValue* args) { 88 void ImportDataHandler::ImportData(const ListValue* args) {
78 std::string string_value; 89 std::string string_value;
79 90
80 int browser_index; 91 int browser_index;
81 if (!args->GetString(0, &string_value) || 92 if (!args->GetString(0, &string_value) ||
82 !base::StringToInt(string_value, &browser_index)) { 93 !base::StringToInt(string_value, &browser_index)) {
83 NOTREACHED(); 94 NOTREACHED();
84 return; 95 return;
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 if (import_did_succeed_) { 187 if (import_did_succeed_) {
177 web_ui()->CallJavascriptFunction("ImportDataOverlay.confirmSuccess"); 188 web_ui()->CallJavascriptFunction("ImportDataOverlay.confirmSuccess");
178 } else { 189 } else {
179 base::FundamentalValue state(false); 190 base::FundamentalValue state(false);
180 web_ui()->CallJavascriptFunction("ImportDataOverlay.setImportingState", 191 web_ui()->CallJavascriptFunction("ImportDataOverlay.setImportingState",
181 state); 192 state);
182 web_ui()->CallJavascriptFunction("ImportDataOverlay.dismiss"); 193 web_ui()->CallJavascriptFunction("ImportDataOverlay.dismiss");
183 } 194 }
184 } 195 }
185 196
197 void ImportDataHandler::FileSelected(const base::FilePath& path,
198 int index,
199 void* params) {
200 base::FundamentalValue importing(true);
201 web_ui()->CallJavascriptFunction("ImportDataOverlay.setImportingState",
202 importing);
203 import_did_succeed_ = false;
204
205 importer_host_ = new ExternalProcessImporterHost();
206 importer_host_->set_observer(this);
207
208 importer::SourceProfile source_profile;
209 source_profile.importer_type = importer::TYPE_BOOKMARKS_FILE;
210 source_profile.source_path = path;
211
212 Profile* profile = Profile::FromWebUI(web_ui());
213
214 importer_host_->StartImportSettings(
215 source_profile, profile, importer::FAVORITES, new ProfileWriter(profile));
216 }
217
218 void ImportDataHandler::HandleChooseBookmarksFile(const base::ListValue* args) {
219 DCHECK(args && args->empty());
Dan Beam 2013/08/08 05:34:00 nit: ^ not particularly useful, I'd just remove
Ilya Sherman 2013/08/08 08:09:28 In fact, can the parameter be removed entirely?
Dan Beam 2013/08/08 21:33:11 no, but it could be commented out, i.e. const base
220 select_file_dialog_ = ui::SelectFileDialog::Create(
221 this, new ChromeSelectFilePolicy(web_ui()->GetWebContents()));
222
223 ui::SelectFileDialog::FileTypeInfo file_type_info;
224 file_type_info.extensions.resize(1);
225 file_type_info.extensions[0].push_back(FILE_PATH_LITERAL("html"));
226
227 Browser* browser =
228 chrome::FindBrowserWithWebContents(web_ui()->GetWebContents());
229
230 select_file_dialog_->SelectFile(ui::SelectFileDialog::SELECT_OPEN_FILE,
231 base::string16(),
232 base::FilePath(),
233 &file_type_info,
234 0,
235 base::FilePath::StringType(),
236 browser->window()->GetNativeWindow(),
237 NULL);
238 }
239
186 } // namespace options 240 } // namespace options
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698