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