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 #ifndef CHROME_BROWSER_NET_NET_ERROR_TAB_HELPER_H_ | 5 #ifndef CHROME_BROWSER_NET_NET_ERROR_TAB_HELPER_H_ |
6 #define CHROME_BROWSER_NET_NET_ERROR_TAB_HELPER_H_ | 6 #define CHROME_BROWSER_NET_NET_ERROR_TAB_HELPER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
14 #include "chrome/browser/net/dns_probe_service.h" | 14 #include "chrome/browser/net/dns_probe_service.h" |
15 #include "chrome/common/features.h" | 15 #include "chrome/common/features.h" |
| 16 #include "chrome/common/network_diagnostics.mojom.h" |
16 #include "components/error_page/common/net_error_info.h" | 17 #include "components/error_page/common/net_error_info.h" |
17 #include "components/prefs/pref_member.h" | 18 #include "components/prefs/pref_member.h" |
| 19 #include "content/public/browser/remote_frame_interface.h" |
| 20 #include "content/public/browser/web_contents_frame_interface_binding.h" |
18 #include "content/public/browser/web_contents_observer.h" | 21 #include "content/public/browser/web_contents_observer.h" |
19 #include "content/public/browser/web_contents_user_data.h" | 22 #include "content/public/browser/web_contents_user_data.h" |
20 | 23 |
| 24 namespace content { |
| 25 class WebContentsInterfaceRegistry; |
| 26 } |
| 27 |
21 namespace chrome_browser_net { | 28 namespace chrome_browser_net { |
22 | 29 |
23 // A TabHelper that monitors loads for certain types of network errors and | 30 // A TabHelper that monitors loads for certain types of network errors and |
24 // does interesting things with them. Currently, starts DNS probes using the | 31 // does interesting things with them. Currently, starts DNS probes using the |
25 // DnsProbeService whenever a page fails to load with a DNS-related error. | 32 // DnsProbeService whenever a page fails to load with a DNS-related error. |
26 class NetErrorTabHelper | 33 class NetErrorTabHelper |
27 : public content::WebContentsObserver, | 34 : public content::WebContentsObserver, |
28 public content::WebContentsUserData<NetErrorTabHelper> { | 35 public content::WebContentsUserData<NetErrorTabHelper>, |
| 36 public mojom::NetworkDiagnostics { |
29 public: | 37 public: |
30 enum TestingState { | 38 enum TestingState { |
31 TESTING_DEFAULT, | 39 TESTING_DEFAULT, |
32 TESTING_FORCE_DISABLED, | 40 TESTING_FORCE_DISABLED, |
33 TESTING_FORCE_ENABLED | 41 TESTING_FORCE_ENABLED |
34 }; | 42 }; |
35 | 43 |
36 typedef base::Callback<void(error_page::DnsProbeStatus)> | 44 typedef base::Callback<void(error_page::DnsProbeStatus)> |
37 DnsProbeStatusSnoopCallback; | 45 DnsProbeStatusSnoopCallback; |
38 | 46 |
(...skipping 29 matching lines...) Expand all Loading... |
68 | 76 |
69 void DidFailProvisionalLoad(content::RenderFrameHost* render_frame_host, | 77 void DidFailProvisionalLoad(content::RenderFrameHost* render_frame_host, |
70 const GURL& validated_url, | 78 const GURL& validated_url, |
71 int error_code, | 79 int error_code, |
72 const base::string16& error_description, | 80 const base::string16& error_description, |
73 bool was_ignored_by_handler) override; | 81 bool was_ignored_by_handler) override; |
74 | 82 |
75 bool OnMessageReceived(const IPC::Message& message, | 83 bool OnMessageReceived(const IPC::Message& message, |
76 content::RenderFrameHost* render_frame_host) override; | 84 content::RenderFrameHost* render_frame_host) override; |
77 | 85 |
78 | |
79 protected: | 86 protected: |
80 // |contents| is the WebContents of the tab this NetErrorTabHelper is | 87 // |contents| is the WebContents of the tab this NetErrorTabHelper is |
81 // attached to. | 88 // attached to. |
82 explicit NetErrorTabHelper(content::WebContents* contents); | 89 explicit NetErrorTabHelper(content::WebContents* contents); |
83 virtual void StartDnsProbe(); | 90 virtual void StartDnsProbe(); |
84 virtual void SendInfo(); | 91 virtual void SendInfo(); |
85 void OnDnsProbeFinished(error_page::DnsProbeStatus result); | 92 void OnDnsProbeFinished(error_page::DnsProbeStatus result); |
86 | 93 |
87 error_page::DnsProbeStatus dns_probe_status() const { | 94 error_page::DnsProbeStatus dns_probe_status() const { |
88 return dns_probe_status_; | 95 return dns_probe_status_; |
89 } | 96 } |
90 | 97 |
91 private: | 98 private: |
92 friend class content::WebContentsUserData<NetErrorTabHelper>; | 99 friend class content::WebContentsUserData<NetErrorTabHelper>; |
93 | 100 |
94 void OnMainFrameDnsError(); | 101 void OnMainFrameDnsError(); |
95 | 102 |
96 void InitializePref(content::WebContents* contents); | 103 void InitializePref(content::WebContents* contents); |
97 bool ProbesAllowed() const; | 104 bool ProbesAllowed() const; |
98 | 105 |
99 // Sanitizes |url| and shows a dialog for it. | 106 // mojom::NetworkDiagnostics: |
100 void RunNetworkDiagnostics(const GURL& url); | 107 void RunNetworkDiagnostics(const GURL& url) override; |
101 | 108 |
102 // Shows the diagnostics dialog after its been sanitized, virtual for | 109 // Shows the diagnostics dialog after its been sanitized, virtual for |
103 // testing. | 110 // testing. |
104 virtual void RunNetworkDiagnosticsHelper(const std::string& sanitized_url); | 111 virtual void RunNetworkDiagnosticsHelper(const std::string& sanitized_url); |
105 | 112 |
106 // Relates to offline pages handling. | 113 // Relates to offline pages handling. |
107 #if BUILDFLAG(ANDROID_JAVA_UI) | 114 #if BUILDFLAG(ANDROID_JAVA_UI) |
108 void UpdateHasOfflinePages(content::RenderFrameHost* render_frame_host); | 115 void UpdateHasOfflinePages(content::RenderFrameHost* render_frame_host); |
109 void SetHasOfflinePages(int frame_tree_node_id, bool has_offline_pages); | 116 void SetHasOfflinePages(int frame_tree_node_id, bool has_offline_pages); |
110 void ShowOfflinePages(); | 117 void ShowOfflinePages(); |
111 bool IsFromErrorPage() const; | 118 bool IsFromErrorPage() const; |
112 #endif // BUILDFLAG(ANDROID_JAVA_UI) | 119 #endif // BUILDFLAG(ANDROID_JAVA_UI) |
113 | 120 |
| 121 content::WebContentsFrameInterfaceBinding<mojom::NetworkDiagnostics> |
| 122 network_diagnostics_binding_; |
| 123 content::RemoteFrameInterface<mojom::NetworkDiagnosticsClient> |
| 124 remote_network_diagnostics_client_; |
| 125 |
114 // True if the last provisional load that started was for an error page. | 126 // True if the last provisional load that started was for an error page. |
115 bool is_error_page_; | 127 bool is_error_page_; |
116 | 128 |
117 // True if the helper has seen a main frame page load fail with a DNS error, | 129 // True if the helper has seen a main frame page load fail with a DNS error, |
118 // but has not yet seen a new page commit successfully afterwards. | 130 // but has not yet seen a new page commit successfully afterwards. |
119 bool dns_error_active_; | 131 bool dns_error_active_; |
120 | 132 |
121 // True if the helper has seen an error page commit while |dns_error_active_| | 133 // True if the helper has seen an error page commit while |dns_error_active_| |
122 // is true. (This should never be true if |dns_error_active_| is false.) | 134 // is true. (This should never be true if |dns_error_active_| is false.) |
123 bool dns_error_page_committed_; | 135 bool dns_error_page_committed_; |
(...skipping 11 matching lines...) Expand all Loading... |
135 BooleanPrefMember resolve_errors_with_web_service_; | 147 BooleanPrefMember resolve_errors_with_web_service_; |
136 | 148 |
137 base::WeakPtrFactory<NetErrorTabHelper> weak_factory_; | 149 base::WeakPtrFactory<NetErrorTabHelper> weak_factory_; |
138 | 150 |
139 DISALLOW_COPY_AND_ASSIGN(NetErrorTabHelper); | 151 DISALLOW_COPY_AND_ASSIGN(NetErrorTabHelper); |
140 }; | 152 }; |
141 | 153 |
142 } // namespace chrome_browser_net | 154 } // namespace chrome_browser_net |
143 | 155 |
144 #endif // CHROME_BROWSER_NET_NET_ERROR_TAB_HELPER_H_ | 156 #endif // CHROME_BROWSER_NET_NET_ERROR_TAB_HELPER_H_ |
OLD | NEW |