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_RENDERER_RENDER_FRAME_IMPL_H_
6 #define CONTENT_RENDERER_RENDER_FRAME_IMPL_H_
10 #include "base/basictypes.h"
11 #include "base/files/file_path.h"
12 #include "base/memory/weak_ptr.h"
13 #include "base/observer_list.h"
14 #include "base/process/process_handle.h"
15 #include "base/strings/string16.h"
16 #include "content/public/renderer/render_frame.h"
17 #include "content/renderer/renderer_webcookiejar_impl.h"
18 #include "ipc/ipc_message.h"
19 #include "third_party/WebKit/public/web/WebDataSource.h"
20 #include "third_party/WebKit/public/web/WebFrameClient.h"
23 struct FrameMsg_BuffersSwapped_Params;
24 struct FrameMsg_CompositorFrameSwapped_Params;
28 struct WebCompositionUnderline;
39 class ChildFrameCompositingHelper;
40 class PepperPluginInstanceImpl;
41 class RendererPpapiHost;
42 class RenderFrameObserver;
45 class RenderWidgetFullscreenPepper;
47 class CONTENT_EXPORT RenderFrameImpl
49 NON_EXPORTED_BASE(public blink::WebFrameClient) {
51 // Creates a new RenderFrame. |render_view| is the RenderView object that this
53 // Callers *must* call |SetWebFrame| immediately after creation.
54 // TODO(creis): We should structure this so that |SetWebFrame| isn't needed.
55 static RenderFrameImpl* Create(RenderViewImpl* render_view, int32 routing_id);
57 // Just like RenderFrame::FromWebFrame but returns the implementation.
58 static RenderFrameImpl* FromWebFrame(blink::WebFrame* web_frame);
60 // Used by content_layouttest_support to hook into the creation of
62 static void InstallCreateHook(
63 RenderFrameImpl* (*create_render_frame_impl)(RenderViewImpl*, int32));
65 virtual ~RenderFrameImpl();
66 // TODO(nasko): Remove when no longer needed.
67 // See comment on the implementation of this method for more details.
68 void operator delete(void*);
70 bool is_swapped_out() const {
71 return is_swapped_out_;
74 // Out-of-process child frames receive a signal from RenderWidgetCompositor
75 // when a compositor frame has committed.
76 void DidCommitCompositorFrame();
78 // TODO(jam): this is a temporary getter until all the code is transitioned
79 // to using RenderFrame instead of RenderView.
80 RenderViewImpl* render_view() { return render_view_.get(); }
82 RendererWebCookieJarImpl* cookie_jar() { return &cookie_jar_; }
84 // Returns the RenderWidget associated with this frame.
85 RenderWidget* GetRenderWidget();
87 // This is called right after creation with the WebFrame for this RenderFrame.
88 void SetWebFrame(blink::WebFrame* web_frame);
90 #if defined(ENABLE_PLUGINS)
91 // Notification that a PPAPI plugin has been created.
92 void PepperPluginCreated(RendererPpapiHost* host);
94 // Notifies that |instance| has changed the cursor.
95 // This will update the cursor appearance if it is currently over the plugin
97 void PepperDidChangeCursor(PepperPluginInstanceImpl* instance,
98 const blink::WebCursorInfo& cursor);
100 // Notifies that |instance| has received a mouse event.
101 void PepperDidReceiveMouseEvent(PepperPluginInstanceImpl* instance);
103 // Informs the render view that a PPAPI plugin has changed text input status.
104 void PepperTextInputTypeChanged(PepperPluginInstanceImpl* instance);
105 void PepperCaretPositionChanged(PepperPluginInstanceImpl* instance);
107 // Cancels current composition.
108 void PepperCancelComposition(PepperPluginInstanceImpl* instance);
110 // Informs the render view that a PPAPI plugin has changed selection.
111 void PepperSelectionChanged(PepperPluginInstanceImpl* instance);
113 // Creates a fullscreen container for a pepper plugin instance.
114 RenderWidgetFullscreenPepper* CreatePepperFullscreenContainer(
115 PepperPluginInstanceImpl* plugin);
117 bool IsPepperAcceptingCompositionEvents() const;
119 // Notification that the given plugin has crashed.
120 void PluginCrashed(const base::FilePath& plugin_path,
121 base::ProcessId plugin_pid);
123 // Simulates IME events for testing purpose.
124 void SimulateImeSetComposition(
125 const base::string16& text,
126 const std::vector<blink::WebCompositionUnderline>& underlines,
129 void SimulateImeConfirmComposition(const base::string16& text,
130 const gfx::Range& replacement_range);
132 // TODO(jam): remove these once the IPC handler moves from RenderView to
134 void OnImeSetComposition(
135 const base::string16& text,
136 const std::vector<blink::WebCompositionUnderline>& underlines,
139 void OnImeConfirmComposition(
140 const base::string16& text,
141 const gfx::Range& replacement_range,
142 bool keep_selection);
143 #endif // ENABLE_PLUGINS
146 virtual bool Send(IPC::Message* msg) OVERRIDE;
149 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE;
151 // RenderFrame implementation:
152 virtual RenderView* GetRenderView() OVERRIDE;
153 virtual int GetRoutingID() OVERRIDE;
154 virtual blink::WebFrame* GetWebFrame() OVERRIDE;
155 virtual WebPreferences& GetWebkitPreferences() OVERRIDE;
156 virtual int ShowContextMenu(ContextMenuClient* client,
157 const ContextMenuParams& params) OVERRIDE;
158 virtual void CancelContextMenu(int request_id) OVERRIDE;
159 virtual blink::WebPlugin* CreatePlugin(
160 blink::WebFrame* frame,
161 const WebPluginInfo& info,
162 const blink::WebPluginParams& params) OVERRIDE;
163 virtual void LoadURLExternally(
164 blink::WebFrame* frame,
165 const blink::WebURLRequest& request,
166 blink::WebNavigationPolicy policy) OVERRIDE;
168 // blink::WebFrameClient implementation -------------------------------------
169 virtual blink::WebPlugin* createPlugin(
170 blink::WebFrame* frame,
171 const blink::WebPluginParams& params);
172 virtual blink::WebMediaPlayer* createMediaPlayer(
173 blink::WebFrame* frame,
174 const blink::WebURL& url,
175 blink::WebMediaPlayerClient* client);
176 virtual blink::WebApplicationCacheHost* createApplicationCacheHost(
177 blink::WebFrame* frame,
178 blink::WebApplicationCacheHostClient* client);
179 virtual blink::WebWorkerPermissionClientProxy*
180 createWorkerPermissionClientProxy(blink::WebFrame* frame);
181 virtual blink::WebCookieJar* cookieJar(blink::WebFrame* frame);
182 virtual blink::WebServiceWorkerProvider* createServiceWorkerProvider(
183 blink::WebFrame* frame,
184 blink::WebServiceWorkerProviderClient*);
185 virtual void didAccessInitialDocument(blink::WebFrame* frame);
186 virtual blink::WebFrame* createChildFrame(blink::WebFrame* parent,
187 const blink::WebString& name);
188 virtual void didDisownOpener(blink::WebFrame* frame);
189 virtual void frameDetached(blink::WebFrame* frame);
190 virtual void willClose(blink::WebFrame* frame);
191 virtual void didChangeName(blink::WebFrame* frame,
192 const blink::WebString& name);
193 virtual void didMatchCSS(
194 blink::WebFrame* frame,
195 const blink::WebVector<blink::WebString>& newly_matching_selectors,
196 const blink::WebVector<blink::WebString>& stopped_matching_selectors);
197 virtual void loadURLExternally(blink::WebFrame* frame,
198 const blink::WebURLRequest& request,
199 blink::WebNavigationPolicy policy);
200 virtual void loadURLExternally(
201 blink::WebFrame* frame,
202 const blink::WebURLRequest& request,
203 blink::WebNavigationPolicy policy,
204 const blink::WebString& suggested_name);
205 // The WebDataSource::ExtraData* is assumed to be a DocumentState* subclass.
206 virtual blink::WebNavigationPolicy decidePolicyForNavigation(
207 blink::WebFrame* frame,
208 blink::WebDataSource::ExtraData* extra_data,
209 const blink::WebURLRequest& request,
210 blink::WebNavigationType type,
211 blink::WebNavigationPolicy default_policy,
214 virtual blink::WebNavigationPolicy decidePolicyForNavigation(
215 blink::WebFrame* frame,
216 const blink::WebURLRequest& request,
217 blink::WebNavigationType type,
218 blink::WebNavigationPolicy default_policy,
220 virtual void willSendSubmitEvent(blink::WebFrame* frame,
221 const blink::WebFormElement& form);
222 virtual void willSubmitForm(blink::WebFrame* frame,
223 const blink::WebFormElement& form);
224 virtual void didCreateDataSource(blink::WebFrame* frame,
225 blink::WebDataSource* datasource);
226 virtual void didStartProvisionalLoad(blink::WebFrame* frame);
227 virtual void didReceiveServerRedirectForProvisionalLoad(
228 blink::WebFrame* frame);
229 virtual void didFailProvisionalLoad(
230 blink::WebFrame* frame,
231 const blink::WebURLError& error);
232 virtual void didCommitProvisionalLoad(blink::WebFrame* frame,
233 bool is_new_navigation);
234 virtual void didClearWindowObject(blink::WebFrame* frame, int world_id);
235 virtual void didCreateDocumentElement(blink::WebFrame* frame);
236 virtual void didReceiveTitle(blink::WebFrame* frame,
237 const blink::WebString& title,
238 blink::WebTextDirection direction);
239 virtual void didChangeIcon(blink::WebFrame* frame,
240 blink::WebIconURL::Type icon_type);
241 virtual void didFinishDocumentLoad(blink::WebFrame* frame);
242 virtual void didHandleOnloadEvents(blink::WebFrame* frame);
243 virtual void didFailLoad(blink::WebFrame* frame,
244 const blink::WebURLError& error);
245 virtual void didFinishLoad(blink::WebFrame* frame);
246 virtual void didNavigateWithinPage(blink::WebFrame* frame,
247 bool is_new_navigation);
248 virtual void didUpdateCurrentHistoryItem(blink::WebFrame* frame);
249 virtual void willRequestAfterPreconnect(blink::WebFrame* frame,
250 blink::WebURLRequest& request);
251 virtual void willSendRequest(
252 blink::WebFrame* frame,
254 blink::WebURLRequest& request,
255 const blink::WebURLResponse& redirect_response);
256 virtual void didReceiveResponse(
257 blink::WebFrame* frame,
259 const blink::WebURLResponse& response);
260 virtual void didFinishResourceLoad(blink::WebFrame* frame,
261 unsigned identifier);
262 virtual void didLoadResourceFromMemoryCache(
263 blink::WebFrame* frame,
264 const blink::WebURLRequest& request,
265 const blink::WebURLResponse& response);
266 virtual void didDisplayInsecureContent(blink::WebFrame* frame);
267 virtual void didRunInsecureContent(blink::WebFrame* frame,
268 const blink::WebSecurityOrigin& origin,
269 const blink::WebURL& target);
270 virtual void didAbortLoading(blink::WebFrame* frame);
271 virtual void didExhaustMemoryAvailableForScript(
272 blink::WebFrame* frame);
273 virtual void didCreateScriptContext(blink::WebFrame* frame,
274 v8::Handle<v8::Context> context,
277 virtual void willReleaseScriptContext(blink::WebFrame* frame,
278 v8::Handle<v8::Context> context,
280 virtual void didFirstVisuallyNonEmptyLayout(blink::WebFrame* frame);
281 virtual void didChangeContentsSize(blink::WebFrame* frame,
282 const blink::WebSize& size);
283 virtual void didChangeScrollOffset(blink::WebFrame* frame);
284 virtual void willInsertBody(blink::WebFrame* frame);
285 virtual void reportFindInPageMatchCount(int request_id,
288 virtual void reportFindInPageSelection(int request_id,
289 int active_match_ordinal,
290 const blink::WebRect& sel);
291 virtual void requestStorageQuota(
292 blink::WebFrame* frame,
293 blink::WebStorageQuotaType type,
294 unsigned long long requested_size,
295 blink::WebStorageQuotaCallbacks* callbacks);
296 virtual void willOpenSocketStream(
297 blink::WebSocketStreamHandle* handle);
298 virtual void willStartUsingPeerConnectionHandler(
299 blink::WebFrame* frame,
300 blink::WebRTCPeerConnectionHandler* handler);
301 virtual bool willCheckAndDispatchMessageEvent(
302 blink::WebFrame* sourceFrame,
303 blink::WebFrame* targetFrame,
304 blink::WebSecurityOrigin targetOrigin,
305 blink::WebDOMMessageEvent event);
306 virtual blink::WebString userAgentOverride(
307 blink::WebFrame* frame,
308 const blink::WebURL& url);
309 virtual blink::WebString doNotTrackValue(blink::WebFrame* frame);
310 virtual bool allowWebGL(blink::WebFrame* frame, bool default_value);
311 virtual void didLoseWebGLContext(blink::WebFrame* frame,
312 int arb_robustness_status_code);
315 RenderFrameImpl(RenderViewImpl* render_view, int32 routing_id);
318 friend class RenderFrameObserver;
320 // Functions to add and remove observers for this object.
321 void AddObserver(RenderFrameObserver* observer);
322 void RemoveObserver(RenderFrameObserver* observer);
324 // IPC message handlers ------------------------------------------------------
326 // The documentation for these functions should be in
327 // content/common/*_messages.h for the message that the function is handling.
329 void OnBuffersSwapped(const FrameMsg_BuffersSwapped_Params& params);
330 void OnCompositorFrameSwapped(const IPC::Message& message);
332 // Stores the WebFrame we are associated with.
333 blink::WebFrame* frame_;
335 base::WeakPtr<RenderViewImpl> render_view_;
337 bool is_swapped_out_;
340 #if defined(ENABLE_PLUGINS)
341 // Current text input composition text. Empty if no composition is in
343 base::string16 pepper_composition_text_;
346 RendererWebCookieJarImpl cookie_jar_;
348 // All the registered observers.
349 ObserverList<RenderFrameObserver> observers_;
351 scoped_refptr<ChildFrameCompositingHelper> compositing_helper_;
353 DISALLOW_COPY_AND_ASSIGN(RenderFrameImpl);
356 } // namespace content
358 #endif // CONTENT_RENDERER_RENDER_FRAME_IMPL_H_