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/options/clear_browser_data_handler.h" | 5 #include "chrome/browser/dom_ui/options/clear_browser_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/string16.h" | 9 #include "base/string16.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
| 11 #include "chrome/browser/browser_process.h" |
11 #include "chrome/browser/prefs/pref_service.h" | 12 #include "chrome/browser/prefs/pref_service.h" |
12 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 14 #include "chrome/common/notification_details.h" |
13 #include "chrome/common/pref_names.h" | 15 #include "chrome/common/pref_names.h" |
14 #include "grit/chromium_strings.h" | 16 #include "grit/chromium_strings.h" |
15 #include "grit/generated_resources.h" | 17 #include "grit/generated_resources.h" |
16 #include "grit/locale_settings.h" | 18 #include "grit/locale_settings.h" |
17 | 19 |
18 ClearBrowserDataHandler::ClearBrowserDataHandler() : remover_(NULL) { | 20 ClearBrowserDataHandler::ClearBrowserDataHandler() : remover_(NULL) { |
19 } | 21 } |
20 | 22 |
21 ClearBrowserDataHandler::~ClearBrowserDataHandler() { | 23 ClearBrowserDataHandler::~ClearBrowserDataHandler() { |
22 if (remover_) { | 24 if (remover_) { |
23 remover_->RemoveObserver(this); | 25 remover_->RemoveObserver(this); |
24 } | 26 } |
25 } | 27 } |
26 | 28 |
| 29 void ClearBrowserDataHandler::Initialize() { |
| 30 clear_plugin_lso_data_enabled_.Init(prefs::kClearPluginLSODataEnabled, |
| 31 g_browser_process->local_state(), |
| 32 this); |
| 33 UpdateClearPluginLSOData(); |
| 34 } |
| 35 |
27 void ClearBrowserDataHandler::GetLocalizedValues( | 36 void ClearBrowserDataHandler::GetLocalizedValues( |
28 DictionaryValue* localized_strings) { | 37 DictionaryValue* localized_strings) { |
29 DCHECK(localized_strings); | 38 DCHECK(localized_strings); |
30 localized_strings->SetString("clearBrowsingDataTitle", | 39 localized_strings->SetString("clearBrowsingDataTitle", |
31 l10n_util::GetStringUTF16(IDS_CLEAR_BROWSING_DATA_TITLE)); | 40 l10n_util::GetStringUTF16(IDS_CLEAR_BROWSING_DATA_TITLE)); |
32 localized_strings->SetString("clearBrowsingDataLabel", | 41 localized_strings->SetString("clearBrowsingDataLabel", |
33 l10n_util::GetStringUTF16(IDS_CLEAR_BROWSING_DATA_LABEL)); | 42 l10n_util::GetStringUTF16(IDS_CLEAR_BROWSING_DATA_LABEL)); |
34 localized_strings->SetString("clearBrowsingDataTimeLabel", | 43 localized_strings->SetString("clearBrowsingDataTimeLabel", |
35 l10n_util::GetStringUTF16(IDS_CLEAR_BROWSING_DATA_TIME_LABEL)); | 44 l10n_util::GetStringUTF16(IDS_CLEAR_BROWSING_DATA_TIME_LABEL)); |
36 localized_strings->SetString("deleteBrowsingHistoryCheckbox", | 45 localized_strings->SetString("deleteBrowsingHistoryCheckbox", |
37 l10n_util::GetStringUTF16(IDS_DEL_BROWSING_HISTORY_CHKBOX)); | 46 l10n_util::GetStringUTF16(IDS_DEL_BROWSING_HISTORY_CHKBOX)); |
38 localized_strings->SetString("deleteDownloadHistoryCheckbox", | 47 localized_strings->SetString("deleteDownloadHistoryCheckbox", |
39 l10n_util::GetStringUTF16(IDS_DEL_DOWNLOAD_HISTORY_CHKBOX)); | 48 l10n_util::GetStringUTF16(IDS_DEL_DOWNLOAD_HISTORY_CHKBOX)); |
40 localized_strings->SetString("deleteCacheCheckbox", | 49 localized_strings->SetString("deleteCacheCheckbox", |
41 l10n_util::GetStringUTF16(IDS_DEL_CACHE_CHKBOX)); | 50 l10n_util::GetStringUTF16(IDS_DEL_CACHE_CHKBOX)); |
42 localized_strings->SetString("deleteCookiesCheckbox", | 51 localized_strings->SetString("deleteCookiesCheckbox", |
43 l10n_util::GetStringUTF16(IDS_DEL_COOKIES_CHKBOX)); | 52 l10n_util::GetStringUTF16(IDS_DEL_COOKIES_CHKBOX)); |
44 localized_strings->SetString("deletePasswordsCheckbox", | 53 localized_strings->SetString("deletePasswordsCheckbox", |
45 l10n_util::GetStringUTF16(IDS_DEL_PASSWORDS_CHKBOX)); | 54 l10n_util::GetStringUTF16(IDS_DEL_PASSWORDS_CHKBOX)); |
| 55 localized_strings->SetString("deleteLSODataCheckbox", |
| 56 l10n_util::GetStringUTF16(IDS_DEL_FLASH_DATA_CHKBOX)); |
46 localized_strings->SetString("deleteFormDataCheckbox", | 57 localized_strings->SetString("deleteFormDataCheckbox", |
47 l10n_util::GetStringUTF16(IDS_DEL_FORM_DATA_CHKBOX)); | 58 l10n_util::GetStringUTF16(IDS_DEL_FORM_DATA_CHKBOX)); |
48 localized_strings->SetString("clearBrowsingDataCommit", | 59 localized_strings->SetString("clearBrowsingDataCommit", |
49 l10n_util::GetStringUTF16(IDS_CLEAR_BROWSING_DATA_COMMIT)); | 60 l10n_util::GetStringUTF16(IDS_CLEAR_BROWSING_DATA_COMMIT)); |
50 localized_strings->SetString("flashStorageSettings", | 61 localized_strings->SetString("flashStorageSettings", |
51 l10n_util::GetStringUTF16(IDS_FLASH_STORAGE_SETTINGS)); | 62 l10n_util::GetStringUTF16(IDS_FLASH_STORAGE_SETTINGS)); |
52 localized_strings->SetString("flash_storage_url", | 63 localized_strings->SetString("flash_storage_url", |
53 l10n_util::GetStringUTF16(IDS_FLASH_STORAGE_URL)); | 64 l10n_util::GetStringUTF16(IDS_FLASH_STORAGE_URL)); |
54 localized_strings->SetString("clearDataDeleting", | 65 localized_strings->SetString("clearDataDeleting", |
55 l10n_util::GetStringUTF16(IDS_CLEAR_DATA_DELETING)); | 66 l10n_util::GetStringUTF16(IDS_CLEAR_DATA_DELETING)); |
(...skipping 26 matching lines...) Expand all Loading... |
82 localized_strings->Set("clearBrowsingDataTimeList", time_list); | 93 localized_strings->Set("clearBrowsingDataTimeList", time_list); |
83 } | 94 } |
84 | 95 |
85 void ClearBrowserDataHandler::RegisterMessages() { | 96 void ClearBrowserDataHandler::RegisterMessages() { |
86 // Setup handlers specific to this panel. | 97 // Setup handlers specific to this panel. |
87 DCHECK(dom_ui_); | 98 DCHECK(dom_ui_); |
88 dom_ui_->RegisterMessageCallback("performClearBrowserData", | 99 dom_ui_->RegisterMessageCallback("performClearBrowserData", |
89 NewCallback(this, &ClearBrowserDataHandler::HandleClearBrowserData)); | 100 NewCallback(this, &ClearBrowserDataHandler::HandleClearBrowserData)); |
90 } | 101 } |
91 | 102 |
| 103 void ClearBrowserDataHandler::Observe(NotificationType type, |
| 104 const NotificationSource& source, |
| 105 const NotificationDetails& details) { |
| 106 switch (type.value) { |
| 107 case NotificationType::PREF_CHANGED: { |
| 108 const std::string& pref_name = *Details<std::string>(details).ptr(); |
| 109 if (pref_name == prefs::kClearPluginLSODataEnabled) |
| 110 UpdateClearPluginLSOData(); |
| 111 else |
| 112 OptionsPageUIHandler::Observe(type, source, details); |
| 113 break; |
| 114 } |
| 115 |
| 116 default: |
| 117 OptionsPageUIHandler::Observe(type, source, details); |
| 118 } |
| 119 } |
| 120 |
92 void ClearBrowserDataHandler::HandleClearBrowserData(const ListValue* value) { | 121 void ClearBrowserDataHandler::HandleClearBrowserData(const ListValue* value) { |
93 Profile *profile = dom_ui_->GetProfile(); | 122 Profile *profile = dom_ui_->GetProfile(); |
94 PrefService *prefs = profile->GetPrefs(); | 123 PrefService *prefs = profile->GetPrefs(); |
95 | 124 |
96 int remove_mask = 0; | 125 int remove_mask = 0; |
97 if (prefs->GetBoolean(prefs::kDeleteBrowsingHistory)) | 126 if (prefs->GetBoolean(prefs::kDeleteBrowsingHistory)) |
98 remove_mask |= BrowsingDataRemover::REMOVE_HISTORY; | 127 remove_mask |= BrowsingDataRemover::REMOVE_HISTORY; |
99 if (prefs->GetBoolean(prefs::kDeleteDownloadHistory)) | 128 if (prefs->GetBoolean(prefs::kDeleteDownloadHistory)) |
100 remove_mask |= BrowsingDataRemover::REMOVE_DOWNLOADS; | 129 remove_mask |= BrowsingDataRemover::REMOVE_DOWNLOADS; |
101 if (prefs->GetBoolean(prefs::kDeleteCache)) | 130 if (prefs->GetBoolean(prefs::kDeleteCache)) |
102 remove_mask |= BrowsingDataRemover::REMOVE_CACHE; | 131 remove_mask |= BrowsingDataRemover::REMOVE_CACHE; |
103 if (prefs->GetBoolean(prefs::kDeleteCookies)) | 132 if (prefs->GetBoolean(prefs::kDeleteCookies)) |
104 remove_mask |= BrowsingDataRemover::REMOVE_COOKIES; | 133 remove_mask |= BrowsingDataRemover::REMOVE_COOKIES; |
105 if (prefs->GetBoolean(prefs::kDeletePasswords)) | 134 if (prefs->GetBoolean(prefs::kDeletePasswords)) |
106 remove_mask |= BrowsingDataRemover::REMOVE_PASSWORDS; | 135 remove_mask |= BrowsingDataRemover::REMOVE_PASSWORDS; |
| 136 if (prefs->GetBoolean(prefs::kDeleteLSOData)) |
| 137 remove_mask |= BrowsingDataRemover::REMOVE_LSO_DATA; |
107 if (prefs->GetBoolean(prefs::kDeleteFormData)) | 138 if (prefs->GetBoolean(prefs::kDeleteFormData)) |
108 remove_mask |= BrowsingDataRemover::REMOVE_FORM_DATA; | 139 remove_mask |= BrowsingDataRemover::REMOVE_FORM_DATA; |
109 | 140 |
110 int period_selected = prefs->GetInteger(prefs::kDeleteTimePeriod); | 141 int period_selected = prefs->GetInteger(prefs::kDeleteTimePeriod); |
111 | 142 |
112 FundamentalValue state(true); | 143 FundamentalValue state(true); |
113 dom_ui_->CallJavascriptFunction(L"ClearBrowserDataOverlay.setClearingState", | 144 dom_ui_->CallJavascriptFunction(L"ClearBrowserDataOverlay.setClearingState", |
114 state); | 145 state); |
115 | 146 |
116 // BrowsingDataRemover deletes itself when done. | 147 // BrowsingDataRemover deletes itself when done. |
117 remover_ = new BrowsingDataRemover(profile, | 148 remover_ = new BrowsingDataRemover(profile, |
118 static_cast<BrowsingDataRemover::TimePeriod>(period_selected), | 149 static_cast<BrowsingDataRemover::TimePeriod>(period_selected), |
119 base::Time()); | 150 base::Time()); |
120 remover_->AddObserver(this); | 151 remover_->AddObserver(this); |
121 remover_->Remove(remove_mask); | 152 remover_->Remove(remove_mask); |
122 } | 153 } |
123 | 154 |
| 155 void ClearBrowserDataHandler::UpdateClearPluginLSOData() { |
| 156 scoped_ptr<Value> enabled( |
| 157 Value::CreateBooleanValue(clear_plugin_lso_data_enabled_.GetValue())); |
| 158 dom_ui_->CallJavascriptFunction( |
| 159 L"ClearBrowserDataOverlay.setClearPluginLSODataEnabled", *enabled); |
| 160 } |
| 161 |
124 void ClearBrowserDataHandler::OnBrowsingDataRemoverDone() { | 162 void ClearBrowserDataHandler::OnBrowsingDataRemoverDone() { |
125 // No need to remove ourselves as an observer as BrowsingDataRemover deletes | 163 // No need to remove ourselves as an observer as BrowsingDataRemover deletes |
126 // itself after we return. | 164 // itself after we return. |
127 remover_ = NULL; | 165 remover_ = NULL; |
128 DCHECK(dom_ui_); | 166 DCHECK(dom_ui_); |
129 dom_ui_->CallJavascriptFunction(L"ClearBrowserDataOverlay.dismiss"); | 167 dom_ui_->CallJavascriptFunction(L"ClearBrowserDataOverlay.dismiss"); |
130 } | 168 } |
131 | 169 |
OLD | NEW |