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