Ignore non-active fullscreen windows for shelf state.
[chromium-blink-merge.git] / content / browser / renderer_host / render_view_host_impl.h
blob44851eea0e2983c78abd680af49322e2b72a555b
1 // Copyright (c) 2012 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_BROWSER_RENDERER_HOST_RENDER_VIEW_HOST_IMPL_H_
6 #define CONTENT_BROWSER_RENDERER_HOST_RENDER_VIEW_HOST_IMPL_H_
8 #include <map>
9 #include <string>
10 #include <vector>
12 #include "base/compiler_specific.h"
13 #include "base/logging.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/process/kill.h"
16 #include "content/browser/frame_host/render_frame_host_impl.h"
17 #include "content/browser/renderer_host/render_widget_host_impl.h"
18 #include "content/browser/site_instance_impl.h"
19 #include "content/common/accessibility_node_data.h"
20 #include "content/common/drag_event_source_info.h"
21 #include "content/public/browser/notification_observer.h"
22 #include "content/public/browser/render_view_host.h"
23 #include "content/public/common/javascript_message_type.h"
24 #include "content/public/common/page_transition_types.h"
25 #include "content/public/common/window_container_type.h"
26 #include "net/base/load_states.h"
27 #include "third_party/WebKit/public/web/WebAXEnums.h"
28 #include "third_party/WebKit/public/web/WebConsoleMessage.h"
29 #include "third_party/WebKit/public/web/WebPopupType.h"
30 #include "third_party/WebKit/public/web/WebTextDirection.h"
31 #include "third_party/skia/include/core/SkColor.h"
32 #include "ui/base/window_open_disposition.h"
34 class SkBitmap;
35 class ViewMsg_Navigate;
36 struct AccessibilityHostMsg_EventParams;
37 struct MediaPlayerAction;
38 struct ViewHostMsg_CreateWindow_Params;
39 struct ViewHostMsg_DidFailProvisionalLoadWithError_Params;
40 struct ViewHostMsg_OpenURL_Params;
41 struct ViewHostMsg_SelectionBounds_Params;
42 struct ViewHostMsg_ShowPopup_Params;
43 struct ViewMsg_Navigate_Params;
44 struct ViewMsg_PostMessage_Params;
45 struct ViewMsg_StopFinding_Params;
47 namespace base {
48 class ListValue;
51 namespace gfx {
52 class Range;
55 namespace ui {
56 struct SelectedFileInfo;
59 namespace content {
61 class BrowserMediaPlayerManager;
62 class ChildProcessSecurityPolicyImpl;
63 class PageState;
64 class RenderFrameHostDelegate;
65 class RenderFrameHostImpl;
66 class RenderWidgetHostDelegate;
67 class SessionStorageNamespace;
68 class SessionStorageNamespaceImpl;
69 class TestRenderViewHost;
70 struct ContextMenuParams;
71 struct FileChooserParams;
72 struct Referrer;
73 struct ShowDesktopNotificationHostMsgParams;
75 #if defined(COMPILER_MSVC)
76 // RenderViewHostImpl is the bottom of a diamond-shaped hierarchy,
77 // with RenderWidgetHost at the root. VS warns when methods from the
78 // root are overridden in only one of the base classes and not both
79 // (in this case, RenderWidgetHostImpl provides implementations of
80 // many of the methods). This is a silly warning when dealing with
81 // pure virtual methods that only have a single implementation in the
82 // hierarchy above this class, and is safe to ignore in this case.
83 #pragma warning(push)
84 #pragma warning(disable: 4250)
85 #endif
87 // This implements the RenderViewHost interface that is exposed to
88 // embedders of content, and adds things only visible to content.
90 // The exact API of this object needs to be more thoroughly designed. Right
91 // now it mimics what WebContentsImpl exposed, which is a fairly large API and
92 // may contain things that are not relevant to a common subset of views. See
93 // also the comment in render_view_host_delegate.h about the size and scope of
94 // the delegate API.
96 // Right now, the concept of page navigation (both top level and frame) exists
97 // in the WebContentsImpl still, so if you instantiate one of these elsewhere,
98 // you will not be able to traverse pages back and forward. We need to determine
99 // if we want to bring that and other functionality down into this object so it
100 // can be shared by others.
101 class CONTENT_EXPORT RenderViewHostImpl
102 : public RenderViewHost,
103 public RenderWidgetHostImpl {
104 public:
105 // Convenience function, just like RenderViewHost::FromID.
106 static RenderViewHostImpl* FromID(int render_process_id, int render_view_id);
108 // |routing_id| could be a valid route id, or it could be MSG_ROUTING_NONE, in
109 // which case RenderWidgetHost will create a new one. |swapped_out| indicates
110 // whether the view should initially be swapped out (e.g., for an opener
111 // frame being rendered by another process). |hidden| indicates whether the
112 // view is initially hidden or visible.
114 // The |session_storage_namespace| parameter allows multiple render views and
115 // WebContentses to share the same session storage (part of the WebStorage
116 // spec) space. This is useful when restoring contentses, but most callers
117 // should pass in NULL which will cause a new SessionStorageNamespace to be
118 // created.
119 RenderViewHostImpl(
120 SiteInstance* instance,
121 RenderViewHostDelegate* delegate,
122 RenderFrameHostDelegate* frame_delegate,
123 RenderWidgetHostDelegate* widget_delegate,
124 int routing_id,
125 int main_frame_routing_id,
126 bool swapped_out,
127 bool hidden);
128 virtual ~RenderViewHostImpl();
130 // RenderViewHost implementation.
131 virtual void AllowBindings(int binding_flags) OVERRIDE;
132 virtual void ClearFocusedNode() OVERRIDE;
133 virtual void ClosePage() OVERRIDE;
134 virtual void CopyImageAt(int x, int y) OVERRIDE;
135 virtual void DesktopNotificationPermissionRequestDone(
136 int callback_context) OVERRIDE;
137 virtual void DesktopNotificationPostDisplay(int callback_context) OVERRIDE;
138 virtual void DesktopNotificationPostError(
139 int notification_id,
140 const base::string16& message) OVERRIDE;
141 virtual void DesktopNotificationPostClose(int notification_id,
142 bool by_user) OVERRIDE;
143 virtual void DesktopNotificationPostClick(int notification_id) OVERRIDE;
144 virtual void DirectoryEnumerationFinished(
145 int request_id,
146 const std::vector<base::FilePath>& files) OVERRIDE;
147 virtual void DisableScrollbarsForThreshold(const gfx::Size& size) OVERRIDE;
148 virtual void DragSourceEndedAt(
149 int client_x, int client_y, int screen_x, int screen_y,
150 blink::WebDragOperation operation) OVERRIDE;
151 virtual void DragSourceMovedTo(
152 int client_x, int client_y, int screen_x, int screen_y) OVERRIDE;
153 virtual void DragSourceSystemDragEnded() OVERRIDE;
154 virtual void DragTargetDragEnter(
155 const DropData& drop_data,
156 const gfx::Point& client_pt,
157 const gfx::Point& screen_pt,
158 blink::WebDragOperationsMask operations_allowed,
159 int key_modifiers) OVERRIDE;
160 virtual void DragTargetDragOver(
161 const gfx::Point& client_pt,
162 const gfx::Point& screen_pt,
163 blink::WebDragOperationsMask operations_allowed,
164 int key_modifiers) OVERRIDE;
165 virtual void DragTargetDragLeave() OVERRIDE;
166 virtual void DragTargetDrop(const gfx::Point& client_pt,
167 const gfx::Point& screen_pt,
168 int key_modifiers) OVERRIDE;
169 virtual void EnableAutoResize(const gfx::Size& min_size,
170 const gfx::Size& max_size) OVERRIDE;
171 virtual void DisableAutoResize(const gfx::Size& new_size) OVERRIDE;
172 virtual void EnablePreferredSizeMode() OVERRIDE;
173 virtual void ExecuteCustomContextMenuCommand(
174 int action, const CustomContextMenuContext& context) OVERRIDE;
175 virtual void ExecuteMediaPlayerActionAtLocation(
176 const gfx::Point& location,
177 const blink::WebMediaPlayerAction& action) OVERRIDE;
178 virtual void ExecuteJavascriptInWebFrame(
179 const base::string16& frame_xpath,
180 const base::string16& jscript) OVERRIDE;
181 virtual void ExecuteJavascriptInWebFrameCallbackResult(
182 const base::string16& frame_xpath,
183 const base::string16& jscript,
184 const JavascriptResultCallback& callback) OVERRIDE;
185 virtual void ExecutePluginActionAtLocation(
186 const gfx::Point& location,
187 const blink::WebPluginAction& action) OVERRIDE;
188 virtual void ExitFullscreen() OVERRIDE;
189 virtual void Find(int request_id, const base::string16& search_text,
190 const blink::WebFindOptions& options) OVERRIDE;
191 virtual void StopFinding(StopFindAction action) OVERRIDE;
192 virtual void FirePageBeforeUnload(bool for_cross_site_transition) OVERRIDE;
193 virtual void FilesSelectedInChooser(
194 const std::vector<ui::SelectedFileInfo>& files,
195 FileChooserParams::Mode permissions) OVERRIDE;
196 virtual RenderViewHostDelegate* GetDelegate() const OVERRIDE;
197 virtual int GetEnabledBindings() const OVERRIDE;
198 virtual SiteInstance* GetSiteInstance() const OVERRIDE;
199 virtual void InsertCSS(const base::string16& frame_xpath,
200 const std::string& css) OVERRIDE;
201 virtual bool IsRenderViewLive() const OVERRIDE;
202 virtual bool IsSubframe() const OVERRIDE;
203 virtual void NotifyContextMenuClosed(
204 const CustomContextMenuContext& context) OVERRIDE;
205 virtual void NotifyMoveOrResizeStarted() OVERRIDE;
206 virtual void ReloadFrame() OVERRIDE;
207 virtual void SetAltErrorPageURL(const GURL& url) OVERRIDE;
208 virtual void SetWebUIProperty(const std::string& name,
209 const std::string& value) OVERRIDE;
210 virtual void SetZoomLevel(double level) OVERRIDE;
211 virtual void Zoom(PageZoom zoom) OVERRIDE;
212 virtual void SyncRendererPrefs() OVERRIDE;
213 virtual void ToggleSpeechInput() OVERRIDE;
214 virtual WebPreferences GetWebkitPreferences() OVERRIDE;
215 virtual void UpdateWebkitPreferences(
216 const WebPreferences& prefs) OVERRIDE;
217 virtual void NotifyTimezoneChange() OVERRIDE;
218 virtual void GetAudioOutputControllers(
219 const GetAudioOutputControllersCallback& callback) const OVERRIDE;
221 #if defined(OS_ANDROID)
222 virtual void ActivateNearestFindResult(int request_id,
223 float x,
224 float y) OVERRIDE;
225 virtual void RequestFindMatchRects(int current_version) OVERRIDE;
226 virtual void DisableFullscreenEncryptedMediaPlayback() OVERRIDE;
227 #endif
229 void set_delegate(RenderViewHostDelegate* d) {
230 CHECK(d); // http://crbug.com/82827
231 delegate_ = d;
234 // Set up the RenderView child process. Virtual because it is overridden by
235 // TestRenderViewHost. If the |frame_name| parameter is non-empty, it is used
236 // as the name of the new top-level frame.
237 // The |opener_route_id| parameter indicates which RenderView created this
238 // (MSG_ROUTING_NONE if none). If |max_page_id| is larger than -1, the
239 // RenderView is told to start issuing page IDs at |max_page_id| + 1.
240 virtual bool CreateRenderView(const base::string16& frame_name,
241 int opener_route_id,
242 int32 max_page_id);
244 base::TerminationStatus render_view_termination_status() const {
245 return render_view_termination_status_;
248 // Returns the content specific prefs for this RenderViewHost.
249 WebPreferences GetWebkitPrefs(const GURL& url);
251 // Sends the given navigation message. Use this rather than sending it
252 // yourself since this does the internal bookkeeping described below. This
253 // function takes ownership of the provided message pointer.
255 // If a cross-site request is in progress, we may be suspended while waiting
256 // for the onbeforeunload handler, so this function might buffer the message
257 // rather than sending it.
258 void Navigate(const ViewMsg_Navigate_Params& message);
260 // Load the specified URL, this is a shortcut for Navigate().
261 void NavigateToURL(const GURL& url);
263 // Returns whether navigation messages are currently suspended for this
264 // RenderViewHost. Only true during a cross-site navigation, while waiting
265 // for the onbeforeunload handler.
266 bool are_navigations_suspended() const { return navigations_suspended_; }
268 // Suspends (or unsuspends) any navigation messages from being sent from this
269 // RenderViewHost. This is called when a pending RenderViewHost is created
270 // for a cross-site navigation, because we must suspend any navigations until
271 // we hear back from the old renderer's onbeforeunload handler. Note that it
272 // is important that only one navigation event happen after calling this
273 // method with |suspend| equal to true. If |suspend| is false and there is
274 // a suspended_nav_message_, this will send the message. This function
275 // should only be called to toggle the state; callers should check
276 // are_navigations_suspended() first. If |suspend| is false, the time that the
277 // user decided the navigation should proceed should be passed as
278 // |proceed_time|.
279 void SetNavigationsSuspended(bool suspend,
280 const base::TimeTicks& proceed_time);
282 // Clears any suspended navigation state after a cross-site navigation is
283 // canceled or suspended. This is important if we later return to this
284 // RenderViewHost.
285 void CancelSuspendedNavigations();
287 // Whether the initial empty page of this view has been accessed by another
288 // page, making it unsafe to show the pending URL. Always false after the
289 // first commit.
290 bool has_accessed_initial_document() {
291 return has_accessed_initial_document_;
294 // Whether this RenderViewHost has been swapped out to be displayed by a
295 // different process.
296 bool is_swapped_out() const { return is_swapped_out_; }
298 // Called on the pending RenderViewHost when the network response is ready to
299 // commit. We should ensure that the old RenderViewHost runs its unload
300 // handler and determine whether a transfer to a different RenderViewHost is
301 // needed.
302 void OnCrossSiteResponse(
303 const GlobalRequestID& global_request_id,
304 bool is_transfer,
305 const std::vector<GURL>& transfer_url_chain,
306 const Referrer& referrer,
307 PageTransition page_transition,
308 int64 frame_id,
309 bool should_replace_current_entry);
311 // Tells the renderer that this RenderView will soon be swapped out, and thus
312 // not to create any new modal dialogs until it happens. This must be done
313 // separately so that the PageGroupLoadDeferrers of any current dialogs are no
314 // longer on the stack when we attempt to swap it out.
315 void SuppressDialogsUntilSwapOut();
317 // Tells the renderer that this RenderView is being swapped out for one in a
318 // different renderer process. It should run its unload handler and move to
319 // a blank document. The renderer should preserve the Frame object until it
320 // exits, in case we come back. The renderer can exit if it has no other
321 // active RenderViews, but not until WasSwappedOut is called (when it is no
322 // longer visible).
323 void SwapOut();
325 // Called when either the SwapOut request has been acknowledged or has timed
326 // out.
327 void OnSwappedOut(bool timed_out);
329 // Called to notify the renderer that it has been visibly swapped out and
330 // replaced by another RenderViewHost, after an earlier call to SwapOut.
331 // It is now safe for the process to exit if there are no other active
332 // RenderViews.
333 void WasSwappedOut();
335 // Close the page ignoring whether it has unload events registers.
336 // This is called after the beforeunload and unload events have fired
337 // and the user has agreed to continue with closing the page.
338 void ClosePageIgnoringUnloadEvents();
340 // Returns whether this RenderViewHost has an outstanding cross-site request.
341 // Cleared when we hear the response and start to swap out the old
342 // RenderViewHost, or if we hear a commit here without a network request.
343 bool HasPendingCrossSiteRequest();
345 // Sets whether this RenderViewHost has an outstanding cross-site request,
346 // for which another renderer will need to run an onunload event handler.
347 // This is called before the first navigation event for this RenderViewHost,
348 // and cleared when we hear the response or commit.
349 void SetHasPendingCrossSiteRequest(bool has_pending_request);
351 // Notifies the RenderView that the JavaScript message that was shown was
352 // closed by the user.
353 void JavaScriptDialogClosed(IPC::Message* reply_msg,
354 bool success,
355 const base::string16& user_input);
357 // Tells the renderer view to focus the first (last if reverse is true) node.
358 void SetInitialFocus(bool reverse);
360 // Get html data by serializing all frames of current page with lists
361 // which contain all resource links that have local copy.
362 // The parameter links contain original URLs of all saved links.
363 // The parameter local_paths contain corresponding local file paths of
364 // all saved links, which matched with vector:links one by one.
365 // The parameter local_directory_name is relative path of directory which
366 // contain all saved auxiliary files included all sub frames and resouces.
367 void GetSerializedHtmlDataForCurrentPageWithLocalLinks(
368 const std::vector<GURL>& links,
369 const std::vector<base::FilePath>& local_paths,
370 const base::FilePath& local_directory_name);
372 // Notifies the RenderViewHost that its load state changed.
373 void LoadStateChanged(const GURL& url,
374 const net::LoadStateWithParam& load_state,
375 uint64 upload_position,
376 uint64 upload_size);
378 bool SuddenTerminationAllowed() const;
379 void set_sudden_termination_allowed(bool enabled) {
380 sudden_termination_allowed_ = enabled;
383 // RenderWidgetHost public overrides.
384 virtual void Init() OVERRIDE;
385 virtual void Shutdown() OVERRIDE;
386 virtual bool IsRenderView() const OVERRIDE;
387 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE;
388 virtual void GotFocus() OVERRIDE;
389 virtual void LostCapture() OVERRIDE;
390 virtual void LostMouseLock() OVERRIDE;
391 virtual void ForwardMouseEvent(
392 const blink::WebMouseEvent& mouse_event) OVERRIDE;
393 virtual void OnPointerEventActivate() OVERRIDE;
394 virtual void ForwardKeyboardEvent(
395 const NativeWebKeyboardEvent& key_event) OVERRIDE;
396 virtual gfx::Rect GetRootWindowResizerRect() const OVERRIDE;
398 // Creates a new RenderView with the given route id.
399 void CreateNewWindow(
400 int route_id,
401 int main_frame_route_id,
402 const ViewHostMsg_CreateWindow_Params& params,
403 SessionStorageNamespace* session_storage_namespace);
405 // Creates a new RenderWidget with the given route id. |popup_type| indicates
406 // if this widget is a popup and what kind of popup it is (select, autofill).
407 void CreateNewWidget(int route_id, blink::WebPopupType popup_type);
409 // Creates a full screen RenderWidget.
410 void CreateNewFullscreenWidget(int route_id);
412 #if defined(OS_MACOSX)
413 // Select popup menu related methods (for external popup menus).
414 void DidSelectPopupMenuItem(int selected_index);
415 void DidCancelPopupMenu();
416 #endif
418 #if defined(OS_ANDROID)
419 BrowserMediaPlayerManager* media_player_manager() {
420 return media_player_manager_.get();
423 void DidSelectPopupMenuItems(const std::vector<int>& selected_indices);
424 void DidCancelPopupMenu();
425 #endif
427 // User rotated the screen. Calls the "onorientationchange" Javascript hook.
428 void SendOrientationChangeEvent(int orientation);
430 // Sets a bit indicating whether the RenderView is responsible for displaying
431 // a subframe in a different process from its parent page.
432 void set_is_subframe(bool is_subframe) {
433 is_subframe_ = is_subframe;
436 // TODO(creis): Remove this when we replace frame IDs with RenderFrameHost
437 // routing IDs.
438 int64 main_frame_id() const {
439 return main_frame_id_;
442 // Set the opener to null in the renderer process.
443 void DisownOpener();
445 // Turn on accessibility testing. The given callback will be run
446 // every time an accessibility notification is received from the
447 // renderer process, and the accessibility tree it sent can be
448 // retrieved using accessibility_tree_for_testing().
449 void SetAccessibilityCallbackForTesting(
450 const base::Callback<void(blink::WebAXEvent)>& callback);
452 // Only valid if SetAccessibilityCallbackForTesting was called and
453 // the callback was run at least once. Returns a snapshot of the
454 // accessibility tree received from the renderer as of the last time
455 // a LoadComplete or LayoutComplete accessibility notification was received.
456 const AccessibilityNodeDataTreeNode& accessibility_tree_for_testing() {
457 return accessibility_tree_;
460 // Set accessibility callbacks.
461 void SetAccessibilityLayoutCompleteCallbackForTesting(
462 const base::Closure& callback);
463 void SetAccessibilityLoadCompleteCallbackForTesting(
464 const base::Closure& callback);
465 void SetAccessibilityOtherCallbackForTesting(
466 const base::Closure& callback);
468 bool is_waiting_for_beforeunload_ack() {
469 return is_waiting_for_beforeunload_ack_;
472 bool is_waiting_for_unload_ack() {
473 return is_waiting_for_unload_ack_;
476 // Returns whether the given URL is allowed to commit in the current process.
477 // This is a more conservative check than FilterURL, since it will be used to
478 // kill processes that commit unauthorized URLs.
479 bool CanCommitURL(const GURL& url);
481 // Checks that the given renderer can request |url|, if not it sets it to
482 // about:blank.
483 // empty_allowed must be set to false for navigations for security reasons.
484 static void FilterURL(ChildProcessSecurityPolicyImpl* policy,
485 const RenderProcessHost* process,
486 bool empty_allowed,
487 GURL* url);
489 // Update the FrameTree to use this RenderViewHost's main frame
490 // RenderFrameHost. Called when the RenderViewHost is committed.
492 // TODO(ajwong): Remove once RenderViewHost no longer owns the main frame
493 // RenderFrameHost.
494 void AttachToFrameTree();
496 // The following IPC handlers are public so RenderFrameHost can call them,
497 // while we transition the code to not use RenderViewHost.
499 // TODO(nasko): Remove those methods once we are done moving navigation
500 // into RenderFrameHost.
501 void OnDidStartProvisionalLoadForFrame(int64 frame_id,
502 int64 parent_frame_id,
503 bool main_frame,
504 const GURL& url);
506 // NOTE: Do not add functions that just send an IPC message that are called in
507 // one or two places. Have the caller send the IPC message directly (unless
508 // the caller places are in different platforms, in which case it's better
509 // to keep them consistent).
511 protected:
512 // RenderWidgetHost protected overrides.
513 virtual void OnUserGesture() OVERRIDE;
514 virtual void NotifyRendererUnresponsive() OVERRIDE;
515 virtual void NotifyRendererResponsive() OVERRIDE;
516 virtual void OnRenderAutoResized(const gfx::Size& size) OVERRIDE;
517 virtual void RequestToLockMouse(bool user_gesture,
518 bool last_unlocked_by_target) OVERRIDE;
519 virtual bool IsFullscreen() const OVERRIDE;
520 virtual void OnFocus() OVERRIDE;
521 virtual void OnBlur() OVERRIDE;
523 // IPC message handlers.
524 void OnShowView(int route_id,
525 WindowOpenDisposition disposition,
526 const gfx::Rect& initial_pos,
527 bool user_gesture);
528 void OnShowWidget(int route_id, const gfx::Rect& initial_pos);
529 void OnShowFullscreenWidget(int route_id);
530 void OnRunModal(int opener_id, IPC::Message* reply_msg);
531 void OnRenderViewReady();
532 void OnRenderProcessGone(int status, int error_code);
533 void OnDidRedirectProvisionalLoad(int32 page_id,
534 const GURL& source_url,
535 const GURL& target_url);
536 void OnDidFailProvisionalLoadWithError(
537 const ViewHostMsg_DidFailProvisionalLoadWithError_Params& params);
538 void OnNavigate(const IPC::Message& msg);
539 void OnUpdateState(int32 page_id, const PageState& state);
540 void OnUpdateTitle(int32 page_id,
541 const base::string16& title,
542 blink::WebTextDirection title_direction);
543 void OnUpdateEncoding(const std::string& encoding);
544 void OnUpdateTargetURL(int32 page_id, const GURL& url);
545 void OnClose();
546 void OnRequestMove(const gfx::Rect& pos);
547 void OnDidStartLoading();
548 void OnDidStopLoading();
549 void OnDidChangeLoadProgress(double load_progress);
550 void OnDidDisownOpener();
551 void OnDocumentAvailableInMainFrame();
552 void OnDocumentOnLoadCompletedInMainFrame(int32 page_id);
553 void OnContextMenu(const ContextMenuParams& params);
554 void OnToggleFullscreen(bool enter_fullscreen);
555 void OnOpenURL(const ViewHostMsg_OpenURL_Params& params);
556 void OnDidContentsPreferredSizeChange(const gfx::Size& new_size);
557 void OnDidChangeScrollOffset();
558 void OnDidChangeScrollbarsForMainFrame(bool has_horizontal_scrollbar,
559 bool has_vertical_scrollbar);
560 void OnDidChangeScrollOffsetPinningForMainFrame(bool is_pinned_to_left,
561 bool is_pinned_to_right);
562 void OnDidChangeNumWheelEvents(int count);
563 void OnSelectionChanged(const base::string16& text,
564 size_t offset,
565 const gfx::Range& range);
566 void OnSelectionBoundsChanged(
567 const ViewHostMsg_SelectionBounds_Params& params);
568 void OnPasteFromSelectionClipboard();
569 void OnRouteCloseEvent();
570 void OnRouteMessageEvent(const ViewMsg_PostMessage_Params& params);
571 void OnRunJavaScriptMessage(const base::string16& message,
572 const base::string16& default_prompt,
573 const GURL& frame_url,
574 JavaScriptMessageType type,
575 IPC::Message* reply_msg);
576 void OnRunBeforeUnloadConfirm(const GURL& frame_url,
577 const base::string16& message,
578 bool is_reload,
579 IPC::Message* reply_msg);
580 void OnStartDragging(const DropData& drop_data,
581 blink::WebDragOperationsMask operations_allowed,
582 const SkBitmap& bitmap,
583 const gfx::Vector2d& bitmap_offset_in_dip,
584 const DragEventSourceInfo& event_info);
585 void OnUpdateDragCursor(blink::WebDragOperation drag_operation);
586 void OnTargetDropACK();
587 void OnTakeFocus(bool reverse);
588 void OnFocusedNodeChanged(bool is_editable_node);
589 void OnAddMessageToConsole(int32 level,
590 const base::string16& message,
591 int32 line_no,
592 const base::string16& source_id);
593 void OnUpdateInspectorSetting(const std::string& key,
594 const std::string& value);
595 void OnShouldCloseACK(
596 bool proceed,
597 const base::TimeTicks& renderer_before_unload_start_time,
598 const base::TimeTicks& renderer_before_unload_end_time);
599 void OnClosePageACK();
600 void OnSwapOutACK();
601 void OnAccessibilityEvents(
602 const std::vector<AccessibilityHostMsg_EventParams>& params);
603 void OnScriptEvalResponse(int id, const base::ListValue& result);
604 void OnDidZoomURL(double zoom_level, bool remember, const GURL& url);
605 void OnRequestDesktopNotificationPermission(const GURL& origin,
606 int callback_id);
607 void OnShowDesktopNotification(
608 const ShowDesktopNotificationHostMsgParams& params);
609 void OnCancelDesktopNotification(int notification_id);
610 void OnRunFileChooser(const FileChooserParams& params);
611 void OnDidAccessInitialDocument();
612 void OnDomOperationResponse(const std::string& json_string,
613 int automation_id);
614 void OnFocusedNodeTouched(bool editable);
616 #if defined(OS_MACOSX) || defined(OS_ANDROID)
617 void OnShowPopup(const ViewHostMsg_ShowPopup_Params& params);
618 #endif
620 // TODO(nasko): Remove this accessor once RenderFrameHost moves into the frame
621 // tree.
622 RenderFrameHostImpl* main_render_frame_host() const {
623 return main_render_frame_host_.get();
626 private:
627 friend class TestRenderViewHost;
628 FRIEND_TEST_ALL_PREFIXES(RenderViewHostTest, BasicRenderFrameHost);
629 FRIEND_TEST_ALL_PREFIXES(RenderViewHostTest, RoutingIdSane);
631 // Sets whether this RenderViewHost is swapped out in favor of another,
632 // and clears any waiting state that is no longer relevant.
633 void SetSwappedOut(bool is_swapped_out);
635 bool CanAccessFilesOfPageState(const PageState& state) const;
637 // All RenderViewHosts must have a RenderFrameHost for its main frame.
638 // Currently the RenderFrameHost is created in lock step on construction
639 // and a pointer to the main frame is given to the FrameTreeNode
640 // when the RenderViewHost commits (see AttachToFrameTree()).
642 // TODO(ajwong): Make this reference non-owning. The root FrameTreeNode of
643 // the FrameTree should be responsible for owning the main frame's
644 // RenderFrameHost.
645 scoped_ptr<RenderFrameHostImpl> main_render_frame_host_;
647 // Our delegate, which wants to know about changes in the RenderView.
648 RenderViewHostDelegate* delegate_;
650 // The SiteInstance associated with this RenderViewHost. All pages drawn
651 // in this RenderViewHost are part of this SiteInstance. Should not change
652 // over time.
653 scoped_refptr<SiteInstanceImpl> instance_;
655 // true if we are currently waiting for a response for drag context
656 // information.
657 bool waiting_for_drag_context_response_;
659 // A bitwise OR of bindings types that have been enabled for this RenderView.
660 // See BindingsPolicy for details.
661 int enabled_bindings_;
663 // Whether we should buffer outgoing Navigate messages rather than sending
664 // them. This will be true when a RenderViewHost is created for a cross-site
665 // request, until we hear back from the onbeforeunload handler of the old
666 // RenderViewHost.
667 bool navigations_suspended_;
669 // We only buffer the params for a suspended navigation while we have a
670 // pending RVH for a WebContentsImpl. There will only ever be one suspended
671 // navigation, because WebContentsImpl will destroy the pending RVH and create
672 // a new one if a second navigation occurs.
673 scoped_ptr<ViewMsg_Navigate_Params> suspended_nav_params_;
675 // Whether the initial empty page of this view has been accessed by another
676 // page, making it unsafe to show the pending URL. Usually false unless
677 // another window tries to modify the blank page. Always false after the
678 // first commit.
679 bool has_accessed_initial_document_;
681 // Whether this RenderViewHost is currently swapped out, such that the view is
682 // being rendered by another process.
683 bool is_swapped_out_;
685 // Whether this RenderView is responsible for displaying a subframe in a
686 // different process from its parent page.
687 bool is_subframe_;
689 // The frame id of the main (top level) frame. This value is set on the
690 // initial navigation of a RenderView and reset when the RenderView's
691 // process is terminated (in RenderProcessGone).
692 int64 main_frame_id_;
694 // If we were asked to RunModal, then this will hold the reply_msg that we
695 // must return to the renderer to unblock it.
696 IPC::Message* run_modal_reply_msg_;
697 // This will hold the routing id of the RenderView that opened us.
698 int run_modal_opener_id_;
700 // Set to true when there is a pending ViewMsg_ShouldClose message. This
701 // ensures we don't spam the renderer with multiple beforeunload requests.
702 // When either this value or is_waiting_for_unload_ack_ is true, the value of
703 // unload_ack_is_for_cross_site_transition_ indicates whether this is for a
704 // cross-site transition or a tab close attempt.
705 bool is_waiting_for_beforeunload_ack_;
707 // Set to true when there is a pending ViewMsg_Close message. Also see
708 // is_waiting_for_beforeunload_ack_, unload_ack_is_for_cross_site_transition_.
709 bool is_waiting_for_unload_ack_;
711 // Set to true when waiting for ViewHostMsg_SwapOut_ACK has timed out.
712 bool has_timed_out_on_unload_;
714 // Valid only when is_waiting_for_beforeunload_ack_ or
715 // is_waiting_for_unload_ack_ is true. This tells us if the unload request
716 // is for closing the entire tab ( = false), or only this RenderViewHost in
717 // the case of a cross-site transition ( = true).
718 bool unload_ack_is_for_cross_site_transition_;
720 bool are_javascript_messages_suppressed_;
722 // The mapping of pending javascript calls created by
723 // ExecuteJavascriptInWebFrameCallbackResult and their corresponding
724 // callbacks.
725 std::map<int, JavascriptResultCallback> javascript_callbacks_;
727 // Accessibility callback for testing.
728 base::Callback<void(blink::WebAXEvent)> accessibility_testing_callback_;
730 // The most recently received accessibility tree - for testing only.
731 AccessibilityNodeDataTreeNode accessibility_tree_;
733 // True if the render view can be shut down suddenly.
734 bool sudden_termination_allowed_;
736 // The termination status of the last render view that terminated.
737 base::TerminationStatus render_view_termination_status_;
739 // When the last ShouldClose message was sent.
740 base::TimeTicks send_should_close_start_time_;
742 #if defined(OS_ANDROID)
743 // Manages all the android mediaplayer objects and handling IPCs for video.
744 scoped_ptr<BrowserMediaPlayerManager> media_player_manager_;
745 #endif
747 DISALLOW_COPY_AND_ASSIGN(RenderViewHostImpl);
750 #if defined(COMPILER_MSVC)
751 #pragma warning(pop)
752 #endif
754 } // namespace content
756 #endif // CONTENT_BROWSER_RENDERER_HOST_RENDER_VIEW_HOST_IMPL_H_