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 23namespace base { 24class DictionaryValue; 25} 26 27namespace options { 28 29class HandlerOptionsHandler : public OptionsPageUIHandler, 30 public content::NotificationObserver { 31 public: 32 HandlerOptionsHandler(); 33 virtual ~HandlerOptionsHandler(); 34 35 // OptionsPageUIHandler implementation. 36 virtual void GetLocalizedValues( 37 base::DictionaryValue* localized_strings) OVERRIDE; 38 virtual void InitializeHandler() OVERRIDE; 39 virtual void InitializePage() OVERRIDE; 40 virtual void RegisterMessages() OVERRIDE; 41 42 // content::NotificationObserver implementation. 43 virtual void Observe(int type, 44 const content::NotificationSource& source, 45 const content::NotificationDetails& details) OVERRIDE; 46 47 private: 48 // Called when the user toggles whether custom handlers are enabled. 49 void SetHandlersEnabled(const base::ListValue* args); 50 51 // Called when the user sets a new default handler for a protocol. 52 void SetDefault(const base::ListValue* args); 53 54 // Called when the user clears the default handler for a protocol. 55 // |args| is the string name of the protocol to clear. 56 void ClearDefault(const base::ListValue* args); 57 58 // Parses a ProtocolHandler out of the arguments passed back from the view. 59 // |args| is a list of [protocol, url, title]. 60 ProtocolHandler ParseHandlerFromArgs(const base::ListValue* args) const; 61 62 // Returns a JSON object describing the set of protocol handlers for the 63 // given protocol. 64 void GetHandlersForProtocol(const std::string& protocol, 65 base::DictionaryValue* value); 66 67 // Returns a JSON list of the ignored protocol handlers. 68 void GetIgnoredHandlers(base::ListValue* handlers); 69 70 // Called when the JS PasswordManager object is initialized. 71 void UpdateHandlerList(); 72 73 // Remove a handler. 74 // |args| is a list of [protocol, url, title]. 75 void RemoveHandler(const base::ListValue* args); 76 77 // Remove an ignored handler. 78 // |args| is a list of [protocol, url, title]. 79 void RemoveIgnoredHandler(const base::ListValue* args); 80 81 ProtocolHandlerRegistry* GetProtocolHandlerRegistry(); 82 83 content::NotificationRegistrar notification_registrar_; 84 85 DISALLOW_COPY_AND_ASSIGN(HandlerOptionsHandler); 86}; 87 88} // namespace options 89 90#endif // CHROME_BROWSER_UI_WEBUI_OPTIONS_HANDLER_OPTIONS_HANDLER_H_ 91