Content settings: remove some plugin-related code/resources when... there are no...
[chromium-blink-merge.git] / content / public / browser / web_ui.h
blob0b2c4ebe421f2d439c4d8ae9400b8fccbd57de21
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.
5 #ifndef CONTENT_PUBLIC_BROWSER_WEB_UI_H_
6 #define CONTENT_PUBLIC_BROWSER_WEB_UI_H_
8 #include <vector>
10 #include "base/basictypes.h"
11 #include "base/callback.h"
12 #include "base/strings/string16.h"
13 #include "content/common/content_export.h"
14 #include "ui/base/page_transition_types.h"
16 class GURL;
18 namespace base {
19 class ListValue;
20 class Value;
23 namespace content {
25 class WebContents;
26 class WebUIController;
27 class WebUIMessageHandler;
29 // A WebUI sets up the datasources and message handlers for a given HTML-based
30 // UI.
31 class CONTENT_EXPORT WebUI {
32 public:
33 // An opaque identifier used to identify a WebUI. This can only be compared to
34 // kNoWebUI or other WebUI types. See GetWebUIType.
35 typedef void* TypeID;
37 // A special WebUI type that signifies that a given page would not use the
38 // Web UI system.
39 static const TypeID kNoWebUI;
41 // Returns JavaScript code that, when executed, calls the function specified
42 // by |function_name| with the arguments specified in |arg_list|.
43 static base::string16 GetJavascriptCall(
44 const std::string& function_name,
45 const std::vector<const base::Value*>& arg_list);
47 virtual ~WebUI() {}
49 virtual WebContents* GetWebContents() const = 0;
51 virtual WebUIController* GetController() const = 0;
52 virtual void SetController(WebUIController* controller) = 0;
54 // Returns the device scale factor of the monitor that the renderer is on.
55 // Whenever possible, WebUI should push resources with this scale factor to
56 // Javascript.
57 virtual float GetDeviceScaleFactor() const = 0;
59 // Gets a custom tab title provided by the Web UI. If there is no title
60 // override, the string will be empty which should trigger the default title
61 // behavior for the tab.
62 virtual const base::string16& GetOverriddenTitle() const = 0;
63 virtual void OverrideTitle(const base::string16& title) = 0;
65 // Returns the transition type that should be used for link clicks on this
66 // Web UI. This will default to LINK but may be overridden.
67 virtual ui::PageTransition GetLinkTransitionType() const = 0;
68 virtual void SetLinkTransitionType(ui::PageTransition type) = 0;
70 // Allows a controller to override the BindingsPolicy that should be enabled
71 // for this page.
72 virtual int GetBindings() const = 0;
73 virtual void SetBindings(int bindings) = 0;
75 // Takes ownership of |handler|, which will be destroyed when the WebUI is.
76 virtual void AddMessageHandler(WebUIMessageHandler* handler) = 0;
78 // Used by WebUIMessageHandlers. If the given message is already registered,
79 // the call has no effect unless |register_callback_overwrites_| is set to
80 // true.
81 typedef base::Callback<void(const base::ListValue*)> MessageCallback;
82 virtual void RegisterMessageCallback(const std::string& message,
83 const MessageCallback& callback) = 0;
85 // This is only needed if an embedder overrides handling of a WebUIMessage and
86 // then later wants to undo that, or to route it to a different WebUI object.
87 virtual void ProcessWebUIMessage(const GURL& source_url,
88 const std::string& message,
89 const base::ListValue& args) = 0;
91 // Call a Javascript function by sending its name and arguments down to
92 // the renderer. This is asynchronous; there's no way to get the result
93 // of the call, and should be thought of more like sending a message to
94 // the page.
95 // All function names in WebUI must consist of only ASCII characters.
96 // There are variants for calls with more arguments.
97 virtual void CallJavascriptFunction(const std::string& function_name) = 0;
98 virtual void CallJavascriptFunction(const std::string& function_name,
99 const base::Value& arg) = 0;
100 virtual void CallJavascriptFunction(const std::string& function_name,
101 const base::Value& arg1,
102 const base::Value& arg2) = 0;
103 virtual void CallJavascriptFunction(const std::string& function_name,
104 const base::Value& arg1,
105 const base::Value& arg2,
106 const base::Value& arg3) = 0;
107 virtual void CallJavascriptFunction(const std::string& function_name,
108 const base::Value& arg1,
109 const base::Value& arg2,
110 const base::Value& arg3,
111 const base::Value& arg4) = 0;
112 virtual void CallJavascriptFunction(
113 const std::string& function_name,
114 const std::vector<const base::Value*>& args) = 0;
117 } // namespace content
119 #endif // CONTENT_PUBLIC_BROWSER_WEB_UI_H_