OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/intranet_redirect_detector.h" |
9 #include "chrome/browser/profile.h" | 10 #include "chrome/browser/profile.h" |
10 #include "chrome/browser/tab_contents/navigation_controller.h" | 11 #include "chrome/browser/tab_contents/navigation_controller.h" |
11 #include "chrome/browser/tab_contents/navigation_entry.h" | 12 #include "chrome/browser/tab_contents/navigation_entry.h" |
12 #include "chrome/browser/tab_contents/tab_contents.h" | 13 #include "chrome/browser/tab_contents/tab_contents.h" |
13 #include "chrome/common/notification_service.h" | 14 #include "chrome/common/notification_service.h" |
14 #include "grit/generated_resources.h" | 15 #include "grit/generated_resources.h" |
15 #include "grit/theme_resources.h" | 16 #include "grit/theme_resources.h" |
16 #include "net/base/registry_controlled_domain.h" | 17 #include "net/base/registry_controlled_domain.h" |
17 #include "net/url_request/url_request.h" | 18 #include "net/url_request/url_request.h" |
18 | 19 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 } | 76 } |
76 } | 77 } |
77 | 78 |
78 void AlternateNavURLFetcher::OnURLFetchComplete(const URLFetcher* source, | 79 void AlternateNavURLFetcher::OnURLFetchComplete(const URLFetcher* source, |
79 const GURL& url, | 80 const GURL& url, |
80 const URLRequestStatus& status, | 81 const URLRequestStatus& status, |
81 int response_code, | 82 int response_code, |
82 const ResponseCookies& cookies, | 83 const ResponseCookies& cookies, |
83 const std::string& data) { | 84 const std::string& data) { |
84 DCHECK(fetcher_.get() == source); | 85 DCHECK(fetcher_.get() == source); |
85 if (status.is_success() && | 86 SetStatusFromURLFetch(url, status, response_code); |
86 // HTTP 2xx, 401, and 407 all indicate that the target address exists. | |
87 (((response_code / 100) == 2) || | |
88 (response_code == 401) || (response_code == 407))) { | |
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 // NOTE: Use complete URLs, because GURL() doesn't do fixup! | |
101 "http://comcast.com/", | |
102 "http://opendns.com/", | |
103 "http://verizon.net/", | |
104 }; | |
105 for (size_t i = 0; i < arraysize(kBlacklistedSites); ++i) { | |
106 if (net::RegistryControlledDomainService::SameDomainOrHost( | |
107 url, GURL(kBlacklistedSites[i]))) { | |
108 state_ = FAILED; | |
109 break; | |
110 } | |
111 } | |
112 } else { | |
113 state_ = FAILED; | |
114 } | |
115 | |
116 ShowInfobarIfPossible(); | 87 ShowInfobarIfPossible(); |
117 } | 88 } |
118 | 89 |
119 std::wstring AlternateNavURLFetcher::GetMessageTextWithOffset( | 90 std::wstring AlternateNavURLFetcher::GetMessageTextWithOffset( |
120 size_t* link_offset) const { | 91 size_t* link_offset) const { |
121 const std::wstring label = l10n_util::GetStringF( | 92 const std::wstring label = l10n_util::GetStringF( |
122 IDS_ALTERNATE_NAV_URL_VIEW_LABEL, std::wstring(), link_offset); | 93 IDS_ALTERNATE_NAV_URL_VIEW_LABEL, std::wstring(), link_offset); |
123 DCHECK(*link_offset != std::wstring::npos); | 94 DCHECK(*link_offset != std::wstring::npos); |
124 return label; | 95 return label; |
125 } | 96 } |
(...skipping 17 matching lines...) Expand all Loading... |
143 | 114 |
144 // We should always close, even if the navigation did not occur within this | 115 // We should always close, even if the navigation did not occur within this |
145 // TabContents. | 116 // TabContents. |
146 return true; | 117 return true; |
147 } | 118 } |
148 | 119 |
149 void AlternateNavURLFetcher::InfoBarClosed() { | 120 void AlternateNavURLFetcher::InfoBarClosed() { |
150 delete this; | 121 delete this; |
151 } | 122 } |
152 | 123 |
| 124 void AlternateNavURLFetcher::SetStatusFromURLFetch( |
| 125 const GURL& url, |
| 126 const URLRequestStatus& status, |
| 127 int response_code) { |
| 128 if (!status.is_success() || |
| 129 // HTTP 2xx, 401, and 407 all indicate that the target address exists. |
| 130 (((response_code / 100) != 2) && |
| 131 (response_code != 401) && (response_code != 407)) || |
| 132 // Fail if we're redirected to a common location. This is the "automatic |
| 133 // heuristic" version of the explicit blacklist below; see comments there. |
| 134 net::RegistryControlledDomainService::SameDomainOrHost(url, |
| 135 IntranetRedirectDetector::RedirectOrigin())) { |
| 136 state_ = FAILED; |
| 137 return; |
| 138 } |
| 139 |
| 140 // The following TLD+1s are used as destinations by ISPs/DNS providers/etc. |
| 141 // who return provider-controlled pages to arbitrary user navigation attempts. |
| 142 // Because this can result in infobars on large fractions of user searches, we |
| 143 // don't show automatic infobars for these. Note that users can still choose |
| 144 // to explicitly navigate to or search for pages in these domains, and can |
| 145 // still get infobars for cases that wind up on other domains (e.g. legit |
| 146 // intranet sites), we're just trying to avoid erroneously harassing the user |
| 147 // with our own UI prompts. |
| 148 const char* kBlacklistedSites[] = { |
| 149 // NOTE: Use complete URLs, because GURL() doesn't do fixup! |
| 150 "http://comcast.com/", |
| 151 "http://opendns.com/", |
| 152 "http://verizon.net/", |
| 153 }; |
| 154 for (size_t i = 0; i < arraysize(kBlacklistedSites); ++i) { |
| 155 if (net::RegistryControlledDomainService::SameDomainOrHost(url, |
| 156 GURL(kBlacklistedSites[i]))) { |
| 157 state_ = FAILED; |
| 158 return; |
| 159 } |
| 160 } |
| 161 |
| 162 state_ = SUCCEEDED; |
| 163 } |
| 164 |
153 void AlternateNavURLFetcher::ShowInfobarIfPossible() { | 165 void AlternateNavURLFetcher::ShowInfobarIfPossible() { |
154 if (!navigated_to_entry_ || state_ != SUCCEEDED) { | 166 if (!navigated_to_entry_ || state_ != SUCCEEDED) { |
155 if (state_ == FAILED) | 167 if (state_ == FAILED) |
156 delete this; | 168 delete this; |
157 return; | 169 return; |
158 } | 170 } |
159 | 171 |
160 infobar_contents_ = controller_->tab_contents(); | 172 infobar_contents_ = controller_->tab_contents(); |
161 StoreActiveEntryUniqueID(infobar_contents_); | 173 StoreActiveEntryUniqueID(infobar_contents_); |
162 // We will be deleted when the InfoBar is destroyed. (See InfoBarClosed). | 174 // We will be deleted when the InfoBar is destroyed. (See InfoBarClosed). |
163 infobar_contents_->AddInfoBar(this); | 175 infobar_contents_->AddInfoBar(this); |
164 } | 176 } |
OLD | NEW |