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 "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 break; | 57 break; |
58 | 58 |
59 default: | 59 default: |
60 NOTREACHED(); | 60 NOTREACHED(); |
61 } | 61 } |
62 } | 62 } |
63 | 63 |
64 void ExtensionCookiesEventRouter::CookieChanged( | 64 void ExtensionCookiesEventRouter::CookieChanged( |
65 Profile* profile, | 65 Profile* profile, |
66 ChromeCookieDetails* details) { | 66 ChromeCookieDetails* details) { |
67 ListValue args; | 67 ListValue* args = new ListValue(); |
68 DictionaryValue* dict = new DictionaryValue(); | 68 DictionaryValue* dict = new DictionaryValue(); |
69 dict->SetBoolean(keys::kRemovedKey, details->removed); | 69 dict->SetBoolean(keys::kRemovedKey, details->removed); |
70 dict->Set( | 70 dict->Set( |
71 keys::kCookieKey, | 71 keys::kCookieKey, |
72 cookies_helpers::CreateCookieValue(*details->cookie, | 72 cookies_helpers::CreateCookieValue(*details->cookie, |
73 cookies_helpers::GetStoreIdFromProfile(profile))); | 73 cookies_helpers::GetStoreIdFromProfile(profile))); |
74 | 74 |
75 // Map the interal cause to an external string. | 75 // Map the interal cause to an external string. |
76 std::string cause; | 76 std::string cause; |
77 switch (details->cause) { | 77 switch (details->cause) { |
(...skipping 15 matching lines...) Expand all Loading... |
93 | 93 |
94 case net::CookieMonster::Delegate::CHANGE_COOKIE_EXPIRED_OVERWRITE: | 94 case net::CookieMonster::Delegate::CHANGE_COOKIE_EXPIRED_OVERWRITE: |
95 cause = keys::kExpiredOverwriteChangeCause; | 95 cause = keys::kExpiredOverwriteChangeCause; |
96 break; | 96 break; |
97 | 97 |
98 default: | 98 default: |
99 NOTREACHED(); | 99 NOTREACHED(); |
100 } | 100 } |
101 dict->SetString(keys::kCauseKey, cause); | 101 dict->SetString(keys::kCauseKey, cause); |
102 | 102 |
103 args.Append(dict); | 103 args->Append(dict); |
104 | 104 |
105 std::string json_args; | |
106 base::JSONWriter::Write(&args, &json_args); | |
107 GURL cookie_domain = | 105 GURL cookie_domain = |
108 cookies_helpers::GetURLFromCanonicalCookie(*details->cookie); | 106 cookies_helpers::GetURLFromCanonicalCookie(*details->cookie); |
109 DispatchEvent(profile, keys::kOnChanged, json_args, cookie_domain); | 107 DispatchEvent(profile, keys::kOnChanged, args, cookie_domain); |
110 } | 108 } |
111 | 109 |
112 void ExtensionCookiesEventRouter::DispatchEvent(Profile* profile, | 110 void ExtensionCookiesEventRouter::DispatchEvent(Profile* profile, |
113 const char* event_name, | 111 const char* event_name, |
114 const std::string& json_args, | 112 ListValue* event_args, |
115 GURL& cookie_domain) { | 113 GURL& cookie_domain) { |
116 if (profile && profile->GetExtensionEventRouter()) { | 114 if (profile && profile->GetExtensionEventRouter()) { |
117 profile->GetExtensionEventRouter()->DispatchEventToRenderers( | 115 profile->GetExtensionEventRouter()->DispatchEventToRenderers( |
118 event_name, json_args, profile, cookie_domain, EventFilteringInfo()); | 116 event_name, event_args, profile, cookie_domain, EventFilteringInfo()); |
119 } | 117 } |
120 } | 118 } |
121 | 119 |
122 bool CookiesFunction::ParseUrl(const DictionaryValue* details, GURL* url, | 120 bool CookiesFunction::ParseUrl(const DictionaryValue* details, GURL* url, |
123 bool check_host_permissions) { | 121 bool check_host_permissions) { |
124 DCHECK(details && url); | 122 DCHECK(details && url); |
125 std::string url_string; | 123 std::string url_string; |
126 // Get the URL string or return false. | 124 // Get the URL string or return false. |
127 EXTENSION_FUNCTION_VALIDATE(details->GetString(keys::kUrlKey, &url_string)); | 125 EXTENSION_FUNCTION_VALIDATE(details->GetString(keys::kUrlKey, &url_string)); |
128 *url = GURL(url_string); | 126 *url = GURL(url_string); |
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
538 } | 536 } |
539 result_.reset(cookie_store_list); | 537 result_.reset(cookie_store_list); |
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 |
OLD | NEW |