OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/alternate_nav_url_fetcher.h" | 5 #include "chrome/browser/alternate_nav_url_fetcher.h" |
6 | 6 |
7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
8 #include "chrome/browser/infobars/infobar_tab_helper.h" | 8 #include "chrome/browser/infobars/infobar_tab_helper.h" |
9 #include "chrome/browser/intranet_redirect_detector.h" | 9 #include "chrome/browser/intranet_redirect_detector.h" |
10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 // access the controller that will be invalid, we delete ourselves. | 155 // access the controller that will be invalid, we delete ourselves. |
156 // This deletes the URLFetcher and insures its callback won't be called. | 156 // This deletes the URLFetcher and insures its callback won't be called. |
157 delete this; | 157 delete this; |
158 break; | 158 break; |
159 | 159 |
160 default: | 160 default: |
161 NOTREACHED(); | 161 NOTREACHED(); |
162 } | 162 } |
163 } | 163 } |
164 | 164 |
165 void AlternateNavURLFetcher::OnURLFetchComplete(const URLFetcher* source) { | 165 void AlternateNavURLFetcher::OnURLFetchComplete( |
| 166 const content::URLFetcher* source) { |
166 DCHECK_EQ(fetcher_.get(), source); | 167 DCHECK_EQ(fetcher_.get(), source); |
167 SetStatusFromURLFetch( | 168 SetStatusFromURLFetch( |
168 source->url(), source->status(), source->response_code()); | 169 source->GetUrl(), source->GetStatus(), source->GetResponseCode()); |
169 ShowInfobarIfPossible(); | 170 ShowInfobarIfPossible(); |
170 // WARNING: |this| may be deleted! | 171 // WARNING: |this| may be deleted! |
171 } | 172 } |
172 | 173 |
173 void AlternateNavURLFetcher::StartFetch(NavigationController* controller) { | 174 void AlternateNavURLFetcher::StartFetch(NavigationController* controller) { |
174 controller_ = controller; | 175 controller_ = controller; |
175 registrar_.Add(this, content::NOTIFICATION_TAB_CLOSED, | 176 registrar_.Add(this, content::NOTIFICATION_TAB_CLOSED, |
176 content::Source<NavigationController>(controller_)); | 177 content::Source<NavigationController>(controller_)); |
177 | 178 |
178 DCHECK_EQ(NOT_STARTED, state_); | 179 DCHECK_EQ(NOT_STARTED, state_); |
179 state_ = IN_PROGRESS; | 180 state_ = IN_PROGRESS; |
180 fetcher_.reset(new URLFetcher(GURL(alternate_nav_url_), URLFetcher::HEAD, | 181 fetcher_.reset(new URLFetcher(GURL(alternate_nav_url_), URLFetcher::HEAD, |
181 this)); | 182 this)); |
182 fetcher_->set_request_context( | 183 fetcher_->SetRequestContext( |
183 controller_->browser_context()->GetRequestContext()); | 184 controller_->browser_context()->GetRequestContext()); |
184 fetcher_->Start(); | 185 fetcher_->Start(); |
185 } | 186 } |
186 | 187 |
187 void AlternateNavURLFetcher::SetStatusFromURLFetch( | 188 void AlternateNavURLFetcher::SetStatusFromURLFetch( |
188 const GURL& url, | 189 const GURL& url, |
189 const net::URLRequestStatus& status, | 190 const net::URLRequestStatus& status, |
190 int response_code) { | 191 int response_code) { |
191 if (!status.is_success() || | 192 if (!status.is_success() || |
192 // HTTP 2xx, 401, and 407 all indicate that the target address exists. | 193 // HTTP 2xx, 401, and 407 all indicate that the target address exists. |
(...skipping 23 matching lines...) Expand all Loading... |
216 return; | 217 return; |
217 } | 218 } |
218 | 219 |
219 InfoBarTabHelper* infobar_helper = | 220 InfoBarTabHelper* infobar_helper = |
220 TabContentsWrapper::GetCurrentWrapperForContents( | 221 TabContentsWrapper::GetCurrentWrapperForContents( |
221 controller_->tab_contents())->infobar_tab_helper(); | 222 controller_->tab_contents())->infobar_tab_helper(); |
222 infobar_helper->AddInfoBar( | 223 infobar_helper->AddInfoBar( |
223 new AlternateNavInfoBarDelegate(infobar_helper, alternate_nav_url_)); | 224 new AlternateNavInfoBarDelegate(infobar_helper, alternate_nav_url_)); |
224 delete this; | 225 delete this; |
225 } | 226 } |
OLD | NEW |