Re-subimission of https://codereview.chromium.org/1041213003/
[chromium-blink-merge.git] / content / public / renderer / render_frame.h
blob875e87de5125ab006f31d2d6fd8fd0c7aa745ec8
1 // Copyright 2013 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.
5 #ifndef CONTENT_PUBLIC_RENDERER_RENDER_FRAME_H_
6 #define CONTENT_PUBLIC_RENDERER_RENDER_FRAME_H_
8 #include "base/callback_forward.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/strings/string16.h"
11 #include "content/common/content_export.h"
12 #include "ipc/ipc_listener.h"
13 #include "ipc/ipc_sender.h"
14 #include "third_party/WebKit/public/web/WebNavigationPolicy.h"
16 class GURL;
18 namespace blink {
19 class WebElement;
20 class WebFrame;
21 class WebLocalFrame;
22 class WebNode;
23 class WebPlugin;
24 class WebURLRequest;
25 class WebURLResponse;
26 struct WebPluginParams;
29 namespace gfx {
30 class Range;
33 namespace v8 {
34 template <typename T> class Handle;
35 class Context;
36 class Isolate;
39 namespace content {
40 class ContextMenuClient;
41 class PluginInstanceThrottler;
42 class RenderView;
43 class ServiceRegistry;
44 struct ContextMenuParams;
45 struct WebPluginInfo;
46 struct WebPreferences;
48 // This interface wraps functionality, which is specific to frames, such as
49 // navigation. It provides communication with a corresponding RenderFrameHost
50 // in the browser process.
51 class CONTENT_EXPORT RenderFrame : public IPC::Listener,
52 public IPC::Sender {
53 public:
54 // Returns the RenderFrame given a WebFrame.
55 static RenderFrame* FromWebFrame(blink::WebFrame* web_frame);
57 // Returns the RenderView associated with this frame.
58 virtual RenderView* GetRenderView() = 0;
60 // Get the routing ID of the frame.
61 virtual int GetRoutingID() = 0;
63 // Returns the associated WebFrame.
64 virtual blink::WebLocalFrame* GetWebFrame() = 0;
66 // Gets the focused element. If no such element exists then
67 // the element will be Null.
68 virtual blink::WebElement GetFocusedElement() const = 0;
70 // Gets WebKit related preferences associated with this frame.
71 virtual WebPreferences& GetWebkitPreferences() = 0;
73 // Shows a context menu with the given information. The given client will
74 // be called with the result.
76 // The request ID will be returned by this function. This is passed to the
77 // client functions for identification.
79 // If the client is destroyed, CancelContextMenu() should be called with the
80 // request ID returned by this function.
82 // Note: if you end up having clients outliving the RenderFrame, we should add
83 // a CancelContextMenuCallback function that takes a request id.
84 virtual int ShowContextMenu(ContextMenuClient* client,
85 const ContextMenuParams& params) = 0;
87 // Cancels a context menu in the event that the client is destroyed before the
88 // menu is closed.
89 virtual void CancelContextMenu(int request_id) = 0;
91 // Gets the node that the context menu was pressed over.
92 virtual blink::WebNode GetContextMenuNode() const = 0;
94 // Create a new NPAPI/Pepper plugin depending on |info|. Returns NULL if no
95 // plugin was found. |throttler| may be empty.
96 virtual blink::WebPlugin* CreatePlugin(
97 blink::WebFrame* frame,
98 const WebPluginInfo& info,
99 const blink::WebPluginParams& params,
100 scoped_ptr<PluginInstanceThrottler> throttler) = 0;
102 // The client should handle the navigation externally.
103 virtual void LoadURLExternally(blink::WebLocalFrame* frame,
104 const blink::WebURLRequest& request,
105 blink::WebNavigationPolicy policy) = 0;
107 // Execute a string of JavaScript in this frame's context.
108 virtual void ExecuteJavaScript(const base::string16& javascript) = 0;
110 // Return true if this frame is hidden.
111 virtual bool IsHidden() = 0;
113 // Returns the ServiceRegistry for this frame.
114 virtual ServiceRegistry* GetServiceRegistry() = 0;
116 #if defined(ENABLE_PLUGINS)
117 // Registers a plugin that has been marked peripheral. If the origin
118 // whitelist is later updated and includes |content_origin|, then
119 // |unthrottle_callback| will be called.
120 virtual void RegisterPeripheralPlugin(
121 const GURL& content_origin,
122 const base::Closure& unthrottle_callback) = 0;
123 #endif
125 // Returns true if this frame is a FTP directory listing.
126 virtual bool IsFTPDirectoryListing() = 0;
128 // Attaches the browser plugin identified by |element_instance_id| to guest
129 // content created by the embedder.
130 virtual void AttachGuest(int element_instance_id) = 0;
132 // Detaches the browser plugin identified by |element_instance_id| from guest
133 // content created by the embedder.
134 virtual void DetachGuest(int element_instance_id) = 0;
136 // Notifies the browser of text selection changes made.
137 virtual void SetSelectedText(const base::string16& selection_text,
138 size_t offset,
139 const gfx::Range& range) = 0;
141 // Ensures that builtin mojo bindings modules are available in |context|.
142 virtual void EnsureMojoBuiltinsAreAvailable(
143 v8::Isolate* isolate,
144 v8::Handle<v8::Context> context) = 0;
146 protected:
147 ~RenderFrame() override {}
149 private:
150 // This interface should only be implemented inside content.
151 friend class RenderFrameImpl;
152 RenderFrame() {}
155 } // namespace content
157 #endif // CONTENT_PUBLIC_RENDERER_RENDER_FRAME_H_