[ServiceWorker] Implement WebServiceWorkerContextClient::openWindow().
[chromium-blink-merge.git] / content / renderer / render_frame_impl.h
blobf6784e7783726bb7288bb07f1288007c9dcffed0
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/scoped_ptr.h"
15 #include "base/memory/weak_ptr.h"
16 #include "base/observer_list.h"
17 #include "base/process/process_handle.h"
18 #include "content/common/accessibility_mode_enums.h"
19 #include "content/common/frame_message_enums.h"
20 #include "content/common/mojo/service_registry_impl.h"
21 #include "content/public/common/javascript_message_type.h"
22 #include "content/public/common/referrer.h"
23 #include "content/public/renderer/render_frame.h"
24 #include "content/renderer/render_frame_proxy.h"
25 #include "content/renderer/renderer_webcookiejar_impl.h"
26 #include "ipc/ipc_message.h"
27 #include "media/blink/webmediaplayer_delegate.h"
28 #include "third_party/WebKit/public/web/WebAXObject.h"
29 #include "third_party/WebKit/public/web/WebDataSource.h"
30 #include "third_party/WebKit/public/web/WebFrameClient.h"
31 #include "third_party/WebKit/public/web/WebHistoryCommitType.h"
32 #include "third_party/WebKit/public/web/WebTransitionElementData.h"
33 #include "ui/gfx/range/range.h"
35 #if defined(ENABLE_PLUGINS)
36 #include "content/renderer/pepper/plugin_power_saver_helper.h"
37 #endif
39 #if defined(OS_ANDROID)
40 #include "content/renderer/media/android/renderer_media_player_manager.h"
41 #endif
43 class GURL;
44 class TransportDIB;
45 struct FrameHostMsg_AddNavigationTransitionData_Params;
46 struct FrameMsg_Navigate_Params;
47 struct FrameMsg_NewFrame_WidgetParams;
48 struct FrameMsg_RequestNavigation_Params;
50 namespace blink {
51 class WebGeolocationClient;
52 class WebMouseEvent;
53 class WebContentDecryptionModule;
54 class WebMediaPlayer;
55 class WebPresentationClient;
56 class WebPushClient;
57 class WebSecurityOrigin;
58 struct WebCompositionUnderline;
59 struct WebContextMenuData;
60 struct WebCursorInfo;
61 struct WebTransitionElementData;
64 namespace gfx {
65 class Point;
66 class Range;
67 class Rect;
70 namespace media {
71 class MediaPermission;
72 class WebEncryptedMediaClientImpl;
75 namespace content {
77 class ChildFrameCompositingHelper;
78 class CompositorDependencies;
79 class ExternalPopupMenu;
80 class GeolocationDispatcher;
81 class ManifestManager;
82 class MediaStreamDispatcher;
83 class MediaStreamRendererFactory;
84 class MediaPermissionDispatcher;
85 class MidiDispatcher;
86 class NotificationPermissionDispatcher;
87 class PageState;
88 class PepperPluginInstanceImpl;
89 class PresentationDispatcher;
90 class PushMessagingDispatcher;
91 class RendererAccessibility;
92 class RendererCdmManager;
93 class RendererMediaPlayerManager;
94 class RendererPpapiHost;
95 class RenderFrameObserver;
96 class RenderViewImpl;
97 class RenderWidget;
98 class RenderWidgetFullscreenPepper;
99 class ScreenOrientationDispatcher;
100 class UserMediaClientImpl;
101 enum class SandboxFlags;
102 struct CommitNavigationParams;
103 struct CommonNavigationParams;
104 struct CustomContextMenuContext;
105 struct FrameReplicationState;
106 struct RequestNavigationParams;
107 struct ResourceResponseHead;
109 class CONTENT_EXPORT RenderFrameImpl
110 : public RenderFrame,
111 NON_EXPORTED_BASE(public blink::WebFrameClient),
112 NON_EXPORTED_BASE(public media::WebMediaPlayerDelegate) {
113 public:
114 // Creates a new RenderFrame. |render_view| is the RenderView object that this
115 // frame belongs to.
116 // Callers *must* call |SetWebFrame| immediately after creation.
117 // Note: This is called only when RenderFrame is created by Blink through
118 // createChildFrame.
119 // TODO(creis): We should structure this so that |SetWebFrame| isn't needed.
120 static RenderFrameImpl* Create(RenderViewImpl* render_view, int32 routing_id);
122 // Creates a new RenderFrame with |routing_id| as a child of the RenderFrame
123 // identified by |parent_routing_id| or as the top-level frame if the latter
124 // is MSG_ROUTING_NONE. If |proxy_routing_id| is MSG_ROUTING_NONE, it creates
125 // the Blink WebLocalFrame and inserts it in the proper place in the frame
126 // tree. Otherwise, the frame is semi-orphaned until it commits, at which
127 // point it replaces the proxy identified by |proxy_routing_id|.
128 // Note: This is called only when RenderFrame is being created in response to
129 // IPC message from the browser process. All other frame creation is driven
130 // through Blink and Create.
131 static void CreateFrame(int routing_id,
132 int parent_routing_id,
133 int proxy_routing_id,
134 const FrameReplicationState& replicated_state,
135 CompositorDependencies* compositor_deps,
136 const FrameMsg_NewFrame_WidgetParams& params);
138 // Returns the RenderFrameImpl for the given routing ID.
139 static RenderFrameImpl* FromRoutingID(int routing_id);
141 // Just like RenderFrame::FromWebFrame but returns the implementation.
142 static RenderFrameImpl* FromWebFrame(blink::WebFrame* web_frame);
144 // Used by content_layouttest_support to hook into the creation of
145 // RenderFrameImpls.
146 using CreateRenderFrameImplFunction = RenderFrameImpl* (*)(RenderViewImpl*,
147 int32);
148 static void InstallCreateHook(
149 CreateRenderFrameImplFunction create_render_frame_impl);
151 static content::SandboxFlags WebToContentSandboxFlags(
152 blink::WebSandboxFlags flags);
154 static blink::WebSandboxFlags ContentToWebSandboxFlags(
155 content::SandboxFlags flags);
157 virtual ~RenderFrameImpl();
159 bool is_swapped_out() const {
160 return is_swapped_out_;
163 // TODO(nasko): This can be removed once we don't have a swapped out state on
164 // RenderFrames. See https://crbug.com/357747.
165 void set_render_frame_proxy(RenderFrameProxy* proxy) {
166 render_frame_proxy_ = proxy;
169 // Out-of-process child frames receive a signal from RenderWidgetCompositor
170 // when a compositor frame has committed.
171 void DidCommitCompositorFrame();
173 // TODO(jam): this is a temporary getter until all the code is transitioned
174 // to using RenderFrame instead of RenderView.
175 RenderViewImpl* render_view() { return render_view_.get(); }
177 RendererWebCookieJarImpl* cookie_jar() { return &cookie_jar_; }
179 // Returns the RenderWidget associated with this frame.
180 RenderWidget* GetRenderWidget();
182 // This is called right after creation with the WebLocalFrame for this
183 // RenderFrame. It must be called before Initialize.
184 void SetWebFrame(blink::WebLocalFrame* web_frame);
186 // This method must be called after the frame has been added to the frame
187 // tree. It creates all objects that depend on the frame being at its proper
188 // spot.
189 void Initialize();
191 // Notifications from RenderWidget.
192 void WasHidden();
193 void WasShown();
195 // Start/Stop loading notifications.
196 // TODO(nasko): Those are page-level methods at this time and come from
197 // WebViewClient. We should move them to be WebFrameClient calls and put
198 // logic in the browser side to balance starts/stops.
199 // |to_different_document| will be true unless the load is a fragment
200 // navigation, or triggered by history.pushState/replaceState.
201 virtual void didStartLoading(bool to_different_document);
202 virtual void didStopLoading();
203 virtual void didChangeLoadProgress(double load_progress);
205 AccessibilityMode accessibility_mode() {
206 return accessibility_mode_;
209 RendererAccessibility* renderer_accessibility() {
210 return renderer_accessibility_;
213 void HandleWebAccessibilityEvent(const blink::WebAXObject& obj,
214 blink::WebAXEvent event);
216 // The focused node changed to |node|. If focus was lost from this frame,
217 // |node| will be null.
218 void FocusedNodeChanged(const blink::WebNode& node);
220 // TODO(dmazzoni): the only reason this is here is to plumb it through to
221 // RendererAccessibility. It should use the RenderFrameObserver method, once
222 // blink has a separate accessibility tree per frame.
223 void FocusedNodeChangedForAccessibility(const blink::WebNode& node);
225 #if defined(ENABLE_PLUGINS)
226 // Notification that a PPAPI plugin has been created.
227 void PepperPluginCreated(RendererPpapiHost* host);
229 // Notifies that |instance| has changed the cursor.
230 // This will update the cursor appearance if it is currently over the plugin
231 // instance.
232 void PepperDidChangeCursor(PepperPluginInstanceImpl* instance,
233 const blink::WebCursorInfo& cursor);
235 // Notifies that |instance| has received a mouse event.
236 void PepperDidReceiveMouseEvent(PepperPluginInstanceImpl* instance);
238 // Informs the render view that a PPAPI plugin has changed text input status.
239 void PepperTextInputTypeChanged(PepperPluginInstanceImpl* instance);
240 void PepperCaretPositionChanged(PepperPluginInstanceImpl* instance);
242 // Cancels current composition.
243 void PepperCancelComposition(PepperPluginInstanceImpl* instance);
245 // Informs the render view that a PPAPI plugin has changed selection.
246 void PepperSelectionChanged(PepperPluginInstanceImpl* instance);
248 // Creates a fullscreen container for a pepper plugin instance.
249 RenderWidgetFullscreenPepper* CreatePepperFullscreenContainer(
250 PepperPluginInstanceImpl* plugin);
252 bool IsPepperAcceptingCompositionEvents() const;
254 // Notification that the given plugin has crashed.
255 void PluginCrashed(const base::FilePath& plugin_path,
256 base::ProcessId plugin_pid);
258 // Simulates IME events for testing purpose.
259 void SimulateImeSetComposition(
260 const base::string16& text,
261 const std::vector<blink::WebCompositionUnderline>& underlines,
262 int selection_start,
263 int selection_end);
264 void SimulateImeConfirmComposition(const base::string16& text,
265 const gfx::Range& replacement_range);
267 // TODO(jam): remove these once the IPC handler moves from RenderView to
268 // RenderFrame.
269 void OnImeSetComposition(
270 const base::string16& text,
271 const std::vector<blink::WebCompositionUnderline>& underlines,
272 int selection_start,
273 int selection_end);
274 void OnImeConfirmComposition(const base::string16& text,
275 const gfx::Range& replacement_range,
276 bool keep_selection);
277 #endif // defined(ENABLE_PLUGINS)
279 // May return NULL in some cases, especially if userMediaClient() returns
280 // NULL.
281 MediaStreamDispatcher* GetMediaStreamDispatcher();
283 #if defined(OS_MACOSX) || defined(OS_ANDROID)
284 void DidHideExternalPopupMenu();
285 #endif
287 // IPC::Sender
288 bool Send(IPC::Message* msg) override;
290 // IPC::Listener
291 bool OnMessageReceived(const IPC::Message& msg) override;
293 // RenderFrame implementation:
294 RenderView* GetRenderView() override;
295 int GetRoutingID() override;
296 blink::WebLocalFrame* GetWebFrame() override;
297 blink::WebElement GetFocusedElement() const override;
298 WebPreferences& GetWebkitPreferences() override;
299 int ShowContextMenu(ContextMenuClient* client,
300 const ContextMenuParams& params) override;
301 void CancelContextMenu(int request_id) override;
302 blink::WebNode GetContextMenuNode() const override;
303 blink::WebPlugin* CreatePlugin(
304 blink::WebFrame* frame,
305 const WebPluginInfo& info,
306 const blink::WebPluginParams& params,
307 scoped_ptr<PluginInstanceThrottler> throttler) override;
308 void LoadURLExternally(blink::WebLocalFrame* frame,
309 const blink::WebURLRequest& request,
310 blink::WebNavigationPolicy policy) override;
311 void ExecuteJavaScript(const base::string16& javascript) override;
312 bool IsHidden() override;
313 ServiceRegistry* GetServiceRegistry() override;
314 #if defined(ENABLE_PLUGINS)
315 void RegisterPeripheralPlugin(
316 const GURL& content_origin,
317 const base::Closure& unthrottle_callback) override;
318 bool ShouldThrottleContent(const blink::WebPluginParams& params,
319 const GURL& page_frame_url,
320 GURL* poster_image,
321 bool* cross_origin_main_content) const override;
322 void WhitelistContentOrigin(const GURL& content_origin) override;
323 #endif
324 bool IsFTPDirectoryListing() override;
325 void AttachGuest(int element_instance_id) override;
326 void DetachGuest(int element_instance_id) override;
327 void SetSelectedText(const base::string16& selection_text,
328 size_t offset,
329 const gfx::Range& range) override;
330 void EnsureMojoBuiltinsAreAvailable(v8::Isolate* isolate,
331 v8::Handle<v8::Context> context) override;
333 // blink::WebFrameClient implementation:
334 blink::WebPluginPlaceholder* createPluginPlaceholder(
335 blink::WebLocalFrame*,
336 const blink::WebPluginParams&) override;
337 virtual blink::WebPlugin* createPlugin(blink::WebLocalFrame* frame,
338 const blink::WebPluginParams& params);
339 // TODO(jrummell): Remove this method once blink updated.
340 virtual blink::WebMediaPlayer* createMediaPlayer(
341 blink::WebLocalFrame* frame,
342 const blink::WebURL& url,
343 blink::WebMediaPlayerClient* client);
344 virtual blink::WebMediaPlayer* createMediaPlayer(
345 blink::WebLocalFrame* frame,
346 const blink::WebURL& url,
347 blink::WebMediaPlayerClient* client,
348 blink::WebContentDecryptionModule* initial_cdm);
349 // TODO(jrummell): remove once blink uses encryptedMediaClient().
350 virtual blink::WebContentDecryptionModule* createContentDecryptionModule(
351 blink::WebLocalFrame* frame,
352 const blink::WebSecurityOrigin& security_origin,
353 const blink::WebString& key_system);
354 virtual blink::WebApplicationCacheHost* createApplicationCacheHost(
355 blink::WebLocalFrame* frame,
356 blink::WebApplicationCacheHostClient* client);
357 virtual blink::WebWorkerPermissionClientProxy*
358 createWorkerPermissionClientProxy(blink::WebLocalFrame* frame);
359 virtual blink::WebExternalPopupMenu* createExternalPopupMenu(
360 const blink::WebPopupMenuInfo& popup_menu_info,
361 blink::WebExternalPopupMenuClient* popup_menu_client);
362 virtual blink::WebCookieJar* cookieJar(blink::WebLocalFrame* frame);
363 virtual blink::WebServiceWorkerProvider* createServiceWorkerProvider(
364 blink::WebLocalFrame* frame);
365 virtual void didAccessInitialDocument(blink::WebLocalFrame* frame);
366 virtual blink::WebFrame* createChildFrame(
367 blink::WebLocalFrame* parent,
368 const blink::WebString& name,
369 blink::WebSandboxFlags sandboxFlags);
370 virtual void didDisownOpener(blink::WebLocalFrame* frame);
371 virtual void frameDetached(blink::WebFrame* frame);
372 virtual void frameFocused();
373 virtual void willClose(blink::WebFrame* frame);
374 virtual void didChangeName(blink::WebLocalFrame* frame,
375 const blink::WebString& name);
376 virtual void didMatchCSS(
377 blink::WebLocalFrame* frame,
378 const blink::WebVector<blink::WebString>& newly_matching_selectors,
379 const blink::WebVector<blink::WebString>& stopped_matching_selectors);
380 virtual bool shouldReportDetailedMessageForSource(
381 const blink::WebString& source);
382 virtual void didAddMessageToConsole(const blink::WebConsoleMessage& message,
383 const blink::WebString& source_name,
384 unsigned source_line,
385 const blink::WebString& stack_trace);
386 virtual void loadURLExternally(blink::WebLocalFrame* frame,
387 const blink::WebURLRequest& request,
388 blink::WebNavigationPolicy policy,
389 const blink::WebString& suggested_name);
390 // The WebDataSource::ExtraData* is assumed to be a DocumentState* subclass.
391 virtual blink::WebNavigationPolicy decidePolicyForNavigation(
392 const NavigationPolicyInfo& info);
393 virtual blink::WebHistoryItem historyItemForNewChildFrame(
394 blink::WebFrame* frame);
395 virtual void willSendSubmitEvent(blink::WebLocalFrame* frame,
396 const blink::WebFormElement& form);
397 virtual void willSubmitForm(blink::WebLocalFrame* frame,
398 const blink::WebFormElement& form);
399 virtual void didCreateDataSource(blink::WebLocalFrame* frame,
400 blink::WebDataSource* datasource);
401 virtual void didStartProvisionalLoad(blink::WebLocalFrame* frame,
402 bool is_transition_navigation,
403 double triggering_event_time);
404 virtual void didReceiveServerRedirectForProvisionalLoad(
405 blink::WebLocalFrame* frame);
406 virtual void didFailProvisionalLoad(
407 blink::WebLocalFrame* frame,
408 const blink::WebURLError& error);
409 virtual void didCommitProvisionalLoad(
410 blink::WebLocalFrame* frame,
411 const blink::WebHistoryItem& item,
412 blink::WebHistoryCommitType commit_type);
413 virtual void didCreateNewDocument(blink::WebLocalFrame* frame);
414 virtual void didClearWindowObject(blink::WebLocalFrame* frame);
415 virtual void didCreateDocumentElement(blink::WebLocalFrame* frame);
416 virtual void didReceiveTitle(blink::WebLocalFrame* frame,
417 const blink::WebString& title,
418 blink::WebTextDirection direction);
419 virtual void didChangeIcon(blink::WebLocalFrame* frame,
420 blink::WebIconURL::Type icon_type);
421 virtual void didFinishDocumentLoad(blink::WebLocalFrame* frame);
422 virtual void didHandleOnloadEvents(blink::WebLocalFrame* frame);
423 virtual void didFailLoad(blink::WebLocalFrame* frame,
424 const blink::WebURLError& error);
425 virtual void didFinishLoad(blink::WebLocalFrame* frame);
426 virtual void didNavigateWithinPage(blink::WebLocalFrame* frame,
427 const blink::WebHistoryItem& item,
428 blink::WebHistoryCommitType commit_type);
429 virtual void didUpdateCurrentHistoryItem(blink::WebLocalFrame* frame);
430 virtual void addNavigationTransitionData(
431 const blink::WebTransitionElementData& data);
432 virtual void didChangeThemeColor();
433 virtual void requestNotificationPermission(
434 const blink::WebSecurityOrigin& origin,
435 blink::WebNotificationPermissionCallback* callback);
436 virtual void didChangeSelection(bool is_empty_selection);
437 virtual blink::WebColorChooser* createColorChooser(
438 blink::WebColorChooserClient* client,
439 const blink::WebColor& initial_color,
440 const blink::WebVector<blink::WebColorSuggestion>& suggestions);
441 virtual void runModalAlertDialog(const blink::WebString& message);
442 virtual bool runModalConfirmDialog(const blink::WebString& message);
443 virtual bool runModalPromptDialog(const blink::WebString& message,
444 const blink::WebString& default_value,
445 blink::WebString* actual_value);
446 virtual bool runModalBeforeUnloadDialog(bool is_reload,
447 const blink::WebString& message);
448 virtual void showContextMenu(const blink::WebContextMenuData& data);
449 virtual void clearContextMenu();
450 virtual void willSendRequest(blink::WebLocalFrame* frame,
451 unsigned identifier,
452 blink::WebURLRequest& request,
453 const blink::WebURLResponse& redirect_response);
454 virtual void didReceiveResponse(blink::WebLocalFrame* frame,
455 unsigned identifier,
456 const blink::WebURLResponse& response);
457 virtual void didFinishResourceLoad(blink::WebLocalFrame* frame,
458 unsigned identifier);
459 virtual void didLoadResourceFromMemoryCache(
460 blink::WebLocalFrame* frame,
461 const blink::WebURLRequest& request,
462 const blink::WebURLResponse& response);
463 virtual void didDisplayInsecureContent(blink::WebLocalFrame* frame);
464 virtual void didRunInsecureContent(blink::WebLocalFrame* frame,
465 const blink::WebSecurityOrigin& origin,
466 const blink::WebURL& target);
467 virtual void didAbortLoading(blink::WebLocalFrame* frame);
468 virtual void didCreateScriptContext(blink::WebLocalFrame* frame,
469 v8::Handle<v8::Context> context,
470 int extension_group,
471 int world_id);
472 virtual void willReleaseScriptContext(blink::WebLocalFrame* frame,
473 v8::Handle<v8::Context> context,
474 int world_id);
475 virtual void didFirstVisuallyNonEmptyLayout(blink::WebLocalFrame* frame);
476 virtual void didChangeScrollOffset(blink::WebLocalFrame* frame);
477 virtual void willInsertBody(blink::WebLocalFrame* frame);
478 virtual void reportFindInPageMatchCount(int request_id,
479 int count,
480 bool final_update);
481 virtual void reportFindInPageSelection(int request_id,
482 int active_match_ordinal,
483 const blink::WebRect& sel);
484 virtual void requestStorageQuota(blink::WebLocalFrame* frame,
485 blink::WebStorageQuotaType type,
486 unsigned long long requested_size,
487 blink::WebStorageQuotaCallbacks callbacks);
488 virtual void willOpenWebSocket(blink::WebSocketHandle* handle);
489 virtual blink::WebGeolocationClient* geolocationClient();
490 virtual blink::WebPushClient* pushClient();
491 virtual blink::WebPresentationClient* presentationClient();
492 virtual void willStartUsingPeerConnectionHandler(
493 blink::WebLocalFrame* frame,
494 blink::WebRTCPeerConnectionHandler* handler);
495 virtual blink::WebUserMediaClient* userMediaClient();
496 virtual blink::WebEncryptedMediaClient* encryptedMediaClient();
497 virtual blink::WebMIDIClient* webMIDIClient();
498 virtual bool willCheckAndDispatchMessageEvent(
499 blink::WebLocalFrame* source_frame,
500 blink::WebFrame* target_frame,
501 blink::WebSecurityOrigin target_origin,
502 blink::WebDOMMessageEvent event);
503 virtual blink::WebString userAgentOverride(blink::WebLocalFrame* frame,
504 const blink::WebURL& url);
505 virtual blink::WebString doNotTrackValue(blink::WebLocalFrame* frame);
506 virtual bool allowWebGL(blink::WebLocalFrame* frame, bool default_value);
507 virtual void didLoseWebGLContext(blink::WebLocalFrame* frame,
508 int arb_robustness_status_code);
509 virtual blink::WebScreenOrientationClient* webScreenOrientationClient();
510 virtual bool isControlledByServiceWorker(blink::WebDataSource& data_source);
511 virtual int64_t serviceWorkerID(blink::WebDataSource& data_source);
512 virtual void postAccessibilityEvent(const blink::WebAXObject& obj,
513 blink::WebAXEvent event);
514 virtual void handleAccessibilityFindInPageResult(
515 int identifier,
516 int match_index,
517 const blink::WebAXObject& start_object,
518 int start_offset,
519 const blink::WebAXObject& end_object,
520 int end_offset);
521 virtual void didChangeManifest(blink::WebLocalFrame*);
522 virtual bool enterFullscreen();
523 virtual bool exitFullscreen();
525 // WebMediaPlayerDelegate implementation:
526 void DidPlay(blink::WebMediaPlayer* player) override;
527 void DidPause(blink::WebMediaPlayer* player) override;
528 void PlayerGone(blink::WebMediaPlayer* player) override;
530 // TODO(nasko): Make all tests in RenderViewImplTest friends and then move
531 // this back to private member.
532 void OnNavigate(const FrameMsg_Navigate_Params& params);
534 // Make this frame show an empty, unscriptable page.
535 // TODO(nasko): Remove this method once swapped out state is no longer used.
536 void NavigateToSwappedOutURL();
538 // Binds this render frame's service registry.
539 void BindServiceRegistry(
540 mojo::InterfaceRequest<mojo::ServiceProvider> services,
541 mojo::ServiceProviderPtr exposed_services);
543 ManifestManager* manifest_manager();
545 protected:
546 RenderFrameImpl(RenderViewImpl* render_view, int32 routing_id);
548 private:
549 friend class RenderFrameObserver;
550 friend class RendererAccessibilityTest;
551 FRIEND_TEST_ALL_PREFIXES(ExternalPopupMenuDisplayNoneTest, SelectItem);
552 FRIEND_TEST_ALL_PREFIXES(ExternalPopupMenuRemoveTest, RemoveOnChange);
553 FRIEND_TEST_ALL_PREFIXES(ExternalPopupMenuTest, NormalCase);
554 FRIEND_TEST_ALL_PREFIXES(ExternalPopupMenuTest, ShowPopupThenNavigate);
555 FRIEND_TEST_ALL_PREFIXES(RendererAccessibilityTest,
556 AccessibilityMessagesQueueWhileSwappedOut);
557 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest,
558 OnExtendSelectionAndDelete);
559 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest, ReloadWhileSwappedOut);
560 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest, SendSwapOutACK);
561 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest, OriginReplicationForSwapOut);
562 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest,
563 SetEditableSelectionAndComposition);
564 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest,
565 OnSetAccessibilityMode);
567 typedef std::map<GURL, double> HostZoomLevels;
569 // Functions to add and remove observers for this object.
570 void AddObserver(RenderFrameObserver* observer);
571 void RemoveObserver(RenderFrameObserver* observer);
573 // Builds and sends DidCommitProvisionalLoad to the host.
574 void SendDidCommitProvisionalLoad(blink::WebFrame* frame,
575 blink::WebHistoryCommitType commit_type);
577 // IPC message handlers ------------------------------------------------------
579 // The documentation for these functions should be in
580 // content/common/*_messages.h for the message that the function is handling.
581 void OnBeforeUnload();
582 void OnSwapOut(int proxy_routing_id,
583 bool is_loading,
584 const FrameReplicationState& replicated_frame_state);
585 void OnStop();
586 void OnShowContextMenu(const gfx::Point& location);
587 void OnContextMenuClosed(const CustomContextMenuContext& custom_context);
588 void OnCustomContextMenuAction(const CustomContextMenuContext& custom_context,
589 unsigned action);
590 void OnUndo();
591 void OnRedo();
592 void OnCut();
593 void OnCopy();
594 void OnPaste();
595 void OnPasteAndMatchStyle();
596 void OnDelete();
597 void OnSelectAll();
598 void OnSelectRange(const gfx::Point& base, const gfx::Point& extent);
599 void OnUnselect();
600 void OnMoveRangeSelectionExtent(const gfx::Point& point);
601 void OnReplace(const base::string16& text);
602 void OnReplaceMisspelling(const base::string16& text);
603 void OnCSSInsertRequest(const std::string& css);
604 void OnJavaScriptExecuteRequest(const base::string16& javascript,
605 int id,
606 bool notify_result);
607 void OnJavaScriptExecuteRequestForTests(const base::string16& javascript,
608 int id,
609 bool notify_result);
610 void OnSetEditableSelectionOffsets(int start, int end);
611 void OnSetCompositionFromExistingText(
612 int start, int end,
613 const std::vector<blink::WebCompositionUnderline>& underlines);
614 void OnExecuteNoValueEditCommand(const std::string& name);
615 void OnExtendSelectionAndDelete(int before, int after);
616 void OnReload(bool ignore_cache);
617 void OnTextSurroundingSelectionRequest(size_t max_length);
618 void OnAddStyleSheetByURL(const std::string& url);
619 void OnSetupTransitionView(const std::string& markup);
620 void OnBeginExitTransition(const std::string& css_selector,
621 bool exit_to_native_app);
622 void OnRevertExitTransition();
623 void OnHideTransitionElements(const std::string& css_selector);
624 void OnShowTransitionElements(const std::string& css_selector);
625 void OnSetAccessibilityMode(AccessibilityMode new_mode);
626 void OnDisownOpener();
627 #if defined(OS_ANDROID)
628 void OnSelectPopupMenuItems(bool canceled,
629 const std::vector<int>& selected_indices);
630 #elif defined(OS_MACOSX)
631 void OnSelectPopupMenuItem(int selected_index);
632 void OnCopyToFindPboard();
633 #endif
635 // PlzNavigate
636 void OnRequestNavigation(const CommonNavigationParams& common_params,
637 const RequestNavigationParams& request_params);
638 void OnCommitNavigation(const ResourceResponseHead& response,
639 const GURL& stream_url,
640 const CommonNavigationParams& common_params,
641 const CommitNavigationParams& commit_params);
643 // Virtual since overridden by WebTestProxy for layout tests.
644 virtual blink::WebNavigationPolicy DecidePolicyForNavigation(
645 RenderFrame* render_frame,
646 const NavigationPolicyInfo& info);
647 void OpenURL(blink::WebFrame* frame,
648 const GURL& url,
649 const Referrer& referrer,
650 blink::WebNavigationPolicy policy);
652 // Update current main frame's encoding and send it to browser window.
653 // Since we want to let users see the right encoding info from menu
654 // before finishing loading, we call the UpdateEncoding in
655 // a) function:DidCommitLoadForFrame. When this function is called,
656 // that means we have got first data. In here we try to get encoding
657 // of page if it has been specified in http header.
658 // b) function:DidReceiveTitle. When this function is called,
659 // that means we have got specified title. Because in most of webpages,
660 // title tags will follow meta tags. In here we try to get encoding of
661 // page if it has been specified in meta tag.
662 // c) function:DidFinishDocumentLoadForFrame. When this function is
663 // called, that means we have got whole html page. In here we should
664 // finally get right encoding of page.
665 void UpdateEncoding(blink::WebFrame* frame,
666 const std::string& encoding_name);
668 // Dispatches the current state of selection on the webpage to the browser if
669 // it has changed.
670 // TODO(varunjain): delete this method once we figure out how to keep
671 // selection handles in sync with the webpage.
672 void SyncSelectionIfRequired();
674 bool RunJavaScriptMessage(JavaScriptMessageType type,
675 const base::string16& message,
676 const base::string16& default_value,
677 const GURL& frame_url,
678 base::string16* result);
680 // Loads the appropriate error page for the specified failure into the frame.
681 void LoadNavigationErrorPage(const blink::WebURLRequest& failed_request,
682 const blink::WebURLError& error,
683 bool replace);
685 void HandleJavascriptExecutionResult(const base::string16& javascript,
686 int id,
687 bool notify_result,
688 v8::Handle<v8::Value> result);
690 // Initializes |web_user_media_client_|. If this fails, because it wasn't
691 // possible to create a MediaStreamClient (e.g., WebRTC is disabled), then
692 // |web_user_media_client_| will remain NULL.
693 void InitializeUserMediaClient();
695 blink::WebMediaPlayer* CreateWebMediaPlayerForMediaStream(
696 const blink::WebURL& url,
697 blink::WebMediaPlayerClient* client);
699 // Creates a factory object used for creating audio and video renderers.
700 // The method is virtual so that layouttests can override it.
701 virtual scoped_ptr<MediaStreamRendererFactory> CreateRendererFactory();
703 // Checks that the RenderView is ready to display the navigation to |url|. If
704 // the return value is false, the navigation should be abandoned.
705 bool PrepareRenderViewForNavigation(
706 const GURL& url,
707 bool check_for_stale_navigation,
708 bool is_history_navigation,
709 int current_history_list_offset,
710 bool* is_reload,
711 blink::WebURLRequest::CachePolicy* cache_policy);
713 // PlzNavigate
714 // Sends a FrameHostMsg_BeginNavigation to the browser based on the contents
715 // of the WebURLRequest.
716 void BeginNavigation(blink::WebURLRequest* request);
718 // Returns the URL being loaded by the |frame_|'s request.
719 GURL GetLoadingUrl() const;
721 #if defined(OS_ANDROID)
722 blink::WebMediaPlayer* CreateAndroidWebMediaPlayer(
723 const blink::WebURL& url,
724 blink::WebMediaPlayerClient* client,
725 media::MediaPermission* media_permission,
726 blink::WebContentDecryptionModule* initial_cdm);
728 RendererMediaPlayerManager* GetMediaPlayerManager();
729 #endif
731 #if defined(ENABLE_BROWSER_CDMS)
732 RendererCdmManager* GetCdmManager();
733 #endif
735 // Stores the WebLocalFrame we are associated with.
736 blink::WebLocalFrame* frame_;
738 base::WeakPtr<RenderViewImpl> render_view_;
739 int routing_id_;
740 bool is_swapped_out_;
741 // RenderFrameProxy exists only when is_swapped_out_ is true.
742 // TODO(nasko): This can be removed once we don't have a swapped out state on
743 // RenderFrame. See https://crbug.com/357747.
744 RenderFrameProxy* render_frame_proxy_;
745 bool is_detaching_;
747 // If this frame was created to replace a proxy, this will store the routing
748 // id of the proxy to replace at commit-time, at which time it will be
749 // cleared.
750 // TODO(creis): Remove this after switching to PlzNavigate.
751 int proxy_routing_id_;
753 // Used when the RenderFrame is a local root. For now, RenderWidgets are
754 // added only when a child frame is in a different process from its parent
755 // frame, but eventually this will also apply to top-level frames.
756 // TODO(kenrb): Correct the above statement when top-level frames have their
757 // own RenderWidgets.
758 scoped_refptr<RenderWidget> render_widget_;
760 #if defined(ENABLE_PLUGINS)
761 // Current text input composition text. Empty if no composition is in
762 // progress.
763 base::string16 pepper_composition_text_;
765 PluginPowerSaverHelper* plugin_power_saver_helper_;
766 #endif
768 RendererWebCookieJarImpl cookie_jar_;
770 // All the registered observers.
771 ObserverList<RenderFrameObserver> observers_;
773 scoped_refptr<ChildFrameCompositingHelper> compositing_helper_;
775 // The node that the context menu was pressed over.
776 blink::WebNode context_menu_node_;
778 // External context menu requests we're waiting for. "Internal"
779 // (WebKit-originated) context menu events will have an ID of 0 and will not
780 // be in this map.
782 // We don't want to add internal ones since some of the "special" page
783 // handlers in the browser process just ignore the context menu requests so
784 // avoid showing context menus, and so this will cause right clicks to leak
785 // entries in this map. Most users of the custom context menu (e.g. Pepper
786 // plugins) are normally only on "regular" pages and the regular pages will
787 // always respond properly to the request, so we don't have to worry so
788 // much about leaks.
789 IDMap<ContextMenuClient, IDMapExternalPointer> pending_context_menus_;
791 // The text selection the last time DidChangeSelection got called. May contain
792 // additional characters before and after the selected text, for IMEs. The
793 // portion of this string that is the actual selected text starts at index
794 // |selection_range_.GetMin() - selection_text_offset_| and has length
795 // |selection_range_.length()|.
796 base::string16 selection_text_;
797 // The offset corresponding to the start of |selection_text_| in the document.
798 size_t selection_text_offset_;
799 // Range over the document corresponding to the actual selected text (which
800 // could correspond to a substring of |selection_text_|; see above).
801 gfx::Range selection_range_;
802 // Used to inform didChangeSelection() when it is called in the context
803 // of handling a InputMsg_SelectRange IPC.
804 bool handling_select_range_;
806 // The next group of objects all implement RenderFrameObserver, so are deleted
807 // along with the RenderFrame automatically. This is why we just store weak
808 // references.
810 // Dispatches permission requests for Web Notifications.
811 NotificationPermissionDispatcher* notification_permission_dispatcher_;
813 // Destroyed via the RenderFrameObserver::OnDestruct() mechanism.
814 UserMediaClientImpl* web_user_media_client_;
816 // EncryptedMediaClient attached to this frame; lazily initialized.
817 scoped_ptr<media::WebEncryptedMediaClientImpl> web_encrypted_media_client_;
819 // The media permission dispatcher attached to this frame, lazily initialized.
820 MediaPermissionDispatcher* media_permission_dispatcher_;
822 // MidiClient attached to this frame; lazily initialized.
823 MidiDispatcher* midi_dispatcher_;
825 #if defined(OS_ANDROID)
826 // Manages all media players in this render frame for communicating with the
827 // real media player in the browser process. It's okay to use a raw pointer
828 // since it's a RenderFrameObserver.
829 RendererMediaPlayerManager* media_player_manager_;
830 #endif
832 #if defined(ENABLE_BROWSER_CDMS)
833 // Manage all CDMs in this render frame for communicating with the real CDM in
834 // the browser process. It's okay to use a raw pointer since it's a
835 // RenderFrameObserver.
836 RendererCdmManager* cdm_manager_;
837 #endif
839 #if defined(VIDEO_HOLE)
840 // Whether or not this RenderFrameImpl contains a media player. Used to
841 // register as an observer for video-hole-specific events.
842 bool contains_media_player_;
843 #endif
845 // The geolocation dispatcher attached to this frame, lazily initialized.
846 GeolocationDispatcher* geolocation_dispatcher_;
848 // The push messaging dispatcher attached to this frame, lazily initialized.
849 PushMessagingDispatcher* push_messaging_dispatcher_;
851 // The presentation dispatcher implementation attached to this frame, lazily
852 // initialized.
853 PresentationDispatcher* presentation_dispatcher_;
855 ServiceRegistryImpl service_registry_;
857 // The screen orientation dispatcher attached to the frame, lazily
858 // initialized.
859 ScreenOrientationDispatcher* screen_orientation_dispatcher_;
861 // The Manifest Manager handles the manifest requests from the browser
862 // process.
863 ManifestManager* manifest_manager_;
865 // The current accessibility mode.
866 AccessibilityMode accessibility_mode_;
868 // Only valid if |accessibility_mode_| is anything other than
869 // AccessibilityModeOff.
870 RendererAccessibility* renderer_accessibility_;
872 #if defined(OS_MACOSX) || defined(OS_ANDROID)
873 // The external popup for the currently showing select popup.
874 scoped_ptr<ExternalPopupMenu> external_popup_menu_;
875 #endif
877 base::WeakPtrFactory<RenderFrameImpl> weak_factory_;
879 DISALLOW_COPY_AND_ASSIGN(RenderFrameImpl);
882 } // namespace content
884 #endif // CONTENT_RENDERER_RENDER_FRAME_IMPL_H_