Upstream version 11.40.277.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / webui / options / handler_options_handler.h
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
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_UI_WEBUI_OPTIONS_HANDLER_OPTIONS_HANDLER_H_
6 #define CHROME_BROWSER_UI_WEBUI_OPTIONS_HANDLER_OPTIONS_HANDLER_H_
7
8 #include <string>
9
10 #include "chrome/browser/custom_handlers/protocol_handler_registry.h"
11 #include "chrome/browser/ui/webui/options/options_ui.h"
12 #include "chrome/common/custom_handlers/protocol_handler.h"
13 #include "content/public/browser/notification_observer.h"
14 #include "content/public/browser/notification_registrar.h"
15
16 ////////////////////////////////////////////////////////////////////////////////
17 // HandlerOptionsHandler
18
19 // Listen for changes to protocol handlers (i.e. registerProtocolHandler()).
20 // This get triggered whenever a user allows a specific website or application
21 // to handle clicks on a link with a specified protocol (i.e. mailto: -> Gmail).
22
23 namespace base {
24 class DictionaryValue;
25 }
26
27 namespace options {
28
29 class HandlerOptionsHandler : public OptionsPageUIHandler,
30                               public content::NotificationObserver {
31  public:
32   HandlerOptionsHandler();
33   ~HandlerOptionsHandler() override;
34
35   // OptionsPageUIHandler implementation.
36   void GetLocalizedValues(base::DictionaryValue* localized_strings) override;
37   void InitializeHandler() override;
38   void InitializePage() override;
39   void RegisterMessages() override;
40
41   // content::NotificationObserver implementation.
42   void Observe(int type,
43                const content::NotificationSource& source,
44                const content::NotificationDetails& details) override;
45
46  private:
47   // Called when the user toggles whether custom handlers are enabled.
48   void SetHandlersEnabled(const base::ListValue* args);
49
50   // Called when the user sets a new default handler for a protocol.
51   void SetDefault(const base::ListValue* args);
52
53   // Called when the user clears the default handler for a protocol.
54   // |args| is the string name of the protocol to clear.
55   void ClearDefault(const base::ListValue* args);
56
57   // Parses a ProtocolHandler out of the arguments passed back from the view.
58   // |args| is a list of [protocol, url, title].
59   ProtocolHandler ParseHandlerFromArgs(const base::ListValue* args) const;
60
61   // Returns a JSON object describing the set of protocol handlers for the
62   // given protocol.
63   void GetHandlersForProtocol(const std::string& protocol,
64                               base::DictionaryValue* value);
65
66   // Returns a JSON list of the ignored protocol handlers.
67   void GetIgnoredHandlers(base::ListValue* handlers);
68
69   // Called when the JS PasswordManager object is initialized.
70   void UpdateHandlerList();
71
72   // Remove a handler.
73   // |args| is a list of [protocol, url, title].
74   void RemoveHandler(const base::ListValue* args);
75
76   // Remove an ignored handler.
77   // |args| is a list of [protocol, url, title].
78   void RemoveIgnoredHandler(const base::ListValue* args);
79
80   ProtocolHandlerRegistry* GetProtocolHandlerRegistry();
81
82   content::NotificationRegistrar notification_registrar_;
83
84   DISALLOW_COPY_AND_ASSIGN(HandlerOptionsHandler);
85 };
86
87 }  // namespace options
88
89 #endif  // CHROME_BROWSER_UI_WEBUI_OPTIONS_HANDLER_OPTIONS_HANDLER_H_