| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 COMPONENTS_SUBRESOURCE_FILTER_CONTENT_BROWSER_CONTENT_SUBRESOURCE_FILTER
_DRIVER_FACTORY_H_ | 5 #ifndef COMPONENTS_SUBRESOURCE_FILTER_CONTENT_BROWSER_CONTENT_SUBRESOURCE_FILTER
_DRIVER_FACTORY_H_ |
| 6 #define COMPONENTS_SUBRESOURCE_FILTER_CONTENT_BROWSER_CONTENT_SUBRESOURCE_FILTER
_DRIVER_FACTORY_H_ | 6 #define COMPONENTS_SUBRESOURCE_FILTER_CONTENT_BROWSER_CONTENT_SUBRESOURCE_FILTER
_DRIVER_FACTORY_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 class WebContents; | 24 class WebContents; |
| 25 class RenderFrameHost; | 25 class RenderFrameHost; |
| 26 } // namespace content | 26 } // namespace content |
| 27 | 27 |
| 28 namespace safe_browsing { | 28 namespace safe_browsing { |
| 29 class SafeBrowsingServiceTest; | 29 class SafeBrowsingServiceTest; |
| 30 }; | 30 }; |
| 31 | 31 |
| 32 namespace subresource_filter { | 32 namespace subresource_filter { |
| 33 | 33 |
| 34 class ContentSubresourceFilterDriver; | |
| 35 class SubresourceFilterClient; | 34 class SubresourceFilterClient; |
| 36 enum class ActivationLevel; | 35 enum class ActivationLevel; |
| 37 enum class ActivationList; | 36 enum class ActivationList; |
| 38 | 37 |
| 39 using HostPathSet = std::set<std::string>; | 38 using HostPathSet = std::set<std::string>; |
| 40 using URLToActivationListsMap = | 39 using URLToActivationListsMap = |
| 41 std::unordered_map<std::string, std::set<ActivationList>>; | 40 std::unordered_map<std::string, std::set<ActivationList>>; |
| 42 | 41 |
| 43 // Controls the activation of subresource filtering for each page load in a | 42 // Controls the activation of subresource filtering for each page load in a |
| 44 // WebContents and manufactures the per-frame ContentSubresourceFilterDrivers. | 43 // WebContents and is responsible for sending the activation signal to all the |
| 44 // per-frame SubresourceFilterAgents on the renderer side. |
| 45 class ContentSubresourceFilterDriverFactory | 45 class ContentSubresourceFilterDriverFactory |
| 46 : public base::SupportsUserData::Data, | 46 : public base::SupportsUserData::Data, |
| 47 public content::WebContentsObserver { | 47 public content::WebContentsObserver { |
| 48 public: | 48 public: |
| 49 static void CreateForWebContents( | 49 static void CreateForWebContents( |
| 50 content::WebContents* web_contents, | 50 content::WebContents* web_contents, |
| 51 std::unique_ptr<SubresourceFilterClient> client); | 51 std::unique_ptr<SubresourceFilterClient> client); |
| 52 static ContentSubresourceFilterDriverFactory* FromWebContents( | 52 static ContentSubresourceFilterDriverFactory* FromWebContents( |
| 53 content::WebContents* web_contents); | 53 content::WebContents* web_contents); |
| 54 | 54 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 72 safe_browsing::SBThreatType threat_type, | 72 safe_browsing::SBThreatType threat_type, |
| 73 safe_browsing::ThreatPatternType threat_type_metadata); | 73 safe_browsing::ThreatPatternType threat_type_metadata); |
| 74 | 74 |
| 75 // Reloads the page and inserts the host of its URL to the whitelist. | 75 // Reloads the page and inserts the host of its URL to the whitelist. |
| 76 void OnReloadRequested(); | 76 void OnReloadRequested(); |
| 77 | 77 |
| 78 private: | 78 private: |
| 79 friend class ContentSubresourceFilterDriverFactoryTest; | 79 friend class ContentSubresourceFilterDriverFactoryTest; |
| 80 friend class safe_browsing::SafeBrowsingServiceTest; | 80 friend class safe_browsing::SafeBrowsingServiceTest; |
| 81 | 81 |
| 82 typedef std::map<content::RenderFrameHost*, | |
| 83 std::unique_ptr<ContentSubresourceFilterDriver>> | |
| 84 FrameHostToOwnedDriverMap; | |
| 85 | |
| 86 void SetDriverForFrameHostForTesting( | |
| 87 content::RenderFrameHost* render_frame_host, | |
| 88 std::unique_ptr<ContentSubresourceFilterDriver> driver); | |
| 89 | |
| 90 void CreateDriverForFrameHostIfNeeded( | |
| 91 content::RenderFrameHost* render_frame_host); | |
| 92 ContentSubresourceFilterDriver* DriverFromFrameHost( | |
| 93 content::RenderFrameHost* render_frame_host); | |
| 94 | |
| 95 void ResetActivationState(); | 82 void ResetActivationState(); |
| 96 | 83 |
| 97 void OnFirstSubresourceLoadDisallowed(); | 84 void OnFirstSubresourceLoadDisallowed(); |
| 98 | 85 |
| 99 void OnDocumentLoadStatistics(const DocumentLoadStatistics& statistics); | 86 void OnDocumentLoadStatistics(const DocumentLoadStatistics& statistics); |
| 100 | 87 |
| 101 bool IsWhitelisted(const GURL& url) const; | 88 bool IsWhitelisted(const GURL& url) const; |
| 102 | 89 |
| 103 // content::WebContentsObserver: | 90 // content::WebContentsObserver: |
| 104 void DidStartNavigation( | 91 void DidStartNavigation( |
| 105 content::NavigationHandle* navigation_handle) override; | 92 content::NavigationHandle* navigation_handle) override; |
| 106 void DidRedirectNavigation( | 93 void DidRedirectNavigation( |
| 107 content::NavigationHandle* navigation_handle) override; | 94 content::NavigationHandle* navigation_handle) override; |
| 108 void RenderFrameCreated(content::RenderFrameHost* render_frame_host) override; | |
| 109 void RenderFrameDeleted(content::RenderFrameHost* render_frame_host) override; | |
| 110 void ReadyToCommitNavigation( | 95 void ReadyToCommitNavigation( |
| 111 content::NavigationHandle* navigation_handle) override; | 96 content::NavigationHandle* navigation_handle) override; |
| 112 void DidFinishLoad(content::RenderFrameHost* render_frame_host, | 97 void DidFinishLoad(content::RenderFrameHost* render_frame_host, |
| 113 const GURL& validated_url) override; | 98 const GURL& validated_url) override; |
| 114 bool OnMessageReceived(const IPC::Message& message, | 99 bool OnMessageReceived(const IPC::Message& message, |
| 115 content::RenderFrameHost* render_frame_host) override; | 100 content::RenderFrameHost* render_frame_host) override; |
| 116 | 101 |
| 117 // Checks base on the value of |urr| and current activation scope if | 102 // Checks base on the value of |urr| and current activation scope if |
| 118 // activation signal should be sent. | 103 // activation signal should be sent. |
| 119 bool ShouldActivateForMainFrameURL(const GURL& url) const; | 104 bool ShouldActivateForMainFrameURL(const GURL& url) const; |
| 120 void ActivateForFrameHostIfNeeded(content::RenderFrameHost* render_frame_host, | 105 void ActivateForFrameHostIfNeeded(content::RenderFrameHost* render_frame_host, |
| 121 const GURL& url, | 106 const GURL& url, |
| 122 bool failed_navigation); | 107 bool failed_navigation); |
| 123 | 108 |
| 124 // Internal implementation of ReadyToCommitNavigation which doesn't use | 109 // Internal implementation of ReadyToCommitNavigation which doesn't use |
| 125 // NavigationHandle to ease unit tests. | 110 // NavigationHandle to ease unit tests. |
| 126 void ReadyToCommitNavigationInternal( | 111 void ReadyToCommitNavigationInternal( |
| 127 content::RenderFrameHost* render_frame_host, | 112 content::RenderFrameHost* render_frame_host, |
| 128 const GURL& url, | 113 const GURL& url, |
| 129 const content::Referrer& referrer, | 114 const content::Referrer& referrer, |
| 130 ui::PageTransition page_transition, | 115 ui::PageTransition page_transition, |
| 131 bool failed_navigation); | 116 bool failed_navigation); |
| 132 | 117 |
| 133 bool DidURLMatchCurrentActivationList(const GURL& url) const; | 118 bool DidURLMatchCurrentActivationList(const GURL& url) const; |
| 134 | 119 |
| 135 void AddActivationListMatch(const GURL& url, ActivationList match_type); | 120 void AddActivationListMatch(const GURL& url, ActivationList match_type); |
| 136 void RecordRedirectChainMatchPattern() const; | 121 void RecordRedirectChainMatchPattern() const; |
| 137 | 122 |
| 138 FrameHostToOwnedDriverMap frame_drivers_; | |
| 139 std::unique_ptr<SubresourceFilterClient> client_; | 123 std::unique_ptr<SubresourceFilterClient> client_; |
| 140 | 124 |
| 141 HostPathSet whitelisted_hosts_; | 125 HostPathSet whitelisted_hosts_; |
| 142 | 126 |
| 143 ActivationLevel activation_level_; | 127 ActivationLevel activation_level_; |
| 144 bool measure_performance_; | 128 bool measure_performance_; |
| 145 | 129 |
| 146 // The URLs in the navigation chain. | 130 // The URLs in the navigation chain. |
| 147 std::vector<GURL> navigation_chain_; | 131 std::vector<GURL> navigation_chain_; |
| 148 | 132 |
| 149 URLToActivationListsMap activation_list_matches_; | 133 URLToActivationListsMap activation_list_matches_; |
| 150 | 134 |
| 151 // Statistics about subresource loads, aggregated across all frames of the | 135 // Statistics about subresource loads, aggregated across all frames of the |
| 152 // current page. | 136 // current page. |
| 153 DocumentLoadStatistics aggregated_document_statistics_; | 137 DocumentLoadStatistics aggregated_document_statistics_; |
| 154 | 138 |
| 155 DISALLOW_COPY_AND_ASSIGN(ContentSubresourceFilterDriverFactory); | 139 DISALLOW_COPY_AND_ASSIGN(ContentSubresourceFilterDriverFactory); |
| 156 }; | 140 }; |
| 157 | 141 |
| 158 } // namespace subresource_filter | 142 } // namespace subresource_filter |
| 159 | 143 |
| 160 #endif // COMPONENTS_SUBRESOURCE_FILTER_CONTENT_BROWSER_CONTENT_SUBRESOURCE_FIL
TER_DRIVER_FACTORY_H_ | 144 #endif // COMPONENTS_SUBRESOURCE_FILTER_CONTENT_BROWSER_CONTENT_SUBRESOURCE_FIL
TER_DRIVER_FACTORY_H_ |
| OLD | NEW |