| 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 CHROME_BROWSER_SUBRESOURCE_FILTER_CHROME_SUBRESOURCE_FILTER_CLIENT_H_ | 5 #ifndef CHROME_BROWSER_SUBRESOURCE_FILTER_CHROME_SUBRESOURCE_FILTER_CLIENT_H_ |
| 6 #define CHROME_BROWSER_SUBRESOURCE_FILTER_CHROME_SUBRESOURCE_FILTER_CLIENT_H_ | 6 #define CHROME_BROWSER_SUBRESOURCE_FILTER_CHROME_SUBRESOURCE_FILTER_CLIENT_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "components/content_settings/core/common/content_settings.h" | 14 #include "components/content_settings/core/common/content_settings.h" |
| 15 #include "components/subresource_filter/content/browser/subresource_filter_clien
t.h" | 15 #include "components/subresource_filter/content/browser/subresource_filter_clien
t.h" |
| 16 #include "content/public/browser/web_contents_user_data.h" | 16 #include "content/public/browser/web_contents_user_data.h" |
| 17 | 17 |
| 18 class GURL; | 18 class GURL; |
| 19 class SubresourceFilterContentSettingsManager; |
| 19 | 20 |
| 20 namespace content { | 21 namespace content { |
| 21 class NavigationHandle; | 22 class NavigationHandle; |
| 22 class NavigationThrottle; | 23 class NavigationThrottle; |
| 23 class WebContents; | 24 class WebContents; |
| 24 } // namespace content | 25 } // namespace content |
| 25 | 26 |
| 26 // This enum backs a histogram. Make sure new elements are only added to the | 27 // This enum backs a histogram. Make sure new elements are only added to the |
| 27 // end. Keep histograms.xml up to date with any changes. | 28 // end. Keep histograms.xml up to date with any changes. |
| 28 enum SubresourceFilterAction { | 29 enum SubresourceFilterAction { |
| 29 // Main frame navigation to a different document. | 30 // Main frame navigation to a different document. |
| 30 kActionNavigationStarted = 0, | 31 kActionNavigationStarted = 0, |
| 31 | 32 |
| 32 // Standard UI shown. On Desktop this is in the omnibox, | 33 // Standard UI shown. On Desktop this is in the omnibox, |
| 33 // On Android, it is an infobar. | 34 // On Android, it is an infobar. |
| 34 kActionUIShown, | 35 kActionUIShown, |
| 35 | 36 |
| 36 // On Desktop, this is a bubble. On Android it is an | 37 // On Desktop, this is a bubble. On Android it is an |
| 37 // expanded infobar. | 38 // expanded infobar. |
| 38 kActionDetailsShown, | 39 kActionDetailsShown, |
| 39 | 40 |
| 40 // TODO(csharrison): Log this once the link is in place. | 41 // TODO(csharrison): Log this once the link is in place. |
| 41 kActionClickedLearnMore, | 42 kActionClickedLearnMore, |
| 42 | 43 |
| 43 // Content settings: | 44 // Content settings: |
| 44 // | 45 // |
| 45 // Content setting updated automatically via the standard UI. | 46 // Content setting updated automatically via the standard UI. |
| 46 kActionContentSettingsBlockedFromUI, | 47 kActionContentSettingsBlockedFromUI, |
| 47 | 48 |
| 48 // Content settings which target specific origins (e.g. no wildcards). | 49 // Content settings which target specific origins (e.g. no wildcards). These |
| 50 // updates do not include updates from the main UI. |
| 49 kActionContentSettingsAllowed, | 51 kActionContentSettingsAllowed, |
| 50 kActionContentSettingsBlocked, | 52 kActionContentSettingsBlocked, |
| 51 | 53 |
| 52 // Global settings. | 54 // Global settings. |
| 53 kActionContentSettingsAllowedGlobal, | 55 kActionContentSettingsAllowedGlobal, |
| 54 kActionContentSettingsBlockedGlobal, | 56 kActionContentSettingsBlockedGlobal, |
| 55 | 57 |
| 56 // A wildcard update. The current content settings API makes this a bit | 58 // A wildcard update. The current content settings API makes this a bit |
| 57 // difficult to see whether it is Block or Allow. This should not be a huge | 59 // difficult to see whether it is Block or Allow. This should not be a huge |
| 58 // problem because this can only be changed from the settings UI, which is | 60 // problem because this can only be changed from the settings UI, which is |
| 59 // relatively rare. | 61 // relatively rare. |
| 60 // TODO(crbug.com/706061): Fix this once content settings API becomes more | 62 // TODO(crbug.com/706061): Fix this once content settings API becomes more |
| 61 // flexible. | 63 // flexible. |
| 62 kActionContentSettingsWildcardUpdate, | 64 kActionContentSettingsWildcardUpdate, |
| 63 | 65 |
| 66 // The UI was suppressed due to "smart" logic which tries not to spam the UI |
| 67 // on navigations on the same origin within a certain time. |
| 68 kActionUISuppressed, |
| 69 |
| 70 // The feature was blocked via content setting manually while smart UI was |
| 71 // suppressing the UI. Potentially indicates that the smart UI is too |
| 72 // aggressive if this happens frequently. This is a reported alongside |
| 73 // kActionContentSettingsBlocked if the UI is currently in suppressed mode. |
| 74 kActionContentSettingsBlockedWhileUISuppressed, |
| 75 |
| 64 kActionLastEntry | 76 kActionLastEntry |
| 65 }; | 77 }; |
| 66 | 78 |
| 67 // Chrome implementation of SubresourceFilterClient. | 79 // Chrome implementation of SubresourceFilterClient. |
| 68 // TODO(csharrison): Make this a WebContentsObserver and own the throttle | 80 // TODO(csharrison): Make this a WebContentsObserver and own the throttle |
| 69 // manager directly. | 81 // manager directly. |
| 70 class ChromeSubresourceFilterClient | 82 class ChromeSubresourceFilterClient |
| 71 : public content::WebContentsUserData<ChromeSubresourceFilterClient>, | 83 : public content::WebContentsUserData<ChromeSubresourceFilterClient>, |
| 72 public subresource_filter::SubresourceFilterClient { | 84 public subresource_filter::SubresourceFilterClient { |
| 73 public: | 85 public: |
| (...skipping 13 matching lines...) Expand all Loading... |
| 87 subresource_filter::VerifiedRulesetDealer::Handle* GetRulesetDealer() | 99 subresource_filter::VerifiedRulesetDealer::Handle* GetRulesetDealer() |
| 88 override; | 100 override; |
| 89 | 101 |
| 90 bool did_show_ui_for_navigation() const { | 102 bool did_show_ui_for_navigation() const { |
| 91 return did_show_ui_for_navigation_; | 103 return did_show_ui_for_navigation_; |
| 92 } | 104 } |
| 93 | 105 |
| 94 static void LogAction(SubresourceFilterAction action); | 106 static void LogAction(SubresourceFilterAction action); |
| 95 | 107 |
| 96 private: | 108 private: |
| 97 ContentSetting GetContentSettingForUrl(const GURL& url); | |
| 98 std::set<std::string> whitelisted_hosts_; | 109 std::set<std::string> whitelisted_hosts_; |
| 110 |
| 111 // Owned by the profile. |
| 112 SubresourceFilterContentSettingsManager* settings_manager_; |
| 113 |
| 99 content::WebContents* web_contents_; | 114 content::WebContents* web_contents_; |
| 100 bool did_show_ui_for_navigation_; | 115 bool did_show_ui_for_navigation_; |
| 101 | 116 |
| 102 DISALLOW_COPY_AND_ASSIGN(ChromeSubresourceFilterClient); | 117 DISALLOW_COPY_AND_ASSIGN(ChromeSubresourceFilterClient); |
| 103 }; | 118 }; |
| 104 | 119 |
| 105 #endif // CHROME_BROWSER_SUBRESOURCE_FILTER_CHROME_SUBRESOURCE_FILTER_CLIENT_H_ | 120 #endif // CHROME_BROWSER_SUBRESOURCE_FILTER_CHROME_SUBRESOURCE_FILTER_CLIENT_H_ |
| OLD | NEW |