| 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 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/json/json_writer.h" | 12 #include "base/json/json_writer.h" |
| 13 #include "base/lazy_instance.h" | 13 #include "base/lazy_instance.h" |
| 14 #include "base/memory/linked_ptr.h" | 14 #include "base/memory/linked_ptr.h" |
| 15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
| 16 #include "base/time/time.h" | 16 #include "base/time/time.h" |
| 17 #include "base/values.h" | 17 #include "base/values.h" |
| 18 #include "chrome/browser/chrome_notification_types.h" | 18 #include "chrome/browser/chrome_notification_types.h" |
| 19 #include "chrome/browser/extensions/api/cookies/cookies_api_constants.h" | 19 #include "chrome/browser/extensions/api/cookies/cookies_api_constants.h" |
| 20 #include "chrome/browser/extensions/api/cookies/cookies_helpers.h" | 20 #include "chrome/browser/extensions/api/cookies/cookies_helpers.h" |
| 21 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
| 22 #include "chrome/browser/ui/browser.h" | 22 #include "chrome/browser/ui/browser.h" |
| 23 #include "chrome/browser/ui/browser_iterator.h" | 23 #include "chrome/browser/ui/browser_iterator.h" |
| 24 #include "chrome/common/extensions/api/cookies.h" | 24 #include "chrome/common/extensions/api/cookies.h" |
| 25 #include "content/public/browser/browser_thread.h" | 25 #include "content/public/browser/browser_thread.h" |
| 26 #include "content/public/browser/notification_service.h" | 26 #include "content/public/browser/notification_service.h" |
| 27 #include "extensions/browser/event_router.h" | 27 #include "extensions/browser/event_router.h" |
| 28 #include "extensions/browser/extension_system.h" | |
| 29 #include "extensions/common/error_utils.h" | 28 #include "extensions/common/error_utils.h" |
| 30 #include "extensions/common/extension.h" | 29 #include "extensions/common/extension.h" |
| 31 #include "extensions/common/permissions/permissions_data.h" | 30 #include "extensions/common/permissions/permissions_data.h" |
| 32 #include "net/cookies/canonical_cookie.h" | 31 #include "net/cookies/canonical_cookie.h" |
| 33 #include "net/cookies/cookie_constants.h" | 32 #include "net/cookies/cookie_constants.h" |
| 34 #include "net/cookies/cookie_monster.h" | 33 #include "net/cookies/cookie_monster.h" |
| 35 #include "net/url_request/url_request_context.h" | 34 #include "net/url_request/url_request_context.h" |
| 36 #include "net/url_request/url_request_context_getter.h" | 35 #include "net/url_request/url_request_context_getter.h" |
| 37 | 36 |
| 38 using content::BrowserThread; | 37 using content::BrowserThread; |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 DispatchEvent(profile, | 126 DispatchEvent(profile, |
| 128 cookies::OnChanged::kEventName, | 127 cookies::OnChanged::kEventName, |
| 129 args.Pass(), | 128 args.Pass(), |
| 130 cookie_domain); | 129 cookie_domain); |
| 131 } | 130 } |
| 132 | 131 |
| 133 void CookiesEventRouter::DispatchEvent(content::BrowserContext* context, | 132 void CookiesEventRouter::DispatchEvent(content::BrowserContext* context, |
| 134 const std::string& event_name, | 133 const std::string& event_name, |
| 135 scoped_ptr<base::ListValue> event_args, | 134 scoped_ptr<base::ListValue> event_args, |
| 136 GURL& cookie_domain) { | 135 GURL& cookie_domain) { |
| 137 EventRouter* router = | 136 EventRouter* router = context ? extensions::EventRouter::Get(context) : NULL; |
| 138 context ? extensions::ExtensionSystem::Get(context)->event_router() | |
| 139 : NULL; | |
| 140 if (!router) | 137 if (!router) |
| 141 return; | 138 return; |
| 142 scoped_ptr<Event> event(new Event(event_name, event_args.Pass())); | 139 scoped_ptr<Event> event(new Event(event_name, event_args.Pass())); |
| 143 event->restrict_to_browser_context = context; | 140 event->restrict_to_browser_context = context; |
| 144 event->event_url = cookie_domain; | 141 event->event_url = cookie_domain; |
| 145 router->BroadcastEvent(event.Pass()); | 142 router->BroadcastEvent(event.Pass()); |
| 146 } | 143 } |
| 147 | 144 |
| 148 bool CookiesFunction::ParseUrl(const std::string& url_string, GURL* url, | 145 bool CookiesFunction::ParseUrl(const std::string& url_string, GURL* url, |
| 149 bool check_host_permissions) { | 146 bool check_host_permissions) { |
| (...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 555 results_ = GetAllCookieStores::Results::Create(cookie_stores); | 552 results_ = GetAllCookieStores::Results::Create(cookie_stores); |
| 556 return true; | 553 return true; |
| 557 } | 554 } |
| 558 | 555 |
| 559 void CookiesGetAllCookieStoresFunction::Run() { | 556 void CookiesGetAllCookieStoresFunction::Run() { |
| 560 SendResponse(RunImpl()); | 557 SendResponse(RunImpl()); |
| 561 } | 558 } |
| 562 | 559 |
| 563 CookiesAPI::CookiesAPI(content::BrowserContext* context) | 560 CookiesAPI::CookiesAPI(content::BrowserContext* context) |
| 564 : browser_context_(context) { | 561 : browser_context_(context) { |
| 565 ExtensionSystem::Get(browser_context_)->event_router()->RegisterObserver( | 562 EventRouter::Get(browser_context_) |
| 566 this, cookies::OnChanged::kEventName); | 563 ->RegisterObserver(this, cookies::OnChanged::kEventName); |
| 567 } | 564 } |
| 568 | 565 |
| 569 CookiesAPI::~CookiesAPI() { | 566 CookiesAPI::~CookiesAPI() { |
| 570 } | 567 } |
| 571 | 568 |
| 572 void CookiesAPI::Shutdown() { | 569 void CookiesAPI::Shutdown() { |
| 573 ExtensionSystem::Get(browser_context_)->event_router()->UnregisterObserver( | 570 EventRouter::Get(browser_context_)->UnregisterObserver(this); |
| 574 this); | |
| 575 } | 571 } |
| 576 | 572 |
| 577 static base::LazyInstance<BrowserContextKeyedAPIFactory<CookiesAPI> > | 573 static base::LazyInstance<BrowserContextKeyedAPIFactory<CookiesAPI> > |
| 578 g_factory = LAZY_INSTANCE_INITIALIZER; | 574 g_factory = LAZY_INSTANCE_INITIALIZER; |
| 579 | 575 |
| 580 // static | 576 // static |
| 581 BrowserContextKeyedAPIFactory<CookiesAPI>* CookiesAPI::GetFactoryInstance() { | 577 BrowserContextKeyedAPIFactory<CookiesAPI>* CookiesAPI::GetFactoryInstance() { |
| 582 return g_factory.Pointer(); | 578 return g_factory.Pointer(); |
| 583 } | 579 } |
| 584 | 580 |
| 585 void CookiesAPI::OnListenerAdded( | 581 void CookiesAPI::OnListenerAdded( |
| 586 const extensions::EventListenerInfo& details) { | 582 const extensions::EventListenerInfo& details) { |
| 587 cookies_event_router_.reset(new CookiesEventRouter(browser_context_)); | 583 cookies_event_router_.reset(new CookiesEventRouter(browser_context_)); |
| 588 ExtensionSystem::Get(browser_context_)->event_router()->UnregisterObserver( | 584 EventRouter::Get(browser_context_)->UnregisterObserver(this); |
| 589 this); | |
| 590 } | 585 } |
| 591 | 586 |
| 592 } // namespace extensions | 587 } // namespace extensions |
| OLD | NEW |