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

Side by Side Diff: chrome/browser/extensions/api/web_navigation/web_navigation_api.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
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.h" 7 #include "chrome/browser/extensions/api/web_navigation/web_navigation_api.h"
8 8
9 #include "base/lazy_instance.h" 9 #include "base/lazy_instance.h"
10 #include "chrome/browser/chrome_notification_types.h" 10 #include "chrome/browser/chrome_notification_types.h"
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 navigation_state_.FrameHostCreated(new_host); 264 navigation_state_.FrameHostCreated(new_host);
265 } 265 }
266 266
267 void WebNavigationTabObserver::DidStartNavigation( 267 void WebNavigationTabObserver::DidStartNavigation(
268 content::NavigationHandle* navigation_handle) { 268 content::NavigationHandle* navigation_handle) {
269 if (navigation_handle->IsSamePage() || 269 if (navigation_handle->IsSamePage() ||
270 !FrameNavigationState::IsValidUrl(navigation_handle->GetURL())) { 270 !FrameNavigationState::IsValidUrl(navigation_handle->GetURL())) {
271 return; 271 return;
272 } 272 }
273 273
274 helpers::DispatchOnBeforeNavigate(navigation_handle); 274 pending_on_before_navigate_event_ =
275 helpers::CreateOnBeforeNavigateEvent(navigation_handle);
276
277 // Only dispatch the onBeforeNavigate event if the associated WebContents
278 // is already added to the tab strip. Otherwise the event should be delayed
279 // and sent after the addition, to preserve the ordering of events.
280 if (ExtensionTabUtil::GetTabById(ExtensionTabUtil::GetTabId(web_contents()),
281 web_contents()->GetBrowserContext(), false,
282 nullptr, nullptr, nullptr, nullptr)) {
283 DispatchCachedOnBeforeNavigate();
284 }
275 } 285 }
276 286
277 void WebNavigationTabObserver::DidFinishNavigation( 287 void WebNavigationTabObserver::DidFinishNavigation(
278 content::NavigationHandle* navigation_handle) { 288 content::NavigationHandle* navigation_handle) {
289 // If there has been a DidStartNavigation call before the tab was ready to
290 // dispatch events, ensure that it is sent before processing the
291 // DidFinishNavigation.
292 // Note: This is exercised by WebNavigationApiTest.TargetBlankIncognito.
293 DispatchCachedOnBeforeNavigate();
294
279 if (navigation_handle->HasCommitted() && !navigation_handle->IsErrorPage()) { 295 if (navigation_handle->HasCommitted() && !navigation_handle->IsErrorPage()) {
280 HandleCommit(navigation_handle); 296 HandleCommit(navigation_handle);
281 return; 297 return;
282 } 298 }
283 299
284 HandleError(navigation_handle); 300 HandleError(navigation_handle);
285 } 301 }
286 302
287 void WebNavigationTabObserver::DocumentLoadedInFrame( 303 void WebNavigationTabObserver::DocumentLoadedInFrame(
288 content::RenderFrameHost* render_frame_host) { 304 content::RenderFrameHost* render_frame_host) {
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 source_render_frame_host, 400 source_render_frame_host,
385 new_contents, 401 new_contents,
386 url); 402 url);
387 } 403 }
388 404
389 void WebNavigationTabObserver::WebContentsDestroyed() { 405 void WebNavigationTabObserver::WebContentsDestroyed() {
390 g_tab_observer.Get().erase(web_contents()); 406 g_tab_observer.Get().erase(web_contents());
391 registrar_.RemoveAll(); 407 registrar_.RemoveAll();
392 } 408 }
393 409
410 void WebNavigationTabObserver::DispatchCachedOnBeforeNavigate() {
411 if (!pending_on_before_navigate_event_.get())
412 return;
413
414 EventRouter::Get(web_contents()->GetBrowserContext())
415 ->BroadcastEvent(std::move(pending_on_before_navigate_event_));
416 }
417
394 void WebNavigationTabObserver::HandleCommit( 418 void WebNavigationTabObserver::HandleCommit(
395 content::NavigationHandle* navigation_handle) { 419 content::NavigationHandle* navigation_handle) {
396 bool is_reference_fragment_navigation = IsReferenceFragmentNavigation( 420 bool is_reference_fragment_navigation = IsReferenceFragmentNavigation(
397 navigation_handle->GetRenderFrameHost(), navigation_handle->GetURL()); 421 navigation_handle->GetRenderFrameHost(), navigation_handle->GetURL());
398 422
399 navigation_state_.StartTrackingDocumentLoad( 423 navigation_state_.StartTrackingDocumentLoad(
400 navigation_handle->GetRenderFrameHost(), navigation_handle->GetURL(), 424 navigation_handle->GetRenderFrameHost(), navigation_handle->GetURL(),
401 navigation_handle->IsSamePage(), 425 navigation_handle->IsSamePage(),
402 false, // is_error_page 426 false, // is_error_page
403 navigation_handle->IsSrcdoc()); 427 navigation_handle->IsSrcdoc());
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
560 return g_factory.Pointer(); 584 return g_factory.Pointer();
561 } 585 }
562 586
563 void WebNavigationAPI::OnListenerAdded(const EventListenerInfo& details) { 587 void WebNavigationAPI::OnListenerAdded(const EventListenerInfo& details) {
564 web_navigation_event_router_.reset(new WebNavigationEventRouter( 588 web_navigation_event_router_.reset(new WebNavigationEventRouter(
565 Profile::FromBrowserContext(browser_context_))); 589 Profile::FromBrowserContext(browser_context_)));
566 EventRouter::Get(browser_context_)->UnregisterObserver(this); 590 EventRouter::Get(browser_context_)->UnregisterObserver(this);
567 } 591 }
568 592
569 } // namespace extensions 593 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698