render_frame_impl.h revision a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7
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.
4
5#ifndef CONTENT_RENDERER_RENDER_FRAME_IMPL_H_
6#define CONTENT_RENDERER_RENDER_FRAME_IMPL_H_
7
8#include <set>
9#include <vector>
10
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 "ipc/ipc_message.h"
18#include "third_party/WebKit/public/web/WebDataSource.h"
19#include "third_party/WebKit/public/web/WebFrameClient.h"
20
21class TransportDIB;
22
23namespace blink {
24class WebMouseEvent;
25struct WebCompositionUnderline;
26struct WebCursorInfo;
27}
28
29namespace gfx {
30class Range;
31class Rect;
32}
33
34namespace content {
35
36class PepperPluginInstanceImpl;
37class RendererPpapiHost;
38class RenderFrameObserver;
39class RenderViewImpl;
40class RenderWidget;
41class RenderWidgetFullscreenPepper;
42
43class CONTENT_EXPORT RenderFrameImpl
44    : public RenderFrame,
45      NON_EXPORTED_BASE(public blink::WebFrameClient) {
46 public:
47  // Creates a new RenderFrame. |render_view| is the RenderView object that this
48  // frame belongs to.
49  static RenderFrameImpl* Create(RenderViewImpl* render_view, int32 routing_id);
50
51  // Used by content_layouttest_support to hook into the creation of
52  // RenderFrameImpls.
53  static void InstallCreateHook(
54      RenderFrameImpl* (*create_render_frame_impl)(RenderViewImpl*, int32));
55
56  virtual ~RenderFrameImpl();
57
58  // TODO(jam): this is a temporary getter until all the code is transitioned
59  // to using RenderFrame instead of RenderView.
60  RenderViewImpl* render_view() { return render_view_; }
61
62  // Returns the RenderWidget associated with this frame.
63  RenderWidget* GetRenderWidget();
64
65#if defined(ENABLE_PLUGINS)
66  // Notification that a PPAPI plugin has been created.
67  void PepperPluginCreated(RendererPpapiHost* host);
68
69  // Indicates that the given instance has been created.
70  void PepperInstanceCreated(PepperPluginInstanceImpl* instance);
71
72  // Indicates that the given instance is being destroyed. This is called from
73  // the destructor, so it's important that the instance is not dereferenced
74  // from this call.
75  void PepperInstanceDeleted(PepperPluginInstanceImpl* instance);
76
77  // Notifies that |instance| has changed the cursor.
78  // This will update the cursor appearance if it is currently over the plugin
79  // instance.
80  void PepperDidChangeCursor(PepperPluginInstanceImpl* instance,
81                             const blink::WebCursorInfo& cursor);
82
83  // Notifies that |instance| has received a mouse event.
84  void PepperDidReceiveMouseEvent(PepperPluginInstanceImpl* instance);
85
86  // Notification that the given plugin is focused or unfocused.
87  void PepperFocusChanged(PepperPluginInstanceImpl* instance, bool focused);
88
89  // Informs the render view that a PPAPI plugin has changed text input status.
90  void PepperTextInputTypeChanged(PepperPluginInstanceImpl* instance);
91  void PepperCaretPositionChanged(PepperPluginInstanceImpl* instance);
92
93  // Cancels current composition.
94  void PepperCancelComposition(PepperPluginInstanceImpl* instance);
95
96  // Informs the render view that a PPAPI plugin has changed selection.
97  void PepperSelectionChanged(PepperPluginInstanceImpl* instance);
98
99  // Creates a fullscreen container for a pepper plugin instance.
100  RenderWidgetFullscreenPepper* CreatePepperFullscreenContainer(
101      PepperPluginInstanceImpl* plugin);
102
103  bool IsPepperAcceptingCompositionEvents() const;
104
105  // Notification that the given plugin has crashed.
106  void PluginCrashed(const base::FilePath& plugin_path,
107                     base::ProcessId plugin_pid);
108
109  // These map to virtual methods on RenderWidget that are used to call out to
110  // RenderView.
111  // TODO(jam): once we get rid of RenderView, RenderFrame will own RenderWidget
112  // and methods would be on a delegate interface.
113  void DidInitiatePaint();
114  void DidFlushPaint();
115  PepperPluginInstanceImpl* GetBitmapForOptimizedPluginPaint(
116      const gfx::Rect& paint_bounds,
117      TransportDIB** dib,
118      gfx::Rect* location,
119      gfx::Rect* clip,
120      float* scale_factor);
121  void PageVisibilityChanged(bool shown);
122  void OnSetFocus(bool enable);
123  void WillHandleMouseEvent(const blink::WebMouseEvent& event);
124
125  // Simulates IME events for testing purpose.
126  void SimulateImeSetComposition(
127      const base::string16& text,
128      const std::vector<blink::WebCompositionUnderline>& underlines,
129      int selection_start,
130      int selection_end);
131  void SimulateImeConfirmComposition(const base::string16& text,
132                                     const gfx::Range& replacement_range);
133
134  // TODO(jam): remove these once the IPC handler moves from RenderView to
135  // RenderFrame.
136  void OnImeSetComposition(
137    const base::string16& text,
138    const std::vector<blink::WebCompositionUnderline>& underlines,
139    int selection_start,
140    int selection_end);
141 void OnImeConfirmComposition(
142    const base::string16& text,
143    const gfx::Range& replacement_range,
144    bool keep_selection);
145#endif  // ENABLE_PLUGINS
146
147  // IPC::Sender
148  virtual bool Send(IPC::Message* msg) OVERRIDE;
149
150  // IPC::Listener
151  virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE;
152
153  // RenderFrame implementation:
154  virtual RenderView* GetRenderView() OVERRIDE;
155  virtual int GetRoutingID() OVERRIDE;
156  virtual WebPreferences& GetWebkitPreferences() OVERRIDE;
157  virtual int ShowContextMenu(ContextMenuClient* client,
158                              const ContextMenuParams& params) OVERRIDE;
159  virtual void CancelContextMenu(int request_id) OVERRIDE;
160  virtual blink::WebPlugin* CreatePlugin(
161      blink::WebFrame* frame,
162      const WebPluginInfo& info,
163      const blink::WebPluginParams& params) OVERRIDE;
164  virtual void LoadURLExternally(
165      blink::WebFrame* frame,
166      const blink::WebURLRequest& request,
167      blink::WebNavigationPolicy policy) OVERRIDE;
168
169  // blink::WebFrameClient implementation -------------------------------------
170  virtual blink::WebPlugin* createPlugin(
171      blink::WebFrame* frame,
172      const blink::WebPluginParams& params);
173  virtual blink::WebMediaPlayer* createMediaPlayer(
174      blink::WebFrame* frame,
175      const blink::WebURL& url,
176      blink::WebMediaPlayerClient* client);
177  virtual blink::WebApplicationCacheHost* createApplicationCacheHost(
178      blink::WebFrame* frame,
179      blink::WebApplicationCacheHostClient* client);
180  virtual blink::WebWorkerPermissionClientProxy*
181      createWorkerPermissionClientProxy(blink::WebFrame* frame);
182  virtual blink::WebCookieJar* cookieJar(blink::WebFrame* frame);
183  virtual blink::WebServiceWorkerProvider* createServiceWorkerProvider(
184      blink::WebFrame* frame,
185      blink::WebServiceWorkerProviderClient*);
186  virtual void didAccessInitialDocument(blink::WebFrame* frame);
187  virtual blink::WebFrame* createChildFrame(blink::WebFrame* parent,
188                                             const blink::WebString& name);
189  virtual void didDisownOpener(blink::WebFrame* frame);
190  virtual void frameDetached(blink::WebFrame* frame);
191  virtual void willClose(blink::WebFrame* frame);
192  virtual void didChangeName(blink::WebFrame* frame,
193                             const blink::WebString& name);
194  virtual void didMatchCSS(
195      blink::WebFrame* frame,
196      const blink::WebVector<blink::WebString>& newly_matching_selectors,
197      const blink::WebVector<blink::WebString>& stopped_matching_selectors);
198  virtual void loadURLExternally(blink::WebFrame* frame,
199                                 const blink::WebURLRequest& request,
200                                 blink::WebNavigationPolicy policy);
201  virtual void loadURLExternally(
202      blink::WebFrame* frame,
203      const blink::WebURLRequest& request,
204      blink::WebNavigationPolicy policy,
205      const blink::WebString& suggested_name);
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,
212      bool is_redirect);
213  // DEPRECATED
214  virtual blink::WebNavigationPolicy decidePolicyForNavigation(
215      blink::WebFrame* frame,
216      const blink::WebURLRequest& request,
217      blink::WebNavigationType type,
218      blink::WebNavigationPolicy default_policy,
219      bool is_redirect);
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);
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,
253      unsigned identifier,
254      blink::WebURLRequest& request,
255      const blink::WebURLResponse& redirect_response);
256  virtual void didReceiveResponse(
257      blink::WebFrame* frame,
258      unsigned identifier,
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,
275                                      int extension_group,
276                                      int world_id);
277  virtual void willReleaseScriptContext(blink::WebFrame* frame,
278                                        v8::Handle<v8::Context> context,
279                                        int world_id);
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,
286                                          int count,
287                                          bool final_update);
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);
313
314 protected:
315  RenderFrameImpl(RenderViewImpl* render_view, int32 routing_id);
316
317 private:
318  friend class RenderFrameObserver;
319
320  // Functions to add and remove observers for this object.
321  void AddObserver(RenderFrameObserver* observer);
322  void RemoveObserver(RenderFrameObserver* observer);
323
324  RenderViewImpl* render_view_;
325  int routing_id_;
326  bool is_swapped_out_;
327  bool is_detaching_;
328
329#if defined(ENABLE_PLUGINS)
330  typedef std::set<PepperPluginInstanceImpl*> PepperPluginSet;
331  PepperPluginSet active_pepper_instances_;
332
333  // Current text input composition text. Empty if no composition is in
334  // progress.
335  base::string16 pepper_composition_text_;
336#endif
337
338  // All the registered observers.
339  ObserverList<RenderFrameObserver> observers_;
340
341  DISALLOW_COPY_AND_ASSIGN(RenderFrameImpl);
342};
343
344}  // namespace content
345
346#endif  // CONTENT_RENDERER_RENDER_FRAME_IMPL_H_
347