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