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

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

Issue 27057004: Make the OmniboxNavigationObserver update the ShortcutsProvider. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years, 2 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/omnibox/omnibox_navigation_observer.h ('k') | 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/history/shortcuts_backend.h"
8 #include "chrome/browser/history/shortcuts_backend_factory.h"
7 #include "chrome/browser/infobars/infobar_service.h" 9 #include "chrome/browser/infobars/infobar_service.h"
8 #include "chrome/browser/intranet_redirect_detector.h" 10 #include "chrome/browser/intranet_redirect_detector.h"
9 #include "chrome/browser/ui/omnibox/alternate_nav_infobar_delegate.h" 11 #include "chrome/browser/ui/omnibox/alternate_nav_infobar_delegate.h"
10 #include "content/public/browser/browser_context.h" 12 #include "content/public/browser/browser_context.h"
11 #include "content/public/browser/navigation_controller.h" 13 #include "content/public/browser/navigation_controller.h"
12 #include "content/public/browser/navigation_details.h" 14 #include "content/public/browser/navigation_details.h"
13 #include "content/public/browser/navigation_entry.h" 15 #include "content/public/browser/navigation_entry.h"
14 #include "content/public/browser/notification_service.h" 16 #include "content/public/browser/notification_service.h"
15 #include "content/public/browser/notification_types.h" 17 #include "content/public/browser/notification_types.h"
16 #include "content/public/browser/web_contents.h" 18 #include "content/public/browser/web_contents.h"
(...skipping 25 matching lines...) Expand all
42 final_url, redirect_url, 44 final_url, redirect_url,
43 net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES); 45 net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES);
44 } 46 }
45 47
46 } // namespace 48 } // namespace
47 49
48 50
49 // OmniboxNavigationObserver -------------------------------------------------- 51 // OmniboxNavigationObserver --------------------------------------------------
50 52
51 OmniboxNavigationObserver::OmniboxNavigationObserver( 53 OmniboxNavigationObserver::OmniboxNavigationObserver(
54 Profile* profile,
55 const string16& text,
56 const AutocompleteMatch& match,
52 const GURL& alternate_nav_url) 57 const GURL& alternate_nav_url)
53 : alternate_nav_url_(alternate_nav_url), 58 : text_(text),
59 match_(match),
60 alternate_nav_url_(alternate_nav_url),
61 shortcuts_backend_(ShortcutsBackendFactory::GetForProfile(profile)),
54 load_state_(LOAD_NOT_SEEN), 62 load_state_(LOAD_NOT_SEEN),
55 fetch_state_(FETCH_NOT_COMPLETE) { 63 fetch_state_(FETCH_NOT_COMPLETE) {
56 if (alternate_nav_url_.is_valid()) { 64 if (alternate_nav_url_.is_valid()) {
57 fetcher_.reset(net::URLFetcher::Create(alternate_nav_url, 65 fetcher_.reset(net::URLFetcher::Create(alternate_nav_url,
58 net::URLFetcher::HEAD, this)); 66 net::URLFetcher::HEAD, this));
59 fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES); 67 fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES);
60 fetcher_->SetStopOnRedirect(true); 68 fetcher_->SetStopOnRedirect(true);
61 } 69 }
62 // We need to start by listening to AllSources, since we don't know which tab 70 // We need to start by listening to AllSources, since we don't know which tab
63 // the navigation might occur in. 71 // the navigation might occur in.
64 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_PENDING, 72 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_PENDING,
65 content::NotificationService::AllSources()); 73 content::NotificationService::AllSources());
66 } 74 }
67 75
68 OmniboxNavigationObserver::~OmniboxNavigationObserver() { 76 OmniboxNavigationObserver::~OmniboxNavigationObserver() {
69 } 77 }
70 78
79 void OmniboxNavigationObserver::OnSuccessfulNavigation() {
80 if (shortcuts_backend_)
Bart N. 2013/10/16 17:42:47 This looks odd. The only place where you assign sh
81 shortcuts_backend_->OnOmniboxNavigation(text_, match_);
82 }
83
71 void OmniboxNavigationObserver::Observe( 84 void OmniboxNavigationObserver::Observe(
72 int type, 85 int type,
73 const content::NotificationSource& source, 86 const content::NotificationSource& source,
74 const content::NotificationDetails& details) { 87 const content::NotificationDetails& details) {
75 DCHECK_EQ(content::NOTIFICATION_NAV_ENTRY_PENDING, type); 88 DCHECK_EQ(content::NOTIFICATION_NAV_ENTRY_PENDING, type);
76 registrar_.Remove(this, content::NOTIFICATION_NAV_ENTRY_PENDING, 89 registrar_.Remove(this, content::NOTIFICATION_NAV_ENTRY_PENDING,
77 content::NotificationService::AllSources()); 90 content::NotificationService::AllSources());
78 content::NavigationController* controller = 91 content::NavigationController* controller =
79 content::Source<content::NavigationController>(source).ptr(); 92 content::Source<content::NavigationController>(source).ptr();
80 if (fetcher_) { 93 if (fetcher_) {
81 fetcher_->SetRequestContext( 94 fetcher_->SetRequestContext(
82 controller->GetBrowserContext()->GetRequestContext()); 95 controller->GetBrowserContext()->GetRequestContext());
83 } 96 }
84 WebContentsObserver::Observe(controller->GetWebContents()); 97 WebContentsObserver::Observe(controller->GetWebContents());
85 // NavigateToPendingEntry() will be called for this load as well. 98 // NavigateToPendingEntry() will be called for this load as well.
86 } 99 }
87 100
88 void OmniboxNavigationObserver::NavigationEntryCommitted( 101 void OmniboxNavigationObserver::NavigationEntryCommitted(
89 const content::LoadCommittedDetails& load_details) { 102 const content::LoadCommittedDetails& load_details) {
90 load_state_ = LOAD_COMMITTED; 103 load_state_ = LOAD_COMMITTED;
104 if (ResponseCodeIndicatesSuccess(load_details.http_status_code) &&
105 IsValidNavigation(match_.destination_url, load_details.entry->GetURL()))
106 OnSuccessfulNavigation();
91 if (!fetcher_ || (fetch_state_ != FETCH_NOT_COMPLETE)) 107 if (!fetcher_ || (fetch_state_ != FETCH_NOT_COMPLETE))
92 OnAllLoadingFinished(); // deletes |this|! 108 OnAllLoadingFinished(); // deletes |this|!
93 } 109 }
94 110
95 void OmniboxNavigationObserver::WebContentsDestroyed( 111 void OmniboxNavigationObserver::WebContentsDestroyed(
96 content::WebContents* web_contents) { 112 content::WebContents* web_contents) {
97 delete this; 113 delete this;
98 } 114 }
99 115
100 void OmniboxNavigationObserver::NavigateToPendingEntry( 116 void OmniboxNavigationObserver::NavigateToPendingEntry(
101 const GURL& url, 117 const GURL& url,
102 content::NavigationController::ReloadType reload_type) { 118 content::NavigationController::ReloadType reload_type) {
103 if (load_state_ == LOAD_NOT_SEEN) { 119 if (load_state_ == LOAD_NOT_SEEN) {
104 load_state_ = LOAD_PENDING; 120 load_state_ = LOAD_PENDING;
105 if (fetcher_) 121 if (fetcher_)
106 fetcher_->Start(); 122 fetcher_->Start();
107 } else { 123 } else {
108 delete this; 124 delete this;
109 } 125 }
110 } 126 }
111 127
112 void OmniboxNavigationObserver::OnURLFetchComplete( 128 void OmniboxNavigationObserver::OnURLFetchComplete(
113 const net::URLFetcher* source) { 129 const net::URLFetcher* source) {
130 DCHECK_EQ(fetcher_.get(), source);
114 const net::URLRequestStatus& status = source->GetStatus(); 131 const net::URLRequestStatus& status = source->GetStatus();
115 int response_code = source->GetResponseCode(); 132 int response_code = source->GetResponseCode();
116 fetch_state_ = 133 fetch_state_ =
117 (status.is_success() && ResponseCodeIndicatesSuccess(response_code)) || 134 (status.is_success() && ResponseCodeIndicatesSuccess(response_code)) ||
118 ((status.status() == net::URLRequestStatus::CANCELED) && 135 ((status.status() == net::URLRequestStatus::CANCELED) &&
119 ((response_code / 100) == 3) && 136 ((response_code / 100) == 3) &&
120 IsValidNavigation(alternate_nav_url_, source->GetURL())) ? 137 IsValidNavigation(alternate_nav_url_, source->GetURL())) ?
121 FETCH_SUCCEEDED : FETCH_FAILED; 138 FETCH_SUCCEEDED : FETCH_FAILED;
122 if (load_state_ == LOAD_COMMITTED) 139 if (load_state_ == LOAD_COMMITTED)
123 OnAllLoadingFinished(); // deletes |this|! 140 OnAllLoadingFinished(); // deletes |this|!
124 } 141 }
125 142
126 void OmniboxNavigationObserver::OnAllLoadingFinished() { 143 void OmniboxNavigationObserver::OnAllLoadingFinished() {
127 if (fetch_state_ == FETCH_SUCCEEDED) { 144 if (fetch_state_ == FETCH_SUCCEEDED) {
128 AlternateNavInfoBarDelegate::Create( 145 AlternateNavInfoBarDelegate::Create(
129 InfoBarService::FromWebContents(web_contents()), alternate_nav_url_); 146 InfoBarService::FromWebContents(web_contents()), alternate_nav_url_);
130 } 147 }
131 delete this; 148 delete this;
132 } 149 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/omnibox/omnibox_navigation_observer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698