Chromium Code Reviews| 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/net/net_error_tab_helper.h" | 5 #include "chrome/browser/net/net_error_tab_helper.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
| 10 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
| 11 #include "chrome/browser/io_thread.h" | 11 #include "chrome/browser/io_thread.h" |
| 12 #include "chrome/browser/net/dns_probe_service.h" | 12 #include "chrome/browser/net/dns_probe_service.h" |
| 13 #include "chrome/browser/net/net_error_diagnostics_dialog.h" | 13 #include "chrome/browser/net/net_error_diagnostics_dialog.h" |
| 14 #include "chrome/browser/platform_util.h" | 14 #include "chrome/browser/platform_util.h" |
| 15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 16 #include "chrome/common/localized_error.h" | |
| 16 #include "chrome/common/pref_names.h" | 17 #include "chrome/common/pref_names.h" |
| 17 #include "chrome/common/render_messages.h" | 18 #include "chrome/common/render_messages.h" |
| 18 #include "components/error_page/common/net_error_info.h" | 19 #include "components/error_page/common/net_error_info.h" |
| 19 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
| 21 #include "content/public/browser/navigation_entry.h" | |
| 22 #include "content/public/browser/navigation_handle.h" | |
| 20 #include "content/public/browser/render_frame_host.h" | 23 #include "content/public/browser/render_frame_host.h" |
| 21 #include "ipc/ipc_message_macros.h" | 24 #include "ipc/ipc_message_macros.h" |
| 22 #include "net/base/net_errors.h" | 25 #include "net/base/net_errors.h" |
| 23 #include "url/gurl.h" | 26 #include "url/gurl.h" |
| 24 | 27 |
| 25 #if defined(OS_ANDROID) | 28 #if defined(OS_ANDROID) |
| 26 #include "chrome/browser/android/tab_android.h" | 29 #include "chrome/browser/android/tab_android.h" |
| 27 #endif | 30 #endif // defined(OS_ANDROID) |
| 28 | 31 |
| 29 using content::BrowserContext; | 32 using content::BrowserContext; |
| 30 using content::BrowserThread; | 33 using content::BrowserThread; |
| 31 using content::WebContents; | 34 using content::WebContents; |
| 32 using content::WebContentsObserver; | 35 using content::WebContentsObserver; |
| 33 using error_page::DnsProbeStatus; | 36 using error_page::DnsProbeStatus; |
| 34 using error_page::DnsProbeStatusToString; | 37 using error_page::DnsProbeStatusToString; |
| 35 using ui::PageTransition; | 38 using ui::PageTransition; |
| 36 | 39 |
| 37 DEFINE_WEB_CONTENTS_USER_DATA_KEY(chrome_browser_net::NetErrorTabHelper); | 40 DEFINE_WEB_CONTENTS_USER_DATA_KEY(chrome_browser_net::NetErrorTabHelper); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 117 bool is_error_page, | 120 bool is_error_page, |
| 118 bool is_iframe_srcdoc) { | 121 bool is_iframe_srcdoc) { |
| 119 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 122 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 120 | 123 |
| 121 if (render_frame_host->GetParent()) | 124 if (render_frame_host->GetParent()) |
| 122 return; | 125 return; |
| 123 | 126 |
| 124 is_error_page_ = is_error_page; | 127 is_error_page_ = is_error_page; |
| 125 | 128 |
| 126 #if defined(OS_ANDROID) | 129 #if defined(OS_ANDROID) |
| 127 SetHasOfflinePages(render_frame_host); | 130 SetOfflinePageInfo(render_frame_host); |
| 128 #endif | 131 #endif // defined(OS_ANDROID) |
| 129 } | 132 } |
| 130 | 133 |
| 131 void NetErrorTabHelper::DidCommitProvisionalLoadForFrame( | 134 void NetErrorTabHelper::DidCommitProvisionalLoadForFrame( |
| 132 content::RenderFrameHost* render_frame_host, | 135 content::RenderFrameHost* render_frame_host, |
| 133 const GURL& url, | 136 const GURL& url, |
| 134 PageTransition transition_type) { | 137 PageTransition transition_type) { |
| 135 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 138 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 136 | 139 |
| 137 if (render_frame_host->GetParent()) | 140 if (render_frame_host->GetParent()) |
| 138 return; | 141 return; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 170 | 173 |
| 171 bool NetErrorTabHelper::OnMessageReceived( | 174 bool NetErrorTabHelper::OnMessageReceived( |
| 172 const IPC::Message& message, | 175 const IPC::Message& message, |
| 173 content::RenderFrameHost* render_frame_host) { | 176 content::RenderFrameHost* render_frame_host) { |
| 174 bool handled = true; | 177 bool handled = true; |
| 175 IPC_BEGIN_MESSAGE_MAP(NetErrorTabHelper, message) | 178 IPC_BEGIN_MESSAGE_MAP(NetErrorTabHelper, message) |
| 176 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_RunNetworkDiagnostics, | 179 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_RunNetworkDiagnostics, |
| 177 RunNetworkDiagnostics) | 180 RunNetworkDiagnostics) |
| 178 #if defined(OS_ANDROID) | 181 #if defined(OS_ANDROID) |
| 179 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_ShowOfflinePages, ShowOfflinePages) | 182 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_ShowOfflinePages, ShowOfflinePages) |
| 180 #endif | 183 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_LoadOfflineCopy, LoadOfflineCopy) |
| 184 #endif // defined(OS_ANDROID) | |
| 181 IPC_MESSAGE_UNHANDLED(handled = false) | 185 IPC_MESSAGE_UNHANDLED(handled = false) |
| 182 IPC_END_MESSAGE_MAP() | 186 IPC_END_MESSAGE_MAP() |
| 183 | 187 |
| 184 return handled; | 188 return handled; |
| 185 } | 189 } |
| 186 | 190 |
| 187 NetErrorTabHelper::NetErrorTabHelper(WebContents* contents) | 191 NetErrorTabHelper::NetErrorTabHelper(WebContents* contents) |
| 188 : WebContentsObserver(contents), | 192 : WebContentsObserver(contents), |
| 189 is_error_page_(false), | 193 is_error_page_(false), |
| 190 dns_error_active_(false), | 194 dns_error_active_(false), |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 279 // Sanitize URL prior to running diagnostics on it. | 283 // Sanitize URL prior to running diagnostics on it. |
| 280 RunNetworkDiagnosticsHelper(url.GetOrigin().spec()); | 284 RunNetworkDiagnosticsHelper(url.GetOrigin().spec()); |
| 281 } | 285 } |
| 282 | 286 |
| 283 void NetErrorTabHelper::RunNetworkDiagnosticsHelper( | 287 void NetErrorTabHelper::RunNetworkDiagnosticsHelper( |
| 284 const std::string& sanitized_url) { | 288 const std::string& sanitized_url) { |
| 285 ShowNetworkDiagnosticsDialog(web_contents(), sanitized_url); | 289 ShowNetworkDiagnosticsDialog(web_contents(), sanitized_url); |
| 286 } | 290 } |
| 287 | 291 |
| 288 #if defined(OS_ANDROID) | 292 #if defined(OS_ANDROID) |
| 289 void NetErrorTabHelper::SetHasOfflinePages( | 293 void NetErrorTabHelper::SetOfflinePageInfo( |
| 290 content::RenderFrameHost* render_frame_host) { | 294 content::RenderFrameHost* render_frame_host) { |
| 291 DCHECK(web_contents()); | 295 DCHECK(web_contents()); |
| 296 std::vector<GURL> offline_page_urls; | |
| 292 TabAndroid* tab = TabAndroid::FromWebContents(web_contents()); | 297 TabAndroid* tab = TabAndroid::FromWebContents(web_contents()); |
| 293 bool has_offline_pages = tab && tab->HasOfflinePages(); | 298 if (tab) |
| 299 tab->GetAllOfflinePageURLS(&offline_page_urls); | |
| 294 render_frame_host->Send( | 300 render_frame_host->Send( |
| 295 new ChromeViewMsg_SetHasOfflinePages( | 301 new ChromeViewMsg_SetOfflinePageInfo( |
| 296 render_frame_host->GetRoutingID(), | 302 render_frame_host->GetRoutingID(), offline_page_urls)); |
| 297 has_offline_pages)); | |
| 298 } | 303 } |
| 299 | 304 |
| 300 void NetErrorTabHelper::ShowOfflinePages() { | 305 void NetErrorTabHelper::ShowOfflinePages() { |
| 306 // Makes sure that this is coming from from an error page. | |
| 307 if (!IsFromErrorPage()) | |
| 308 return; | |
| 309 | |
| 301 DCHECK(web_contents()); | 310 DCHECK(web_contents()); |
| 302 TabAndroid* tab = TabAndroid::FromWebContents(web_contents()); | 311 TabAndroid* tab = TabAndroid::FromWebContents(web_contents()); |
| 303 if (tab) | 312 if (tab) |
| 304 tab->ShowOfflinePages(); | 313 tab->ShowOfflinePages(); |
| 305 } | 314 } |
| 306 #endif | 315 |
| 316 void NetErrorTabHelper::LoadOfflineCopy(const GURL& url) { | |
| 317 // Makes sure that this is coming from from an error page. | |
| 318 if (!IsFromErrorPage()) | |
| 319 return; | |
| 320 | |
| 321 GURL validated_url(url); | |
| 322 if (!validated_url.is_valid()) | |
| 323 return; | |
| 324 DCHECK(web_contents()); | |
| 325 if (validated_url != web_contents()->GetVisibleURL()) | |
|
nasko
2015/11/19 15:11:41
Why use GetVisibleURL? This is inconsistent with t
mmenke
2015/11/19 17:39:12
I was concerned about allowing any page (Even one
nasko
2015/11/19 17:52:53
A page that has not committed should not be able t
jianli
2015/11/19 23:28:08
We do not allow any page to navigate to any offlin
| |
| 326 return; | |
| 327 | |
| 328 TabAndroid* tab = TabAndroid::FromWebContents(web_contents()); | |
| 329 if (tab) | |
| 330 tab->LoadOfflineCopy(url); | |
| 331 } | |
| 332 | |
| 333 bool NetErrorTabHelper::IsFromErrorPage() const { | |
| 334 content::NavigationEntry* entry = | |
| 335 web_contents()->GetController().GetLastCommittedEntry(); | |
| 336 if (!entry) | |
| 337 return false; | |
| 338 return entry->GetPageType() == content::PAGE_TYPE_ERROR; | |
| 339 } | |
| 340 #endif // defined(OS_ANDROID) | |
| 307 | 341 |
| 308 } // namespace chrome_browser_net | 342 } // namespace chrome_browser_net |
| OLD | NEW |