OLD | NEW |
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 #include "ui/base/page_transition_types.h" |
11 | 12 |
12 class GURL; | 13 class GURL; |
13 class PrefRegistrySimple; | 14 class PrefRegistrySimple; |
14 | 15 |
15 namespace base { | 16 namespace base { |
16 class DictionaryValue; | 17 class DictionaryValue; |
17 } | 18 } |
18 | 19 |
19 class ExternalProtocolHandler { | 20 class ExternalProtocolHandler { |
20 public: | 21 public: |
21 enum BlockState { | 22 enum BlockState { |
22 DONT_BLOCK, | 23 DONT_BLOCK, |
23 BLOCK, | 24 BLOCK, |
24 UNKNOWN, | 25 UNKNOWN, |
25 }; | 26 }; |
26 | 27 |
27 // Delegate to allow unit testing to provide different behavior. | 28 // Delegate to allow unit testing to provide different behavior. |
28 class Delegate { | 29 class Delegate { |
29 public: | 30 public: |
30 virtual ShellIntegration::DefaultProtocolClientWorker* CreateShellWorker( | 31 virtual ShellIntegration::DefaultProtocolClientWorker* CreateShellWorker( |
31 ShellIntegration::DefaultWebClientObserver* observer, | 32 ShellIntegration::DefaultWebClientObserver* observer, |
32 const std::string& protocol) = 0; | 33 const std::string& protocol) = 0; |
33 virtual BlockState GetBlockState(const std::string& scheme) = 0; | 34 virtual BlockState GetBlockState(const std::string& scheme) = 0; |
34 virtual void BlockRequest() = 0; | 35 virtual void BlockRequest() = 0; |
35 virtual void RunExternalProtocolDialog(const GURL& url, | 36 virtual void RunExternalProtocolDialog( |
36 int render_process_host_id, | 37 const GURL& url, |
37 int routing_id) = 0; | 38 int render_process_host_id, |
| 39 int routing_id, |
| 40 ui::PageTransition page_transition, |
| 41 bool has_user_gesture) = 0; |
38 virtual void LaunchUrlWithoutSecurityCheck(const GURL& url) = 0; | 42 virtual void LaunchUrlWithoutSecurityCheck(const GURL& url) = 0; |
39 virtual void FinishedProcessingCheck() = 0; | 43 virtual void FinishedProcessingCheck() = 0; |
40 virtual ~Delegate() {} | 44 virtual ~Delegate() {} |
41 }; | 45 }; |
42 | 46 |
43 // Returns whether we should block a given scheme. | 47 // Returns whether we should block a given scheme. |
44 static BlockState GetBlockState(const std::string& scheme); | 48 static BlockState GetBlockState(const std::string& scheme); |
45 | 49 |
46 // Sets whether we should block a given scheme. | 50 // Sets whether we should block a given scheme. |
47 static void SetBlockState(const std::string& scheme, BlockState state); | 51 static void SetBlockState(const std::string& scheme, BlockState state); |
48 | 52 |
49 // Checks to see if the protocol is allowed, if it is whitelisted, | 53 // 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, | 54 // the application associated with the protocol is launched on the io thread, |
51 // if it is blacklisted, returns silently. Otherwise, an | 55 // if it is blacklisted, returns silently. Otherwise, an |
52 // ExternalProtocolDialog is created asking the user. If the user accepts, | 56 // ExternalProtocolDialog is created asking the user. If the user accepts, |
53 // LaunchUrlWithoutSecurityCheck is called on the io thread and the | 57 // LaunchUrlWithoutSecurityCheck is called on the io thread and the |
54 // application is launched. | 58 // application is launched. |
55 // Must run on the UI thread. | 59 // Must run on the UI thread. |
56 static void LaunchUrl(const GURL& url, | 60 // Allowing use of a delegate to facilitate unit testing. |
57 int render_process_host_id, | |
58 int tab_contents_id) { | |
59 LaunchUrlWithDelegate(url, render_process_host_id, tab_contents_id, NULL); | |
60 } | |
61 | |
62 // Version of LaunchUrl allowing use of a delegate to facilitate unit | |
63 // testing. | |
64 static void LaunchUrlWithDelegate(const GURL& url, | 61 static void LaunchUrlWithDelegate(const GURL& url, |
65 int render_process_host_id, | 62 int render_process_host_id, |
66 int tab_contents_id, | 63 int tab_contents_id, |
| 64 ui::PageTransition page_transition, |
| 65 bool has_user_gesture, |
67 Delegate* delegate); | 66 Delegate* delegate); |
68 | 67 |
69 // Creates and runs a External Protocol dialog box. | 68 // Creates and runs a External Protocol dialog box. |
70 // |url| - The url of the request. | 69 // |url| - The url of the request. |
71 // |render_process_host_id| and |routing_id| are used by | 70 // |render_process_host_id| and |routing_id| are used by |
72 // tab_util::GetWebContentsByID to aquire the tab contents associated with | 71 // tab_util::GetWebContentsByID to aquire the tab contents associated with |
73 // this dialog. | 72 // this dialog. |
74 // NOTE: There is a race between the Time of Check and the Time Of Use for | 73 // NOTE: There is a race between the Time of Check and the Time Of Use for |
75 // the command line. Since the caller (web page) does not have access | 74 // the command line. Since the caller (web page) does not have access |
76 // to change the command line by itself, we do not do anything special | 75 // to change the command line by itself, we do not do anything special |
77 // to protect against this scenario. | 76 // to protect against this scenario. |
78 // This is implemented separately on each platform. | 77 // This is implemented separately on each platform. |
79 static void RunExternalProtocolDialog(const GURL& url, | 78 static void RunExternalProtocolDialog(const GURL& url, |
80 int render_process_host_id, | 79 int render_process_host_id, |
81 int routing_id); | 80 int routing_id, |
| 81 ui::PageTransition page_transition, |
| 82 bool has_user_gesture); |
82 | 83 |
83 // Register the ExcludedSchemes preference. | 84 // Register the ExcludedSchemes preference. |
84 static void RegisterPrefs(PrefRegistrySimple* registry); | 85 static void RegisterPrefs(PrefRegistrySimple* registry); |
85 | 86 |
86 // Starts a url using the external protocol handler with the help | 87 // Starts a url using the external protocol handler with the help |
87 // of shellexecute. Should only be called if the protocol is whitelisted | 88 // of shellexecute. Should only be called if the protocol is whitelisted |
88 // (checked in LaunchUrl) or if the user explicitly allows it. (By selecting | 89 // (checked in LaunchUrl) or if the user explicitly allows it. (By selecting |
89 // "Launch Application" in an ExternalProtocolDialog.) It is assumed that the | 90 // "Launch Application" in an ExternalProtocolDialog.) It is assumed that the |
90 // url has already been escaped, which happens in LaunchUrl. | 91 // url has already been escaped, which happens in LaunchUrl. |
91 // NOTE: You should Not call this function directly unless you are sure the | 92 // NOTE: You should Not call this function directly unless you are sure the |
(...skipping 11 matching lines...) Expand all Loading... |
103 // This is typically triggered by a user gesture, but is also called for | 104 // This is typically triggered by a user gesture, but is also called for |
104 // each extension API function. Note that each call to LaunchUrl resets | 105 // each extension API function. Note that each call to LaunchUrl resets |
105 // the state to false (not allowed). | 106 // the state to false (not allowed). |
106 static void PermitLaunchUrl(); | 107 static void PermitLaunchUrl(); |
107 | 108 |
108 private: | 109 private: |
109 DISALLOW_COPY_AND_ASSIGN(ExternalProtocolHandler); | 110 DISALLOW_COPY_AND_ASSIGN(ExternalProtocolHandler); |
110 }; | 111 }; |
111 | 112 |
112 #endif // CHROME_BROWSER_EXTERNAL_PROTOCOL_EXTERNAL_PROTOCOL_HANDLER_H_ | 113 #endif // CHROME_BROWSER_EXTERNAL_PROTOCOL_EXTERNAL_PROTOCOL_HANDLER_H_ |
OLD | NEW |