Add ICU message format support
[chromium-blink-merge.git] / content / renderer / render_frame_impl.h
blob321248faff625a6d5b441a9085d3bb8ae8520e85
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 "third_party/WebKit/public/platform/modules/app_banner/WebAppBannerClient.h"
30 #include "third_party/WebKit/public/web/WebAXObject.h"
31 #include "third_party/WebKit/public/web/WebDataSource.h"
32 #include "third_party/WebKit/public/web/WebFrameClient.h"
33 #include "third_party/WebKit/public/web/WebHistoryCommitType.h"
34 #include "third_party/WebKit/public/web/WebScriptExecutionCallback.h"
35 #include "ui/gfx/range/range.h"
37 #if defined(ENABLE_PLUGINS)
38 #include "content/renderer/pepper/plugin_power_saver_helper.h"
39 #endif
41 #if defined(OS_ANDROID)
42 #include "content/renderer/media/android/renderer_media_player_manager.h"
43 #endif
45 #if defined(ENABLE_MOJO_MEDIA)
46 #include "media/mojo/interfaces/service_factory.mojom.h"
47 #endif
49 class GURL;
50 class TransportDIB;
51 struct FrameMsg_NewFrame_WidgetParams;
52 struct FrameMsg_PostMessage_Params;
53 struct FrameMsg_TextTrackSettings_Params;
55 namespace blink {
56 class WebGeolocationClient;
57 class WebMouseEvent;
58 class WebContentDecryptionModule;
59 class WebMediaPlayer;
60 class WebPresentationClient;
61 class WebPushClient;
62 class WebSecurityOrigin;
63 struct WebCompositionUnderline;
64 struct WebContextMenuData;
65 struct WebCursorInfo;
68 namespace gfx {
69 class Point;
70 class Range;
71 class Rect;
74 namespace media {
75 class CdmFactory;
76 class MediaPermission;
77 class WebEncryptedMediaClientImpl;
80 namespace mojo {
81 class ServiceProvider;
84 namespace content {
86 class ChildFrameCompositingHelper;
87 class CompositorDependencies;
88 class DevToolsAgent;
89 class DocumentState;
90 class ExternalPopupMenu;
91 class GeolocationDispatcher;
92 class ManifestManager;
93 class MediaStreamDispatcher;
94 class MediaStreamRendererFactory;
95 class MediaPermissionDispatcher;
96 class MidiDispatcher;
97 class NavigationState;
98 class NotificationPermissionDispatcher;
99 class PageState;
100 class PepperPluginInstanceImpl;
101 class PermissionDispatcher;
102 class PresentationDispatcher;
103 class PushMessagingDispatcher;
104 class RendererAccessibility;
105 class RendererCdmManager;
106 class RendererMediaPlayerManager;
107 class RendererPpapiHost;
108 class RenderFrameObserver;
109 class RenderViewImpl;
110 class RenderWidget;
111 class RenderWidgetFullscreenPepper;
112 class ScreenOrientationDispatcher;
113 class UserMediaClientImpl;
114 struct CommonNavigationParams;
115 struct CustomContextMenuContext;
116 struct FrameReplicationState;
117 struct NavigationParams;
118 struct RequestNavigationParams;
119 struct ResourceResponseHead;
120 struct StartNavigationParams;
121 struct StreamOverrideParameters;
122 class VRDispatcher;
124 class CONTENT_EXPORT RenderFrameImpl
125 : public RenderFrame,
126 NON_EXPORTED_BASE(public blink::WebFrameClient),
127 NON_EXPORTED_BASE(public media::WebMediaPlayerDelegate) {
128 public:
129 // Creates a new RenderFrame. |render_view| is the RenderView object that this
130 // frame belongs to.
131 // Callers *must* call |SetWebFrame| immediately after creation.
132 // Note: This is called only when RenderFrame is created by Blink through
133 // createChildFrame.
134 // TODO(creis): We should structure this so that |SetWebFrame| isn't needed.
135 static RenderFrameImpl* Create(RenderViewImpl* render_view, int32 routing_id);
137 // Creates a new RenderFrame with |routing_id| as a child of the RenderFrame
138 // identified by |parent_routing_id| or as the top-level frame if the latter
139 // is MSG_ROUTING_NONE. If |proxy_routing_id| is MSG_ROUTING_NONE, it creates
140 // the Blink WebLocalFrame and inserts it into the frame tree after the frame
141 // identified by |previous_sibling_routing_id|, or as the first child if
142 // |previous_sibling_routing_id| is MSG_ROUTING_NONE. Otherwise, the frame is
143 // semi-orphaned until it commits, at which point it replaces the proxy
144 // identified by |proxy_routing_id|. Note: This is called only when
145 // RenderFrame is being created in response to IPC message from the browser
146 // process. All other frame creation is driven through Blink and Create.
147 static void CreateFrame(int routing_id,
148 int parent_routing_id,
149 int previous_sibling_routing_id,
150 int proxy_routing_id,
151 const FrameReplicationState& replicated_state,
152 CompositorDependencies* compositor_deps,
153 const FrameMsg_NewFrame_WidgetParams& params);
155 // Returns the RenderFrameImpl for the given routing ID.
156 static RenderFrameImpl* FromRoutingID(int routing_id);
158 // Just like RenderFrame::FromWebFrame but returns the implementation.
159 static RenderFrameImpl* FromWebFrame(blink::WebFrame* web_frame);
161 // Used by content_layouttest_support to hook into the creation of
162 // RenderFrameImpls.
163 struct CreateParams {
164 CreateParams(RenderViewImpl* render_view, int32 routing_id)
165 : render_view(render_view), routing_id(routing_id) {}
166 ~CreateParams() {}
168 RenderViewImpl* render_view;
169 int32 routing_id;
172 using CreateRenderFrameImplFunction =
173 RenderFrameImpl* (*)(const CreateParams&);
174 static void InstallCreateHook(
175 CreateRenderFrameImplFunction create_render_frame_impl);
177 virtual ~RenderFrameImpl();
179 bool is_swapped_out() const {
180 return is_swapped_out_;
183 // TODO(nasko): This can be removed once we don't have a swapped out state on
184 // RenderFrames. See https://crbug.com/357747.
185 void set_render_frame_proxy(RenderFrameProxy* proxy) {
186 render_frame_proxy_ = proxy;
189 // Out-of-process child frames receive a signal from RenderWidgetCompositor
190 // when a compositor frame has committed.
191 void DidCommitCompositorFrame();
193 // TODO(jam): this is a temporary getter until all the code is transitioned
194 // to using RenderFrame instead of RenderView.
195 RenderViewImpl* render_view() { return render_view_.get(); }
197 RendererWebCookieJarImpl* cookie_jar() { return &cookie_jar_; }
199 // Returns the RenderWidget associated with this frame.
200 RenderWidget* GetRenderWidget();
202 DevToolsAgent* devtools_agent() { return devtools_agent_; }
204 // This is called right after creation with the WebLocalFrame for this
205 // RenderFrame. It must be called before Initialize.
206 void SetWebFrame(blink::WebLocalFrame* web_frame);
208 // This method must be called after the frame has been added to the frame
209 // tree. It creates all objects that depend on the frame being at its proper
210 // spot.
211 void Initialize();
213 // Notifications from RenderWidget.
214 void WasHidden();
215 void WasShown();
216 void WidgetWillClose();
218 // Start/Stop loading notifications.
219 // TODO(nasko): Those are page-level methods at this time and come from
220 // WebViewClient. We should move them to be WebFrameClient calls and put
221 // logic in the browser side to balance starts/stops.
222 // |to_different_document| will be true unless the load is a fragment
223 // navigation, or triggered by history.pushState/replaceState.
224 virtual void didStartLoading(bool to_different_document);
225 virtual void didStopLoading();
226 virtual void didChangeLoadProgress(double load_progress);
228 AccessibilityMode accessibility_mode() {
229 return accessibility_mode_;
232 RendererAccessibility* renderer_accessibility() {
233 return renderer_accessibility_;
236 void HandleWebAccessibilityEvent(const blink::WebAXObject& obj,
237 blink::WebAXEvent event);
239 // The focused node changed to |node|. If focus was lost from this frame,
240 // |node| will be null.
241 void FocusedNodeChanged(const blink::WebNode& node);
243 // TODO(dmazzoni): the only reason this is here is to plumb it through to
244 // RendererAccessibility. It should use the RenderFrameObserver method, once
245 // blink has a separate accessibility tree per frame.
246 void FocusedNodeChangedForAccessibility(const blink::WebNode& node);
248 #if defined(ENABLE_PLUGINS)
249 // Notification that a PPAPI plugin has been created.
250 void PepperPluginCreated(RendererPpapiHost* host);
252 // Notifies that |instance| has changed the cursor.
253 // This will update the cursor appearance if it is currently over the plugin
254 // instance.
255 void PepperDidChangeCursor(PepperPluginInstanceImpl* instance,
256 const blink::WebCursorInfo& cursor);
258 // Notifies that |instance| has received a mouse event.
259 void PepperDidReceiveMouseEvent(PepperPluginInstanceImpl* instance);
261 // Informs the render view that a PPAPI plugin has changed text input status.
262 void PepperTextInputTypeChanged(PepperPluginInstanceImpl* instance);
263 void PepperCaretPositionChanged(PepperPluginInstanceImpl* instance);
265 // Cancels current composition.
266 void PepperCancelComposition(PepperPluginInstanceImpl* instance);
268 // Informs the render view that a PPAPI plugin has changed selection.
269 void PepperSelectionChanged(PepperPluginInstanceImpl* instance);
271 // Creates a fullscreen container for a pepper plugin instance.
272 RenderWidgetFullscreenPepper* CreatePepperFullscreenContainer(
273 PepperPluginInstanceImpl* plugin);
275 bool IsPepperAcceptingCompositionEvents() const;
277 // Notification that the given plugin has crashed.
278 void PluginCrashed(const base::FilePath& plugin_path,
279 base::ProcessId plugin_pid);
281 // Simulates IME events for testing purpose.
282 void SimulateImeSetComposition(
283 const base::string16& text,
284 const std::vector<blink::WebCompositionUnderline>& underlines,
285 int selection_start,
286 int selection_end);
287 void SimulateImeConfirmComposition(const base::string16& text,
288 const gfx::Range& replacement_range);
290 // TODO(jam): remove these once the IPC handler moves from RenderView to
291 // RenderFrame.
292 void OnImeSetComposition(
293 const base::string16& text,
294 const std::vector<blink::WebCompositionUnderline>& underlines,
295 int selection_start,
296 int selection_end);
297 void OnImeConfirmComposition(const base::string16& text,
298 const gfx::Range& replacement_range,
299 bool keep_selection);
300 #endif // defined(ENABLE_PLUGINS)
302 // May return NULL in some cases, especially if userMediaClient() returns
303 // NULL.
304 MediaStreamDispatcher* GetMediaStreamDispatcher();
306 #if defined(OS_MACOSX) || defined(OS_ANDROID)
307 void DidHideExternalPopupMenu();
308 #endif
310 // IPC::Sender
311 bool Send(IPC::Message* msg) override;
313 // IPC::Listener
314 bool OnMessageReceived(const IPC::Message& msg) override;
316 // RenderFrame implementation:
317 RenderView* GetRenderView() override;
318 int GetRoutingID() override;
319 blink::WebLocalFrame* GetWebFrame() override;
320 blink::WebElement GetFocusedElement() const override;
321 WebPreferences& GetWebkitPreferences() override;
322 int ShowContextMenu(ContextMenuClient* client,
323 const ContextMenuParams& params) override;
324 void CancelContextMenu(int request_id) override;
325 blink::WebNode GetContextMenuNode() const override;
326 blink::WebPlugin* CreatePlugin(
327 blink::WebFrame* frame,
328 const WebPluginInfo& info,
329 const blink::WebPluginParams& params,
330 scoped_ptr<PluginInstanceThrottler> throttler) override;
331 void LoadURLExternally(blink::WebLocalFrame* frame,
332 const blink::WebURLRequest& request,
333 blink::WebNavigationPolicy policy) override;
334 void ExecuteJavaScript(const base::string16& javascript) override;
335 bool IsHidden() override;
336 ServiceRegistry* GetServiceRegistry() override;
337 #if defined(ENABLE_PLUGINS)
338 void RegisterPeripheralPlugin(
339 const GURL& content_origin,
340 const base::Closure& unthrottle_callback) override;
341 PluginPowerSaverHelper* plugin_power_saver_helper() {
342 return plugin_power_saver_helper_;
344 #endif
345 bool IsFTPDirectoryListing() override;
346 void AttachGuest(int element_instance_id) override;
347 void DetachGuest(int element_instance_id) override;
348 void SetSelectedText(const base::string16& selection_text,
349 size_t offset,
350 const gfx::Range& range) override;
351 void EnsureMojoBuiltinsAreAvailable(v8::Isolate* isolate,
352 v8::Local<v8::Context> context) override;
353 void AddMessageToConsole(ConsoleMessageLevel level,
354 const std::string& message) override;
356 // blink::WebFrameClient implementation:
357 blink::WebPluginPlaceholder* createPluginPlaceholder(
358 blink::WebLocalFrame*,
359 const blink::WebPluginParams&) override;
360 virtual blink::WebPlugin* createPlugin(blink::WebLocalFrame* frame,
361 const blink::WebPluginParams& params);
362 virtual blink::WebMediaPlayer* createMediaPlayer(
363 blink::WebLocalFrame* frame,
364 const blink::WebURL& url,
365 blink::WebMediaPlayerClient* client,
366 blink::WebMediaPlayerEncryptedMediaClient* encrypted_client,
367 blink::WebContentDecryptionModule* initial_cdm);
368 virtual blink::WebApplicationCacheHost* createApplicationCacheHost(
369 blink::WebLocalFrame* frame,
370 blink::WebApplicationCacheHostClient* client);
371 virtual blink::WebWorkerContentSettingsClientProxy*
372 createWorkerContentSettingsClientProxy(blink::WebLocalFrame* frame);
373 virtual blink::WebExternalPopupMenu* createExternalPopupMenu(
374 const blink::WebPopupMenuInfo& popup_menu_info,
375 blink::WebExternalPopupMenuClient* popup_menu_client);
376 virtual blink::WebCookieJar* cookieJar(blink::WebLocalFrame* frame);
377 virtual blink::WebServiceWorkerProvider* createServiceWorkerProvider(
378 blink::WebLocalFrame* frame);
379 virtual void didAccessInitialDocument(blink::WebLocalFrame* frame);
380 virtual blink::WebFrame* createChildFrame(
381 blink::WebLocalFrame* parent,
382 blink::WebTreeScopeType scope,
383 const blink::WebString& name,
384 blink::WebSandboxFlags sandboxFlags);
385 virtual void didDisownOpener(blink::WebLocalFrame* frame);
386 virtual void frameDetached(blink::WebFrame* frame, DetachType type);
387 virtual void frameFocused();
388 virtual void willClose(blink::WebFrame* frame);
389 virtual void didChangeName(blink::WebLocalFrame* frame,
390 const blink::WebString& name);
391 virtual void didChangeSandboxFlags(blink::WebFrame* child_frame,
392 blink::WebSandboxFlags flags);
393 virtual void didMatchCSS(
394 blink::WebLocalFrame* frame,
395 const blink::WebVector<blink::WebString>& newly_matching_selectors,
396 const blink::WebVector<blink::WebString>& stopped_matching_selectors);
397 virtual bool shouldReportDetailedMessageForSource(
398 const blink::WebString& source);
399 virtual void didAddMessageToConsole(const blink::WebConsoleMessage& message,
400 const blink::WebString& source_name,
401 unsigned source_line,
402 const blink::WebString& stack_trace);
403 virtual void loadURLExternally(blink::WebLocalFrame* frame,
404 const blink::WebURLRequest& request,
405 blink::WebNavigationPolicy policy,
406 const blink::WebString& suggested_name);
407 // The WebDataSource::ExtraData* is assumed to be a DocumentState* subclass.
408 virtual blink::WebNavigationPolicy decidePolicyForNavigation(
409 const NavigationPolicyInfo& info);
410 virtual blink::WebHistoryItem historyItemForNewChildFrame(
411 blink::WebFrame* frame);
412 virtual void willSendSubmitEvent(blink::WebLocalFrame* frame,
413 const blink::WebFormElement& form);
414 virtual void willSubmitForm(blink::WebLocalFrame* frame,
415 const blink::WebFormElement& form);
416 virtual void didCreateDataSource(blink::WebLocalFrame* frame,
417 blink::WebDataSource* datasource);
418 virtual void didStartProvisionalLoad(blink::WebLocalFrame* frame,
419 double triggering_event_time);
420 virtual void didReceiveServerRedirectForProvisionalLoad(
421 blink::WebLocalFrame* frame);
422 virtual void didFailProvisionalLoad(
423 blink::WebLocalFrame* frame,
424 const blink::WebURLError& error,
425 blink::WebHistoryCommitType commit_type);
426 virtual void didCommitProvisionalLoad(
427 blink::WebLocalFrame* frame,
428 const blink::WebHistoryItem& item,
429 blink::WebHistoryCommitType commit_type);
430 virtual void didCreateNewDocument(blink::WebLocalFrame* frame);
431 virtual void didClearWindowObject(blink::WebLocalFrame* frame);
432 virtual void didCreateDocumentElement(blink::WebLocalFrame* frame);
433 virtual void didReceiveTitle(blink::WebLocalFrame* frame,
434 const blink::WebString& title,
435 blink::WebTextDirection direction);
436 virtual void didChangeIcon(blink::WebLocalFrame* frame,
437 blink::WebIconURL::Type icon_type);
438 virtual void didFinishDocumentLoad(blink::WebLocalFrame* frame,
439 bool document_is_empty);
440 virtual void didHandleOnloadEvents(blink::WebLocalFrame* frame);
441 virtual void didFailLoad(blink::WebLocalFrame* frame,
442 const blink::WebURLError& error,
443 blink::WebHistoryCommitType commit_type);
444 virtual void didFinishLoad(blink::WebLocalFrame* frame);
445 virtual void didNavigateWithinPage(blink::WebLocalFrame* frame,
446 const blink::WebHistoryItem& item,
447 blink::WebHistoryCommitType commit_type);
448 virtual void didUpdateCurrentHistoryItem(blink::WebLocalFrame* frame);
449 virtual void didChangeThemeColor();
450 virtual void dispatchLoad();
451 virtual void requestNotificationPermission(
452 const blink::WebSecurityOrigin& origin,
453 blink::WebNotificationPermissionCallback* callback);
454 virtual void didChangeSelection(bool is_empty_selection);
455 virtual blink::WebColorChooser* createColorChooser(
456 blink::WebColorChooserClient* client,
457 const blink::WebColor& initial_color,
458 const blink::WebVector<blink::WebColorSuggestion>& suggestions);
459 virtual void runModalAlertDialog(const blink::WebString& message);
460 virtual bool runModalConfirmDialog(const blink::WebString& message);
461 virtual bool runModalPromptDialog(const blink::WebString& message,
462 const blink::WebString& default_value,
463 blink::WebString* actual_value);
464 virtual bool runModalBeforeUnloadDialog(bool is_reload,
465 const blink::WebString& message);
466 virtual void showContextMenu(const blink::WebContextMenuData& data);
467 virtual void clearContextMenu();
468 virtual void willSendRequest(blink::WebLocalFrame* frame,
469 unsigned identifier,
470 blink::WebURLRequest& request,
471 const blink::WebURLResponse& redirect_response);
472 virtual void didReceiveResponse(blink::WebLocalFrame* frame,
473 unsigned identifier,
474 const blink::WebURLResponse& response);
475 virtual void didLoadResourceFromMemoryCache(
476 blink::WebLocalFrame* frame,
477 const blink::WebURLRequest& request,
478 const blink::WebURLResponse& response);
479 virtual void didDisplayInsecureContent(blink::WebLocalFrame* frame);
480 virtual void didRunInsecureContent(blink::WebLocalFrame* frame,
481 const blink::WebSecurityOrigin& origin,
482 const blink::WebURL& target);
483 virtual void didAbortLoading(blink::WebLocalFrame* frame);
484 virtual void didCreateScriptContext(blink::WebLocalFrame* frame,
485 v8::Local<v8::Context> context,
486 int extension_group,
487 int world_id);
488 virtual void willReleaseScriptContext(blink::WebLocalFrame* frame,
489 v8::Local<v8::Context> context,
490 int world_id);
491 virtual void didFirstVisuallyNonEmptyLayout(blink::WebLocalFrame* frame);
492 virtual void didChangeScrollOffset(blink::WebLocalFrame* frame);
493 virtual void willInsertBody(blink::WebLocalFrame* frame);
494 virtual void reportFindInPageMatchCount(int request_id,
495 int count,
496 bool final_update);
497 virtual void reportFindInPageSelection(int request_id,
498 int active_match_ordinal,
499 const blink::WebRect& sel);
500 virtual void requestStorageQuota(blink::WebLocalFrame* frame,
501 blink::WebStorageQuotaType type,
502 unsigned long long requested_size,
503 blink::WebStorageQuotaCallbacks callbacks);
504 virtual void willOpenWebSocket(blink::WebSocketHandle* handle);
505 virtual blink::WebGeolocationClient* geolocationClient();
506 virtual blink::WebPushClient* pushClient();
507 virtual blink::WebPresentationClient* presentationClient();
508 virtual void willStartUsingPeerConnectionHandler(
509 blink::WebLocalFrame* frame,
510 blink::WebRTCPeerConnectionHandler* handler);
511 virtual blink::WebUserMediaClient* userMediaClient();
512 virtual blink::WebEncryptedMediaClient* encryptedMediaClient();
513 virtual blink::WebMIDIClient* webMIDIClient();
514 virtual bool willCheckAndDispatchMessageEvent(
515 blink::WebLocalFrame* source_frame,
516 blink::WebFrame* target_frame,
517 blink::WebSecurityOrigin target_origin,
518 blink::WebDOMMessageEvent event);
519 virtual blink::WebString userAgentOverride(blink::WebLocalFrame* frame,
520 const blink::WebURL& url);
521 virtual blink::WebString doNotTrackValue(blink::WebLocalFrame* frame);
522 virtual bool allowWebGL(blink::WebLocalFrame* frame, bool default_value);
523 virtual void didLoseWebGLContext(blink::WebLocalFrame* frame,
524 int arb_robustness_status_code);
525 virtual blink::WebScreenOrientationClient* webScreenOrientationClient();
526 virtual bool isControlledByServiceWorker(blink::WebDataSource& data_source);
527 virtual int64_t serviceWorkerID(blink::WebDataSource& data_source);
528 virtual void postAccessibilityEvent(const blink::WebAXObject& obj,
529 blink::WebAXEvent event);
530 virtual void handleAccessibilityFindInPageResult(
531 int identifier,
532 int match_index,
533 const blink::WebAXObject& start_object,
534 int start_offset,
535 const blink::WebAXObject& end_object,
536 int end_offset);
537 virtual void didChangeManifest(blink::WebLocalFrame*);
538 virtual bool enterFullscreen();
539 virtual bool exitFullscreen();
540 virtual blink::WebPermissionClient* permissionClient();
541 virtual blink::WebAppBannerClient* appBannerClient();
542 virtual void registerProtocolHandler(const blink::WebString& scheme,
543 const blink::WebURL& url,
544 const blink::WebString& title);
545 virtual void unregisterProtocolHandler(const blink::WebString& scheme,
546 const blink::WebURL& url);
547 virtual blink::WebBluetooth* bluetooth();
549 #if defined(ENABLE_WEBVR)
550 blink::WebVRClient* webVRClient() override;
551 #endif
553 // WebMediaPlayerDelegate implementation:
554 void DidPlay(blink::WebMediaPlayer* player) override;
555 void DidPause(blink::WebMediaPlayer* player) override;
556 void PlayerGone(blink::WebMediaPlayer* player) override;
558 // Make this frame show an empty, unscriptable page.
559 // TODO(nasko): Remove this method once swapped out state is no longer used.
560 void NavigateToSwappedOutURL();
562 // Binds this render frame's service registry.
563 void BindServiceRegistry(
564 mojo::InterfaceRequest<mojo::ServiceProvider> services,
565 mojo::ServiceProviderPtr exposed_services);
567 ManifestManager* manifest_manager();
569 // TODO(creis): Remove when the only caller, the HistoryController, is no
570 // more.
571 void SetPendingNavigationParams(
572 scoped_ptr<NavigationParams> navigation_params);
574 protected:
575 explicit RenderFrameImpl(const CreateParams& params);
577 private:
578 friend class RenderFrameImplTest;
579 friend class RenderFrameObserver;
580 friend class RendererAccessibilityTest;
581 friend class TestRenderFrame;
582 FRIEND_TEST_ALL_PREFIXES(ExternalPopupMenuDisplayNoneTest, SelectItem);
583 FRIEND_TEST_ALL_PREFIXES(ExternalPopupMenuRemoveTest, RemoveOnChange);
584 FRIEND_TEST_ALL_PREFIXES(ExternalPopupMenuTest, NormalCase);
585 FRIEND_TEST_ALL_PREFIXES(ExternalPopupMenuTest, ShowPopupThenNavigate);
586 FRIEND_TEST_ALL_PREFIXES(RendererAccessibilityTest,
587 AccessibilityMessagesQueueWhileSwappedOut);
589 // A wrapper class used as the callback for JavaScript executed
590 // in an isolated world.
591 class JavaScriptIsolatedWorldRequest
592 : public blink::WebScriptExecutionCallback {
593 public:
594 JavaScriptIsolatedWorldRequest(
595 int id,
596 bool notify_result,
597 int routing_id,
598 base::WeakPtr<RenderFrameImpl> render_frame_impl);
599 void completed(
600 const blink::WebVector<v8::Local<v8::Value>>& result) override;
602 private:
603 ~JavaScriptIsolatedWorldRequest();
605 int id_;
606 bool notify_result_;
607 int routing_id_;
608 base::WeakPtr<RenderFrameImpl> render_frame_impl_;
610 DISALLOW_COPY_AND_ASSIGN(JavaScriptIsolatedWorldRequest);
613 typedef std::map<GURL, double> HostZoomLevels;
615 // Functions to add and remove observers for this object.
616 void AddObserver(RenderFrameObserver* observer);
617 void RemoveObserver(RenderFrameObserver* observer);
619 // Builds and sends DidCommitProvisionalLoad to the host.
620 void SendDidCommitProvisionalLoad(blink::WebFrame* frame,
621 blink::WebHistoryCommitType commit_type,
622 const blink::WebHistoryItem& item);
624 // IPC message handlers ------------------------------------------------------
626 // The documentation for these functions should be in
627 // content/common/*_messages.h for the message that the function is handling.
628 void OnNavigate(const CommonNavigationParams& common_params,
629 const StartNavigationParams& start_params,
630 const RequestNavigationParams& request_params);
631 void OnBeforeUnload();
632 void OnSwapOut(int proxy_routing_id,
633 bool is_loading,
634 const FrameReplicationState& replicated_frame_state);
635 void OnStop();
636 void OnShowContextMenu(const gfx::Point& location);
637 void OnContextMenuClosed(const CustomContextMenuContext& custom_context);
638 void OnCustomContextMenuAction(const CustomContextMenuContext& custom_context,
639 unsigned action);
640 void OnUndo();
641 void OnRedo();
642 void OnCut();
643 void OnCopy();
644 void OnPaste();
645 void OnPasteAndMatchStyle();
646 void OnDelete();
647 void OnSelectAll();
648 void OnSelectRange(const gfx::Point& base, const gfx::Point& extent);
649 void OnAdjustSelectionByCharacterOffset(int start_adjust, int end_adjust);
650 void OnUnselect();
651 void OnMoveRangeSelectionExtent(const gfx::Point& point);
652 void OnReplace(const base::string16& text);
653 void OnReplaceMisspelling(const base::string16& text);
654 void OnCSSInsertRequest(const std::string& css);
655 void OnAddMessageToConsole(ConsoleMessageLevel level,
656 const std::string& message);
657 void OnJavaScriptExecuteRequest(const base::string16& javascript,
658 int id,
659 bool notify_result);
660 void OnJavaScriptExecuteRequestForTests(const base::string16& javascript,
661 int id,
662 bool notify_result,
663 bool has_user_gesture);
664 void OnJavaScriptExecuteRequestInIsolatedWorld(const base::string16& jscript,
665 int id,
666 bool notify_result,
667 int world_id);
668 void OnVisualStateRequest(uint64 key);
669 void OnSetEditableSelectionOffsets(int start, int end);
670 void OnSetCompositionFromExistingText(
671 int start, int end,
672 const std::vector<blink::WebCompositionUnderline>& underlines);
673 void OnExecuteNoValueEditCommand(const std::string& name);
674 void OnExtendSelectionAndDelete(int before, int after);
675 void OnReload(bool ignore_cache);
676 void OnTextSurroundingSelectionRequest(size_t max_length);
677 void OnSetAccessibilityMode(AccessibilityMode new_mode);
678 void OnSnapshotAccessibilityTree(int callback_id);
679 void OnDisownOpener();
680 void OnDidUpdateSandboxFlags(blink::WebSandboxFlags flags);
681 void OnTextTrackSettingsChanged(
682 const FrameMsg_TextTrackSettings_Params& params);
683 void OnPostMessageEvent(const FrameMsg_PostMessage_Params& params);
684 #if defined(OS_ANDROID)
685 void OnSelectPopupMenuItems(bool canceled,
686 const std::vector<int>& selected_indices);
687 #elif defined(OS_MACOSX)
688 void OnSelectPopupMenuItem(int selected_index);
689 void OnCopyToFindPboard();
690 #endif
692 void OnCommitNavigation(const ResourceResponseHead& response,
693 const GURL& stream_url,
694 const CommonNavigationParams& common_params,
695 const RequestNavigationParams& request_params);
696 void OnFailedNavigation(const CommonNavigationParams& common_params,
697 const RequestNavigationParams& request_params,
698 bool has_stale_copy_in_cache,
699 int error_code);
701 // Virtual since overridden by WebTestProxy for layout tests.
702 virtual blink::WebNavigationPolicy DecidePolicyForNavigation(
703 RenderFrame* render_frame,
704 const NavigationPolicyInfo& info);
705 void OpenURL(blink::WebFrame* frame,
706 const GURL& url,
707 const Referrer& referrer,
708 blink::WebNavigationPolicy policy);
710 // Performs a navigation in the frame. This provides a unified function for
711 // the current code path and the browser-side navigation path (in
712 // development). Currently used by OnNavigate, with all *NavigationParams
713 // provided by the browser. |stream_params| should be null.
714 // PlzNavigate: used by OnCommitNavigation, with |common_params| and
715 // |request_params| received by the browser. |stream_params| should be non
716 // null and created from the information provided by the browser.
717 // |start_params| is not used.
718 void NavigateInternal(const CommonNavigationParams& common_params,
719 const StartNavigationParams& start_params,
720 const RequestNavigationParams& request_params,
721 scoped_ptr<StreamOverrideParameters> stream_params);
723 // Update current main frame's encoding and send it to browser window.
724 // Since we want to let users see the right encoding info from menu
725 // before finishing loading, we call the UpdateEncoding in
726 // a) function:DidCommitLoadForFrame. When this function is called,
727 // that means we have got first data. In here we try to get encoding
728 // of page if it has been specified in http header.
729 // b) function:DidReceiveTitle. When this function is called,
730 // that means we have got specified title. Because in most of webpages,
731 // title tags will follow meta tags. In here we try to get encoding of
732 // page if it has been specified in meta tag.
733 // c) function:DidFinishDocumentLoadForFrame. When this function is
734 // called, that means we have got whole html page. In here we should
735 // finally get right encoding of page.
736 void UpdateEncoding(blink::WebFrame* frame,
737 const std::string& encoding_name);
739 // Dispatches the current state of selection on the webpage to the browser if
740 // it has changed.
741 // TODO(varunjain): delete this method once we figure out how to keep
742 // selection handles in sync with the webpage.
743 void SyncSelectionIfRequired();
745 bool RunJavaScriptMessage(JavaScriptMessageType type,
746 const base::string16& message,
747 const base::string16& default_value,
748 const GURL& frame_url,
749 base::string16* result);
751 // Loads the appropriate error page for the specified failure into the frame.
752 void LoadNavigationErrorPage(const blink::WebURLRequest& failed_request,
753 const blink::WebURLError& error,
754 bool replace);
756 void HandleJavascriptExecutionResult(const base::string16& javascript,
757 int id,
758 bool notify_result,
759 v8::Local<v8::Value> result);
761 // Initializes |web_user_media_client_|. If this fails, because it wasn't
762 // possible to create a MediaStreamClient (e.g., WebRTC is disabled), then
763 // |web_user_media_client_| will remain NULL.
764 void InitializeUserMediaClient();
766 blink::WebMediaPlayer* CreateWebMediaPlayerForMediaStream(
767 blink::WebMediaPlayerClient* client);
769 // Creates a factory object used for creating audio and video renderers.
770 scoped_ptr<MediaStreamRendererFactory> CreateRendererFactory();
772 // Does preparation for the navigation to |url|.
773 void PrepareRenderViewForNavigation(
774 const GURL& url,
775 const RequestNavigationParams& request_params,
776 bool* is_reload,
777 blink::WebURLRequest::CachePolicy* cache_policy);
779 // PlzNavigate
780 // Sends a FrameHostMsg_BeginNavigation to the browser based on the contents
781 // of the WebURLRequest.
782 void BeginNavigation(blink::WebURLRequest* request);
784 // Loads a data url.
785 void LoadDataURL(const CommonNavigationParams& params,
786 blink::WebFrame* frame);
788 // Sends a proper FrameHostMsg_DidFailProvisionalLoadWithError_Params IPC for
789 // the failed request |request|.
790 void SendFailedProvisionalLoad(const blink::WebURLRequest& request,
791 const blink::WebURLError& error,
792 blink::WebLocalFrame* frame);
794 bool ShouldDisplayErrorPageForFailedLoad(int error_code,
795 const GURL& unreachable_url);
797 // Returns the URL being loaded by the |frame_|'s request.
798 GURL GetLoadingUrl() const;
800 // If we initiated a navigation, this function will populate |document_state|
801 // with the navigation information saved in OnNavigate().
802 void PopulateDocumentStateFromPending(DocumentState* document_state);
804 // Returns a new NavigationState populated with the navigation information
805 // saved in OnNavigate().
806 NavigationState* CreateNavigationStateFromPending();
808 #if defined(OS_ANDROID)
809 blink::WebMediaPlayer* CreateAndroidWebMediaPlayer(
810 blink::WebMediaPlayerClient* client,
811 blink::WebMediaPlayerEncryptedMediaClient* encrypted_client,
812 media::MediaPermission* media_permission,
813 blink::WebContentDecryptionModule* initial_cdm);
815 RendererMediaPlayerManager* GetMediaPlayerManager();
816 #endif
818 bool AreSecureCodecsSupported();
820 media::MediaPermission* GetMediaPermission();
822 #if defined(ENABLE_MOJO_MEDIA)
823 media::interfaces::ServiceFactory* GetMediaServiceFactory();
825 // Called when a connection error happened on |media_service_factory_|.
826 void OnMediaServiceFactoryConnectionError();
827 #endif
829 media::CdmFactory* GetCdmFactory();
831 void RegisterMojoServices();
833 // Stores the WebLocalFrame we are associated with. This is null from the
834 // constructor until SetWebFrame is called, and it is null after
835 // frameDetached is called until destruction (which is asynchronous in the
836 // case of the main frame, but not subframes).
837 blink::WebLocalFrame* frame_;
839 // Boolean value indicating whether this RenderFrameImpl object is for a
840 // subframe or not. It remains accurate during destruction, even when |frame_|
841 // has been invalidated.
842 bool is_subframe_;
844 // Frame is a local root if it is rendered in a process different than parent
845 // or it is a main frame.
846 bool is_local_root_;
848 base::WeakPtr<RenderViewImpl> render_view_;
849 int routing_id_;
850 bool is_swapped_out_;
852 // RenderFrameProxy exists only when is_swapped_out_ is true.
853 // TODO(nasko): This can be removed once we don't have a swapped out state on
854 // RenderFrame. See https://crbug.com/357747.
855 RenderFrameProxy* render_frame_proxy_;
856 bool is_detaching_;
858 // If this frame was created to replace a proxy, this will store the routing
859 // id of the proxy to replace at commit-time, at which time it will be
860 // cleared.
861 // TODO(creis): Remove this after switching to PlzNavigate.
862 int proxy_routing_id_;
864 // Used when the RenderFrame is a local root. For now, RenderWidgets are
865 // added only when a child frame is in a different process from its parent
866 // frame, but eventually this will also apply to top-level frames.
867 // TODO(kenrb): Correct the above statement when top-level frames have their
868 // own RenderWidgets.
869 scoped_refptr<RenderWidget> render_widget_;
871 // Temporarily holds state pertaining to a navigation that has been initiated
872 // until the NavigationState corresponding to the new navigation is created in
873 // didCreateDataSource().
874 scoped_ptr<NavigationParams> pending_navigation_params_;
876 #if defined(ENABLE_PLUGINS)
877 // Current text input composition text. Empty if no composition is in
878 // progress.
879 base::string16 pepper_composition_text_;
881 PluginPowerSaverHelper* plugin_power_saver_helper_;
882 #endif
884 RendererWebCookieJarImpl cookie_jar_;
886 // All the registered observers.
887 base::ObserverList<RenderFrameObserver> observers_;
889 scoped_refptr<ChildFrameCompositingHelper> compositing_helper_;
891 // The node that the context menu was pressed over.
892 blink::WebNode context_menu_node_;
894 // External context menu requests we're waiting for. "Internal"
895 // (WebKit-originated) context menu events will have an ID of 0 and will not
896 // be in this map.
898 // We don't want to add internal ones since some of the "special" page
899 // handlers in the browser process just ignore the context menu requests so
900 // avoid showing context menus, and so this will cause right clicks to leak
901 // entries in this map. Most users of the custom context menu (e.g. Pepper
902 // plugins) are normally only on "regular" pages and the regular pages will
903 // always respond properly to the request, so we don't have to worry so
904 // much about leaks.
905 IDMap<ContextMenuClient, IDMapExternalPointer> pending_context_menus_;
907 // The text selection the last time DidChangeSelection got called. May contain
908 // additional characters before and after the selected text, for IMEs. The
909 // portion of this string that is the actual selected text starts at index
910 // |selection_range_.GetMin() - selection_text_offset_| and has length
911 // |selection_range_.length()|.
912 base::string16 selection_text_;
913 // The offset corresponding to the start of |selection_text_| in the document.
914 size_t selection_text_offset_;
915 // Range over the document corresponding to the actual selected text (which
916 // could correspond to a substring of |selection_text_|; see above).
917 gfx::Range selection_range_;
918 // Used to inform didChangeSelection() when it is called in the context
919 // of handling a InputMsg_SelectRange IPC.
920 bool handling_select_range_;
922 // The next group of objects all implement RenderFrameObserver, so are deleted
923 // along with the RenderFrame automatically. This is why we just store weak
924 // references.
926 // Dispatches permission requests for Web Notifications.
927 NotificationPermissionDispatcher* notification_permission_dispatcher_;
929 // Destroyed via the RenderFrameObserver::OnDestruct() mechanism.
930 UserMediaClientImpl* web_user_media_client_;
932 // EncryptedMediaClient attached to this frame; lazily initialized.
933 scoped_ptr<media::WebEncryptedMediaClientImpl> web_encrypted_media_client_;
935 // The media permission dispatcher attached to this frame, lazily initialized.
936 MediaPermissionDispatcher* media_permission_dispatcher_;
938 #if defined(ENABLE_MOJO_MEDIA)
939 // The media factory attached to this frame, lazily initialized.
940 media::interfaces::ServiceFactoryPtr media_service_factory_;
941 #endif
943 // MidiClient attached to this frame; lazily initialized.
944 MidiDispatcher* midi_dispatcher_;
946 #if defined(OS_ANDROID)
947 // Manages all media players in this render frame for communicating with the
948 // real media player in the browser process. It's okay to use a raw pointer
949 // since it's a RenderFrameObserver.
950 RendererMediaPlayerManager* media_player_manager_;
951 #endif
953 #if defined(ENABLE_BROWSER_CDMS)
954 // Manage all CDMs in this render frame for communicating with the real CDM in
955 // the browser process. It's okay to use a raw pointer since it's a
956 // RenderFrameObserver.
957 RendererCdmManager* cdm_manager_;
958 #endif
960 // The CDM factory attached to this frame, lazily initialized.
961 scoped_ptr<media::CdmFactory> cdm_factory_;
963 #if defined(VIDEO_HOLE)
964 // Whether or not this RenderFrameImpl contains a media player. Used to
965 // register as an observer for video-hole-specific events.
966 bool contains_media_player_;
967 #endif
969 // The devtools agent for this frame; only created for main frame and
970 // local roots.
971 DevToolsAgent* devtools_agent_;
973 // The geolocation dispatcher attached to this frame, lazily initialized.
974 GeolocationDispatcher* geolocation_dispatcher_;
976 // The push messaging dispatcher attached to this frame, lazily initialized.
977 PushMessagingDispatcher* push_messaging_dispatcher_;
979 // The presentation dispatcher implementation attached to this frame, lazily
980 // initialized.
981 PresentationDispatcher* presentation_dispatcher_;
983 ServiceRegistryImpl service_registry_;
985 // The screen orientation dispatcher attached to the frame, lazily
986 // initialized.
987 ScreenOrientationDispatcher* screen_orientation_dispatcher_;
989 // The Manifest Manager handles the manifest requests from the browser
990 // process.
991 ManifestManager* manifest_manager_;
993 // The current accessibility mode.
994 AccessibilityMode accessibility_mode_;
996 // Only valid if |accessibility_mode_| is anything other than
997 // AccessibilityModeOff.
998 RendererAccessibility* renderer_accessibility_;
1000 scoped_ptr<PermissionDispatcher> permission_client_;
1002 scoped_ptr<blink::WebAppBannerClient> app_banner_client_;
1004 scoped_ptr<blink::WebBluetooth> bluetooth_;
1006 #if defined(ENABLE_WEBVR)
1007 // The VR dispatcher attached to the frame, lazily initialized.
1008 scoped_ptr<VRDispatcher> vr_dispatcher_;
1009 #endif
1011 #if defined(OS_MACOSX) || defined(OS_ANDROID)
1012 // The external popup for the currently showing select popup.
1013 scoped_ptr<ExternalPopupMenu> external_popup_menu_;
1014 #endif
1016 base::WeakPtrFactory<RenderFrameImpl> weak_factory_;
1018 DISALLOW_COPY_AND_ASSIGN(RenderFrameImpl);
1021 } // namespace content
1023 #endif // CONTENT_RENDERER_RENDER_FRAME_IMPL_H_