Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(254)

Side by Side Diff: chrome/browser/plugins/flash_download_interception.cc

Issue 2699993002: [HBD]: Add additional intercept URL.
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/plugins/flash_download_interception_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 kGetFlashURLGoLinkRegex[] =
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 "(get[-_]?flash|fl(ash)?.?pl(ayer)?|flash_completion|flashpm|flashdownload|"
37 "fp|h-m-a-?2|chrome|download_player|gnav_fl|pdcredirect).*"; 37 "fp|h-m-a-?2|chrome|download_player|gnav_fl|pdcredirect).*";
38 const char kGetFlashURLShockwaveRegex[] =
39 "(?i)(www\\.)?(adobe)\\.com/shockwave/download.*";
38 40
39 void DoNothing(blink::mojom::PermissionStatus result) {} 41 void DoNothing(blink::mojom::PermissionStatus 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 10 matching lines...) Expand all
58 Profile* profile = 60 Profile* profile =
59 Profile::FromBrowserContext(web_contents->GetBrowserContext()); 61 Profile::FromBrowserContext(web_contents->GetBrowserContext());
60 HostContentSettingsMap* host_content_settings_map = 62 HostContentSettingsMap* host_content_settings_map =
61 HostContentSettingsMapFactory::GetForProfile(profile); 63 HostContentSettingsMapFactory::GetForProfile(profile);
62 ContentSetting flash_setting = PluginUtils::GetFlashPluginContentSetting( 64 ContentSetting flash_setting = PluginUtils::GetFlashPluginContentSetting(
63 host_content_settings_map, url::Origin(source_url), source_url, nullptr); 65 host_content_settings_map, url::Origin(source_url), source_url, nullptr);
64 flash_setting = PluginsFieldTrial::EffectiveContentSetting( 66 flash_setting = PluginsFieldTrial::EffectiveContentSetting(
65 host_content_settings_map, CONTENT_SETTINGS_TYPE_PLUGINS, flash_setting); 67 host_content_settings_map, CONTENT_SETTINGS_TYPE_PLUGINS, flash_setting);
66 68
67 if (flash_setting == CONTENT_SETTING_DETECT_IMPORTANT_CONTENT) { 69 if (flash_setting == CONTENT_SETTING_DETECT_IMPORTANT_CONTENT) {
70 printf("Requesting permission...\n");
68 PermissionManager* manager = PermissionManager::Get(profile); 71 PermissionManager* manager = PermissionManager::Get(profile);
69 manager->RequestPermission( 72 manager->RequestPermission(
70 content::PermissionType::FLASH, web_contents->GetMainFrame(), 73 content::PermissionType::FLASH, web_contents->GetMainFrame(),
71 web_contents->GetLastCommittedURL(), true, base::Bind(&DoNothing)); 74 web_contents->GetLastCommittedURL(), true, base::Bind(&DoNothing));
72 } else if (flash_setting == CONTENT_SETTING_BLOCK) { 75 } else if (flash_setting == CONTENT_SETTING_BLOCK) {
73 TabSpecificContentSettings::FromWebContents(web_contents) 76 TabSpecificContentSettings::FromWebContents(web_contents)
74 ->FlashDownloadBlocked(); 77 ->FlashDownloadBlocked();
75 } 78 }
76 79
77 // If the content setting has been already changed, do nothing. 80 // If the content setting has been already changed, do nothing.
(...skipping 10 matching lines...) Expand all
88 91
89 if (!has_user_gesture) 92 if (!has_user_gesture)
90 return false; 93 return false;
91 94
92 // If the navigation source is already the Flash download page, don't 95 // If the navigation source is already the Flash download page, don't
93 // intercept the download. The user may be trying to download Flash. 96 // intercept the download. The user may be trying to download Flash.
94 if (RE2::PartialMatch(source_url.GetContent(), kGetFlashURLCanonicalRegex)) 97 if (RE2::PartialMatch(source_url.GetContent(), kGetFlashURLCanonicalRegex))
95 return false; 98 return false;
96 99
97 std::string target_url_str = target_url.GetContent(); 100 std::string target_url_str = target_url.GetContent();
101 printf("target url: %s\n", target_url_str.c_str());
98 if (RE2::FullMatch(target_url_str, kGetFlashURLCanonicalRegex) || 102 if (RE2::FullMatch(target_url_str, kGetFlashURLCanonicalRegex) ||
99 RE2::FullMatch(target_url_str, kGetFlashURLSecondaryRegex)) { 103 RE2::FullMatch(target_url_str, kGetFlashURLGoLinkRegex) ||
104 RE2::FullMatch(target_url_str, kGetFlashURLShockwaveRegex)) {
100 ContentSetting flash_setting = PluginUtils::GetFlashPluginContentSetting( 105 ContentSetting flash_setting = PluginUtils::GetFlashPluginContentSetting(
101 host_content_settings_map, url::Origin(source_url), source_url, 106 host_content_settings_map, url::Origin(source_url), source_url,
102 nullptr); 107 nullptr);
103 flash_setting = PluginsFieldTrial::EffectiveContentSetting( 108 flash_setting = PluginsFieldTrial::EffectiveContentSetting(
104 host_content_settings_map, CONTENT_SETTINGS_TYPE_PLUGINS, 109 host_content_settings_map, CONTENT_SETTINGS_TYPE_PLUGINS,
105 flash_setting); 110 flash_setting);
106 111
107 return flash_setting == CONTENT_SETTING_DETECT_IMPORTANT_CONTENT || 112 return flash_setting == CONTENT_SETTING_DETECT_IMPORTANT_CONTENT ||
108 flash_setting == CONTENT_SETTING_BLOCK; 113 flash_setting == CONTENT_SETTING_BLOCK;
109 } 114 }
110 115
111 return false; 116 return false;
112 } 117 }
113 118
114 // static 119 // static
115 std::unique_ptr<NavigationThrottle> 120 std::unique_ptr<NavigationThrottle>
116 FlashDownloadInterception::MaybeCreateThrottleFor(NavigationHandle* handle) { 121 FlashDownloadInterception::MaybeCreateThrottleFor(NavigationHandle* handle) {
117 DCHECK_CURRENTLY_ON(BrowserThread::UI); 122 DCHECK_CURRENTLY_ON(BrowserThread::UI);
118 123
119 // Browser initiated navigations like the Back button or the context menu 124 // Browser initiated navigations like the Back button or the context menu
120 // should never be intercepted. 125 // should never be intercepted.
121 if (!handle->IsRendererInitiated()) 126 if (!handle->IsRendererInitiated())
122 return nullptr; 127 return nullptr;
123 128
129 printf("Src url: %s target: %s, has gesture %d, main frame %d\n",
130 handle->GetWebContents()->GetLastCommittedURL().spec().c_str(),
131 handle->GetURL().spec().c_str(),
132 handle->HasUserGesture(), handle->IsInMainFrame());
133
124 // The source URL may be empty, it's a new tab. Intercepting that navigation 134 // The source URL may be empty, it's a new tab. Intercepting that navigation
125 // would lead to a blank new tab, which would be bad. 135 // would lead to a blank new tab, which would be bad.
126 GURL source_url = handle->GetWebContents()->GetLastCommittedURL(); 136 GURL source_url = handle->GetWebContents()->GetLastCommittedURL();
127 if (source_url.is_empty()) 137 if (source_url.is_empty())
128 return nullptr; 138 return nullptr;
129 139
130 // Always treat main-frame navigations as having a user gesture. We have to do 140 // Always treat main-frame navigations as having a user gesture. We have to do
131 // this because the user gesture system can be foiled by popular JavaScript 141 // this because the user gesture system can be foiled by popular JavaScript
132 // analytics frameworks that capture the click event. crbug.com/678097 142 // analytics frameworks that capture the click event. crbug.com/678097
133 bool has_user_gesture = handle->HasUserGesture() || handle->IsInMainFrame(); 143 bool has_user_gesture = handle->HasUserGesture() || handle->IsInMainFrame();
134 144
135 Profile* profile = Profile::FromBrowserContext( 145 Profile* profile = Profile::FromBrowserContext(
136 handle->GetWebContents()->GetBrowserContext()); 146 handle->GetWebContents()->GetBrowserContext());
137 HostContentSettingsMap* host_content_settings_map = 147 HostContentSettingsMap* host_content_settings_map =
138 HostContentSettingsMapFactory::GetForProfile(profile); 148 HostContentSettingsMapFactory::GetForProfile(profile);
139 if (!ShouldStopFlashDownloadAction(host_content_settings_map, source_url, 149 if (!ShouldStopFlashDownloadAction(host_content_settings_map, source_url,
140 handle->GetURL(), has_user_gesture)) { 150 handle->GetURL(), has_user_gesture)) {
141 return nullptr; 151 return nullptr;
142 } 152 }
143 153
154 printf("making nav throttle\n");
144 return base::MakeUnique<navigation_interception::InterceptNavigationThrottle>( 155 return base::MakeUnique<navigation_interception::InterceptNavigationThrottle>(
145 handle, base::Bind(&InterceptNavigation, source_url), true); 156 handle, base::Bind(&InterceptNavigation, source_url), true);
146 } 157 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/plugins/flash_download_interception_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698