OLD | NEW |
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 // Defines the Chrome Extensions BrowsingData API functions, which entail | 5 // Defines the Chrome Extensions BrowsingData API functions, which entail |
6 // clearing browsing data, and clearing the browser's cache (which, let's be | 6 // clearing browsing data, and clearing the browser's cache (which, let's be |
7 // honest, are the same thing), as specified in the extension API JSON. | 7 // honest, are the same thing), as specified in the extension API JSON. |
8 | 8 |
9 #include "chrome/browser/extensions/api/browsing_data/browsing_data_api.h" | 9 #include "chrome/browser/extensions/api/browsing_data/browsing_data_api.h" |
10 | 10 |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 | 114 |
115 | 115 |
116 bool BrowsingDataSettingsFunction::RunImpl() { | 116 bool BrowsingDataSettingsFunction::RunImpl() { |
117 PrefService* prefs = profile()->GetPrefs(); | 117 PrefService* prefs = profile()->GetPrefs(); |
118 | 118 |
119 // Fill origin types. | 119 // Fill origin types. |
120 // The "cookies" and "hosted apps" UI checkboxes both map to | 120 // The "cookies" and "hosted apps" UI checkboxes both map to |
121 // REMOVE_SITE_DATA in browsing_data_remover.h, the former for the unprotected | 121 // REMOVE_SITE_DATA in browsing_data_remover.h, the former for the unprotected |
122 // web, the latter for protected web data. There is no UI control for | 122 // web, the latter for protected web data. There is no UI control for |
123 // extension data. | 123 // extension data. |
124 scoped_ptr<DictionaryValue> origin_types(new DictionaryValue); | 124 scoped_ptr<base::DictionaryValue> origin_types(new base::DictionaryValue); |
125 origin_types->SetBoolean( | 125 origin_types->SetBoolean( |
126 extension_browsing_data_api_constants::kUnprotectedWebKey, | 126 extension_browsing_data_api_constants::kUnprotectedWebKey, |
127 prefs->GetBoolean(prefs::kDeleteCookies)); | 127 prefs->GetBoolean(prefs::kDeleteCookies)); |
128 origin_types->SetBoolean( | 128 origin_types->SetBoolean( |
129 extension_browsing_data_api_constants::kProtectedWebKey, | 129 extension_browsing_data_api_constants::kProtectedWebKey, |
130 prefs->GetBoolean(prefs::kDeleteHostedAppsData)); | 130 prefs->GetBoolean(prefs::kDeleteHostedAppsData)); |
131 origin_types->SetBoolean( | 131 origin_types->SetBoolean( |
132 extension_browsing_data_api_constants::kExtensionsKey, false); | 132 extension_browsing_data_api_constants::kExtensionsKey, false); |
133 | 133 |
134 // Fill deletion time period. | 134 // Fill deletion time period. |
135 int period_pref = prefs->GetInteger(prefs::kDeleteTimePeriod); | 135 int period_pref = prefs->GetInteger(prefs::kDeleteTimePeriod); |
136 BrowsingDataRemover::TimePeriod period = | 136 BrowsingDataRemover::TimePeriod period = |
137 static_cast<BrowsingDataRemover::TimePeriod>(period_pref); | 137 static_cast<BrowsingDataRemover::TimePeriod>(period_pref); |
138 double since = 0; | 138 double since = 0; |
139 if (period != BrowsingDataRemover::EVERYTHING) { | 139 if (period != BrowsingDataRemover::EVERYTHING) { |
140 base::Time time = BrowsingDataRemover::CalculateBeginDeleteTime(period); | 140 base::Time time = BrowsingDataRemover::CalculateBeginDeleteTime(period); |
141 since = time.ToJsTime(); | 141 since = time.ToJsTime(); |
142 } | 142 } |
143 | 143 |
144 scoped_ptr<DictionaryValue> options(new DictionaryValue); | 144 scoped_ptr<base::DictionaryValue> options(new base::DictionaryValue); |
145 options->Set(extension_browsing_data_api_constants::kOriginTypesKey, | 145 options->Set(extension_browsing_data_api_constants::kOriginTypesKey, |
146 origin_types.release()); | 146 origin_types.release()); |
147 options->SetDouble(extension_browsing_data_api_constants::kSinceKey, since); | 147 options->SetDouble(extension_browsing_data_api_constants::kSinceKey, since); |
148 | 148 |
149 // Fill dataToRemove and dataRemovalPermitted. | 149 // Fill dataToRemove and dataRemovalPermitted. |
150 scoped_ptr<DictionaryValue> selected(new DictionaryValue); | 150 scoped_ptr<base::DictionaryValue> selected(new base::DictionaryValue); |
151 scoped_ptr<DictionaryValue> permitted(new DictionaryValue); | 151 scoped_ptr<base::DictionaryValue> permitted(new base::DictionaryValue); |
152 | 152 |
153 bool delete_site_data = prefs->GetBoolean(prefs::kDeleteCookies) || | 153 bool delete_site_data = prefs->GetBoolean(prefs::kDeleteCookies) || |
154 prefs->GetBoolean(prefs::kDeleteHostedAppsData); | 154 prefs->GetBoolean(prefs::kDeleteHostedAppsData); |
155 | 155 |
156 SetDetails(selected.get(), permitted.get(), | 156 SetDetails(selected.get(), permitted.get(), |
157 extension_browsing_data_api_constants::kAppCacheKey, | 157 extension_browsing_data_api_constants::kAppCacheKey, |
158 delete_site_data); | 158 delete_site_data); |
159 SetDetails(selected.get(), permitted.get(), | 159 SetDetails(selected.get(), permitted.get(), |
160 extension_browsing_data_api_constants::kCookiesKey, | 160 extension_browsing_data_api_constants::kCookiesKey, |
161 delete_site_data); | 161 delete_site_data); |
(...skipping 26 matching lines...) Expand all Loading... |
188 SetDetails(selected.get(), permitted.get(), | 188 SetDetails(selected.get(), permitted.get(), |
189 extension_browsing_data_api_constants::kCacheKey, | 189 extension_browsing_data_api_constants::kCacheKey, |
190 prefs->GetBoolean(prefs::kDeleteCache)); | 190 prefs->GetBoolean(prefs::kDeleteCache)); |
191 SetDetails(selected.get(), permitted.get(), | 191 SetDetails(selected.get(), permitted.get(), |
192 extension_browsing_data_api_constants::kFormDataKey, | 192 extension_browsing_data_api_constants::kFormDataKey, |
193 prefs->GetBoolean(prefs::kDeleteFormData)); | 193 prefs->GetBoolean(prefs::kDeleteFormData)); |
194 SetDetails(selected.get(), permitted.get(), | 194 SetDetails(selected.get(), permitted.get(), |
195 extension_browsing_data_api_constants::kPasswordsKey, | 195 extension_browsing_data_api_constants::kPasswordsKey, |
196 prefs->GetBoolean(prefs::kDeletePasswords)); | 196 prefs->GetBoolean(prefs::kDeletePasswords)); |
197 | 197 |
198 scoped_ptr<DictionaryValue> result(new DictionaryValue); | 198 scoped_ptr<base::DictionaryValue> result(new base::DictionaryValue); |
199 result->Set(extension_browsing_data_api_constants::kOptionsKey, | 199 result->Set(extension_browsing_data_api_constants::kOptionsKey, |
200 options.release()); | 200 options.release()); |
201 result->Set(extension_browsing_data_api_constants::kDataToRemoveKey, | 201 result->Set(extension_browsing_data_api_constants::kDataToRemoveKey, |
202 selected.release()); | 202 selected.release()); |
203 result->Set(extension_browsing_data_api_constants::kDataRemovalPermittedKey, | 203 result->Set(extension_browsing_data_api_constants::kDataRemovalPermittedKey, |
204 permitted.release()); | 204 permitted.release()); |
205 SetResult(result.release()); | 205 SetResult(result.release()); |
206 return true; | 206 return true; |
207 } | 207 } |
208 | 208 |
209 void BrowsingDataSettingsFunction::SetDetails(DictionaryValue* selected_dict, | 209 void BrowsingDataSettingsFunction::SetDetails( |
210 DictionaryValue* permitted_dict, | 210 base::DictionaryValue* selected_dict, |
211 const char* data_type, | 211 base::DictionaryValue* permitted_dict, |
212 bool is_selected) { | 212 const char* data_type, |
| 213 bool is_selected) { |
213 bool is_permitted = IsRemovalPermitted(MaskForKey(data_type), | 214 bool is_permitted = IsRemovalPermitted(MaskForKey(data_type), |
214 profile()->GetPrefs()); | 215 profile()->GetPrefs()); |
215 selected_dict->SetBoolean(data_type, is_selected && is_permitted); | 216 selected_dict->SetBoolean(data_type, is_selected && is_permitted); |
216 permitted_dict->SetBoolean(data_type, is_permitted); | 217 permitted_dict->SetBoolean(data_type, is_permitted); |
217 } | 218 } |
218 | 219 |
219 void BrowsingDataRemoveFunction::OnBrowsingDataRemoverDone() { | 220 void BrowsingDataRemoveFunction::OnBrowsingDataRemoverDone() { |
220 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 221 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
221 this->SendResponse(true); | 222 this->SendResponse(true); |
222 | 223 |
223 Release(); // Balanced in RunImpl. | 224 Release(); // Balanced in RunImpl. |
224 } | 225 } |
225 | 226 |
226 bool BrowsingDataRemoveFunction::RunImpl() { | 227 bool BrowsingDataRemoveFunction::RunImpl() { |
227 // If we don't have a profile, something's pretty wrong. | 228 // If we don't have a profile, something's pretty wrong. |
228 DCHECK(profile()); | 229 DCHECK(profile()); |
229 | 230 |
230 // Grab the initial |options| parameter, and parse out the arguments. | 231 // Grab the initial |options| parameter, and parse out the arguments. |
231 DictionaryValue* options; | 232 base::DictionaryValue* options; |
232 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &options)); | 233 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &options)); |
233 DCHECK(options); | 234 DCHECK(options); |
234 | 235 |
235 origin_set_mask_ = ParseOriginSetMask(*options); | 236 origin_set_mask_ = ParseOriginSetMask(*options); |
236 | 237 |
237 // If |ms_since_epoch| isn't set, default it to 0. | 238 // If |ms_since_epoch| isn't set, default it to 0. |
238 double ms_since_epoch; | 239 double ms_since_epoch; |
239 if (!options->GetDouble(extension_browsing_data_api_constants::kSinceKey, | 240 if (!options->GetDouble(extension_browsing_data_api_constants::kSinceKey, |
240 &ms_since_epoch)) | 241 &ms_since_epoch)) |
241 ms_since_epoch = 0; | 242 ms_since_epoch = 0; |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 remover->AddObserver(this); | 305 remover->AddObserver(this); |
305 remover->Remove(removal_mask_, origin_set_mask_); | 306 remover->Remove(removal_mask_, origin_set_mask_); |
306 } | 307 } |
307 | 308 |
308 int BrowsingDataRemoveFunction::ParseOriginSetMask( | 309 int BrowsingDataRemoveFunction::ParseOriginSetMask( |
309 const base::DictionaryValue& options) { | 310 const base::DictionaryValue& options) { |
310 // Parse the |options| dictionary to generate the origin set mask. Default to | 311 // Parse the |options| dictionary to generate the origin set mask. Default to |
311 // UNPROTECTED_WEB if the developer doesn't specify anything. | 312 // UNPROTECTED_WEB if the developer doesn't specify anything. |
312 int mask = BrowsingDataHelper::UNPROTECTED_WEB; | 313 int mask = BrowsingDataHelper::UNPROTECTED_WEB; |
313 | 314 |
314 const DictionaryValue* d = NULL; | 315 const base::DictionaryValue* d = NULL; |
315 if (options.HasKey(extension_browsing_data_api_constants::kOriginTypesKey)) { | 316 if (options.HasKey(extension_browsing_data_api_constants::kOriginTypesKey)) { |
316 EXTENSION_FUNCTION_VALIDATE(options.GetDictionary( | 317 EXTENSION_FUNCTION_VALIDATE(options.GetDictionary( |
317 extension_browsing_data_api_constants::kOriginTypesKey, &d)); | 318 extension_browsing_data_api_constants::kOriginTypesKey, &d)); |
318 bool value; | 319 bool value; |
319 | 320 |
320 // The developer specified something! Reset to 0 and parse the dictionary. | 321 // The developer specified something! Reset to 0 and parse the dictionary. |
321 mask = 0; | 322 mask = 0; |
322 | 323 |
323 // Unprotected web. | 324 // Unprotected web. |
324 if (d->HasKey(extension_browsing_data_api_constants::kUnprotectedWebKey)) { | 325 if (d->HasKey(extension_browsing_data_api_constants::kUnprotectedWebKey)) { |
(...skipping 26 matching lines...) Expand all Loading... |
351 // supported (boolean) values. | 352 // supported (boolean) values. |
352 int RemoveBrowsingDataFunction::GetRemovalMask() { | 353 int RemoveBrowsingDataFunction::GetRemovalMask() { |
353 base::DictionaryValue* data_to_remove; | 354 base::DictionaryValue* data_to_remove; |
354 if (!args_->GetDictionary(1, &data_to_remove)) { | 355 if (!args_->GetDictionary(1, &data_to_remove)) { |
355 bad_message_ = true; | 356 bad_message_ = true; |
356 return 0; | 357 return 0; |
357 } | 358 } |
358 | 359 |
359 int removal_mask = 0; | 360 int removal_mask = 0; |
360 | 361 |
361 for (DictionaryValue::Iterator i(*data_to_remove); | 362 for (base::DictionaryValue::Iterator i(*data_to_remove); |
362 !i.IsAtEnd(); | 363 !i.IsAtEnd(); |
363 i.Advance()) { | 364 i.Advance()) { |
364 bool selected = false; | 365 bool selected = false; |
365 if (!i.value().GetAsBoolean(&selected)) { | 366 if (!i.value().GetAsBoolean(&selected)) { |
366 bad_message_ = true; | 367 bad_message_ = true; |
367 return 0; | 368 return 0; |
368 } | 369 } |
369 if (selected) | 370 if (selected) |
370 removal_mask |= MaskForKey(i.key().c_str()); | 371 removal_mask |= MaskForKey(i.key().c_str()); |
371 } | 372 } |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
414 return BrowsingDataRemover::REMOVE_PLUGIN_DATA; | 415 return BrowsingDataRemover::REMOVE_PLUGIN_DATA; |
415 } | 416 } |
416 | 417 |
417 int RemovePasswordsFunction::GetRemovalMask() { | 418 int RemovePasswordsFunction::GetRemovalMask() { |
418 return BrowsingDataRemover::REMOVE_PASSWORDS; | 419 return BrowsingDataRemover::REMOVE_PASSWORDS; |
419 } | 420 } |
420 | 421 |
421 int RemoveWebSQLFunction::GetRemovalMask() { | 422 int RemoveWebSQLFunction::GetRemovalMask() { |
422 return BrowsingDataRemover::REMOVE_WEBSQL; | 423 return BrowsingDataRemover::REMOVE_WEBSQL; |
423 } | 424 } |
OLD | NEW |