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

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

Issue 10694085: Refactor extension event distribution to use Values instead of JSON strings. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixing memory leak in a test. Created 8 years, 4 months 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
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 break; 73 break;
74 74
75 default: 75 default:
76 NOTREACHED(); 76 NOTREACHED();
77 } 77 }
78 } 78 }
79 79
80 void ExtensionCookiesEventRouter::CookieChanged( 80 void ExtensionCookiesEventRouter::CookieChanged(
81 Profile* profile, 81 Profile* profile,
82 ChromeCookieDetails* details) { 82 ChromeCookieDetails* details) {
83 ListValue args; 83 scoped_ptr<ListValue> args(new ListValue());
84 DictionaryValue* dict = new DictionaryValue(); 84 DictionaryValue* dict = new DictionaryValue();
85 dict->SetBoolean(keys::kRemovedKey, details->removed); 85 dict->SetBoolean(keys::kRemovedKey, details->removed);
86 86
87 scoped_ptr<Cookie> cookie( 87 scoped_ptr<Cookie> cookie(
88 cookies_helpers::CreateCookie(*details->cookie, 88 cookies_helpers::CreateCookie(*details->cookie,
89 cookies_helpers::GetStoreIdFromProfile(profile))); 89 cookies_helpers::GetStoreIdFromProfile(profile)));
90 dict->Set(keys::kCookieKey, cookie->ToValue().release()); 90 dict->Set(keys::kCookieKey, cookie->ToValue().release());
91 91
92 // Map the interal cause to an external string. 92 // Map the interal cause to an external string.
93 std::string cause; 93 std::string cause;
(...skipping 16 matching lines...) Expand all
110 110
111 case net::CookieMonster::Delegate::CHANGE_COOKIE_EXPIRED_OVERWRITE: 111 case net::CookieMonster::Delegate::CHANGE_COOKIE_EXPIRED_OVERWRITE:
112 cause = keys::kExpiredOverwriteChangeCause; 112 cause = keys::kExpiredOverwriteChangeCause;
113 break; 113 break;
114 114
115 default: 115 default:
116 NOTREACHED(); 116 NOTREACHED();
117 } 117 }
118 dict->SetString(keys::kCauseKey, cause); 118 dict->SetString(keys::kCauseKey, cause);
119 119
120 args.Append(dict); 120 args->Append(dict);
121 121
122 std::string json_args;
123 base::JSONWriter::Write(&args, &json_args);
124 GURL cookie_domain = 122 GURL cookie_domain =
125 cookies_helpers::GetURLFromCanonicalCookie(*details->cookie); 123 cookies_helpers::GetURLFromCanonicalCookie(*details->cookie);
126 DispatchEvent(profile, keys::kOnChanged, json_args, cookie_domain); 124 DispatchEvent(profile, keys::kOnChanged, args.Pass(), cookie_domain);
127 } 125 }
128 126
129 void ExtensionCookiesEventRouter::DispatchEvent(Profile* profile, 127 void ExtensionCookiesEventRouter::DispatchEvent(
130 const char* event_name, 128 Profile* profile, const char* event_name, scoped_ptr<ListValue> event_args,
131 const std::string& json_args, 129 GURL& cookie_domain) {
132 GURL& cookie_domain) {
133 if (profile && profile->GetExtensionEventRouter()) { 130 if (profile && profile->GetExtensionEventRouter()) {
134 profile->GetExtensionEventRouter()->DispatchEventToRenderers( 131 profile->GetExtensionEventRouter()->DispatchEventToRenderers(
135 event_name, json_args, profile, cookie_domain, EventFilteringInfo()); 132 event_name, event_args.Pass(), profile, cookie_domain,
133 EventFilteringInfo());
136 } 134 }
137 } 135 }
138 136
139 bool CookiesFunction::ParseUrl(const std::string& url_string, GURL* url, 137 bool CookiesFunction::ParseUrl(const std::string& url_string, GURL* url,
140 bool check_host_permissions) { 138 bool check_host_permissions) {
141 *url = GURL(url_string); 139 *url = GURL(url_string);
142 if (!url->is_valid()) { 140 if (!url->is_valid()) {
143 error_ = ExtensionErrorUtils::FormatErrorMessage( 141 error_ = ExtensionErrorUtils::FormatErrorMessage(
144 keys::kInvalidUrlError, url_string); 142 keys::kInvalidUrlError, url_string);
145 return false; 143 return false;
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after
538 } 536 }
539 results_ = GetAllCookieStores::Results::Create(cookie_stores); 537 results_ = GetAllCookieStores::Results::Create(cookie_stores);
540 return true; 538 return true;
541 } 539 }
542 540
543 void GetAllCookieStoresFunction::Run() { 541 void GetAllCookieStoresFunction::Run() {
544 SendResponse(RunImpl()); 542 SendResponse(RunImpl());
545 } 543 }
546 544
547 } // namespace extensions 545 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/cookies/cookies_api.h ('k') | chrome/browser/extensions/api/debugger/debugger_api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698