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 #include "chrome/browser/subresource_filter/chrome_subresource_filter_client.h" | 5 #include "chrome/browser/subresource_filter/chrome_subresource_filter_client.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/metrics/histogram_macros.h" | 9 #include "base/metrics/histogram_macros.h" |
10 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | 10 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
11 #include "chrome/browser/content_settings/tab_specific_content_settings.h" | 11 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
12 #include "chrome/browser/infobars/infobar_service.h" | 12 #include "chrome/browser/infobars/infobar_service.h" |
13 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
14 #include "chrome/browser/subresource_filter/subresource_filter_content_settings_
observer_factory.h" | 14 #include "chrome/browser/subresource_filter/subresource_filter_content_settings_
observer_factory.h" |
15 #include "chrome/browser/ui/android/content_settings/subresource_filter_infobar_
delegate.h" | 15 #include "chrome/browser/ui/android/content_settings/subresource_filter_infobar_
delegate.h" |
16 #include "components/content_settings/core/browser/host_content_settings_map.h" | 16 #include "components/content_settings/core/browser/host_content_settings_map.h" |
| 17 #include "components/content_settings/core/common/content_settings_types.h" |
17 | 18 |
18 ChromeSubresourceFilterClient::ChromeSubresourceFilterClient( | 19 ChromeSubresourceFilterClient::ChromeSubresourceFilterClient( |
19 content::WebContents* web_contents) | 20 content::WebContents* web_contents) |
20 : web_contents_(web_contents), shown_for_navigation_(false) { | 21 : web_contents_(web_contents), shown_for_navigation_(false) { |
21 DCHECK(web_contents); | 22 DCHECK(web_contents); |
22 // Ensure the content settings observer is initialized. | 23 // Ensure the content settings observer is initialized. |
23 SubresourceFilterContentSettingsObserverFactory::EnsureForProfile( | 24 SubresourceFilterContentSettingsObserverFactory::EnsureForProfile( |
24 Profile::FromBrowserContext(web_contents_->GetBrowserContext())); | 25 Profile::FromBrowserContext(web_contents_->GetBrowserContext())); |
25 } | 26 } |
26 | 27 |
27 ChromeSubresourceFilterClient::~ChromeSubresourceFilterClient() {} | 28 ChromeSubresourceFilterClient::~ChromeSubresourceFilterClient() {} |
28 | 29 |
29 void ChromeSubresourceFilterClient::ToggleNotificationVisibility( | 30 void ChromeSubresourceFilterClient::ToggleNotificationVisibility( |
30 bool visibility) { | 31 bool visibility) { |
31 if (shown_for_navigation_ && visibility) | 32 if (shown_for_navigation_ && visibility) |
32 return; | 33 return; |
33 | 34 |
34 // |visibility| is false when a new navigation starts. | |
35 if (visibility) | |
36 LogAction(kActionUIShown); | |
37 else | |
38 LogAction(kActionNavigationStarted); | |
39 | |
40 shown_for_navigation_ = visibility; | 35 shown_for_navigation_ = visibility; |
41 TabSpecificContentSettings* content_settings = | 36 TabSpecificContentSettings* content_settings = |
42 TabSpecificContentSettings::FromWebContents(web_contents_); | 37 TabSpecificContentSettings::FromWebContents(web_contents_); |
43 content_settings->SetSubresourceBlocked(visibility); | 38 |
| 39 // |visibility| is false when a new navigation starts. |
| 40 if (visibility) { |
| 41 content_settings->OnContentBlocked( |
| 42 CONTENT_SETTINGS_TYPE_SUBRESOURCE_FILTER); |
| 43 LogAction(kActionUIShown); |
44 #if defined(OS_ANDROID) | 44 #if defined(OS_ANDROID) |
45 if (visibility) { | |
46 InfoBarService* infobar_service = | 45 InfoBarService* infobar_service = |
47 InfoBarService::FromWebContents(web_contents_); | 46 InfoBarService::FromWebContents(web_contents_); |
48 | |
49 SubresourceFilterInfobarDelegate::Create(infobar_service); | 47 SubresourceFilterInfobarDelegate::Create(infobar_service); |
50 content_settings->SetSubresourceBlockageIndicated(); | 48 #endif |
| 49 } else { |
| 50 LogAction(kActionNavigationStarted); |
51 } | 51 } |
52 #endif | |
53 } | 52 } |
54 | 53 |
55 bool ChromeSubresourceFilterClient::IsWhitelistedByContentSettings( | 54 bool ChromeSubresourceFilterClient::IsWhitelistedByContentSettings( |
56 const GURL& url) { | 55 const GURL& url) { |
57 return GetContentSettingForUrl(url) == CONTENT_SETTING_BLOCK; | 56 return GetContentSettingForUrl(url) == CONTENT_SETTING_BLOCK; |
58 } | 57 } |
59 | 58 |
60 void ChromeSubresourceFilterClient::WhitelistByContentSettings( | 59 void ChromeSubresourceFilterClient::WhitelistByContentSettings( |
61 const GURL& url) { | 60 const GURL& url) { |
62 // Whitelist via content settings. | 61 // Whitelist via content settings. |
(...skipping 19 matching lines...) Expand all Loading... |
82 const GURL& url) { | 81 const GURL& url) { |
83 Profile* profile = | 82 Profile* profile = |
84 Profile::FromBrowserContext(web_contents_->GetBrowserContext()); | 83 Profile::FromBrowserContext(web_contents_->GetBrowserContext()); |
85 DCHECK(profile); | 84 DCHECK(profile); |
86 HostContentSettingsMap* settings_map = | 85 HostContentSettingsMap* settings_map = |
87 HostContentSettingsMapFactory::GetForProfile(profile); | 86 HostContentSettingsMapFactory::GetForProfile(profile); |
88 return settings_map->GetContentSetting( | 87 return settings_map->GetContentSetting( |
89 url, url, ContentSettingsType::CONTENT_SETTINGS_TYPE_SUBRESOURCE_FILTER, | 88 url, url, ContentSettingsType::CONTENT_SETTINGS_TYPE_SUBRESOURCE_FILTER, |
90 std::string()); | 89 std::string()); |
91 } | 90 } |
OLD | NEW |