Add git cl format presubmit warning for extension and apps.
[chromium-blink-merge.git] / content / renderer / render_frame_impl.h
blob5633aa42f66148d04864264490964a3b187a8957
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_
8 #include <vector>
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"
24 class TransportDIB;
25 struct FrameMsg_BuffersSwapped_Params;
26 struct FrameMsg_CompositorFrameSwapped_Params;
28 namespace blink {
29 class WebInputEvent;
30 class WebMouseEvent;
31 struct WebCompositionUnderline;
32 struct WebContextMenuData;
33 struct WebCursorInfo;
36 namespace gfx {
37 class Point;
38 class Range;
39 class Rect;
42 namespace content {
44 class ChildFrameCompositingHelper;
45 class PepperPluginInstanceImpl;
46 class RendererPpapiHost;
47 class RenderFrameObserver;
48 class RenderViewImpl;
49 class RenderWidget;
50 class RenderWidgetFullscreenPepper;
51 struct CustomContextMenuContext;
53 class CONTENT_EXPORT RenderFrameImpl
54 : public RenderFrame,
55 NON_EXPORTED_BASE(public blink::WebFrameClient) {
56 public:
57 // Creates a new RenderFrame. |render_view| is the RenderView object that this
58 // frame belongs to.
59 // Callers *must* call |SetWebFrame| immediately after creation.
60 // TODO(creis): We should structure this so that |SetWebFrame| isn't needed.
61 static RenderFrameImpl* Create(RenderViewImpl* render_view, int32 routing_id);
63 // Just like RenderFrame::FromWebFrame but returns the implementation.
64 static RenderFrameImpl* FromWebFrame(blink::WebFrame* web_frame);
66 // Used by content_layouttest_support to hook into the creation of
67 // RenderFrameImpls.
68 static void InstallCreateHook(
69 RenderFrameImpl* (*create_render_frame_impl)(RenderViewImpl*, int32));
71 virtual ~RenderFrameImpl();
73 bool is_swapped_out() const {
74 return is_swapped_out_;
77 // Out-of-process child frames receive a signal from RenderWidgetCompositor
78 // when a compositor frame has committed.
79 void DidCommitCompositorFrame();
81 // TODO(jam): this is a temporary getter until all the code is transitioned
82 // to using RenderFrame instead of RenderView.
83 RenderViewImpl* render_view() { return render_view_.get(); }
85 RendererWebCookieJarImpl* cookie_jar() { return &cookie_jar_; }
87 // Returns the RenderWidget associated with this frame.
88 RenderWidget* GetRenderWidget();
90 // This is called right after creation with the WebFrame for this RenderFrame.
91 void SetWebFrame(blink::WebFrame* web_frame);
93 // Notification from RenderView.
94 virtual void OnStop();
96 #if defined(ENABLE_PLUGINS)
97 // Notification that a PPAPI plugin has been created.
98 void PepperPluginCreated(RendererPpapiHost* host);
100 // Notifies that |instance| has changed the cursor.
101 // This will update the cursor appearance if it is currently over the plugin
102 // instance.
103 void PepperDidChangeCursor(PepperPluginInstanceImpl* instance,
104 const blink::WebCursorInfo& cursor);
106 // Notifies that |instance| has received a mouse event.
107 void PepperDidReceiveMouseEvent(PepperPluginInstanceImpl* instance);
109 // Informs the render view that a PPAPI plugin has changed text input status.
110 void PepperTextInputTypeChanged(PepperPluginInstanceImpl* instance);
111 void PepperCaretPositionChanged(PepperPluginInstanceImpl* instance);
113 // Cancels current composition.
114 void PepperCancelComposition(PepperPluginInstanceImpl* instance);
116 // Informs the render view that a PPAPI plugin has changed selection.
117 void PepperSelectionChanged(PepperPluginInstanceImpl* instance);
119 // Creates a fullscreen container for a pepper plugin instance.
120 RenderWidgetFullscreenPepper* CreatePepperFullscreenContainer(
121 PepperPluginInstanceImpl* plugin);
123 bool IsPepperAcceptingCompositionEvents() const;
125 // Notification that the given plugin has crashed.
126 void PluginCrashed(const base::FilePath& plugin_path,
127 base::ProcessId plugin_pid);
129 // Simulates IME events for testing purpose.
130 void SimulateImeSetComposition(
131 const base::string16& text,
132 const std::vector<blink::WebCompositionUnderline>& underlines,
133 int selection_start,
134 int selection_end);
135 void SimulateImeConfirmComposition(const base::string16& text,
136 const gfx::Range& replacement_range);
138 // TODO(jam): remove these once the IPC handler moves from RenderView to
139 // RenderFrame.
140 void OnImeSetComposition(
141 const base::string16& text,
142 const std::vector<blink::WebCompositionUnderline>& underlines,
143 int selection_start,
144 int selection_end);
145 void OnImeConfirmComposition(
146 const base::string16& text,
147 const gfx::Range& replacement_range,
148 bool keep_selection);
149 #endif // ENABLE_PLUGINS
151 // IPC::Sender
152 virtual bool Send(IPC::Message* msg) OVERRIDE;
154 // IPC::Listener
155 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE;
157 // RenderFrame implementation:
158 virtual RenderView* GetRenderView() OVERRIDE;
159 virtual int GetRoutingID() OVERRIDE;
160 virtual blink::WebFrame* GetWebFrame() OVERRIDE;
161 virtual WebPreferences& GetWebkitPreferences() OVERRIDE;
162 virtual int ShowContextMenu(ContextMenuClient* client,
163 const ContextMenuParams& params) OVERRIDE;
164 virtual void CancelContextMenu(int request_id) OVERRIDE;
165 virtual blink::WebPlugin* CreatePlugin(
166 blink::WebFrame* frame,
167 const WebPluginInfo& info,
168 const blink::WebPluginParams& params) OVERRIDE;
169 virtual void LoadURLExternally(
170 blink::WebFrame* frame,
171 const blink::WebURLRequest& request,
172 blink::WebNavigationPolicy policy) OVERRIDE;
174 // blink::WebFrameClient implementation -------------------------------------
175 virtual blink::WebPlugin* createPlugin(
176 blink::WebFrame* frame,
177 const blink::WebPluginParams& params);
178 virtual blink::WebMediaPlayer* createMediaPlayer(
179 blink::WebFrame* frame,
180 const blink::WebURL& url,
181 blink::WebMediaPlayerClient* client);
182 virtual blink::WebApplicationCacheHost* createApplicationCacheHost(
183 blink::WebFrame* frame,
184 blink::WebApplicationCacheHostClient* client);
185 virtual blink::WebWorkerPermissionClientProxy*
186 createWorkerPermissionClientProxy(blink::WebFrame* frame);
187 virtual blink::WebCookieJar* cookieJar(blink::WebFrame* frame);
188 virtual blink::WebServiceWorkerProvider* createServiceWorkerProvider(
189 blink::WebFrame* frame,
190 blink::WebServiceWorkerProviderClient*);
191 virtual void didAccessInitialDocument(blink::WebFrame* frame);
192 virtual blink::WebFrame* createChildFrame(blink::WebFrame* parent,
193 const blink::WebString& name);
194 virtual void didDisownOpener(blink::WebFrame* frame);
195 virtual void frameDetached(blink::WebFrame* frame);
196 virtual void willClose(blink::WebFrame* frame);
197 virtual void didChangeName(blink::WebFrame* frame,
198 const blink::WebString& name);
199 virtual void didMatchCSS(
200 blink::WebFrame* frame,
201 const blink::WebVector<blink::WebString>& newly_matching_selectors,
202 const blink::WebVector<blink::WebString>& stopped_matching_selectors);
203 virtual void loadURLExternally(blink::WebFrame* frame,
204 const blink::WebURLRequest& request,
205 blink::WebNavigationPolicy policy);
206 virtual void loadURLExternally(
207 blink::WebFrame* frame,
208 const blink::WebURLRequest& request,
209 blink::WebNavigationPolicy policy,
210 const blink::WebString& suggested_name);
211 // The WebDataSource::ExtraData* is assumed to be a DocumentState* subclass.
212 virtual blink::WebNavigationPolicy decidePolicyForNavigation(
213 blink::WebFrame* frame,
214 blink::WebDataSource::ExtraData* extra_data,
215 const blink::WebURLRequest& request,
216 blink::WebNavigationType type,
217 blink::WebNavigationPolicy default_policy,
218 bool is_redirect);
219 // DEPRECATED
220 virtual blink::WebNavigationPolicy decidePolicyForNavigation(
221 blink::WebFrame* frame,
222 const blink::WebURLRequest& request,
223 blink::WebNavigationType type,
224 blink::WebNavigationPolicy default_policy,
225 bool is_redirect);
226 virtual void willSendSubmitEvent(blink::WebFrame* frame,
227 const blink::WebFormElement& form);
228 virtual void willSubmitForm(blink::WebFrame* frame,
229 const blink::WebFormElement& form);
230 virtual void didCreateDataSource(blink::WebFrame* frame,
231 blink::WebDataSource* datasource);
232 virtual void didStartProvisionalLoad(blink::WebFrame* frame);
233 virtual void didReceiveServerRedirectForProvisionalLoad(
234 blink::WebFrame* frame);
235 virtual void didFailProvisionalLoad(
236 blink::WebFrame* frame,
237 const blink::WebURLError& error);
238 virtual void didCommitProvisionalLoad(blink::WebFrame* frame,
239 bool is_new_navigation);
240 virtual void didClearWindowObject(blink::WebFrame* frame, int world_id);
241 virtual void didCreateDocumentElement(blink::WebFrame* frame);
242 virtual void didReceiveTitle(blink::WebFrame* frame,
243 const blink::WebString& title,
244 blink::WebTextDirection direction);
245 virtual void didChangeIcon(blink::WebFrame* frame,
246 blink::WebIconURL::Type icon_type);
247 virtual void didFinishDocumentLoad(blink::WebFrame* frame);
248 virtual void didHandleOnloadEvents(blink::WebFrame* frame);
249 virtual void didFailLoad(blink::WebFrame* frame,
250 const blink::WebURLError& error);
251 virtual void didFinishLoad(blink::WebFrame* frame);
252 virtual void didNavigateWithinPage(blink::WebFrame* frame,
253 bool is_new_navigation);
254 virtual void didUpdateCurrentHistoryItem(blink::WebFrame* frame);
255 virtual void willRequestAfterPreconnect(blink::WebFrame* frame,
256 blink::WebURLRequest& request);
257 virtual void willSendRequest(
258 blink::WebFrame* frame,
259 unsigned identifier,
260 blink::WebURLRequest& request,
261 const blink::WebURLResponse& redirect_response);
262 virtual void didReceiveResponse(
263 blink::WebFrame* frame,
264 unsigned identifier,
265 const blink::WebURLResponse& response);
266 virtual void didFinishResourceLoad(blink::WebFrame* frame,
267 unsigned identifier);
268 virtual void didLoadResourceFromMemoryCache(
269 blink::WebFrame* frame,
270 const blink::WebURLRequest& request,
271 const blink::WebURLResponse& response);
272 virtual void didDisplayInsecureContent(blink::WebFrame* frame);
273 virtual void didRunInsecureContent(blink::WebFrame* frame,
274 const blink::WebSecurityOrigin& origin,
275 const blink::WebURL& target);
276 virtual void didAbortLoading(blink::WebFrame* frame);
277 virtual void didExhaustMemoryAvailableForScript(
278 blink::WebFrame* frame);
279 virtual void didCreateScriptContext(blink::WebFrame* frame,
280 v8::Handle<v8::Context> context,
281 int extension_group,
282 int world_id);
283 virtual void willReleaseScriptContext(blink::WebFrame* frame,
284 v8::Handle<v8::Context> context,
285 int world_id);
286 virtual void didFirstVisuallyNonEmptyLayout(blink::WebFrame* frame);
287 virtual void didChangeContentsSize(blink::WebFrame* frame,
288 const blink::WebSize& size);
289 virtual void didChangeScrollOffset(blink::WebFrame* frame);
290 virtual void willInsertBody(blink::WebFrame* frame);
291 virtual void reportFindInPageMatchCount(int request_id,
292 int count,
293 bool final_update);
294 virtual void reportFindInPageSelection(int request_id,
295 int active_match_ordinal,
296 const blink::WebRect& sel);
297 virtual void requestStorageQuota(
298 blink::WebFrame* frame,
299 blink::WebStorageQuotaType type,
300 unsigned long long requested_size,
301 blink::WebStorageQuotaCallbacks callbacks);
302 virtual void willOpenSocketStream(
303 blink::WebSocketStreamHandle* handle);
304 virtual void willStartUsingPeerConnectionHandler(
305 blink::WebFrame* frame,
306 blink::WebRTCPeerConnectionHandler* handler);
307 virtual bool willCheckAndDispatchMessageEvent(
308 blink::WebFrame* sourceFrame,
309 blink::WebFrame* targetFrame,
310 blink::WebSecurityOrigin targetOrigin,
311 blink::WebDOMMessageEvent event);
312 virtual blink::WebString userAgentOverride(
313 blink::WebFrame* frame,
314 const blink::WebURL& url);
315 virtual blink::WebString doNotTrackValue(blink::WebFrame* frame);
316 virtual bool allowWebGL(blink::WebFrame* frame, bool default_value);
317 virtual void didLoseWebGLContext(blink::WebFrame* frame,
318 int arb_robustness_status_code);
319 virtual void forwardInputEvent(const blink::WebInputEvent* event);
321 // TODO(jam): move this to WebFrameClient
322 virtual void showContextMenu(const blink::WebContextMenuData& data);
324 protected:
325 RenderFrameImpl(RenderViewImpl* render_view, int32 routing_id);
327 private:
328 friend class RenderFrameObserver;
329 FRIEND_TEST_ALL_PREFIXES(RenderFrameImplTest,
330 ShouldUpdateSelectionTextFromContextMenuParams);
332 // Functions to add and remove observers for this object.
333 void AddObserver(RenderFrameObserver* observer);
334 void RemoveObserver(RenderFrameObserver* observer);
336 // IPC message handlers ------------------------------------------------------
338 // The documentation for these functions should be in
339 // content/common/*_messages.h for the message that the function is handling.
340 void OnSwapOut();
341 void OnChildFrameProcessGone();
342 void OnBuffersSwapped(const FrameMsg_BuffersSwapped_Params& params);
343 void OnCompositorFrameSwapped(const IPC::Message& message);
344 void OnShowContextMenu(const gfx::Point& location);
345 void OnContextMenuClosed(const CustomContextMenuContext& custom_context);
346 void OnCustomContextMenuAction(const CustomContextMenuContext& custom_context,
347 unsigned action);
349 // Returns whether |params.selection_text| should be synchronized to the
350 // browser before bringing up the context menu. Static for testing.
351 static bool ShouldUpdateSelectionTextFromContextMenuParams(
352 const base::string16& selection_text,
353 size_t selection_text_offset,
354 const gfx::Range& selection_range,
355 const ContextMenuParams& params);
357 // Stores the WebFrame we are associated with.
358 blink::WebFrame* frame_;
360 base::WeakPtr<RenderViewImpl> render_view_;
361 int routing_id_;
362 bool is_swapped_out_;
363 bool is_detaching_;
365 #if defined(ENABLE_PLUGINS)
366 // Current text input composition text. Empty if no composition is in
367 // progress.
368 base::string16 pepper_composition_text_;
369 #endif
371 RendererWebCookieJarImpl cookie_jar_;
373 // All the registered observers.
374 ObserverList<RenderFrameObserver> observers_;
376 scoped_refptr<ChildFrameCompositingHelper> compositing_helper_;
378 // External context menu requests we're waiting for. "Internal"
379 // (WebKit-originated) context menu events will have an ID of 0 and will not
380 // be in this map.
382 // We don't want to add internal ones since some of the "special" page
383 // handlers in the browser process just ignore the context menu requests so
384 // avoid showing context menus, and so this will cause right clicks to leak
385 // entries in this map. Most users of the custom context menu (e.g. Pepper
386 // plugins) are normally only on "regular" pages and the regular pages will
387 // always respond properly to the request, so we don't have to worry so
388 // much about leaks.
389 IDMap<ContextMenuClient, IDMapExternalPointer> pending_context_menus_;
391 DISALLOW_COPY_AND_ASSIGN(RenderFrameImpl);
394 } // namespace content
396 #endif // CONTENT_RENDERER_RENDER_FRAME_IMPL_H_