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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_EXTERNAL_PROTOCOL_EXTERNAL_PROTOCOL_HANDLER_H_
6 #define CHROME_BROWSER_EXTERNAL_PROTOCOL_EXTERNAL_PROTOCOL_HANDLER_H_
10 #include "chrome/browser/shell_integration.h"
13 class PrefRegistrySimple
;
16 class DictionaryValue
;
19 class ExternalProtocolHandler
{
27 // Delegate to allow unit testing to provide different behavior.
30 virtual ShellIntegration::DefaultProtocolClientWorker
* CreateShellWorker(
31 ShellIntegration::DefaultWebClientObserver
* observer
,
32 const std::string
& protocol
) = 0;
33 virtual BlockState
GetBlockState(const std::string
& scheme
,
34 bool initiated_by_user_gesture
) = 0;
35 virtual void BlockRequest() = 0;
36 virtual void RunExternalProtocolDialog(const GURL
& url
,
37 int render_process_host_id
,
39 virtual void LaunchUrlWithoutSecurityCheck(const GURL
& url
) = 0;
40 virtual void FinishedProcessingCheck() = 0;
41 virtual ~Delegate() {}
44 // Returns whether we should block a given scheme.
45 static BlockState
GetBlockState(const std::string
& scheme
,
46 bool initiated_by_user_gesture
);
48 // Sets whether we should block a given scheme.
49 static void SetBlockState(const std::string
& scheme
, BlockState state
);
51 // Version of LaunchUrl allowing use of a delegate to facilitate unit
53 static void LaunchUrlWithDelegate(const GURL
& url
, int render_process_host_id
,
54 int tab_contents_id
, Delegate
* delegate
,
55 bool initiated_by_user_gesture
);
57 // Creates and runs a External Protocol dialog box.
58 // |url| - The url of the request.
59 // |render_process_host_id| and |routing_id| are used by
60 // tab_util::GetWebContentsByID to aquire the tab contents associated with
62 // NOTE: There is a race between the Time of Check and the Time Of Use for
63 // the command line. Since the caller (web page) does not have access
64 // to change the command line by itself, we do not do anything special
65 // to protect against this scenario.
66 // This is implemented separately on each platform.
67 static void RunExternalProtocolDialog(const GURL
& url
,
68 int render_process_host_id
,
71 // Register the ExcludedSchemes preference.
72 static void RegisterPrefs(PrefRegistrySimple
* registry
);
74 // Starts a url using the external protocol handler with the help
75 // of shellexecute. Should only be called if the protocol is whitelisted
76 // (checked in LaunchUrl) or if the user explicitly allows it. (By selecting
77 // "Launch Application" in an ExternalProtocolDialog.) It is assumed that the
78 // url has already been escaped, which happens in LaunchUrl.
79 // NOTE: You should Not call this function directly unless you are sure the
80 // url you have has been checked against the blacklist, and has been escaped.
81 // All calls to this function should originate in some way from LaunchUrl.
82 static void LaunchUrlWithoutSecurityCheck(const GURL
& url
,
83 int render_process_host_id
,
86 // Prepopulates the dictionary with known protocols to deny or allow, if
87 // preferences for them do not already exist.
88 static void PrepopulateDictionary(base::DictionaryValue
* win_pref
);
91 DISALLOW_COPY_AND_ASSIGN(ExternalProtocolHandler
);
94 #endif // CHROME_BROWSER_EXTERNAL_PROTOCOL_EXTERNAL_PROTOCOL_HANDLER_H_