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/pref_names.h" | 16 #include "chrome/common/pref_names.h" |
17 #include "chrome/common/render_messages.h" | 17 #include "chrome/common/render_messages.h" |
18 #include "components/error_page/common/net_error_info.h" | 18 #include "components/error_page/common/net_error_info.h" |
19 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
20 #include "content/public/browser/render_frame_host.h" | 20 #include "content/public/browser/render_frame_host.h" |
21 #include "ipc/ipc_message_macros.h" | 21 #include "ipc/ipc_message_macros.h" |
22 #include "net/base/net_errors.h" | 22 #include "net/base/net_errors.h" |
23 #include "url/gurl.h" | 23 #include "url/gurl.h" |
24 | 24 |
| 25 #if defined(OS_ANDROID) |
| 26 #include "chrome/browser/android/tab_android.h" |
| 27 #endif |
| 28 |
25 using content::BrowserContext; | 29 using content::BrowserContext; |
26 using content::BrowserThread; | 30 using content::BrowserThread; |
27 using content::WebContents; | 31 using content::WebContents; |
28 using content::WebContentsObserver; | 32 using content::WebContentsObserver; |
29 using error_page::DnsProbeStatus; | 33 using error_page::DnsProbeStatus; |
30 using error_page::DnsProbeStatusToString; | 34 using error_page::DnsProbeStatusToString; |
31 using ui::PageTransition; | 35 using ui::PageTransition; |
32 | 36 |
33 DEFINE_WEB_CONTENTS_USER_DATA_KEY(chrome_browser_net::NetErrorTabHelper); | 37 DEFINE_WEB_CONTENTS_USER_DATA_KEY(chrome_browser_net::NetErrorTabHelper); |
34 | 38 |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 content::RenderFrameHost* render_frame_host, | 115 content::RenderFrameHost* render_frame_host, |
112 const GURL& validated_url, | 116 const GURL& validated_url, |
113 bool is_error_page, | 117 bool is_error_page, |
114 bool is_iframe_srcdoc) { | 118 bool is_iframe_srcdoc) { |
115 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 119 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
116 | 120 |
117 if (render_frame_host->GetParent()) | 121 if (render_frame_host->GetParent()) |
118 return; | 122 return; |
119 | 123 |
120 is_error_page_ = is_error_page; | 124 is_error_page_ = is_error_page; |
| 125 |
| 126 #if defined(OS_ANDROID) |
| 127 SetHasOfflinePages(render_frame_host); |
| 128 #endif |
121 } | 129 } |
122 | 130 |
123 void NetErrorTabHelper::DidCommitProvisionalLoadForFrame( | 131 void NetErrorTabHelper::DidCommitProvisionalLoadForFrame( |
124 content::RenderFrameHost* render_frame_host, | 132 content::RenderFrameHost* render_frame_host, |
125 const GURL& url, | 133 const GURL& url, |
126 PageTransition transition_type) { | 134 PageTransition transition_type) { |
127 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 135 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
128 | 136 |
129 if (render_frame_host->GetParent()) | 137 if (render_frame_host->GetParent()) |
130 return; | 138 return; |
(...skipping 29 matching lines...) Expand all Loading... |
160 } | 168 } |
161 } | 169 } |
162 | 170 |
163 bool NetErrorTabHelper::OnMessageReceived( | 171 bool NetErrorTabHelper::OnMessageReceived( |
164 const IPC::Message& message, | 172 const IPC::Message& message, |
165 content::RenderFrameHost* render_frame_host) { | 173 content::RenderFrameHost* render_frame_host) { |
166 bool handled = true; | 174 bool handled = true; |
167 IPC_BEGIN_MESSAGE_MAP(NetErrorTabHelper, message) | 175 IPC_BEGIN_MESSAGE_MAP(NetErrorTabHelper, message) |
168 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_RunNetworkDiagnostics, | 176 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_RunNetworkDiagnostics, |
169 RunNetworkDiagnostics) | 177 RunNetworkDiagnostics) |
| 178 #if defined(OS_ANDROID) |
| 179 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_ShowOfflinePages, ShowOfflinePages) |
| 180 #endif |
170 IPC_MESSAGE_UNHANDLED(handled = false) | 181 IPC_MESSAGE_UNHANDLED(handled = false) |
171 IPC_END_MESSAGE_MAP() | 182 IPC_END_MESSAGE_MAP() |
172 | 183 |
173 return handled; | 184 return handled; |
174 } | 185 } |
175 | 186 |
176 NetErrorTabHelper::NetErrorTabHelper(WebContents* contents) | 187 NetErrorTabHelper::NetErrorTabHelper(WebContents* contents) |
177 : WebContentsObserver(contents), | 188 : WebContentsObserver(contents), |
178 is_error_page_(false), | 189 is_error_page_(false), |
179 dns_error_active_(false), | 190 dns_error_active_(false), |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 return; | 278 return; |
268 // Sanitize URL prior to running diagnostics on it. | 279 // Sanitize URL prior to running diagnostics on it. |
269 RunNetworkDiagnosticsHelper(url.GetOrigin().spec()); | 280 RunNetworkDiagnosticsHelper(url.GetOrigin().spec()); |
270 } | 281 } |
271 | 282 |
272 void NetErrorTabHelper::RunNetworkDiagnosticsHelper( | 283 void NetErrorTabHelper::RunNetworkDiagnosticsHelper( |
273 const std::string& sanitized_url) { | 284 const std::string& sanitized_url) { |
274 ShowNetworkDiagnosticsDialog(web_contents(), sanitized_url); | 285 ShowNetworkDiagnosticsDialog(web_contents(), sanitized_url); |
275 } | 286 } |
276 | 287 |
| 288 #if defined(OS_ANDROID) |
| 289 void NetErrorTabHelper::SetHasOfflinePages( |
| 290 content::RenderFrameHost* render_frame_host) { |
| 291 DCHECK(web_contents()); |
| 292 TabAndroid* tab = TabAndroid::FromWebContents(web_contents()); |
| 293 bool has_offline_pages = tab && tab->HasOfflinePages(); |
| 294 render_frame_host->Send( |
| 295 new ChromeViewMsg_SetHasOfflinePages( |
| 296 render_frame_host->GetRoutingID(), |
| 297 has_offline_pages)); |
| 298 } |
| 299 |
| 300 void NetErrorTabHelper::ShowOfflinePages() { |
| 301 DCHECK(web_contents()); |
| 302 TabAndroid* tab = TabAndroid::FromWebContents(web_contents()); |
| 303 if (tab) |
| 304 tab->ShowOfflinePages(); |
| 305 } |
| 306 #endif |
| 307 |
277 } // namespace chrome_browser_net | 308 } // namespace chrome_browser_net |
OLD | NEW |