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

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: 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(
Devlin 2016/12/02 20:17:11 I don't love that this is how we check this. It m
nasko 2016/12/02 21:40:45 I think there will be more fallout if we did that
Devlin 2016/12/02 21:58:31 // TODO(nasko|devlin): We have to do this check be
nasko 2016/12/02 23:41:39 Done.
281 ExtensionTabUtil::GetTabId(web_contents()),
282 Profile::FromBrowserContext(web_contents()->GetBrowserContext()),
Devlin 2016/12/02 20:17:11 nit: this can take a browser context, so no need f
nasko 2016/12/02 21:40:45 Done.
283 false, NULL, NULL, NULL, NULL)) {
Devlin 2016/12/02 20:17:11 nit: nullptr in new code.
nasko 2016/12/02 21:40:45 Done.
284 DispatchOnBeforeNavigate();
285 }
275 } 286 }
276 287
277 void WebNavigationTabObserver::DidFinishNavigation( 288 void WebNavigationTabObserver::DidFinishNavigation(
278 content::NavigationHandle* navigation_handle) { 289 content::NavigationHandle* navigation_handle) {
290 // If there has been a DidStartNavigation call before the tab was ready to
291 // dispatch events, ensure that it is sent before processing the
292 // DidFinishNavigation.
293 // Note: This is exercised by WebNavigationApiTest.TargetBlankIncognito.
294 DispatchOnBeforeNavigate();
Devlin 2016/12/02 20:17:11 Does this not have the same possible race? Or why
nasko 2016/12/02 21:40:45 This guarantees that if we are going to send a com
Devlin 2016/12/02 21:58:31 If the TabAdded notification is sent before DidSta
nasko 2016/12/02 23:41:39 The BrowserContext passed in should already be the
295
279 if (navigation_handle->HasCommitted() && !navigation_handle->IsErrorPage()) { 296 if (navigation_handle->HasCommitted() && !navigation_handle->IsErrorPage()) {
280 HandleCommit(navigation_handle); 297 HandleCommit(navigation_handle);
281 return; 298 return;
282 } 299 }
283 300
284 HandleError(navigation_handle); 301 HandleError(navigation_handle);
285 } 302 }
286 303
287 void WebNavigationTabObserver::DocumentLoadedInFrame( 304 void WebNavigationTabObserver::DocumentLoadedInFrame(
288 content::RenderFrameHost* render_frame_host) { 305 content::RenderFrameHost* render_frame_host) {
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 source_render_frame_host, 401 source_render_frame_host,
385 new_contents, 402 new_contents,
386 url); 403 url);
387 } 404 }
388 405
389 void WebNavigationTabObserver::WebContentsDestroyed() { 406 void WebNavigationTabObserver::WebContentsDestroyed() {
390 g_tab_observer.Get().erase(web_contents()); 407 g_tab_observer.Get().erase(web_contents());
391 registrar_.RemoveAll(); 408 registrar_.RemoveAll();
392 } 409 }
393 410
411 void WebNavigationTabObserver::DispatchOnBeforeNavigate() {
412 if (!pending_on_before_navigate_event_.get())
413 return;
414
415 Profile* profile =
416 Profile::FromBrowserContext(web_contents()->GetBrowserContext());
417 EventRouter* event_router = EventRouter::Get(profile);
Devlin 2016/12/02 20:17:11 nit: use browser context directly.
nasko 2016/12/02 21:40:45 Done.
418 if (profile && event_router)
Devlin 2016/12/02 20:17:11 can profile/context be null? (Or event router, fo
nasko 2016/12/02 21:40:45 I don't know whether the context can be null, poss
419 event_router->BroadcastEvent(std::move(pending_on_before_navigate_event_));
420 }
421
394 void WebNavigationTabObserver::HandleCommit( 422 void WebNavigationTabObserver::HandleCommit(
395 content::NavigationHandle* navigation_handle) { 423 content::NavigationHandle* navigation_handle) {
396 bool is_reference_fragment_navigation = IsReferenceFragmentNavigation( 424 bool is_reference_fragment_navigation = IsReferenceFragmentNavigation(
397 navigation_handle->GetRenderFrameHost(), navigation_handle->GetURL()); 425 navigation_handle->GetRenderFrameHost(), navigation_handle->GetURL());
398 426
399 navigation_state_.StartTrackingDocumentLoad( 427 navigation_state_.StartTrackingDocumentLoad(
400 navigation_handle->GetRenderFrameHost(), navigation_handle->GetURL(), 428 navigation_handle->GetRenderFrameHost(), navigation_handle->GetURL(),
401 navigation_handle->IsSamePage(), 429 navigation_handle->IsSamePage(),
402 false, // is_error_page 430 false, // is_error_page
403 navigation_handle->IsSrcdoc()); 431 navigation_handle->IsSrcdoc());
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
560 return g_factory.Pointer(); 588 return g_factory.Pointer();
561 } 589 }
562 590
563 void WebNavigationAPI::OnListenerAdded(const EventListenerInfo& details) { 591 void WebNavigationAPI::OnListenerAdded(const EventListenerInfo& details) {
564 web_navigation_event_router_.reset(new WebNavigationEventRouter( 592 web_navigation_event_router_.reset(new WebNavigationEventRouter(
565 Profile::FromBrowserContext(browser_context_))); 593 Profile::FromBrowserContext(browser_context_)));
566 EventRouter::Get(browser_context_)->UnregisterObserver(this); 594 EventRouter::Get(browser_context_)->UnregisterObserver(this);
567 } 595 }
568 596
569 } // namespace extensions 597 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698