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