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/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" |
11 #include "chrome/browser/tab_contents/link_infobar_delegate.h" | 11 #include "chrome/browser/tab_contents/link_infobar_delegate.h" |
12 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 12 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
13 #include "chrome/common/chrome_notification_types.h" | 13 #include "chrome/common/chrome_notification_types.h" |
14 #include "content/public/browser/navigation_controller.h" | 14 #include "content/public/browser/navigation_controller.h" |
15 #include "content/public/browser/notification_service.h" | 15 #include "content/public/browser/notification_service.h" |
16 #include "content/public/common/url_fetcher.h" | 16 #include "content/public/common/url_fetcher.h" |
| 17 #include "content/public/browser/render_process_host.h" |
| 18 #include "content/public/browser/render_view_host.h" |
17 #include "content/public/browser/web_contents.h" | 19 #include "content/public/browser/web_contents.h" |
18 #include "grit/generated_resources.h" | 20 #include "grit/generated_resources.h" |
19 #include "grit/theme_resources_standard.h" | 21 #include "grit/theme_resources_standard.h" |
20 #include "net/base/load_flags.h" | 22 #include "net/base/load_flags.h" |
21 #include "net/base/registry_controlled_domain.h" | 23 #include "net/base/registry_controlled_domain.h" |
22 #include "net/url_request/url_request.h" | 24 #include "net/url_request/url_request.h" |
23 #include "ui/base/l10n/l10n_util.h" | 25 #include "ui/base/l10n/l10n_util.h" |
24 #include "ui/base/resource/resource_bundle.h" | 26 #include "ui/base/resource/resource_bundle.h" |
25 | 27 |
26 using content::NavigationController; | 28 using content::NavigationController; |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 controller_ = controller; | 186 controller_ = controller; |
185 registrar_.Add(this, content::NOTIFICATION_TAB_CLOSED, | 187 registrar_.Add(this, content::NOTIFICATION_TAB_CLOSED, |
186 content::Source<NavigationController>(controller_)); | 188 content::Source<NavigationController>(controller_)); |
187 | 189 |
188 DCHECK_EQ(NOT_STARTED, state_); | 190 DCHECK_EQ(NOT_STARTED, state_); |
189 state_ = IN_PROGRESS; | 191 state_ = IN_PROGRESS; |
190 fetcher_.reset(content::URLFetcher::Create( | 192 fetcher_.reset(content::URLFetcher::Create( |
191 GURL(alternate_nav_url_), content::URLFetcher::HEAD, this)); | 193 GURL(alternate_nav_url_), content::URLFetcher::HEAD, this)); |
192 fetcher_->SetRequestContext( | 194 fetcher_->SetRequestContext( |
193 controller_->GetBrowserContext()->GetRequestContext()); | 195 controller_->GetBrowserContext()->GetRequestContext()); |
194 fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES); | 196 |
| 197 content::WebContents* web_contents = controller_->GetWebContents(); |
| 198 fetcher_->AssociateWithRenderView( |
| 199 web_contents->GetURL(), |
| 200 web_contents->GetRenderProcessHost()->GetID(), |
| 201 web_contents->GetRenderViewHost()->GetRoutingID()); |
195 fetcher_->Start(); | 202 fetcher_->Start(); |
196 } | 203 } |
197 | 204 |
198 void AlternateNavURLFetcher::SetStatusFromURLFetch( | 205 void AlternateNavURLFetcher::SetStatusFromURLFetch( |
199 const GURL& url, | 206 const GURL& url, |
200 const net::URLRequestStatus& status, | 207 const net::URLRequestStatus& status, |
201 int response_code) { | 208 int response_code) { |
202 if (!status.is_success() || | 209 if (!status.is_success() || |
203 // HTTP 2xx, 401, and 407 all indicate that the target address exists. | 210 // HTTP 2xx, 401, and 407 all indicate that the target address exists. |
204 (((response_code / 100) != 2) && | 211 (((response_code / 100) != 2) && |
(...skipping 22 matching lines...) Expand all Loading... |
227 return; | 234 return; |
228 } | 235 } |
229 | 236 |
230 InfoBarTabHelper* infobar_helper = | 237 InfoBarTabHelper* infobar_helper = |
231 TabContentsWrapper::GetCurrentWrapperForContents( | 238 TabContentsWrapper::GetCurrentWrapperForContents( |
232 controller_->GetWebContents())->infobar_tab_helper(); | 239 controller_->GetWebContents())->infobar_tab_helper(); |
233 infobar_helper->AddInfoBar( | 240 infobar_helper->AddInfoBar( |
234 new AlternateNavInfoBarDelegate(infobar_helper, alternate_nav_url_)); | 241 new AlternateNavInfoBarDelegate(infobar_helper, alternate_nav_url_)); |
235 delete this; | 242 delete this; |
236 } | 243 } |
OLD | NEW |