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" |
| 20 #include "content/public/browser/render_frame_host.h" | 21 #include "content/public/browser/render_frame_host.h" |
| 21 #include "ipc/ipc_message_macros.h" | 22 #include "ipc/ipc_message_macros.h" |
| 22 #include "net/base/net_errors.h" | 23 #include "net/base/net_errors.h" |
| 23 #include "url/gurl.h" | 24 #include "url/gurl.h" |
| 24 | 25 |
| 25 #if defined(OS_ANDROID) | 26 #if defined(OS_ANDROID) |
| 26 #include "chrome/browser/android/tab_android.h" | 27 #include "chrome/browser/android/tab_android.h" |
| 27 #endif | 28 #endif |
| 28 | 29 |
| 29 using content::BrowserContext; | 30 using content::BrowserContext; |
| 30 using content::BrowserThread; | 31 using content::BrowserThread; |
| 31 using content::WebContents; | 32 using content::WebContents; |
| 32 using content::WebContentsObserver; | 33 using content::WebContentsObserver; |
| 33 using error_page::DnsProbeStatus; | 34 using error_page::DnsProbeStatus; |
| 34 using error_page::DnsProbeStatusToString; | 35 using error_page::DnsProbeStatusToString; |
| 36 using error_page::OfflinePageStatus; | |
| 35 using ui::PageTransition; | 37 using ui::PageTransition; |
| 36 | 38 |
| 37 DEFINE_WEB_CONTENTS_USER_DATA_KEY(chrome_browser_net::NetErrorTabHelper); | 39 DEFINE_WEB_CONTENTS_USER_DATA_KEY(chrome_browser_net::NetErrorTabHelper); |
| 38 | 40 |
| 39 namespace chrome_browser_net { | 41 namespace chrome_browser_net { |
| 40 | 42 |
| 41 namespace { | 43 namespace { |
| 42 | 44 |
| 43 static NetErrorTabHelper::TestingState testing_state_ = | 45 static NetErrorTabHelper::TestingState testing_state_ = |
| 44 NetErrorTabHelper::TESTING_DEFAULT; | 46 NetErrorTabHelper::TESTING_DEFAULT; |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 117 bool is_error_page, | 119 bool is_error_page, |
| 118 bool is_iframe_srcdoc) { | 120 bool is_iframe_srcdoc) { |
| 119 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 121 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 120 | 122 |
| 121 if (render_frame_host->GetParent()) | 123 if (render_frame_host->GetParent()) |
| 122 return; | 124 return; |
| 123 | 125 |
| 124 is_error_page_ = is_error_page; | 126 is_error_page_ = is_error_page; |
| 125 | 127 |
| 126 #if defined(OS_ANDROID) | 128 #if defined(OS_ANDROID) |
| 127 SetHasOfflinePages(render_frame_host); | 129 SetOfflinePageInfo(render_frame_host); |
| 128 #endif | 130 #endif |
| 129 } | 131 } |
| 130 | 132 |
| 131 void NetErrorTabHelper::DidCommitProvisionalLoadForFrame( | 133 void NetErrorTabHelper::DidCommitProvisionalLoadForFrame( |
| 132 content::RenderFrameHost* render_frame_host, | 134 content::RenderFrameHost* render_frame_host, |
| 133 const GURL& url, | 135 const GURL& url, |
| 134 PageTransition transition_type) { | 136 PageTransition transition_type) { |
| 135 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 137 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 136 | 138 |
| 137 if (render_frame_host->GetParent()) | 139 if (render_frame_host->GetParent()) |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 170 | 172 |
| 171 bool NetErrorTabHelper::OnMessageReceived( | 173 bool NetErrorTabHelper::OnMessageReceived( |
| 172 const IPC::Message& message, | 174 const IPC::Message& message, |
| 173 content::RenderFrameHost* render_frame_host) { | 175 content::RenderFrameHost* render_frame_host) { |
| 174 bool handled = true; | 176 bool handled = true; |
| 175 IPC_BEGIN_MESSAGE_MAP(NetErrorTabHelper, message) | 177 IPC_BEGIN_MESSAGE_MAP(NetErrorTabHelper, message) |
| 176 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_RunNetworkDiagnostics, | 178 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_RunNetworkDiagnostics, |
| 177 RunNetworkDiagnostics) | 179 RunNetworkDiagnostics) |
| 178 #if defined(OS_ANDROID) | 180 #if defined(OS_ANDROID) |
| 179 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_ShowOfflinePages, ShowOfflinePages) | 181 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_ShowOfflinePages, ShowOfflinePages) |
| 182 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_LoadOfflineCopy, LoadOfflineCopy) | |
| 180 #endif | 183 #endif |
| 181 IPC_MESSAGE_UNHANDLED(handled = false) | 184 IPC_MESSAGE_UNHANDLED(handled = false) |
| 182 IPC_END_MESSAGE_MAP() | 185 IPC_END_MESSAGE_MAP() |
| 183 | 186 |
| 184 return handled; | 187 return handled; |
| 185 } | 188 } |
| 186 | 189 |
| 187 NetErrorTabHelper::NetErrorTabHelper(WebContents* contents) | 190 NetErrorTabHelper::NetErrorTabHelper(WebContents* contents) |
| 188 : WebContentsObserver(contents), | 191 : WebContentsObserver(contents), |
| 189 is_error_page_(false), | 192 is_error_page_(false), |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 279 // Sanitize URL prior to running diagnostics on it. | 282 // Sanitize URL prior to running diagnostics on it. |
| 280 RunNetworkDiagnosticsHelper(url.GetOrigin().spec()); | 283 RunNetworkDiagnosticsHelper(url.GetOrigin().spec()); |
| 281 } | 284 } |
| 282 | 285 |
| 283 void NetErrorTabHelper::RunNetworkDiagnosticsHelper( | 286 void NetErrorTabHelper::RunNetworkDiagnosticsHelper( |
| 284 const std::string& sanitized_url) { | 287 const std::string& sanitized_url) { |
| 285 ShowNetworkDiagnosticsDialog(web_contents(), sanitized_url); | 288 ShowNetworkDiagnosticsDialog(web_contents(), sanitized_url); |
| 286 } | 289 } |
| 287 | 290 |
| 288 #if defined(OS_ANDROID) | 291 #if defined(OS_ANDROID) |
| 289 void NetErrorTabHelper::SetHasOfflinePages( | 292 void NetErrorTabHelper::SetOfflinePageInfo( |
| 290 content::RenderFrameHost* render_frame_host) { | 293 content::RenderFrameHost* render_frame_host) { |
| 291 DCHECK(web_contents()); | 294 DCHECK(web_contents()); |
| 295 OfflinePageStatus status = OfflinePageStatus::NONE; | |
| 292 TabAndroid* tab = TabAndroid::FromWebContents(web_contents()); | 296 TabAndroid* tab = TabAndroid::FromWebContents(web_contents()); |
| 293 bool has_offline_pages = tab && tab->HasOfflinePages(); | 297 if (tab && tab->HasOfflinePages()) { |
| 298 status = tab->HasOfflineCopyForCurrentPage() ? | |
| 299 OfflinePageStatus::HAS_PAGE_COPY : | |
| 300 OfflinePageStatus::HAS_OTHER_PAGES_COPIES; | |
| 301 } | |
| 294 render_frame_host->Send( | 302 render_frame_host->Send( |
| 295 new ChromeViewMsg_SetHasOfflinePages( | 303 new ChromeViewMsg_SetOfflinePageInfo( |
| 296 render_frame_host->GetRoutingID(), | 304 render_frame_host->GetRoutingID(), status)); |
| 297 has_offline_pages)); | |
| 298 } | 305 } |
| 299 | 306 |
| 300 void NetErrorTabHelper::ShowOfflinePages() { | 307 void NetErrorTabHelper::ShowOfflinePages() { |
| 301 DCHECK(web_contents()); | 308 DCHECK(web_contents()); |
| 302 TabAndroid* tab = TabAndroid::FromWebContents(web_contents()); | 309 TabAndroid* tab = TabAndroid::FromWebContents(web_contents()); |
| 303 if (tab) | 310 if (tab) |
| 304 tab->ShowOfflinePages(); | 311 tab->ShowOfflinePages(); |
| 305 } | 312 } |
| 306 #endif | 313 |
| 314 void NetErrorTabHelper::LoadOfflineCopy(const GURL& url) { | |
| 315 GURL validated_url(url); | |
| 316 if (!validated_url.is_valid()) | |
| 317 return; | |
|
mmenke
2015/11/17 21:02:15
Should we also compare the URL with the web_conten
jianli
2015/11/19 02:23:46
Done.
| |
| 318 | |
| 319 DCHECK(web_contents()); | |
| 320 TabAndroid* tab = TabAndroid::FromWebContents(web_contents()); | |
| 321 if (tab) | |
| 322 tab->LoadOfflineCopy(url); | |
| 323 } | |
| 324 #endif // defined(OS_ANDROID) | |
| 307 | 325 |
| 308 } // namespace chrome_browser_net | 326 } // namespace chrome_browser_net |
| OLD | NEW |