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_
11 #include "base/basictypes.h"
12 #include "base/files/file_path.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"
26 struct WebCompositionUnderline
;
37 class PepperPluginInstanceImpl
;
38 class RendererPpapiHost
;
39 class RenderFrameObserver
;
42 class RenderWidgetFullscreenPepper
;
44 class CONTENT_EXPORT RenderFrameImpl
46 NON_EXPORTED_BASE(public blink::WebFrameClient
) {
48 // Creates a new RenderFrame. |render_view| is the RenderView object that this
50 // Callers *must* call |SetWebFrame| immediately after creation.
51 // TODO(creis): We should structure this so that |SetWebFrame| isn't needed.
52 static RenderFrameImpl
* Create(RenderViewImpl
* render_view
, int32 routing_id
);
54 // For subframes, look up the RenderFrameImpl for the given WebFrame. Returns
55 // NULL for main frames.
56 // This only works when using --site-per-process, and returns NULL otherwise.
57 // TODO(creis): Remove this when the RenderView methods dealing with frames
58 // have moved to RenderFrame.
59 static RenderFrameImpl
* FindByWebFrame(blink::WebFrame
* web_frame
);
61 // Used by content_layouttest_support to hook into the creation of
63 static void InstallCreateHook(
64 RenderFrameImpl
* (*create_render_frame_impl
)(RenderViewImpl
*, int32
));
66 virtual ~RenderFrameImpl();
67 // TODO(nasko): Remove when no longer needed.
68 // See comment on the implementation of this method for more details.
69 void operator delete(void*);
71 bool is_swapped_out() const {
72 return is_swapped_out_
;
75 // TODO(jam): this is a temporary getter until all the code is transitioned
76 // to using RenderFrame instead of RenderView.
77 RenderViewImpl
* render_view() { return render_view_
; }
79 RendererWebCookieJarImpl
* cookie_jar() { return &cookie_jar_
; }
81 // Returns the RenderWidget associated with this frame.
82 RenderWidget
* GetRenderWidget();
84 // Called by RenderView right after creating this object when the
85 // blink::WebFrame has been created.
86 void MainWebFrameCreated(blink::WebFrame
* frame
);
88 // In --site-per-process mode, we keep track of which WebFrame this
89 // RenderFrameImpl is for.
90 void SetWebFrame(blink::WebFrame
* web_frame
);
92 #if defined(ENABLE_PLUGINS)
93 // Notification that a PPAPI plugin has been created.
94 void PepperPluginCreated(RendererPpapiHost
* host
);
96 // Indicates that the given instance has been created.
97 void PepperInstanceCreated(PepperPluginInstanceImpl
* instance
);
99 // Indicates that the given instance is being destroyed. This is called from
100 // the destructor, so it's important that the instance is not dereferenced
102 void PepperInstanceDeleted(PepperPluginInstanceImpl
* instance
);
104 // Notifies that |instance| has changed the cursor.
105 // This will update the cursor appearance if it is currently over the plugin
107 void PepperDidChangeCursor(PepperPluginInstanceImpl
* instance
,
108 const blink::WebCursorInfo
& cursor
);
110 // Notifies that |instance| has received a mouse event.
111 void PepperDidReceiveMouseEvent(PepperPluginInstanceImpl
* instance
);
113 // Notification that the given plugin is focused or unfocused.
114 void PepperFocusChanged(PepperPluginInstanceImpl
* instance
, bool focused
);
116 // Informs the render view that a PPAPI plugin has changed text input status.
117 void PepperTextInputTypeChanged(PepperPluginInstanceImpl
* instance
);
118 void PepperCaretPositionChanged(PepperPluginInstanceImpl
* instance
);
120 // Cancels current composition.
121 void PepperCancelComposition(PepperPluginInstanceImpl
* instance
);
123 // Informs the render view that a PPAPI plugin has changed selection.
124 void PepperSelectionChanged(PepperPluginInstanceImpl
* instance
);
126 // Creates a fullscreen container for a pepper plugin instance.
127 RenderWidgetFullscreenPepper
* CreatePepperFullscreenContainer(
128 PepperPluginInstanceImpl
* plugin
);
130 bool IsPepperAcceptingCompositionEvents() const;
132 // Notification that the given plugin has crashed.
133 void PluginCrashed(const base::FilePath
& plugin_path
,
134 base::ProcessId plugin_pid
);
136 // These map to virtual methods on RenderWidget that are used to call out to
138 // TODO(jam): once we get rid of RenderView, RenderFrame will own RenderWidget
139 // and methods would be on a delegate interface.
140 void DidInitiatePaint();
141 void DidFlushPaint();
142 PepperPluginInstanceImpl
* GetBitmapForOptimizedPluginPaint(
143 const gfx::Rect
& paint_bounds
,
147 float* scale_factor
);
148 void PageVisibilityChanged(bool shown
);
149 void OnSetFocus(bool enable
);
150 void WillHandleMouseEvent(const blink::WebMouseEvent
& event
);
152 // Simulates IME events for testing purpose.
153 void SimulateImeSetComposition(
154 const base::string16
& text
,
155 const std::vector
<blink::WebCompositionUnderline
>& underlines
,
158 void SimulateImeConfirmComposition(const base::string16
& text
,
159 const gfx::Range
& replacement_range
);
161 // TODO(jam): remove these once the IPC handler moves from RenderView to
163 void OnImeSetComposition(
164 const base::string16
& text
,
165 const std::vector
<blink::WebCompositionUnderline
>& underlines
,
168 void OnImeConfirmComposition(
169 const base::string16
& text
,
170 const gfx::Range
& replacement_range
,
171 bool keep_selection
);
172 #endif // ENABLE_PLUGINS
175 virtual bool Send(IPC::Message
* msg
) OVERRIDE
;
178 virtual bool OnMessageReceived(const IPC::Message
& msg
) OVERRIDE
;
180 // RenderFrame implementation:
181 virtual RenderView
* GetRenderView() OVERRIDE
;
182 virtual int GetRoutingID() OVERRIDE
;
183 virtual WebPreferences
& GetWebkitPreferences() OVERRIDE
;
184 virtual int ShowContextMenu(ContextMenuClient
* client
,
185 const ContextMenuParams
& params
) OVERRIDE
;
186 virtual void CancelContextMenu(int request_id
) OVERRIDE
;
187 virtual blink::WebPlugin
* CreatePlugin(
188 blink::WebFrame
* frame
,
189 const WebPluginInfo
& info
,
190 const blink::WebPluginParams
& params
) OVERRIDE
;
191 virtual void LoadURLExternally(
192 blink::WebFrame
* frame
,
193 const blink::WebURLRequest
& request
,
194 blink::WebNavigationPolicy policy
) OVERRIDE
;
196 // blink::WebFrameClient implementation -------------------------------------
197 virtual blink::WebPlugin
* createPlugin(
198 blink::WebFrame
* frame
,
199 const blink::WebPluginParams
& params
);
200 virtual blink::WebMediaPlayer
* createMediaPlayer(
201 blink::WebFrame
* frame
,
202 const blink::WebURL
& url
,
203 blink::WebMediaPlayerClient
* client
);
204 virtual blink::WebApplicationCacheHost
* createApplicationCacheHost(
205 blink::WebFrame
* frame
,
206 blink::WebApplicationCacheHostClient
* client
);
207 virtual blink::WebWorkerPermissionClientProxy
*
208 createWorkerPermissionClientProxy(blink::WebFrame
* frame
);
209 virtual blink::WebCookieJar
* cookieJar(blink::WebFrame
* frame
);
210 virtual blink::WebServiceWorkerProvider
* createServiceWorkerProvider(
211 blink::WebFrame
* frame
,
212 blink::WebServiceWorkerProviderClient
*);
213 virtual void didAccessInitialDocument(blink::WebFrame
* frame
);
214 virtual blink::WebFrame
* createChildFrame(blink::WebFrame
* parent
,
215 const blink::WebString
& name
);
216 virtual void didDisownOpener(blink::WebFrame
* frame
);
217 virtual void frameDetached(blink::WebFrame
* frame
);
218 virtual void willClose(blink::WebFrame
* frame
);
219 virtual void didChangeName(blink::WebFrame
* frame
,
220 const blink::WebString
& name
);
221 virtual void didMatchCSS(
222 blink::WebFrame
* frame
,
223 const blink::WebVector
<blink::WebString
>& newly_matching_selectors
,
224 const blink::WebVector
<blink::WebString
>& stopped_matching_selectors
);
225 virtual void loadURLExternally(blink::WebFrame
* frame
,
226 const blink::WebURLRequest
& request
,
227 blink::WebNavigationPolicy policy
);
228 virtual void loadURLExternally(
229 blink::WebFrame
* frame
,
230 const blink::WebURLRequest
& request
,
231 blink::WebNavigationPolicy policy
,
232 const blink::WebString
& suggested_name
);
233 // The WebDataSource::ExtraData* is assumed to be a DocumentState* subclass.
234 virtual blink::WebNavigationPolicy
decidePolicyForNavigation(
235 blink::WebFrame
* frame
,
236 blink::WebDataSource::ExtraData
* extra_data
,
237 const blink::WebURLRequest
& request
,
238 blink::WebNavigationType type
,
239 blink::WebNavigationPolicy default_policy
,
242 virtual blink::WebNavigationPolicy
decidePolicyForNavigation(
243 blink::WebFrame
* frame
,
244 const blink::WebURLRequest
& request
,
245 blink::WebNavigationType type
,
246 blink::WebNavigationPolicy default_policy
,
248 virtual void willSendSubmitEvent(blink::WebFrame
* frame
,
249 const blink::WebFormElement
& form
);
250 virtual void willSubmitForm(blink::WebFrame
* frame
,
251 const blink::WebFormElement
& form
);
252 virtual void didCreateDataSource(blink::WebFrame
* frame
,
253 blink::WebDataSource
* datasource
);
254 virtual void didStartProvisionalLoad(blink::WebFrame
* frame
);
255 virtual void didReceiveServerRedirectForProvisionalLoad(
256 blink::WebFrame
* frame
);
257 virtual void didFailProvisionalLoad(
258 blink::WebFrame
* frame
,
259 const blink::WebURLError
& error
);
260 virtual void didCommitProvisionalLoad(blink::WebFrame
* frame
,
261 bool is_new_navigation
);
262 virtual void didClearWindowObject(blink::WebFrame
* frame
);
263 virtual void didCreateDocumentElement(blink::WebFrame
* frame
);
264 virtual void didReceiveTitle(blink::WebFrame
* frame
,
265 const blink::WebString
& title
,
266 blink::WebTextDirection direction
);
267 virtual void didChangeIcon(blink::WebFrame
* frame
,
268 blink::WebIconURL::Type icon_type
);
269 virtual void didFinishDocumentLoad(blink::WebFrame
* frame
);
270 virtual void didHandleOnloadEvents(blink::WebFrame
* frame
);
271 virtual void didFailLoad(blink::WebFrame
* frame
,
272 const blink::WebURLError
& error
);
273 virtual void didFinishLoad(blink::WebFrame
* frame
);
274 virtual void didNavigateWithinPage(blink::WebFrame
* frame
,
275 bool is_new_navigation
);
276 virtual void didUpdateCurrentHistoryItem(blink::WebFrame
* frame
);
277 virtual void willRequestAfterPreconnect(blink::WebFrame
* frame
,
278 blink::WebURLRequest
& request
);
279 virtual void willSendRequest(
280 blink::WebFrame
* frame
,
282 blink::WebURLRequest
& request
,
283 const blink::WebURLResponse
& redirect_response
);
284 virtual void didReceiveResponse(
285 blink::WebFrame
* frame
,
287 const blink::WebURLResponse
& response
);
288 virtual void didFinishResourceLoad(blink::WebFrame
* frame
,
289 unsigned identifier
);
290 virtual void didLoadResourceFromMemoryCache(
291 blink::WebFrame
* frame
,
292 const blink::WebURLRequest
& request
,
293 const blink::WebURLResponse
& response
);
294 virtual void didDisplayInsecureContent(blink::WebFrame
* frame
);
295 virtual void didRunInsecureContent(blink::WebFrame
* frame
,
296 const blink::WebSecurityOrigin
& origin
,
297 const blink::WebURL
& target
);
298 virtual void didAbortLoading(blink::WebFrame
* frame
);
299 virtual void didExhaustMemoryAvailableForScript(
300 blink::WebFrame
* frame
);
301 virtual void didCreateScriptContext(blink::WebFrame
* frame
,
302 v8::Handle
<v8::Context
> context
,
305 virtual void willReleaseScriptContext(blink::WebFrame
* frame
,
306 v8::Handle
<v8::Context
> context
,
308 virtual void didFirstVisuallyNonEmptyLayout(blink::WebFrame
* frame
);
309 virtual void didChangeContentsSize(blink::WebFrame
* frame
,
310 const blink::WebSize
& size
);
311 virtual void didChangeScrollOffset(blink::WebFrame
* frame
);
312 virtual void willInsertBody(blink::WebFrame
* frame
);
313 virtual void reportFindInPageMatchCount(int request_id
,
316 virtual void reportFindInPageSelection(int request_id
,
317 int active_match_ordinal
,
318 const blink::WebRect
& sel
);
319 virtual void requestStorageQuota(
320 blink::WebFrame
* frame
,
321 blink::WebStorageQuotaType type
,
322 unsigned long long requested_size
,
323 blink::WebStorageQuotaCallbacks
* callbacks
);
324 virtual void willOpenSocketStream(
325 blink::WebSocketStreamHandle
* handle
);
326 virtual void willStartUsingPeerConnectionHandler(
327 blink::WebFrame
* frame
,
328 blink::WebRTCPeerConnectionHandler
* handler
);
329 virtual bool willCheckAndDispatchMessageEvent(
330 blink::WebFrame
* sourceFrame
,
331 blink::WebFrame
* targetFrame
,
332 blink::WebSecurityOrigin targetOrigin
,
333 blink::WebDOMMessageEvent event
);
334 virtual blink::WebString
userAgentOverride(
335 blink::WebFrame
* frame
,
336 const blink::WebURL
& url
);
337 virtual blink::WebString
doNotTrackValue(blink::WebFrame
* frame
);
338 virtual bool allowWebGL(blink::WebFrame
* frame
, bool default_value
);
339 virtual void didLoseWebGLContext(blink::WebFrame
* frame
,
340 int arb_robustness_status_code
);
343 RenderFrameImpl(RenderViewImpl
* render_view
, int32 routing_id
);
346 friend class RenderFrameObserver
;
348 // Functions to add and remove observers for this object.
349 void AddObserver(RenderFrameObserver
* observer
);
350 void RemoveObserver(RenderFrameObserver
* observer
);
352 // IPC message handlers ------------------------------------------------------
354 // The documentation for these functions should be in
355 // content/common/*_messages.h for the message that the function is handling.
358 // In --site-per-process mode, stores the WebFrame we are associated with.
360 blink::WebFrame
* frame_
;
362 RenderViewImpl
* render_view_
;
364 bool is_swapped_out_
;
367 #if defined(ENABLE_PLUGINS)
368 typedef std::set
<PepperPluginInstanceImpl
*> PepperPluginSet
;
369 PepperPluginSet active_pepper_instances_
;
371 // Current text input composition text. Empty if no composition is in
373 base::string16 pepper_composition_text_
;
376 RendererWebCookieJarImpl cookie_jar_
;
378 // All the registered observers.
379 ObserverList
<RenderFrameObserver
> observers_
;
381 DISALLOW_COPY_AND_ASSIGN(RenderFrameImpl
);
384 } // namespace content
386 #endif // CONTENT_RENDERER_RENDER_FRAME_IMPL_H_