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

Side by Side Diff: chrome/browser/extensions/api/web_navigation/web_navigation_api.cc

Issue 10661038: Revert 143896 - Filtered events. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 6 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 WebNavigation API. 5 // Implements the Chrome Extensions WebNavigation API.
6 6
7 #include "chrome/browser/extensions/api/web_navigation/web_navigation_api.h" 7 #include "chrome/browser/extensions/api/web_navigation/web_navigation_api.h"
8 8
9 #include "base/json/json_writer.h" 9 #include "base/json/json_writer.h"
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
11 #include "base/string_number_conversions.h" 11 #include "base/string_number_conversions.h"
12 #include "base/time.h" 12 #include "base/time.h"
13 #include "base/values.h" 13 #include "base/values.h"
14 #include "chrome/browser/extensions/api/web_navigation/web_navigation_api_consta nts.h" 14 #include "chrome/browser/extensions/api/web_navigation/web_navigation_api_consta nts.h"
15 #include "chrome/browser/extensions/extension_event_router.h" 15 #include "chrome/browser/extensions/extension_event_router.h"
16 #include "chrome/browser/extensions/extension_tab_util.h" 16 #include "chrome/browser/extensions/extension_tab_util.h"
17 #include "chrome/browser/profiles/profile.h" 17 #include "chrome/browser/profiles/profile.h"
18 #include "chrome/browser/tab_contents/retargeting_details.h" 18 #include "chrome/browser/tab_contents/retargeting_details.h"
19 #include "chrome/browser/ui/tab_contents/tab_contents.h" 19 #include "chrome/browser/ui/tab_contents/tab_contents.h"
20 #include "chrome/browser/view_type_utils.h" 20 #include "chrome/browser/view_type_utils.h"
21 #include "chrome/common/chrome_notification_types.h" 21 #include "chrome/common/chrome_notification_types.h"
22 #include "chrome/common/extensions/api/web_navigation.h" 22 #include "chrome/common/extensions/api/web_navigation.h"
23 #include "chrome/common/extensions/event_filtering_info.h"
24 #include "chrome/common/url_constants.h" 23 #include "chrome/common/url_constants.h"
25 #include "content/public/browser/resource_request_details.h" 24 #include "content/public/browser/resource_request_details.h"
26 #include "content/public/browser/navigation_details.h" 25 #include "content/public/browser/navigation_details.h"
27 #include "content/public/browser/notification_service.h" 26 #include "content/public/browser/notification_service.h"
28 #include "content/public/browser/notification_types.h" 27 #include "content/public/browser/notification_types.h"
29 #include "content/public/browser/render_view_host.h" 28 #include "content/public/browser/render_view_host.h"
30 #include "content/public/browser/web_contents.h" 29 #include "content/public/browser/web_contents.h"
31 #include "net/base/net_errors.h" 30 #include "net/base/net_errors.h"
32 31
33 namespace GetFrame = extensions::api::web_navigation::GetFrame; 32 namespace GetFrame = extensions::api::web_navigation::GetFrame;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 } 67 }
69 68
70 // Returns |time| as milliseconds since the epoch. 69 // Returns |time| as milliseconds since the epoch.
71 double MilliSecondsFromTime(const base::Time& time) { 70 double MilliSecondsFromTime(const base::Time& time) {
72 return 1000 * time.ToDoubleT(); 71 return 1000 * time.ToDoubleT();
73 } 72 }
74 73
75 // Dispatches events to the extension message service. 74 // Dispatches events to the extension message service.
76 void DispatchEvent(BrowserContext* browser_context, 75 void DispatchEvent(BrowserContext* browser_context,
77 const char* event_name, 76 const char* event_name,
78 const ListValue& args, 77 const std::string& json_args) {
79 const GURL& url) {
80 std::string json_args;
81 base::JSONWriter::Write(&args, &json_args);
82
83 extensions::EventFilteringInfo info;
84 info.SetURL(url);
85
86 Profile* profile = Profile::FromBrowserContext(browser_context); 78 Profile* profile = Profile::FromBrowserContext(browser_context);
87 if (profile && profile->GetExtensionEventRouter()) { 79 if (profile && profile->GetExtensionEventRouter()) {
88 profile->GetExtensionEventRouter()->DispatchEventToRenderers( 80 profile->GetExtensionEventRouter()->DispatchEventToRenderers(
89 event_name, json_args, profile, GURL(), info); 81 event_name, json_args, profile, GURL());
90 } 82 }
91 } 83 }
92 84
93 // Constructs and dispatches an onBeforeNavigate event. 85 // Constructs and dispatches an onBeforeNavigate event.
94 void DispatchOnBeforeNavigate(WebContents* web_contents, 86 void DispatchOnBeforeNavigate(WebContents* web_contents,
95 int64 frame_id, 87 int64 frame_id,
96 bool is_main_frame, 88 bool is_main_frame,
97 const GURL& validated_url) { 89 const GURL& validated_url) {
98 ListValue args; 90 ListValue args;
99 DictionaryValue* dict = new DictionaryValue(); 91 DictionaryValue* dict = new DictionaryValue();
100 dict->SetInteger(keys::kTabIdKey, ExtensionTabUtil::GetTabId(web_contents)); 92 dict->SetInteger(keys::kTabIdKey, ExtensionTabUtil::GetTabId(web_contents));
101 dict->SetString(keys::kUrlKey, validated_url.spec()); 93 dict->SetString(keys::kUrlKey, validated_url.spec());
102 dict->SetInteger(keys::kFrameIdKey, GetFrameId(is_main_frame, frame_id)); 94 dict->SetInteger(keys::kFrameIdKey, GetFrameId(is_main_frame, frame_id));
103 dict->SetDouble(keys::kTimeStampKey, MilliSecondsFromTime(base::Time::Now())); 95 dict->SetDouble(keys::kTimeStampKey, MilliSecondsFromTime(base::Time::Now()));
104 args.Append(dict); 96 args.Append(dict);
105 97
98 std::string json_args;
99 base::JSONWriter::Write(&args, &json_args);
106 DispatchEvent(web_contents->GetBrowserContext(), 100 DispatchEvent(web_contents->GetBrowserContext(),
107 keys::kOnBeforeNavigate, 101 keys::kOnBeforeNavigate,
108 args, 102 json_args);
109 validated_url);
110 } 103 }
111 104
112 // Constructs and dispatches an onCommitted or onReferenceFragmentUpdated 105 // Constructs and dispatches an onCommitted or onReferenceFragmentUpdated
113 // event. 106 // event.
114 void DispatchOnCommitted(const char* event_name, 107 void DispatchOnCommitted(const char* event_name,
115 WebContents* web_contents, 108 WebContents* web_contents,
116 int64 frame_id, 109 int64 frame_id,
117 bool is_main_frame, 110 bool is_main_frame,
118 const GURL& url, 111 const GURL& url,
119 content::PageTransition transition_type) { 112 content::PageTransition transition_type) {
(...skipping 11 matching lines...) Expand all
131 if (transition_type & content::PAGE_TRANSITION_SERVER_REDIRECT) 124 if (transition_type & content::PAGE_TRANSITION_SERVER_REDIRECT)
132 qualifiers->Append(Value::CreateStringValue("server_redirect")); 125 qualifiers->Append(Value::CreateStringValue("server_redirect"));
133 if (transition_type & content::PAGE_TRANSITION_FORWARD_BACK) 126 if (transition_type & content::PAGE_TRANSITION_FORWARD_BACK)
134 qualifiers->Append(Value::CreateStringValue("forward_back")); 127 qualifiers->Append(Value::CreateStringValue("forward_back"));
135 if (transition_type & content::PAGE_TRANSITION_FROM_ADDRESS_BAR) 128 if (transition_type & content::PAGE_TRANSITION_FROM_ADDRESS_BAR)
136 qualifiers->Append(Value::CreateStringValue("from_address_bar")); 129 qualifiers->Append(Value::CreateStringValue("from_address_bar"));
137 dict->Set(keys::kTransitionQualifiersKey, qualifiers); 130 dict->Set(keys::kTransitionQualifiersKey, qualifiers);
138 dict->SetDouble(keys::kTimeStampKey, MilliSecondsFromTime(base::Time::Now())); 131 dict->SetDouble(keys::kTimeStampKey, MilliSecondsFromTime(base::Time::Now()));
139 args.Append(dict); 132 args.Append(dict);
140 133
141 DispatchEvent(web_contents->GetBrowserContext(), event_name, args, url); 134 std::string json_args;
135 base::JSONWriter::Write(&args, &json_args);
136 DispatchEvent(web_contents->GetBrowserContext(), event_name, json_args);
142 } 137 }
143 138
144 // Constructs and dispatches an onDOMContentLoaded event. 139 // Constructs and dispatches an onDOMContentLoaded event.
145 void DispatchOnDOMContentLoaded(WebContents* web_contents, 140 void DispatchOnDOMContentLoaded(WebContents* web_contents,
146 const GURL& url, 141 const GURL& url,
147 bool is_main_frame, 142 bool is_main_frame,
148 int64 frame_id) { 143 int64 frame_id) {
149 ListValue args; 144 ListValue args;
150 DictionaryValue* dict = new DictionaryValue(); 145 DictionaryValue* dict = new DictionaryValue();
151 dict->SetInteger(keys::kTabIdKey, 146 dict->SetInteger(keys::kTabIdKey,
152 ExtensionTabUtil::GetTabId(web_contents)); 147 ExtensionTabUtil::GetTabId(web_contents));
153 dict->SetString(keys::kUrlKey, url.spec()); 148 dict->SetString(keys::kUrlKey, url.spec());
154 dict->SetInteger(keys::kFrameIdKey, GetFrameId(is_main_frame, frame_id)); 149 dict->SetInteger(keys::kFrameIdKey, GetFrameId(is_main_frame, frame_id));
155 dict->SetDouble(keys::kTimeStampKey, MilliSecondsFromTime(base::Time::Now())); 150 dict->SetDouble(keys::kTimeStampKey, MilliSecondsFromTime(base::Time::Now()));
156 args.Append(dict); 151 args.Append(dict);
157 152
153 std::string json_args;
154 base::JSONWriter::Write(&args, &json_args);
158 DispatchEvent(web_contents->GetBrowserContext(), 155 DispatchEvent(web_contents->GetBrowserContext(),
159 keys::kOnDOMContentLoaded, 156 keys::kOnDOMContentLoaded,
160 args, 157 json_args);
161 url);
162 } 158 }
163 159
164 // Constructs and dispatches an onCompleted event. 160 // Constructs and dispatches an onCompleted event.
165 void DispatchOnCompleted(WebContents* web_contents, 161 void DispatchOnCompleted(WebContents* web_contents,
166 const GURL& url, 162 const GURL& url,
167 bool is_main_frame, 163 bool is_main_frame,
168 int64 frame_id) { 164 int64 frame_id) {
169 ListValue args; 165 ListValue args;
170 DictionaryValue* dict = new DictionaryValue(); 166 DictionaryValue* dict = new DictionaryValue();
171 dict->SetInteger(keys::kTabIdKey, 167 dict->SetInteger(keys::kTabIdKey,
172 ExtensionTabUtil::GetTabId(web_contents)); 168 ExtensionTabUtil::GetTabId(web_contents));
173 dict->SetString(keys::kUrlKey, url.spec()); 169 dict->SetString(keys::kUrlKey, url.spec());
174 dict->SetInteger(keys::kFrameIdKey, GetFrameId(is_main_frame, frame_id)); 170 dict->SetInteger(keys::kFrameIdKey, GetFrameId(is_main_frame, frame_id));
175 dict->SetDouble(keys::kTimeStampKey, MilliSecondsFromTime(base::Time::Now())); 171 dict->SetDouble(keys::kTimeStampKey, MilliSecondsFromTime(base::Time::Now()));
176 args.Append(dict); 172 args.Append(dict);
177 173
178 DispatchEvent(web_contents->GetBrowserContext(), keys::kOnCompleted, args, 174 std::string json_args;
179 url); 175 base::JSONWriter::Write(&args, &json_args);
176 DispatchEvent(web_contents->GetBrowserContext(),
177 keys::kOnCompleted, json_args);
180 } 178 }
181 179
182 // Constructs and dispatches an onCreatedNavigationTarget event. 180 // Constructs and dispatches an onCreatedNavigationTarget event.
183 void DispatchOnCreatedNavigationTarget( 181 void DispatchOnCreatedNavigationTarget(
184 WebContents* web_contents, 182 WebContents* web_contents,
185 BrowserContext* browser_context, 183 BrowserContext* browser_context,
186 int64 source_frame_id, 184 int64 source_frame_id,
187 bool source_frame_is_main_frame, 185 bool source_frame_is_main_frame,
188 WebContents* target_web_contents, 186 WebContents* target_web_contents,
189 const GURL& target_url) { 187 const GURL& target_url) {
190 // Check that the tab is already inserted into a tab strip model. This code 188 // Check that the tab is already inserted into a tab strip model. This code
191 // path is exercised by ExtensionApiTest.WebNavigationRequestOpenTab. 189 // path is exercised by ExtensionApiTest.WebNavigationRequestOpenTab.
192 DCHECK(ExtensionTabUtil::GetTabById( 190 DCHECK(ExtensionTabUtil::GetTabById(
193 ExtensionTabUtil::GetTabId(target_web_contents), 191 ExtensionTabUtil::GetTabId(target_web_contents),
194 Profile::FromBrowserContext(target_web_contents->GetBrowserContext()), 192 Profile::FromBrowserContext(target_web_contents->GetBrowserContext()),
195 false, NULL, NULL, NULL, NULL)); 193 false, NULL, NULL, NULL, NULL));
196 194
197 ListValue args; 195 ListValue args;
198 DictionaryValue* dict = new DictionaryValue(); 196 DictionaryValue* dict = new DictionaryValue();
199 dict->SetInteger(keys::kSourceTabIdKey, 197 dict->SetInteger(keys::kSourceTabIdKey,
200 ExtensionTabUtil::GetTabId(web_contents)); 198 ExtensionTabUtil::GetTabId(web_contents));
201 dict->SetInteger(keys::kSourceFrameIdKey, 199 dict->SetInteger(keys::kSourceFrameIdKey,
202 GetFrameId(source_frame_is_main_frame, source_frame_id)); 200 GetFrameId(source_frame_is_main_frame, source_frame_id));
203 dict->SetString(keys::kUrlKey, target_url.possibly_invalid_spec()); 201 dict->SetString(keys::kUrlKey, target_url.possibly_invalid_spec());
204 dict->SetInteger(keys::kTabIdKey, 202 dict->SetInteger(keys::kTabIdKey,
205 ExtensionTabUtil::GetTabId(target_web_contents)); 203 ExtensionTabUtil::GetTabId(target_web_contents));
206 dict->SetDouble(keys::kTimeStampKey, MilliSecondsFromTime(base::Time::Now())); 204 dict->SetDouble(keys::kTimeStampKey, MilliSecondsFromTime(base::Time::Now()));
207 args.Append(dict); 205 args.Append(dict);
208 206
209 DispatchEvent(browser_context, keys::kOnCreatedNavigationTarget, args, 207 std::string json_args;
210 target_url); 208 base::JSONWriter::Write(&args, &json_args);
209 DispatchEvent(
210 browser_context, keys::kOnCreatedNavigationTarget, json_args);
211 } 211 }
212 212
213 // Constructs and dispatches an onErrorOccurred event. 213 // Constructs and dispatches an onErrorOccurred event.
214 void DispatchOnErrorOccurred(WebContents* web_contents, 214 void DispatchOnErrorOccurred(WebContents* web_contents,
215 const GURL& url, 215 const GURL& url,
216 int64 frame_id, 216 int64 frame_id,
217 bool is_main_frame, 217 bool is_main_frame,
218 int error_code) { 218 int error_code) {
219 ListValue args; 219 ListValue args;
220 DictionaryValue* dict = new DictionaryValue(); 220 DictionaryValue* dict = new DictionaryValue();
221 dict->SetInteger(keys::kTabIdKey, ExtensionTabUtil::GetTabId(web_contents)); 221 dict->SetInteger(keys::kTabIdKey, ExtensionTabUtil::GetTabId(web_contents));
222 dict->SetString(keys::kUrlKey, url.spec()); 222 dict->SetString(keys::kUrlKey, url.spec());
223 dict->SetInteger(keys::kFrameIdKey, GetFrameId(is_main_frame, frame_id)); 223 dict->SetInteger(keys::kFrameIdKey, GetFrameId(is_main_frame, frame_id));
224 dict->SetString(keys::kErrorKey, net::ErrorToString(error_code)); 224 dict->SetString(keys::kErrorKey, net::ErrorToString(error_code));
225 dict->SetDouble(keys::kTimeStampKey, MilliSecondsFromTime(base::Time::Now())); 225 dict->SetDouble(keys::kTimeStampKey, MilliSecondsFromTime(base::Time::Now()));
226 args.Append(dict); 226 args.Append(dict);
227 227
228 DispatchEvent(web_contents->GetBrowserContext(), keys::kOnErrorOccurred, 228 std::string json_args;
229 args, url); 229 base::JSONWriter::Write(&args, &json_args);
230 DispatchEvent(web_contents->GetBrowserContext(),
231 keys::kOnErrorOccurred,
232 json_args);
230 } 233 }
231 234
232 } // namespace 235 } // namespace
233 236
234 237
235 // FrameNavigationState ------------------------------------------------------- 238 // FrameNavigationState -------------------------------------------------------
236 239
237 // static 240 // static
238 bool FrameNavigationState::allow_extension_scheme_ = false; 241 bool FrameNavigationState::allow_extension_scheme_ = false;
239 242
(...skipping 561 matching lines...) Expand 10 before | Expand all | Expand 10 after
801 frame->frame_id = GetFrameId(navigation_state.IsMainFrame(frame_id), 804 frame->frame_id = GetFrameId(navigation_state.IsMainFrame(frame_id),
802 frame_id); 805 frame_id);
803 frame->error_occurred = navigation_state.GetErrorOccurredInFrame(frame_id); 806 frame->error_occurred = navigation_state.GetErrorOccurredInFrame(frame_id);
804 result_list.push_back(frame); 807 result_list.push_back(frame);
805 } 808 }
806 result_.reset(GetAllFrames::Result::Create(result_list)); 809 result_.reset(GetAllFrames::Result::Create(result_list));
807 return true; 810 return true;
808 } 811 }
809 812
810 } // namespace extensions 813 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698