OLD | NEW |
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 #include "chrome/browser/ui/omnibox/omnibox_navigation_observer.h" | 5 #include "chrome/browser/ui/omnibox/omnibox_navigation_observer.h" |
6 | 6 |
7 #include "chrome/browser/autocomplete/shortcuts_backend.h" | 7 #include "chrome/browser/autocomplete/shortcuts_backend.h" |
8 #include "chrome/browser/autocomplete/shortcuts_backend_factory.h" | 8 #include "chrome/browser/autocomplete/shortcuts_backend_factory.h" |
9 #include "chrome/browser/infobars/infobar_service.h" | 9 #include "chrome/browser/infobars/infobar_service.h" |
10 #include "chrome/browser/intranet_redirect_detector.h" | 10 #include "chrome/browser/intranet_redirect_detector.h" |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 // system to synchronously navigate an extension background page. Not only is | 92 // system to synchronously navigate an extension background page. Not only is |
93 // this navigation not the one we want to observe, the associated WebContents | 93 // this navigation not the one we want to observe, the associated WebContents |
94 // is invisible and has no InfoBarService, so trying to show an infobar in it | 94 // is invisible and has no InfoBarService, so trying to show an infobar in it |
95 // later will crash. Just ignore this navigation and keep listening. | 95 // later will crash. Just ignore this navigation and keep listening. |
96 content::NavigationController* controller = | 96 content::NavigationController* controller = |
97 content::Source<content::NavigationController>(source).ptr(); | 97 content::Source<content::NavigationController>(source).ptr(); |
98 content::WebContents* web_contents = controller->GetWebContents(); | 98 content::WebContents* web_contents = controller->GetWebContents(); |
99 if (!InfoBarService::FromWebContents(web_contents)) | 99 if (!InfoBarService::FromWebContents(web_contents)) |
100 return; | 100 return; |
101 | 101 |
102 CHECK_EQ(match_.destination_url, | 102 // Ignore navgiations to the wrong URL. |
103 content::Details<content::NavigationEntry>( | 103 // This shouldn't actually happen, but right now it's possible because the |
104 details)->GetVirtualURL()); | 104 // prerenderer doesn't properly notify us when it swaps in a prerendered page. |
| 105 // Plus, the swap-in can trigger instant to kick off a new background |
| 106 // prerender, which we _do_ get notified about. Once crbug.com/247848 is |
| 107 // fixed, this conditional should be able to be replaced with a [D]CHECK; |
| 108 // until then we ignore the incorrect navigation (and will be torn down |
| 109 // without having received the correct notification). |
| 110 if (match_.destination_url != |
| 111 content::Details<content::NavigationEntry>(details)->GetVirtualURL()) |
| 112 return; |
| 113 |
105 registrar_.Remove(this, content::NOTIFICATION_NAV_ENTRY_PENDING, | 114 registrar_.Remove(this, content::NOTIFICATION_NAV_ENTRY_PENDING, |
106 content::NotificationService::AllSources()); | 115 content::NotificationService::AllSources()); |
107 if (fetcher_) { | 116 if (fetcher_) { |
108 fetcher_->SetRequestContext( | 117 fetcher_->SetRequestContext( |
109 controller->GetBrowserContext()->GetRequestContext()); | 118 controller->GetBrowserContext()->GetRequestContext()); |
110 } | 119 } |
111 WebContentsObserver::Observe(web_contents); | 120 WebContentsObserver::Observe(web_contents); |
112 // DidStartNavigationToPendingEntry() will be called for this load as well. | 121 // DidStartNavigationToPendingEntry() will be called for this load as well. |
113 } | 122 } |
114 | 123 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 OnAllLoadingFinished(); // deletes |this|! | 173 OnAllLoadingFinished(); // deletes |this|! |
165 } | 174 } |
166 | 175 |
167 void OmniboxNavigationObserver::OnAllLoadingFinished() { | 176 void OmniboxNavigationObserver::OnAllLoadingFinished() { |
168 if (fetch_state_ == FETCH_SUCCEEDED) { | 177 if (fetch_state_ == FETCH_SUCCEEDED) { |
169 AlternateNavInfoBarDelegate::Create( | 178 AlternateNavInfoBarDelegate::Create( |
170 web_contents(), text_, alternate_nav_match_, match_.destination_url); | 179 web_contents(), text_, alternate_nav_match_, match_.destination_url); |
171 } | 180 } |
172 delete this; | 181 delete this; |
173 } | 182 } |
OLD | NEW |