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