OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/dom_ui/import_data_handler.h" | 5 #include "chrome/browser/dom_ui/import_data_handler.h" |
6 | 6 |
7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/scoped_ptr.h" | 9 #include "base/scoped_ptr.h" |
10 #include "base/string16.h" | 10 #include "base/string16.h" |
11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
13 #include "base/values.h" | 13 #include "base/values.h" |
14 #include "base/callback.h" | 14 #include "base/callback.h" |
15 #include "chrome/browser/pref_service.h" | 15 #include "chrome/browser/pref_service.h" |
16 #include "chrome/browser/profile.h" | 16 #include "chrome/browser/profile.h" |
17 #include "grit/chromium_strings.h" | 17 #include "grit/chromium_strings.h" |
18 #include "grit/generated_resources.h" | 18 #include "grit/generated_resources.h" |
19 #include "chrome/browser/importer/importer_data_types.h" | 19 #include "chrome/browser/importer/importer_data_types.h" |
20 | 20 |
21 ImportDataHandler::ImportDataHandler() { | 21 ImportDataHandler::ImportDataHandler() { |
22 } | 22 } |
23 | 23 |
24 ImportDataHandler::~ImportDataHandler() { | 24 ImportDataHandler::~ImportDataHandler() { |
| 25 if (importer_host_ != NULL) { |
| 26 importer_host_->SetObserver(NULL); |
| 27 importer_host_ = NULL; |
| 28 } |
25 } | 29 } |
26 | 30 |
27 void ImportDataHandler::Initialize() { | 31 void ImportDataHandler::Initialize() { |
28 importer_host_ = new ImporterHost(); | |
29 DetectSupportedBrowsers(); | |
30 } | 32 } |
31 | 33 |
32 void ImportDataHandler::GetLocalizedValues( | 34 void ImportDataHandler::GetLocalizedValues( |
33 DictionaryValue* localized_strings) { | 35 DictionaryValue* localized_strings) { |
34 DCHECK(localized_strings); | 36 DCHECK(localized_strings); |
35 localized_strings->SetString("import_data_title", | 37 localized_strings->SetString("import_data_title", |
36 l10n_util::GetStringUTF16(IDS_IMPORT_SETTINGS_TITLE)); | 38 l10n_util::GetStringUTF16(IDS_IMPORT_SETTINGS_TITLE)); |
37 localized_strings->SetString("import_from_label", | 39 localized_strings->SetString("import_from_label", |
38 l10n_util::GetStringUTF16(IDS_IMPORT_FROM_LABEL)); | 40 l10n_util::GetStringUTF16(IDS_IMPORT_FROM_LABEL)); |
39 localized_strings->SetString("import_commit", | 41 localized_strings->SetString("import_commit", |
40 l10n_util::GetStringUTF16(IDS_IMPORT_COMMIT)); | 42 l10n_util::GetStringUTF16(IDS_IMPORT_COMMIT)); |
41 localized_strings->SetString("import_description", | 43 localized_strings->SetString("import_description", |
42 l10n_util::GetStringUTF16(IDS_IMPORT_ITEMS_LABEL)); | 44 l10n_util::GetStringUTF16(IDS_IMPORT_ITEMS_LABEL)); |
43 localized_strings->SetString("import_favorites", | 45 localized_strings->SetString("import_favorites", |
44 l10n_util::GetStringUTF16(IDS_IMPORT_FAVORITES_CHKBOX)); | 46 l10n_util::GetStringUTF16(IDS_IMPORT_FAVORITES_CHKBOX)); |
45 localized_strings->SetString("import_search", | 47 localized_strings->SetString("import_search", |
46 l10n_util::GetStringUTF16(IDS_IMPORT_SEARCH_ENGINES_CHKBOX)); | 48 l10n_util::GetStringUTF16(IDS_IMPORT_SEARCH_ENGINES_CHKBOX)); |
47 localized_strings->SetString("import_passwords", | 49 localized_strings->SetString("import_passwords", |
48 l10n_util::GetStringUTF16(IDS_IMPORT_PASSWORDS_CHKBOX)); | 50 l10n_util::GetStringUTF16(IDS_IMPORT_PASSWORDS_CHKBOX)); |
49 localized_strings->SetString("import_history", | 51 localized_strings->SetString("import_history", |
50 l10n_util::GetStringUTF16(IDS_IMPORT_HISTORY_CHKBOX)); | 52 l10n_util::GetStringUTF16(IDS_IMPORT_HISTORY_CHKBOX)); |
51 localized_strings->SetString("no_profile_found", | 53 localized_strings->SetString("no_profile_found", |
52 l10n_util::GetStringUTF16(IDS_IMPORT_NO_PROFILE_FOUND)); | 54 l10n_util::GetStringUTF16(IDS_IMPORT_NO_PROFILE_FOUND)); |
53 } | 55 } |
54 | 56 |
55 void ImportDataHandler::RegisterMessages() { | 57 void ImportDataHandler::RegisterMessages() { |
56 dom_ui_->RegisterMessageCallback( | 58 dom_ui_->RegisterMessageCallback( |
| 59 "loadImporter", NewCallback(this, &ImportDataHandler::LoadImporter)); |
| 60 dom_ui_->RegisterMessageCallback( |
57 "importData", NewCallback(this, &ImportDataHandler::ImportData)); | 61 "importData", NewCallback(this, &ImportDataHandler::ImportData)); |
58 } | 62 } |
59 | 63 |
| 64 void ImportDataHandler::LoadImporter(const ListValue* args) { |
| 65 importer_host_ = new ImporterHost(); |
| 66 DetectSupportedBrowsers(); |
| 67 } |
| 68 |
60 void ImportDataHandler::DetectSupportedBrowsers() { | 69 void ImportDataHandler::DetectSupportedBrowsers() { |
61 ListValue supported_browsers; | 70 ListValue supported_browsers; |
62 int profiles_count = importer_host_->GetAvailableProfileCount(); | 71 int profiles_count = importer_host_->GetAvailableProfileCount(); |
63 | 72 |
64 if (profiles_count > 0) { | 73 if (profiles_count > 0) { |
65 for (int i = 0; i < profiles_count; i++) { | 74 for (int i = 0; i < profiles_count; i++) { |
66 string16 profile = | 75 string16 profile = |
67 WideToUTF16Hack(importer_host_->GetSourceProfileNameAt(i)); | 76 WideToUTF16Hack(importer_host_->GetSourceProfileNameAt(i)); |
68 DictionaryValue* entry = new DictionaryValue(); | 77 DictionaryValue* entry = new DictionaryValue(); |
69 entry->SetString("name", profile); | 78 entry->SetString("name", profile); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 } | 122 } |
114 | 123 |
115 void ImportDataHandler::ImportItemStarted(importer::ImportItem item) { | 124 void ImportDataHandler::ImportItemStarted(importer::ImportItem item) { |
116 } | 125 } |
117 | 126 |
118 void ImportDataHandler::ImportItemEnded(importer::ImportItem item) { | 127 void ImportDataHandler::ImportItemEnded(importer::ImportItem item) { |
119 } | 128 } |
120 | 129 |
121 void ImportDataHandler::ImportEnded() { | 130 void ImportDataHandler::ImportEnded() { |
122 dom_ui_->CallJavascriptFunction(L"ImportDataOverlay.dismiss"); | 131 dom_ui_->CallJavascriptFunction(L"ImportDataOverlay.dismiss"); |
| 132 importer_host_ = NULL; |
123 } | 133 } |
OLD | NEW |