render_view.h revision f2477e01787aa58f445919b809d89e252beef54f
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 <string> 9 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" 18 19struct WebPreferences; 20 21namespace blink { 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 content { 37 38class ContextMenuClient; 39class RenderViewVisitor; 40struct ContextMenuParams; 41struct SSLStatus; 42struct WebPluginInfo; 43 44class CONTENT_EXPORT RenderView : public IPC::Sender { 45 public: 46 // Returns the RenderView containing the given WebView. 47 static RenderView* FromWebView(blink::WebView* webview); 48 49 // Returns the RenderView for the given routing ID. 50 static RenderView* FromRoutingID(int routing_id); 51 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); 55 56 // Get the routing ID of the view. 57 virtual int GetRoutingID() const = 0; 58 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; 66 67 // Returns the size of the view. 68 virtual gfx::Size GetSize() const = 0; 69 70 // Gets WebKit related preferences associated with this view. 71 virtual WebPreferences& GetWebkitPreferences() = 0; 72 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; 76 77 // Returns the associated WebView. May return NULL when the view is closing. 78 virtual blink::WebView* GetWebView() = 0; 79 80 // Gets the focused node. If no such node exists then the node will be isNull. 81 virtual blink::WebNode GetFocusedNode() const = 0; 82 83 // Gets the node that the context menu was pressed over. 84 virtual blink::WebNode GetContextMenuNode() const = 0; 85 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 blink::WebNode& node) const = 0; 89 90 // Create a new NPAPI/Pepper plugin depending on |info|. Returns NULL if no 91 // plugin was found. 92 virtual blink::WebPlugin* CreatePlugin( 93 blink::WebFrame* frame, 94 const WebPluginInfo& info, 95 const blink::WebPluginParams& params) = 0; 96 97 // Evaluates a string of JavaScript in a particular frame. 98 virtual void EvaluateScript(const string16& frame_xpath, 99 const string16& jscript, 100 int id, 101 bool notify_result) = 0; 102 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; 106 107 // Bitwise-ORed set of extra bindings that have been enabled. See 108 // BindingsPolicy for details. 109 virtual int GetEnabledBindings() const = 0; 110 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; 115 116 // Filtered time per frame based on UpdateRect messages. 117 virtual float GetFilteredTimePerFrame() const = 0; 118 119 // Shows a context menu with the given information. The given client will 120 // be called with the result. 121 // 122 // The request ID will be returned by this function. This is passed to the 123 // client functions for identification. 124 // 125 // If the client is destroyed, CancelContextMenu() should be called with the 126 // request ID returned by this function. 127 // 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; 132 133 // Cancels a context menu in the event that the client is destroyed before the 134 // menu is closed. 135 virtual void CancelContextMenu(int request_id) = 0; 136 137 // Returns the current visibility of the WebView. 138 virtual blink::WebPageVisibilityState GetVisibilityState() const = 0; 139 140 // Displays a modal alert dialog containing the given message. Returns 141 // once the user dismisses the dialog. 142 virtual void RunModalAlertDialog(blink::WebFrame* frame, 143 const blink::WebString& message) = 0; 144 145 // The client should handle the navigation externally. 146 virtual void LoadURLExternally( 147 blink::WebFrame* frame, 148 const blink::WebURLRequest& request, 149 blink::WebNavigationPolicy policy) = 0; 150 151 // Used by plugins that load data in this RenderView to update the loading 152 // notifications. 153 virtual void DidStartLoading() = 0; 154 virtual void DidStopLoading() = 0; 155 156 // Notifies the renderer that a paint is to be generated for the size 157 // passed in. 158 virtual void Repaint(const gfx::Size& size) = 0; 159 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; 164 165 // Returns a collection of security info about |frame|. 166 virtual SSLStatus GetSSLStatusOfFrame(blink::WebFrame* frame) const = 0; 167 168 // Returns |renderer_preferences_.accept_languages| value. 169 virtual const std::string& GetAcceptLanguages() const = 0; 170 171#if defined(OS_ANDROID) 172 virtual void UpdateTopControlsState(TopControlsState constraints, 173 TopControlsState current, 174 bool animate) = 0; 175#endif 176 177 protected: 178 virtual ~RenderView() {} 179 180 private: 181 // This interface should only be implemented inside content. 182 friend class RenderViewImpl; 183 RenderView() {} 184}; 185 186} // namespace content 187 188#endif // CONTENT_PUBLIC_RENDERER_RENDER_VIEW_H_ 189