OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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("clearBrowsingDataSectionHeader", | 41 localized_strings->SetString("clearBrowsingDataSectionHeader", |
33 l10n_util::GetStringUTF16(IDS_CLEAR_BROWSING_DATA_SECTION_HEADER)); | 42 l10n_util::GetStringUTF16(IDS_CLEAR_BROWSING_DATA_SECTION_HEADER)); |
34 localized_strings->SetString("clearBrowsingDataLabel", | 43 localized_strings->SetString("clearBrowsingDataLabel", |
35 l10n_util::GetStringUTF16(IDS_CLEAR_BROWSING_DATA_LABEL)); | 44 l10n_util::GetStringUTF16(IDS_CLEAR_BROWSING_DATA_LABEL)); |
36 localized_strings->SetString("deleteBrowsingHistoryCheckbox", | 45 localized_strings->SetString("deleteBrowsingHistoryCheckbox", |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 localized_strings->Set("clearBrowsingDataTimeList", time_list); | 91 localized_strings->Set("clearBrowsingDataTimeList", time_list); |
83 } | 92 } |
84 | 93 |
85 void ClearBrowserDataHandler::RegisterMessages() { | 94 void ClearBrowserDataHandler::RegisterMessages() { |
86 // Setup handlers specific to this panel. | 95 // Setup handlers specific to this panel. |
87 DCHECK(dom_ui_); | 96 DCHECK(dom_ui_); |
88 dom_ui_->RegisterMessageCallback("performClearBrowserData", | 97 dom_ui_->RegisterMessageCallback("performClearBrowserData", |
89 NewCallback(this, &ClearBrowserDataHandler::HandleClearBrowserData)); | 98 NewCallback(this, &ClearBrowserDataHandler::HandleClearBrowserData)); |
90 } | 99 } |
91 | 100 |
| 101 void ClearBrowserDataHandler::Observe(NotificationType type, |
| 102 const NotificationSource& source, |
| 103 const NotificationDetails& details) { |
| 104 switch (type.value) { |
| 105 case NotificationType::PREF_CHANGED: { |
| 106 const std::string& pref_name = *Details<std::string>(details).ptr(); |
| 107 if (pref_name == prefs::kClearPluginLSODataEnabled) |
| 108 UpdateClearPluginLSOData(); |
| 109 else |
| 110 OptionsPageUIHandler::Observe(type, source, details); |
| 111 break; |
| 112 } |
| 113 |
| 114 default: |
| 115 OptionsPageUIHandler::Observe(type, source, details); |
| 116 } |
| 117 } |
| 118 |
92 void ClearBrowserDataHandler::HandleClearBrowserData(const ListValue* value) { | 119 void ClearBrowserDataHandler::HandleClearBrowserData(const ListValue* value) { |
93 Profile* profile = dom_ui_->GetProfile(); | 120 Profile* profile = dom_ui_->GetProfile(); |
94 PrefService* prefs = profile->GetPrefs(); | 121 PrefService* prefs = profile->GetPrefs(); |
95 | 122 |
96 int remove_mask = 0; | 123 int remove_mask = 0; |
97 if (prefs->GetBoolean(prefs::kDeleteBrowsingHistory)) | 124 if (prefs->GetBoolean(prefs::kDeleteBrowsingHistory)) |
98 remove_mask |= BrowsingDataRemover::REMOVE_HISTORY; | 125 remove_mask |= BrowsingDataRemover::REMOVE_HISTORY; |
99 if (prefs->GetBoolean(prefs::kDeleteDownloadHistory)) | 126 if (prefs->GetBoolean(prefs::kDeleteDownloadHistory)) |
100 remove_mask |= BrowsingDataRemover::REMOVE_DOWNLOADS; | 127 remove_mask |= BrowsingDataRemover::REMOVE_DOWNLOADS; |
101 if (prefs->GetBoolean(prefs::kDeleteCache)) | 128 if (prefs->GetBoolean(prefs::kDeleteCache)) |
102 remove_mask |= BrowsingDataRemover::REMOVE_CACHE; | 129 remove_mask |= BrowsingDataRemover::REMOVE_CACHE; |
103 if (prefs->GetBoolean(prefs::kDeleteCookies)) | 130 if (prefs->GetBoolean(prefs::kDeleteCookies)) { |
104 remove_mask |= BrowsingDataRemover::REMOVE_COOKIES; | 131 remove_mask |= BrowsingDataRemover::REMOVE_COOKIES; |
| 132 if (clear_plugin_lso_data_enabled_.GetValue()) |
| 133 remove_mask |= BrowsingDataRemover::REMOVE_LSO_DATA; |
| 134 } |
105 if (prefs->GetBoolean(prefs::kDeletePasswords)) | 135 if (prefs->GetBoolean(prefs::kDeletePasswords)) |
106 remove_mask |= BrowsingDataRemover::REMOVE_PASSWORDS; | 136 remove_mask |= BrowsingDataRemover::REMOVE_PASSWORDS; |
107 if (prefs->GetBoolean(prefs::kDeleteFormData)) | 137 if (prefs->GetBoolean(prefs::kDeleteFormData)) |
108 remove_mask |= BrowsingDataRemover::REMOVE_FORM_DATA; | 138 remove_mask |= BrowsingDataRemover::REMOVE_FORM_DATA; |
109 | 139 |
110 int period_selected = prefs->GetInteger(prefs::kDeleteTimePeriod); | 140 int period_selected = prefs->GetInteger(prefs::kDeleteTimePeriod); |
111 | 141 |
112 FundamentalValue state(true); | 142 FundamentalValue state(true); |
113 dom_ui_->CallJavascriptFunction(L"ClearBrowserDataOverlay.setClearingState", | 143 dom_ui_->CallJavascriptFunction(L"ClearBrowserDataPage.setClearingState", |
114 state); | 144 state); |
115 | 145 |
116 // BrowsingDataRemover deletes itself when done. | 146 // BrowsingDataRemover deletes itself when done. |
117 remover_ = new BrowsingDataRemover(profile, | 147 remover_ = new BrowsingDataRemover(profile, |
118 static_cast<BrowsingDataRemover::TimePeriod>(period_selected), | 148 static_cast<BrowsingDataRemover::TimePeriod>(period_selected), |
119 base::Time()); | 149 base::Time()); |
120 remover_->AddObserver(this); | 150 remover_->AddObserver(this); |
121 remover_->Remove(remove_mask); | 151 remover_->Remove(remove_mask); |
122 } | 152 } |
123 | 153 |
| 154 void ClearBrowserDataHandler::UpdateClearPluginLSOData() { |
| 155 int label_id = clear_plugin_lso_data_enabled_.GetValue() ? |
| 156 IDS_DEL_COOKIES_FLASH_CHKBOX : |
| 157 IDS_DEL_COOKIES_CHKBOX; |
| 158 scoped_ptr<Value> label( |
| 159 Value::CreateStringValue(l10n_util::GetStringUTF16(label_id))); |
| 160 dom_ui_->CallJavascriptFunction( |
| 161 L"ClearBrowserDataPage.setClearLocalDataLabel", *label); |
| 162 } |
| 163 |
124 void ClearBrowserDataHandler::OnBrowsingDataRemoverDone() { | 164 void ClearBrowserDataHandler::OnBrowsingDataRemoverDone() { |
125 // No need to remove ourselves as an observer as BrowsingDataRemover deletes | 165 // No need to remove ourselves as an observer as BrowsingDataRemover deletes |
126 // itself after we return. | 166 // itself after we return. |
127 remover_ = NULL; | 167 remover_ = NULL; |
128 DCHECK(dom_ui_); | 168 DCHECK(dom_ui_); |
129 dom_ui_->CallJavascriptFunction(L"ClearBrowserDataOverlay.dismiss"); | 169 dom_ui_->CallJavascriptFunction(L"ClearBrowserDataPage.dismiss"); |
130 } | 170 } |
131 | 171 |
OLD | NEW |