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