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

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

Issue 131783012: Fix the handling of user gestures for external protocol handler dialogs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix build Created 6 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #ifndef CHROME_BROWSER_EXTERNAL_PROTOCOL_EXTERNAL_PROTOCOL_HANDLER_H_ 5 #ifndef CHROME_BROWSER_EXTERNAL_PROTOCOL_EXTERNAL_PROTOCOL_HANDLER_H_
6 #define CHROME_BROWSER_EXTERNAL_PROTOCOL_EXTERNAL_PROTOCOL_HANDLER_H_ 6 #define CHROME_BROWSER_EXTERNAL_PROTOCOL_EXTERNAL_PROTOCOL_HANDLER_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "chrome/browser/shell_integration.h" 10 #include "chrome/browser/shell_integration.h"
11 11
12 class GURL; 12 class GURL;
13 class PrefRegistrySimple; 13 class PrefRegistrySimple;
14 14
15 namespace base { 15 namespace base {
16 class DictionaryValue; 16 class DictionaryValue;
17 } 17 }
18 18
19 class ExternalProtocolHandler { 19 class ExternalProtocolHandler {
not at google - send to devlin 2014/02/13 22:17:54 Could you do the scoping as part of the implementa
meacer 2014/02/14 00:37:19 Hmm, not sure if I understand. Do you mean to crea
20 public: 20 public:
21 enum BlockState { 21 enum BlockState {
22 DONT_BLOCK, 22 DONT_BLOCK,
23 BLOCK, 23 BLOCK,
24 UNKNOWN, 24 UNKNOWN,
25 }; 25 };
26 26
27 // Delegate to allow unit testing to provide different behavior. 27 // Delegate to allow unit testing to provide different behavior.
28 class Delegate { 28 class Delegate {
29 public: 29 public:
30 virtual ShellIntegration::DefaultProtocolClientWorker* CreateShellWorker( 30 virtual ShellIntegration::DefaultProtocolClientWorker* CreateShellWorker(
31 ShellIntegration::DefaultWebClientObserver* observer, 31 ShellIntegration::DefaultWebClientObserver* observer,
32 const std::string& protocol) = 0; 32 const std::string& protocol) = 0;
33 virtual BlockState GetBlockState(const std::string& scheme) = 0; 33 virtual BlockState GetBlockState(const std::string& scheme,
34 bool user_gesture) = 0;
34 virtual void BlockRequest() = 0; 35 virtual void BlockRequest() = 0;
35 virtual void RunExternalProtocolDialog(const GURL& url, 36 virtual void RunExternalProtocolDialog(const GURL& url,
36 int render_process_host_id, 37 int render_process_host_id,
37 int routing_id) = 0; 38 int routing_id) = 0;
38 virtual void LaunchUrlWithoutSecurityCheck(const GURL& url) = 0; 39 virtual void LaunchUrlWithoutSecurityCheck(const GURL& url) = 0;
39 virtual void FinishedProcessingCheck() = 0; 40 virtual void FinishedProcessingCheck() = 0;
40 virtual ~Delegate() {} 41 virtual ~Delegate() {}
41 }; 42 };
42 43
43 // Returns whether we should block a given scheme. 44 // Returns whether we should block a given scheme.
44 static BlockState GetBlockState(const std::string& scheme); 45 static BlockState GetBlockState(const std::string& scheme, bool user_gesture);
45 46
46 // Sets whether we should block a given scheme. 47 // Sets whether we should block a given scheme.
47 static void SetBlockState(const std::string& scheme, BlockState state); 48 static void SetBlockState(const std::string& scheme, BlockState state);
48 49
49 // Checks to see if the protocol is allowed, if it is whitelisted, 50 // Checks to see if the protocol is allowed, if it is whitelisted,
50 // the application associated with the protocol is launched on the io thread, 51 // the application associated with the protocol is launched on the io thread,
51 // if it is blacklisted, returns silently. Otherwise, an 52 // if it is blacklisted, returns silently. Otherwise, an
52 // ExternalProtocolDialog is created asking the user. If the user accepts, 53 // ExternalProtocolDialog is created asking the user. If the user accepts,
53 // LaunchUrlWithoutSecurityCheck is called on the io thread and the 54 // LaunchUrlWithoutSecurityCheck is called on the io thread and the
54 // application is launched. 55 // application is launched.
55 // Must run on the UI thread. 56 // Must run on the UI thread.
56 static void LaunchUrl(const GURL& url, int render_process_host_id, 57 static void LaunchUrl(const GURL& url, int render_process_host_id,
57 int tab_contents_id) { 58 int tab_contents_id, bool user_gesture) {
58 LaunchUrlWithDelegate(url, render_process_host_id, tab_contents_id, NULL); 59 LaunchUrlWithDelegate(
60 url, render_process_host_id, tab_contents_id, NULL, user_gesture);
59 } 61 }
60 62
61 // Version of LaunchUrl allowing use of a delegate to facilitate unit 63 // Version of LaunchUrl allowing use of a delegate to facilitate unit
62 // testing. 64 // testing.
63 static void LaunchUrlWithDelegate(const GURL& url, int render_process_host_id, 65 static void LaunchUrlWithDelegate(const GURL& url, int render_process_host_id,
64 int tab_contents_id, Delegate* delegate); 66 int tab_contents_id, Delegate* delegate,
67 bool user_gesture);
65 68
66 // Creates and runs a External Protocol dialog box. 69 // Creates and runs a External Protocol dialog box.
67 // |url| - The url of the request. 70 // |url| - The url of the request.
68 // |render_process_host_id| and |routing_id| are used by 71 // |render_process_host_id| and |routing_id| are used by
69 // tab_util::GetWebContentsByID to aquire the tab contents associated with 72 // tab_util::GetWebContentsByID to aquire the tab contents associated with
70 // this dialog. 73 // this dialog.
71 // NOTE: There is a race between the Time of Check and the Time Of Use for 74 // NOTE: There is a race between the Time of Check and the Time Of Use for
72 // the command line. Since the caller (web page) does not have access 75 // the command line. Since the caller (web page) does not have access
73 // to change the command line by itself, we do not do anything special 76 // to change the command line by itself, we do not do anything special
74 // to protect against this scenario. 77 // to protect against this scenario.
(...skipping 13 matching lines...) Expand all
88 // NOTE: You should Not call this function directly unless you are sure the 91 // NOTE: You should Not call this function directly unless you are sure the
89 // url you have has been checked against the blacklist, and has been escaped. 92 // url you have has been checked against the blacklist, and has been escaped.
90 // All calls to this function should originate in some way from LaunchUrl. 93 // All calls to this function should originate in some way from LaunchUrl.
91 static void LaunchUrlWithoutSecurityCheck(const GURL& url, 94 static void LaunchUrlWithoutSecurityCheck(const GURL& url,
92 int render_process_host_id, 95 int render_process_host_id,
93 int tab_contents_id); 96 int tab_contents_id);
94 97
95 // Prepopulates the dictionary with known protocols to deny or allow, if 98 // Prepopulates the dictionary with known protocols to deny or allow, if
96 // preferences for them do not already exist. 99 // preferences for them do not already exist.
97 static void PrepopulateDictionary(base::DictionaryValue* win_pref); 100 static void PrepopulateDictionary(base::DictionaryValue* win_pref);
98
99 // Allows LaunchUrl to proceed with launching an external protocol handler.
100 // This is typically triggered by a user gesture, but is also called for
101 // each extension API function. Note that each call to LaunchUrl resets
102 // the state to false (not allowed).
103 static void PermitLaunchUrl();
104 }; 101 };
105 102
106 #endif // CHROME_BROWSER_EXTERNAL_PROTOCOL_EXTERNAL_PROTOCOL_HANDLER_H_ 103 #endif // CHROME_BROWSER_EXTERNAL_PROTOCOL_EXTERNAL_PROTOCOL_HANDLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698