Chromium Code Reviews| 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 "chrome/browser/content_settings/host_content_settings_map_factory.h" | 9 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
| 10 #include "chrome/browser/content_settings/tab_specific_content_settings.h" | 10 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 25 | 25 |
| 26 using content::BrowserThread; | 26 using content::BrowserThread; |
| 27 using content::NavigationHandle; | 27 using content::NavigationHandle; |
| 28 using content::NavigationThrottle; | 28 using content::NavigationThrottle; |
| 29 | 29 |
| 30 namespace { | 30 namespace { |
| 31 | 31 |
| 32 // Regexes matching | 32 // Regexes matching |
| 33 const char kGetFlashURLCanonicalRegex[] = "(?i)get\\.adobe\\.com/.*flash.*"; | 33 const char kGetFlashURLCanonicalRegex[] = "(?i)get\\.adobe\\.com/.*flash.*"; |
| 34 const char kGetFlashURLSecondaryRegex[] = | 34 const char kGetFlashURLSecondaryRegex[] = |
| 35 "(?i)(www\\.)?(adobe|macromedia)\\.com/go.*" | 35 "(?i)(www\\.)?(adobe|macromedia)\\.com/go/" |
| 36 "(get[-_]?flash|fl(ash)?.?pl(ayer)?|flash_completion|flashpm|flashdownload|" | 36 "((?i).*get[-_]?flash|getfp10android|.*fl(ash)player|.*flashpl|" |
|
raymes
2017/04/10 23:54:13
is the (?i) needed here?
tommycli
2017/04/11 17:40:04
Yes, because both 'flashdownload' and 'FlashDownlo
| |
| 37 "fp|h-m-a-?2|chrome|download_player|gnav_fl|pdcredirect).*"; | 37 ".*flash_player|flash_completion|flashpm|.*flashdownload|d65_flplayer|" |
| 38 "fp_jp|runtimes_fp|[a-z_-]{3,6}h-m-a-?2|chrome|download_player|" | |
| 39 "gnav_fl|pdcredirect).*"; | |
| 38 | 40 |
| 39 void DoNothing(ContentSetting result) {} | 41 void DoNothing(ContentSetting result) {} |
| 40 | 42 |
| 41 bool InterceptNavigation( | 43 bool InterceptNavigation( |
| 42 const GURL& source_url, | 44 const GURL& source_url, |
| 43 content::WebContents* source, | 45 content::WebContents* source, |
| 44 const navigation_interception::NavigationParams& params) { | 46 const navigation_interception::NavigationParams& params) { |
| 45 FlashDownloadInterception::InterceptFlashDownloadNavigation(source, | 47 FlashDownloadInterception::InterceptFlashDownloadNavigation(source, |
| 46 source_url); | 48 source_url); |
| 47 return true; | 49 return true; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 87 return false; | 89 return false; |
| 88 | 90 |
| 89 if (!has_user_gesture) | 91 if (!has_user_gesture) |
| 90 return false; | 92 return false; |
| 91 | 93 |
| 92 // If the navigation source is already the Flash download page, don't | 94 // If the navigation source is already the Flash download page, don't |
| 93 // intercept the download. The user may be trying to download Flash. | 95 // intercept the download. The user may be trying to download Flash. |
| 94 if (RE2::PartialMatch(source_url.GetContent(), kGetFlashURLCanonicalRegex)) | 96 if (RE2::PartialMatch(source_url.GetContent(), kGetFlashURLCanonicalRegex)) |
| 95 return false; | 97 return false; |
| 96 | 98 |
| 97 std::string target_url_str = target_url.GetContent(); | 99 std::string target_url_str = target_url.GetContent(); |
|
mihai.balan
2017/04/11 06:44:14
Would this address the regex matching parts of the
tommycli
2017/04/11 17:40:04
Done. Awesome suggestion. I used this basically ve
| |
| 98 if (RE2::FullMatch(target_url_str, kGetFlashURLCanonicalRegex) || | 100 if (RE2::FullMatch(target_url_str, kGetFlashURLCanonicalRegex) || |
| 99 RE2::FullMatch(target_url_str, kGetFlashURLSecondaryRegex)) { | 101 RE2::FullMatch(target_url_str, kGetFlashURLSecondaryRegex)) { |
| 100 ContentSetting flash_setting = PluginUtils::GetFlashPluginContentSetting( | 102 ContentSetting flash_setting = PluginUtils::GetFlashPluginContentSetting( |
| 101 host_content_settings_map, url::Origin(source_url), source_url, | 103 host_content_settings_map, url::Origin(source_url), source_url, |
| 102 nullptr); | 104 nullptr); |
| 103 flash_setting = PluginsFieldTrial::EffectiveContentSetting( | 105 flash_setting = PluginsFieldTrial::EffectiveContentSetting( |
| 104 host_content_settings_map, CONTENT_SETTINGS_TYPE_PLUGINS, | 106 host_content_settings_map, CONTENT_SETTINGS_TYPE_PLUGINS, |
| 105 flash_setting); | 107 flash_setting); |
| 106 | 108 |
| 107 return flash_setting == CONTENT_SETTING_DETECT_IMPORTANT_CONTENT || | 109 return flash_setting == CONTENT_SETTING_DETECT_IMPORTANT_CONTENT || |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 137 HostContentSettingsMap* host_content_settings_map = | 139 HostContentSettingsMap* host_content_settings_map = |
| 138 HostContentSettingsMapFactory::GetForProfile(profile); | 140 HostContentSettingsMapFactory::GetForProfile(profile); |
| 139 if (!ShouldStopFlashDownloadAction(host_content_settings_map, source_url, | 141 if (!ShouldStopFlashDownloadAction(host_content_settings_map, source_url, |
| 140 handle->GetURL(), has_user_gesture)) { | 142 handle->GetURL(), has_user_gesture)) { |
| 141 return nullptr; | 143 return nullptr; |
| 142 } | 144 } |
| 143 | 145 |
| 144 return base::MakeUnique<navigation_interception::InterceptNavigationThrottle>( | 146 return base::MakeUnique<navigation_interception::InterceptNavigationThrottle>( |
| 145 handle, base::Bind(&InterceptNavigation, source_url), true); | 147 handle, base::Bind(&InterceptNavigation, source_url), true); |
| 146 } | 148 } |
| OLD | NEW |