| 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/history/shortcuts_backend.h" | 7 #include "chrome/browser/history/shortcuts_backend.h" |
| 8 #include "chrome/browser/history/shortcuts_backend_factory.h" | 8 #include "chrome/browser/history/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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 | 47 |
| 48 } // namespace | 48 } // namespace |
| 49 | 49 |
| 50 | 50 |
| 51 // OmniboxNavigationObserver -------------------------------------------------- | 51 // OmniboxNavigationObserver -------------------------------------------------- |
| 52 | 52 |
| 53 OmniboxNavigationObserver::OmniboxNavigationObserver( | 53 OmniboxNavigationObserver::OmniboxNavigationObserver( |
| 54 Profile* profile, | 54 Profile* profile, |
| 55 const string16& text, | 55 const string16& text, |
| 56 const AutocompleteMatch& match, | 56 const AutocompleteMatch& match, |
| 57 const GURL& alternate_nav_url) | 57 const AutocompleteMatch& alternate_nav_match) |
| 58 : text_(text), | 58 : text_(text), |
| 59 match_(match), | 59 match_(match), |
| 60 alternate_nav_url_(alternate_nav_url), | 60 alternate_nav_match_(alternate_nav_match), |
| 61 shortcuts_backend_(ShortcutsBackendFactory::GetForProfile(profile)), | 61 shortcuts_backend_(ShortcutsBackendFactory::GetForProfile(profile)), |
| 62 load_state_(LOAD_NOT_SEEN), | 62 load_state_(LOAD_NOT_SEEN), |
| 63 fetch_state_(FETCH_NOT_COMPLETE) { | 63 fetch_state_(FETCH_NOT_COMPLETE) { |
| 64 if (alternate_nav_url_.is_valid()) { | 64 if (alternate_nav_match_.destination_url.is_valid()) { |
| 65 fetcher_.reset(net::URLFetcher::Create(alternate_nav_url, | 65 fetcher_.reset(net::URLFetcher::Create(alternate_nav_match_.destination_url, |
| 66 net::URLFetcher::HEAD, this)); | 66 net::URLFetcher::HEAD, this)); |
| 67 fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES); | 67 fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES); |
| 68 fetcher_->SetStopOnRedirect(true); | 68 fetcher_->SetStopOnRedirect(true); |
| 69 } | 69 } |
| 70 // 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 |
| 71 // the navigation might occur in. | 71 // the navigation might occur in. |
| 72 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_PENDING, | 72 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_PENDING, |
| 73 content::NotificationService::AllSources()); | 73 content::NotificationService::AllSources()); |
| 74 } | 74 } |
| 75 | 75 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 | 127 |
| 128 void OmniboxNavigationObserver::OnURLFetchComplete( | 128 void OmniboxNavigationObserver::OnURLFetchComplete( |
| 129 const net::URLFetcher* source) { | 129 const net::URLFetcher* source) { |
| 130 DCHECK_EQ(fetcher_.get(), source); | 130 DCHECK_EQ(fetcher_.get(), source); |
| 131 const net::URLRequestStatus& status = source->GetStatus(); | 131 const net::URLRequestStatus& status = source->GetStatus(); |
| 132 int response_code = source->GetResponseCode(); | 132 int response_code = source->GetResponseCode(); |
| 133 fetch_state_ = | 133 fetch_state_ = |
| 134 (status.is_success() && ResponseCodeIndicatesSuccess(response_code)) || | 134 (status.is_success() && ResponseCodeIndicatesSuccess(response_code)) || |
| 135 ((status.status() == net::URLRequestStatus::CANCELED) && | 135 ((status.status() == net::URLRequestStatus::CANCELED) && |
| 136 ((response_code / 100) == 3) && | 136 ((response_code / 100) == 3) && |
| 137 IsValidNavigation(alternate_nav_url_, source->GetURL())) ? | 137 IsValidNavigation(alternate_nav_match_.destination_url, |
| 138 source->GetURL())) ? |
| 138 FETCH_SUCCEEDED : FETCH_FAILED; | 139 FETCH_SUCCEEDED : FETCH_FAILED; |
| 139 if (load_state_ == LOAD_COMMITTED) | 140 if (load_state_ == LOAD_COMMITTED) |
| 140 OnAllLoadingFinished(); // deletes |this|! | 141 OnAllLoadingFinished(); // deletes |this|! |
| 141 } | 142 } |
| 142 | 143 |
| 143 void OmniboxNavigationObserver::OnAllLoadingFinished() { | 144 void OmniboxNavigationObserver::OnAllLoadingFinished() { |
| 144 if (fetch_state_ == FETCH_SUCCEEDED) { | 145 if (fetch_state_ == FETCH_SUCCEEDED) { |
| 145 AlternateNavInfoBarDelegate::Create( | 146 AlternateNavInfoBarDelegate::Create( |
| 146 InfoBarService::FromWebContents(web_contents()), alternate_nav_url_); | 147 InfoBarService::FromWebContents(web_contents()), alternate_nav_match_); |
| 147 } | 148 } |
| 148 delete this; | 149 delete this; |
| 149 } | 150 } |
| OLD | NEW |