Index: chrome/browser/extensions/api/web_navigation/web_navigation_api_helpers.cc |
diff --git a/chrome/browser/extensions/api/web_navigation/web_navigation_api_helpers.cc b/chrome/browser/extensions/api/web_navigation/web_navigation_api_helpers.cc |
index 3f1e5a4aa9900b1928d6fb2b720e1357d11962f7..540940a8427c5f99425a5c5d3d073bcd6464b785 100644 |
--- a/chrome/browser/extensions/api/web_navigation/web_navigation_api_helpers.cc |
+++ b/chrome/browser/extensions/api/web_navigation/web_navigation_api_helpers.cc |
@@ -13,6 +13,7 @@ |
#include "base/strings/string_number_conversions.h" |
#include "base/time/time.h" |
#include "base/values.h" |
+#include "chrome/browser/extensions/api/web_navigation/web_navigation_api.h" |
#include "chrome/browser/extensions/api/web_navigation/web_navigation_api_constants.h" |
#include "chrome/browser/extensions/extension_tab_util.h" |
#include "chrome/browser/profiles/profile.h" |
@@ -61,8 +62,9 @@ void DispatchEvent(content::BrowserContext* browser_context, |
} // namespace |
-// Constructs and dispatches an onBeforeNavigate event. |
-void DispatchOnBeforeNavigate(content::NavigationHandle* navigation_handle) { |
+// Constructs an onBeforeNavigate event. |
+std::unique_ptr<Event> CreateOnBeforeNavigateEvent( |
+ content::NavigationHandle* navigation_handle) { |
GURL url(navigation_handle->GetURL()); |
if (navigation_handle->IsSrcdoc()) |
url = GURL(content::kAboutSrcDocURL); |
@@ -81,8 +83,19 @@ void DispatchOnBeforeNavigate(content::NavigationHandle* navigation_handle) { |
new Event(events::WEB_NAVIGATION_ON_BEFORE_NAVIGATE, |
web_navigation::OnBeforeNavigate::kEventName, |
web_navigation::OnBeforeNavigate::Create(details))); |
- DispatchEvent(navigation_handle->GetWebContents()->GetBrowserContext(), |
- std::move(event), url); |
+ |
+ EventFilteringInfo info; |
+ info.SetURL(navigation_handle->GetURL()); |
+ |
+ Profile* profile = Profile::FromBrowserContext( |
+ navigation_handle->GetWebContents()->GetBrowserContext()); |
+ EventRouter* event_router = EventRouter::Get(profile); |
Devlin
2016/12/02 20:17:11
Why do we need event router?
nasko
2016/12/02 21:40:45
Because of copy/paste :).
|
+ if (profile && event_router) { |
+ event->restrict_to_browser_context = profile; |
+ event->filter_info = info; |
+ } |
+ |
+ return event; |
} |
// Constructs and dispatches an onCommitted or onReferenceFragmentUpdated |
@@ -203,6 +216,12 @@ void DispatchOnCreatedNavigationTarget( |
web_navigation::OnCreatedNavigationTarget::kEventName, |
web_navigation::OnCreatedNavigationTarget::Create(details))); |
DispatchEvent(browser_context, std::move(event), target_url); |
+ |
+ // If the target WebContents already received the onBeforeNavigate event, |
+ // send it immediately after the onCreatedNavigationTarget above. |
+ WebNavigationTabObserver* target_observer = |
+ WebNavigationTabObserver::Get(target_web_contents); |
+ target_observer->DispatchOnBeforeNavigate(); |
} |
// Constructs and dispatches an onErrorOccurred event. |