| 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.h" | 16 #include "base/time.h" |
| 17 #include "base/values.h" | 17 #include "base/values.h" |
| 18 #include "chrome/browser/extensions/api/cookies/cookies_api_constants.h" | 18 #include "chrome/browser/extensions/api/cookies/cookies_api_constants.h" |
| 19 #include "chrome/browser/extensions/api/cookies/cookies_helpers.h" | 19 #include "chrome/browser/extensions/api/cookies/cookies_helpers.h" |
| 20 #include "chrome/browser/extensions/event_router.h" | 20 #include "chrome/browser/extensions/event_router.h" |
| 21 #include "chrome/browser/extensions/extension_system.h" | 21 #include "chrome/browser/extensions/extension_system.h" |
| 22 #include "chrome/browser/profiles/profile.h" | 22 #include "chrome/browser/profiles/profile.h" |
| 23 #include "chrome/browser/ui/browser.h" | 23 #include "chrome/browser/ui/browser.h" |
| 24 #include "chrome/browser/ui/browser_iterator.h" | 24 #include "chrome/browser/ui/browser_iterator.h" |
| 25 #include "chrome/common/chrome_notification_types.h" | 25 #include "chrome/common/chrome_notification_types.h" |
| 26 #include "chrome/common/extensions/api/cookies.h" | 26 #include "chrome/common/extensions/api/cookies.h" |
| 27 #include "chrome/common/extensions/extension.h" | 27 #include "chrome/common/extensions/extension.h" |
| 28 #include "chrome/common/extensions/permissions/permissions_data.h" |
| 28 #include "content/public/browser/browser_thread.h" | 29 #include "content/public/browser/browser_thread.h" |
| 29 #include "content/public/browser/notification_service.h" | 30 #include "content/public/browser/notification_service.h" |
| 30 #include "extensions/common/error_utils.h" | 31 #include "extensions/common/error_utils.h" |
| 31 #include "net/cookies/canonical_cookie.h" | 32 #include "net/cookies/canonical_cookie.h" |
| 32 #include "net/cookies/cookie_constants.h" | 33 #include "net/cookies/cookie_constants.h" |
| 33 #include "net/cookies/cookie_monster.h" | 34 #include "net/cookies/cookie_monster.h" |
| 34 #include "net/url_request/url_request_context.h" | 35 #include "net/url_request/url_request_context.h" |
| 35 #include "net/url_request/url_request_context_getter.h" | 36 #include "net/url_request/url_request_context_getter.h" |
| 36 | 37 |
| 37 using content::BrowserThread; | 38 using content::BrowserThread; |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 | 143 |
| 143 bool CookiesFunction::ParseUrl(const std::string& url_string, GURL* url, | 144 bool CookiesFunction::ParseUrl(const std::string& url_string, GURL* url, |
| 144 bool check_host_permissions) { | 145 bool check_host_permissions) { |
| 145 *url = GURL(url_string); | 146 *url = GURL(url_string); |
| 146 if (!url->is_valid()) { | 147 if (!url->is_valid()) { |
| 147 error_ = ErrorUtils::FormatErrorMessage( | 148 error_ = ErrorUtils::FormatErrorMessage( |
| 148 keys::kInvalidUrlError, url_string); | 149 keys::kInvalidUrlError, url_string); |
| 149 return false; | 150 return false; |
| 150 } | 151 } |
| 151 // Check against host permissions if needed. | 152 // Check against host permissions if needed. |
| 152 if (check_host_permissions && !GetExtension()->HasHostPermission(*url)) { | 153 if (check_host_permissions && |
| 154 !PermissionsData::HasHostPermission(GetExtension(), *url)) { |
| 153 error_ = ErrorUtils::FormatErrorMessage( | 155 error_ = ErrorUtils::FormatErrorMessage( |
| 154 keys::kNoHostPermissionsError, url->spec()); | 156 keys::kNoHostPermissionsError, url->spec()); |
| 155 return false; | 157 return false; |
| 156 } | 158 } |
| 157 return true; | 159 return true; |
| 158 } | 160 } |
| 159 | 161 |
| 160 bool CookiesFunction::ParseStoreContext( | 162 bool CookiesFunction::ParseStoreContext( |
| 161 std::string* store_id, | 163 std::string* store_id, |
| 162 net::URLRequestContextGetter** context) { | 164 net::URLRequestContextGetter** context) { |
| (...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 573 return &g_factory.Get(); | 575 return &g_factory.Get(); |
| 574 } | 576 } |
| 575 | 577 |
| 576 void CookiesAPI::OnListenerAdded( | 578 void CookiesAPI::OnListenerAdded( |
| 577 const extensions::EventListenerInfo& details) { | 579 const extensions::EventListenerInfo& details) { |
| 578 cookies_event_router_.reset(new CookiesEventRouter(profile_)); | 580 cookies_event_router_.reset(new CookiesEventRouter(profile_)); |
| 579 ExtensionSystem::Get(profile_)->event_router()->UnregisterObserver(this); | 581 ExtensionSystem::Get(profile_)->event_router()->UnregisterObserver(this); |
| 580 } | 582 } |
| 581 | 583 |
| 582 } // namespace extensions | 584 } // namespace extensions |
| OLD | NEW |