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 // Implements the Chrome Extensions Cookies API. | 5 // Implements the Chrome Extensions Cookies API. |
6 | 6 |
7 #include "chrome/browser/extensions/api/cookies/cookies_api.h" | 7 #include "chrome/browser/extensions/api/cookies/cookies_api.h" |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
11 #include "base/values.h" | 11 #include "base/values.h" |
12 #include "chrome/browser/extensions/api/cookies/cookies_api_constants.h" | 12 #include "chrome/browser/extensions/api/cookies/cookies_api_constants.h" |
13 #include "chrome/browser/extensions/api/cookies/cookies_helpers.h" | 13 #include "chrome/browser/extensions/api/cookies/cookies_helpers.h" |
14 #include "chrome/browser/extensions/extension_event_router.h" | 14 #include "chrome/browser/extensions/extension_event_router.h" |
15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
16 #include "chrome/browser/ui/browser.h" | 16 #include "chrome/browser/ui/browser.h" |
17 #include "chrome/browser/ui/browser_list.h" | 17 #include "chrome/browser/ui/browser_list.h" |
18 #include "chrome/common/chrome_notification_types.h" | 18 #include "chrome/common/chrome_notification_types.h" |
19 #include "chrome/common/extensions/api/cookies.h" | |
19 #include "chrome/common/extensions/extension.h" | 20 #include "chrome/common/extensions/extension.h" |
20 #include "chrome/common/extensions/extension_error_utils.h" | 21 #include "chrome/common/extensions/extension_error_utils.h" |
21 #include "content/public/browser/browser_thread.h" | 22 #include "content/public/browser/browser_thread.h" |
22 #include "content/public/browser/notification_service.h" | 23 #include "content/public/browser/notification_service.h" |
23 #include "net/cookies/cookie_monster.h" | 24 #include "net/cookies/cookie_monster.h" |
24 #include "net/url_request/url_request_context.h" | 25 #include "net/url_request/url_request_context.h" |
25 #include "net/url_request/url_request_context_getter.h" | 26 #include "net/url_request/url_request_context_getter.h" |
26 | 27 |
27 using content::BrowserThread; | 28 using content::BrowserThread; |
29 using extensions::api::cookies::CookieStore; | |
30 | |
31 namespace Get = extensions::api::cookies::Get; | |
32 namespace GetAll = extensions::api::cookies::GetAll; | |
33 namespace GetAllCookieStores = extensions::api::cookies::GetAllCookieStores; | |
34 namespace Remove = extensions::api::cookies::Remove; | |
35 namespace Set = extensions::api::cookies::Set; | |
28 | 36 |
29 namespace extensions { | 37 namespace extensions { |
30 namespace keys = cookies_api_constants; | 38 namespace keys = cookies_api_constants; |
31 | 39 |
32 ExtensionCookiesEventRouter::ExtensionCookiesEventRouter(Profile* profile) | 40 ExtensionCookiesEventRouter::ExtensionCookiesEventRouter(Profile* profile) |
33 : profile_(profile) {} | 41 : profile_(profile) {} |
34 | 42 |
35 ExtensionCookiesEventRouter::~ExtensionCookiesEventRouter() {} | 43 ExtensionCookiesEventRouter::~ExtensionCookiesEventRouter() {} |
36 | 44 |
37 void ExtensionCookiesEventRouter::Init() { | 45 void ExtensionCookiesEventRouter::Init() { |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
112 void ExtensionCookiesEventRouter::DispatchEvent(Profile* profile, | 120 void ExtensionCookiesEventRouter::DispatchEvent(Profile* profile, |
113 const char* event_name, | 121 const char* event_name, |
114 const std::string& json_args, | 122 const std::string& json_args, |
115 GURL& cookie_domain) { | 123 GURL& cookie_domain) { |
116 if (profile && profile->GetExtensionEventRouter()) { | 124 if (profile && profile->GetExtensionEventRouter()) { |
117 profile->GetExtensionEventRouter()->DispatchEventToRenderers( | 125 profile->GetExtensionEventRouter()->DispatchEventToRenderers( |
118 event_name, json_args, profile, cookie_domain, EventFilteringInfo()); | 126 event_name, json_args, profile, cookie_domain, EventFilteringInfo()); |
119 } | 127 } |
120 } | 128 } |
121 | 129 |
122 bool CookiesFunction::ParseUrl(const DictionaryValue* details, GURL* url, | 130 bool CookiesFunction::ParseUrl(std::string url_string, GURL* url, |
123 bool check_host_permissions) { | 131 bool check_host_permissions) { |
124 DCHECK(details && url); | |
125 std::string url_string; | |
126 // Get the URL string or return false. | |
127 EXTENSION_FUNCTION_VALIDATE(details->GetString(keys::kUrlKey, &url_string)); | |
128 *url = GURL(url_string); | 132 *url = GURL(url_string); |
129 if (!url->is_valid()) { | 133 if (!url->is_valid()) { |
130 error_ = ExtensionErrorUtils::FormatErrorMessage( | 134 error_ = ExtensionErrorUtils::FormatErrorMessage( |
131 keys::kInvalidUrlError, url_string); | 135 keys::kInvalidUrlError, url_string); |
132 return false; | 136 return false; |
133 } | 137 } |
134 // Check against host permissions if needed. | 138 // Check against host permissions if needed. |
135 if (check_host_permissions && | 139 if (check_host_permissions && |
136 !GetExtension()->HasHostPermission(*url)) { | 140 !GetExtension()->HasHostPermission(*url)) { |
137 error_ = ExtensionErrorUtils::FormatErrorMessage( | 141 error_ = ExtensionErrorUtils::FormatErrorMessage( |
138 keys::kNoHostPermissionsError, url->spec()); | 142 keys::kNoHostPermissionsError, url->spec()); |
139 return false; | 143 return false; |
140 } | 144 } |
141 return true; | 145 return true; |
142 } | 146 } |
143 | 147 |
144 bool CookiesFunction::ParseStoreContext(const DictionaryValue* details, | 148 bool CookiesFunction::ParseStoreContext(std::string* in_store_id, |
145 net::URLRequestContextGetter** context, | 149 net::URLRequestContextGetter** context, |
146 std::string* store_id) { | 150 std::string* out_store_id) { |
147 DCHECK(details && (context || store_id)); | 151 DCHECK((context || out_store_id)); |
148 Profile* store_profile = NULL; | 152 Profile* store_profile = NULL; |
149 if (details->HasKey(keys::kStoreIdKey)) { | 153 if (in_store_id != NULL) { |
150 // The store ID was explicitly specified in the details dictionary. | |
151 // Retrieve its corresponding cookie store. | |
152 std::string store_id_value; | |
153 // Get the store ID string or return false. | |
154 EXTENSION_FUNCTION_VALIDATE( | |
155 details->GetString(keys::kStoreIdKey, &store_id_value)); | |
156 store_profile = cookies_helpers::ChooseProfileFromStoreId( | 154 store_profile = cookies_helpers::ChooseProfileFromStoreId( |
157 store_id_value, profile(), include_incognito()); | 155 *in_store_id, profile(), include_incognito()); |
158 if (!store_profile) { | 156 if (!store_profile) { |
159 error_ = ExtensionErrorUtils::FormatErrorMessage( | 157 error_ = ExtensionErrorUtils::FormatErrorMessage( |
160 keys::kInvalidStoreIdError, store_id_value); | 158 keys::kInvalidStoreIdError, *in_store_id); |
161 return false; | 159 return false; |
162 } | 160 } |
163 } else { | 161 } else { |
164 // The store ID was not specified; use the current execution context's | 162 // The store ID was not specified; use the current execution context's |
165 // cookie store by default. | 163 // cookie store by default. |
166 // GetCurrentBrowser() already takes into account incognito settings. | 164 // GetCurrentBrowser() already takes into account incognito settings. |
167 Browser* current_browser = GetCurrentBrowser(); | 165 Browser* current_browser = GetCurrentBrowser(); |
168 if (!current_browser) { | 166 if (!current_browser) { |
169 error_ = keys::kNoCookieStoreFoundError; | 167 error_ = keys::kNoCookieStoreFoundError; |
170 return false; | 168 return false; |
171 } | 169 } |
172 store_profile = current_browser->profile(); | 170 store_profile = current_browser->profile(); |
173 } | 171 } |
174 DCHECK(store_profile); | 172 DCHECK(store_profile); |
175 | 173 |
176 if (context) | 174 if (context) |
177 *context = store_profile->GetRequestContext(); | 175 *context = store_profile->GetRequestContext(); |
178 if (store_id) | 176 if (out_store_id) |
179 *store_id = cookies_helpers::GetStoreIdFromProfile(store_profile); | 177 *out_store_id = cookies_helpers::GetStoreIdFromProfile(store_profile); |
180 | 178 |
181 return true; | 179 return true; |
182 } | 180 } |
183 | 181 |
184 GetCookieFunction::GetCookieFunction() {} | 182 GetCookieFunction::GetCookieFunction() {} |
185 | 183 |
186 GetCookieFunction::~GetCookieFunction() {} | 184 GetCookieFunction::~GetCookieFunction() {} |
187 | 185 |
188 bool GetCookieFunction::RunImpl() { | 186 bool GetCookieFunction::RunImpl() { |
189 // Return false if the arguments are malformed. | 187 scoped_ptr<Get::Params> params(Get::Params::Create(*args_)); |
190 DictionaryValue* details; | 188 EXTENSION_FUNCTION_VALIDATE(params.get()); |
191 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &details)); | |
192 DCHECK(details); | |
193 | 189 |
194 // Read/validate input parameters. | 190 // Read/validate input parameters. |
195 if (!ParseUrl(details, &url_, true)) | 191 if (!ParseUrl(params->details.url, &url_, true)) |
196 return false; | 192 return false; |
197 | 193 |
198 // Get the cookie name string or return false. | 194 name_ = params->details.name; |
199 EXTENSION_FUNCTION_VALIDATE(details->GetString(keys::kNameKey, &name_)); | |
200 | 195 |
201 net::URLRequestContextGetter* store_context = NULL; | 196 net::URLRequestContextGetter* store_context = NULL; |
202 if (!ParseStoreContext(details, &store_context, &store_id_)) | 197 if (!ParseStoreContext(params->details.store_id.get(), |
198 &store_context, | |
199 &store_id_)) | |
Aaron Boodman
2012/07/04 00:04:31
This code was badly formatted before; it should ha
mitchellwrosen
2012/07/04 02:04:40
Done.
| |
203 return false; | 200 return false; |
204 | 201 |
205 DCHECK(store_context && !store_id_.empty()); | 202 DCHECK(store_context && !store_id_.empty()); |
206 store_context_ = store_context; | 203 store_context_ = store_context; |
207 | 204 |
208 bool rv = BrowserThread::PostTask( | 205 bool rv = BrowserThread::PostTask( |
209 BrowserThread::IO, FROM_HERE, | 206 BrowserThread::IO, FROM_HERE, |
210 base::Bind(&GetCookieFunction::GetCookieOnIOThread, this)); | 207 base::Bind(&GetCookieFunction::GetCookieOnIOThread, this)); |
211 DCHECK(rv); | 208 DCHECK(rv); |
212 | 209 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
254 GetAllCookiesFunction::GetAllCookiesFunction() : details_(NULL) {} | 251 GetAllCookiesFunction::GetAllCookiesFunction() : details_(NULL) {} |
255 | 252 |
256 GetAllCookiesFunction::~GetAllCookiesFunction() {} | 253 GetAllCookiesFunction::~GetAllCookiesFunction() {} |
257 | 254 |
258 bool GetAllCookiesFunction::RunImpl() { | 255 bool GetAllCookiesFunction::RunImpl() { |
259 // Return false if the arguments are malformed. | 256 // Return false if the arguments are malformed. |
260 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &details_)); | 257 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &details_)); |
261 DCHECK(details_); | 258 DCHECK(details_); |
262 | 259 |
263 // Read/validate input parameters. | 260 // Read/validate input parameters. |
264 if (details_->HasKey(keys::kUrlKey) && !ParseUrl(details_, &url_, false)) | 261 scoped_ptr<GetAll::Params> params(GetAll::Params::Create(*args_)); |
265 return false; | 262 if (params->details.url.get()) |
Aaron Boodman
2012/07/04 00:04:31
This if statement should have curly braces. The on
mitchellwrosen
2012/07/04 02:04:40
Done.
| |
263 if (!ParseUrl(*params->details.url, &url_, false)) | |
264 return false; | |
266 | 265 |
267 net::URLRequestContextGetter* store_context = NULL; | 266 net::URLRequestContextGetter* store_context = NULL; |
268 if (!ParseStoreContext(details_, &store_context, &store_id_)) | 267 if (!ParseStoreContext(params->details.store_id.get(), |
268 &store_context, | |
269 &store_id_)) | |
Aaron Boodman
2012/07/04 00:04:31
This requires curlies
mitchellwrosen
2012/07/04 02:04:40
Done.
| |
269 return false; | 270 return false; |
270 DCHECK(store_context); | 271 DCHECK(store_context); |
271 store_context_ = store_context; | 272 store_context_ = store_context; |
272 | 273 |
273 bool rv = BrowserThread::PostTask( | 274 bool rv = BrowserThread::PostTask( |
274 BrowserThread::IO, FROM_HERE, | 275 BrowserThread::IO, FROM_HERE, |
275 base::Bind(&GetAllCookiesFunction::GetAllCookiesOnIOThread, this)); | 276 base::Bind(&GetAllCookiesFunction::GetAllCookiesOnIOThread, this)); |
276 DCHECK(rv); | 277 DCHECK(rv); |
277 | 278 |
278 // Will finish asynchronously. | 279 // Will finish asynchronously. |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
312 SetCookieFunction::SetCookieFunction() | 313 SetCookieFunction::SetCookieFunction() |
313 : secure_(false), | 314 : secure_(false), |
314 http_only_(false), | 315 http_only_(false), |
315 success_(false) { | 316 success_(false) { |
316 } | 317 } |
317 | 318 |
318 SetCookieFunction::~SetCookieFunction() { | 319 SetCookieFunction::~SetCookieFunction() { |
319 } | 320 } |
320 | 321 |
321 bool SetCookieFunction::RunImpl() { | 322 bool SetCookieFunction::RunImpl() { |
322 // Return false if the arguments are malformed. | 323 scoped_ptr<Set::Params> params(Set::Params::Create(*args_)); |
323 DictionaryValue* details; | 324 EXTENSION_FUNCTION_VALIDATE(params.get()); |
324 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &details)); | |
325 DCHECK(details); | |
326 | 325 |
327 // Read/validate input parameters. | 326 // Read/validate input parameters. |
328 if (!ParseUrl(details, &url_, true)) | 327 if (!ParseUrl(params->details.url, &url_, true)) |
329 return false; | 328 return false; |
330 // The macros below return false if argument types are not as expected. | |
331 if (details->HasKey(keys::kNameKey)) | |
332 EXTENSION_FUNCTION_VALIDATE(details->GetString(keys::kNameKey, &name_)); | |
333 if (details->HasKey(keys::kValueKey)) | |
334 EXTENSION_FUNCTION_VALIDATE(details->GetString(keys::kValueKey, &value_)); | |
335 if (details->HasKey(keys::kDomainKey)) | |
336 EXTENSION_FUNCTION_VALIDATE(details->GetString(keys::kDomainKey, &domain_)); | |
337 if (details->HasKey(keys::kPathKey)) | |
338 EXTENSION_FUNCTION_VALIDATE(details->GetString(keys::kPathKey, &path_)); | |
339 | 329 |
340 if (details->HasKey(keys::kSecureKey)) { | 330 if (params->details.name.get()) |
341 EXTENSION_FUNCTION_VALIDATE( | 331 name_ = *params->details.name; |
Aaron Boodman
2012/07/04 00:04:31
Do we need all these members now? Can we just stor
mitchellwrosen
2012/07/04 02:04:40
That would clean this code up a lot. I thought abo
Aaron Boodman
2012/07/04 06:35:40
Yes, that is what I had in mind.
Naming nit: how
mitchellwrosen
2012/07/05 17:43:38
I'm still going to have to make a bunch of local v
Aaron Boodman
2012/07/05 18:09:55
Why can't you just do SetCookieWithDetailsAsync(*p
| |
342 details->GetBoolean(keys::kSecureKey, &secure_)); | 332 if (params->details.value.get()) |
343 } | 333 value_ = *params->details.value; |
344 if (details->HasKey(keys::kHttpOnlyKey)) { | 334 if (params->details.domain.get()) |
345 EXTENSION_FUNCTION_VALIDATE( | 335 domain_ = *params->details.domain; |
346 details->GetBoolean(keys::kHttpOnlyKey, &http_only_)); | 336 if (params->details.path.get()) |
347 } | 337 path_ = *params->details.path; |
348 if (details->HasKey(keys::kExpirationDateKey)) { | 338 if (params->details.secure.get()) |
349 Value* expiration_date_value; | 339 secure_ = *params->details.secure; |
350 EXTENSION_FUNCTION_VALIDATE(details->Get(keys::kExpirationDateKey, | 340 if (params->details.http_only.get()) |
351 &expiration_date_value)); | 341 http_only_ = *params->details.http_only; |
352 double expiration_date; | 342 if (params->details.expiration_date.get()) { |
353 if (expiration_date_value->IsType(Value::TYPE_INTEGER)) { | |
354 int expiration_date_int; | |
355 EXTENSION_FUNCTION_VALIDATE( | |
356 expiration_date_value->GetAsInteger(&expiration_date_int)); | |
357 expiration_date = static_cast<double>(expiration_date_int); | |
358 } else { | |
359 EXTENSION_FUNCTION_VALIDATE( | |
360 expiration_date_value->GetAsDouble(&expiration_date)); | |
361 } | |
362 // Time::FromDoubleT converts double time 0 to empty Time object. So we need | 343 // Time::FromDoubleT converts double time 0 to empty Time object. So we need |
363 // to do special handling here. | 344 // to do special handling here. |
364 expiration_time_ = (expiration_date == 0) ? | 345 expiration_time_ = (*params->details.expiration_date == 0) ? |
365 base::Time::UnixEpoch() : base::Time::FromDoubleT(expiration_date); | 346 base::Time::UnixEpoch() : |
347 base::Time::FromDoubleT(*params->details.expiration_date); | |
366 } | 348 } |
367 | 349 |
368 net::URLRequestContextGetter* store_context = NULL; | 350 net::URLRequestContextGetter* store_context = NULL; |
369 if (!ParseStoreContext(details, &store_context, NULL)) | 351 if (!ParseStoreContext(params->details.store_id.get(), &store_context, NULL)) |
370 return false; | 352 return false; |
371 DCHECK(store_context); | 353 DCHECK(store_context); |
372 store_context_ = store_context; | 354 store_context_ = store_context; |
373 | 355 |
374 bool rv = BrowserThread::PostTask( | 356 bool rv = BrowserThread::PostTask( |
375 BrowserThread::IO, FROM_HERE, | 357 BrowserThread::IO, FROM_HERE, |
376 base::Bind(&SetCookieFunction::SetCookieOnIOThread, this)); | 358 base::Bind(&SetCookieFunction::SetCookieOnIOThread, this)); |
377 DCHECK(rv); | 359 DCHECK(rv); |
378 | 360 |
379 // Will finish asynchronously. | 361 // Will finish asynchronously. |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
429 SendResponse(success_); | 411 SendResponse(success_); |
430 } | 412 } |
431 | 413 |
432 RemoveCookieFunction::RemoveCookieFunction() : success_(false) { | 414 RemoveCookieFunction::RemoveCookieFunction() : success_(false) { |
433 } | 415 } |
434 | 416 |
435 RemoveCookieFunction::~RemoveCookieFunction() { | 417 RemoveCookieFunction::~RemoveCookieFunction() { |
436 } | 418 } |
437 | 419 |
438 bool RemoveCookieFunction::RunImpl() { | 420 bool RemoveCookieFunction::RunImpl() { |
439 // Return false if the arguments are malformed. | 421 scoped_ptr<Remove::Params> params(Remove::Params::Create(*args_)); |
440 DictionaryValue* details; | 422 EXTENSION_FUNCTION_VALIDATE(params.get()); |
441 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &details)); | |
442 DCHECK(details); | |
443 | 423 |
444 // Read/validate input parameters. | 424 // Read/validate input parameters. |
445 if (!ParseUrl(details, &url_, true)) | 425 if (!ParseUrl(params->details.url, &url_, true)) |
446 return false; | 426 return false; |
447 | 427 |
448 // Get the cookie name string or return false. | 428 name_ = params->details.name; |
Aaron Boodman
2012/07/04 00:04:31
same question here about storing params.
| |
449 EXTENSION_FUNCTION_VALIDATE(details->GetString(keys::kNameKey, &name_)); | |
450 | 429 |
451 net::URLRequestContextGetter* store_context = NULL; | 430 net::URLRequestContextGetter* store_context = NULL; |
452 if (!ParseStoreContext(details, &store_context, &store_id_)) | 431 if (!ParseStoreContext(params->details.store_id.get(), |
432 &store_context, | |
433 &store_id_)) | |
Aaron Boodman
2012/07/04 00:04:31
braces
mitchellwrosen
2012/07/04 02:04:40
Done.
| |
453 return false; | 434 return false; |
454 DCHECK(store_context); | 435 DCHECK(store_context); |
455 store_context_ = store_context; | 436 store_context_ = store_context; |
456 | 437 |
457 // Pass the work off to the IO thread. | 438 // Pass the work off to the IO thread. |
458 bool rv = BrowserThread::PostTask( | 439 bool rv = BrowserThread::PostTask( |
459 BrowserThread::IO, FROM_HERE, | 440 BrowserThread::IO, FROM_HERE, |
460 base::Bind(&RemoveCookieFunction::RemoveCookieOnIOThread, this)); | 441 base::Bind(&RemoveCookieFunction::RemoveCookieOnIOThread, this)); |
461 DCHECK(rv); | 442 DCHECK(rv); |
462 | 443 |
463 // Will return asynchronously. | 444 // Will return asynchronously. |
464 return true; | 445 return true; |
465 } | 446 } |
466 | 447 |
467 void RemoveCookieFunction::RemoveCookieOnIOThread() { | 448 void RemoveCookieFunction::RemoveCookieOnIOThread() { |
468 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 449 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
469 | 450 |
470 // Remove the cookie | 451 // Remove the cookie |
471 net::CookieStore* cookie_store = | 452 net::CookieStore* cookie_store = |
472 store_context_->GetURLRequestContext()->cookie_store(); | 453 store_context_->GetURLRequestContext()->cookie_store(); |
473 cookie_store->DeleteCookieAsync( | 454 cookie_store->DeleteCookieAsync( |
474 url_, name_, | 455 url_, name_, |
475 base::Bind(&RemoveCookieFunction::RemoveCookieCallback, this)); | 456 base::Bind(&RemoveCookieFunction::RemoveCookieCallback, this)); |
476 } | 457 } |
477 | 458 |
478 void RemoveCookieFunction::RemoveCookieCallback() { | 459 void RemoveCookieFunction::RemoveCookieCallback() { |
479 // Build the callback result | 460 // Build the callback result |
480 DictionaryValue* resultDictionary = new DictionaryValue(); | 461 Remove::Result::Details details; |
481 resultDictionary->SetString(keys::kNameKey, name_); | 462 details.name = name_; |
482 resultDictionary->SetString(keys::kUrlKey, url_.spec()); | 463 details.url = url_.spec(); |
483 resultDictionary->SetString(keys::kStoreIdKey, store_id_); | 464 details.store_id = store_id_; |
484 result_.reset(resultDictionary); | 465 result_.reset(Remove::Result::Create(details)); |
485 | 466 |
486 // Return to UI thread | 467 // Return to UI thread |
487 bool rv = BrowserThread::PostTask( | 468 bool rv = BrowserThread::PostTask( |
488 BrowserThread::UI, FROM_HERE, | 469 BrowserThread::UI, FROM_HERE, |
489 base::Bind(&RemoveCookieFunction::RespondOnUIThread, this)); | 470 base::Bind(&RemoveCookieFunction::RespondOnUIThread, this)); |
490 DCHECK(rv); | 471 DCHECK(rv); |
491 } | 472 } |
492 | 473 |
493 void RemoveCookieFunction::RespondOnUIThread() { | 474 void RemoveCookieFunction::RespondOnUIThread() { |
494 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 475 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
(...skipping 13 matching lines...) Expand all Loading... | |
508 } | 489 } |
509 DCHECK(original_profile != incognito_profile); | 490 DCHECK(original_profile != incognito_profile); |
510 | 491 |
511 // Iterate through all browser instances, and for each browser, | 492 // Iterate through all browser instances, and for each browser, |
512 // add its tab IDs to either the regular or incognito tab ID list depending | 493 // add its tab IDs to either the regular or incognito tab ID list depending |
513 // whether the browser is regular or incognito. | 494 // whether the browser is regular or incognito. |
514 for (BrowserList::const_iterator iter = BrowserList::begin(); | 495 for (BrowserList::const_iterator iter = BrowserList::begin(); |
515 iter != BrowserList::end(); ++iter) { | 496 iter != BrowserList::end(); ++iter) { |
516 Browser* browser = *iter; | 497 Browser* browser = *iter; |
517 if (browser->profile() == original_profile) { | 498 if (browser->profile() == original_profile) { |
518 cookies_helpers::AppendToTabIdList(browser, | 499 cookies_helpers::AppendToTabIdList(browser, original_tab_ids.get()); |
519 original_tab_ids.get()); | |
520 } else if (incognito_tab_ids.get() && | 500 } else if (incognito_tab_ids.get() && |
521 browser->profile() == incognito_profile) { | 501 browser->profile() == incognito_profile) { |
522 cookies_helpers::AppendToTabIdList(browser, | 502 cookies_helpers::AppendToTabIdList(browser, incognito_tab_ids.get()); |
523 incognito_tab_ids.get()); | |
524 } | 503 } |
525 } | 504 } |
526 // Return a list of all cookie stores with at least one open tab. | 505 // Return a list of all cookie stores with at least one open tab. |
527 ListValue* cookie_store_list = new ListValue(); | 506 std::vector<linked_ptr<CookieStore> > cookie_stores; |
528 if (original_tab_ids->GetSize() > 0) { | 507 if (original_tab_ids->GetSize() > 0) { |
529 cookie_store_list->Append( | 508 scoped_ptr<DictionaryValue> dict( |
530 cookies_helpers::CreateCookieStoreValue( | 509 cookies_helpers::CreateCookieStoreValue( |
531 original_profile, original_tab_ids.release())); | 510 original_profile, original_tab_ids.release())); |
511 | |
512 linked_ptr<CookieStore> cookie_store(new CookieStore()); | |
513 CookieStore::Populate(*dict, cookie_store.get()); | |
514 cookie_stores.push_back(cookie_store); | |
532 } | 515 } |
533 if (incognito_tab_ids.get() && incognito_tab_ids->GetSize() > 0 && | 516 if (incognito_tab_ids.get() && incognito_tab_ids->GetSize() > 0 && |
534 incognito_profile) { | 517 incognito_profile) { |
535 cookie_store_list->Append( | 518 scoped_ptr<DictionaryValue> dict( |
536 cookies_helpers::CreateCookieStoreValue( | 519 cookies_helpers::CreateCookieStoreValue( |
537 incognito_profile, incognito_tab_ids.release())); | 520 incognito_profile, incognito_tab_ids.release())); |
521 linked_ptr<CookieStore> cookie_store(new CookieStore()); | |
522 CookieStore::Populate(*dict, cookie_store.get()); | |
523 cookie_stores.push_back(cookie_store); | |
538 } | 524 } |
539 result_.reset(cookie_store_list); | 525 result_.reset(GetAllCookieStores::Result::Create(cookie_stores)); |
540 return true; | 526 return true; |
541 } | 527 } |
542 | 528 |
543 void GetAllCookieStoresFunction::Run() { | 529 void GetAllCookieStoresFunction::Run() { |
544 SendResponse(RunImpl()); | 530 SendResponse(RunImpl()); |
545 } | 531 } |
546 | 532 |
547 } // namespace extensions | 533 } // namespace extensions |
OLD | NEW |