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

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

Issue 1670673003: Refactor the implementation of the webNavigation extension API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@Bug-532666-NavigationHandleAPI
Patch Set: Remove UI thread DCHECKs. Created 4 years, 10 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
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 <utility> 9 #include <utility>
10 10
11 #include "base/json/json_writer.h" 11 #include "base/json/json_writer.h"
12 #include "base/strings/string_number_conversions.h" 12 #include "base/strings/string_number_conversions.h"
13 #include "base/time/time.h" 13 #include "base/time/time.h"
14 #include "base/values.h" 14 #include "base/values.h"
15 #include "chrome/browser/extensions/api/web_navigation/web_navigation_api_consta nts.h" 15 #include "chrome/browser/extensions/api/web_navigation/web_navigation_api_consta nts.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/common/extensions/api/web_navigation.h" 18 #include "chrome/common/extensions/api/web_navigation.h"
19 #include "content/public/browser/navigation_handle.h"
19 #include "content/public/browser/render_frame_host.h" 20 #include "content/public/browser/render_frame_host.h"
20 #include "content/public/browser/render_process_host.h" 21 #include "content/public/browser/render_process_host.h"
21 #include "content/public/browser/render_view_host.h" 22 #include "content/public/browser/render_view_host.h"
22 #include "content/public/browser/web_contents.h" 23 #include "content/public/browser/web_contents.h"
24 #include "content/public/common/url_constants.h"
23 #include "extensions/browser/event_router.h" 25 #include "extensions/browser/event_router.h"
24 #include "extensions/browser/extension_api_frame_id_map.h" 26 #include "extensions/browser/extension_api_frame_id_map.h"
25 #include "extensions/common/event_filtering_info.h" 27 #include "extensions/common/event_filtering_info.h"
26 #include "net/base/net_errors.h" 28 #include "net/base/net_errors.h"
27 #include "ui/base/page_transition_types.h" 29 #include "ui/base/page_transition_types.h"
28 30
29 namespace extensions { 31 namespace extensions {
30 32
31 namespace keys = web_navigation_api_constants; 33 namespace keys = web_navigation_api_constants;
32 namespace web_navigation = api::web_navigation; 34 namespace web_navigation = api::web_navigation;
33 35
34 namespace web_navigation_api_helpers { 36 namespace web_navigation_api_helpers {
35 37
36 namespace { 38 namespace {
37 39
38 // Returns |time| as milliseconds since the epoch. 40 // Returns |time| as milliseconds since the epoch.
39 double MilliSecondsFromTime(const base::Time& time) { 41 double MilliSecondsFromTime(const base::Time& time) {
40 return 1000 * time.ToDoubleT(); 42 return 1000 * time.ToDoubleT();
41 } 43 }
42 44
43 // Dispatches events to the extension message service. 45 // Dispatches events to the extension message service.
44 void DispatchEvent(content::BrowserContext* browser_context, 46 void DispatchEvent(content::BrowserContext* browser_context,
45 events::HistogramValue histogram_value, 47 scoped_ptr<Event> event,
46 const std::string& event_name,
47 scoped_ptr<base::ListValue> args,
48 const GURL& url) { 48 const GURL& url) {
49 EventFilteringInfo info; 49 EventFilteringInfo info;
50 info.SetURL(url); 50 info.SetURL(url);
51 51
52 Profile* profile = Profile::FromBrowserContext(browser_context); 52 Profile* profile = Profile::FromBrowserContext(browser_context);
53 EventRouter* event_router = EventRouter::Get(profile); 53 EventRouter* event_router = EventRouter::Get(profile);
54 if (profile && event_router) { 54 if (profile && event_router) {
55 scoped_ptr<Event> event(
56 new Event(histogram_value, event_name, std::move(args)));
57 event->restrict_to_browser_context = profile; 55 event->restrict_to_browser_context = profile;
58 event->filter_info = info; 56 event->filter_info = info;
59 event_router->BroadcastEvent(std::move(event)); 57 event_router->BroadcastEvent(std::move(event));
60 } 58 }
61 } 59 }
62 60
63 } // namespace 61 } // namespace
64 62
65 int GetFrameId(content::RenderFrameHost* frame_host) { 63 // Constructs and dispatches an onBeforeNavigate event.
66 return ExtensionApiFrameIdMap::GetFrameId(frame_host); 64 void DispatchOnBeforeNavigate(content::NavigationHandle* navigation_handle) {
67 } 65 GURL url(navigation_handle->GetURL());
66 if (navigation_handle->IsSrcdoc())
67 url = GURL(content::kAboutSrcDocURL);
68 68
69 // Constructs and dispatches an onBeforeNavigate event. 69 web_navigation::OnBeforeNavigate::Details details;
70 void DispatchOnBeforeNavigate(content::WebContents* web_contents, 70 details.tab_id =
71 content::RenderFrameHost* frame_host, 71 ExtensionTabUtil::GetTabId(navigation_handle->GetWebContents());
72 const GURL& validated_url) { 72 details.url = url.spec();
73 scoped_ptr<base::ListValue> args(new base::ListValue()); 73 details.process_id = -1;
74 base::DictionaryValue* dict = new base::DictionaryValue(); 74 details.frame_id = ExtensionApiFrameIdMap::GetFrameId(navigation_handle);
75 dict->SetInteger(keys::kTabIdKey, ExtensionTabUtil::GetTabId(web_contents)); 75 details.parent_frame_id =
76 dict->SetString(keys::kUrlKey, validated_url.spec()); 76 ExtensionApiFrameIdMap::GetParentFrameId(navigation_handle);
77 dict->SetInteger(keys::kProcessIdKey, frame_host->GetProcess()->GetID()); 77 details.time_stamp = MilliSecondsFromTime(base::Time::Now());
78 dict->SetInteger(keys::kFrameIdKey, GetFrameId(frame_host));
79 dict->SetInteger(keys::kParentFrameIdKey,
80 GetFrameId(frame_host->GetParent()));
81 dict->SetDouble(keys::kTimeStampKey, MilliSecondsFromTime(base::Time::Now()));
82 args->Append(dict);
83 78
84 DispatchEvent(web_contents->GetBrowserContext(), 79 scoped_ptr<Event> event(
85 events::WEB_NAVIGATION_ON_BEFORE_NAVIGATE, 80 new Event(events::WEB_NAVIGATION_ON_BEFORE_NAVIGATE,
86 web_navigation::OnBeforeNavigate::kEventName, std::move(args), 81 web_navigation::OnBeforeNavigate::kEventName,
87 validated_url); 82 web_navigation::OnBeforeNavigate::Create(details)));
83 DispatchEvent(navigation_handle->GetWebContents()->GetBrowserContext(),
84 std::move(event), url);
88 } 85 }
89 86
90 // Constructs and dispatches an onCommitted or onReferenceFragmentUpdated 87 // Constructs and dispatches an onCommitted or onReferenceFragmentUpdated
91 // event. 88 // event.
92 void DispatchOnCommitted(events::HistogramValue histogram_value, 89 void DispatchOnCommitted(events::HistogramValue histogram_value,
93 const std::string& event_name, 90 const std::string& event_name,
94 content::WebContents* web_contents, 91 content::NavigationHandle* navigation_handle) {
95 content::RenderFrameHost* frame_host, 92 content::WebContents* web_contents = navigation_handle->GetWebContents();
96 const GURL& url, 93 GURL url(navigation_handle->GetURL());
97 ui::PageTransition transition_type) { 94 content::RenderFrameHost* frame_host =
95 navigation_handle->GetRenderFrameHost();
96 ui::PageTransition transition_type = navigation_handle->GetPageTransition();
97
98 if (navigation_handle->IsSrcdoc())
99 url = GURL(content::kAboutSrcDocURL);
100
98 scoped_ptr<base::ListValue> args(new base::ListValue()); 101 scoped_ptr<base::ListValue> args(new base::ListValue());
99 base::DictionaryValue* dict = new base::DictionaryValue(); 102 base::DictionaryValue* dict = new base::DictionaryValue();
100 dict->SetInteger(keys::kTabIdKey, ExtensionTabUtil::GetTabId(web_contents)); 103 dict->SetInteger(keys::kTabIdKey, ExtensionTabUtil::GetTabId(web_contents));
101 dict->SetString(keys::kUrlKey, url.spec()); 104 dict->SetString(keys::kUrlKey, url.spec());
102 dict->SetInteger(keys::kProcessIdKey, frame_host->GetProcess()->GetID()); 105 dict->SetInteger(keys::kProcessIdKey, frame_host->GetProcess()->GetID());
103 dict->SetInteger(keys::kFrameIdKey, GetFrameId(frame_host)); 106 dict->SetInteger(keys::kFrameIdKey,
107 ExtensionApiFrameIdMap::GetFrameId(frame_host));
108
109 if (navigation_handle->WasServerRedirect()) {
110 transition_type = ui::PageTransitionFromInt(
111 transition_type | ui::PAGE_TRANSITION_SERVER_REDIRECT);
112 }
113
104 std::string transition_type_string = 114 std::string transition_type_string =
105 ui::PageTransitionGetCoreTransitionString(transition_type); 115 ui::PageTransitionGetCoreTransitionString(transition_type);
106 // For webNavigation API backward compatibility, keep "start_page" even after 116 // For webNavigation API backward compatibility, keep "start_page" even after
107 // renamed to "auto_toplevel". 117 // renamed to "auto_toplevel".
108 if (ui::PageTransitionStripQualifier(transition_type) == 118 if (ui::PageTransitionStripQualifier(transition_type) ==
109 ui::PAGE_TRANSITION_AUTO_TOPLEVEL) 119 ui::PAGE_TRANSITION_AUTO_TOPLEVEL)
110 transition_type_string = "start_page"; 120 transition_type_string = "start_page";
111 dict->SetString(keys::kTransitionTypeKey, transition_type_string); 121 dict->SetString(keys::kTransitionTypeKey, transition_type_string);
112 base::ListValue* qualifiers = new base::ListValue(); 122 base::ListValue* qualifiers = new base::ListValue();
113 if (transition_type & ui::PAGE_TRANSITION_CLIENT_REDIRECT) 123 if (transition_type & ui::PAGE_TRANSITION_CLIENT_REDIRECT)
114 qualifiers->Append(new base::StringValue("client_redirect")); 124 qualifiers->Append(new base::StringValue("client_redirect"));
115 if (transition_type & ui::PAGE_TRANSITION_SERVER_REDIRECT) 125 if (transition_type & ui::PAGE_TRANSITION_SERVER_REDIRECT)
116 qualifiers->Append(new base::StringValue("server_redirect")); 126 qualifiers->Append(new base::StringValue("server_redirect"));
117 if (transition_type & ui::PAGE_TRANSITION_FORWARD_BACK) 127 if (transition_type & ui::PAGE_TRANSITION_FORWARD_BACK)
118 qualifiers->Append(new base::StringValue("forward_back")); 128 qualifiers->Append(new base::StringValue("forward_back"));
119 if (transition_type & ui::PAGE_TRANSITION_FROM_ADDRESS_BAR) 129 if (transition_type & ui::PAGE_TRANSITION_FROM_ADDRESS_BAR)
120 qualifiers->Append(new base::StringValue("from_address_bar")); 130 qualifiers->Append(new base::StringValue("from_address_bar"));
121 dict->Set(keys::kTransitionQualifiersKey, qualifiers); 131 dict->Set(keys::kTransitionQualifiersKey, qualifiers);
122 dict->SetDouble(keys::kTimeStampKey, MilliSecondsFromTime(base::Time::Now())); 132 dict->SetDouble(keys::kTimeStampKey, MilliSecondsFromTime(base::Time::Now()));
123 args->Append(dict); 133 args->Append(dict);
124 134
125 DispatchEvent(web_contents->GetBrowserContext(), histogram_value, event_name, 135 scoped_ptr<Event> event(
126 std::move(args), url); 136 new Event(histogram_value, event_name, std::move(args)));
137 DispatchEvent(navigation_handle->GetWebContents()->GetBrowserContext(),
138 std::move(event), url);
127 } 139 }
128 140
129 // Constructs and dispatches an onDOMContentLoaded event. 141 // Constructs and dispatches an onDOMContentLoaded event.
130 void DispatchOnDOMContentLoaded(content::WebContents* web_contents, 142 void DispatchOnDOMContentLoaded(content::WebContents* web_contents,
131 content::RenderFrameHost* frame_host, 143 content::RenderFrameHost* frame_host,
132 const GURL& url) { 144 const GURL& url) {
133 scoped_ptr<base::ListValue> args(new base::ListValue()); 145 web_navigation::OnDOMContentLoaded::Details details;
134 base::DictionaryValue* dict = new base::DictionaryValue(); 146 details.tab_id = ExtensionTabUtil::GetTabId(web_contents);
135 dict->SetInteger(keys::kTabIdKey, 147 details.url = url.spec();
136 ExtensionTabUtil::GetTabId(web_contents)); 148 details.process_id = frame_host->GetProcess()->GetID();
137 dict->SetString(keys::kUrlKey, url.spec()); 149 details.frame_id = ExtensionApiFrameIdMap::GetFrameId(frame_host);
138 dict->SetInteger(keys::kProcessIdKey, frame_host->GetProcess()->GetID()); 150 details.time_stamp = MilliSecondsFromTime(base::Time::Now());
139 dict->SetInteger(keys::kFrameIdKey, GetFrameId(frame_host));
140 dict->SetDouble(keys::kTimeStampKey, MilliSecondsFromTime(base::Time::Now()));
141 args->Append(dict);
142 151
143 DispatchEvent(web_contents->GetBrowserContext(), 152 scoped_ptr<Event> event(
144 events::WEB_NAVIGATION_ON_DOM_CONTENT_LOADED, 153 new Event(events::WEB_NAVIGATION_ON_DOM_CONTENT_LOADED,
145 web_navigation::OnDOMContentLoaded::kEventName, std::move(args), 154 web_navigation::OnDOMContentLoaded::kEventName,
146 url); 155 web_navigation::OnDOMContentLoaded::Create(details)));
156 DispatchEvent(web_contents->GetBrowserContext(), std::move(event), url);
147 } 157 }
148 158
149 // Constructs and dispatches an onCompleted event. 159 // Constructs and dispatches an onCompleted event.
150 void DispatchOnCompleted(content::WebContents* web_contents, 160 void DispatchOnCompleted(content::WebContents* web_contents,
151 content::RenderFrameHost* frame_host, 161 content::RenderFrameHost* frame_host,
152 const GURL& url) { 162 const GURL& url) {
153 scoped_ptr<base::ListValue> args(new base::ListValue()); 163 web_navigation::OnCompleted::Details details;
154 base::DictionaryValue* dict = new base::DictionaryValue(); 164 details.tab_id = ExtensionTabUtil::GetTabId(web_contents);
155 dict->SetInteger(keys::kTabIdKey, 165 details.url = url.spec();
156 ExtensionTabUtil::GetTabId(web_contents)); 166 details.process_id = frame_host->GetProcess()->GetID();
157 dict->SetString(keys::kUrlKey, url.spec()); 167 details.frame_id = ExtensionApiFrameIdMap::GetFrameId(frame_host);
158 dict->SetInteger(keys::kProcessIdKey, frame_host->GetProcess()->GetID()); 168 details.time_stamp = MilliSecondsFromTime(base::Time::Now());
159 dict->SetInteger(keys::kFrameIdKey, GetFrameId(frame_host));
160 dict->SetDouble(keys::kTimeStampKey, MilliSecondsFromTime(base::Time::Now()));
161 args->Append(dict);
162 169
163 DispatchEvent(web_contents->GetBrowserContext(), 170 scoped_ptr<Event> event(
164 events::WEB_NAVIGATION_ON_COMPLETED, 171 new Event(events::WEB_NAVIGATION_ON_COMPLETED,
165 web_navigation::OnCompleted::kEventName, std::move(args), url); 172 web_navigation::OnCompleted::kEventName,
173 web_navigation::OnCompleted::Create(details)));
174 DispatchEvent(web_contents->GetBrowserContext(), std::move(event), url);
166 } 175 }
167 176
168 // Constructs and dispatches an onCreatedNavigationTarget event. 177 // Constructs and dispatches an onCreatedNavigationTarget event.
169 void DispatchOnCreatedNavigationTarget( 178 void DispatchOnCreatedNavigationTarget(
170 content::WebContents* web_contents, 179 content::WebContents* web_contents,
171 content::BrowserContext* browser_context, 180 content::BrowserContext* browser_context,
172 content::RenderFrameHost* source_frame_host, 181 content::RenderFrameHost* source_frame_host,
173 content::WebContents* target_web_contents, 182 content::WebContents* target_web_contents,
174 const GURL& target_url) { 183 const GURL& target_url) {
175 // Check that the tab is already inserted into a tab strip model. This code 184 // Check that the tab is already inserted into a tab strip model. This code
176 // path is exercised by ExtensionApiTest.WebNavigationRequestOpenTab. 185 // path is exercised by ExtensionApiTest.WebNavigationRequestOpenTab.
177 DCHECK(ExtensionTabUtil::GetTabById( 186 DCHECK(ExtensionTabUtil::GetTabById(
178 ExtensionTabUtil::GetTabId(target_web_contents), 187 ExtensionTabUtil::GetTabId(target_web_contents),
179 Profile::FromBrowserContext(target_web_contents->GetBrowserContext()), 188 Profile::FromBrowserContext(target_web_contents->GetBrowserContext()),
180 false, NULL, NULL, NULL, NULL)); 189 false, NULL, NULL, NULL, NULL));
181 190
182 scoped_ptr<base::ListValue> args(new base::ListValue()); 191 web_navigation::OnCreatedNavigationTarget::Details details;
183 base::DictionaryValue* dict = new base::DictionaryValue(); 192 details.source_tab_id = ExtensionTabUtil::GetTabId(web_contents);
184 dict->SetInteger(keys::kSourceTabIdKey, 193 details.source_process_id = source_frame_host->GetProcess()->GetID();
185 ExtensionTabUtil::GetTabId(web_contents)); 194 details.source_frame_id =
186 dict->SetInteger(keys::kSourceProcessIdKey, 195 ExtensionApiFrameIdMap::GetFrameId(source_frame_host);
187 source_frame_host->GetProcess()->GetID()); 196 details.url = target_url.possibly_invalid_spec();
188 dict->SetInteger(keys::kSourceFrameIdKey, GetFrameId(source_frame_host)); 197 details.tab_id = ExtensionTabUtil::GetTabId(target_web_contents);
189 dict->SetString(keys::kUrlKey, target_url.possibly_invalid_spec()); 198 details.time_stamp = MilliSecondsFromTime(base::Time::Now());
190 dict->SetInteger(keys::kTabIdKey,
191 ExtensionTabUtil::GetTabId(target_web_contents));
192 dict->SetDouble(keys::kTimeStampKey, MilliSecondsFromTime(base::Time::Now()));
193 args->Append(dict);
194 199
195 DispatchEvent(browser_context, 200 scoped_ptr<Event> event(
196 events::WEB_NAVIGATION_ON_CREATED_NAVIGATION_TARGET, 201 new Event(events::WEB_NAVIGATION_ON_CREATED_NAVIGATION_TARGET,
197 web_navigation::OnCreatedNavigationTarget::kEventName, 202 web_navigation::OnCreatedNavigationTarget::kEventName,
198 std::move(args), target_url); 203 web_navigation::OnCreatedNavigationTarget::Create(details)));
204 DispatchEvent(browser_context, std::move(event), target_url);
199 } 205 }
200 206
201 // Constructs and dispatches an onErrorOccurred event. 207 // Constructs and dispatches an onErrorOccurred event.
202 void DispatchOnErrorOccurred(content::WebContents* web_contents, 208 void DispatchOnErrorOccurred(content::WebContents* web_contents,
203 content::RenderFrameHost* frame_host, 209 content::RenderFrameHost* frame_host,
204 const GURL& url, 210 const GURL& url,
205 int error_code) { 211 int error_code) {
206 scoped_ptr<base::ListValue> args(new base::ListValue()); 212 web_navigation::OnErrorOccurred::Details details;
207 base::DictionaryValue* dict = new base::DictionaryValue(); 213 details.tab_id = ExtensionTabUtil::GetTabId(web_contents);
208 dict->SetInteger(keys::kTabIdKey, ExtensionTabUtil::GetTabId(web_contents)); 214 details.url = url.spec();
209 dict->SetString(keys::kUrlKey, url.spec()); 215 details.process_id = frame_host->GetProcess()->GetID();
210 dict->SetInteger(keys::kProcessIdKey, frame_host->GetProcess()->GetID()); 216 details.frame_id = ExtensionApiFrameIdMap::GetFrameId(frame_host);
211 dict->SetInteger(keys::kFrameIdKey, GetFrameId(frame_host)); 217 details.error = net::ErrorToString(error_code);
212 dict->SetString(keys::kErrorKey, net::ErrorToString(error_code)); 218 details.time_stamp = MilliSecondsFromTime(base::Time::Now());
213 dict->SetDouble(keys::kTimeStampKey,
214 MilliSecondsFromTime(base::Time::Now()));
215 args->Append(dict);
216 219
217 DispatchEvent(web_contents->GetBrowserContext(), 220 scoped_ptr<Event> event(
218 events::WEB_NAVIGATION_ON_ERROR_OCCURRED, 221 new Event(events::WEB_NAVIGATION_ON_ERROR_OCCURRED,
219 web_navigation::OnErrorOccurred::kEventName, std::move(args), 222 web_navigation::OnErrorOccurred::kEventName,
220 url); 223 web_navigation::OnErrorOccurred::Create(details)));
224 DispatchEvent(web_contents->GetBrowserContext(), std::move(event), url);
225 }
226
227 void DispatchOnErrorOccurred(content::NavigationHandle* navigation_handle) {
228 web_navigation::OnErrorOccurred::Details details;
229 details.tab_id =
230 ExtensionTabUtil::GetTabId(navigation_handle->GetWebContents());
231 details.url = navigation_handle->GetURL().spec();
232 details.process_id = -1;
233 details.frame_id = ExtensionApiFrameIdMap::GetFrameId(navigation_handle);
234 details.error = (navigation_handle->GetNetErrorCode() != net::OK)
235 ? net::ErrorToString(navigation_handle->GetNetErrorCode())
236 : net::ErrorToString(net::ERR_ABORTED);
237 details.time_stamp = MilliSecondsFromTime(base::Time::Now());
238
239 scoped_ptr<Event> event(
240 new Event(events::WEB_NAVIGATION_ON_ERROR_OCCURRED,
241 web_navigation::OnErrorOccurred::kEventName,
242 web_navigation::OnErrorOccurred::Create(details)));
243 DispatchEvent(navigation_handle->GetWebContents()->GetBrowserContext(),
244 std::move(event), navigation_handle->GetURL());
221 } 245 }
222 246
223 // Constructs and dispatches an onTabReplaced event. 247 // Constructs and dispatches an onTabReplaced event.
224 void DispatchOnTabReplaced( 248 void DispatchOnTabReplaced(
225 content::WebContents* old_web_contents, 249 content::WebContents* old_web_contents,
226 content::BrowserContext* browser_context, 250 content::BrowserContext* browser_context,
227 content::WebContents* new_web_contents) { 251 content::WebContents* new_web_contents) {
228 scoped_ptr<base::ListValue> args(new base::ListValue()); 252 web_navigation::OnTabReplaced::Details details;
229 base::DictionaryValue* dict = new base::DictionaryValue(); 253 details.replaced_tab_id = ExtensionTabUtil::GetTabId(old_web_contents);
230 dict->SetInteger(keys::kReplacedTabIdKey, 254 details.tab_id = ExtensionTabUtil::GetTabId(new_web_contents);
231 ExtensionTabUtil::GetTabId(old_web_contents)); 255 details.time_stamp = MilliSecondsFromTime(base::Time::Now());
232 dict->SetInteger(
233 keys::kTabIdKey,
234 ExtensionTabUtil::GetTabId(new_web_contents));
235 dict->SetDouble(keys::kTimeStampKey, MilliSecondsFromTime(base::Time::Now()));
236 args->Append(dict);
237 256
238 DispatchEvent(browser_context, events::WEB_NAVIGATION_ON_TAB_REPLACED, 257 scoped_ptr<Event> event(
239 web_navigation::OnTabReplaced::kEventName, std::move(args), 258 new Event(events::WEB_NAVIGATION_ON_TAB_REPLACED,
240 GURL()); 259 web_navigation::OnTabReplaced::kEventName,
260 web_navigation::OnTabReplaced::Create(details)));
261 DispatchEvent(browser_context, std::move(event), GURL());
241 } 262 }
242 263
243 } // namespace web_navigation_api_helpers 264 } // namespace web_navigation_api_helpers
244 265
245 } // namespace extensions 266 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698