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_
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 "content/public/common/page_transition_types.h"
15 #include "ui/base/layout.h"
27 class WebUIController
;
28 class WebUIMessageHandler
;
30 // A WebUI sets up the datasources and message handlers for a given HTML-based
32 class CONTENT_EXPORT WebUI
{
34 // An opaque identifier used to identify a WebUI. This can only be compared to
35 // kNoWebUI or other WebUI types. See GetWebUIType.
38 // A special WebUI type that signifies that a given page would not use the
40 static const TypeID kNoWebUI
;
42 // Returns JavaScript code that, when executed, calls the function specified
43 // by |function_name| with the arguments specified in |arg_list|.
44 static string16
GetJavascriptCall(
45 const std::string
& function_name
,
46 const std::vector
<const base::Value
*>& arg_list
);
50 virtual WebContents
* GetWebContents() const = 0;
52 virtual WebUIController
* GetController() const = 0;
53 virtual void SetController(WebUIController
* controller
) = 0;
55 // Returns the device scale factor of the monitor that the renderer is on.
56 // Whenever possible, WebUI should push resources with this scale factor to
58 virtual ui::ScaleFactor
GetDeviceScaleFactor() const = 0;
60 // Gets a custom tab title provided by the Web UI. If there is no title
61 // override, the string will be empty which should trigger the default title
62 // behavior for the tab.
63 virtual const string16
& GetOverriddenTitle() const = 0;
64 virtual void OverrideTitle(const string16
& title
) = 0;
66 // Returns the transition type that should be used for link clicks on this
67 // Web UI. This will default to LINK but may be overridden.
68 virtual PageTransition
GetLinkTransitionType() const = 0;
69 virtual void SetLinkTransitionType(PageTransition type
) = 0;
71 // Allows a controller to override the BindingsPolicy that should be enabled
73 virtual int GetBindings() const = 0;
74 virtual void SetBindings(int bindings
) = 0;
76 // Sets the path for the iframe if this WebUI is embedded in a page.
77 virtual void SetFrameXPath(const std::string
& xpath
) = 0;
79 // Takes ownership of |handler|, which will be destroyed when the WebUI is.
80 virtual void AddMessageHandler(WebUIMessageHandler
* handler
) = 0;
82 // Used by WebUIMessageHandlers. If the given message is already registered,
83 // the call has no effect unless |register_callback_overwrites_| is set to
85 typedef base::Callback
<void(const base::ListValue
*)> MessageCallback
;
86 virtual void RegisterMessageCallback(const std::string
& message
,
87 const MessageCallback
& callback
) = 0;
89 // This is only needed if an embedder overrides handling of a WebUIMessage and
90 // then later wants to undo that, or to route it to a different WebUI object.
91 virtual void ProcessWebUIMessage(const GURL
& source_url
,
92 const std::string
& message
,
93 const base::ListValue
& args
) = 0;
95 // Call a Javascript function by sending its name and arguments down to
96 // the renderer. This is asynchronous; there's no way to get the result
97 // of the call, and should be thought of more like sending a message to
99 // All function names in WebUI must consist of only ASCII characters.
100 // There are variants for calls with more arguments.
101 virtual void CallJavascriptFunction(const std::string
& function_name
) = 0;
102 virtual void CallJavascriptFunction(const std::string
& function_name
,
103 const base::Value
& arg
) = 0;
104 virtual void CallJavascriptFunction(const std::string
& function_name
,
105 const base::Value
& arg1
,
106 const base::Value
& arg2
) = 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
) = 0;
111 virtual void CallJavascriptFunction(const std::string
& function_name
,
112 const base::Value
& arg1
,
113 const base::Value
& arg2
,
114 const base::Value
& arg3
,
115 const base::Value
& arg4
) = 0;
116 virtual void CallJavascriptFunction(
117 const std::string
& function_name
,
118 const std::vector
<const base::Value
*>& args
) = 0;
121 } // namespace content
123 #endif // CONTENT_PUBLIC_BROWSER_WEB_UI_H_