Roll src/third_party/WebKit a452221:9ff6d11 (svn 202117:202119)
[chromium-blink-merge.git] / content / renderer / render_frame_impl.h
blobbaf0dbac86bc2abac093285b18a1846e8ac37d8b
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CONTENT_RENDERER_RENDER_FRAME_IMPL_H_
6 #define CONTENT_RENDERER_RENDER_FRAME_IMPL_H_
8 #include <vector>
10 #include "base/basictypes.h"
11 #include "base/files/file_path.h"
12 #include "base/gtest_prod_util.h"
13 #include "base/id_map.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/memory/weak_ptr.h"
16 #include "base/observer_list.h"
17 #include "base/process/process_handle.h"
18 #include "content/common/accessibility_mode_enums.h"
19 #include "content/common/frame_message_enums.h"
20 #include "content/common/mojo/service_registry_impl.h"
21 #include "content/public/common/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"
42 #endif
44 #if defined(OS_ANDROID)
45 #include "content/renderer/media/android/renderer_media_player_manager.h"
46 #endif
48 #if defined(ENABLE_MOJO_MEDIA)
49 #include "media/mojo/interfaces/service_factory.mojom.h"
50 #endif
52 class GURL;
53 class TransportDIB;
54 struct FrameMsg_NewFrame_WidgetParams;
55 struct FrameMsg_PostMessage_Params;
56 struct FrameMsg_TextTrackSettings_Params;
58 namespace blink {
59 class WebGeolocationClient;
60 class WebMouseEvent;
61 class WebContentDecryptionModule;
62 class WebMediaPlayer;
63 class WebPresentationClient;
64 class WebPushClient;
65 class WebSecurityOrigin;
66 struct WebCompositionUnderline;
67 struct WebContextMenuData;
68 struct WebCursorInfo;
71 namespace gfx {
72 class Point;
73 class Range;
74 class Rect;
77 namespace media {
78 class CdmFactory;
79 class MediaPermission;
80 class WebEncryptedMediaClientImpl;
83 namespace mojo {
84 class ServiceProvider;
87 namespace content {
89 class ChildFrameCompositingHelper;
90 class CompositorDependencies;
91 class DevToolsAgent;
92 class DocumentState;
93 class ExternalPopupMenu;
94 class GeolocationDispatcher;
95 class ManifestManager;
96 class MediaStreamDispatcher;
97 class MediaStreamRendererFactory;
98 class MediaPermissionDispatcher;
99 class MidiDispatcher;
100 class NavigationState;
101 class NotificationPermissionDispatcher;
102 class PageState;
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;
113 class RenderWidget;
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;
125 class VRDispatcher;
127 class CONTENT_EXPORT RenderFrameImpl
128 : public RenderFrame,
129 NON_EXPORTED_BASE(public blink::WebFrameClient),
130 NON_EXPORTED_BASE(public media::WebMediaPlayerDelegate) {
131 public:
132 // Creates a new RenderFrame as the main frame of |render_view|.
133 static RenderFrameImpl* CreateMainFrame(RenderViewImpl* render_view,
134 int32 routing_id);
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
164 // RenderFrameImpls.
165 struct CreateParams {
166 CreateParams(RenderViewImpl* render_view, int32 routing_id)
167 : render_view(render_view), routing_id(routing_id) {}
168 ~CreateParams() {}
170 RenderViewImpl* render_view;
171 int32 routing_id;
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
221 // spot.
222 void Initialize();
224 // Notifications from RenderWidget.
225 void WasHidden();
226 void WasShown();
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
265 // instance.
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,
296 int selection_start,
297 int selection_end);
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
302 // RenderFrame.
303 void OnImeSetComposition(
304 const base::string16& text,
305 const std::vector<blink::WebCompositionUnderline>& underlines,
306 int selection_start,
307 int selection_end);
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
314 // NULL.
315 MediaStreamDispatcher* GetMediaStreamDispatcher();
317 #if defined(OS_MACOSX) || defined(OS_ANDROID)
318 void DidHideExternalPopupMenu();
319 #endif
321 // IPC::Sender
322 bool Send(IPC::Message* msg) override;
324 // IPC::Listener
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_;
355 #endif
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,
360 size_t offset,
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,
477 unsigned identifier,
478 blink::WebURLRequest& request,
479 const blink::WebURLResponse& redirect_response);
480 virtual void didReceiveResponse(blink::WebLocalFrame* frame,
481 unsigned identifier,
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 didChangePerformanceTiming();
492 virtual void didAbortLoading(blink::WebLocalFrame* frame);
493 virtual void didCreateScriptContext(blink::WebLocalFrame* frame,
494 v8::Local<v8::Context> context,
495 int extension_group,
496 int world_id);
497 virtual void willReleaseScriptContext(blink::WebLocalFrame* frame,
498 v8::Local<v8::Context> context,
499 int world_id);
500 virtual void didChangeScrollOffset(blink::WebLocalFrame* frame);
501 virtual void willInsertBody(blink::WebLocalFrame* frame);
502 virtual void reportFindInPageMatchCount(int request_id,
503 int count,
504 bool final_update);
505 virtual void reportFindInPageSelection(int request_id,
506 int active_match_ordinal,
507 const blink::WebRect& sel);
508 virtual void requestStorageQuota(blink::WebLocalFrame* frame,
509 blink::WebStorageQuotaType type,
510 unsigned long long requested_size,
511 blink::WebStorageQuotaCallbacks callbacks);
512 virtual void willOpenWebSocket(blink::WebSocketHandle* handle);
513 virtual blink::WebGeolocationClient* geolocationClient();
514 virtual blink::WebPushClient* pushClient();
515 virtual blink::WebPresentationClient* presentationClient();
516 virtual void willStartUsingPeerConnectionHandler(
517 blink::WebLocalFrame* frame,
518 blink::WebRTCPeerConnectionHandler* handler);
519 virtual blink::WebUserMediaClient* userMediaClient();
520 virtual blink::WebEncryptedMediaClient* encryptedMediaClient();
521 virtual blink::WebMIDIClient* webMIDIClient();
522 virtual bool willCheckAndDispatchMessageEvent(
523 blink::WebLocalFrame* source_frame,
524 blink::WebFrame* target_frame,
525 blink::WebSecurityOrigin target_origin,
526 blink::WebDOMMessageEvent event);
527 virtual blink::WebString userAgentOverride(blink::WebLocalFrame* frame,
528 const blink::WebURL& url);
529 virtual blink::WebString doNotTrackValue(blink::WebLocalFrame* frame);
530 virtual bool allowWebGL(blink::WebLocalFrame* frame, bool default_value);
531 virtual void didLoseWebGLContext(blink::WebLocalFrame* frame,
532 int arb_robustness_status_code);
533 virtual blink::WebScreenOrientationClient* webScreenOrientationClient();
534 virtual bool isControlledByServiceWorker(blink::WebDataSource& data_source);
535 virtual int64_t serviceWorkerID(blink::WebDataSource& data_source);
536 virtual void postAccessibilityEvent(const blink::WebAXObject& obj,
537 blink::WebAXEvent event);
538 virtual void handleAccessibilityFindInPageResult(
539 int identifier,
540 int match_index,
541 const blink::WebAXObject& start_object,
542 int start_offset,
543 const blink::WebAXObject& end_object,
544 int end_offset);
545 virtual void didChangeManifest(blink::WebLocalFrame*);
546 virtual bool enterFullscreen();
547 virtual bool exitFullscreen();
548 virtual blink::WebPermissionClient* permissionClient();
549 virtual blink::WebAppBannerClient* appBannerClient();
550 virtual void registerProtocolHandler(const blink::WebString& scheme,
551 const blink::WebURL& url,
552 const blink::WebString& title);
553 virtual void unregisterProtocolHandler(const blink::WebString& scheme,
554 const blink::WebURL& url);
555 virtual blink::WebBluetooth* bluetooth();
556 virtual blink::WebUSBClient* usbClient();
558 #if defined(ENABLE_WEBVR)
559 blink::WebVRClient* webVRClient() override;
560 #endif
562 // WebMediaPlayerDelegate implementation:
563 void DidPlay(blink::WebMediaPlayer* player) override;
564 void DidPause(blink::WebMediaPlayer* player) override;
565 void PlayerGone(blink::WebMediaPlayer* player) override;
567 // Make this frame show an empty, unscriptable page.
568 // TODO(nasko): Remove this method once swapped out state is no longer used.
569 void NavigateToSwappedOutURL();
571 // Binds this render frame's service registry.
572 void BindServiceRegistry(
573 mojo::InterfaceRequest<mojo::ServiceProvider> services,
574 mojo::ServiceProviderPtr exposed_services);
576 ManifestManager* manifest_manager();
578 // TODO(creis): Remove when the only caller, the HistoryController, is no
579 // more.
580 void SetPendingNavigationParams(
581 scoped_ptr<NavigationParams> navigation_params);
583 protected:
584 explicit RenderFrameImpl(const CreateParams& params);
586 private:
587 friend class RenderFrameImplTest;
588 friend class RenderFrameObserver;
589 friend class RendererAccessibilityTest;
590 friend class TestRenderFrame;
591 FRIEND_TEST_ALL_PREFIXES(ExternalPopupMenuDisplayNoneTest, SelectItem);
592 FRIEND_TEST_ALL_PREFIXES(ExternalPopupMenuRemoveTest, RemoveOnChange);
593 FRIEND_TEST_ALL_PREFIXES(ExternalPopupMenuTest, NormalCase);
594 FRIEND_TEST_ALL_PREFIXES(ExternalPopupMenuTest, ShowPopupThenNavigate);
595 FRIEND_TEST_ALL_PREFIXES(RendererAccessibilityTest,
596 AccessibilityMessagesQueueWhileSwappedOut);
598 // A wrapper class used as the callback for JavaScript executed
599 // in an isolated world.
600 class JavaScriptIsolatedWorldRequest
601 : public blink::WebScriptExecutionCallback {
602 public:
603 JavaScriptIsolatedWorldRequest(
604 int id,
605 bool notify_result,
606 int routing_id,
607 base::WeakPtr<RenderFrameImpl> render_frame_impl);
608 void completed(
609 const blink::WebVector<v8::Local<v8::Value>>& result) override;
611 private:
612 ~JavaScriptIsolatedWorldRequest();
614 int id_;
615 bool notify_result_;
616 int routing_id_;
617 base::WeakPtr<RenderFrameImpl> render_frame_impl_;
619 DISALLOW_COPY_AND_ASSIGN(JavaScriptIsolatedWorldRequest);
622 typedef std::map<GURL, double> HostZoomLevels;
624 // Creates a new RenderFrame. |render_view| is the RenderView object that this
625 // frame belongs to.
626 // Callers *must* call |SetWebFrame| immediately after creation.
627 static RenderFrameImpl* Create(RenderViewImpl* render_view, int32 routing_id);
629 // Functions to add and remove observers for this object.
630 void AddObserver(RenderFrameObserver* observer);
631 void RemoveObserver(RenderFrameObserver* observer);
633 // Builds and sends DidCommitProvisionalLoad to the host.
634 void SendDidCommitProvisionalLoad(blink::WebFrame* frame,
635 blink::WebHistoryCommitType commit_type,
636 const blink::WebHistoryItem& item);
638 // IPC message handlers ------------------------------------------------------
640 // The documentation for these functions should be in
641 // content/common/*_messages.h for the message that the function is handling.
642 void OnNavigate(const CommonNavigationParams& common_params,
643 const StartNavigationParams& start_params,
644 const RequestNavigationParams& request_params);
645 void OnBeforeUnload();
646 void OnSwapOut(int proxy_routing_id,
647 bool is_loading,
648 const FrameReplicationState& replicated_frame_state);
649 void OnStop();
650 void OnShowContextMenu(const gfx::Point& location);
651 void OnContextMenuClosed(const CustomContextMenuContext& custom_context);
652 void OnCustomContextMenuAction(const CustomContextMenuContext& custom_context,
653 unsigned action);
654 void OnUndo();
655 void OnRedo();
656 void OnCut();
657 void OnCopy();
658 void OnPaste();
659 void OnPasteAndMatchStyle();
660 void OnDelete();
661 void OnSelectAll();
662 void OnSelectRange(const gfx::Point& base, const gfx::Point& extent);
663 void OnAdjustSelectionByCharacterOffset(int start_adjust, int end_adjust);
664 void OnUnselect();
665 void OnMoveRangeSelectionExtent(const gfx::Point& point);
666 void OnReplace(const base::string16& text);
667 void OnReplaceMisspelling(const base::string16& text);
668 void OnCSSInsertRequest(const std::string& css);
669 void OnAddMessageToConsole(ConsoleMessageLevel level,
670 const std::string& message);
671 void OnJavaScriptExecuteRequest(const base::string16& javascript,
672 int id,
673 bool notify_result);
674 void OnJavaScriptExecuteRequestForTests(const base::string16& javascript,
675 int id,
676 bool notify_result,
677 bool has_user_gesture);
678 void OnJavaScriptExecuteRequestInIsolatedWorld(const base::string16& jscript,
679 int id,
680 bool notify_result,
681 int world_id);
682 void OnVisualStateRequest(uint64 key);
683 void OnSetEditableSelectionOffsets(int start, int end);
684 void OnSetCompositionFromExistingText(
685 int start, int end,
686 const std::vector<blink::WebCompositionUnderline>& underlines);
687 void OnExecuteNoValueEditCommand(const std::string& name);
688 void OnExtendSelectionAndDelete(int before, int after);
689 void OnReload(bool ignore_cache);
690 void OnTextSurroundingSelectionRequest(size_t max_length);
691 void OnSetAccessibilityMode(AccessibilityMode new_mode);
692 void OnSnapshotAccessibilityTree(int callback_id);
693 void OnUpdateOpener(int opener_routing_id);
694 void OnDidUpdateSandboxFlags(blink::WebSandboxFlags flags);
695 void OnTextTrackSettingsChanged(
696 const FrameMsg_TextTrackSettings_Params& params);
697 void OnPostMessageEvent(const FrameMsg_PostMessage_Params& params);
698 #if defined(OS_ANDROID)
699 void OnSelectPopupMenuItems(bool canceled,
700 const std::vector<int>& selected_indices);
701 #elif defined(OS_MACOSX)
702 void OnSelectPopupMenuItem(int selected_index);
703 void OnCopyToFindPboard();
704 #endif
706 void OnCommitNavigation(const ResourceResponseHead& response,
707 const GURL& stream_url,
708 const CommonNavigationParams& common_params,
709 const RequestNavigationParams& request_params);
710 void OnFailedNavigation(const CommonNavigationParams& common_params,
711 const RequestNavigationParams& request_params,
712 bool has_stale_copy_in_cache,
713 int error_code);
715 // Virtual since overridden by WebTestProxy for layout tests.
716 virtual blink::WebNavigationPolicy DecidePolicyForNavigation(
717 RenderFrame* render_frame,
718 const NavigationPolicyInfo& info);
719 void OpenURL(blink::WebFrame* frame,
720 const GURL& url,
721 const Referrer& referrer,
722 blink::WebNavigationPolicy policy);
724 // Performs a navigation in the frame. This provides a unified function for
725 // the current code path and the browser-side navigation path (in
726 // development). Currently used by OnNavigate, with all *NavigationParams
727 // provided by the browser. |stream_params| should be null.
728 // PlzNavigate: used by OnCommitNavigation, with |common_params| and
729 // |request_params| received by the browser. |stream_params| should be non
730 // null and created from the information provided by the browser.
731 // |start_params| is not used.
732 void NavigateInternal(const CommonNavigationParams& common_params,
733 const StartNavigationParams& start_params,
734 const RequestNavigationParams& request_params,
735 scoped_ptr<StreamOverrideParameters> stream_params);
737 // Update current main frame's encoding and send it to browser window.
738 // Since we want to let users see the right encoding info from menu
739 // before finishing loading, we call the UpdateEncoding in
740 // a) function:DidCommitLoadForFrame. When this function is called,
741 // that means we have got first data. In here we try to get encoding
742 // of page if it has been specified in http header.
743 // b) function:DidReceiveTitle. When this function is called,
744 // that means we have got specified title. Because in most of webpages,
745 // title tags will follow meta tags. In here we try to get encoding of
746 // page if it has been specified in meta tag.
747 // c) function:DidFinishDocumentLoadForFrame. When this function is
748 // called, that means we have got whole html page. In here we should
749 // finally get right encoding of page.
750 void UpdateEncoding(blink::WebFrame* frame,
751 const std::string& encoding_name);
753 // Dispatches the current state of selection on the webpage to the browser if
754 // it has changed.
755 // TODO(varunjain): delete this method once we figure out how to keep
756 // selection handles in sync with the webpage.
757 void SyncSelectionIfRequired();
759 bool RunJavaScriptMessage(JavaScriptMessageType type,
760 const base::string16& message,
761 const base::string16& default_value,
762 const GURL& frame_url,
763 base::string16* result);
765 // Loads the appropriate error page for the specified failure into the frame.
766 void LoadNavigationErrorPage(const blink::WebURLRequest& failed_request,
767 const blink::WebURLError& error,
768 bool replace);
770 void HandleJavascriptExecutionResult(const base::string16& javascript,
771 int id,
772 bool notify_result,
773 v8::Local<v8::Value> result);
775 // Initializes |web_user_media_client_|. If this fails, because it wasn't
776 // possible to create a MediaStreamClient (e.g., WebRTC is disabled), then
777 // |web_user_media_client_| will remain NULL.
778 void InitializeUserMediaClient();
780 blink::WebMediaPlayer* CreateWebMediaPlayerForMediaStream(
781 blink::WebMediaPlayerClient* client);
783 // Creates a factory object used for creating audio and video renderers.
784 scoped_ptr<MediaStreamRendererFactory> CreateRendererFactory();
786 // Does preparation for the navigation to |url|.
787 void PrepareRenderViewForNavigation(
788 const GURL& url,
789 const RequestNavigationParams& request_params,
790 bool* is_reload,
791 blink::WebURLRequest::CachePolicy* cache_policy);
793 // PlzNavigate
794 // Sends a FrameHostMsg_BeginNavigation to the browser based on the contents
795 // of the WebURLRequest.
796 void BeginNavigation(blink::WebURLRequest* request);
798 // Loads a data url.
799 void LoadDataURL(const CommonNavigationParams& params,
800 blink::WebFrame* frame);
802 // Sends a proper FrameHostMsg_DidFailProvisionalLoadWithError_Params IPC for
803 // the failed request |request|.
804 void SendFailedProvisionalLoad(const blink::WebURLRequest& request,
805 const blink::WebURLError& error,
806 blink::WebLocalFrame* frame);
808 bool ShouldDisplayErrorPageForFailedLoad(int error_code,
809 const GURL& unreachable_url);
811 // Returns the URL being loaded by the |frame_|'s request.
812 GURL GetLoadingUrl() const;
814 // If we initiated a navigation, this function will populate |document_state|
815 // with the navigation information saved in OnNavigate().
816 void PopulateDocumentStateFromPending(DocumentState* document_state);
818 // Returns a new NavigationState populated with the navigation information
819 // saved in OnNavigate().
820 NavigationState* CreateNavigationStateFromPending();
822 #if defined(OS_ANDROID)
823 blink::WebMediaPlayer* CreateAndroidWebMediaPlayer(
824 blink::WebMediaPlayerClient* client,
825 blink::WebMediaPlayerEncryptedMediaClient* encrypted_client,
826 const media::WebMediaPlayerParams& params);
828 RendererMediaPlayerManager* GetMediaPlayerManager();
829 #endif
831 bool AreSecureCodecsSupported();
833 media::MediaPermission* GetMediaPermission();
835 #if defined(ENABLE_MOJO_MEDIA)
836 media::interfaces::ServiceFactory* GetMediaServiceFactory();
838 // Called when a connection error happened on |media_service_factory_|.
839 void OnMediaServiceFactoryConnectionError();
840 #endif
842 media::CdmFactory* GetCdmFactory();
844 void RegisterMojoServices();
846 // Connects to a Mojo application and returns a proxy to its exposed
847 // ServiceProvider.
848 mojo::ServiceProviderPtr ConnectToApplication(const GURL& url);
850 // Stores the WebLocalFrame we are associated with. This is null from the
851 // constructor until SetWebFrame is called, and it is null after
852 // frameDetached is called until destruction (which is asynchronous in the
853 // case of the main frame, but not subframes).
854 blink::WebLocalFrame* frame_;
856 // Boolean value indicating whether this RenderFrameImpl object is for a
857 // subframe or not. It remains accurate during destruction, even when |frame_|
858 // has been invalidated.
859 bool is_subframe_;
861 // Frame is a local root if it is rendered in a process different than parent
862 // or it is a main frame.
863 bool is_local_root_;
865 base::WeakPtr<RenderViewImpl> render_view_;
866 int routing_id_;
867 bool is_swapped_out_;
869 // RenderFrameProxy exists only when is_swapped_out_ is true.
870 // TODO(nasko): This can be removed once we don't have a swapped out state on
871 // RenderFrame. See https://crbug.com/357747.
872 RenderFrameProxy* render_frame_proxy_;
873 bool is_detaching_;
875 // If this frame was created to replace a proxy, this will store the routing
876 // id of the proxy to replace at commit-time, at which time it will be
877 // cleared.
878 // TODO(creis): Remove this after switching to PlzNavigate.
879 int proxy_routing_id_;
881 // Used when the RenderFrame is a local root. For now, RenderWidgets are
882 // added only when a child frame is in a different process from its parent
883 // frame, but eventually this will also apply to top-level frames.
884 // TODO(kenrb): Correct the above statement when top-level frames have their
885 // own RenderWidgets.
886 scoped_refptr<RenderWidget> render_widget_;
888 // Temporarily holds state pertaining to a navigation that has been initiated
889 // until the NavigationState corresponding to the new navigation is created in
890 // didCreateDataSource().
891 scoped_ptr<NavigationParams> pending_navigation_params_;
893 #if defined(ENABLE_PLUGINS)
894 // Current text input composition text. Empty if no composition is in
895 // progress.
896 base::string16 pepper_composition_text_;
898 PluginPowerSaverHelper* plugin_power_saver_helper_;
899 #endif
901 RendererWebCookieJarImpl cookie_jar_;
903 // All the registered observers.
904 base::ObserverList<RenderFrameObserver> observers_;
906 scoped_refptr<ChildFrameCompositingHelper> compositing_helper_;
908 // The node that the context menu was pressed over.
909 blink::WebNode context_menu_node_;
911 // External context menu requests we're waiting for. "Internal"
912 // (WebKit-originated) context menu events will have an ID of 0 and will not
913 // be in this map.
915 // We don't want to add internal ones since some of the "special" page
916 // handlers in the browser process just ignore the context menu requests so
917 // avoid showing context menus, and so this will cause right clicks to leak
918 // entries in this map. Most users of the custom context menu (e.g. Pepper
919 // plugins) are normally only on "regular" pages and the regular pages will
920 // always respond properly to the request, so we don't have to worry so
921 // much about leaks.
922 IDMap<ContextMenuClient, IDMapExternalPointer> pending_context_menus_;
924 // The text selection the last time DidChangeSelection got called. May contain
925 // additional characters before and after the selected text, for IMEs. The
926 // portion of this string that is the actual selected text starts at index
927 // |selection_range_.GetMin() - selection_text_offset_| and has length
928 // |selection_range_.length()|.
929 base::string16 selection_text_;
930 // The offset corresponding to the start of |selection_text_| in the document.
931 size_t selection_text_offset_;
932 // Range over the document corresponding to the actual selected text (which
933 // could correspond to a substring of |selection_text_|; see above).
934 gfx::Range selection_range_;
935 // Used to inform didChangeSelection() when it is called in the context
936 // of handling a InputMsg_SelectRange IPC.
937 bool handling_select_range_;
939 // The next group of objects all implement RenderFrameObserver, so are deleted
940 // along with the RenderFrame automatically. This is why we just store weak
941 // references.
943 // Dispatches permission requests for Web Notifications.
944 NotificationPermissionDispatcher* notification_permission_dispatcher_;
946 // Destroyed via the RenderFrameObserver::OnDestruct() mechanism.
947 UserMediaClientImpl* web_user_media_client_;
949 // EncryptedMediaClient attached to this frame; lazily initialized.
950 scoped_ptr<media::WebEncryptedMediaClientImpl> web_encrypted_media_client_;
952 // The media permission dispatcher attached to this frame, lazily initialized.
953 MediaPermissionDispatcher* media_permission_dispatcher_;
955 #if defined(ENABLE_MOJO_MEDIA)
956 // The media factory attached to this frame, lazily initialized.
957 media::interfaces::ServiceFactoryPtr media_service_factory_;
958 #endif
960 // MidiClient attached to this frame; lazily initialized.
961 MidiDispatcher* midi_dispatcher_;
963 #if defined(OS_ANDROID)
964 // Manages all media players in this render frame for communicating with the
965 // real media player in the browser process. It's okay to use a raw pointer
966 // since it's a RenderFrameObserver.
967 RendererMediaPlayerManager* media_player_manager_;
968 #endif
970 #if defined(ENABLE_BROWSER_CDMS)
971 // Manage all CDMs in this render frame for communicating with the real CDM in
972 // the browser process. It's okay to use a raw pointer since it's a
973 // RenderFrameObserver.
974 RendererCdmManager* cdm_manager_;
975 #endif
977 // The CDM factory attached to this frame, lazily initialized.
978 scoped_ptr<media::CdmFactory> cdm_factory_;
980 #if defined(VIDEO_HOLE)
981 // Whether or not this RenderFrameImpl contains a media player. Used to
982 // register as an observer for video-hole-specific events.
983 bool contains_media_player_;
984 #endif
986 // True if this RenderFrame has ever played media.
987 bool has_played_media_;
989 // The devtools agent for this frame; only created for main frame and
990 // local roots.
991 DevToolsAgent* devtools_agent_;
993 // The geolocation dispatcher attached to this frame, lazily initialized.
994 GeolocationDispatcher* geolocation_dispatcher_;
996 // The push messaging dispatcher attached to this frame, lazily initialized.
997 PushMessagingDispatcher* push_messaging_dispatcher_;
999 // The presentation dispatcher implementation attached to this frame, lazily
1000 // initialized.
1001 PresentationDispatcher* presentation_dispatcher_;
1003 ServiceRegistryImpl service_registry_;
1005 // The shell proxy used to connect to Mojo applications.
1006 mojo::ShellPtr mojo_shell_;
1008 // The screen orientation dispatcher attached to the frame, lazily
1009 // initialized.
1010 ScreenOrientationDispatcher* screen_orientation_dispatcher_;
1012 // The Manifest Manager handles the manifest requests from the browser
1013 // process.
1014 ManifestManager* manifest_manager_;
1016 // The current accessibility mode.
1017 AccessibilityMode accessibility_mode_;
1019 // Only valid if |accessibility_mode_| is anything other than
1020 // AccessibilityModeOff.
1021 RendererAccessibility* renderer_accessibility_;
1023 scoped_ptr<PermissionDispatcher> permission_client_;
1025 scoped_ptr<blink::WebAppBannerClient> app_banner_client_;
1027 scoped_ptr<blink::WebBluetooth> bluetooth_;
1029 scoped_ptr<blink::WebUSBClient> usb_client_;
1031 #if defined(ENABLE_WEBVR)
1032 // The VR dispatcher attached to the frame, lazily initialized.
1033 scoped_ptr<VRDispatcher> vr_dispatcher_;
1034 #endif
1036 #if defined(OS_MACOSX) || defined(OS_ANDROID)
1037 // The external popup for the currently showing select popup.
1038 scoped_ptr<ExternalPopupMenu> external_popup_menu_;
1039 #endif
1041 base::WeakPtrFactory<RenderFrameImpl> weak_factory_;
1043 DISALLOW_COPY_AND_ASSIGN(RenderFrameImpl);
1046 } // namespace content
1048 #endif // CONTENT_RENDERER_RENDER_FRAME_IMPL_H_