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

Side by Side Diff: chrome/browser/ui/omnibox/omnibox_navigation_observer.cc

Issue 865313002: Prevent a possible crash on omnibox navigation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 11 months 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 void OmniboxNavigationObserver::OnSuccessfulNavigation() { 79 void OmniboxNavigationObserver::OnSuccessfulNavigation() {
80 if (shortcuts_backend_.get()) 80 if (shortcuts_backend_.get())
81 shortcuts_backend_->AddOrUpdateShortcut(text_, match_); 81 shortcuts_backend_->AddOrUpdateShortcut(text_, match_);
82 } 82 }
83 83
84 void OmniboxNavigationObserver::Observe( 84 void OmniboxNavigationObserver::Observe(
85 int type, 85 int type,
86 const content::NotificationSource& source, 86 const content::NotificationSource& source,
87 const content::NotificationDetails& details) { 87 const content::NotificationDetails& details) {
88 DCHECK_EQ(content::NOTIFICATION_NAV_ENTRY_PENDING, type); 88 DCHECK_EQ(content::NOTIFICATION_NAV_ENTRY_PENDING, type);
89
90 // It's possible for an attempted omnibox navigation to cause the extensions
91 // system to synchronously navigate an extension background page. Not only is
92 // this navigation not the one we want to observe, the associated WebContents
93 // is invisible and has no InfoBarService, so trying to show an infobar in it
94 // later will crash. Just ignore this navigation and keep listening.
95 content::NavigationController* controller =
96 content::Source<content::NavigationController>(source).ptr();
97 content::WebContents* web_contents = controller->GetWebContents();
98 if (!InfoBarService::FromWebContents(web_contents))
Vitaly Buka (NO REVIEWS) 2015/01/22 21:59:09 Using InfoBarservice for unwanted web-contents loo
Peter Kasting 2015/01/22 22:02:26 There's no theoretical reason why an extension bac
99 return;
100
101 CHECK_EQ(match_.destination_url,
102 content::Details<content::NavigationEntry>(details)->GetURL());
89 registrar_.Remove(this, content::NOTIFICATION_NAV_ENTRY_PENDING, 103 registrar_.Remove(this, content::NOTIFICATION_NAV_ENTRY_PENDING,
90 content::NotificationService::AllSources()); 104 content::NotificationService::AllSources());
91 content::NavigationController* controller =
92 content::Source<content::NavigationController>(source).ptr();
93 if (fetcher_) { 105 if (fetcher_) {
94 fetcher_->SetRequestContext( 106 fetcher_->SetRequestContext(
95 controller->GetBrowserContext()->GetRequestContext()); 107 controller->GetBrowserContext()->GetRequestContext());
96 } 108 }
97 WebContentsObserver::Observe(controller->GetWebContents()); 109 WebContentsObserver::Observe(web_contents);
98 // DidStartNavigationToPendingEntry() will be called for this load as well. 110 // DidStartNavigationToPendingEntry() will be called for this load as well.
99 } 111 }
100 112
101 void OmniboxNavigationObserver::NavigationEntryCommitted( 113 void OmniboxNavigationObserver::NavigationEntryCommitted(
102 const content::LoadCommittedDetails& load_details) { 114 const content::LoadCommittedDetails& load_details) {
103 load_state_ = LOAD_COMMITTED; 115 load_state_ = LOAD_COMMITTED;
104 if (ResponseCodeIndicatesSuccess(load_details.http_status_code) && 116 if (ResponseCodeIndicatesSuccess(load_details.http_status_code) &&
105 IsValidNavigation(match_.destination_url, load_details.entry->GetURL())) 117 IsValidNavigation(match_.destination_url, load_details.entry->GetURL()))
106 OnSuccessfulNavigation(); 118 OnSuccessfulNavigation();
107 if (!fetcher_ || (fetch_state_ != FETCH_NOT_COMPLETE)) 119 if (!fetcher_ || (fetch_state_ != FETCH_NOT_COMPLETE))
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 OnAllLoadingFinished(); // deletes |this|! 152 OnAllLoadingFinished(); // deletes |this|!
141 } 153 }
142 154
143 void OmniboxNavigationObserver::OnAllLoadingFinished() { 155 void OmniboxNavigationObserver::OnAllLoadingFinished() {
144 if (fetch_state_ == FETCH_SUCCEEDED) { 156 if (fetch_state_ == FETCH_SUCCEEDED) {
145 AlternateNavInfoBarDelegate::Create( 157 AlternateNavInfoBarDelegate::Create(
146 web_contents(), text_, alternate_nav_match_, match_.destination_url); 158 web_contents(), text_, alternate_nav_match_, match_.destination_url);
147 } 159 }
148 delete this; 160 delete this;
149 } 161 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698