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