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