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/plugins/flash_download_interception.h" | 5 #include "chrome/browser/plugins/flash_download_interception.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.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/permissions/permission_manager.h" | 12 #include "chrome/browser/permissions/permission_manager.h" |
13 #include "chrome/browser/plugins/plugin_utils.h" | 13 #include "chrome/browser/plugins/plugin_utils.h" |
14 #include "chrome/browser/plugins/plugins_field_trial.h" | 14 #include "chrome/browser/plugins/plugins_field_trial.h" |
15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
16 #include "chrome/common/chrome_features.h" | 16 #include "chrome/common/chrome_features.h" |
17 #include "components/navigation_interception/intercept_navigation_throttle.h" | 17 #include "components/navigation_interception/intercept_navigation_throttle.h" |
18 #include "components/navigation_interception/navigation_params.h" | 18 #include "components/navigation_interception/navigation_params.h" |
19 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
20 #include "content/public/browser/navigation_handle.h" | 20 #include "content/public/browser/navigation_handle.h" |
21 #include "content/public/browser/permission_type.h" | 21 #include "content/public/browser/permission_type.h" |
22 #include "content/public/browser/web_contents.h" | 22 #include "content/public/browser/web_contents.h" |
23 #include "third_party/WebKit/public/platform/modules/permissions/permission_stat
us.mojom.h" | 23 #include "third_party/WebKit/public/platform/modules/permissions/permission_stat
us.mojom.h" |
| 24 #include "url/origin.h" |
24 | 25 |
25 using content::BrowserThread; | 26 using content::BrowserThread; |
26 using content::NavigationHandle; | 27 using content::NavigationHandle; |
27 using content::NavigationThrottle; | 28 using content::NavigationThrottle; |
28 | 29 |
29 namespace { | 30 namespace { |
30 | 31 |
31 const char kFlashDownloadURL[] = "get.adobe.com/flash"; | 32 const char kFlashDownloadURL[] = "get.adobe.com/flash"; |
32 | 33 |
33 void DoNothing(blink::mojom::PermissionStatus result) {} | 34 void DoNothing(blink::mojom::PermissionStatus result) {} |
(...skipping 13 matching lines...) Expand all Loading... |
47 void FlashDownloadInterception::InterceptFlashDownloadNavigation( | 48 void FlashDownloadInterception::InterceptFlashDownloadNavigation( |
48 content::WebContents* web_contents, | 49 content::WebContents* web_contents, |
49 const GURL& source_url) { | 50 const GURL& source_url) { |
50 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 51 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
51 | 52 |
52 Profile* profile = | 53 Profile* profile = |
53 Profile::FromBrowserContext(web_contents->GetBrowserContext()); | 54 Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
54 HostContentSettingsMap* host_content_settings_map = | 55 HostContentSettingsMap* host_content_settings_map = |
55 HostContentSettingsMapFactory::GetForProfile(profile); | 56 HostContentSettingsMapFactory::GetForProfile(profile); |
56 ContentSetting flash_setting = PluginUtils::GetFlashPluginContentSetting( | 57 ContentSetting flash_setting = PluginUtils::GetFlashPluginContentSetting( |
57 host_content_settings_map, source_url, source_url, nullptr); | 58 host_content_settings_map, url::Origin(source_url), source_url, nullptr); |
58 flash_setting = PluginsFieldTrial::EffectiveContentSetting( | 59 flash_setting = PluginsFieldTrial::EffectiveContentSetting( |
59 CONTENT_SETTINGS_TYPE_PLUGINS, flash_setting); | 60 CONTENT_SETTINGS_TYPE_PLUGINS, flash_setting); |
60 | 61 |
61 if (flash_setting == CONTENT_SETTING_DETECT_IMPORTANT_CONTENT) { | 62 if (flash_setting == CONTENT_SETTING_DETECT_IMPORTANT_CONTENT) { |
62 PermissionManager* manager = PermissionManager::Get(profile); | 63 PermissionManager* manager = PermissionManager::Get(profile); |
63 manager->RequestPermission( | 64 manager->RequestPermission( |
64 content::PermissionType::FLASH, web_contents->GetMainFrame(), | 65 content::PermissionType::FLASH, web_contents->GetMainFrame(), |
65 web_contents->GetLastCommittedURL(), true, base::Bind(&DoNothing)); | 66 web_contents->GetLastCommittedURL(), true, base::Bind(&DoNothing)); |
66 } else if (flash_setting == CONTENT_SETTING_BLOCK) { | 67 } else if (flash_setting == CONTENT_SETTING_BLOCK) { |
67 TabSpecificContentSettings::FromWebContents(web_contents) | 68 TabSpecificContentSettings::FromWebContents(web_contents) |
(...skipping 14 matching lines...) Expand all Loading... |
82 | 83 |
83 if (!has_user_gesture) | 84 if (!has_user_gesture) |
84 return false; | 85 return false; |
85 | 86 |
86 if (!base::StartsWith(target_url.GetContent(), kFlashDownloadURL, | 87 if (!base::StartsWith(target_url.GetContent(), kFlashDownloadURL, |
87 base::CompareCase::INSENSITIVE_ASCII)) { | 88 base::CompareCase::INSENSITIVE_ASCII)) { |
88 return false; | 89 return false; |
89 } | 90 } |
90 | 91 |
91 ContentSetting flash_setting = PluginUtils::GetFlashPluginContentSetting( | 92 ContentSetting flash_setting = PluginUtils::GetFlashPluginContentSetting( |
92 host_content_settings_map, source_url, source_url, nullptr); | 93 host_content_settings_map, url::Origin(source_url), source_url, nullptr); |
93 flash_setting = PluginsFieldTrial::EffectiveContentSetting( | 94 flash_setting = PluginsFieldTrial::EffectiveContentSetting( |
94 CONTENT_SETTINGS_TYPE_PLUGINS, flash_setting); | 95 CONTENT_SETTINGS_TYPE_PLUGINS, flash_setting); |
95 | 96 |
96 return flash_setting == CONTENT_SETTING_DETECT_IMPORTANT_CONTENT || | 97 return flash_setting == CONTENT_SETTING_DETECT_IMPORTANT_CONTENT || |
97 flash_setting == CONTENT_SETTING_BLOCK; | 98 flash_setting == CONTENT_SETTING_BLOCK; |
98 } | 99 } |
99 | 100 |
100 // static | 101 // static |
101 std::unique_ptr<NavigationThrottle> | 102 std::unique_ptr<NavigationThrottle> |
102 FlashDownloadInterception::MaybeCreateThrottleFor(NavigationHandle* handle) { | 103 FlashDownloadInterception::MaybeCreateThrottleFor(NavigationHandle* handle) { |
(...skipping 10 matching lines...) Expand all Loading... |
113 GURL source_url = handle->GetWebContents()->GetLastCommittedURL(); | 114 GURL source_url = handle->GetWebContents()->GetLastCommittedURL(); |
114 if (!ShouldStopFlashDownloadAction(host_content_settings_map, source_url, | 115 if (!ShouldStopFlashDownloadAction(host_content_settings_map, source_url, |
115 handle->GetURL(), | 116 handle->GetURL(), |
116 handle->HasUserGesture())) { | 117 handle->HasUserGesture())) { |
117 return nullptr; | 118 return nullptr; |
118 } | 119 } |
119 | 120 |
120 return base::MakeUnique<navigation_interception::InterceptNavigationThrottle>( | 121 return base::MakeUnique<navigation_interception::InterceptNavigationThrottle>( |
121 handle, base::Bind(&InterceptNavigation, source_url), true); | 122 handle, base::Bind(&InterceptNavigation, source_url), true); |
122 } | 123 } |
OLD | NEW |