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/gtest_prod_util.h"
13 #include "base/id_map.h"
14 #include "base/memory/weak_ptr.h"
15 #include "base/observer_list.h"
16 #include "base/process/process_handle.h"
17 #include "base/strings/string16.h"
18 #include "content/public/renderer/render_frame.h"
19 #include "content/renderer/renderer_webcookiejar_impl.h"
20 #include "ipc/ipc_message.h"
21 #include "third_party/WebKit/public/web/WebDataSource.h"
22 #include "third_party/WebKit/public/web/WebFrameClient.h"
25 struct FrameMsg_BuffersSwapped_Params;
26 struct FrameMsg_CompositorFrameSwapped_Params;
27 struct FrameMsg_Navigate_Params;
32 struct WebCompositionUnderline;
33 struct WebContextMenuData;
45 class ChildFrameCompositingHelper;
46 class PepperPluginInstanceImpl;
47 class RendererPpapiHost;
48 class RenderFrameObserver;
51 class RenderWidgetFullscreenPepper;
52 struct CustomContextMenuContext;
54 class CONTENT_EXPORT RenderFrameImpl
56 NON_EXPORTED_BASE(public blink::WebFrameClient) {
58 // Creates a new RenderFrame. |render_view| is the RenderView object that this
60 // Callers *must* call |SetWebFrame| immediately after creation.
61 // TODO(creis): We should structure this so that |SetWebFrame| isn't needed.
62 static RenderFrameImpl* Create(RenderViewImpl* render_view, int32 routing_id);
64 // Just like RenderFrame::FromWebFrame but returns the implementation.
65 static RenderFrameImpl* FromWebFrame(blink::WebFrame* web_frame);
67 // Used by content_layouttest_support to hook into the creation of
69 static void InstallCreateHook(
70 RenderFrameImpl* (*create_render_frame_impl)(RenderViewImpl*, int32));
72 virtual ~RenderFrameImpl();
74 bool is_swapped_out() const {
75 return is_swapped_out_;
78 // Out-of-process child frames receive a signal from RenderWidgetCompositor
79 // when a compositor frame has committed.
80 void DidCommitCompositorFrame();
82 // TODO(jam): this is a temporary getter until all the code is transitioned
83 // to using RenderFrame instead of RenderView.
84 RenderViewImpl* render_view() { return render_view_.get(); }
86 RendererWebCookieJarImpl* cookie_jar() { return &cookie_jar_; }
88 // Returns the RenderWidget associated with this frame.
89 RenderWidget* GetRenderWidget();
91 // This is called right after creation with the WebFrame for this RenderFrame.
92 void SetWebFrame(blink::WebFrame* web_frame);
94 // Notification from RenderView.
95 virtual void OnStop();
97 // Start/Stop loading notifications.
98 // TODO(nasko): Those are page-level methods at this time and come from
99 // WebViewClient. We should move them to be WebFrameClient calls and put
100 // logic in the browser side to balance starts/stops.
101 void didStartLoading();
102 void didStopLoading();
104 #if defined(ENABLE_PLUGINS)
105 // Notification that a PPAPI plugin has been created.
106 void PepperPluginCreated(RendererPpapiHost* host);
108 // Notifies that |instance| has changed the cursor.
109 // This will update the cursor appearance if it is currently over the plugin
111 void PepperDidChangeCursor(PepperPluginInstanceImpl* instance,
112 const blink::WebCursorInfo& cursor);
114 // Notifies that |instance| has received a mouse event.
115 void PepperDidReceiveMouseEvent(PepperPluginInstanceImpl* instance);
117 // Informs the render view that a PPAPI plugin has changed text input status.
118 void PepperTextInputTypeChanged(PepperPluginInstanceImpl* instance);
119 void PepperCaretPositionChanged(PepperPluginInstanceImpl* instance);
121 // Cancels current composition.
122 void PepperCancelComposition(PepperPluginInstanceImpl* instance);
124 // Informs the render view that a PPAPI plugin has changed selection.
125 void PepperSelectionChanged(PepperPluginInstanceImpl* instance);
127 // Creates a fullscreen container for a pepper plugin instance.
128 RenderWidgetFullscreenPepper* CreatePepperFullscreenContainer(
129 PepperPluginInstanceImpl* plugin);
131 bool IsPepperAcceptingCompositionEvents() const;
133 // Notification that the given plugin has crashed.
134 void PluginCrashed(const base::FilePath& plugin_path,
135 base::ProcessId plugin_pid);
137 // Simulates IME events for testing purpose.
138 void SimulateImeSetComposition(
139 const base::string16& text,
140 const std::vector<blink::WebCompositionUnderline>& underlines,
143 void SimulateImeConfirmComposition(const base::string16& text,
144 const gfx::Range& replacement_range);
146 // TODO(jam): remove these once the IPC handler moves from RenderView to
148 void OnImeSetComposition(
149 const base::string16& text,
150 const std::vector<blink::WebCompositionUnderline>& underlines,
153 void OnImeConfirmComposition(
154 const base::string16& text,
155 const gfx::Range& replacement_range,
156 bool keep_selection);
157 #endif // ENABLE_PLUGINS
160 virtual bool Send(IPC::Message* msg) OVERRIDE;
163 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE;
165 // RenderFrame implementation:
166 virtual RenderView* GetRenderView() OVERRIDE;
167 virtual int GetRoutingID() OVERRIDE;
168 virtual blink::WebFrame* GetWebFrame() OVERRIDE;
169 virtual WebPreferences& GetWebkitPreferences() OVERRIDE;
170 virtual int ShowContextMenu(ContextMenuClient* client,
171 const ContextMenuParams& params) OVERRIDE;
172 virtual void CancelContextMenu(int request_id) OVERRIDE;
173 virtual blink::WebPlugin* CreatePlugin(
174 blink::WebFrame* frame,
175 const WebPluginInfo& info,
176 const blink::WebPluginParams& params) OVERRIDE;
177 virtual void LoadURLExternally(
178 blink::WebFrame* frame,
179 const blink::WebURLRequest& request,
180 blink::WebNavigationPolicy policy) OVERRIDE;
182 // blink::WebFrameClient implementation -------------------------------------
183 virtual blink::WebPlugin* createPlugin(
184 blink::WebFrame* frame,
185 const blink::WebPluginParams& params);
186 virtual blink::WebMediaPlayer* createMediaPlayer(
187 blink::WebFrame* frame,
188 const blink::WebURL& url,
189 blink::WebMediaPlayerClient* client);
190 virtual blink::WebApplicationCacheHost* createApplicationCacheHost(
191 blink::WebFrame* frame,
192 blink::WebApplicationCacheHostClient* client);
193 virtual blink::WebWorkerPermissionClientProxy*
194 createWorkerPermissionClientProxy(blink::WebFrame* frame);
195 virtual blink::WebCookieJar* cookieJar(blink::WebFrame* frame);
196 virtual blink::WebServiceWorkerProvider* createServiceWorkerProvider(
197 blink::WebFrame* frame,
198 blink::WebServiceWorkerProviderClient*);
199 virtual void didAccessInitialDocument(blink::WebFrame* frame);
200 virtual blink::WebFrame* createChildFrame(blink::WebFrame* parent,
201 const blink::WebString& name);
202 virtual void didDisownOpener(blink::WebFrame* frame);
203 virtual void frameDetached(blink::WebFrame* frame);
204 virtual void willClose(blink::WebFrame* frame);
205 virtual void didChangeName(blink::WebFrame* frame,
206 const blink::WebString& name);
207 virtual void didMatchCSS(
208 blink::WebFrame* frame,
209 const blink::WebVector<blink::WebString>& newly_matching_selectors,
210 const blink::WebVector<blink::WebString>& stopped_matching_selectors);
211 virtual void loadURLExternally(blink::WebFrame* frame,
212 const blink::WebURLRequest& request,
213 blink::WebNavigationPolicy policy);
214 virtual void loadURLExternally(
215 blink::WebFrame* frame,
216 const blink::WebURLRequest& request,
217 blink::WebNavigationPolicy policy,
218 const blink::WebString& suggested_name);
219 // The WebDataSource::ExtraData* is assumed to be a DocumentState* subclass.
220 virtual blink::WebNavigationPolicy decidePolicyForNavigation(
221 blink::WebFrame* frame,
222 blink::WebDataSource::ExtraData* extra_data,
223 const blink::WebURLRequest& request,
224 blink::WebNavigationType type,
225 blink::WebNavigationPolicy default_policy,
228 virtual blink::WebNavigationPolicy decidePolicyForNavigation(
229 blink::WebFrame* frame,
230 const blink::WebURLRequest& request,
231 blink::WebNavigationType type,
232 blink::WebNavigationPolicy default_policy,
234 virtual void willSendSubmitEvent(blink::WebFrame* frame,
235 const blink::WebFormElement& form);
236 virtual void willSubmitForm(blink::WebFrame* frame,
237 const blink::WebFormElement& form);
238 virtual void didCreateDataSource(blink::WebFrame* frame,
239 blink::WebDataSource* datasource);
240 virtual void didStartProvisionalLoad(blink::WebFrame* frame);
241 virtual void didReceiveServerRedirectForProvisionalLoad(
242 blink::WebFrame* frame);
243 virtual void didFailProvisionalLoad(
244 blink::WebFrame* frame,
245 const blink::WebURLError& error);
246 virtual void didCommitProvisionalLoad(blink::WebFrame* frame,
247 bool is_new_navigation);
248 virtual void didClearWindowObject(blink::WebFrame* frame, int world_id);
249 virtual void didCreateDocumentElement(blink::WebFrame* frame);
250 virtual void didReceiveTitle(blink::WebFrame* frame,
251 const blink::WebString& title,
252 blink::WebTextDirection direction);
253 virtual void didChangeIcon(blink::WebFrame* frame,
254 blink::WebIconURL::Type icon_type);
255 virtual void didFinishDocumentLoad(blink::WebFrame* frame);
256 virtual void didHandleOnloadEvents(blink::WebFrame* frame);
257 virtual void didFailLoad(blink::WebFrame* frame,
258 const blink::WebURLError& error);
259 virtual void didFinishLoad(blink::WebFrame* frame);
260 virtual void didNavigateWithinPage(blink::WebFrame* frame,
261 bool is_new_navigation);
262 virtual void didUpdateCurrentHistoryItem(blink::WebFrame* frame);
263 virtual void willRequestAfterPreconnect(blink::WebFrame* frame,
264 blink::WebURLRequest& request);
265 virtual void willSendRequest(
266 blink::WebFrame* frame,
268 blink::WebURLRequest& request,
269 const blink::WebURLResponse& redirect_response);
270 virtual void didReceiveResponse(
271 blink::WebFrame* frame,
273 const blink::WebURLResponse& response);
274 virtual void didFinishResourceLoad(blink::WebFrame* frame,
275 unsigned identifier);
276 virtual void didLoadResourceFromMemoryCache(
277 blink::WebFrame* frame,
278 const blink::WebURLRequest& request,
279 const blink::WebURLResponse& response);
280 virtual void didDisplayInsecureContent(blink::WebFrame* frame);
281 virtual void didRunInsecureContent(blink::WebFrame* frame,
282 const blink::WebSecurityOrigin& origin,
283 const blink::WebURL& target);
284 virtual void didAbortLoading(blink::WebFrame* frame);
285 virtual void didExhaustMemoryAvailableForScript(
286 blink::WebFrame* frame);
287 virtual void didCreateScriptContext(blink::WebFrame* frame,
288 v8::Handle<v8::Context> context,
291 virtual void willReleaseScriptContext(blink::WebFrame* frame,
292 v8::Handle<v8::Context> context,
294 virtual void didFirstVisuallyNonEmptyLayout(blink::WebFrame* frame);
295 virtual void didChangeContentsSize(blink::WebFrame* frame,
296 const blink::WebSize& size);
297 virtual void didChangeScrollOffset(blink::WebFrame* frame);
298 virtual void willInsertBody(blink::WebFrame* frame);
299 virtual void reportFindInPageMatchCount(int request_id,
302 virtual void reportFindInPageSelection(int request_id,
303 int active_match_ordinal,
304 const blink::WebRect& sel);
305 virtual void requestStorageQuota(
306 blink::WebFrame* frame,
307 blink::WebStorageQuotaType type,
308 unsigned long long requested_size,
309 blink::WebStorageQuotaCallbacks callbacks);
310 virtual void willOpenSocketStream(
311 blink::WebSocketStreamHandle* handle);
312 virtual void willStartUsingPeerConnectionHandler(
313 blink::WebFrame* frame,
314 blink::WebRTCPeerConnectionHandler* handler);
315 virtual bool willCheckAndDispatchMessageEvent(
316 blink::WebFrame* sourceFrame,
317 blink::WebFrame* targetFrame,
318 blink::WebSecurityOrigin targetOrigin,
319 blink::WebDOMMessageEvent event);
320 virtual blink::WebString userAgentOverride(
321 blink::WebFrame* frame,
322 const blink::WebURL& url);
323 virtual blink::WebString doNotTrackValue(blink::WebFrame* frame);
324 virtual bool allowWebGL(blink::WebFrame* frame, bool default_value);
325 virtual void didLoseWebGLContext(blink::WebFrame* frame,
326 int arb_robustness_status_code);
327 virtual void forwardInputEvent(const blink::WebInputEvent* event);
329 // TODO(jam): move this to WebFrameClient
330 virtual void showContextMenu(const blink::WebContextMenuData& data);
332 // TODO(nasko): Make all tests in RenderViewImplTest friends and then move
333 // this back to private member.
334 void OnNavigate(const FrameMsg_Navigate_Params& params);
337 RenderFrameImpl(RenderViewImpl* render_view, int32 routing_id);
340 friend class RenderFrameObserver;
341 FRIEND_TEST_ALL_PREFIXES(RenderFrameImplTest,
342 ShouldUpdateSelectionTextFromContextMenuParams);
344 typedef std::map<GURL, double> HostZoomLevels;
346 // Functions to add and remove observers for this object.
347 void AddObserver(RenderFrameObserver* observer);
348 void RemoveObserver(RenderFrameObserver* observer);
350 void UpdateURL(blink::WebFrame* frame);
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.
357 void OnChildFrameProcessGone();
358 void OnBuffersSwapped(const FrameMsg_BuffersSwapped_Params& params);
359 void OnCompositorFrameSwapped(const IPC::Message& message);
360 void OnShowContextMenu(const gfx::Point& location);
361 void OnContextMenuClosed(const CustomContextMenuContext& custom_context);
362 void OnCustomContextMenuAction(const CustomContextMenuContext& custom_context,
365 // Returns whether |params.selection_text| should be synchronized to the
366 // browser before bringing up the context menu. Static for testing.
367 static bool ShouldUpdateSelectionTextFromContextMenuParams(
368 const base::string16& selection_text,
369 size_t selection_text_offset,
370 const gfx::Range& selection_range,
371 const ContextMenuParams& params);
373 // Stores the WebFrame we are associated with.
374 blink::WebFrame* frame_;
376 base::WeakPtr<RenderViewImpl> render_view_;
378 bool is_swapped_out_;
381 #if defined(ENABLE_PLUGINS)
382 // Current text input composition text. Empty if no composition is in
384 base::string16 pepper_composition_text_;
387 RendererWebCookieJarImpl cookie_jar_;
389 // All the registered observers.
390 ObserverList<RenderFrameObserver> observers_;
392 scoped_refptr<ChildFrameCompositingHelper> compositing_helper_;
394 // External context menu requests we're waiting for. "Internal"
395 // (WebKit-originated) context menu events will have an ID of 0 and will not
398 // We don't want to add internal ones since some of the "special" page
399 // handlers in the browser process just ignore the context menu requests so
400 // avoid showing context menus, and so this will cause right clicks to leak
401 // entries in this map. Most users of the custom context menu (e.g. Pepper
402 // plugins) are normally only on "regular" pages and the regular pages will
403 // always respond properly to the request, so we don't have to worry so
405 IDMap<ContextMenuClient, IDMapExternalPointer> pending_context_menus_;
407 DISALLOW_COPY_AND_ASSIGN(RenderFrameImpl);
410 } // namespace content
412 #endif // CONTENT_RENDERER_RENDER_FRAME_IMPL_H_