| 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 13 matching lines...) Expand all Loading... |
| 24 #include "url/origin.h" | 24 #include "url/origin.h" |
| 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 kGetFlashURLSecondaryGoRegex[] = |
| 35 "(?i)(www\\.)?(adobe|macromedia)\\.com/go/" | 35 "(?i)(www\\.)?(adobe|macromedia)\\.com/go/" |
| 36 "((?i).*get[-_]?flash|getfp10android|.*fl(ash)player|.*flashpl|" | 36 "((?i).*get[-_]?flash|getfp10android|.*fl(ash)player|.*flashpl|" |
| 37 ".*flash_player|flash_completion|flashpm|.*flashdownload|d65_flplayer|" | 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|" | 38 "fp_jp|runtimes_fp|[a-z_-]{3,6}h-m-a-?2|chrome|download_player|" |
| 39 "gnav_fl|pdcredirect).*"; | 39 "gnav_fl|pdcredirect).*"; |
| 40 const char kGetFlashURLSecondaryDownloadRegex[] = |
| 41 "(?i)(www\\.)?(adobe|macromedia)\\.com/shockwave/download/download.cgi"; |
| 42 const char kGetFlashURLSecondaryDownloadQuery[] = |
| 43 "P1_Prod_Version=ShockwaveFlash"; |
| 40 | 44 |
| 41 void DoNothing(ContentSetting result) {} | 45 void DoNothing(ContentSetting result) {} |
| 42 | 46 |
| 43 bool InterceptNavigation( | 47 bool InterceptNavigation( |
| 44 const GURL& source_url, | 48 const GURL& source_url, |
| 45 content::WebContents* source, | 49 content::WebContents* source, |
| 46 const navigation_interception::NavigationParams& params) { | 50 const navigation_interception::NavigationParams& params) { |
| 47 FlashDownloadInterception::InterceptFlashDownloadNavigation(source, | 51 FlashDownloadInterception::InterceptFlashDownloadNavigation(source, |
| 48 source_url); | 52 source_url); |
| 49 return true; | 53 return true; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 // If the navigation source is already the Flash download page, don't | 104 // If the navigation source is already the Flash download page, don't |
| 101 // intercept the download. The user may be trying to download Flash. | 105 // intercept the download. The user may be trying to download Flash. |
| 102 std::string source_url_str = | 106 std::string source_url_str = |
| 103 source_url.ReplaceComponents(replacements).GetContent(); | 107 source_url.ReplaceComponents(replacements).GetContent(); |
| 104 if (RE2::PartialMatch(source_url_str, kGetFlashURLCanonicalRegex)) | 108 if (RE2::PartialMatch(source_url_str, kGetFlashURLCanonicalRegex)) |
| 105 return false; | 109 return false; |
| 106 | 110 |
| 107 std::string target_url_str = | 111 std::string target_url_str = |
| 108 target_url.ReplaceComponents(replacements).GetContent(); | 112 target_url.ReplaceComponents(replacements).GetContent(); |
| 109 if (RE2::FullMatch(target_url_str, kGetFlashURLCanonicalRegex) || | 113 if (RE2::FullMatch(target_url_str, kGetFlashURLCanonicalRegex) || |
| 110 RE2::FullMatch(target_url_str, kGetFlashURLSecondaryRegex)) { | 114 RE2::FullMatch(target_url_str, kGetFlashURLSecondaryGoRegex) || |
| 115 (RE2::FullMatch(target_url_str, kGetFlashURLSecondaryDownloadRegex) && |
| 116 target_url.query() == kGetFlashURLSecondaryDownloadQuery)) { |
| 111 ContentSetting flash_setting = PluginUtils::GetFlashPluginContentSetting( | 117 ContentSetting flash_setting = PluginUtils::GetFlashPluginContentSetting( |
| 112 host_content_settings_map, url::Origin(source_url), source_url, | 118 host_content_settings_map, url::Origin(source_url), source_url, |
| 113 nullptr); | 119 nullptr); |
| 114 flash_setting = PluginsFieldTrial::EffectiveContentSetting( | 120 flash_setting = PluginsFieldTrial::EffectiveContentSetting( |
| 115 host_content_settings_map, CONTENT_SETTINGS_TYPE_PLUGINS, | 121 host_content_settings_map, CONTENT_SETTINGS_TYPE_PLUGINS, |
| 116 flash_setting); | 122 flash_setting); |
| 117 | 123 |
| 118 return flash_setting == CONTENT_SETTING_DETECT_IMPORTANT_CONTENT || | 124 return flash_setting == CONTENT_SETTING_DETECT_IMPORTANT_CONTENT || |
| 119 flash_setting == CONTENT_SETTING_BLOCK; | 125 flash_setting == CONTENT_SETTING_BLOCK; |
| 120 } | 126 } |
| (...skipping 27 matching lines...) Expand all Loading... |
| 148 HostContentSettingsMap* host_content_settings_map = | 154 HostContentSettingsMap* host_content_settings_map = |
| 149 HostContentSettingsMapFactory::GetForProfile(profile); | 155 HostContentSettingsMapFactory::GetForProfile(profile); |
| 150 if (!ShouldStopFlashDownloadAction(host_content_settings_map, source_url, | 156 if (!ShouldStopFlashDownloadAction(host_content_settings_map, source_url, |
| 151 handle->GetURL(), has_user_gesture)) { | 157 handle->GetURL(), has_user_gesture)) { |
| 152 return nullptr; | 158 return nullptr; |
| 153 } | 159 } |
| 154 | 160 |
| 155 return base::MakeUnique<navigation_interception::InterceptNavigationThrottle>( | 161 return base::MakeUnique<navigation_interception::InterceptNavigationThrottle>( |
| 156 handle, base::Bind(&InterceptNavigation, source_url), true); | 162 handle, base::Bind(&InterceptNavigation, source_url), true); |
| 157 } | 163 } |
| OLD | NEW |