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/permissions/permission_manager.h" | 11 #include "chrome/browser/permissions/permission_manager.h" |
12 #include "chrome/browser/plugins/plugin_utils.h" | 12 #include "chrome/browser/plugins/plugin_utils.h" |
13 #include "chrome/browser/plugins/plugins_field_trial.h" | 13 #include "chrome/browser/plugins/plugins_field_trial.h" |
14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
15 #include "chrome/common/chrome_features.h" | 15 #include "chrome/common/chrome_features.h" |
16 #include "components/navigation_interception/intercept_navigation_throttle.h" | 16 #include "components/navigation_interception/intercept_navigation_throttle.h" |
17 #include "components/navigation_interception/navigation_params.h" | 17 #include "components/navigation_interception/navigation_params.h" |
18 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
19 #include "content/public/browser/navigation_handle.h" | 19 #include "content/public/browser/navigation_handle.h" |
20 #include "content/public/browser/permission_type.h" | 20 #include "content/public/browser/permission_type.h" |
21 #include "content/public/browser/web_contents.h" | 21 #include "content/public/browser/web_contents.h" |
22 #include "third_party/WebKit/public/platform/modules/permissions/permission_stat
us.mojom.h" | 22 #include "third_party/WebKit/public/platform/modules/permissions/permission_stat
us.mojom.h" |
| 23 #include "url/origin.h" |
23 | 24 |
24 using content::BrowserThread; | 25 using content::BrowserThread; |
25 using content::NavigationHandle; | 26 using content::NavigationHandle; |
26 using content::NavigationThrottle; | 27 using content::NavigationThrottle; |
27 | 28 |
28 namespace { | 29 namespace { |
29 | 30 |
30 const char kFlashDownloadURL[] = "get.adobe.com/flash"; | 31 const char kFlashDownloadURL[] = "get.adobe.com/flash"; |
31 | 32 |
32 void DoNothing(blink::mojom::PermissionStatus result) {} | 33 void DoNothing(blink::mojom::PermissionStatus result) {} |
(...skipping 29 matching lines...) Expand all Loading... |
62 | 63 |
63 if (!has_user_gesture) | 64 if (!has_user_gesture) |
64 return false; | 65 return false; |
65 | 66 |
66 if (!base::StartsWith(target_url.GetContent(), kFlashDownloadURL, | 67 if (!base::StartsWith(target_url.GetContent(), kFlashDownloadURL, |
67 base::CompareCase::INSENSITIVE_ASCII)) { | 68 base::CompareCase::INSENSITIVE_ASCII)) { |
68 return false; | 69 return false; |
69 } | 70 } |
70 | 71 |
71 ContentSetting flash_setting = PluginUtils::GetFlashPluginContentSetting( | 72 ContentSetting flash_setting = PluginUtils::GetFlashPluginContentSetting( |
72 host_content_settings_map, source_url, source_url, nullptr); | 73 host_content_settings_map, url::Origin(source_url), source_url, nullptr); |
73 flash_setting = PluginsFieldTrial::EffectiveContentSetting( | 74 flash_setting = PluginsFieldTrial::EffectiveContentSetting( |
74 CONTENT_SETTINGS_TYPE_PLUGINS, flash_setting); | 75 CONTENT_SETTINGS_TYPE_PLUGINS, flash_setting); |
75 | 76 |
76 return flash_setting == CONTENT_SETTING_DETECT_IMPORTANT_CONTENT; | 77 return flash_setting == CONTENT_SETTING_DETECT_IMPORTANT_CONTENT; |
77 } | 78 } |
78 | 79 |
79 // static | 80 // static |
80 std::unique_ptr<NavigationThrottle> | 81 std::unique_ptr<NavigationThrottle> |
81 FlashDownloadInterception::MaybeCreateThrottleFor(NavigationHandle* handle) { | 82 FlashDownloadInterception::MaybeCreateThrottleFor(NavigationHandle* handle) { |
82 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 83 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
83 | 84 |
84 // Never intercept Flash Download navigations in a new window. | 85 // Never intercept Flash Download navigations in a new window. |
85 if (handle->GetWebContents()->HasOpener()) | 86 if (handle->GetWebContents()->HasOpener()) |
86 return nullptr; | 87 return nullptr; |
87 | 88 |
88 Profile* profile = Profile::FromBrowserContext( | 89 Profile* profile = Profile::FromBrowserContext( |
89 handle->GetWebContents()->GetBrowserContext()); | 90 handle->GetWebContents()->GetBrowserContext()); |
90 HostContentSettingsMap* host_content_settings_map = | 91 HostContentSettingsMap* host_content_settings_map = |
91 HostContentSettingsMapFactory::GetForProfile(profile); | 92 HostContentSettingsMapFactory::GetForProfile(profile); |
92 GURL source_url = handle->GetWebContents()->GetLastCommittedURL(); | 93 GURL source_url = handle->GetWebContents()->GetLastCommittedURL(); |
93 if (!ShouldStopFlashDownloadAction(host_content_settings_map, source_url, | 94 if (!ShouldStopFlashDownloadAction(host_content_settings_map, source_url, |
94 handle->GetURL(), | 95 handle->GetURL(), |
95 handle->HasUserGesture())) { | 96 handle->HasUserGesture())) { |
96 return nullptr; | 97 return nullptr; |
97 } | 98 } |
98 | 99 |
99 return base::MakeUnique<navigation_interception::InterceptNavigationThrottle>( | 100 return base::MakeUnique<navigation_interception::InterceptNavigationThrottle>( |
100 handle, base::Bind(&InterceptNavigation), true); | 101 handle, base::Bind(&InterceptNavigation), true); |
101 } | 102 } |
OLD | NEW |