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