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 <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 *store_id = cookies_helpers::GetStoreIdFromProfile(store_profile); | 182 *store_id = cookies_helpers::GetStoreIdFromProfile(store_profile); |
183 } | 183 } |
184 | 184 |
185 if (context) | 185 if (context) |
186 *context = store_profile->GetRequestContext(); | 186 *context = store_profile->GetRequestContext(); |
187 DCHECK(context); | 187 DCHECK(context); |
188 | 188 |
189 return true; | 189 return true; |
190 } | 190 } |
191 | 191 |
192 CookiesGetFunction::CookiesGetFunction() { | 192 GetCookieFunction::GetCookieFunction() { |
193 } | 193 } |
194 | 194 |
195 CookiesGetFunction::~CookiesGetFunction() { | 195 GetCookieFunction::~GetCookieFunction() { |
196 } | 196 } |
197 | 197 |
198 bool CookiesGetFunction::RunImpl() { | 198 bool GetCookieFunction::RunImpl() { |
199 parsed_args_ = Get::Params::Create(*args_); | 199 parsed_args_ = Get::Params::Create(*args_); |
200 EXTENSION_FUNCTION_VALIDATE(parsed_args_.get()); | 200 EXTENSION_FUNCTION_VALIDATE(parsed_args_.get()); |
201 | 201 |
202 // Read/validate input parameters. | 202 // Read/validate input parameters. |
203 if (!ParseUrl(parsed_args_->details.url, &url_, true)) | 203 if (!ParseUrl(parsed_args_->details.url, &url_, true)) |
204 return false; | 204 return false; |
205 | 205 |
206 std::string store_id = parsed_args_->details.store_id.get() ? | 206 std::string store_id = parsed_args_->details.store_id.get() ? |
207 *parsed_args_->details.store_id : ""; | 207 *parsed_args_->details.store_id : ""; |
208 net::URLRequestContextGetter* store_context = NULL; | 208 net::URLRequestContextGetter* store_context = NULL; |
209 if (!ParseStoreContext(&store_id, &store_context)) | 209 if (!ParseStoreContext(&store_id, &store_context)) |
210 return false; | 210 return false; |
211 store_context_ = store_context; | 211 store_context_ = store_context; |
212 if (!parsed_args_->details.store_id.get()) | 212 if (!parsed_args_->details.store_id.get()) |
213 parsed_args_->details.store_id.reset(new std::string(store_id)); | 213 parsed_args_->details.store_id.reset(new std::string(store_id)); |
214 | 214 |
215 store_context_ = store_context; | 215 store_context_ = store_context; |
216 | 216 |
217 bool rv = BrowserThread::PostTask( | 217 bool rv = BrowserThread::PostTask( |
218 BrowserThread::IO, FROM_HERE, | 218 BrowserThread::IO, FROM_HERE, |
219 base::Bind(&CookiesGetFunction::GetCookieOnIOThread, this)); | 219 base::Bind(&GetCookieFunction::GetCookieOnIOThread, this)); |
220 DCHECK(rv); | 220 DCHECK(rv); |
221 | 221 |
222 // Will finish asynchronously. | 222 // Will finish asynchronously. |
223 return true; | 223 return true; |
224 } | 224 } |
225 | 225 |
226 void CookiesGetFunction::GetCookieOnIOThread() { | 226 void GetCookieFunction::GetCookieOnIOThread() { |
227 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 227 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
228 net::CookieStore* cookie_store = | 228 net::CookieStore* cookie_store = |
229 store_context_->GetURLRequestContext()->cookie_store(); | 229 store_context_->GetURLRequestContext()->cookie_store(); |
230 cookies_helpers::GetCookieListFromStore( | 230 cookies_helpers::GetCookieListFromStore( |
231 cookie_store, url_, | 231 cookie_store, url_, |
232 base::Bind(&CookiesGetFunction::GetCookieCallback, this)); | 232 base::Bind(&GetCookieFunction::GetCookieCallback, this)); |
233 } | 233 } |
234 | 234 |
235 void CookiesGetFunction::GetCookieCallback(const net::CookieList& cookie_list) { | 235 void GetCookieFunction::GetCookieCallback(const net::CookieList& cookie_list) { |
236 net::CookieList::const_iterator it; | 236 net::CookieList::const_iterator it; |
237 for (it = cookie_list.begin(); it != cookie_list.end(); ++it) { | 237 for (it = cookie_list.begin(); it != cookie_list.end(); ++it) { |
238 // Return the first matching cookie. Relies on the fact that the | 238 // Return the first matching cookie. Relies on the fact that the |
239 // CookieMonster returns them in canonical order (longest path, then | 239 // CookieMonster returns them in canonical order (longest path, then |
240 // earliest creation time). | 240 // earliest creation time). |
241 if (it->Name() == parsed_args_->details.name) { | 241 if (it->Name() == parsed_args_->details.name) { |
242 scoped_ptr<Cookie> cookie( | 242 scoped_ptr<Cookie> cookie( |
243 cookies_helpers::CreateCookie(*it, *parsed_args_->details.store_id)); | 243 cookies_helpers::CreateCookie(*it, *parsed_args_->details.store_id)); |
244 results_ = Get::Results::Create(*cookie); | 244 results_ = Get::Results::Create(*cookie); |
245 break; | 245 break; |
246 } | 246 } |
247 } | 247 } |
248 | 248 |
249 // The cookie doesn't exist; return null. | 249 // The cookie doesn't exist; return null. |
250 if (it == cookie_list.end()) | 250 if (it == cookie_list.end()) |
251 SetResult(Value::CreateNullValue()); | 251 SetResult(Value::CreateNullValue()); |
252 | 252 |
253 bool rv = BrowserThread::PostTask( | 253 bool rv = BrowserThread::PostTask( |
254 BrowserThread::UI, FROM_HERE, | 254 BrowserThread::UI, FROM_HERE, |
255 base::Bind(&CookiesGetFunction::RespondOnUIThread, this)); | 255 base::Bind(&GetCookieFunction::RespondOnUIThread, this)); |
256 DCHECK(rv); | 256 DCHECK(rv); |
257 } | 257 } |
258 | 258 |
259 void CookiesGetFunction::RespondOnUIThread() { | 259 void GetCookieFunction::RespondOnUIThread() { |
260 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 260 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
261 SendResponse(true); | 261 SendResponse(true); |
262 } | 262 } |
263 | 263 |
264 CookiesGetAllFunction::CookiesGetAllFunction() { | 264 GetAllCookiesFunction::GetAllCookiesFunction() { |
265 } | 265 } |
266 | 266 |
267 CookiesGetAllFunction::~CookiesGetAllFunction() { | 267 GetAllCookiesFunction::~GetAllCookiesFunction() { |
268 } | 268 } |
269 | 269 |
270 bool CookiesGetAllFunction::RunImpl() { | 270 bool GetAllCookiesFunction::RunImpl() { |
271 parsed_args_ = GetAll::Params::Create(*args_); | 271 parsed_args_ = GetAll::Params::Create(*args_); |
272 EXTENSION_FUNCTION_VALIDATE(parsed_args_.get()); | 272 EXTENSION_FUNCTION_VALIDATE(parsed_args_.get()); |
273 | 273 |
274 if (parsed_args_->details.url.get() && | 274 if (parsed_args_->details.url.get() && |
275 !ParseUrl(*parsed_args_->details.url, &url_, false)) { | 275 !ParseUrl(*parsed_args_->details.url, &url_, false)) { |
276 return false; | 276 return false; |
277 } | 277 } |
278 | 278 |
279 std::string store_id = parsed_args_->details.store_id.get() ? | 279 std::string store_id = parsed_args_->details.store_id.get() ? |
280 *parsed_args_->details.store_id : ""; | 280 *parsed_args_->details.store_id : ""; |
281 net::URLRequestContextGetter* store_context = NULL; | 281 net::URLRequestContextGetter* store_context = NULL; |
282 if (!ParseStoreContext(&store_id, &store_context)) | 282 if (!ParseStoreContext(&store_id, &store_context)) |
283 return false; | 283 return false; |
284 store_context_ = store_context; | 284 store_context_ = store_context; |
285 if (!parsed_args_->details.store_id.get()) | 285 if (!parsed_args_->details.store_id.get()) |
286 parsed_args_->details.store_id.reset(new std::string(store_id)); | 286 parsed_args_->details.store_id.reset(new std::string(store_id)); |
287 | 287 |
288 bool rv = BrowserThread::PostTask( | 288 bool rv = BrowserThread::PostTask( |
289 BrowserThread::IO, FROM_HERE, | 289 BrowserThread::IO, FROM_HERE, |
290 base::Bind(&CookiesGetAllFunction::GetAllCookiesOnIOThread, this)); | 290 base::Bind(&GetAllCookiesFunction::GetAllCookiesOnIOThread, this)); |
291 DCHECK(rv); | 291 DCHECK(rv); |
292 | 292 |
293 // Will finish asynchronously. | 293 // Will finish asynchronously. |
294 return true; | 294 return true; |
295 } | 295 } |
296 | 296 |
297 void CookiesGetAllFunction::GetAllCookiesOnIOThread() { | 297 void GetAllCookiesFunction::GetAllCookiesOnIOThread() { |
298 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 298 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
299 net::CookieStore* cookie_store = | 299 net::CookieStore* cookie_store = |
300 store_context_->GetURLRequestContext()->cookie_store(); | 300 store_context_->GetURLRequestContext()->cookie_store(); |
301 cookies_helpers::GetCookieListFromStore( | 301 cookies_helpers::GetCookieListFromStore( |
302 cookie_store, url_, | 302 cookie_store, url_, |
303 base::Bind(&CookiesGetAllFunction::GetAllCookiesCallback, this)); | 303 base::Bind(&GetAllCookiesFunction::GetAllCookiesCallback, this)); |
304 } | 304 } |
305 | 305 |
306 void CookiesGetAllFunction::GetAllCookiesCallback( | 306 void GetAllCookiesFunction::GetAllCookiesCallback( |
307 const net::CookieList& cookie_list) { | 307 const net::CookieList& cookie_list) { |
308 const extensions::Extension* extension = GetExtension(); | 308 const extensions::Extension* extension = GetExtension(); |
309 if (extension) { | 309 if (extension) { |
310 std::vector<linked_ptr<Cookie> > match_vector; | 310 std::vector<linked_ptr<Cookie> > match_vector; |
311 cookies_helpers::AppendMatchingCookiesToVector( | 311 cookies_helpers::AppendMatchingCookiesToVector( |
312 cookie_list, url_, &parsed_args_->details, | 312 cookie_list, url_, &parsed_args_->details, |
313 GetExtension(), &match_vector); | 313 GetExtension(), &match_vector); |
314 | 314 |
315 results_ = GetAll::Results::Create(match_vector); | 315 results_ = GetAll::Results::Create(match_vector); |
316 } | 316 } |
317 bool rv = BrowserThread::PostTask( | 317 bool rv = BrowserThread::PostTask( |
318 BrowserThread::UI, FROM_HERE, | 318 BrowserThread::UI, FROM_HERE, |
319 base::Bind(&CookiesGetAllFunction::RespondOnUIThread, this)); | 319 base::Bind(&GetAllCookiesFunction::RespondOnUIThread, this)); |
320 DCHECK(rv); | 320 DCHECK(rv); |
321 } | 321 } |
322 | 322 |
323 void CookiesGetAllFunction::RespondOnUIThread() { | 323 void GetAllCookiesFunction::RespondOnUIThread() { |
324 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 324 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
325 SendResponse(true); | 325 SendResponse(true); |
326 } | 326 } |
327 | 327 |
328 CookiesSetFunction::CookiesSetFunction() : success_(false) { | 328 SetCookieFunction::SetCookieFunction() : success_(false) { |
329 } | 329 } |
330 | 330 |
331 CookiesSetFunction::~CookiesSetFunction() { | 331 SetCookieFunction::~SetCookieFunction() { |
332 } | 332 } |
333 | 333 |
334 bool CookiesSetFunction::RunImpl() { | 334 bool SetCookieFunction::RunImpl() { |
335 parsed_args_ = Set::Params::Create(*args_); | 335 parsed_args_ = Set::Params::Create(*args_); |
336 EXTENSION_FUNCTION_VALIDATE(parsed_args_.get()); | 336 EXTENSION_FUNCTION_VALIDATE(parsed_args_.get()); |
337 | 337 |
338 // Read/validate input parameters. | 338 // Read/validate input parameters. |
339 if (!ParseUrl(parsed_args_->details.url, &url_, true)) | 339 if (!ParseUrl(parsed_args_->details.url, &url_, true)) |
340 return false; | 340 return false; |
341 | 341 |
342 std::string store_id = parsed_args_->details.store_id.get() ? | 342 std::string store_id = parsed_args_->details.store_id.get() ? |
343 *parsed_args_->details.store_id : ""; | 343 *parsed_args_->details.store_id : ""; |
344 net::URLRequestContextGetter* store_context = NULL; | 344 net::URLRequestContextGetter* store_context = NULL; |
345 if (!ParseStoreContext(&store_id, &store_context)) | 345 if (!ParseStoreContext(&store_id, &store_context)) |
346 return false; | 346 return false; |
347 store_context_ = store_context; | 347 store_context_ = store_context; |
348 if (!parsed_args_->details.store_id.get()) | 348 if (!parsed_args_->details.store_id.get()) |
349 parsed_args_->details.store_id.reset(new std::string(store_id)); | 349 parsed_args_->details.store_id.reset(new std::string(store_id)); |
350 | 350 |
351 bool rv = BrowserThread::PostTask( | 351 bool rv = BrowserThread::PostTask( |
352 BrowserThread::IO, FROM_HERE, | 352 BrowserThread::IO, FROM_HERE, |
353 base::Bind(&CookiesSetFunction::SetCookieOnIOThread, this)); | 353 base::Bind(&SetCookieFunction::SetCookieOnIOThread, this)); |
354 DCHECK(rv); | 354 DCHECK(rv); |
355 | 355 |
356 // Will finish asynchronously. | 356 // Will finish asynchronously. |
357 return true; | 357 return true; |
358 } | 358 } |
359 | 359 |
360 void CookiesSetFunction::SetCookieOnIOThread() { | 360 void SetCookieFunction::SetCookieOnIOThread() { |
361 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 361 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
362 net::CookieMonster* cookie_monster = | 362 net::CookieMonster* cookie_monster = |
363 store_context_->GetURLRequestContext()->cookie_store()-> | 363 store_context_->GetURLRequestContext()->cookie_store()-> |
364 GetCookieMonster(); | 364 GetCookieMonster(); |
365 | 365 |
366 base::Time expiration_time; | 366 base::Time expiration_time; |
367 if (parsed_args_->details.expiration_date.get()) { | 367 if (parsed_args_->details.expiration_date.get()) { |
368 // Time::FromDoubleT converts double time 0 to empty Time object. So we need | 368 // Time::FromDoubleT converts double time 0 to empty Time object. So we need |
369 // to do special handling here. | 369 // to do special handling here. |
370 expiration_time = (*parsed_args_->details.expiration_date == 0) ? | 370 expiration_time = (*parsed_args_->details.expiration_date == 0) ? |
371 base::Time::UnixEpoch() : | 371 base::Time::UnixEpoch() : |
372 base::Time::FromDoubleT(*parsed_args_->details.expiration_date); | 372 base::Time::FromDoubleT(*parsed_args_->details.expiration_date); |
373 } | 373 } |
374 | 374 |
375 cookie_monster->SetCookieWithDetailsAsync( | 375 cookie_monster->SetCookieWithDetailsAsync( |
376 url_, | 376 url_, |
377 parsed_args_->details.name.get() ? *parsed_args_->details.name : "", | 377 parsed_args_->details.name.get() ? *parsed_args_->details.name : "", |
378 parsed_args_->details.value.get() ? *parsed_args_->details.value : "", | 378 parsed_args_->details.value.get() ? *parsed_args_->details.value : "", |
379 parsed_args_->details.domain.get() ? *parsed_args_->details.domain : "", | 379 parsed_args_->details.domain.get() ? *parsed_args_->details.domain : "", |
380 parsed_args_->details.path.get() ? *parsed_args_->details.path : "", | 380 parsed_args_->details.path.get() ? *parsed_args_->details.path : "", |
381 expiration_time, | 381 expiration_time, |
382 parsed_args_->details.secure.get() ? | 382 parsed_args_->details.secure.get() ? |
383 *parsed_args_->details.secure.get() : | 383 *parsed_args_->details.secure.get() : |
384 false, | 384 false, |
385 parsed_args_->details.http_only.get() ? | 385 parsed_args_->details.http_only.get() ? |
386 *parsed_args_->details.http_only : | 386 *parsed_args_->details.http_only : |
387 false, | 387 false, |
388 base::Bind(&CookiesSetFunction::PullCookie, this)); | 388 base::Bind(&SetCookieFunction::PullCookie, this)); |
389 } | 389 } |
390 | 390 |
391 void CookiesSetFunction::PullCookie(bool set_cookie_result) { | 391 void SetCookieFunction::PullCookie(bool set_cookie_result) { |
392 // Pull the newly set cookie. | 392 // Pull the newly set cookie. |
393 net::CookieMonster* cookie_monster = | 393 net::CookieMonster* cookie_monster = |
394 store_context_->GetURLRequestContext()->cookie_store()-> | 394 store_context_->GetURLRequestContext()->cookie_store()-> |
395 GetCookieMonster(); | 395 GetCookieMonster(); |
396 success_ = set_cookie_result; | 396 success_ = set_cookie_result; |
397 cookies_helpers::GetCookieListFromStore( | 397 cookies_helpers::GetCookieListFromStore( |
398 cookie_monster, url_, | 398 cookie_monster, url_, |
399 base::Bind(&CookiesSetFunction::PullCookieCallback, this)); | 399 base::Bind(&SetCookieFunction::PullCookieCallback, this)); |
400 } | 400 } |
401 | 401 |
402 void CookiesSetFunction::PullCookieCallback( | 402 void SetCookieFunction::PullCookieCallback(const net::CookieList& cookie_list) { |
403 const net::CookieList& cookie_list) { | |
404 net::CookieList::const_iterator it; | 403 net::CookieList::const_iterator it; |
405 for (it = cookie_list.begin(); it != cookie_list.end(); ++it) { | 404 for (it = cookie_list.begin(); it != cookie_list.end(); ++it) { |
406 // Return the first matching cookie. Relies on the fact that the | 405 // Return the first matching cookie. Relies on the fact that the |
407 // CookieMonster returns them in canonical order (longest path, then | 406 // CookieMonster returns them in canonical order (longest path, then |
408 // earliest creation time). | 407 // earliest creation time). |
409 std::string name = parsed_args_->details.name.get() ? | 408 std::string name = parsed_args_->details.name.get() ? |
410 *parsed_args_->details.name : ""; | 409 *parsed_args_->details.name : ""; |
411 if (it->Name() == name) { | 410 if (it->Name() == name) { |
412 scoped_ptr<Cookie> cookie( | 411 scoped_ptr<Cookie> cookie( |
413 cookies_helpers::CreateCookie(*it, *parsed_args_->details.store_id)); | 412 cookies_helpers::CreateCookie(*it, *parsed_args_->details.store_id)); |
414 results_ = Set::Results::Create(*cookie); | 413 results_ = Set::Results::Create(*cookie); |
415 break; | 414 break; |
416 } | 415 } |
417 } | 416 } |
418 | 417 |
419 bool rv = BrowserThread::PostTask( | 418 bool rv = BrowserThread::PostTask( |
420 BrowserThread::UI, FROM_HERE, | 419 BrowserThread::UI, FROM_HERE, |
421 base::Bind(&CookiesSetFunction::RespondOnUIThread, this)); | 420 base::Bind(&SetCookieFunction::RespondOnUIThread, this)); |
422 DCHECK(rv); | 421 DCHECK(rv); |
423 } | 422 } |
424 | 423 |
425 void CookiesSetFunction::RespondOnUIThread() { | 424 void SetCookieFunction::RespondOnUIThread() { |
426 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 425 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
427 if (!success_) { | 426 if (!success_) { |
428 std::string name = parsed_args_->details.name.get() ? | 427 std::string name = parsed_args_->details.name.get() ? |
429 *parsed_args_->details.name : ""; | 428 *parsed_args_->details.name : ""; |
430 error_ = ErrorUtils::FormatErrorMessage( | 429 error_ = ErrorUtils::FormatErrorMessage( |
431 keys::kCookieSetFailedError, name); | 430 keys::kCookieSetFailedError, name); |
432 } | 431 } |
433 SendResponse(success_); | 432 SendResponse(success_); |
434 } | 433 } |
435 | 434 |
436 CookiesRemoveFunction::CookiesRemoveFunction() { | 435 RemoveCookieFunction::RemoveCookieFunction() { |
437 } | 436 } |
438 | 437 |
439 CookiesRemoveFunction::~CookiesRemoveFunction() { | 438 RemoveCookieFunction::~RemoveCookieFunction() { |
440 } | 439 } |
441 | 440 |
442 bool CookiesRemoveFunction::RunImpl() { | 441 bool RemoveCookieFunction::RunImpl() { |
443 parsed_args_ = Remove::Params::Create(*args_); | 442 parsed_args_ = Remove::Params::Create(*args_); |
444 EXTENSION_FUNCTION_VALIDATE(parsed_args_.get()); | 443 EXTENSION_FUNCTION_VALIDATE(parsed_args_.get()); |
445 | 444 |
446 // Read/validate input parameters. | 445 // Read/validate input parameters. |
447 if (!ParseUrl(parsed_args_->details.url, &url_, true)) | 446 if (!ParseUrl(parsed_args_->details.url, &url_, true)) |
448 return false; | 447 return false; |
449 | 448 |
450 std::string store_id = parsed_args_->details.store_id.get() ? | 449 std::string store_id = parsed_args_->details.store_id.get() ? |
451 *parsed_args_->details.store_id : ""; | 450 *parsed_args_->details.store_id : ""; |
452 net::URLRequestContextGetter* store_context = NULL; | 451 net::URLRequestContextGetter* store_context = NULL; |
453 if (!ParseStoreContext(&store_id, &store_context)) | 452 if (!ParseStoreContext(&store_id, &store_context)) |
454 return false; | 453 return false; |
455 store_context_ = store_context; | 454 store_context_ = store_context; |
456 if (!parsed_args_->details.store_id.get()) | 455 if (!parsed_args_->details.store_id.get()) |
457 parsed_args_->details.store_id.reset(new std::string(store_id)); | 456 parsed_args_->details.store_id.reset(new std::string(store_id)); |
458 | 457 |
459 // Pass the work off to the IO thread. | 458 // Pass the work off to the IO thread. |
460 bool rv = BrowserThread::PostTask( | 459 bool rv = BrowserThread::PostTask( |
461 BrowserThread::IO, FROM_HERE, | 460 BrowserThread::IO, FROM_HERE, |
462 base::Bind(&CookiesRemoveFunction::RemoveCookieOnIOThread, this)); | 461 base::Bind(&RemoveCookieFunction::RemoveCookieOnIOThread, this)); |
463 DCHECK(rv); | 462 DCHECK(rv); |
464 | 463 |
465 // Will return asynchronously. | 464 // Will return asynchronously. |
466 return true; | 465 return true; |
467 } | 466 } |
468 | 467 |
469 void CookiesRemoveFunction::RemoveCookieOnIOThread() { | 468 void RemoveCookieFunction::RemoveCookieOnIOThread() { |
470 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 469 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
471 | 470 |
472 // Remove the cookie | 471 // Remove the cookie |
473 net::CookieStore* cookie_store = | 472 net::CookieStore* cookie_store = |
474 store_context_->GetURLRequestContext()->cookie_store(); | 473 store_context_->GetURLRequestContext()->cookie_store(); |
475 cookie_store->DeleteCookieAsync( | 474 cookie_store->DeleteCookieAsync( |
476 url_, parsed_args_->details.name, | 475 url_, parsed_args_->details.name, |
477 base::Bind(&CookiesRemoveFunction::RemoveCookieCallback, this)); | 476 base::Bind(&RemoveCookieFunction::RemoveCookieCallback, this)); |
478 } | 477 } |
479 | 478 |
480 void CookiesRemoveFunction::RemoveCookieCallback() { | 479 void RemoveCookieFunction::RemoveCookieCallback() { |
481 // Build the callback result | 480 // Build the callback result |
482 Remove::Results::Details details; | 481 Remove::Results::Details details; |
483 details.name = parsed_args_->details.name; | 482 details.name = parsed_args_->details.name; |
484 details.url = url_.spec(); | 483 details.url = url_.spec(); |
485 details.store_id = *parsed_args_->details.store_id; | 484 details.store_id = *parsed_args_->details.store_id; |
486 results_ = Remove::Results::Create(details); | 485 results_ = Remove::Results::Create(details); |
487 | 486 |
488 // Return to UI thread | 487 // Return to UI thread |
489 bool rv = BrowserThread::PostTask( | 488 bool rv = BrowserThread::PostTask( |
490 BrowserThread::UI, FROM_HERE, | 489 BrowserThread::UI, FROM_HERE, |
491 base::Bind(&CookiesRemoveFunction::RespondOnUIThread, this)); | 490 base::Bind(&RemoveCookieFunction::RespondOnUIThread, this)); |
492 DCHECK(rv); | 491 DCHECK(rv); |
493 } | 492 } |
494 | 493 |
495 void CookiesRemoveFunction::RespondOnUIThread() { | 494 void RemoveCookieFunction::RespondOnUIThread() { |
496 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 495 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
497 SendResponse(true); | 496 SendResponse(true); |
498 } | 497 } |
499 | 498 |
500 bool CookiesGetAllCookieStoresFunction::RunImpl() { | 499 bool GetAllCookieStoresFunction::RunImpl() { |
501 Profile* original_profile = profile(); | 500 Profile* original_profile = profile(); |
502 DCHECK(original_profile); | 501 DCHECK(original_profile); |
503 scoped_ptr<ListValue> original_tab_ids(new ListValue()); | 502 scoped_ptr<ListValue> original_tab_ids(new ListValue()); |
504 Profile* incognito_profile = NULL; | 503 Profile* incognito_profile = NULL; |
505 scoped_ptr<ListValue> incognito_tab_ids; | 504 scoped_ptr<ListValue> incognito_tab_ids; |
506 if (include_incognito() && profile()->HasOffTheRecordProfile()) { | 505 if (include_incognito() && profile()->HasOffTheRecordProfile()) { |
507 incognito_profile = profile()->GetOffTheRecordProfile(); | 506 incognito_profile = profile()->GetOffTheRecordProfile(); |
508 if (incognito_profile) | 507 if (incognito_profile) |
509 incognito_tab_ids.reset(new ListValue()); | 508 incognito_tab_ids.reset(new ListValue()); |
510 } | 509 } |
(...skipping 22 matching lines...) Expand all Loading... |
533 if (incognito_tab_ids.get() && incognito_tab_ids->GetSize() > 0 && | 532 if (incognito_tab_ids.get() && incognito_tab_ids->GetSize() > 0 && |
534 incognito_profile) { | 533 incognito_profile) { |
535 cookie_stores.push_back(make_linked_ptr( | 534 cookie_stores.push_back(make_linked_ptr( |
536 cookies_helpers::CreateCookieStore( | 535 cookies_helpers::CreateCookieStore( |
537 incognito_profile, incognito_tab_ids.release()).release())); | 536 incognito_profile, incognito_tab_ids.release()).release())); |
538 } | 537 } |
539 results_ = GetAllCookieStores::Results::Create(cookie_stores); | 538 results_ = GetAllCookieStores::Results::Create(cookie_stores); |
540 return true; | 539 return true; |
541 } | 540 } |
542 | 541 |
543 void CookiesGetAllCookieStoresFunction::Run() { | 542 void GetAllCookieStoresFunction::Run() { |
544 SendResponse(RunImpl()); | 543 SendResponse(RunImpl()); |
545 } | 544 } |
546 | 545 |
547 CookiesAPI::CookiesAPI(Profile* profile) | 546 CookiesAPI::CookiesAPI(Profile* profile) |
548 : profile_(profile) { | 547 : profile_(profile) { |
549 ExtensionSystem::Get(profile_)->event_router()->RegisterObserver( | 548 ExtensionSystem::Get(profile_)->event_router()->RegisterObserver( |
550 this, keys::kOnChanged); | 549 this, keys::kOnChanged); |
551 } | 550 } |
552 | 551 |
553 CookiesAPI::~CookiesAPI() { | 552 CookiesAPI::~CookiesAPI() { |
(...skipping 11 matching lines...) Expand all Loading... |
565 return &g_factory.Get(); | 564 return &g_factory.Get(); |
566 } | 565 } |
567 | 566 |
568 void CookiesAPI::OnListenerAdded( | 567 void CookiesAPI::OnListenerAdded( |
569 const extensions::EventListenerInfo& details) { | 568 const extensions::EventListenerInfo& details) { |
570 cookies_event_router_.reset(new CookiesEventRouter(profile_)); | 569 cookies_event_router_.reset(new CookiesEventRouter(profile_)); |
571 ExtensionSystem::Get(profile_)->event_router()->UnregisterObserver(this); | 570 ExtensionSystem::Get(profile_)->event_router()->UnregisterObserver(this); |
572 } | 571 } |
573 | 572 |
574 } // namespace extensions | 573 } // namespace extensions |
OLD | NEW |