| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
| 8 #include "app/resource_bundle.h" | 8 #include "app/resource_bundle.h" |
| 9 #include "chrome/browser/profile.h" | 9 #include "chrome/browser/profile.h" |
| 10 #include "chrome/browser/tab_contents/navigation_controller.h" | 10 #include "chrome/browser/tab_contents/navigation_controller.h" |
| 11 #include "chrome/browser/tab_contents/navigation_entry.h" | 11 #include "chrome/browser/tab_contents/navigation_entry.h" |
| 12 #include "chrome/browser/tab_contents/tab_contents.h" | 12 #include "chrome/browser/tab_contents/tab_contents.h" |
| 13 #include "chrome/common/notification_service.h" | 13 #include "chrome/common/notification_service.h" |
| 14 #include "grit/generated_resources.h" | 14 #include "grit/generated_resources.h" |
| 15 #include "grit/theme_resources.h" | 15 #include "grit/theme_resources.h" |
| 16 #include "net/base/registry_controlled_domain.h" |
| 16 #include "net/url_request/url_request.h" | 17 #include "net/url_request/url_request.h" |
| 17 | 18 |
| 18 AlternateNavURLFetcher::AlternateNavURLFetcher( | 19 AlternateNavURLFetcher::AlternateNavURLFetcher( |
| 19 const GURL& alternate_nav_url) | 20 const GURL& alternate_nav_url) |
| 20 : LinkInfoBarDelegate(NULL), | 21 : LinkInfoBarDelegate(NULL), |
| 21 alternate_nav_url_(alternate_nav_url), | 22 alternate_nav_url_(alternate_nav_url), |
| 22 controller_(NULL), | 23 controller_(NULL), |
| 23 state_(NOT_STARTED), | 24 state_(NOT_STARTED), |
| 24 navigated_to_entry_(false), | 25 navigated_to_entry_(false), |
| 25 infobar_contents_(NULL) { | 26 infobar_contents_(NULL) { |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 const URLRequestStatus& status, | 80 const URLRequestStatus& status, |
| 80 int response_code, | 81 int response_code, |
| 81 const ResponseCookies& cookies, | 82 const ResponseCookies& cookies, |
| 82 const std::string& data) { | 83 const std::string& data) { |
| 83 DCHECK(fetcher_.get() == source); | 84 DCHECK(fetcher_.get() == source); |
| 84 if (status.is_success() && | 85 if (status.is_success() && |
| 85 // HTTP 2xx, 401, and 407 all indicate that the target address exists. | 86 // HTTP 2xx, 401, and 407 all indicate that the target address exists. |
| 86 (((response_code / 100) == 2) || | 87 (((response_code / 100) == 2) || |
| 87 (response_code == 401) || (response_code == 407))) { | 88 (response_code == 401) || (response_code == 407))) { |
| 88 state_ = SUCCEEDED; | 89 state_ = SUCCEEDED; |
| 90 |
| 91 // The following TLD+1s are used as destinations by ISPs/DNS providers/etc. |
| 92 // who return provider-controlled pages to arbitrary user navigation |
| 93 // attempts. Because this can result in infobars on large fractions of user |
| 94 // searches, we don't show automatic infobars for these. Note that users |
| 95 // can still choose to explicitly navigate to or search for pages in these |
| 96 // domains, and can still get infobars for cases that wind up on other |
| 97 // domains (e.g. legit intranet sites), we're just trying to avoid |
| 98 // erroneously harassing the user with our own UI prompts. |
| 99 const char* kBlacklistedSites[] = { |
| 100 "comcast.com", |
| 101 "opendns.com", |
| 102 "verizon.net", |
| 103 }; |
| 104 for (size_t i = 0; i < arraysize(kBlacklistedSites); ++i) { |
| 105 if (net::RegistryControlledDomainService::SameDomainOrHost( |
| 106 url, GURL(kBlacklistedSites[i]))) { |
| 107 state_ = FAILED; |
| 108 break; |
| 109 } |
| 110 } |
| 89 } else { | 111 } else { |
| 90 state_ = FAILED; | 112 state_ = FAILED; |
| 91 } | 113 } |
| 114 |
| 92 ShowInfobarIfPossible(); | 115 ShowInfobarIfPossible(); |
| 93 } | 116 } |
| 94 | 117 |
| 95 std::wstring AlternateNavURLFetcher::GetMessageTextWithOffset( | 118 std::wstring AlternateNavURLFetcher::GetMessageTextWithOffset( |
| 96 size_t* link_offset) const { | 119 size_t* link_offset) const { |
| 97 const std::wstring label = l10n_util::GetStringF( | 120 const std::wstring label = l10n_util::GetStringF( |
| 98 IDS_ALTERNATE_NAV_URL_VIEW_LABEL, std::wstring(), link_offset); | 121 IDS_ALTERNATE_NAV_URL_VIEW_LABEL, std::wstring(), link_offset); |
| 99 DCHECK(*link_offset != std::wstring::npos); | 122 DCHECK(*link_offset != std::wstring::npos); |
| 100 return label; | 123 return label; |
| 101 } | 124 } |
| (...skipping 29 matching lines...) Expand all Loading... |
| 131 if (state_ == FAILED) | 154 if (state_ == FAILED) |
| 132 delete this; | 155 delete this; |
| 133 return; | 156 return; |
| 134 } | 157 } |
| 135 | 158 |
| 136 infobar_contents_ = controller_->tab_contents(); | 159 infobar_contents_ = controller_->tab_contents(); |
| 137 StoreActiveEntryUniqueID(infobar_contents_); | 160 StoreActiveEntryUniqueID(infobar_contents_); |
| 138 // We will be deleted when the InfoBar is destroyed. (See InfoBarClosed). | 161 // We will be deleted when the InfoBar is destroyed. (See InfoBarClosed). |
| 139 infobar_contents_->AddInfoBar(this); | 162 infobar_contents_->AddInfoBar(this); |
| 140 } | 163 } |
| OLD | NEW |