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

Side by Side Diff: chrome/browser/external_protocol/external_protocol_handler.cc

Issue 426713002: Revert of Fix the handling of user gestures for external protocol handler dialogs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 6 years, 4 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/external_protocol/external_protocol_handler.h" 5 #include "chrome/browser/external_protocol/external_protocol_handler.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
12 #include "base/prefs/pref_registry_simple.h" 12 #include "base/prefs/pref_registry_simple.h"
13 #include "base/prefs/pref_service.h" 13 #include "base/prefs/pref_service.h"
14 #include "base/prefs/scoped_user_pref_update.h" 14 #include "base/prefs/scoped_user_pref_update.h"
15 #include "base/strings/string_util.h" 15 #include "base/strings/string_util.h"
16 #include "base/threading/thread.h" 16 #include "base/threading/thread.h"
17 #include "build/build_config.h" 17 #include "build/build_config.h"
18 #include "chrome/browser/browser_process.h" 18 #include "chrome/browser/browser_process.h"
19 #include "chrome/browser/platform_util.h" 19 #include "chrome/browser/platform_util.h"
20 #include "chrome/browser/profiles/profile.h" 20 #include "chrome/browser/profiles/profile.h"
21 #include "chrome/browser/tab_contents/tab_util.h" 21 #include "chrome/browser/tab_contents/tab_util.h"
22 #include "chrome/common/pref_names.h" 22 #include "chrome/common/pref_names.h"
23 #include "content/public/browser/browser_thread.h" 23 #include "content/public/browser/browser_thread.h"
24 #include "content/public/browser/web_contents.h" 24 #include "content/public/browser/web_contents.h"
25 #include "net/base/escape.h" 25 #include "net/base/escape.h"
26 #include "url/gurl.h" 26 #include "url/gurl.h"
27 27
28 using content::BrowserThread; 28 using content::BrowserThread;
29 29
30 // Whether we accept requests for launching external protocols. This is set to
31 // false every time an external protocol is requested, and set back to true on
32 // each user gesture. This variable should only be accessed from the UI thread.
33 static bool g_accept_requests = true;
34
30 namespace { 35 namespace {
31 36
32 // Functions enabling unit testing. Using a NULL delegate will use the default 37 // Functions enabling unit testing. Using a NULL delegate will use the default
33 // behavior; if a delegate is provided it will be used instead. 38 // behavior; if a delegate is provided it will be used instead.
34 ShellIntegration::DefaultProtocolClientWorker* CreateShellWorker( 39 ShellIntegration::DefaultProtocolClientWorker* CreateShellWorker(
35 ShellIntegration::DefaultWebClientObserver* observer, 40 ShellIntegration::DefaultWebClientObserver* observer,
36 const std::string& protocol, 41 const std::string& protocol,
37 ExternalProtocolHandler::Delegate* delegate) { 42 ExternalProtocolHandler::Delegate* delegate) {
38 if (!delegate) 43 if (!delegate)
39 return new ShellIntegration::DefaultProtocolClientWorker(observer, 44 return new ShellIntegration::DefaultProtocolClientWorker(observer,
40 protocol); 45 protocol);
41 46
42 return delegate->CreateShellWorker(observer, protocol); 47 return delegate->CreateShellWorker(observer, protocol);
43 } 48 }
44 49
45 ExternalProtocolHandler::BlockState GetBlockStateWithDelegate( 50 ExternalProtocolHandler::BlockState GetBlockStateWithDelegate(
46 const std::string& scheme, 51 const std::string& scheme,
47 ExternalProtocolHandler::Delegate* delegate, 52 ExternalProtocolHandler::Delegate* delegate) {
48 bool initiated_by_user_gesture) {
49 if (!delegate) 53 if (!delegate)
50 return ExternalProtocolHandler::GetBlockState(scheme, 54 return ExternalProtocolHandler::GetBlockState(scheme);
51 initiated_by_user_gesture);
52 55
53 return delegate->GetBlockState(scheme, initiated_by_user_gesture); 56 return delegate->GetBlockState(scheme);
54 } 57 }
55 58
56 void RunExternalProtocolDialogWithDelegate( 59 void RunExternalProtocolDialogWithDelegate(
57 const GURL& url, 60 const GURL& url,
58 int render_process_host_id, 61 int render_process_host_id,
59 int routing_id, 62 int routing_id,
60 ExternalProtocolHandler::Delegate* delegate) { 63 ExternalProtocolHandler::Delegate* delegate) {
61 if (!delegate) { 64 if (!delegate) {
62 ExternalProtocolHandler::RunExternalProtocolDialog(url, 65 ExternalProtocolHandler::RunExternalProtocolDialog(url,
63 render_process_host_id, 66 render_process_host_id,
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 196
194 for (size_t i = 0; i < arraysize(allowed_schemes); ++i) { 197 for (size_t i = 0; i < arraysize(allowed_schemes); ++i) {
195 if (!win_pref->GetBoolean(allowed_schemes[i], &should_block)) { 198 if (!win_pref->GetBoolean(allowed_schemes[i], &should_block)) {
196 win_pref->SetBoolean(allowed_schemes[i], false); 199 win_pref->SetBoolean(allowed_schemes[i], false);
197 } 200 }
198 } 201 }
199 } 202 }
200 203
201 // static 204 // static
202 ExternalProtocolHandler::BlockState ExternalProtocolHandler::GetBlockState( 205 ExternalProtocolHandler::BlockState ExternalProtocolHandler::GetBlockState(
203 const std::string& scheme, 206 const std::string& scheme) {
204 bool initiated_by_user_gesture) { 207 // If we are being carpet bombed, block the request.
205 if (!initiated_by_user_gesture) 208 if (!g_accept_requests)
206 return BLOCK; 209 return BLOCK;
207 210
208 if (scheme.length() == 1) { 211 if (scheme.length() == 1) {
209 // We have a URL that looks something like: 212 // We have a URL that looks something like:
210 // C:/WINDOWS/system32/notepad.exe 213 // C:/WINDOWS/system32/notepad.exe
211 // ShellExecuting this URL will cause the specified program to be executed. 214 // ShellExecuting this URL will cause the specified program to be executed.
212 return BLOCK; 215 return BLOCK;
213 } 216 }
214 217
215 // Check the stored prefs. 218 // Check the stored prefs.
(...skipping 26 matching lines...) Expand all
242 245
243 if (state == UNKNOWN) { 246 if (state == UNKNOWN) {
244 update_excluded_schemas->Remove(scheme, NULL); 247 update_excluded_schemas->Remove(scheme, NULL);
245 } else { 248 } else {
246 update_excluded_schemas->SetBoolean(scheme, (state == BLOCK)); 249 update_excluded_schemas->SetBoolean(scheme, (state == BLOCK));
247 } 250 }
248 } 251 }
249 } 252 }
250 253
251 // static 254 // static
252 void ExternalProtocolHandler::LaunchUrlWithDelegate( 255 void ExternalProtocolHandler::LaunchUrlWithDelegate(const GURL& url,
253 const GURL& url, 256 int render_process_host_id,
254 int render_process_host_id, 257 int tab_contents_id,
255 int tab_contents_id, 258 Delegate* delegate) {
256 Delegate* delegate,
257 bool initiated_by_user_gesture) {
258 DCHECK(base::MessageLoopForUI::IsCurrent()); 259 DCHECK(base::MessageLoopForUI::IsCurrent());
259 260
260 // Escape the input scheme to be sure that the command does not 261 // Escape the input scheme to be sure that the command does not
261 // have parameters unexpected by the external program. 262 // have parameters unexpected by the external program.
262 std::string escaped_url_string = net::EscapeExternalHandlerValue(url.spec()); 263 std::string escaped_url_string = net::EscapeExternalHandlerValue(url.spec());
263 GURL escaped_url(escaped_url_string); 264 GURL escaped_url(escaped_url_string);
264 BlockState block_state = GetBlockStateWithDelegate(escaped_url.scheme(), 265 BlockState block_state =
265 delegate, 266 GetBlockStateWithDelegate(escaped_url.scheme(), delegate);
266 initiated_by_user_gesture);
267 if (block_state == BLOCK) { 267 if (block_state == BLOCK) {
268 if (delegate) 268 if (delegate)
269 delegate->BlockRequest(); 269 delegate->BlockRequest();
270 return; 270 return;
271 } 271 }
272 272
273 g_accept_requests = false;
274
273 // The worker creates tasks with references to itself and puts them into 275 // The worker creates tasks with references to itself and puts them into
274 // message loops. When no tasks are left it will delete the observer and 276 // message loops. When no tasks are left it will delete the observer and
275 // eventually be deleted itself. 277 // eventually be deleted itself.
276 ShellIntegration::DefaultWebClientObserver* observer = 278 ShellIntegration::DefaultWebClientObserver* observer =
277 new ExternalDefaultProtocolObserver(url, 279 new ExternalDefaultProtocolObserver(url,
278 render_process_host_id, 280 render_process_host_id,
279 tab_contents_id, 281 tab_contents_id,
280 block_state == UNKNOWN, 282 block_state == UNKNOWN,
281 delegate); 283 delegate);
282 scoped_refptr<ShellIntegration::DefaultProtocolClientWorker> worker = 284 scoped_refptr<ShellIntegration::DefaultProtocolClientWorker> worker =
(...skipping 16 matching lines...) Expand all
299 return; 301 return;
300 302
301 platform_util::OpenExternal( 303 platform_util::OpenExternal(
302 Profile::FromBrowserContext(web_contents->GetBrowserContext()), url); 304 Profile::FromBrowserContext(web_contents->GetBrowserContext()), url);
303 } 305 }
304 306
305 // static 307 // static
306 void ExternalProtocolHandler::RegisterPrefs(PrefRegistrySimple* registry) { 308 void ExternalProtocolHandler::RegisterPrefs(PrefRegistrySimple* registry) {
307 registry->RegisterDictionaryPref(prefs::kExcludedSchemes); 309 registry->RegisterDictionaryPref(prefs::kExcludedSchemes);
308 } 310 }
311
312 // static
313 void ExternalProtocolHandler::PermitLaunchUrl() {
314 DCHECK(base::MessageLoopForUI::IsCurrent());
315 g_accept_requests = true;
316 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698