1// Copyright (c) 2010 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.
4
5#ifndef CHROME_BROWSER_EXTERNAL_PROTOCOL_HANDLER_H_
6#define CHROME_BROWSER_EXTERNAL_PROTOCOL_HANDLER_H_
7#pragma once
8
9#include <string>
10
11class DictionaryValue;
12class GURL;
13class PrefService;
14
15class ExternalProtocolHandler {
16 public:
17  enum BlockState {
18    DONT_BLOCK,
19    BLOCK,
20    UNKNOWN,
21  };
22
23  // Returns whether we should block a given scheme.
24  static BlockState GetBlockState(const std::string& scheme);
25
26  // Sets whether we should block a given scheme.
27  static void SetBlockState(const std::string& scheme, BlockState state);
28
29  // Checks to see if the protocol is allowed, if it is whitelisted,
30  // the application associated with the protocol is launched on the io thread,
31  // if it is blacklisted, returns silently. Otherwise, an
32  // ExternalProtocolDialog is created asking the user. If the user accepts,
33  // LaunchUrlWithoutSecurityCheck is called on the io thread and the
34  // application is launched.
35  // Must run on the UI thread.
36  static void LaunchUrl(const GURL& url, int render_process_host_id,
37                        int tab_contents_id);
38
39  // Creates and runs a External Protocol dialog box.
40  // |url| - The url of the request.
41  // |render_process_host_id| and |routing_id| are used by
42  // tab_util::GetTabContentsByID to aquire the tab contents associated with
43  // this dialog.
44  // NOTE: There is a race between the Time of Check and the Time Of Use for
45  //       the command line. Since the caller (web page) does not have access
46  //       to change the command line by itself, we do not do anything special
47  //       to protect against this scenario.
48  // This is implemented separately on each platform.
49  static void RunExternalProtocolDialog(const GURL& url,
50                                        int render_process_host_id,
51                                        int routing_id);
52
53  // Register the ExcludedSchemes preference.
54  static void RegisterPrefs(PrefService* prefs);
55
56  // Starts a url using the external protocol handler with the help
57  // of shellexecute. Should only be called if the protocol is whitelisted
58  // (checked in LaunchUrl) or if the user explicitly allows it. (By selecting
59  // "Launch Application" in an ExternalProtocolDialog.) It is assumed that the
60  // url has already been escaped, which happens in LaunchUrl.
61  // NOTE: You should Not call this function directly unless you are sure the
62  // url you have has been checked against the blacklist, and has been escaped.
63  // All calls to this function should originate in some way from LaunchUrl.
64  // This will execute on the file thread.
65  static void LaunchUrlWithoutSecurityCheck(const GURL& url);
66
67  // Prepopulates the dictionary with known protocols to deny or allow, if
68  // preferences for them do not already exist.
69  static void PrepopulateDictionary(DictionaryValue* win_pref);
70
71  // Allows LaunchUrl to proceed with launching an external protocol handler.
72  // This is typically triggered by a user gesture, but is also called for
73  // each extension API function. Note that each call to LaunchUrl resets
74  // the state to false (not allowed).
75  static void PermitLaunchUrl();
76};
77
78#endif  // CHROME_BROWSER_EXTERNAL_PROTOCOL_HANDLER_H_
79