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

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

Issue 22671003: Revert 216860 "Add option to import from bookmarks html file to ..." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: 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
« no previous file with comments | « trunk/src/chrome/browser/ui/webui/options/import_data_handler.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
27 #include "content/public/browser/web_ui.h" 25 #include "content/public/browser/web_ui.h"
28 #include "grit/chromium_strings.h" 26 #include "grit/chromium_strings.h"
29 #include "grit/generated_resources.h" 27 #include "grit/generated_resources.h"
30 #include "ui/base/l10n/l10n_util.h" 28 #include "ui/base/l10n/l10n_util.h"
31 29
32 namespace options { 30 namespace options {
33 31
34 ImportDataHandler::ImportDataHandler() : importer_host_(NULL), 32 ImportDataHandler::ImportDataHandler() : importer_host_(NULL),
35 import_did_succeed_(false) { 33 import_did_succeed_(false) {
36 } 34 }
37 35
38 ImportDataHandler::~ImportDataHandler() { 36 ImportDataHandler::~ImportDataHandler() {
39 if (importer_list_) 37 if (importer_list_.get())
40 importer_list_->set_observer(NULL); 38 importer_list_->set_observer(NULL);
41 39
42 if (importer_host_) 40 if (importer_host_)
43 importer_host_->set_observer(NULL); 41 importer_host_->set_observer(NULL);
44
45 if (select_file_dialog_)
46 select_file_dialog_->ListenerDestroyed();
47 } 42 }
48 43
49 void ImportDataHandler::GetLocalizedValues(DictionaryValue* localized_strings) { 44 void ImportDataHandler::GetLocalizedValues(DictionaryValue* localized_strings) {
50 DCHECK(localized_strings); 45 DCHECK(localized_strings);
51 46
52 static OptionsStringResource resources[] = { 47 static OptionsStringResource resources[] = {
53 { "importFromLabel", IDS_IMPORT_FROM_LABEL }, 48 { "importFromLabel", IDS_IMPORT_FROM_LABEL },
54 { "importLoading", IDS_IMPORT_LOADING_PROFILES }, 49 { "importLoading", IDS_IMPORT_LOADING_PROFILES },
55 { "importDescription", IDS_IMPORT_ITEMS_LABEL }, 50 { "importDescription", IDS_IMPORT_ITEMS_LABEL },
56 { "importHistory", IDS_IMPORT_HISTORY_CHKBOX }, 51 { "importHistory", IDS_IMPORT_HISTORY_CHKBOX },
57 { "importFavorites", IDS_IMPORT_FAVORITES_CHKBOX }, 52 { "importFavorites", IDS_IMPORT_FAVORITES_CHKBOX },
58 { "importSearch", IDS_IMPORT_SEARCH_ENGINES_CHKBOX }, 53 { "importSearch", IDS_IMPORT_SEARCH_ENGINES_CHKBOX },
59 { "importPasswords", IDS_IMPORT_PASSWORDS_CHKBOX }, 54 { "importPasswords", IDS_IMPORT_PASSWORDS_CHKBOX },
60 { "importChooseFile", IDS_IMPORT_CHOOSE_FILE },
61 { "importCommit", IDS_IMPORT_COMMIT }, 55 { "importCommit", IDS_IMPORT_COMMIT },
62 { "noProfileFound", IDS_IMPORT_NO_PROFILE_FOUND }, 56 { "noProfileFound", IDS_IMPORT_NO_PROFILE_FOUND },
63 { "importSucceeded", IDS_IMPORT_SUCCEEDED }, 57 { "importSucceeded", IDS_IMPORT_SUCCEEDED },
64 { "findYourImportedBookmarks", IDS_IMPORT_FIND_YOUR_BOOKMARKS }, 58 { "findYourImportedBookmarks", IDS_IMPORT_FIND_YOUR_BOOKMARKS },
65 { "macPasswordKeychain", IDS_IMPORT_PASSWORD_KEYCHAIN_WARNING }, 59 { "macPasswordKeychain", IDS_IMPORT_PASSWORD_KEYCHAIN_WARNING },
66 }; 60 };
67 61
68 RegisterStrings(localized_strings, resources, arraysize(resources)); 62 RegisterStrings(localized_strings, resources, arraysize(resources));
69 RegisterTitle(localized_strings, "importDataOverlay", 63 RegisterTitle(localized_strings, "importDataOverlay",
70 IDS_IMPORT_SETTINGS_TITLE); 64 IDS_IMPORT_SETTINGS_TITLE);
71 } 65 }
72 66
73 void ImportDataHandler::InitializeHandler() { 67 void ImportDataHandler::InitializeHandler() {
74 importer_list_ = new ImporterList(); 68 importer_list_ = new ImporterList();
75 importer_list_->DetectSourceProfiles( 69 importer_list_->DetectSourceProfiles(
76 g_browser_process->GetApplicationLocale(), this); 70 g_browser_process->GetApplicationLocale(), this);
77 } 71 }
78 72
79 void ImportDataHandler::RegisterMessages() { 73 void ImportDataHandler::RegisterMessages() {
80 web_ui()->RegisterMessageCallback( 74 web_ui()->RegisterMessageCallback("importData",
81 "importData",
82 base::Bind(&ImportDataHandler::ImportData, base::Unretained(this))); 75 base::Bind(&ImportDataHandler::ImportData, base::Unretained(this)));
83 web_ui()->RegisterMessageCallback(
84 "chooseBookmarksFile",
85 base::Bind(&ImportDataHandler::HandleChooseBookmarksFile,
86 base::Unretained(this)));
87 } 76 }
88 77
89 void ImportDataHandler::ImportData(const ListValue* args) { 78 void ImportDataHandler::ImportData(const ListValue* args) {
90 std::string string_value; 79 std::string string_value;
91 80
92 int browser_index; 81 int browser_index;
93 if (!args->GetString(0, &string_value) || 82 if (!args->GetString(0, &string_value) ||
94 !base::StringToInt(string_value, &browser_index)) { 83 !base::StringToInt(string_value, &browser_index)) {
95 NOTREACHED(); 84 NOTREACHED();
96 return; 85 return;
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 if (import_did_succeed_) { 184 if (import_did_succeed_) {
196 web_ui()->CallJavascriptFunction("ImportDataOverlay.confirmSuccess"); 185 web_ui()->CallJavascriptFunction("ImportDataOverlay.confirmSuccess");
197 } else { 186 } else {
198 base::FundamentalValue state(false); 187 base::FundamentalValue state(false);
199 web_ui()->CallJavascriptFunction("ImportDataOverlay.setImportingState", 188 web_ui()->CallJavascriptFunction("ImportDataOverlay.setImportingState",
200 state); 189 state);
201 web_ui()->CallJavascriptFunction("ImportDataOverlay.dismiss"); 190 web_ui()->CallJavascriptFunction("ImportDataOverlay.dismiss");
202 } 191 }
203 } 192 }
204 193
205 void ImportDataHandler::FileSelected(const base::FilePath& path,
206 int index,
207 void* params) {
208 base::FundamentalValue importing(true);
209 web_ui()->CallJavascriptFunction("ImportDataOverlay.setImportingState",
210 importing);
211 import_did_succeed_ = false;
212
213 importer_host_ = new ExternalProcessImporterHost();
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
248 } // namespace options 194 } // namespace options
OLDNEW
« no previous file with comments | « trunk/src/chrome/browser/ui/webui/options/import_data_handler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698