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/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/console_message_level.h"
22 #include "content/public/common/javascript_message_type.h"
23 #include "content/public/common/referrer.h"
24 #include "content/public/renderer/render_frame.h"
25 #include "content/renderer/render_frame_proxy.h"
26 #include "content/renderer/renderer_webcookiejar_impl.h"
27 #include "ipc/ipc_message.h"
28 #include "media/blink/webmediaplayer_delegate.h"
29 #include "media/blink/webmediaplayer_params.h"
30 #include "mojo/application/public/interfaces/service_provider.mojom.h"
31 #include "mojo/application/public/interfaces/shell.mojom.h"
32 #include "third_party/WebKit/public/platform/modules/app_banner/WebAppBannerClient.h"
33 #include "third_party/WebKit/public/web/WebAXObject.h"
34 #include "third_party/WebKit/public/web/WebDataSource.h"
35 #include "third_party/WebKit/public/web/WebFrameClient.h"
36 #include "third_party/WebKit/public/web/WebHistoryCommitType.h"
37 #include "third_party/WebKit/public/web/WebScriptExecutionCallback.h"
38 #include "ui/gfx/range/range.h"
40 #if defined(ENABLE_PLUGINS)
41 #include "content/renderer/pepper/plugin_power_saver_helper.h"
44 #if defined(OS_ANDROID)
45 #include "content/renderer/media/android/renderer_media_player_manager.h"
48 #if defined(ENABLE_MOJO_MEDIA)
49 #include "media/mojo/interfaces/service_factory.mojom.h"
54 struct FrameMsg_NewFrame_WidgetParams
;
55 struct FrameMsg_PostMessage_Params
;
56 struct FrameMsg_TextTrackSettings_Params
;
59 class WebGeolocationClient
;
61 class WebContentDecryptionModule
;
63 class WebPresentationClient
;
65 class WebSecurityOrigin
;
66 struct WebCompositionUnderline
;
67 struct WebContextMenuData
;
79 class MediaPermission
;
80 class WebEncryptedMediaClientImpl
;
84 class ServiceProvider
;
93 class ChildFrameCompositingHelper
;
94 class CompositorDependencies
;
97 class ExternalPopupMenu
;
98 class GeolocationDispatcher
;
99 class ManifestManager
;
100 class MediaStreamDispatcher
;
101 class MediaStreamRendererFactory
;
102 class MediaPermissionDispatcher
;
103 class MidiDispatcher
;
104 class NavigationState
;
105 class NotificationPermissionDispatcher
;
107 class PepperPluginInstanceImpl
;
108 class PermissionDispatcher
;
109 class PresentationDispatcher
;
110 class PushMessagingDispatcher
;
111 class RendererAccessibility
;
112 class RendererCdmManager
;
113 class RendererMediaPlayerManager
;
114 class RendererPpapiHost
;
115 class RenderFrameObserver
;
116 class RenderViewImpl
;
118 class RenderWidgetFullscreenPepper
;
119 class ScreenOrientationDispatcher
;
120 class UserMediaClientImpl
;
121 struct CommonNavigationParams
;
122 struct CustomContextMenuContext
;
123 struct FrameReplicationState
;
124 struct NavigationParams
;
125 struct RequestNavigationParams
;
126 struct ResourceResponseHead
;
127 struct StartNavigationParams
;
128 struct StreamOverrideParameters
;
131 class CONTENT_EXPORT RenderFrameImpl
132 : public RenderFrame
,
133 NON_EXPORTED_BASE(public blink::WebFrameClient
),
134 NON_EXPORTED_BASE(public media::WebMediaPlayerDelegate
) {
136 // Creates a new RenderFrame as the main frame of |render_view|.
137 static RenderFrameImpl
* CreateMainFrame(RenderViewImpl
* render_view
,
140 // Creates a new RenderFrame with |routing_id|. If |proxy_routing_id| is
141 // MSG_ROUTING_NONE, it creates the Blink WebLocalFrame and inserts it into
142 // the frame tree after the frame identified by
143 // |previous_sibling_routing_id|, or as the first child if
144 // |previous_sibling_routing_id| is MSG_ROUTING_NONE. Otherwise, the frame is
145 // semi-orphaned until it commits, at which point it replaces the proxy
146 // identified by |proxy_routing_id|. The frame's opener is set to the frame
147 // identified by |opener_routing_id|. The frame is created as a child of the
148 // RenderFrame identified by |parent_routing_id| or as the top-level frame if
149 // the latter is MSG_ROUTING_NONE. Note: This is called only when
150 // RenderFrame is being created in response to IPC message from the browser
151 // process. All other frame creation is driven through Blink and Create.
152 static void CreateFrame(int routing_id
,
153 int proxy_routing_id
,
154 int opener_routing_id
,
155 int parent_routing_id
,
156 int previous_sibling_routing_id
,
157 const FrameReplicationState
& replicated_state
,
158 CompositorDependencies
* compositor_deps
,
159 const FrameMsg_NewFrame_WidgetParams
& params
);
161 // Returns the RenderFrameImpl for the given routing ID.
162 static RenderFrameImpl
* FromRoutingID(int routing_id
);
164 // Just like RenderFrame::FromWebFrame but returns the implementation.
165 static RenderFrameImpl
* FromWebFrame(blink::WebFrame
* web_frame
);
167 // Used by content_layouttest_support to hook into the creation of
169 struct CreateParams
{
170 CreateParams(RenderViewImpl
* render_view
, int32 routing_id
)
171 : render_view(render_view
), routing_id(routing_id
) {}
174 RenderViewImpl
* render_view
;
178 using CreateRenderFrameImplFunction
=
179 RenderFrameImpl
* (*)(const CreateParams
&);
180 static void InstallCreateHook(
181 CreateRenderFrameImplFunction create_render_frame_impl
);
183 // Looks up and returns the WebFrame corresponding to a given opener frame
184 // routing ID. Also stores the opener's RenderView routing ID into
185 // |opener_view_routing_id|.
187 // TODO(alexmos): remove RenderViewImpl's dependency on
188 // opener_view_routing_id.
189 static blink::WebFrame
* ResolveOpener(int opener_frame_routing_id
,
190 int* opener_view_routing_id
);
192 virtual ~RenderFrameImpl();
194 bool is_swapped_out() const {
195 return is_swapped_out_
;
198 // TODO(nasko): This can be removed once we don't have a swapped out state on
199 // RenderFrames. See https://crbug.com/357747.
200 void set_render_frame_proxy(RenderFrameProxy
* proxy
) {
201 render_frame_proxy_
= proxy
;
204 // Out-of-process child frames receive a signal from RenderWidgetCompositor
205 // when a compositor frame has committed.
206 void DidCommitCompositorFrame();
208 // TODO(jam): this is a temporary getter until all the code is transitioned
209 // to using RenderFrame instead of RenderView.
210 RenderViewImpl
* render_view() { return render_view_
.get(); }
212 RendererWebCookieJarImpl
* cookie_jar() { return &cookie_jar_
; }
214 // Returns the RenderWidget associated with this frame.
215 RenderWidget
* GetRenderWidget();
217 DevToolsAgent
* devtools_agent() { return devtools_agent_
; }
219 // This is called right after creation with the WebLocalFrame for this
220 // RenderFrame. It must be called before Initialize.
221 void SetWebFrame(blink::WebLocalFrame
* web_frame
);
223 // This method must be called after the frame has been added to the frame
224 // tree. It creates all objects that depend on the frame being at its proper
228 // Notifications from RenderWidget.
231 void WidgetWillClose();
233 // Start/Stop loading notifications.
234 // TODO(nasko): Those are page-level methods at this time and come from
235 // WebViewClient. We should move them to be WebFrameClient calls and put
236 // logic in the browser side to balance starts/stops.
237 // |to_different_document| will be true unless the load is a fragment
238 // navigation, or triggered by history.pushState/replaceState.
239 virtual void didStartLoading(bool to_different_document
);
240 virtual void didStopLoading();
241 virtual void didChangeLoadProgress(double load_progress
);
243 AccessibilityMode
accessibility_mode() {
244 return accessibility_mode_
;
247 RendererAccessibility
* renderer_accessibility() {
248 return renderer_accessibility_
;
251 void HandleWebAccessibilityEvent(const blink::WebAXObject
& obj
,
252 blink::WebAXEvent event
);
254 // The focused node changed to |node|. If focus was lost from this frame,
255 // |node| will be null.
256 void FocusedNodeChanged(const blink::WebNode
& node
);
258 // TODO(dmazzoni): the only reason this is here is to plumb it through to
259 // RendererAccessibility. It should use the RenderFrameObserver method, once
260 // blink has a separate accessibility tree per frame.
261 void FocusedNodeChangedForAccessibility(const blink::WebNode
& node
);
263 #if defined(ENABLE_PLUGINS)
264 // Notification that a PPAPI plugin has been created.
265 void PepperPluginCreated(RendererPpapiHost
* host
);
267 // Notifies that |instance| has changed the cursor.
268 // This will update the cursor appearance if it is currently over the plugin
270 void PepperDidChangeCursor(PepperPluginInstanceImpl
* instance
,
271 const blink::WebCursorInfo
& cursor
);
273 // Notifies that |instance| has received a mouse event.
274 void PepperDidReceiveMouseEvent(PepperPluginInstanceImpl
* instance
);
276 // Informs the render view that a PPAPI plugin has changed text input status.
277 void PepperTextInputTypeChanged(PepperPluginInstanceImpl
* instance
);
278 void PepperCaretPositionChanged(PepperPluginInstanceImpl
* instance
);
280 // Cancels current composition.
281 void PepperCancelComposition(PepperPluginInstanceImpl
* instance
);
283 // Informs the render view that a PPAPI plugin has changed selection.
284 void PepperSelectionChanged(PepperPluginInstanceImpl
* instance
);
286 // Creates a fullscreen container for a pepper plugin instance.
287 RenderWidgetFullscreenPepper
* CreatePepperFullscreenContainer(
288 PepperPluginInstanceImpl
* plugin
);
290 bool IsPepperAcceptingCompositionEvents() const;
292 // Notification that the given plugin has crashed.
293 void PluginCrashed(const base::FilePath
& plugin_path
,
294 base::ProcessId plugin_pid
);
296 // Simulates IME events for testing purpose.
297 void SimulateImeSetComposition(
298 const base::string16
& text
,
299 const std::vector
<blink::WebCompositionUnderline
>& underlines
,
302 void SimulateImeConfirmComposition(const base::string16
& text
,
303 const gfx::Range
& replacement_range
);
305 // TODO(jam): remove these once the IPC handler moves from RenderView to
307 void OnImeSetComposition(
308 const base::string16
& text
,
309 const std::vector
<blink::WebCompositionUnderline
>& underlines
,
312 void OnImeConfirmComposition(const base::string16
& text
,
313 const gfx::Range
& replacement_range
,
314 bool keep_selection
);
315 #endif // defined(ENABLE_PLUGINS)
317 // May return NULL in some cases, especially if userMediaClient() returns
319 MediaStreamDispatcher
* GetMediaStreamDispatcher();
321 #if defined(OS_MACOSX) || defined(OS_ANDROID)
322 void DidHideExternalPopupMenu();
326 bool Send(IPC::Message
* msg
) override
;
329 bool OnMessageReceived(const IPC::Message
& msg
) override
;
331 // RenderFrame implementation:
332 RenderView
* GetRenderView() override
;
333 int GetRoutingID() override
;
334 blink::WebLocalFrame
* GetWebFrame() override
;
335 blink::WebElement
GetFocusedElement() const override
;
336 WebPreferences
& GetWebkitPreferences() override
;
337 int ShowContextMenu(ContextMenuClient
* client
,
338 const ContextMenuParams
& params
) override
;
339 void CancelContextMenu(int request_id
) override
;
340 blink::WebNode
GetContextMenuNode() const override
;
341 blink::WebPlugin
* CreatePlugin(
342 blink::WebFrame
* frame
,
343 const WebPluginInfo
& info
,
344 const blink::WebPluginParams
& params
,
345 scoped_ptr
<PluginInstanceThrottler
> throttler
) override
;
346 void LoadURLExternally(blink::WebLocalFrame
* frame
,
347 const blink::WebURLRequest
& request
,
348 blink::WebNavigationPolicy policy
) override
;
349 void ExecuteJavaScript(const base::string16
& javascript
) override
;
350 bool IsHidden() override
;
351 ServiceRegistry
* GetServiceRegistry() override
;
352 #if defined(ENABLE_PLUGINS)
353 void RegisterPeripheralPlugin(
354 const url::Origin
& content_origin
,
355 const base::Closure
& unthrottle_callback
) override
;
356 PluginPowerSaverHelper
* plugin_power_saver_helper() {
357 return plugin_power_saver_helper_
;
360 bool IsFTPDirectoryListing() override
;
361 void AttachGuest(int element_instance_id
) override
;
362 void DetachGuest(int element_instance_id
) override
;
363 void SetSelectedText(const base::string16
& selection_text
,
365 const gfx::Range
& range
) override
;
366 void EnsureMojoBuiltinsAreAvailable(v8::Isolate
* isolate
,
367 v8::Local
<v8::Context
> context
) override
;
368 void AddMessageToConsole(ConsoleMessageLevel level
,
369 const std::string
& message
) override
;
371 // blink::WebFrameClient implementation:
372 virtual blink::WebPlugin
* createPlugin(blink::WebLocalFrame
* frame
,
373 const blink::WebPluginParams
& params
);
374 virtual blink::WebMediaPlayer
* createMediaPlayer(
375 blink::WebLocalFrame
* frame
,
376 const blink::WebURL
& url
,
377 blink::WebMediaPlayerClient
* client
,
378 blink::WebMediaPlayerEncryptedMediaClient
* encrypted_client
,
379 blink::WebContentDecryptionModule
* initial_cdm
);
380 virtual blink::WebApplicationCacheHost
* createApplicationCacheHost(
381 blink::WebLocalFrame
* frame
,
382 blink::WebApplicationCacheHostClient
* client
);
383 virtual blink::WebWorkerContentSettingsClientProxy
*
384 createWorkerContentSettingsClientProxy(blink::WebLocalFrame
* frame
);
385 virtual blink::WebExternalPopupMenu
* createExternalPopupMenu(
386 const blink::WebPopupMenuInfo
& popup_menu_info
,
387 blink::WebExternalPopupMenuClient
* popup_menu_client
);
388 virtual blink::WebCookieJar
* cookieJar(blink::WebLocalFrame
* frame
);
389 virtual blink::WebServiceWorkerProvider
* createServiceWorkerProvider(
390 blink::WebLocalFrame
* frame
);
391 virtual void didAccessInitialDocument(blink::WebLocalFrame
* frame
);
392 virtual blink::WebFrame
* createChildFrame(
393 blink::WebLocalFrame
* parent
,
394 blink::WebTreeScopeType scope
,
395 const blink::WebString
& name
,
396 blink::WebSandboxFlags sandboxFlags
);
397 virtual void didChangeOpener(blink::WebFrame
* frame
);
398 virtual void frameDetached(blink::WebFrame
* frame
, DetachType type
);
399 virtual void frameFocused();
400 virtual void willClose(blink::WebFrame
* frame
);
401 virtual void didChangeName(blink::WebLocalFrame
* frame
,
402 const blink::WebString
& name
);
403 virtual void didChangeSandboxFlags(blink::WebFrame
* child_frame
,
404 blink::WebSandboxFlags flags
);
405 virtual void didMatchCSS(
406 blink::WebLocalFrame
* frame
,
407 const blink::WebVector
<blink::WebString
>& newly_matching_selectors
,
408 const blink::WebVector
<blink::WebString
>& stopped_matching_selectors
);
409 virtual bool shouldReportDetailedMessageForSource(
410 const blink::WebString
& source
);
411 virtual void didAddMessageToConsole(const blink::WebConsoleMessage
& message
,
412 const blink::WebString
& source_name
,
413 unsigned source_line
,
414 const blink::WebString
& stack_trace
);
415 virtual void loadURLExternally(blink::WebLocalFrame
* frame
,
416 const blink::WebURLRequest
& request
,
417 blink::WebNavigationPolicy policy
,
418 const blink::WebString
& suggested_name
);
419 // The WebDataSource::ExtraData* is assumed to be a DocumentState* subclass.
420 virtual blink::WebNavigationPolicy
decidePolicyForNavigation(
421 const NavigationPolicyInfo
& info
);
422 virtual blink::WebHistoryItem
historyItemForNewChildFrame(
423 blink::WebFrame
* frame
);
424 virtual void willSendSubmitEvent(blink::WebLocalFrame
* frame
,
425 const blink::WebFormElement
& form
);
426 virtual void willSubmitForm(blink::WebLocalFrame
* frame
,
427 const blink::WebFormElement
& form
);
428 virtual void didCreateDataSource(blink::WebLocalFrame
* frame
,
429 blink::WebDataSource
* datasource
);
430 virtual void didStartProvisionalLoad(blink::WebLocalFrame
* frame
,
431 double triggering_event_time
);
432 virtual void didReceiveServerRedirectForProvisionalLoad(
433 blink::WebLocalFrame
* frame
);
434 virtual void didFailProvisionalLoad(
435 blink::WebLocalFrame
* frame
,
436 const blink::WebURLError
& error
,
437 blink::WebHistoryCommitType commit_type
);
438 virtual void didCommitProvisionalLoad(
439 blink::WebLocalFrame
* frame
,
440 const blink::WebHistoryItem
& item
,
441 blink::WebHistoryCommitType commit_type
);
442 virtual void didCreateNewDocument(blink::WebLocalFrame
* frame
);
443 virtual void didClearWindowObject(blink::WebLocalFrame
* frame
);
444 virtual void didCreateDocumentElement(blink::WebLocalFrame
* frame
);
445 virtual void didReceiveTitle(blink::WebLocalFrame
* frame
,
446 const blink::WebString
& title
,
447 blink::WebTextDirection direction
);
448 virtual void didChangeIcon(blink::WebLocalFrame
* frame
,
449 blink::WebIconURL::Type icon_type
);
450 virtual void didFinishDocumentLoad(blink::WebLocalFrame
* frame
,
451 bool document_is_empty
);
452 virtual void didHandleOnloadEvents(blink::WebLocalFrame
* frame
);
453 virtual void didFailLoad(blink::WebLocalFrame
* frame
,
454 const blink::WebURLError
& error
,
455 blink::WebHistoryCommitType commit_type
);
456 virtual void didFinishLoad(blink::WebLocalFrame
* frame
);
457 virtual void didNavigateWithinPage(blink::WebLocalFrame
* frame
,
458 const blink::WebHistoryItem
& item
,
459 blink::WebHistoryCommitType commit_type
);
460 virtual void didUpdateCurrentHistoryItem(blink::WebLocalFrame
* frame
);
461 virtual void didChangeThemeColor();
462 virtual void dispatchLoad();
463 virtual void requestNotificationPermission(
464 const blink::WebSecurityOrigin
& origin
,
465 blink::WebNotificationPermissionCallback
* callback
);
466 virtual void didChangeSelection(bool is_empty_selection
);
467 virtual blink::WebColorChooser
* createColorChooser(
468 blink::WebColorChooserClient
* client
,
469 const blink::WebColor
& initial_color
,
470 const blink::WebVector
<blink::WebColorSuggestion
>& suggestions
);
471 virtual void runModalAlertDialog(const blink::WebString
& message
);
472 virtual bool runModalConfirmDialog(const blink::WebString
& message
);
473 virtual bool runModalPromptDialog(const blink::WebString
& message
,
474 const blink::WebString
& default_value
,
475 blink::WebString
* actual_value
);
476 virtual bool runModalBeforeUnloadDialog(bool is_reload
,
477 const blink::WebString
& message
);
478 virtual void showContextMenu(const blink::WebContextMenuData
& data
);
479 virtual void clearContextMenu();
480 virtual void willSendRequest(blink::WebLocalFrame
* frame
,
482 blink::WebURLRequest
& request
,
483 const blink::WebURLResponse
& redirect_response
);
484 virtual void didReceiveResponse(blink::WebLocalFrame
* frame
,
486 const blink::WebURLResponse
& response
);
487 virtual void didLoadResourceFromMemoryCache(
488 blink::WebLocalFrame
* frame
,
489 const blink::WebURLRequest
& request
,
490 const blink::WebURLResponse
& response
);
491 virtual void didDisplayInsecureContent(blink::WebLocalFrame
* frame
);
492 virtual void didRunInsecureContent(blink::WebLocalFrame
* frame
,
493 const blink::WebSecurityOrigin
& origin
,
494 const blink::WebURL
& target
);
495 virtual void didChangePerformanceTiming();
496 virtual void didAbortLoading(blink::WebLocalFrame
* frame
);
497 virtual void didCreateScriptContext(blink::WebLocalFrame
* frame
,
498 v8::Local
<v8::Context
> context
,
501 virtual void willReleaseScriptContext(blink::WebLocalFrame
* frame
,
502 v8::Local
<v8::Context
> context
,
504 virtual void didChangeScrollOffset(blink::WebLocalFrame
* frame
);
505 virtual void willInsertBody(blink::WebLocalFrame
* frame
);
506 virtual void reportFindInPageMatchCount(int request_id
,
509 virtual void reportFindInPageSelection(int request_id
,
510 int active_match_ordinal
,
511 const blink::WebRect
& sel
);
512 virtual void requestStorageQuota(blink::WebLocalFrame
* frame
,
513 blink::WebStorageQuotaType type
,
514 unsigned long long requested_size
,
515 blink::WebStorageQuotaCallbacks callbacks
);
516 virtual void willOpenWebSocket(blink::WebSocketHandle
* handle
);
517 virtual blink::WebGeolocationClient
* geolocationClient();
518 virtual blink::WebPushClient
* pushClient();
519 virtual blink::WebPresentationClient
* presentationClient();
520 virtual void willStartUsingPeerConnectionHandler(
521 blink::WebLocalFrame
* frame
,
522 blink::WebRTCPeerConnectionHandler
* handler
);
523 virtual blink::WebUserMediaClient
* userMediaClient();
524 virtual blink::WebEncryptedMediaClient
* encryptedMediaClient();
525 virtual blink::WebMIDIClient
* webMIDIClient();
526 virtual bool willCheckAndDispatchMessageEvent(
527 blink::WebLocalFrame
* source_frame
,
528 blink::WebFrame
* target_frame
,
529 blink::WebSecurityOrigin target_origin
,
530 blink::WebDOMMessageEvent event
);
531 virtual blink::WebString
userAgentOverride(blink::WebLocalFrame
* frame
,
532 const blink::WebURL
& url
);
533 virtual blink::WebString
doNotTrackValue(blink::WebLocalFrame
* frame
);
534 virtual bool allowWebGL(blink::WebLocalFrame
* frame
, bool default_value
);
535 virtual void didLoseWebGLContext(blink::WebLocalFrame
* frame
,
536 int arb_robustness_status_code
);
537 virtual blink::WebScreenOrientationClient
* webScreenOrientationClient();
538 virtual bool isControlledByServiceWorker(blink::WebDataSource
& data_source
);
539 virtual int64_t serviceWorkerID(blink::WebDataSource
& data_source
);
540 virtual void postAccessibilityEvent(const blink::WebAXObject
& obj
,
541 blink::WebAXEvent event
);
542 virtual void handleAccessibilityFindInPageResult(
545 const blink::WebAXObject
& start_object
,
547 const blink::WebAXObject
& end_object
,
549 virtual void didChangeManifest(blink::WebLocalFrame
*);
550 virtual bool enterFullscreen();
551 virtual bool exitFullscreen();
552 virtual blink::WebPermissionClient
* permissionClient();
553 virtual blink::WebAppBannerClient
* appBannerClient();
554 virtual void registerProtocolHandler(const blink::WebString
& scheme
,
555 const blink::WebURL
& url
,
556 const blink::WebString
& title
);
557 virtual void unregisterProtocolHandler(const blink::WebString
& scheme
,
558 const blink::WebURL
& url
);
559 virtual blink::WebBluetooth
* bluetooth();
560 virtual blink::WebUSBClient
* usbClient();
562 #if defined(ENABLE_WEBVR)
563 blink::WebVRClient
* webVRClient() override
;
566 // WebMediaPlayerDelegate implementation:
567 void DidPlay(blink::WebMediaPlayer
* player
) override
;
568 void DidPause(blink::WebMediaPlayer
* player
) override
;
569 void PlayerGone(blink::WebMediaPlayer
* player
) override
;
571 // Make this frame show an empty, unscriptable page.
572 // TODO(nasko): Remove this method once swapped out state is no longer used.
573 void NavigateToSwappedOutURL();
575 // Binds this render frame's service registry.
576 void BindServiceRegistry(
577 mojo::InterfaceRequest
<mojo::ServiceProvider
> services
,
578 mojo::ServiceProviderPtr exposed_services
);
580 ManifestManager
* manifest_manager();
582 // TODO(creis): Remove when the only caller, the HistoryController, is no
584 void SetPendingNavigationParams(
585 scoped_ptr
<NavigationParams
> navigation_params
);
588 explicit RenderFrameImpl(const CreateParams
& params
);
591 friend class RenderFrameImplTest
;
592 friend class RenderFrameObserver
;
593 friend class RendererAccessibilityTest
;
594 friend class TestRenderFrame
;
595 FRIEND_TEST_ALL_PREFIXES(ExternalPopupMenuDisplayNoneTest
, SelectItem
);
596 FRIEND_TEST_ALL_PREFIXES(ExternalPopupMenuRemoveTest
, RemoveOnChange
);
597 FRIEND_TEST_ALL_PREFIXES(ExternalPopupMenuTest
, NormalCase
);
598 FRIEND_TEST_ALL_PREFIXES(ExternalPopupMenuTest
, ShowPopupThenNavigate
);
599 FRIEND_TEST_ALL_PREFIXES(RendererAccessibilityTest
,
600 AccessibilityMessagesQueueWhileSwappedOut
);
602 // A wrapper class used as the callback for JavaScript executed
603 // in an isolated world.
604 class JavaScriptIsolatedWorldRequest
605 : public blink::WebScriptExecutionCallback
{
607 JavaScriptIsolatedWorldRequest(
611 base::WeakPtr
<RenderFrameImpl
> render_frame_impl
);
613 const blink::WebVector
<v8::Local
<v8::Value
>>& result
) override
;
616 ~JavaScriptIsolatedWorldRequest();
621 base::WeakPtr
<RenderFrameImpl
> render_frame_impl_
;
623 DISALLOW_COPY_AND_ASSIGN(JavaScriptIsolatedWorldRequest
);
626 typedef std::map
<GURL
, double> HostZoomLevels
;
628 // Creates a new RenderFrame. |render_view| is the RenderView object that this
630 // Callers *must* call |SetWebFrame| immediately after creation.
631 static RenderFrameImpl
* Create(RenderViewImpl
* render_view
, int32 routing_id
);
633 // Functions to add and remove observers for this object.
634 void AddObserver(RenderFrameObserver
* observer
);
635 void RemoveObserver(RenderFrameObserver
* observer
);
637 // Builds and sends DidCommitProvisionalLoad to the host.
638 void SendDidCommitProvisionalLoad(blink::WebFrame
* frame
,
639 blink::WebHistoryCommitType commit_type
,
640 const blink::WebHistoryItem
& item
);
642 // IPC message handlers ------------------------------------------------------
644 // The documentation for these functions should be in
645 // content/common/*_messages.h for the message that the function is handling.
646 void OnNavigate(const CommonNavigationParams
& common_params
,
647 const StartNavigationParams
& start_params
,
648 const RequestNavigationParams
& request_params
);
649 void OnBeforeUnload();
650 void OnSwapOut(int proxy_routing_id
,
652 const FrameReplicationState
& replicated_frame_state
);
654 void OnShowContextMenu(const gfx::Point
& location
);
655 void OnContextMenuClosed(const CustomContextMenuContext
& custom_context
);
656 void OnCustomContextMenuAction(const CustomContextMenuContext
& custom_context
,
663 void OnPasteAndMatchStyle();
666 void OnSelectRange(const gfx::Point
& base
, const gfx::Point
& extent
);
667 void OnAdjustSelectionByCharacterOffset(int start_adjust
, int end_adjust
);
669 void OnMoveRangeSelectionExtent(const gfx::Point
& point
);
670 void OnReplace(const base::string16
& text
);
671 void OnReplaceMisspelling(const base::string16
& text
);
672 void OnCSSInsertRequest(const std::string
& css
);
673 void OnAddMessageToConsole(ConsoleMessageLevel level
,
674 const std::string
& message
);
675 void OnJavaScriptExecuteRequest(const base::string16
& javascript
,
678 void OnJavaScriptExecuteRequestForTests(const base::string16
& javascript
,
681 bool has_user_gesture
);
682 void OnJavaScriptExecuteRequestInIsolatedWorld(const base::string16
& jscript
,
686 void OnVisualStateRequest(uint64 key
);
687 void OnSetEditableSelectionOffsets(int start
, int end
);
688 void OnSetCompositionFromExistingText(
690 const std::vector
<blink::WebCompositionUnderline
>& underlines
);
691 void OnExecuteNoValueEditCommand(const std::string
& name
);
692 void OnExtendSelectionAndDelete(int before
, int after
);
693 void OnReload(bool ignore_cache
);
694 void OnTextSurroundingSelectionRequest(size_t max_length
);
695 void OnSetAccessibilityMode(AccessibilityMode new_mode
);
696 void OnSnapshotAccessibilityTree(int callback_id
);
697 void OnUpdateOpener(int opener_routing_id
);
698 void OnDidUpdateSandboxFlags(blink::WebSandboxFlags flags
);
699 void OnTextTrackSettingsChanged(
700 const FrameMsg_TextTrackSettings_Params
& params
);
701 void OnPostMessageEvent(const FrameMsg_PostMessage_Params
& params
);
702 #if defined(OS_ANDROID)
703 void OnSelectPopupMenuItems(bool canceled
,
704 const std::vector
<int>& selected_indices
);
705 #elif defined(OS_MACOSX)
706 void OnSelectPopupMenuItem(int selected_index
);
707 void OnCopyToFindPboard();
710 void OnCommitNavigation(const ResourceResponseHead
& response
,
711 const GURL
& stream_url
,
712 const CommonNavigationParams
& common_params
,
713 const RequestNavigationParams
& request_params
);
714 void OnFailedNavigation(const CommonNavigationParams
& common_params
,
715 const RequestNavigationParams
& request_params
,
716 bool has_stale_copy_in_cache
,
719 // Virtual since overridden by WebTestProxy for layout tests.
720 virtual blink::WebNavigationPolicy
DecidePolicyForNavigation(
721 RenderFrame
* render_frame
,
722 const NavigationPolicyInfo
& info
);
723 void OpenURL(blink::WebFrame
* frame
,
725 const Referrer
& referrer
,
726 blink::WebNavigationPolicy policy
);
728 // Performs a navigation in the frame. This provides a unified function for
729 // the current code path and the browser-side navigation path (in
730 // development). Currently used by OnNavigate, with all *NavigationParams
731 // provided by the browser. |stream_params| should be null.
732 // PlzNavigate: used by OnCommitNavigation, with |common_params| and
733 // |request_params| received by the browser. |stream_params| should be non
734 // null and created from the information provided by the browser.
735 // |start_params| is not used.
736 void NavigateInternal(const CommonNavigationParams
& common_params
,
737 const StartNavigationParams
& start_params
,
738 const RequestNavigationParams
& request_params
,
739 scoped_ptr
<StreamOverrideParameters
> stream_params
);
741 // Update current main frame's encoding and send it to browser window.
742 // Since we want to let users see the right encoding info from menu
743 // before finishing loading, we call the UpdateEncoding in
744 // a) function:DidCommitLoadForFrame. When this function is called,
745 // that means we have got first data. In here we try to get encoding
746 // of page if it has been specified in http header.
747 // b) function:DidReceiveTitle. When this function is called,
748 // that means we have got specified title. Because in most of webpages,
749 // title tags will follow meta tags. In here we try to get encoding of
750 // page if it has been specified in meta tag.
751 // c) function:DidFinishDocumentLoadForFrame. When this function is
752 // called, that means we have got whole html page. In here we should
753 // finally get right encoding of page.
754 void UpdateEncoding(blink::WebFrame
* frame
,
755 const std::string
& encoding_name
);
757 // Dispatches the current state of selection on the webpage to the browser if
759 // TODO(varunjain): delete this method once we figure out how to keep
760 // selection handles in sync with the webpage.
761 void SyncSelectionIfRequired();
763 bool RunJavaScriptMessage(JavaScriptMessageType type
,
764 const base::string16
& message
,
765 const base::string16
& default_value
,
766 const GURL
& frame_url
,
767 base::string16
* result
);
769 // Loads the appropriate error page for the specified failure into the frame.
770 void LoadNavigationErrorPage(const blink::WebURLRequest
& failed_request
,
771 const blink::WebURLError
& error
,
774 void HandleJavascriptExecutionResult(const base::string16
& javascript
,
777 v8::Local
<v8::Value
> result
);
779 // Initializes |web_user_media_client_|. If this fails, because it wasn't
780 // possible to create a MediaStreamClient (e.g., WebRTC is disabled), then
781 // |web_user_media_client_| will remain NULL.
782 void InitializeUserMediaClient();
784 blink::WebMediaPlayer
* CreateWebMediaPlayerForMediaStream(
785 blink::WebMediaPlayerClient
* client
);
787 // Creates a factory object used for creating audio and video renderers.
788 scoped_ptr
<MediaStreamRendererFactory
> CreateRendererFactory();
790 // Does preparation for the navigation to |url|.
791 void PrepareRenderViewForNavigation(
793 const RequestNavigationParams
& request_params
,
795 blink::WebURLRequest::CachePolicy
* cache_policy
);
798 // Sends a FrameHostMsg_BeginNavigation to the browser based on the contents
799 // of the WebURLRequest.
800 void BeginNavigation(blink::WebURLRequest
* request
);
803 void LoadDataURL(const CommonNavigationParams
& params
,
804 blink::WebFrame
* frame
);
806 // Sends a proper FrameHostMsg_DidFailProvisionalLoadWithError_Params IPC for
807 // the failed request |request|.
808 void SendFailedProvisionalLoad(const blink::WebURLRequest
& request
,
809 const blink::WebURLError
& error
,
810 blink::WebLocalFrame
* frame
);
812 bool ShouldDisplayErrorPageForFailedLoad(int error_code
,
813 const GURL
& unreachable_url
);
815 // Returns the URL being loaded by the |frame_|'s request.
816 GURL
GetLoadingUrl() const;
818 // If we initiated a navigation, this function will populate |document_state|
819 // with the navigation information saved in OnNavigate().
820 void PopulateDocumentStateFromPending(DocumentState
* document_state
);
822 // Returns a new NavigationState populated with the navigation information
823 // saved in OnNavigate().
824 NavigationState
* CreateNavigationStateFromPending();
826 #if defined(OS_ANDROID)
827 blink::WebMediaPlayer
* CreateAndroidWebMediaPlayer(
828 blink::WebMediaPlayerClient
* client
,
829 blink::WebMediaPlayerEncryptedMediaClient
* encrypted_client
,
830 const media::WebMediaPlayerParams
& params
);
832 RendererMediaPlayerManager
* GetMediaPlayerManager();
835 bool AreSecureCodecsSupported();
837 media::MediaPermission
* GetMediaPermission();
839 #if defined(ENABLE_MOJO_MEDIA)
840 media::interfaces::ServiceFactory
* GetMediaServiceFactory();
842 // Called when a connection error happened on |media_service_factory_|.
843 void OnMediaServiceFactoryConnectionError();
846 media::CdmFactory
* GetCdmFactory();
848 void RegisterMojoServices();
850 // Connects to a Mojo application and returns a proxy to its exposed
852 mojo::ServiceProviderPtr
ConnectToApplication(const GURL
& url
);
854 // Stores the WebLocalFrame we are associated with. This is null from the
855 // constructor until SetWebFrame is called, and it is null after
856 // frameDetached is called until destruction (which is asynchronous in the
857 // case of the main frame, but not subframes).
858 blink::WebLocalFrame
* frame_
;
860 // Boolean value indicating whether this RenderFrameImpl object is for a
861 // subframe or not. It remains accurate during destruction, even when |frame_|
862 // has been invalidated.
865 // Frame is a local root if it is rendered in a process different than parent
866 // or it is a main frame.
869 base::WeakPtr
<RenderViewImpl
> render_view_
;
871 bool is_swapped_out_
;
873 // RenderFrameProxy exists only when is_swapped_out_ is true.
874 // TODO(nasko): This can be removed once we don't have a swapped out state on
875 // RenderFrame. See https://crbug.com/357747.
876 RenderFrameProxy
* render_frame_proxy_
;
879 // If this frame was created to replace a proxy, this will store the routing
880 // id of the proxy to replace at commit-time, at which time it will be
882 // TODO(creis): Remove this after switching to PlzNavigate.
883 int proxy_routing_id_
;
885 // Used when the RenderFrame is a local root. For now, RenderWidgets are
886 // added only when a child frame is in a different process from its parent
887 // frame, but eventually this will also apply to top-level frames.
888 // TODO(kenrb): Correct the above statement when top-level frames have their
889 // own RenderWidgets.
890 scoped_refptr
<RenderWidget
> render_widget_
;
892 // Temporarily holds state pertaining to a navigation that has been initiated
893 // until the NavigationState corresponding to the new navigation is created in
894 // didCreateDataSource().
895 scoped_ptr
<NavigationParams
> pending_navigation_params_
;
897 #if defined(ENABLE_PLUGINS)
898 // Current text input composition text. Empty if no composition is in
900 base::string16 pepper_composition_text_
;
902 PluginPowerSaverHelper
* plugin_power_saver_helper_
;
905 RendererWebCookieJarImpl cookie_jar_
;
907 // All the registered observers.
908 base::ObserverList
<RenderFrameObserver
> observers_
;
910 scoped_refptr
<ChildFrameCompositingHelper
> compositing_helper_
;
912 // The node that the context menu was pressed over.
913 blink::WebNode context_menu_node_
;
915 // External context menu requests we're waiting for. "Internal"
916 // (WebKit-originated) context menu events will have an ID of 0 and will not
919 // We don't want to add internal ones since some of the "special" page
920 // handlers in the browser process just ignore the context menu requests so
921 // avoid showing context menus, and so this will cause right clicks to leak
922 // entries in this map. Most users of the custom context menu (e.g. Pepper
923 // plugins) are normally only on "regular" pages and the regular pages will
924 // always respond properly to the request, so we don't have to worry so
926 IDMap
<ContextMenuClient
, IDMapExternalPointer
> pending_context_menus_
;
928 // The text selection the last time DidChangeSelection got called. May contain
929 // additional characters before and after the selected text, for IMEs. The
930 // portion of this string that is the actual selected text starts at index
931 // |selection_range_.GetMin() - selection_text_offset_| and has length
932 // |selection_range_.length()|.
933 base::string16 selection_text_
;
934 // The offset corresponding to the start of |selection_text_| in the document.
935 size_t selection_text_offset_
;
936 // Range over the document corresponding to the actual selected text (which
937 // could correspond to a substring of |selection_text_|; see above).
938 gfx::Range selection_range_
;
939 // Used to inform didChangeSelection() when it is called in the context
940 // of handling a InputMsg_SelectRange IPC.
941 bool handling_select_range_
;
943 // The next group of objects all implement RenderFrameObserver, so are deleted
944 // along with the RenderFrame automatically. This is why we just store weak
947 // Dispatches permission requests for Web Notifications.
948 NotificationPermissionDispatcher
* notification_permission_dispatcher_
;
950 // Destroyed via the RenderFrameObserver::OnDestruct() mechanism.
951 UserMediaClientImpl
* web_user_media_client_
;
953 // EncryptedMediaClient attached to this frame; lazily initialized.
954 scoped_ptr
<media::WebEncryptedMediaClientImpl
> web_encrypted_media_client_
;
956 // The media permission dispatcher attached to this frame, lazily initialized.
957 MediaPermissionDispatcher
* media_permission_dispatcher_
;
959 #if defined(ENABLE_MOJO_MEDIA)
960 // The media factory attached to this frame, lazily initialized.
961 media::interfaces::ServiceFactoryPtr media_service_factory_
;
964 // MidiClient attached to this frame; lazily initialized.
965 MidiDispatcher
* midi_dispatcher_
;
967 #if defined(OS_ANDROID)
968 // Manages all media players in this render frame for communicating with the
969 // real media player in the browser process. It's okay to use a raw pointer
970 // since it's a RenderFrameObserver.
971 RendererMediaPlayerManager
* media_player_manager_
;
974 #if defined(ENABLE_BROWSER_CDMS)
975 // Manage all CDMs in this render frame for communicating with the real CDM in
976 // the browser process. It's okay to use a raw pointer since it's a
977 // RenderFrameObserver.
978 RendererCdmManager
* cdm_manager_
;
981 // The CDM factory attached to this frame, lazily initialized.
982 scoped_ptr
<media::CdmFactory
> cdm_factory_
;
984 #if defined(VIDEO_HOLE)
985 // Whether or not this RenderFrameImpl contains a media player. Used to
986 // register as an observer for video-hole-specific events.
987 bool contains_media_player_
;
990 // True if this RenderFrame has ever played media.
991 bool has_played_media_
;
993 // The devtools agent for this frame; only created for main frame and
995 DevToolsAgent
* devtools_agent_
;
997 // The geolocation dispatcher attached to this frame, lazily initialized.
998 GeolocationDispatcher
* geolocation_dispatcher_
;
1000 // The push messaging dispatcher attached to this frame, lazily initialized.
1001 PushMessagingDispatcher
* push_messaging_dispatcher_
;
1003 // The presentation dispatcher implementation attached to this frame, lazily
1005 PresentationDispatcher
* presentation_dispatcher_
;
1007 ServiceRegistryImpl service_registry_
;
1009 // The shell proxy used to connect to Mojo applications.
1010 mojo::ShellPtr mojo_shell_
;
1012 // The screen orientation dispatcher attached to the frame, lazily
1014 ScreenOrientationDispatcher
* screen_orientation_dispatcher_
;
1016 // The Manifest Manager handles the manifest requests from the browser
1018 ManifestManager
* manifest_manager_
;
1020 // The current accessibility mode.
1021 AccessibilityMode accessibility_mode_
;
1023 // Only valid if |accessibility_mode_| is anything other than
1024 // AccessibilityModeOff.
1025 RendererAccessibility
* renderer_accessibility_
;
1027 scoped_ptr
<PermissionDispatcher
> permission_client_
;
1029 scoped_ptr
<blink::WebAppBannerClient
> app_banner_client_
;
1031 scoped_ptr
<blink::WebBluetooth
> bluetooth_
;
1033 scoped_ptr
<blink::WebUSBClient
> usb_client_
;
1035 #if defined(ENABLE_WEBVR)
1036 // The VR dispatcher attached to the frame, lazily initialized.
1037 scoped_ptr
<VRDispatcher
> vr_dispatcher_
;
1040 #if defined(OS_MACOSX) || defined(OS_ANDROID)
1041 // The external popup for the currently showing select popup.
1042 scoped_ptr
<ExternalPopupMenu
> external_popup_menu_
;
1045 base::WeakPtrFactory
<RenderFrameImpl
> weak_factory_
;
1047 DISALLOW_COPY_AND_ASSIGN(RenderFrameImpl
);
1050 } // namespace content
1052 #endif // CONTENT_RENDERER_RENDER_FRAME_IMPL_H_