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

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

Issue 10815051: Send the correct process ID with webNavigation events (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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 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"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 } 52 }
53 53
54 } // namespace 54 } // namespace
55 55
56 int GetFrameId(bool is_main_frame, int64 frame_id) { 56 int GetFrameId(bool is_main_frame, int64 frame_id) {
57 return is_main_frame ? 0 : static_cast<int>(frame_id); 57 return is_main_frame ? 0 : static_cast<int>(frame_id);
58 } 58 }
59 59
60 // Constructs and dispatches an onBeforeNavigate event. 60 // Constructs and dispatches an onBeforeNavigate event.
61 void DispatchOnBeforeNavigate(content::WebContents* web_contents, 61 void DispatchOnBeforeNavigate(content::WebContents* web_contents,
62 int render_process_id,
62 int64 frame_id, 63 int64 frame_id,
63 bool is_main_frame, 64 bool is_main_frame,
64 const GURL& validated_url) { 65 const GURL& validated_url) {
65 ListValue args; 66 ListValue args;
66 DictionaryValue* dict = new DictionaryValue(); 67 DictionaryValue* dict = new DictionaryValue();
67 dict->SetInteger(keys::kTabIdKey, ExtensionTabUtil::GetTabId(web_contents)); 68 dict->SetInteger(keys::kTabIdKey, ExtensionTabUtil::GetTabId(web_contents));
68 dict->SetString(keys::kUrlKey, validated_url.spec()); 69 dict->SetString(keys::kUrlKey, validated_url.spec());
69 dict->SetInteger(keys::kProcessIdKey, 70 dict->SetInteger(keys::kProcessIdKey, render_process_id);
70 web_contents->GetRenderViewHost()->GetProcess()->GetID());
71 dict->SetInteger(keys::kFrameIdKey, GetFrameId(is_main_frame, frame_id)); 71 dict->SetInteger(keys::kFrameIdKey, GetFrameId(is_main_frame, frame_id));
72 dict->SetDouble(keys::kTimeStampKey, MilliSecondsFromTime(base::Time::Now())); 72 dict->SetDouble(keys::kTimeStampKey, MilliSecondsFromTime(base::Time::Now()));
73 args.Append(dict); 73 args.Append(dict);
74 74
75 DispatchEvent(web_contents->GetBrowserContext(), 75 DispatchEvent(web_contents->GetBrowserContext(),
76 keys::kOnBeforeNavigate, 76 keys::kOnBeforeNavigate,
77 args, 77 args,
78 validated_url); 78 validated_url);
79 } 79 }
80 80
81 // Constructs and dispatches an onCommitted or onReferenceFragmentUpdated 81 // Constructs and dispatches an onCommitted or onReferenceFragmentUpdated
82 // event. 82 // event.
83 void DispatchOnCommitted(const char* event_name, 83 void DispatchOnCommitted(const char* event_name,
84 content::WebContents* web_contents, 84 content::WebContents* web_contents,
battre 2012/07/23 12:06:35 Optional: have you considered passing the render_p
jochen (gone - plz use gerrit) 2012/07/23 13:17:13 Yes, but I didn't like it :) The places I pass th
85 int64 frame_id, 85 int64 frame_id,
86 bool is_main_frame, 86 bool is_main_frame,
87 const GURL& url, 87 const GURL& url,
88 content::PageTransition transition_type) { 88 content::PageTransition transition_type) {
89 ListValue args; 89 ListValue args;
90 DictionaryValue* dict = new DictionaryValue(); 90 DictionaryValue* dict = new DictionaryValue();
91 dict->SetInteger(keys::kTabIdKey, ExtensionTabUtil::GetTabId(web_contents)); 91 dict->SetInteger(keys::kTabIdKey, ExtensionTabUtil::GetTabId(web_contents));
92 dict->SetString(keys::kUrlKey, url.spec()); 92 dict->SetString(keys::kUrlKey, url.spec());
93 dict->SetInteger(keys::kProcessIdKey, 93 dict->SetInteger(keys::kProcessIdKey,
94 web_contents->GetRenderViewHost()->GetProcess()->GetID()); 94 web_contents->GetRenderViewHost()->GetProcess()->GetID());
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 ExtensionTabUtil::GetTabId(target_web_contents)); 182 ExtensionTabUtil::GetTabId(target_web_contents));
183 dict->SetDouble(keys::kTimeStampKey, MilliSecondsFromTime(base::Time::Now())); 183 dict->SetDouble(keys::kTimeStampKey, MilliSecondsFromTime(base::Time::Now()));
184 args.Append(dict); 184 args.Append(dict);
185 185
186 DispatchEvent(browser_context, keys::kOnCreatedNavigationTarget, args, 186 DispatchEvent(browser_context, keys::kOnCreatedNavigationTarget, args,
187 target_url); 187 target_url);
188 } 188 }
189 189
190 // Constructs and dispatches an onErrorOccurred event. 190 // Constructs and dispatches an onErrorOccurred event.
191 void DispatchOnErrorOccurred(content::WebContents* web_contents, 191 void DispatchOnErrorOccurred(content::WebContents* web_contents,
192 int render_process_id,
192 const GURL& url, 193 const GURL& url,
193 int64 frame_id, 194 int64 frame_id,
194 bool is_main_frame, 195 bool is_main_frame,
195 int error_code) { 196 int error_code) {
196 ListValue args; 197 ListValue args;
197 DictionaryValue* dict = new DictionaryValue(); 198 DictionaryValue* dict = new DictionaryValue();
198 dict->SetInteger(keys::kTabIdKey, ExtensionTabUtil::GetTabId(web_contents)); 199 dict->SetInteger(keys::kTabIdKey, ExtensionTabUtil::GetTabId(web_contents));
199 dict->SetString(keys::kUrlKey, url.spec()); 200 dict->SetString(keys::kUrlKey, url.spec());
200 dict->SetInteger(keys::kProcessIdKey, 201 dict->SetInteger(keys::kProcessIdKey, render_process_id);
201 web_contents->GetRenderViewHost()->GetProcess()->GetID());
202 dict->SetInteger(keys::kFrameIdKey, GetFrameId(is_main_frame, frame_id)); 202 dict->SetInteger(keys::kFrameIdKey, GetFrameId(is_main_frame, frame_id));
203 dict->SetString(keys::kErrorKey, net::ErrorToString(error_code)); 203 dict->SetString(keys::kErrorKey, net::ErrorToString(error_code));
204 dict->SetDouble(keys::kTimeStampKey, MilliSecondsFromTime(base::Time::Now())); 204 dict->SetDouble(keys::kTimeStampKey, MilliSecondsFromTime(base::Time::Now()));
205 args.Append(dict); 205 args.Append(dict);
206 206
207 DispatchEvent(web_contents->GetBrowserContext(), keys::kOnErrorOccurred, 207 DispatchEvent(web_contents->GetBrowserContext(), keys::kOnErrorOccurred,
208 args, url); 208 args, url);
209 } 209 }
210 210
211 // Constructs and dispatches an onTabReplaced event. 211 // Constructs and dispatches an onTabReplaced event.
212 void DispatchOnTabReplaced( 212 void DispatchOnTabReplaced(
213 content::WebContents* old_web_contents, 213 content::WebContents* old_web_contents,
214 content::BrowserContext* browser_context, 214 content::BrowserContext* browser_context,
215 content::WebContents* new_web_contents) { 215 content::WebContents* new_web_contents) {
216 ListValue args; 216 ListValue args;
217 DictionaryValue* dict = new DictionaryValue(); 217 DictionaryValue* dict = new DictionaryValue();
218 dict->SetInteger(keys::kReplacedTabIdKey, 218 dict->SetInteger(keys::kReplacedTabIdKey,
219 ExtensionTabUtil::GetTabId(old_web_contents)); 219 ExtensionTabUtil::GetTabId(old_web_contents));
220 dict->SetInteger(keys::kTabIdKey, 220 dict->SetInteger(keys::kTabIdKey,
221 ExtensionTabUtil::GetTabId(new_web_contents)); 221 ExtensionTabUtil::GetTabId(new_web_contents));
222 dict->SetDouble(keys::kTimeStampKey, MilliSecondsFromTime(base::Time::Now())); 222 dict->SetDouble(keys::kTimeStampKey, MilliSecondsFromTime(base::Time::Now()));
223 args.Append(dict); 223 args.Append(dict);
224 224
225 DispatchEvent(browser_context, keys::kOnTabReplaced, args, GURL()); 225 DispatchEvent(browser_context, keys::kOnTabReplaced, args, GURL());
226 } 226 }
227 227
228 } // namespace web_navigation_api_helpers 228 } // namespace web_navigation_api_helpers
229 229
230 } // namespace extensions 230 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698