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