 Chromium Code Reviews
 Chromium Code Reviews Issue 2545133002:
  PlzNavigate: Fix ordering of onBeforeNavigate and onCreatedNavigationTarget.  (Closed)
    
  
    Issue 2545133002:
  PlzNavigate: Fix ordering of onBeforeNavigate and onCreatedNavigationTarget.  (Closed) 
  | 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..9659414e4ad83240cba00ccf8c4eb91f4e9e6f86 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,18 @@ 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()); | 
| + if (profile) { | 
| + 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.
 | 
| + event->filter_info = info; | 
| + } | 
| + | 
| + return event; | 
| } | 
| // Constructs and dispatches an onCommitted or onReferenceFragmentUpdated | 
| @@ -203,6 +215,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->DispatchCachedOnBeforeNavigate(); | 
| } | 
| // Constructs and dispatches an onErrorOccurred event. |