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 SetHasOfflinePages(render_frame_host); | |
121 } | 127 } |
122 | 128 |
123 void NetErrorTabHelper::DidCommitProvisionalLoadForFrame( | 129 void NetErrorTabHelper::DidCommitProvisionalLoadForFrame( |
124 content::RenderFrameHost* render_frame_host, | 130 content::RenderFrameHost* render_frame_host, |
125 const GURL& url, | 131 const GURL& url, |
126 PageTransition transition_type) { | 132 PageTransition transition_type) { |
127 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 133 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
128 | 134 |
129 if (render_frame_host->GetParent()) | 135 if (render_frame_host->GetParent()) |
130 return; | 136 return; |
(...skipping 29 matching lines...) Expand all Loading... | |
160 } | 166 } |
161 } | 167 } |
162 | 168 |
163 bool NetErrorTabHelper::OnMessageReceived( | 169 bool NetErrorTabHelper::OnMessageReceived( |
164 const IPC::Message& message, | 170 const IPC::Message& message, |
165 content::RenderFrameHost* render_frame_host) { | 171 content::RenderFrameHost* render_frame_host) { |
166 bool handled = true; | 172 bool handled = true; |
167 IPC_BEGIN_MESSAGE_MAP(NetErrorTabHelper, message) | 173 IPC_BEGIN_MESSAGE_MAP(NetErrorTabHelper, message) |
168 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_RunNetworkDiagnostics, | 174 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_RunNetworkDiagnostics, |
169 RunNetworkDiagnostics) | 175 RunNetworkDiagnostics) |
176 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_ShowOfflinePages, ShowOfflinePages) | |
170 IPC_MESSAGE_UNHANDLED(handled = false) | 177 IPC_MESSAGE_UNHANDLED(handled = false) |
171 IPC_END_MESSAGE_MAP() | 178 IPC_END_MESSAGE_MAP() |
172 | 179 |
173 return handled; | 180 return handled; |
174 } | 181 } |
175 | 182 |
176 NetErrorTabHelper::NetErrorTabHelper(WebContents* contents) | 183 NetErrorTabHelper::NetErrorTabHelper(WebContents* contents) |
177 : WebContentsObserver(contents), | 184 : WebContentsObserver(contents), |
178 is_error_page_(false), | 185 is_error_page_(false), |
179 dns_error_active_(false), | 186 dns_error_active_(false), |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
267 return; | 274 return; |
268 // Sanitize URL prior to running diagnostics on it. | 275 // Sanitize URL prior to running diagnostics on it. |
269 RunNetworkDiagnosticsHelper(url.GetOrigin().spec()); | 276 RunNetworkDiagnosticsHelper(url.GetOrigin().spec()); |
270 } | 277 } |
271 | 278 |
272 void NetErrorTabHelper::RunNetworkDiagnosticsHelper( | 279 void NetErrorTabHelper::RunNetworkDiagnosticsHelper( |
273 const std::string& sanitized_url) { | 280 const std::string& sanitized_url) { |
274 ShowNetworkDiagnosticsDialog(web_contents(), sanitized_url); | 281 ShowNetworkDiagnosticsDialog(web_contents(), sanitized_url); |
275 } | 282 } |
276 | 283 |
284 void NetErrorTabHelper::SetHasOfflinePages( | |
newt (away)
2015/11/09 22:15:13
Does this get called on every page load, or only w
jianli
2015/11/09 23:08:56
Good catch. Added is_error_page_ check to bail out
mmenke
2015/11/09 23:11:47
Hrm...Does that actually work? Won't the message
jianli
2015/11/10 00:14:26
You're right. |is_error_page_| is only set when th
| |
285 content::RenderFrameHost* render_frame_host) { | |
286 #if defined(OS_ANDROID) | |
287 TabAndroid* tab = | |
288 web_contents() ? TabAndroid::FromWebContents(web_contents()) : nullptr; | |
289 bool has_offline_pages = (tab && tab->HasOfflinePages()); | |
290 render_frame_host->Send( | |
291 new ChromeViewMsg_SetHasOfflinePages( | |
292 render_frame_host->GetRoutingID(), | |
293 has_offline_pages)); | |
294 #endif | |
295 } | |
296 | |
297 void NetErrorTabHelper::ShowOfflinePages() { | |
298 #if defined(OS_ANDROID) | |
299 TabAndroid* tab = | |
300 web_contents() ? TabAndroid::FromWebContents(web_contents()) : nullptr; | |
301 if (tab) | |
302 tab->ShowOfflinePages(); | |
303 #endif | |
304 } | |
305 | |
277 } // namespace chrome_browser_net | 306 } // namespace chrome_browser_net |
OLD | NEW |