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_RENDERER_RENDER_VIEW_H_
6 #define CONTENT_PUBLIC_RENDERER_RENDER_VIEW_H_
10 #include "base/basictypes.h"
11 #include "base/strings/string16.h"
12 #include "content/common/content_export.h"
13 #include "content/public/common/top_controls_state.h"
14 #include "ipc/ipc_sender.h"
15 #include "third_party/WebKit/public/web/WebNavigationPolicy.h"
16 #include "third_party/WebKit/public/web/WebPageVisibilityState.h"
17 #include "ui/gfx/native_widget_types.h"
19 struct WebPreferences
;
28 struct WebContextMenuData
;
29 struct WebPluginParams
;
38 class ContextMenuClient
;
39 class RenderViewVisitor
;
40 struct ContextMenuParams
;
44 class CONTENT_EXPORT RenderView
: public IPC::Sender
{
46 // Returns the RenderView containing the given WebView.
47 static RenderView
* FromWebView(WebKit::WebView
* webview
);
49 // Returns the RenderView for the given routing ID.
50 static RenderView
* FromRoutingID(int routing_id
);
52 // Visit all RenderViews with a live WebView (i.e., RenderViews that have
53 // been closed but not yet destroyed are excluded).
54 static void ForEach(RenderViewVisitor
* visitor
);
56 // Get the routing ID of the view.
57 virtual int GetRoutingID() const = 0;
59 // Page IDs allow the browser to identify pages in each renderer process for
60 // keeping back/forward history in sync.
61 // Note that this is NOT updated for every main frame navigation, only for
62 // "regular" navigations that go into session history. In particular, client
63 // redirects, like the page cycler uses (document.location.href="foo") do not
64 // count as regular navigations and do not increment the page id.
65 virtual int GetPageId() const = 0;
67 // Returns the size of the view.
68 virtual gfx::Size
GetSize() const = 0;
70 // Gets WebKit related preferences associated with this view.
71 virtual WebPreferences
& GetWebkitPreferences() = 0;
73 // Overrides the WebKit related preferences associated with this view. Note
74 // that the browser process may update the preferences at any time.
75 virtual void SetWebkitPreferences(const WebPreferences
& preferences
) = 0;
77 // Returns the associated WebView. May return NULL when the view is closing.
78 virtual WebKit::WebView
* GetWebView() = 0;
80 // Gets the focused node. If no such node exists then the node will be isNull.
81 virtual WebKit::WebNode
GetFocusedNode() const = 0;
83 // Gets the node that the context menu was pressed over.
84 virtual WebKit::WebNode
GetContextMenuNode() const = 0;
86 // Returns true if the parameter node is a textfield, text area, a content
87 // editable div, or has an ARIA role of textbox.
88 virtual bool IsEditableNode(const WebKit::WebNode
& node
) const = 0;
90 // Create a new NPAPI/Pepper plugin depending on |info|. Returns NULL if no
92 virtual WebKit::WebPlugin
* CreatePlugin(
93 WebKit::WebFrame
* frame
,
94 const WebPluginInfo
& info
,
95 const WebKit::WebPluginParams
& params
) = 0;
97 // Evaluates a string of JavaScript in a particular frame.
98 virtual void EvaluateScript(const string16
& frame_xpath
,
99 const string16
& jscript
,
101 bool notify_result
) = 0;
103 // Returns true if we should display scrollbars for the given view size and
104 // false if the scrollbars should be hidden.
105 virtual bool ShouldDisplayScrollbars(int width
, int height
) const = 0;
107 // Bitwise-ORed set of extra bindings that have been enabled. See
108 // BindingsPolicy for details.
109 virtual int GetEnabledBindings() const = 0;
111 // Whether content state (such as form state, scroll position and page
112 // contents) should be sent to the browser immediately. This is normally
113 // false, but set to true by some tests.
114 virtual bool GetContentStateImmediately() const = 0;
116 // Filtered time per frame based on UpdateRect messages.
117 virtual float GetFilteredTimePerFrame() const = 0;
119 // Shows a context menu with the given information. The given client will
120 // be called with the result.
122 // The request ID will be returned by this function. This is passed to the
123 // client functions for identification.
125 // If the client is destroyed, CancelContextMenu() should be called with the
126 // request ID returned by this function.
128 // Note: if you end up having clients outliving the RenderView, we should add
129 // a CancelContextMenuCallback function that takes a request id.
130 virtual int ShowContextMenu(ContextMenuClient
* client
,
131 const ContextMenuParams
& params
) = 0;
133 // Cancels a context menu in the event that the client is destroyed before the
135 virtual void CancelContextMenu(int request_id
) = 0;
137 // Returns the current visibility of the WebView.
138 virtual WebKit::WebPageVisibilityState
GetVisibilityState() const = 0;
140 // Displays a modal alert dialog containing the given message. Returns
141 // once the user dismisses the dialog.
142 virtual void RunModalAlertDialog(WebKit::WebFrame
* frame
,
143 const WebKit::WebString
& message
) = 0;
145 // The client should handle the navigation externally.
146 virtual void LoadURLExternally(
147 WebKit::WebFrame
* frame
,
148 const WebKit::WebURLRequest
& request
,
149 WebKit::WebNavigationPolicy policy
) = 0;
151 // Used by plugins that load data in this RenderView to update the loading
153 virtual void DidStartLoading() = 0;
154 virtual void DidStopLoading() = 0;
156 // Notifies the renderer that a paint is to be generated for the size
158 virtual void Repaint(const gfx::Size
& size
) = 0;
160 // Inject edit commands to be used for the next keyboard event.
161 virtual void SetEditCommandForNextKeyEvent(const std::string
& name
,
162 const std::string
& value
) = 0;
163 virtual void ClearEditCommands() = 0;
165 // Returns a collection of security info about |frame|.
166 virtual SSLStatus
GetSSLStatusOfFrame(WebKit::WebFrame
* frame
) const = 0;
168 // Returns |renderer_preferences_.accept_languages| value.
169 virtual const std::string
& GetAcceptLanguages() const = 0;
171 #if defined(OS_ANDROID)
172 virtual void UpdateTopControlsState(TopControlsState constraints
,
173 TopControlsState current
,
178 virtual ~RenderView() {}
181 // This interface should only be implemented inside content.
182 friend class RenderViewImpl
;
186 } // namespace content
188 #endif // CONTENT_PUBLIC_RENDERER_RENDER_VIEW_H_