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

Side by Side Diff: chrome/browser/extensions/api/browsing_data/browsing_data_api.cc

Issue 10522002: `chrome.browsingData` extension API can now remove data from protected origins. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 6 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
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 // 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 23 matching lines...) Expand all
34 const char kFormDataKey[] = "formData"; 34 const char kFormDataKey[] = "formData";
35 const char kHistoryKey[] = "history"; 35 const char kHistoryKey[] = "history";
36 const char kIndexedDBKey[] = "indexedDB"; 36 const char kIndexedDBKey[] = "indexedDB";
37 const char kLocalStorageKey[] = "localStorage"; 37 const char kLocalStorageKey[] = "localStorage";
38 const char kServerBoundCertsKey[] = "serverBoundCerts"; 38 const char kServerBoundCertsKey[] = "serverBoundCerts";
39 const char kPasswordsKey[] = "passwords"; 39 const char kPasswordsKey[] = "passwords";
40 const char kPluginDataKey[] = "pluginData"; 40 const char kPluginDataKey[] = "pluginData";
41 const char kWebSQLKey[] = "webSQL"; 41 const char kWebSQLKey[] = "webSQL";
42 42
43 // Option Keys. 43 // Option Keys.
44 const char kExtensionsKey[] = "extensions";
45 const char kOriginTypesKey[] = "origin_types";
46 const char kProtectedWebKey[] = "protected_web";
44 const char kSinceKey[] = "since"; 47 const char kSinceKey[] = "since";
48 const char kUnprotectedWebKey[] = "unprotected_web";
45 49
46 // Errors! 50 // Errors!
47 const char kOneAtATimeError[] = "Only one 'browsingData' API call can run at" 51 const char kOneAtATimeError[] = "Only one 'browsingData' API call can run at "
48 "a time."; 52 "a time.";
49 53
50 } // namespace extension_browsing_data_api_constants 54 } // namespace extension_browsing_data_api_constants
51 55
52 namespace { 56 namespace {
53 // Converts the JavaScript API's numeric input (miliseconds since epoch) into an 57 // Converts the JavaScript API's numeric input (miliseconds since epoch) into an
54 // appropriate base::Time that we can pass into the BrowsingDataRemove. 58 // appropriate base::Time that we can pass into the BrowsingDataRemove.
55 bool ParseTimeFromValue(const double& ms_since_epoch, base::Time* time) { 59 bool ParseTimeFromValue(const double& ms_since_epoch, base::Time* time) {
56 return true; 60 return true;
57 } 61 }
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 DictionaryValue* options; 125 DictionaryValue* options;
122 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &options)); 126 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &options));
123 DCHECK(options); 127 DCHECK(options);
124 128
125 // If |ms_since_epoch| isn't set, default it to 0. 129 // If |ms_since_epoch| isn't set, default it to 0.
126 double ms_since_epoch; 130 double ms_since_epoch;
127 if (!options->GetDouble(extension_browsing_data_api_constants::kSinceKey, 131 if (!options->GetDouble(extension_browsing_data_api_constants::kSinceKey,
128 &ms_since_epoch)) 132 &ms_since_epoch))
129 ms_since_epoch = 0; 133 ms_since_epoch = 0;
130 134
135 // If |m_origin_set_mask| isn't set, default it to 'UNPROTECTED_WEB'.
Bernhard Bauer 2012/06/04 11:20:16 Nit: |origin_set_mask_|
Mike West 2012/06/04 12:23:39 Done.
136 origin_set_mask_ = 0;
Bernhard Bauer 2012/06/04 11:20:16 I guess you could directly initialize the value to
Mike West 2012/06/04 12:23:39 I'm not sure that would save me any work: I'd stil
Bernhard Bauer 2012/06/04 12:42:17 Ah, true. Just do what's simpler then.
137 ListValue* origin_set_list = NULL;
138 if (options->GetList(extension_browsing_data_api_constants::kOriginTypesKey,
Bernhard Bauer 2012/06/04 11:20:16 You could be more aggressive in enforcing paramete
Mike West 2012/06/04 12:23:39 Done.
139 &origin_set_list)) {
140 for (size_t i = 0; i < origin_set_list->GetSize(); ++i) {
141 std::string value;
142 if (!origin_set_list->GetString(i, &value))
143 continue;
144
145 if (value == extension_browsing_data_api_constants::kUnprotectedWebKey)
146 origin_set_mask_ |= BrowsingDataHelper::UNPROTECTED_WEB;
147 else if (value == extension_browsing_data_api_constants::kProtectedWebKey)
148 origin_set_mask_ |= BrowsingDataHelper::PROTECTED_WEB;
149 else if (value == extension_browsing_data_api_constants::kExtensionsKey)
Bernhard Bauer 2012/06/04 11:20:16 This value isn't in the API definition.
Mike West 2012/06/04 12:23:39 That's intentional. I'm not sure we want to open u
Bernhard Bauer 2012/06/04 12:42:17 Fair enough, but then you shouldn't accept it here
Mike West 2012/06/04 13:20:53 Fair enough. Commented out for the moment. Once we
150 origin_set_mask_ |= BrowsingDataHelper::EXTENSION;
151 else
152 continue;
153 }
154 } else {
155 origin_set_mask_ = BrowsingDataHelper::UNPROTECTED_WEB;
156 }
157
131 // base::Time takes a double that represents seconds since epoch. JavaScript 158 // base::Time takes a double that represents seconds since epoch. JavaScript
132 // gives developers milliseconds, so do a quick conversion before populating 159 // gives developers milliseconds, so do a quick conversion before populating
133 // the object. Also, Time::FromDoubleT converts double time 0 to empty Time 160 // the object. Also, Time::FromDoubleT converts double time 0 to empty Time
134 // object. So we need to do special handling here. 161 // object. So we need to do special handling here.
135 remove_since_ = (ms_since_epoch == 0) ? 162 remove_since_ = (ms_since_epoch == 0) ?
136 base::Time::UnixEpoch() : 163 base::Time::UnixEpoch() :
137 base::Time::FromDoubleT(ms_since_epoch / 1000.0); 164 base::Time::FromDoubleT(ms_since_epoch / 1000.0);
138 165
139 removal_mask_ = GetRemovalMask(); 166 removal_mask_ = GetRemovalMask();
140 167
(...skipping 29 matching lines...) Expand all
170 // If we're good to go, add a ref (Balanced in OnBrowsingDataRemoverDone) 197 // If we're good to go, add a ref (Balanced in OnBrowsingDataRemoverDone)
171 AddRef(); 198 AddRef();
172 199
173 // Create a BrowsingDataRemover, set the current object as an observer (so 200 // Create a BrowsingDataRemover, set the current object as an observer (so
174 // that we're notified after removal) and call remove() with the arguments 201 // that we're notified after removal) and call remove() with the arguments
175 // we've generated above. We can use a raw pointer here, as the browsing data 202 // we've generated above. We can use a raw pointer here, as the browsing data
176 // remover is responsible for deleting itself once data removal is complete. 203 // remover is responsible for deleting itself once data removal is complete.
177 BrowsingDataRemover* remover = new BrowsingDataRemover( 204 BrowsingDataRemover* remover = new BrowsingDataRemover(
178 GetCurrentBrowser()->profile(), remove_since_, base::Time::Now()); 205 GetCurrentBrowser()->profile(), remove_since_, base::Time::Now());
179 remover->AddObserver(this); 206 remover->AddObserver(this);
180 remover->Remove(removal_mask_, BrowsingDataHelper::UNPROTECTED_WEB); 207 remover->Remove(removal_mask_, origin_set_mask_);
181 } 208 }
182 209
183 int RemoveBrowsingDataFunction::GetRemovalMask() const { 210 int RemoveBrowsingDataFunction::GetRemovalMask() const {
184 // Parse the |dataToRemove| argument to generate the removal mask. 211 // Parse the |dataToRemove| argument to generate the removal mask.
185 base::DictionaryValue* data_to_remove; 212 base::DictionaryValue* data_to_remove;
186 if (args_->GetDictionary(1, &data_to_remove)) 213 if (args_->GetDictionary(1, &data_to_remove))
187 return ParseRemovalMask(data_to_remove); 214 return ParseRemovalMask(data_to_remove);
188 else 215 else
189 return 0; 216 return 0;
190 } 217 }
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 return BrowsingDataRemover::REMOVE_PLUGIN_DATA; 260 return BrowsingDataRemover::REMOVE_PLUGIN_DATA;
234 } 261 }
235 262
236 int RemovePasswordsFunction::GetRemovalMask() const { 263 int RemovePasswordsFunction::GetRemovalMask() const {
237 return BrowsingDataRemover::REMOVE_PASSWORDS; 264 return BrowsingDataRemover::REMOVE_PASSWORDS;
238 } 265 }
239 266
240 int RemoveWebSQLFunction::GetRemovalMask() const { 267 int RemoveWebSQLFunction::GetRemovalMask() const {
241 return BrowsingDataRemover::REMOVE_WEBSQL; 268 return BrowsingDataRemover::REMOVE_WEBSQL;
242 } 269 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698