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