| 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" |
| (...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 const char kWwwPrefix[] = "www."; | 32 const char kWwwPrefix[] = "www."; |
| 33 | 33 |
| 34 // URLs that will be intercepted with any www. prefix pruned. | 34 // The URL of the page where Flash can be downloaded. |
| 35 const char kFlashDownloadURL[] = "get.adobe.com/flash"; |
| 36 |
| 37 // URLs that will be intercepted with any www. prefix pruned. These should all |
| 38 // redirect to |kFlashDownloadURL|. |
| 35 const char* kFlashDownloadURLs[] = { | 39 const char* kFlashDownloadURLs[] = { |
| 36 "get.adobe.com/flash", "macromedia.com/go/getflashplayer", | 40 kFlashDownloadURL, "macromedia.com/go/getflashplayer", |
| 37 "adobe.com/go/getflashplayer", "adobe.com/go/gntray_dl_getflashplayer"}; | 41 "adobe.com/go/getflashplayer", "adobe.com/go/gntray_dl_getflashplayer"}; |
| 38 | 42 |
| 39 void DoNothing(blink::mojom::PermissionStatus result) {} | 43 void DoNothing(blink::mojom::PermissionStatus result) {} |
| 40 | 44 |
| 41 bool InterceptNavigation( | 45 bool InterceptNavigation( |
| 42 const GURL& source_url, | 46 const GURL& source_url, |
| 43 content::WebContents* source, | 47 content::WebContents* source, |
| 44 const navigation_interception::NavigationParams& params) { | 48 const navigation_interception::NavigationParams& params) { |
| 45 FlashDownloadInterception::InterceptFlashDownloadNavigation(source, | 49 FlashDownloadInterception::InterceptFlashDownloadNavigation(source, |
| 46 source_url); | 50 source_url); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 HostContentSettingsMap* host_content_settings_map, | 86 HostContentSettingsMap* host_content_settings_map, |
| 83 const GURL& source_url, | 87 const GURL& source_url, |
| 84 const GURL& target_url, | 88 const GURL& target_url, |
| 85 bool has_user_gesture) { | 89 bool has_user_gesture) { |
| 86 if (!PluginUtils::ShouldPreferHtmlOverPlugins(host_content_settings_map)) | 90 if (!PluginUtils::ShouldPreferHtmlOverPlugins(host_content_settings_map)) |
| 87 return false; | 91 return false; |
| 88 | 92 |
| 89 if (!has_user_gesture) | 93 if (!has_user_gesture) |
| 90 return false; | 94 return false; |
| 91 | 95 |
| 96 // If the navigation source is already the Flash download page, don't |
| 97 // intercept the download. The user may be trying to download Flash. |
| 98 if (base::StartsWith(source_url.GetContent(), kFlashDownloadURL, |
| 99 base::CompareCase::INSENSITIVE_ASCII)) { |
| 100 return false; |
| 101 } |
| 102 |
| 92 std::string target_url_str = target_url.GetContent(); | 103 std::string target_url_str = target_url.GetContent(); |
| 93 // Ignore www. if it's at the start of the URL. | 104 // Ignore www. if it's at the start of the URL. |
| 94 if (base::StartsWith(target_url_str, kWwwPrefix, | 105 if (base::StartsWith(target_url_str, kWwwPrefix, |
| 95 base::CompareCase::INSENSITIVE_ASCII)) { | 106 base::CompareCase::INSENSITIVE_ASCII)) { |
| 96 target_url_str = | 107 target_url_str = |
| 97 target_url_str.substr(sizeof(kWwwPrefix) - 1, std::string::npos); | 108 target_url_str.substr(sizeof(kWwwPrefix) - 1, std::string::npos); |
| 98 } | 109 } |
| 99 | 110 |
| 100 for (const char* flash_url : kFlashDownloadURLs) { | 111 for (const char* flash_url : kFlashDownloadURLs) { |
| 101 if (base::StartsWith(target_url_str, flash_url, | 112 if (base::StartsWith(target_url_str, flash_url, |
| (...skipping 29 matching lines...) Expand all Loading... |
| 131 GURL source_url = handle->GetWebContents()->GetLastCommittedURL(); | 142 GURL source_url = handle->GetWebContents()->GetLastCommittedURL(); |
| 132 if (!ShouldStopFlashDownloadAction(host_content_settings_map, source_url, | 143 if (!ShouldStopFlashDownloadAction(host_content_settings_map, source_url, |
| 133 handle->GetURL(), | 144 handle->GetURL(), |
| 134 handle->HasUserGesture())) { | 145 handle->HasUserGesture())) { |
| 135 return nullptr; | 146 return nullptr; |
| 136 } | 147 } |
| 137 | 148 |
| 138 return base::MakeUnique<navigation_interception::InterceptNavigationThrottle>( | 149 return base::MakeUnique<navigation_interception::InterceptNavigationThrottle>( |
| 139 handle, base::Bind(&InterceptNavigation, source_url), true); | 150 handle, base::Bind(&InterceptNavigation, source_url), true); |
| 140 } | 151 } |
| OLD | NEW |