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

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

Issue 2545133002: PlzNavigate: Fix ordering of onBeforeNavigate and onCreatedNavigationTarget. (Closed)
Patch Set: Fixes based on review. Created 4 years 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
« no previous file with comments | « chrome/browser/extensions/api/web_navigation/web_navigation_api_helpers.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <memory> 9 #include <memory>
10 #include <utility> 10 #include <utility>
11 11
12 #include "base/json/json_writer.h" 12 #include "base/json/json_writer.h"
13 #include "base/strings/string_number_conversions.h" 13 #include "base/strings/string_number_conversions.h"
14 #include "base/time/time.h" 14 #include "base/time/time.h"
15 #include "base/values.h" 15 #include "base/values.h"
16 #include "chrome/browser/extensions/api/web_navigation/web_navigation_api.h"
16 #include "chrome/browser/extensions/api/web_navigation/web_navigation_api_consta nts.h" 17 #include "chrome/browser/extensions/api/web_navigation/web_navigation_api_consta nts.h"
17 #include "chrome/browser/extensions/extension_tab_util.h" 18 #include "chrome/browser/extensions/extension_tab_util.h"
18 #include "chrome/browser/profiles/profile.h" 19 #include "chrome/browser/profiles/profile.h"
19 #include "chrome/common/extensions/api/web_navigation.h" 20 #include "chrome/common/extensions/api/web_navigation.h"
20 #include "content/public/browser/navigation_handle.h" 21 #include "content/public/browser/navigation_handle.h"
21 #include "content/public/browser/render_frame_host.h" 22 #include "content/public/browser/render_frame_host.h"
22 #include "content/public/browser/render_process_host.h" 23 #include "content/public/browser/render_process_host.h"
23 #include "content/public/browser/render_view_host.h" 24 #include "content/public/browser/render_view_host.h"
24 #include "content/public/browser/web_contents.h" 25 #include "content/public/browser/web_contents.h"
25 #include "content/public/common/url_constants.h" 26 #include "content/public/common/url_constants.h"
(...skipping 28 matching lines...) Expand all
54 EventRouter* event_router = EventRouter::Get(profile); 55 EventRouter* event_router = EventRouter::Get(profile);
55 if (profile && event_router) { 56 if (profile && event_router) {
56 event->restrict_to_browser_context = profile; 57 event->restrict_to_browser_context = profile;
57 event->filter_info = info; 58 event->filter_info = info;
58 event_router->BroadcastEvent(std::move(event)); 59 event_router->BroadcastEvent(std::move(event));
59 } 60 }
60 } 61 }
61 62
62 } // namespace 63 } // namespace
63 64
64 // Constructs and dispatches an onBeforeNavigate event. 65 // Constructs an onBeforeNavigate event.
65 void DispatchOnBeforeNavigate(content::NavigationHandle* navigation_handle) { 66 std::unique_ptr<Event> CreateOnBeforeNavigateEvent(
67 content::NavigationHandle* navigation_handle) {
66 GURL url(navigation_handle->GetURL()); 68 GURL url(navigation_handle->GetURL());
67 if (navigation_handle->IsSrcdoc()) 69 if (navigation_handle->IsSrcdoc())
68 url = GURL(content::kAboutSrcDocURL); 70 url = GURL(content::kAboutSrcDocURL);
69 71
70 web_navigation::OnBeforeNavigate::Details details; 72 web_navigation::OnBeforeNavigate::Details details;
71 details.tab_id = 73 details.tab_id =
72 ExtensionTabUtil::GetTabId(navigation_handle->GetWebContents()); 74 ExtensionTabUtil::GetTabId(navigation_handle->GetWebContents());
73 details.url = url.spec(); 75 details.url = url.spec();
74 details.process_id = -1; 76 details.process_id = -1;
75 details.frame_id = ExtensionApiFrameIdMap::GetFrameId(navigation_handle); 77 details.frame_id = ExtensionApiFrameIdMap::GetFrameId(navigation_handle);
76 details.parent_frame_id = 78 details.parent_frame_id =
77 ExtensionApiFrameIdMap::GetParentFrameId(navigation_handle); 79 ExtensionApiFrameIdMap::GetParentFrameId(navigation_handle);
78 details.time_stamp = MilliSecondsFromTime(base::Time::Now()); 80 details.time_stamp = MilliSecondsFromTime(base::Time::Now());
79 81
80 std::unique_ptr<Event> event( 82 std::unique_ptr<Event> event(
81 new Event(events::WEB_NAVIGATION_ON_BEFORE_NAVIGATE, 83 new Event(events::WEB_NAVIGATION_ON_BEFORE_NAVIGATE,
82 web_navigation::OnBeforeNavigate::kEventName, 84 web_navigation::OnBeforeNavigate::kEventName,
83 web_navigation::OnBeforeNavigate::Create(details))); 85 web_navigation::OnBeforeNavigate::Create(details)));
84 DispatchEvent(navigation_handle->GetWebContents()->GetBrowserContext(), 86
85 std::move(event), url); 87 EventFilteringInfo info;
88 info.SetURL(navigation_handle->GetURL());
89
90 Profile* profile = Profile::FromBrowserContext(
91 navigation_handle->GetWebContents()->GetBrowserContext());
92 if (profile) {
93 event->restrict_to_browser_context = profile;
Devlin 2016/12/02 21:58:31 Just use browser context directly.
nasko 2016/12/02 23:41:39 Done.
94 event->filter_info = info;
95 }
96
97 return event;
86 } 98 }
87 99
88 // Constructs and dispatches an onCommitted or onReferenceFragmentUpdated 100 // Constructs and dispatches an onCommitted or onReferenceFragmentUpdated
89 // event. 101 // event.
90 void DispatchOnCommitted(events::HistogramValue histogram_value, 102 void DispatchOnCommitted(events::HistogramValue histogram_value,
91 const std::string& event_name, 103 const std::string& event_name,
92 content::NavigationHandle* navigation_handle) { 104 content::NavigationHandle* navigation_handle) {
93 content::WebContents* web_contents = navigation_handle->GetWebContents(); 105 content::WebContents* web_contents = navigation_handle->GetWebContents();
94 GURL url(navigation_handle->GetURL()); 106 GURL url(navigation_handle->GetURL());
95 content::RenderFrameHost* frame_host = 107 content::RenderFrameHost* frame_host =
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 ExtensionApiFrameIdMap::GetFrameId(source_frame_host); 208 ExtensionApiFrameIdMap::GetFrameId(source_frame_host);
197 details.url = target_url.possibly_invalid_spec(); 209 details.url = target_url.possibly_invalid_spec();
198 details.tab_id = ExtensionTabUtil::GetTabId(target_web_contents); 210 details.tab_id = ExtensionTabUtil::GetTabId(target_web_contents);
199 details.time_stamp = MilliSecondsFromTime(base::Time::Now()); 211 details.time_stamp = MilliSecondsFromTime(base::Time::Now());
200 212
201 std::unique_ptr<Event> event( 213 std::unique_ptr<Event> event(
202 new Event(events::WEB_NAVIGATION_ON_CREATED_NAVIGATION_TARGET, 214 new Event(events::WEB_NAVIGATION_ON_CREATED_NAVIGATION_TARGET,
203 web_navigation::OnCreatedNavigationTarget::kEventName, 215 web_navigation::OnCreatedNavigationTarget::kEventName,
204 web_navigation::OnCreatedNavigationTarget::Create(details))); 216 web_navigation::OnCreatedNavigationTarget::Create(details)));
205 DispatchEvent(browser_context, std::move(event), target_url); 217 DispatchEvent(browser_context, std::move(event), target_url);
218
219 // If the target WebContents already received the onBeforeNavigate event,
220 // send it immediately after the onCreatedNavigationTarget above.
221 WebNavigationTabObserver* target_observer =
222 WebNavigationTabObserver::Get(target_web_contents);
223 target_observer->DispatchCachedOnBeforeNavigate();
206 } 224 }
207 225
208 // Constructs and dispatches an onErrorOccurred event. 226 // Constructs and dispatches an onErrorOccurred event.
209 void DispatchOnErrorOccurred(content::WebContents* web_contents, 227 void DispatchOnErrorOccurred(content::WebContents* web_contents,
210 content::RenderFrameHost* frame_host, 228 content::RenderFrameHost* frame_host,
211 const GURL& url, 229 const GURL& url,
212 int error_code) { 230 int error_code) {
213 web_navigation::OnErrorOccurred::Details details; 231 web_navigation::OnErrorOccurred::Details details;
214 details.tab_id = ExtensionTabUtil::GetTabId(web_contents); 232 details.tab_id = ExtensionTabUtil::GetTabId(web_contents);
215 details.url = url.spec(); 233 details.url = url.spec();
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 std::unique_ptr<Event> event( 276 std::unique_ptr<Event> event(
259 new Event(events::WEB_NAVIGATION_ON_TAB_REPLACED, 277 new Event(events::WEB_NAVIGATION_ON_TAB_REPLACED,
260 web_navigation::OnTabReplaced::kEventName, 278 web_navigation::OnTabReplaced::kEventName,
261 web_navigation::OnTabReplaced::Create(details))); 279 web_navigation::OnTabReplaced::Create(details)));
262 DispatchEvent(browser_context, std::move(event), GURL()); 280 DispatchEvent(browser_context, std::move(event), GURL());
263 } 281 }
264 282
265 } // namespace web_navigation_api_helpers 283 } // namespace web_navigation_api_helpers
266 284
267 } // namespace extensions 285 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/web_navigation/web_navigation_api_helpers.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698