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