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

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

Issue 10807009: Include the processId in webNavigation events (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 5 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_helper s.h" 7 #include "chrome/browser/extensions/api/web_navigation/web_navigation_api_helper s.h"
8 8
9 #include "base/json/json_writer.h" 9 #include "base/json/json_writer.h"
10 #include "base/string_number_conversions.h" 10 #include "base/string_number_conversions.h"
11 #include "base/time.h" 11 #include "base/time.h"
12 #include "base/values.h" 12 #include "base/values.h"
13 #include "chrome/browser/extensions/api/web_navigation/web_navigation_api_consta nts.h" 13 #include "chrome/browser/extensions/api/web_navigation/web_navigation_api_consta nts.h"
14 #include "chrome/browser/extensions/extension_event_router.h" 14 #include "chrome/browser/extensions/extension_event_router.h"
15 #include "chrome/browser/extensions/extension_tab_util.h" 15 #include "chrome/browser/extensions/extension_tab_util.h"
16 #include "chrome/browser/profiles/profile.h" 16 #include "chrome/browser/profiles/profile.h"
17 #include "chrome/common/extensions/event_filtering_info.h" 17 #include "chrome/common/extensions/event_filtering_info.h"
18 #include "content/public/browser/render_process_host.h"
19 #include "content/public/browser/render_view_host.h"
18 #include "content/public/browser/web_contents.h" 20 #include "content/public/browser/web_contents.h"
19 #include "net/base/net_errors.h" 21 #include "net/base/net_errors.h"
20 22
21 namespace extensions { 23 namespace extensions {
22 24
23 namespace keys = web_navigation_api_constants; 25 namespace keys = web_navigation_api_constants;
24 26
25 namespace web_navigation_api_helpers { 27 namespace web_navigation_api_helpers {
26 28
27 namespace { 29 namespace {
(...skipping 29 matching lines...) Expand all
57 59
58 // Constructs and dispatches an onBeforeNavigate event. 60 // Constructs and dispatches an onBeforeNavigate event.
59 void DispatchOnBeforeNavigate(content::WebContents* web_contents, 61 void DispatchOnBeforeNavigate(content::WebContents* web_contents,
60 int64 frame_id, 62 int64 frame_id,
61 bool is_main_frame, 63 bool is_main_frame,
62 const GURL& validated_url) { 64 const GURL& validated_url) {
63 ListValue args; 65 ListValue args;
64 DictionaryValue* dict = new DictionaryValue(); 66 DictionaryValue* dict = new DictionaryValue();
65 dict->SetInteger(keys::kTabIdKey, ExtensionTabUtil::GetTabId(web_contents)); 67 dict->SetInteger(keys::kTabIdKey, ExtensionTabUtil::GetTabId(web_contents));
66 dict->SetString(keys::kUrlKey, validated_url.spec()); 68 dict->SetString(keys::kUrlKey, validated_url.spec());
69 dict->SetInteger(keys::kProcessIdKey,
70 web_contents->GetRenderViewHost()->GetProcess()->GetID());
67 dict->SetInteger(keys::kFrameIdKey, GetFrameId(is_main_frame, frame_id)); 71 dict->SetInteger(keys::kFrameIdKey, GetFrameId(is_main_frame, frame_id));
68 dict->SetDouble(keys::kTimeStampKey, MilliSecondsFromTime(base::Time::Now())); 72 dict->SetDouble(keys::kTimeStampKey, MilliSecondsFromTime(base::Time::Now()));
69 args.Append(dict); 73 args.Append(dict);
70 74
71 DispatchEvent(web_contents->GetBrowserContext(), 75 DispatchEvent(web_contents->GetBrowserContext(),
72 keys::kOnBeforeNavigate, 76 keys::kOnBeforeNavigate,
73 args, 77 args,
74 validated_url); 78 validated_url);
75 } 79 }
76 80
77 // Constructs and dispatches an onCommitted or onReferenceFragmentUpdated 81 // Constructs and dispatches an onCommitted or onReferenceFragmentUpdated
78 // event. 82 // event.
79 void DispatchOnCommitted(const char* event_name, 83 void DispatchOnCommitted(const char* event_name,
80 content::WebContents* web_contents, 84 content::WebContents* web_contents,
81 int64 frame_id, 85 int64 frame_id,
82 bool is_main_frame, 86 bool is_main_frame,
83 const GURL& url, 87 const GURL& url,
84 content::PageTransition transition_type) { 88 content::PageTransition transition_type) {
85 ListValue args; 89 ListValue args;
86 DictionaryValue* dict = new DictionaryValue(); 90 DictionaryValue* dict = new DictionaryValue();
87 dict->SetInteger(keys::kTabIdKey, ExtensionTabUtil::GetTabId(web_contents)); 91 dict->SetInteger(keys::kTabIdKey, ExtensionTabUtil::GetTabId(web_contents));
88 dict->SetString(keys::kUrlKey, url.spec()); 92 dict->SetString(keys::kUrlKey, url.spec());
93 dict->SetInteger(keys::kProcessIdKey,
94 web_contents->GetRenderViewHost()->GetProcess()->GetID());
89 dict->SetInteger(keys::kFrameIdKey, GetFrameId(is_main_frame, frame_id)); 95 dict->SetInteger(keys::kFrameIdKey, GetFrameId(is_main_frame, frame_id));
90 dict->SetString( 96 dict->SetString(
91 keys::kTransitionTypeKey, 97 keys::kTransitionTypeKey,
92 content::PageTransitionGetCoreTransitionString(transition_type)); 98 content::PageTransitionGetCoreTransitionString(transition_type));
93 ListValue* qualifiers = new ListValue(); 99 ListValue* qualifiers = new ListValue();
94 if (transition_type & content::PAGE_TRANSITION_CLIENT_REDIRECT) 100 if (transition_type & content::PAGE_TRANSITION_CLIENT_REDIRECT)
95 qualifiers->Append(Value::CreateStringValue("client_redirect")); 101 qualifiers->Append(Value::CreateStringValue("client_redirect"));
96 if (transition_type & content::PAGE_TRANSITION_SERVER_REDIRECT) 102 if (transition_type & content::PAGE_TRANSITION_SERVER_REDIRECT)
97 qualifiers->Append(Value::CreateStringValue("server_redirect")); 103 qualifiers->Append(Value::CreateStringValue("server_redirect"));
98 if (transition_type & content::PAGE_TRANSITION_FORWARD_BACK) 104 if (transition_type & content::PAGE_TRANSITION_FORWARD_BACK)
(...skipping 10 matching lines...) Expand all
109 // Constructs and dispatches an onDOMContentLoaded event. 115 // Constructs and dispatches an onDOMContentLoaded event.
110 void DispatchOnDOMContentLoaded(content::WebContents* web_contents, 116 void DispatchOnDOMContentLoaded(content::WebContents* web_contents,
111 const GURL& url, 117 const GURL& url,
112 bool is_main_frame, 118 bool is_main_frame,
113 int64 frame_id) { 119 int64 frame_id) {
114 ListValue args; 120 ListValue args;
115 DictionaryValue* dict = new DictionaryValue(); 121 DictionaryValue* dict = new DictionaryValue();
116 dict->SetInteger(keys::kTabIdKey, 122 dict->SetInteger(keys::kTabIdKey,
117 ExtensionTabUtil::GetTabId(web_contents)); 123 ExtensionTabUtil::GetTabId(web_contents));
118 dict->SetString(keys::kUrlKey, url.spec()); 124 dict->SetString(keys::kUrlKey, url.spec());
125 dict->SetInteger(keys::kProcessIdKey,
126 web_contents->GetRenderViewHost()->GetProcess()->GetID());
119 dict->SetInteger(keys::kFrameIdKey, GetFrameId(is_main_frame, frame_id)); 127 dict->SetInteger(keys::kFrameIdKey, GetFrameId(is_main_frame, frame_id));
120 dict->SetDouble(keys::kTimeStampKey, MilliSecondsFromTime(base::Time::Now())); 128 dict->SetDouble(keys::kTimeStampKey, MilliSecondsFromTime(base::Time::Now()));
121 args.Append(dict); 129 args.Append(dict);
122 130
123 DispatchEvent(web_contents->GetBrowserContext(), 131 DispatchEvent(web_contents->GetBrowserContext(),
124 keys::kOnDOMContentLoaded, 132 keys::kOnDOMContentLoaded,
125 args, 133 args,
126 url); 134 url);
127 } 135 }
128 136
129 // Constructs and dispatches an onCompleted event. 137 // Constructs and dispatches an onCompleted event.
130 void DispatchOnCompleted(content::WebContents* web_contents, 138 void DispatchOnCompleted(content::WebContents* web_contents,
131 const GURL& url, 139 const GURL& url,
132 bool is_main_frame, 140 bool is_main_frame,
133 int64 frame_id) { 141 int64 frame_id) {
134 ListValue args; 142 ListValue args;
135 DictionaryValue* dict = new DictionaryValue(); 143 DictionaryValue* dict = new DictionaryValue();
136 dict->SetInteger(keys::kTabIdKey, 144 dict->SetInteger(keys::kTabIdKey,
137 ExtensionTabUtil::GetTabId(web_contents)); 145 ExtensionTabUtil::GetTabId(web_contents));
138 dict->SetString(keys::kUrlKey, url.spec()); 146 dict->SetString(keys::kUrlKey, url.spec());
147 dict->SetInteger(keys::kProcessIdKey,
148 web_contents->GetRenderViewHost()->GetProcess()->GetID());
139 dict->SetInteger(keys::kFrameIdKey, GetFrameId(is_main_frame, frame_id)); 149 dict->SetInteger(keys::kFrameIdKey, GetFrameId(is_main_frame, frame_id));
140 dict->SetDouble(keys::kTimeStampKey, MilliSecondsFromTime(base::Time::Now())); 150 dict->SetDouble(keys::kTimeStampKey, MilliSecondsFromTime(base::Time::Now()));
141 args.Append(dict); 151 args.Append(dict);
142 152
143 DispatchEvent(web_contents->GetBrowserContext(), keys::kOnCompleted, args, 153 DispatchEvent(web_contents->GetBrowserContext(), keys::kOnCompleted, args,
144 url); 154 url);
145 } 155 }
146 156
147 // Constructs and dispatches an onCreatedNavigationTarget event. 157 // Constructs and dispatches an onCreatedNavigationTarget event.
148 void DispatchOnCreatedNavigationTarget( 158 void DispatchOnCreatedNavigationTarget(
149 content::WebContents* web_contents, 159 content::WebContents* web_contents,
150 content::BrowserContext* browser_context, 160 content::BrowserContext* browser_context,
151 int64 source_frame_id, 161 int64 source_frame_id,
152 bool source_frame_is_main_frame, 162 bool source_frame_is_main_frame,
153 content::WebContents* target_web_contents, 163 content::WebContents* target_web_contents,
154 const GURL& target_url) { 164 const GURL& target_url) {
155 // Check that the tab is already inserted into a tab strip model. This code 165 // Check that the tab is already inserted into a tab strip model. This code
156 // path is exercised by ExtensionApiTest.WebNavigationRequestOpenTab. 166 // path is exercised by ExtensionApiTest.WebNavigationRequestOpenTab.
157 DCHECK(ExtensionTabUtil::GetTabById( 167 DCHECK(ExtensionTabUtil::GetTabById(
158 ExtensionTabUtil::GetTabId(target_web_contents), 168 ExtensionTabUtil::GetTabId(target_web_contents),
159 Profile::FromBrowserContext(target_web_contents->GetBrowserContext()), 169 Profile::FromBrowserContext(target_web_contents->GetBrowserContext()),
160 false, NULL, NULL, NULL, NULL)); 170 false, NULL, NULL, NULL, NULL));
161 171
162 ListValue args; 172 ListValue args;
163 DictionaryValue* dict = new DictionaryValue(); 173 DictionaryValue* dict = new DictionaryValue();
164 dict->SetInteger(keys::kSourceTabIdKey, 174 dict->SetInteger(keys::kSourceTabIdKey,
165 ExtensionTabUtil::GetTabId(web_contents)); 175 ExtensionTabUtil::GetTabId(web_contents));
176 dict->SetInteger(keys::kSourceProcessIdKey,
177 web_contents->GetRenderViewHost()->GetProcess()->GetID());
166 dict->SetInteger(keys::kSourceFrameIdKey, 178 dict->SetInteger(keys::kSourceFrameIdKey,
167 GetFrameId(source_frame_is_main_frame, source_frame_id)); 179 GetFrameId(source_frame_is_main_frame, source_frame_id));
168 dict->SetString(keys::kUrlKey, target_url.possibly_invalid_spec()); 180 dict->SetString(keys::kUrlKey, target_url.possibly_invalid_spec());
169 dict->SetInteger(keys::kTabIdKey, 181 dict->SetInteger(keys::kTabIdKey,
170 ExtensionTabUtil::GetTabId(target_web_contents)); 182 ExtensionTabUtil::GetTabId(target_web_contents));
171 dict->SetDouble(keys::kTimeStampKey, MilliSecondsFromTime(base::Time::Now())); 183 dict->SetDouble(keys::kTimeStampKey, MilliSecondsFromTime(base::Time::Now()));
172 args.Append(dict); 184 args.Append(dict);
173 185
174 DispatchEvent(browser_context, keys::kOnCreatedNavigationTarget, args, 186 DispatchEvent(browser_context, keys::kOnCreatedNavigationTarget, args,
175 target_url); 187 target_url);
176 } 188 }
177 189
178 // Constructs and dispatches an onErrorOccurred event. 190 // Constructs and dispatches an onErrorOccurred event.
179 void DispatchOnErrorOccurred(content::WebContents* web_contents, 191 void DispatchOnErrorOccurred(content::WebContents* web_contents,
180 const GURL& url, 192 const GURL& url,
181 int64 frame_id, 193 int64 frame_id,
182 bool is_main_frame, 194 bool is_main_frame,
183 int error_code) { 195 int error_code) {
184 ListValue args; 196 ListValue args;
185 DictionaryValue* dict = new DictionaryValue(); 197 DictionaryValue* dict = new DictionaryValue();
186 dict->SetInteger(keys::kTabIdKey, ExtensionTabUtil::GetTabId(web_contents)); 198 dict->SetInteger(keys::kTabIdKey, ExtensionTabUtil::GetTabId(web_contents));
187 dict->SetString(keys::kUrlKey, url.spec()); 199 dict->SetString(keys::kUrlKey, url.spec());
200 dict->SetInteger(keys::kProcessIdKey,
201 web_contents->GetRenderViewHost()->GetProcess()->GetID());
188 dict->SetInteger(keys::kFrameIdKey, GetFrameId(is_main_frame, frame_id)); 202 dict->SetInteger(keys::kFrameIdKey, GetFrameId(is_main_frame, frame_id));
189 dict->SetString(keys::kErrorKey, net::ErrorToString(error_code)); 203 dict->SetString(keys::kErrorKey, net::ErrorToString(error_code));
190 dict->SetDouble(keys::kTimeStampKey, MilliSecondsFromTime(base::Time::Now())); 204 dict->SetDouble(keys::kTimeStampKey, MilliSecondsFromTime(base::Time::Now()));
191 args.Append(dict); 205 args.Append(dict);
192 206
193 DispatchEvent(web_contents->GetBrowserContext(), keys::kOnErrorOccurred, 207 DispatchEvent(web_contents->GetBrowserContext(), keys::kOnErrorOccurred,
194 args, url); 208 args, url);
195 } 209 }
196 210
197 // Constructs and dispatches an onTabReplaced event. 211 // Constructs and dispatches an onTabReplaced event.
198 void DispatchOnTabReplaced( 212 void DispatchOnTabReplaced(
199 content::WebContents* old_web_contents, 213 content::WebContents* old_web_contents,
200 content::BrowserContext* browser_context, 214 content::BrowserContext* browser_context,
201 content::WebContents* new_web_contents) { 215 content::WebContents* new_web_contents) {
202 ListValue args; 216 ListValue args;
203 DictionaryValue* dict = new DictionaryValue(); 217 DictionaryValue* dict = new DictionaryValue();
204 dict->SetInteger(keys::kReplacedTabIdKey, 218 dict->SetInteger(keys::kReplacedTabIdKey,
205 ExtensionTabUtil::GetTabId(old_web_contents)); 219 ExtensionTabUtil::GetTabId(old_web_contents));
206 dict->SetInteger(keys::kTabIdKey, 220 dict->SetInteger(keys::kTabIdKey,
207 ExtensionTabUtil::GetTabId(new_web_contents)); 221 ExtensionTabUtil::GetTabId(new_web_contents));
208 dict->SetDouble(keys::kTimeStampKey, MilliSecondsFromTime(base::Time::Now())); 222 dict->SetDouble(keys::kTimeStampKey, MilliSecondsFromTime(base::Time::Now()));
209 args.Append(dict); 223 args.Append(dict);
210 224
211 DispatchEvent(browser_context, keys::kOnTabReplaced, args, GURL()); 225 DispatchEvent(browser_context, keys::kOnTabReplaced, args, GURL());
212 } 226 }
213 227
214 } // namespace web_navigation_api_helpers 228 } // namespace web_navigation_api_helpers
215 229
216 } // namespace extensions 230 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698