| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/extension_cookies_api.h" | 7 #include "chrome/browser/extensions/extension_cookies_api.h" |
| 8 | 8 |
| 9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
| 10 #include "base/task.h" | 10 #include "base/task.h" |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 extension_cookies_helpers::GetURLFromCanonicalCookie(*details->cookie); | 69 extension_cookies_helpers::GetURLFromCanonicalCookie(*details->cookie); |
| 70 DispatchEvent(profile, keys::kOnChanged, json_args, cookie_domain); | 70 DispatchEvent(profile, keys::kOnChanged, json_args, cookie_domain); |
| 71 } | 71 } |
| 72 | 72 |
| 73 void ExtensionCookiesEventRouter::DispatchEvent(Profile* profile, | 73 void ExtensionCookiesEventRouter::DispatchEvent(Profile* profile, |
| 74 const char* event_name, | 74 const char* event_name, |
| 75 const std::string& json_args, | 75 const std::string& json_args, |
| 76 GURL& cookie_domain) { | 76 GURL& cookie_domain) { |
| 77 if (profile && profile->GetExtensionMessageService()) { | 77 if (profile && profile->GetExtensionMessageService()) { |
| 78 profile->GetExtensionMessageService()->DispatchEventToRenderers( | 78 profile->GetExtensionMessageService()->DispatchEventToRenderers( |
| 79 event_name, json_args, profile->IsOffTheRecord(), cookie_domain); | 79 event_name, json_args, profile, cookie_domain); |
| 80 } | 80 } |
| 81 } | 81 } |
| 82 | 82 |
| 83 bool CookiesFunction::ParseUrl(const DictionaryValue* details, GURL* url, | 83 bool CookiesFunction::ParseUrl(const DictionaryValue* details, GURL* url, |
| 84 bool check_host_permissions) { | 84 bool check_host_permissions) { |
| 85 DCHECK(details && url); | 85 DCHECK(details && url); |
| 86 std::string url_string; | 86 std::string url_string; |
| 87 // Get the URL string or return false. | 87 // Get the URL string or return false. |
| 88 EXTENSION_FUNCTION_VALIDATE(details->GetString(keys::kUrlKey, &url_string)); | 88 EXTENSION_FUNCTION_VALIDATE(details->GetString(keys::kUrlKey, &url_string)); |
| 89 *url = GURL(url_string); | 89 *url = GURL(url_string); |
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 398 // should happen after this. | 398 // should happen after this. |
| 399 bool rv = ChromeThread::PostTask( | 399 bool rv = ChromeThread::PostTask( |
| 400 ChromeThread::IO, FROM_HERE, | 400 ChromeThread::IO, FROM_HERE, |
| 401 new RemoveCookieTask(url, name, store_context)); | 401 new RemoveCookieTask(url, name, store_context)); |
| 402 DCHECK(rv); | 402 DCHECK(rv); |
| 403 | 403 |
| 404 return true; | 404 return true; |
| 405 } | 405 } |
| 406 | 406 |
| 407 bool GetAllCookieStoresFunction::RunImpl() { | 407 bool GetAllCookieStoresFunction::RunImpl() { |
| 408 Profile* original_profile = profile()->GetOriginalProfile(); | 408 Profile* original_profile = profile(); |
| 409 DCHECK(original_profile); | 409 DCHECK(original_profile); |
| 410 scoped_ptr<ListValue> original_tab_ids(new ListValue()); | 410 scoped_ptr<ListValue> original_tab_ids(new ListValue()); |
| 411 Profile* incognito_profile = NULL; | 411 Profile* incognito_profile = NULL; |
| 412 scoped_ptr<ListValue> incognito_tab_ids; | 412 scoped_ptr<ListValue> incognito_tab_ids; |
| 413 if (include_incognito()) { | 413 if (include_incognito()) { |
| 414 incognito_profile = profile()->GetOffTheRecordProfile(); | 414 incognito_profile = profile()->GetOffTheRecordProfile(); |
| 415 if (incognito_profile) | 415 if (incognito_profile) |
| 416 incognito_tab_ids.reset(new ListValue()); | 416 incognito_tab_ids.reset(new ListValue()); |
| 417 } | 417 } |
| 418 DCHECK(original_profile != incognito_profile); |
| 419 |
| 418 // Iterate through all browser instances, and for each browser, | 420 // Iterate through all browser instances, and for each browser, |
| 419 // add its tab IDs to either the regular or incognito tab ID list depending | 421 // add its tab IDs to either the regular or incognito tab ID list depending |
| 420 // whether the browser is regular or incognito. | 422 // whether the browser is regular or incognito. |
| 421 for (BrowserList::const_iterator iter = BrowserList::begin(); | 423 for (BrowserList::const_iterator iter = BrowserList::begin(); |
| 422 iter != BrowserList::end(); ++iter) { | 424 iter != BrowserList::end(); ++iter) { |
| 423 Browser* browser = *iter; | 425 Browser* browser = *iter; |
| 424 if (browser->profile() == original_profile) { | 426 if (browser->profile() == original_profile) { |
| 425 extension_cookies_helpers::AppendToTabIdList(browser, | 427 extension_cookies_helpers::AppendToTabIdList(browser, |
| 426 original_tab_ids.get()); | 428 original_tab_ids.get()); |
| 427 } else if (incognito_tab_ids.get() && | 429 } else if (incognito_tab_ids.get() && |
| (...skipping 10 matching lines...) Expand all Loading... |
| 438 original_profile, original_tab_ids.release())); | 440 original_profile, original_tab_ids.release())); |
| 439 } | 441 } |
| 440 if (incognito_tab_ids.get() && incognito_tab_ids->GetSize() > 0) { | 442 if (incognito_tab_ids.get() && incognito_tab_ids->GetSize() > 0) { |
| 441 cookie_store_list->Append( | 443 cookie_store_list->Append( |
| 442 extension_cookies_helpers::CreateCookieStoreValue( | 444 extension_cookies_helpers::CreateCookieStoreValue( |
| 443 incognito_profile, incognito_tab_ids.release())); | 445 incognito_profile, incognito_tab_ids.release())); |
| 444 } | 446 } |
| 445 result_.reset(cookie_store_list); | 447 result_.reset(cookie_store_list); |
| 446 return true; | 448 return true; |
| 447 } | 449 } |
| OLD | NEW |