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 "content/public/common/console_message_level.h"
13 #include "ipc/ipc_listener.h"
14 #include "ipc/ipc_sender.h"
15 #include "third_party/WebKit/public/web/WebNavigationPolicy.h"
27 struct WebPluginParams
;
39 template <typename T
> class Local
;
45 class ContextMenuClient
;
46 class PluginInstanceThrottler
;
48 class ServiceRegistry
;
49 struct ContextMenuParams
;
51 struct WebPreferences
;
53 // This interface wraps functionality, which is specific to frames, such as
54 // navigation. It provides communication with a corresponding RenderFrameHost
55 // in the browser process.
56 class CONTENT_EXPORT RenderFrame
: public IPC::Listener
,
59 // Returns the RenderFrame given a WebFrame.
60 static RenderFrame
* FromWebFrame(blink::WebFrame
* web_frame
);
62 // Returns the RenderFrame given a routing id.
63 static RenderFrame
* FromRoutingID(int routing_id
);
65 // Returns the RenderView associated with this frame.
66 virtual RenderView
* GetRenderView() = 0;
68 // Get the routing ID of the frame.
69 virtual int GetRoutingID() = 0;
71 // Returns the associated WebFrame.
72 virtual blink::WebLocalFrame
* GetWebFrame() = 0;
74 // Gets the focused element. If no such element exists then
75 // the element will be Null.
76 virtual blink::WebElement
GetFocusedElement() const = 0;
78 // Gets WebKit related preferences associated with this frame.
79 virtual WebPreferences
& GetWebkitPreferences() = 0;
81 // Shows a context menu with the given information. The given client will
82 // be called with the result.
84 // The request ID will be returned by this function. This is passed to the
85 // client functions for identification.
87 // If the client is destroyed, CancelContextMenu() should be called with the
88 // request ID returned by this function.
90 // Note: if you end up having clients outliving the RenderFrame, we should add
91 // a CancelContextMenuCallback function that takes a request id.
92 virtual int ShowContextMenu(ContextMenuClient
* client
,
93 const ContextMenuParams
& params
) = 0;
95 // Cancels a context menu in the event that the client is destroyed before the
97 virtual void CancelContextMenu(int request_id
) = 0;
99 // Gets the node that the context menu was pressed over.
100 virtual blink::WebNode
GetContextMenuNode() const = 0;
102 // Create a new NPAPI/Pepper plugin depending on |info|. Returns NULL if no
103 // plugin was found. |throttler| may be empty.
104 virtual blink::WebPlugin
* CreatePlugin(
105 blink::WebFrame
* frame
,
106 const WebPluginInfo
& info
,
107 const blink::WebPluginParams
& params
,
108 scoped_ptr
<PluginInstanceThrottler
> throttler
) = 0;
110 // The client should handle the navigation externally.
111 virtual void LoadURLExternally(blink::WebLocalFrame
* frame
,
112 const blink::WebURLRequest
& request
,
113 blink::WebNavigationPolicy policy
) = 0;
115 // Execute a string of JavaScript in this frame's context.
116 virtual void ExecuteJavaScript(const base::string16
& javascript
) = 0;
118 // Return true if this frame is hidden.
119 virtual bool IsHidden() = 0;
121 // Returns the ServiceRegistry for this frame.
122 virtual ServiceRegistry
* GetServiceRegistry() = 0;
124 #if defined(ENABLE_PLUGINS)
125 // Registers a plugin that has been marked peripheral. If the origin
126 // whitelist is later updated and includes |content_origin|, then
127 // |unthrottle_callback| will be called.
128 virtual void RegisterPeripheralPlugin(
129 const url::Origin
& content_origin
,
130 const base::Closure
& unthrottle_callback
) = 0;
133 // Returns true if this frame is a FTP directory listing.
134 virtual bool IsFTPDirectoryListing() = 0;
136 // Attaches the browser plugin identified by |element_instance_id| to guest
137 // content created by the embedder.
138 virtual void AttachGuest(int element_instance_id
) = 0;
140 // Detaches the browser plugin identified by |element_instance_id| from guest
141 // content created by the embedder.
142 virtual void DetachGuest(int element_instance_id
) = 0;
144 // Notifies the browser of text selection changes made.
145 virtual void SetSelectedText(const base::string16
& selection_text
,
147 const gfx::Range
& range
) = 0;
149 // Ensures that builtin mojo bindings modules are available in |context|.
150 virtual void EnsureMojoBuiltinsAreAvailable(
151 v8::Isolate
* isolate
,
152 v8::Local
<v8::Context
> context
) = 0;
154 // Adds |message| to the DevTools console.
155 virtual void AddMessageToConsole(ConsoleMessageLevel level
,
156 const std::string
& message
) = 0;
159 ~RenderFrame() override
{}
162 // This interface should only be implemented inside content.
163 friend class RenderFrameImpl
;
167 } // namespace content
169 #endif // CONTENT_PUBLIC_RENDERER_RENDER_FRAME_H_