Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(204)

Side by Side Diff: chrome/browser/extensions/api/cookies/cookies_api.cc

Issue 11312228: Move extension_error_utils.* and url_pattern_set.* into (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: hate Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/memory/linked_ptr.h" 13 #include "base/memory/linked_ptr.h"
14 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
15 #include "base/time.h" 15 #include "base/time.h"
16 #include "base/values.h" 16 #include "base/values.h"
17 #include "chrome/browser/extensions/api/cookies/cookies_api_constants.h" 17 #include "chrome/browser/extensions/api/cookies/cookies_api_constants.h"
18 #include "chrome/browser/extensions/api/cookies/cookies_helpers.h" 18 #include "chrome/browser/extensions/api/cookies/cookies_helpers.h"
19 #include "chrome/browser/extensions/event_router.h" 19 #include "chrome/browser/extensions/event_router.h"
20 #include "chrome/browser/extensions/extension_system.h" 20 #include "chrome/browser/extensions/extension_system.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_list.h" 23 #include "chrome/browser/ui/browser_list.h"
24 #include "chrome/common/chrome_notification_types.h" 24 #include "chrome/common/chrome_notification_types.h"
25 #include "chrome/common/extensions/api/cookies.h" 25 #include "chrome/common/extensions/api/cookies.h"
26 #include "chrome/common/extensions/extension.h" 26 #include "chrome/common/extensions/extension.h"
27 #include "chrome/common/extensions/extension_error_utils.h"
28 #include "content/public/browser/browser_thread.h" 27 #include "content/public/browser/browser_thread.h"
29 #include "content/public/browser/notification_service.h" 28 #include "content/public/browser/notification_service.h"
29 #include "extensions/common/error_utils.h"
30 #include "net/cookies/canonical_cookie.h" 30 #include "net/cookies/canonical_cookie.h"
31 #include "net/cookies/cookie_monster.h" 31 #include "net/cookies/cookie_monster.h"
32 #include "net/url_request/url_request_context.h" 32 #include "net/url_request/url_request_context.h"
33 #include "net/url_request/url_request_context_getter.h" 33 #include "net/url_request/url_request_context_getter.h"
34 34
35 using content::BrowserThread; 35 using content::BrowserThread;
36 using extensions::api::cookies::Cookie; 36 using extensions::api::cookies::Cookie;
37 using extensions::api::cookies::CookieStore; 37 using extensions::api::cookies::CookieStore;
38 38
39 namespace Get = extensions::api::cookies::Get; 39 namespace Get = extensions::api::cookies::Get;
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 if (!router) 133 if (!router)
134 return; 134 return;
135 router->DispatchEventToRenderers(event_name, event_args.Pass(), profile, 135 router->DispatchEventToRenderers(event_name, event_args.Pass(), profile,
136 cookie_domain); 136 cookie_domain);
137 } 137 }
138 138
139 bool CookiesFunction::ParseUrl(const std::string& url_string, GURL* url, 139 bool CookiesFunction::ParseUrl(const std::string& url_string, GURL* url,
140 bool check_host_permissions) { 140 bool check_host_permissions) {
141 *url = GURL(url_string); 141 *url = GURL(url_string);
142 if (!url->is_valid()) { 142 if (!url->is_valid()) {
143 error_ = ExtensionErrorUtils::FormatErrorMessage( 143 error_ = ErrorUtils::FormatErrorMessage(
144 keys::kInvalidUrlError, url_string); 144 keys::kInvalidUrlError, url_string);
145 return false; 145 return false;
146 } 146 }
147 // Check against host permissions if needed. 147 // Check against host permissions if needed.
148 if (check_host_permissions && !GetExtension()->HasHostPermission(*url)) { 148 if (check_host_permissions && !GetExtension()->HasHostPermission(*url)) {
149 error_ = ExtensionErrorUtils::FormatErrorMessage( 149 error_ = ErrorUtils::FormatErrorMessage(
150 keys::kNoHostPermissionsError, url->spec()); 150 keys::kNoHostPermissionsError, url->spec());
151 return false; 151 return false;
152 } 152 }
153 return true; 153 return true;
154 } 154 }
155 155
156 bool CookiesFunction::ParseStoreContext( 156 bool CookiesFunction::ParseStoreContext(
157 std::string* store_id, 157 std::string* store_id,
158 net::URLRequestContextGetter** context) { 158 net::URLRequestContextGetter** context) {
159 DCHECK((context || store_id->empty())); 159 DCHECK((context || store_id->empty()));
160 Profile* store_profile = NULL; 160 Profile* store_profile = NULL;
161 if (!store_id->empty()) { 161 if (!store_id->empty()) {
162 store_profile = cookies_helpers::ChooseProfileFromStoreId( 162 store_profile = cookies_helpers::ChooseProfileFromStoreId(
163 *store_id, profile(), include_incognito()); 163 *store_id, profile(), include_incognito());
164 if (!store_profile) { 164 if (!store_profile) {
165 error_ = ExtensionErrorUtils::FormatErrorMessage( 165 error_ = ErrorUtils::FormatErrorMessage(
166 keys::kInvalidStoreIdError, *store_id); 166 keys::kInvalidStoreIdError, *store_id);
167 return false; 167 return false;
168 } 168 }
169 } else { 169 } else {
170 // The store ID was not specified; use the current execution context's 170 // The store ID was not specified; use the current execution context's
171 // cookie store by default. 171 // cookie store by default.
172 // GetCurrentBrowser() already takes into account incognito settings. 172 // GetCurrentBrowser() already takes into account incognito settings.
173 Browser* current_browser = GetCurrentBrowser(); 173 Browser* current_browser = GetCurrentBrowser();
174 if (!current_browser) { 174 if (!current_browser) {
175 error_ = keys::kNoCookieStoreFoundError; 175 error_ = keys::kNoCookieStoreFoundError;
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 BrowserThread::UI, FROM_HERE, 416 BrowserThread::UI, FROM_HERE,
417 base::Bind(&SetCookieFunction::RespondOnUIThread, this)); 417 base::Bind(&SetCookieFunction::RespondOnUIThread, this));
418 DCHECK(rv); 418 DCHECK(rv);
419 } 419 }
420 420
421 void SetCookieFunction::RespondOnUIThread() { 421 void SetCookieFunction::RespondOnUIThread() {
422 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 422 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
423 if (!success_) { 423 if (!success_) {
424 std::string name = parsed_args_->details.name.get() ? 424 std::string name = parsed_args_->details.name.get() ?
425 *parsed_args_->details.name : ""; 425 *parsed_args_->details.name : "";
426 error_ = ExtensionErrorUtils::FormatErrorMessage( 426 error_ = ErrorUtils::FormatErrorMessage(
427 keys::kCookieSetFailedError, name); 427 keys::kCookieSetFailedError, name);
428 } 428 }
429 SendResponse(success_); 429 SendResponse(success_);
430 } 430 }
431 431
432 RemoveCookieFunction::RemoveCookieFunction() { 432 RemoveCookieFunction::RemoveCookieFunction() {
433 } 433 }
434 434
435 RemoveCookieFunction::~RemoveCookieFunction() { 435 RemoveCookieFunction::~RemoveCookieFunction() {
436 } 436 }
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
534 } 534 }
535 results_ = GetAllCookieStores::Results::Create(cookie_stores); 535 results_ = GetAllCookieStores::Results::Create(cookie_stores);
536 return true; 536 return true;
537 } 537 }
538 538
539 void GetAllCookieStoresFunction::Run() { 539 void GetAllCookieStoresFunction::Run() {
540 SendResponse(RunImpl()); 540 SendResponse(RunImpl());
541 } 541 }
542 542
543 } // namespace extensions 543 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/context_menu/context_menu_api.cc ('k') | chrome/browser/extensions/api/debugger/debugger_api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698