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/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"
39 #if defined(OS_ANDROID)
40 #include "content/renderer/media/android/renderer_media_player_manager.h"
45 struct FrameHostMsg_AddNavigationTransitionData_Params
;
46 struct FrameMsg_NewFrame_WidgetParams
;
49 class WebGeolocationClient
;
51 class WebContentDecryptionModule
;
53 class WebPresentationClient
;
55 class WebSecurityOrigin
;
56 struct WebCompositionUnderline
;
57 struct WebContextMenuData
;
59 struct WebTransitionElementData
;
69 class MediaPermission
;
70 class WebEncryptedMediaClientImpl
;
75 class ChildFrameCompositingHelper
;
76 class CompositorDependencies
;
79 class ExternalPopupMenu
;
80 class GeolocationDispatcher
;
81 class ManifestManager
;
82 class MediaStreamDispatcher
;
83 class MediaStreamRendererFactory
;
84 class MediaPermissionDispatcher
;
86 class NavigationState
;
87 class NotificationPermissionDispatcher
;
89 class PepperPluginInstanceImpl
;
90 class PermissionManager
;
91 class PresentationDispatcher
;
92 class PushMessagingDispatcher
;
93 class RendererAccessibility
;
94 class RendererCdmManager
;
95 class RendererMediaPlayerManager
;
96 class RendererPpapiHost
;
97 class RenderFrameObserver
;
100 class RenderWidgetFullscreenPepper
;
101 class ScreenOrientationDispatcher
;
102 class UserMediaClientImpl
;
103 enum class SandboxFlags
;
104 struct CommonNavigationParams
;
105 struct CustomContextMenuContext
;
106 struct FrameReplicationState
;
107 struct NavigationParams
;
108 struct RequestNavigationParams
;
109 struct ResourceResponseHead
;
110 struct StartNavigationParams
;
112 class CONTENT_EXPORT RenderFrameImpl
113 : public RenderFrame
,
114 NON_EXPORTED_BASE(public blink::WebFrameClient
),
115 NON_EXPORTED_BASE(public media::WebMediaPlayerDelegate
) {
117 // Creates a new RenderFrame. |render_view| is the RenderView object that this
119 // Callers *must* call |SetWebFrame| immediately after creation.
120 // Note: This is called only when RenderFrame is created by Blink through
122 // TODO(creis): We should structure this so that |SetWebFrame| isn't needed.
123 static RenderFrameImpl
* Create(RenderViewImpl
* render_view
, int32 routing_id
);
125 // Creates a new RenderFrame with |routing_id| as a child of the RenderFrame
126 // identified by |parent_routing_id| or as the top-level frame if the latter
127 // is MSG_ROUTING_NONE. If |proxy_routing_id| is MSG_ROUTING_NONE, it creates
128 // the Blink WebLocalFrame and inserts it in the proper place in the frame
129 // tree. Otherwise, the frame is semi-orphaned until it commits, at which
130 // point it replaces the proxy identified by |proxy_routing_id|.
131 // Note: This is called only when RenderFrame is being created in response to
132 // IPC message from the browser process. All other frame creation is driven
133 // through Blink and Create.
134 static void CreateFrame(int routing_id
,
135 int parent_routing_id
,
136 int proxy_routing_id
,
137 const FrameReplicationState
& replicated_state
,
138 CompositorDependencies
* compositor_deps
,
139 const FrameMsg_NewFrame_WidgetParams
& params
);
141 // Returns the RenderFrameImpl for the given routing ID.
142 static RenderFrameImpl
* FromRoutingID(int routing_id
);
144 // Just like RenderFrame::FromWebFrame but returns the implementation.
145 static RenderFrameImpl
* FromWebFrame(blink::WebFrame
* web_frame
);
147 // Used by content_layouttest_support to hook into the creation of
149 using CreateRenderFrameImplFunction
= RenderFrameImpl
* (*)(RenderViewImpl
*,
151 static void InstallCreateHook(
152 CreateRenderFrameImplFunction create_render_frame_impl
);
154 static content::SandboxFlags
WebToContentSandboxFlags(
155 blink::WebSandboxFlags flags
);
157 static blink::WebSandboxFlags
ContentToWebSandboxFlags(
158 content::SandboxFlags flags
);
160 virtual ~RenderFrameImpl();
162 bool is_swapped_out() const {
163 return is_swapped_out_
;
166 // TODO(nasko): This can be removed once we don't have a swapped out state on
167 // RenderFrames. See https://crbug.com/357747.
168 void set_render_frame_proxy(RenderFrameProxy
* proxy
) {
169 render_frame_proxy_
= proxy
;
172 // Out-of-process child frames receive a signal from RenderWidgetCompositor
173 // when a compositor frame has committed.
174 void DidCommitCompositorFrame();
176 // TODO(jam): this is a temporary getter until all the code is transitioned
177 // to using RenderFrame instead of RenderView.
178 RenderViewImpl
* render_view() { return render_view_
.get(); }
180 RendererWebCookieJarImpl
* cookie_jar() { return &cookie_jar_
; }
182 // Returns the RenderWidget associated with this frame.
183 RenderWidget
* GetRenderWidget();
185 // This is called right after creation with the WebLocalFrame for this
186 // RenderFrame. It must be called before Initialize.
187 void SetWebFrame(blink::WebLocalFrame
* web_frame
);
189 // This method must be called after the frame has been added to the frame
190 // tree. It creates all objects that depend on the frame being at its proper
194 // Notifications from RenderWidget.
198 // Start/Stop loading notifications.
199 // TODO(nasko): Those are page-level methods at this time and come from
200 // WebViewClient. We should move them to be WebFrameClient calls and put
201 // logic in the browser side to balance starts/stops.
202 // |to_different_document| will be true unless the load is a fragment
203 // navigation, or triggered by history.pushState/replaceState.
204 virtual void didStartLoading(bool to_different_document
);
205 virtual void didStopLoading();
206 virtual void didChangeLoadProgress(double load_progress
);
208 AccessibilityMode
accessibility_mode() {
209 return accessibility_mode_
;
212 RendererAccessibility
* renderer_accessibility() {
213 return renderer_accessibility_
;
216 void HandleWebAccessibilityEvent(const blink::WebAXObject
& obj
,
217 blink::WebAXEvent event
);
219 // The focused node changed to |node|. If focus was lost from this frame,
220 // |node| will be null.
221 void FocusedNodeChanged(const blink::WebNode
& node
);
223 // TODO(dmazzoni): the only reason this is here is to plumb it through to
224 // RendererAccessibility. It should use the RenderFrameObserver method, once
225 // blink has a separate accessibility tree per frame.
226 void FocusedNodeChangedForAccessibility(const blink::WebNode
& node
);
228 #if defined(ENABLE_PLUGINS)
229 // Notification that a PPAPI plugin has been created.
230 void PepperPluginCreated(RendererPpapiHost
* host
);
232 // Notifies that |instance| has changed the cursor.
233 // This will update the cursor appearance if it is currently over the plugin
235 void PepperDidChangeCursor(PepperPluginInstanceImpl
* instance
,
236 const blink::WebCursorInfo
& cursor
);
238 // Notifies that |instance| has received a mouse event.
239 void PepperDidReceiveMouseEvent(PepperPluginInstanceImpl
* instance
);
241 // Informs the render view that a PPAPI plugin has changed text input status.
242 void PepperTextInputTypeChanged(PepperPluginInstanceImpl
* instance
);
243 void PepperCaretPositionChanged(PepperPluginInstanceImpl
* instance
);
245 // Cancels current composition.
246 void PepperCancelComposition(PepperPluginInstanceImpl
* instance
);
248 // Informs the render view that a PPAPI plugin has changed selection.
249 void PepperSelectionChanged(PepperPluginInstanceImpl
* instance
);
251 // Creates a fullscreen container for a pepper plugin instance.
252 RenderWidgetFullscreenPepper
* CreatePepperFullscreenContainer(
253 PepperPluginInstanceImpl
* plugin
);
255 bool IsPepperAcceptingCompositionEvents() const;
257 // Notification that the given plugin has crashed.
258 void PluginCrashed(const base::FilePath
& plugin_path
,
259 base::ProcessId plugin_pid
);
261 // Simulates IME events for testing purpose.
262 void SimulateImeSetComposition(
263 const base::string16
& text
,
264 const std::vector
<blink::WebCompositionUnderline
>& underlines
,
267 void SimulateImeConfirmComposition(const base::string16
& text
,
268 const gfx::Range
& replacement_range
);
270 // TODO(jam): remove these once the IPC handler moves from RenderView to
272 void OnImeSetComposition(
273 const base::string16
& text
,
274 const std::vector
<blink::WebCompositionUnderline
>& underlines
,
277 void OnImeConfirmComposition(const base::string16
& text
,
278 const gfx::Range
& replacement_range
,
279 bool keep_selection
);
280 #endif // defined(ENABLE_PLUGINS)
282 // May return NULL in some cases, especially if userMediaClient() returns
284 MediaStreamDispatcher
* GetMediaStreamDispatcher();
286 #if defined(OS_MACOSX) || defined(OS_ANDROID)
287 void DidHideExternalPopupMenu();
291 bool Send(IPC::Message
* msg
) override
;
294 bool OnMessageReceived(const IPC::Message
& msg
) override
;
296 // RenderFrame implementation:
297 RenderView
* GetRenderView() override
;
298 int GetRoutingID() override
;
299 blink::WebLocalFrame
* GetWebFrame() override
;
300 blink::WebElement
GetFocusedElement() const override
;
301 WebPreferences
& GetWebkitPreferences() override
;
302 int ShowContextMenu(ContextMenuClient
* client
,
303 const ContextMenuParams
& params
) override
;
304 void CancelContextMenu(int request_id
) override
;
305 blink::WebNode
GetContextMenuNode() const override
;
306 blink::WebPlugin
* CreatePlugin(
307 blink::WebFrame
* frame
,
308 const WebPluginInfo
& info
,
309 const blink::WebPluginParams
& params
,
310 scoped_ptr
<PluginInstanceThrottler
> throttler
) override
;
311 void LoadURLExternally(blink::WebLocalFrame
* frame
,
312 const blink::WebURLRequest
& request
,
313 blink::WebNavigationPolicy policy
) override
;
314 void ExecuteJavaScript(const base::string16
& javascript
) override
;
315 bool IsHidden() override
;
316 ServiceRegistry
* GetServiceRegistry() override
;
317 #if defined(ENABLE_PLUGINS)
318 void RegisterPeripheralPlugin(
319 const GURL
& content_origin
,
320 const base::Closure
& unthrottle_callback
) override
;
321 PluginPowerSaverHelper
* plugin_power_saver_helper() {
322 return plugin_power_saver_helper_
;
325 bool IsFTPDirectoryListing() override
;
326 void AttachGuest(int element_instance_id
) override
;
327 void DetachGuest(int element_instance_id
) override
;
328 void SetSelectedText(const base::string16
& selection_text
,
330 const gfx::Range
& range
) override
;
331 void EnsureMojoBuiltinsAreAvailable(v8::Isolate
* isolate
,
332 v8::Handle
<v8::Context
> context
) override
;
334 // blink::WebFrameClient implementation:
335 blink::WebPluginPlaceholder
* createPluginPlaceholder(
336 blink::WebLocalFrame
*,
337 const blink::WebPluginParams
&) override
;
338 virtual blink::WebPlugin
* createPlugin(blink::WebLocalFrame
* frame
,
339 const blink::WebPluginParams
& params
);
340 // TODO(jrummell): Remove this method once blink updated.
341 virtual blink::WebMediaPlayer
* createMediaPlayer(
342 blink::WebLocalFrame
* frame
,
343 const blink::WebURL
& url
,
344 blink::WebMediaPlayerClient
* client
);
345 virtual blink::WebMediaPlayer
* createMediaPlayer(
346 blink::WebLocalFrame
* frame
,
347 const blink::WebURL
& url
,
348 blink::WebMediaPlayerClient
* client
,
349 blink::WebContentDecryptionModule
* initial_cdm
);
350 virtual blink::WebApplicationCacheHost
* createApplicationCacheHost(
351 blink::WebLocalFrame
* frame
,
352 blink::WebApplicationCacheHostClient
* client
);
353 virtual blink::WebWorkerContentSettingsClientProxy
*
354 createWorkerContentSettingsClientProxy(blink::WebLocalFrame
* frame
);
355 virtual blink::WebExternalPopupMenu
* createExternalPopupMenu(
356 const blink::WebPopupMenuInfo
& popup_menu_info
,
357 blink::WebExternalPopupMenuClient
* popup_menu_client
);
358 virtual blink::WebCookieJar
* cookieJar(blink::WebLocalFrame
* frame
);
359 virtual blink::WebServiceWorkerProvider
* createServiceWorkerProvider(
360 blink::WebLocalFrame
* frame
);
361 virtual void didAccessInitialDocument(blink::WebLocalFrame
* frame
);
362 virtual blink::WebFrame
* createChildFrame(
363 blink::WebLocalFrame
* parent
,
364 const blink::WebString
& name
,
365 blink::WebSandboxFlags sandboxFlags
);
366 virtual void didDisownOpener(blink::WebLocalFrame
* frame
);
367 virtual void frameDetached(blink::WebFrame
* frame
);
368 virtual void frameFocused();
369 virtual void willClose(blink::WebFrame
* frame
);
370 virtual void didChangeName(blink::WebLocalFrame
* frame
,
371 const blink::WebString
& name
);
372 virtual void didChangeSandboxFlags(blink::WebFrame
* child_frame
,
373 blink::WebSandboxFlags flags
);
374 virtual void didMatchCSS(
375 blink::WebLocalFrame
* frame
,
376 const blink::WebVector
<blink::WebString
>& newly_matching_selectors
,
377 const blink::WebVector
<blink::WebString
>& stopped_matching_selectors
);
378 virtual bool shouldReportDetailedMessageForSource(
379 const blink::WebString
& source
);
380 virtual void didAddMessageToConsole(const blink::WebConsoleMessage
& message
,
381 const blink::WebString
& source_name
,
382 unsigned source_line
,
383 const blink::WebString
& stack_trace
);
384 virtual void loadURLExternally(blink::WebLocalFrame
* frame
,
385 const blink::WebURLRequest
& request
,
386 blink::WebNavigationPolicy policy
,
387 const blink::WebString
& suggested_name
);
388 // The WebDataSource::ExtraData* is assumed to be a DocumentState* subclass.
389 virtual blink::WebNavigationPolicy
decidePolicyForNavigation(
390 const NavigationPolicyInfo
& info
);
391 virtual blink::WebHistoryItem
historyItemForNewChildFrame(
392 blink::WebFrame
* frame
);
393 virtual void willSendSubmitEvent(blink::WebLocalFrame
* frame
,
394 const blink::WebFormElement
& form
);
395 virtual void willSubmitForm(blink::WebLocalFrame
* frame
,
396 const blink::WebFormElement
& form
);
397 virtual void didCreateDataSource(blink::WebLocalFrame
* frame
,
398 blink::WebDataSource
* datasource
);
399 virtual void didStartProvisionalLoad(blink::WebLocalFrame
* frame
,
400 bool is_transition_navigation
,
401 double triggering_event_time
);
402 virtual void didReceiveServerRedirectForProvisionalLoad(
403 blink::WebLocalFrame
* frame
);
404 virtual void didFailProvisionalLoad(
405 blink::WebLocalFrame
* frame
,
406 const blink::WebURLError
& error
);
407 virtual void didCommitProvisionalLoad(
408 blink::WebLocalFrame
* frame
,
409 const blink::WebHistoryItem
& item
,
410 blink::WebHistoryCommitType commit_type
);
411 virtual void didCreateNewDocument(blink::WebLocalFrame
* frame
);
412 virtual void didClearWindowObject(blink::WebLocalFrame
* frame
);
413 virtual void didCreateDocumentElement(blink::WebLocalFrame
* frame
);
414 virtual void didReceiveTitle(blink::WebLocalFrame
* frame
,
415 const blink::WebString
& title
,
416 blink::WebTextDirection direction
);
417 virtual void didChangeIcon(blink::WebLocalFrame
* frame
,
418 blink::WebIconURL::Type icon_type
);
419 virtual void didFinishDocumentLoad(blink::WebLocalFrame
* frame
);
420 virtual void didHandleOnloadEvents(blink::WebLocalFrame
* frame
);
421 virtual void didFailLoad(blink::WebLocalFrame
* frame
,
422 const blink::WebURLError
& error
);
423 virtual void didFinishLoad(blink::WebLocalFrame
* frame
);
424 virtual void didNavigateWithinPage(blink::WebLocalFrame
* frame
,
425 const blink::WebHistoryItem
& item
,
426 blink::WebHistoryCommitType commit_type
);
427 virtual void didUpdateCurrentHistoryItem(blink::WebLocalFrame
* frame
);
428 virtual void addNavigationTransitionData(
429 const blink::WebTransitionElementData
& data
);
430 virtual void didChangeThemeColor();
431 virtual void dispatchLoad();
432 virtual void requestNotificationPermission(
433 const blink::WebSecurityOrigin
& origin
,
434 blink::WebNotificationPermissionCallback
* callback
);
435 virtual void didChangeSelection(bool is_empty_selection
);
436 virtual blink::WebColorChooser
* createColorChooser(
437 blink::WebColorChooserClient
* client
,
438 const blink::WebColor
& initial_color
,
439 const blink::WebVector
<blink::WebColorSuggestion
>& suggestions
);
440 virtual void runModalAlertDialog(const blink::WebString
& message
);
441 virtual bool runModalConfirmDialog(const blink::WebString
& message
);
442 virtual bool runModalPromptDialog(const blink::WebString
& message
,
443 const blink::WebString
& default_value
,
444 blink::WebString
* actual_value
);
445 virtual bool runModalBeforeUnloadDialog(bool is_reload
,
446 const blink::WebString
& message
);
447 virtual void showContextMenu(const blink::WebContextMenuData
& data
);
448 virtual void clearContextMenu();
449 virtual void willSendRequest(blink::WebLocalFrame
* frame
,
451 blink::WebURLRequest
& request
,
452 const blink::WebURLResponse
& redirect_response
);
453 virtual void didReceiveResponse(blink::WebLocalFrame
* frame
,
455 const blink::WebURLResponse
& response
);
456 virtual void didFinishResourceLoad(blink::WebLocalFrame
* frame
,
457 unsigned identifier
);
458 virtual void didLoadResourceFromMemoryCache(
459 blink::WebLocalFrame
* frame
,
460 const blink::WebURLRequest
& request
,
461 const blink::WebURLResponse
& response
);
462 virtual void didDisplayInsecureContent(blink::WebLocalFrame
* frame
);
463 virtual void didRunInsecureContent(blink::WebLocalFrame
* frame
,
464 const blink::WebSecurityOrigin
& origin
,
465 const blink::WebURL
& target
);
466 virtual void didAbortLoading(blink::WebLocalFrame
* frame
);
467 virtual void didCreateScriptContext(blink::WebLocalFrame
* frame
,
468 v8::Handle
<v8::Context
> context
,
471 virtual void willReleaseScriptContext(blink::WebLocalFrame
* frame
,
472 v8::Handle
<v8::Context
> context
,
474 virtual void didFirstVisuallyNonEmptyLayout(blink::WebLocalFrame
* frame
);
475 virtual void didChangeScrollOffset(blink::WebLocalFrame
* frame
);
476 virtual void willInsertBody(blink::WebLocalFrame
* frame
);
477 virtual void reportFindInPageMatchCount(int request_id
,
480 virtual void reportFindInPageSelection(int request_id
,
481 int active_match_ordinal
,
482 const blink::WebRect
& sel
);
483 virtual void requestStorageQuota(blink::WebLocalFrame
* frame
,
484 blink::WebStorageQuotaType type
,
485 unsigned long long requested_size
,
486 blink::WebStorageQuotaCallbacks callbacks
);
487 virtual void willOpenWebSocket(blink::WebSocketHandle
* handle
);
488 virtual blink::WebGeolocationClient
* geolocationClient();
489 virtual blink::WebPushClient
* pushClient();
490 virtual blink::WebPresentationClient
* presentationClient();
491 virtual void willStartUsingPeerConnectionHandler(
492 blink::WebLocalFrame
* frame
,
493 blink::WebRTCPeerConnectionHandler
* handler
);
494 virtual blink::WebUserMediaClient
* userMediaClient();
495 virtual blink::WebEncryptedMediaClient
* encryptedMediaClient();
496 virtual blink::WebMIDIClient
* webMIDIClient();
497 virtual bool willCheckAndDispatchMessageEvent(
498 blink::WebLocalFrame
* source_frame
,
499 blink::WebFrame
* target_frame
,
500 blink::WebSecurityOrigin target_origin
,
501 blink::WebDOMMessageEvent event
);
502 virtual blink::WebString
userAgentOverride(blink::WebLocalFrame
* frame
,
503 const blink::WebURL
& url
);
504 virtual blink::WebString
doNotTrackValue(blink::WebLocalFrame
* frame
);
505 virtual bool allowWebGL(blink::WebLocalFrame
* frame
, bool default_value
);
506 virtual void didLoseWebGLContext(blink::WebLocalFrame
* frame
,
507 int arb_robustness_status_code
);
508 virtual blink::WebScreenOrientationClient
* webScreenOrientationClient();
509 virtual bool isControlledByServiceWorker(blink::WebDataSource
& data_source
);
510 virtual int64_t serviceWorkerID(blink::WebDataSource
& data_source
);
511 virtual void postAccessibilityEvent(const blink::WebAXObject
& obj
,
512 blink::WebAXEvent event
);
513 virtual void handleAccessibilityFindInPageResult(
516 const blink::WebAXObject
& start_object
,
518 const blink::WebAXObject
& end_object
,
520 virtual void didChangeManifest(blink::WebLocalFrame
*);
521 virtual void didChangeDefaultPresentation(blink::WebLocalFrame
*);
522 virtual bool enterFullscreen();
523 virtual bool exitFullscreen();
524 virtual blink::WebPermissionClient
* permissionClient();
526 // WebMediaPlayerDelegate implementation:
527 void DidPlay(blink::WebMediaPlayer
* player
) override
;
528 void DidPause(blink::WebMediaPlayer
* player
) override
;
529 void PlayerGone(blink::WebMediaPlayer
* player
) override
;
531 // TODO(nasko): Make all tests in RenderViewImplTest friends and then move
532 // this back to private member.
533 void OnNavigate(const CommonNavigationParams
& common_params
,
534 const StartNavigationParams
& start_params
,
535 const RequestNavigationParams
& request_params
);
537 // Make this frame show an empty, unscriptable page.
538 // TODO(nasko): Remove this method once swapped out state is no longer used.
539 void NavigateToSwappedOutURL();
541 // Binds this render frame's service registry.
542 void BindServiceRegistry(
543 mojo::InterfaceRequest
<mojo::ServiceProvider
> services
,
544 mojo::ServiceProviderPtr exposed_services
);
546 ManifestManager
* manifest_manager();
548 // TODO(creis): Remove when the only caller, the HistoryController, is no
550 void SetPendingNavigationParams(
551 scoped_ptr
<NavigationParams
> navigation_params
);
554 RenderFrameImpl(RenderViewImpl
* render_view
, int32 routing_id
);
557 friend class RenderFrameObserver
;
558 friend class RendererAccessibilityTest
;
559 FRIEND_TEST_ALL_PREFIXES(ExternalPopupMenuDisplayNoneTest
, SelectItem
);
560 FRIEND_TEST_ALL_PREFIXES(ExternalPopupMenuRemoveTest
, RemoveOnChange
);
561 FRIEND_TEST_ALL_PREFIXES(ExternalPopupMenuTest
, NormalCase
);
562 FRIEND_TEST_ALL_PREFIXES(ExternalPopupMenuTest
, ShowPopupThenNavigate
);
563 FRIEND_TEST_ALL_PREFIXES(RendererAccessibilityTest
,
564 AccessibilityMessagesQueueWhileSwappedOut
);
565 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
,
566 OnExtendSelectionAndDelete
);
567 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
, ReloadWhileSwappedOut
);
568 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
, SendSwapOutACK
);
569 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
, OriginReplicationForSwapOut
);
570 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
,
571 SetEditableSelectionAndComposition
);
572 FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest
,
573 OnSetAccessibilityMode
);
575 typedef std::map
<GURL
, double> HostZoomLevels
;
577 // Functions to add and remove observers for this object.
578 void AddObserver(RenderFrameObserver
* observer
);
579 void RemoveObserver(RenderFrameObserver
* observer
);
581 // Builds and sends DidCommitProvisionalLoad to the host.
582 void SendDidCommitProvisionalLoad(blink::WebFrame
* frame
,
583 blink::WebHistoryCommitType commit_type
);
585 // IPC message handlers ------------------------------------------------------
587 // The documentation for these functions should be in
588 // content/common/*_messages.h for the message that the function is handling.
589 void OnBeforeUnload();
590 void OnSwapOut(int proxy_routing_id
,
592 const FrameReplicationState
& replicated_frame_state
);
594 void OnShowContextMenu(const gfx::Point
& location
);
595 void OnContextMenuClosed(const CustomContextMenuContext
& custom_context
);
596 void OnCustomContextMenuAction(const CustomContextMenuContext
& custom_context
,
603 void OnPasteAndMatchStyle();
606 void OnSelectRange(const gfx::Point
& base
, const gfx::Point
& extent
);
608 void OnMoveRangeSelectionExtent(const gfx::Point
& point
);
609 void OnReplace(const base::string16
& text
);
610 void OnReplaceMisspelling(const base::string16
& text
);
611 void OnCSSInsertRequest(const std::string
& css
);
612 void OnJavaScriptExecuteRequest(const base::string16
& javascript
,
615 void OnJavaScriptExecuteRequestForTests(const base::string16
& javascript
,
618 void OnVisualStateRequest(uint64 key
);
619 void OnSetEditableSelectionOffsets(int start
, int end
);
620 void OnSetCompositionFromExistingText(
622 const std::vector
<blink::WebCompositionUnderline
>& underlines
);
623 void OnExecuteNoValueEditCommand(const std::string
& name
);
624 void OnExtendSelectionAndDelete(int before
, int after
);
625 void OnReload(bool ignore_cache
);
626 void OnTextSurroundingSelectionRequest(size_t max_length
);
627 void OnAddStyleSheetByURL(const std::string
& url
);
628 void OnSetupTransitionView(const std::string
& markup
);
629 void OnBeginExitTransition(const std::string
& css_selector
,
630 bool exit_to_native_app
);
631 void OnRevertExitTransition();
632 void OnHideTransitionElements(const std::string
& css_selector
);
633 void OnShowTransitionElements(const std::string
& css_selector
);
634 void OnSetAccessibilityMode(AccessibilityMode new_mode
);
635 void OnDisownOpener();
636 void OnDidUpdateSandboxFlags(SandboxFlags flags
);
637 #if defined(OS_ANDROID)
638 void OnSelectPopupMenuItems(bool canceled
,
639 const std::vector
<int>& selected_indices
);
640 #elif defined(OS_MACOSX)
641 void OnSelectPopupMenuItem(int selected_index
);
642 void OnCopyToFindPboard();
645 void OnCommitNavigation(const ResourceResponseHead
& response
,
646 const GURL
& stream_url
,
647 const CommonNavigationParams
& common_params
,
648 const RequestNavigationParams
& request_params
);
650 // Virtual since overridden by WebTestProxy for layout tests.
651 virtual blink::WebNavigationPolicy
DecidePolicyForNavigation(
652 RenderFrame
* render_frame
,
653 const NavigationPolicyInfo
& info
);
654 void OpenURL(blink::WebFrame
* frame
,
656 const Referrer
& referrer
,
657 blink::WebNavigationPolicy policy
);
659 // Update current main frame's encoding and send it to browser window.
660 // Since we want to let users see the right encoding info from menu
661 // before finishing loading, we call the UpdateEncoding in
662 // a) function:DidCommitLoadForFrame. When this function is called,
663 // that means we have got first data. In here we try to get encoding
664 // of page if it has been specified in http header.
665 // b) function:DidReceiveTitle. When this function is called,
666 // that means we have got specified title. Because in most of webpages,
667 // title tags will follow meta tags. In here we try to get encoding of
668 // page if it has been specified in meta tag.
669 // c) function:DidFinishDocumentLoadForFrame. When this function is
670 // called, that means we have got whole html page. In here we should
671 // finally get right encoding of page.
672 void UpdateEncoding(blink::WebFrame
* frame
,
673 const std::string
& encoding_name
);
675 // Dispatches the current state of selection on the webpage to the browser if
677 // TODO(varunjain): delete this method once we figure out how to keep
678 // selection handles in sync with the webpage.
679 void SyncSelectionIfRequired();
681 bool RunJavaScriptMessage(JavaScriptMessageType type
,
682 const base::string16
& message
,
683 const base::string16
& default_value
,
684 const GURL
& frame_url
,
685 base::string16
* result
);
687 // Loads the appropriate error page for the specified failure into the frame.
688 void LoadNavigationErrorPage(const blink::WebURLRequest
& failed_request
,
689 const blink::WebURLError
& error
,
692 void HandleJavascriptExecutionResult(const base::string16
& javascript
,
695 v8::Handle
<v8::Value
> result
);
697 // Initializes |web_user_media_client_|. If this fails, because it wasn't
698 // possible to create a MediaStreamClient (e.g., WebRTC is disabled), then
699 // |web_user_media_client_| will remain NULL.
700 void InitializeUserMediaClient();
702 blink::WebMediaPlayer
* CreateWebMediaPlayerForMediaStream(
703 const blink::WebURL
& url
,
704 blink::WebMediaPlayerClient
* client
);
706 // Creates a factory object used for creating audio and video renderers.
707 // The method is virtual so that layouttests can override it.
708 virtual scoped_ptr
<MediaStreamRendererFactory
> CreateRendererFactory();
710 // Checks that the RenderView is ready to display the navigation to |url|. If
711 // the return value is false, the navigation should be abandoned.
712 bool PrepareRenderViewForNavigation(
714 bool is_history_navigation
,
715 const RequestNavigationParams
& request_params
,
717 blink::WebURLRequest::CachePolicy
* cache_policy
);
720 // Sends a FrameHostMsg_BeginNavigation to the browser based on the contents
721 // of the WebURLRequest.
722 void BeginNavigation(blink::WebURLRequest
* request
);
725 void LoadDataURL(const CommonNavigationParams
& params
,
726 blink::WebFrame
* frame
);
728 // Returns the URL being loaded by the |frame_|'s request.
729 GURL
GetLoadingUrl() const;
731 // If we initiated a navigation, this function will populate |document_state|
732 // with the navigation information saved in OnNavigate().
733 void PopulateDocumentStateFromPending(DocumentState
* document_state
);
735 // Returns a new NavigationState populated with the navigation information
736 // saved in OnNavigate().
737 NavigationState
* CreateNavigationStateFromPending();
739 #if defined(OS_ANDROID)
740 blink::WebMediaPlayer
* CreateAndroidWebMediaPlayer(
741 const blink::WebURL
& url
,
742 blink::WebMediaPlayerClient
* client
,
743 media::MediaPermission
* media_permission
,
744 blink::WebContentDecryptionModule
* initial_cdm
);
746 RendererMediaPlayerManager
* GetMediaPlayerManager();
749 #if defined(ENABLE_BROWSER_CDMS)
750 RendererCdmManager
* GetCdmManager();
753 // Stores the WebLocalFrame we are associated with. This is null from the
754 // constructor until SetWebFrame is called, and it is null after
755 // frameDetached is called until destruction (which is asynchronous in the
756 // case of the main frame, but not subframes).
757 blink::WebLocalFrame
* frame_
;
759 // Frame is a local root if it is rendered in a process different than parent
760 // or it is a main frame.
763 base::WeakPtr
<RenderViewImpl
> render_view_
;
765 bool is_swapped_out_
;
766 // RenderFrameProxy exists only when is_swapped_out_ is true.
767 // TODO(nasko): This can be removed once we don't have a swapped out state on
768 // RenderFrame. See https://crbug.com/357747.
769 RenderFrameProxy
* render_frame_proxy_
;
772 // If this frame was created to replace a proxy, this will store the routing
773 // id of the proxy to replace at commit-time, at which time it will be
775 // TODO(creis): Remove this after switching to PlzNavigate.
776 int proxy_routing_id_
;
778 // Used when the RenderFrame is a local root. For now, RenderWidgets are
779 // added only when a child frame is in a different process from its parent
780 // frame, but eventually this will also apply to top-level frames.
781 // TODO(kenrb): Correct the above statement when top-level frames have their
782 // own RenderWidgets.
783 scoped_refptr
<RenderWidget
> render_widget_
;
785 // Temporarily holds state pertaining to a navigation that has been initiated
786 // until the NavigationState corresponding to the new navigation is created in
787 // didCreateDataSource().
788 scoped_ptr
<NavigationParams
> pending_navigation_params_
;
790 #if defined(ENABLE_PLUGINS)
791 // Current text input composition text. Empty if no composition is in
793 base::string16 pepper_composition_text_
;
795 PluginPowerSaverHelper
* plugin_power_saver_helper_
;
798 RendererWebCookieJarImpl cookie_jar_
;
800 // All the registered observers.
801 ObserverList
<RenderFrameObserver
> observers_
;
803 scoped_refptr
<ChildFrameCompositingHelper
> compositing_helper_
;
805 // The node that the context menu was pressed over.
806 blink::WebNode context_menu_node_
;
808 // External context menu requests we're waiting for. "Internal"
809 // (WebKit-originated) context menu events will have an ID of 0 and will not
812 // We don't want to add internal ones since some of the "special" page
813 // handlers in the browser process just ignore the context menu requests so
814 // avoid showing context menus, and so this will cause right clicks to leak
815 // entries in this map. Most users of the custom context menu (e.g. Pepper
816 // plugins) are normally only on "regular" pages and the regular pages will
817 // always respond properly to the request, so we don't have to worry so
819 IDMap
<ContextMenuClient
, IDMapExternalPointer
> pending_context_menus_
;
821 // The text selection the last time DidChangeSelection got called. May contain
822 // additional characters before and after the selected text, for IMEs. The
823 // portion of this string that is the actual selected text starts at index
824 // |selection_range_.GetMin() - selection_text_offset_| and has length
825 // |selection_range_.length()|.
826 base::string16 selection_text_
;
827 // The offset corresponding to the start of |selection_text_| in the document.
828 size_t selection_text_offset_
;
829 // Range over the document corresponding to the actual selected text (which
830 // could correspond to a substring of |selection_text_|; see above).
831 gfx::Range selection_range_
;
832 // Used to inform didChangeSelection() when it is called in the context
833 // of handling a InputMsg_SelectRange IPC.
834 bool handling_select_range_
;
836 // The next group of objects all implement RenderFrameObserver, so are deleted
837 // along with the RenderFrame automatically. This is why we just store weak
840 // Dispatches permission requests for Web Notifications.
841 NotificationPermissionDispatcher
* notification_permission_dispatcher_
;
843 // Destroyed via the RenderFrameObserver::OnDestruct() mechanism.
844 UserMediaClientImpl
* web_user_media_client_
;
846 // EncryptedMediaClient attached to this frame; lazily initialized.
847 scoped_ptr
<media::WebEncryptedMediaClientImpl
> web_encrypted_media_client_
;
849 // The media permission dispatcher attached to this frame, lazily initialized.
850 MediaPermissionDispatcher
* media_permission_dispatcher_
;
852 // MidiClient attached to this frame; lazily initialized.
853 MidiDispatcher
* midi_dispatcher_
;
855 #if defined(OS_ANDROID)
856 // Manages all media players in this render frame for communicating with the
857 // real media player in the browser process. It's okay to use a raw pointer
858 // since it's a RenderFrameObserver.
859 RendererMediaPlayerManager
* media_player_manager_
;
862 #if defined(ENABLE_BROWSER_CDMS)
863 // Manage all CDMs in this render frame for communicating with the real CDM in
864 // the browser process. It's okay to use a raw pointer since it's a
865 // RenderFrameObserver.
866 RendererCdmManager
* cdm_manager_
;
869 #if defined(VIDEO_HOLE)
870 // Whether or not this RenderFrameImpl contains a media player. Used to
871 // register as an observer for video-hole-specific events.
872 bool contains_media_player_
;
875 // The devtools agent for this frame; only created for main frame and
877 DevToolsAgent
* devtools_agent_
;
879 // The geolocation dispatcher attached to this frame, lazily initialized.
880 GeolocationDispatcher
* geolocation_dispatcher_
;
882 // The push messaging dispatcher attached to this frame, lazily initialized.
883 PushMessagingDispatcher
* push_messaging_dispatcher_
;
885 // The presentation dispatcher implementation attached to this frame, lazily
887 PresentationDispatcher
* presentation_dispatcher_
;
889 ServiceRegistryImpl service_registry_
;
891 // The screen orientation dispatcher attached to the frame, lazily
893 ScreenOrientationDispatcher
* screen_orientation_dispatcher_
;
895 // The Manifest Manager handles the manifest requests from the browser
897 ManifestManager
* manifest_manager_
;
899 // The current accessibility mode.
900 AccessibilityMode accessibility_mode_
;
902 // Only valid if |accessibility_mode_| is anything other than
903 // AccessibilityModeOff.
904 RendererAccessibility
* renderer_accessibility_
;
906 scoped_ptr
<PermissionManager
> permission_client_
;
908 #if defined(OS_MACOSX) || defined(OS_ANDROID)
909 // The external popup for the currently showing select popup.
910 scoped_ptr
<ExternalPopupMenu
> external_popup_menu_
;
913 base::WeakPtrFactory
<RenderFrameImpl
> weak_factory_
;
915 DISALLOW_COPY_AND_ASSIGN(RenderFrameImpl
);
918 } // namespace content
920 #endif // CONTENT_RENDERER_RENDER_FRAME_IMPL_H_