web_contents_impl.h revision 90dce4d38c5ff5333bea97d859d4e484e27edf0c
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_WEB_CONTENTS_WEB_CONTENTS_IMPL_H_ 6#define CONTENT_BROWSER_WEB_CONTENTS_WEB_CONTENTS_IMPL_H_ 7 8#include <map> 9#include <set> 10#include <string> 11 12#include "base/compiler_specific.h" 13#include "base/gtest_prod_util.h" 14#include "base/memory/scoped_ptr.h" 15#include "base/observer_list.h" 16#include "base/process.h" 17#include "content/browser/renderer_host/frame_tree_node.h" 18#include "content/browser/renderer_host/render_view_host_delegate.h" 19#include "content/browser/renderer_host/render_widget_host_delegate.h" 20#include "content/browser/web_contents/navigation_controller_impl.h" 21#include "content/browser/web_contents/render_view_host_manager.h" 22#include "content/common/content_export.h" 23#include "content/public/browser/notification_observer.h" 24#include "content/public/browser/notification_registrar.h" 25#include "content/public/browser/web_contents.h" 26#include "content/public/common/renderer_preferences.h" 27#include "content/public/common/three_d_api_types.h" 28#include "net/base/load_states.h" 29#include "third_party/WebKit/Source/WebKit/chromium/public/WebDragOperation.h" 30#include "ui/gfx/rect_f.h" 31#include "ui/gfx/size.h" 32#include "ui/gfx/vector2d.h" 33#include "webkit/glue/resource_type.h" 34 35struct BrowserPluginHostMsg_ResizeGuest_Params; 36struct ViewHostMsg_DateTimeDialogValue_Params; 37struct ViewMsg_PostMessage_Params; 38 39namespace content { 40class BrowserPluginEmbedder; 41class BrowserPluginGuest; 42class BrowserPluginGuestManager; 43class ColorChooser; 44class DateTimeChooserAndroid; 45class DownloadItem; 46class InterstitialPageImpl; 47class JavaBridgeDispatcherHostManager; 48class JavaScriptDialogManager; 49class RenderViewHost; 50class RenderViewHostDelegateView; 51class RenderViewHostImpl; 52class RenderWidgetHostImpl; 53class RenderWidgetHostViewPort; 54class SavePackage; 55class SessionStorageNamespaceImpl; 56class SiteInstance; 57class TestWebContents; 58class WebContentsDelegate; 59class WebContentsImpl; 60class WebContentsObserver; 61class WebContentsViewPort; 62class WebContentsViewDelegate; 63struct FaviconURL; 64struct LoadNotificationDetails; 65 66// Factory function for the implementations that content knows about. Takes 67// ownership of |delegate|. 68WebContentsViewPort* CreateWebContentsView( 69 WebContentsImpl* web_contents, 70 WebContentsViewDelegate* delegate, 71 RenderViewHostDelegateView** render_view_host_delegate_view); 72 73class CONTENT_EXPORT WebContentsImpl 74 : public NON_EXPORTED_BASE(WebContents), 75 public RenderViewHostDelegate, 76 public RenderWidgetHostDelegate, 77 public RenderViewHostManager::Delegate, 78 public NotificationObserver { 79 public: 80 virtual ~WebContentsImpl(); 81 82 static WebContentsImpl* CreateWithOpener( 83 const WebContents::CreateParams& params, 84 WebContentsImpl* opener); 85 86 // Returns the opener WebContentsImpl, if any. This can be set to null if the 87 // opener is closed or the page clears its window.opener. 88 WebContentsImpl* opener() const { return opener_; } 89 90 // Creates a WebContents to be used as a browser plugin guest. 91 static BrowserPluginGuest* CreateGuest( 92 BrowserContext* browser_context, 93 content::SiteInstance* site_instance, 94 int guest_instance_id); 95 96 // Returns the content specific prefs for the given RVH. 97 static WebPreferences GetWebkitPrefs( 98 RenderViewHost* rvh, const GURL& url); 99 100 // Creates a swapped out RenderView. This is used by the browser plugin to 101 // create a swapped out RenderView in the embedder render process for the 102 // guest, to expose the guest's window object to the embedder. 103 // This returns the routing ID of the newly created swapped out RenderView. 104 int CreateSwappedOutRenderView(SiteInstance* instance); 105 106 // Complex initialization here. Specifically needed to avoid having 107 // members call back into our virtual functions in the constructor. 108 virtual void Init(const WebContents::CreateParams& params); 109 110 // Returns the SavePackage which manages the page saving job. May be NULL. 111 SavePackage* save_package() const { return save_package_.get(); } 112 113 // Updates the max page ID for the current SiteInstance in this 114 // WebContentsImpl to be at least |page_id|. 115 void UpdateMaxPageID(int32 page_id); 116 117 // Updates the max page ID for the given SiteInstance in this WebContentsImpl 118 // to be at least |page_id|. 119 void UpdateMaxPageIDForSiteInstance(SiteInstance* site_instance, 120 int32 page_id); 121 122 // Copy the current map of SiteInstance ID to max page ID from another tab. 123 // This is necessary when this tab adopts the NavigationEntries from 124 // |web_contents|. 125 void CopyMaxPageIDsFrom(WebContentsImpl* web_contents); 126 127 // Called by the NavigationController to cause the WebContentsImpl to navigate 128 // to the current pending entry. The NavigationController should be called 129 // back with RendererDidNavigate on success or DiscardPendingEntry on failure. 130 // The callbacks can be inside of this function, or at some future time. 131 // 132 // The entry has a PageID of -1 if newly created (corresponding to navigation 133 // to a new URL). 134 // 135 // If this method returns false, then the navigation is discarded (equivalent 136 // to calling DiscardPendingEntry on the NavigationController). 137 bool NavigateToPendingEntry(NavigationController::ReloadType reload_type); 138 139 // Called by InterstitialPageImpl when it creates a RenderViewHost. 140 void RenderViewForInterstitialPageCreated(RenderViewHost* render_view_host); 141 142 // Sets the passed interstitial as the currently showing interstitial. 143 // No interstitial page should already be attached. 144 void AttachInterstitialPage(InterstitialPageImpl* interstitial_page); 145 146 // Unsets the currently showing interstitial. 147 void DetachInterstitialPage(); 148 149#if defined(ENABLE_JAVA_BRIDGE) 150 JavaBridgeDispatcherHostManager* java_bridge_dispatcher_host_manager() const { 151 return java_bridge_dispatcher_host_manager_.get(); 152 } 153#endif 154 155 // Expose the render manager for testing. 156 RenderViewHostManager* GetRenderManagerForTesting(); 157 158 // Returns guest browser plugin object, or NULL if this WebContents is not a 159 // guest. 160 BrowserPluginGuest* GetBrowserPluginGuest() const; 161 // Returns embedder browser plugin object, or NULL if this WebContents is not 162 // an embedder. 163 BrowserPluginEmbedder* GetBrowserPluginEmbedder() const; 164 // Returns the BrowserPluginGuestManager object, or NULL if this web contents 165 // does not have a BrowserPluginGuestManager. 166 BrowserPluginGuestManager* GetBrowserPluginGuestManager() const; 167 168 // Gets the current fullscreen render widget's routing ID. Returns 169 // MSG_ROUTING_NONE when there is no fullscreen render widget. 170 int GetFullscreenWidgetRoutingID() const; 171 172 // Invoked when visible SSL state (as defined by SSLStatus) changes. 173 void DidChangeVisibleSSLState(); 174 175 // Invoked before a form repost warning is shown. 176 void NotifyBeforeFormRepostWarningShow(); 177 178 179 // Informs the render view host and the BrowserPluginEmbedder, if present, of 180 // a Drag Source End. 181 void DragSourceEndedAt(int client_x, int client_y, int screen_x, 182 int screen_y, WebKit::WebDragOperation operation); 183 184 // Informs the render view host and the BrowserPluginEmbedder, if present, of 185 // a Drag Source Move. 186 void DragSourceMovedTo(int client_x, int client_y, 187 int screen_x, int screen_y); 188 189 FrameTreeNode* GetFrameTreeRootForTesting() { 190 return frame_tree_root_.get(); 191 } 192 193 // WebContents ------------------------------------------------------ 194 virtual WebContentsDelegate* GetDelegate() OVERRIDE; 195 virtual void SetDelegate(WebContentsDelegate* delegate) OVERRIDE; 196 virtual NavigationControllerImpl& GetController() OVERRIDE; 197 virtual const NavigationControllerImpl& GetController() const OVERRIDE; 198 virtual BrowserContext* GetBrowserContext() const OVERRIDE; 199 virtual RenderProcessHost* GetRenderProcessHost() const OVERRIDE; 200 virtual RenderViewHost* GetRenderViewHost() const OVERRIDE; 201 virtual void GetRenderViewHostAtPosition( 202 int x, 203 int y, 204 const GetRenderViewHostCallback& callback) OVERRIDE; 205 virtual WebContents* GetEmbedderWebContents() const OVERRIDE; 206 virtual int GetEmbeddedInstanceID() const OVERRIDE; 207 virtual int GetRoutingID() const OVERRIDE; 208 virtual RenderWidgetHostView* GetRenderWidgetHostView() const OVERRIDE; 209 virtual WebContentsView* GetView() const OVERRIDE; 210 virtual WebUI* CreateWebUI(const GURL& url) OVERRIDE; 211 virtual WebUI* GetWebUI() const OVERRIDE; 212 virtual WebUI* GetCommittedWebUI() const OVERRIDE; 213 virtual void SetUserAgentOverride(const std::string& override) OVERRIDE; 214 virtual const std::string& GetUserAgentOverride() const OVERRIDE; 215#if defined(OS_WIN) && defined(USE_AURA) 216 virtual void SetParentNativeViewAccessible( 217 gfx::NativeViewAccessible accessible_parent) OVERRIDE; 218#endif 219 virtual const string16& GetTitle() const OVERRIDE; 220 virtual int32 GetMaxPageID() OVERRIDE; 221 virtual int32 GetMaxPageIDForSiteInstance( 222 SiteInstance* site_instance) OVERRIDE; 223 virtual SiteInstance* GetSiteInstance() const OVERRIDE; 224 virtual SiteInstance* GetPendingSiteInstance() const OVERRIDE; 225 virtual bool IsLoading() const OVERRIDE; 226 virtual bool IsWaitingForResponse() const OVERRIDE; 227 virtual const net::LoadStateWithParam& GetLoadState() const OVERRIDE; 228 virtual const string16& GetLoadStateHost() const OVERRIDE; 229 virtual uint64 GetUploadSize() const OVERRIDE; 230 virtual uint64 GetUploadPosition() const OVERRIDE; 231 virtual const std::string& GetEncoding() const OVERRIDE; 232 virtual bool DisplayedInsecureContent() const OVERRIDE; 233 virtual void IncrementCapturerCount() OVERRIDE; 234 virtual void DecrementCapturerCount() OVERRIDE; 235 virtual bool IsCrashed() const OVERRIDE; 236 virtual void SetIsCrashed(base::TerminationStatus status, 237 int error_code) OVERRIDE; 238 virtual base::TerminationStatus GetCrashedStatus() const OVERRIDE; 239 virtual bool IsBeingDestroyed() const OVERRIDE; 240 virtual void NotifyNavigationStateChanged(unsigned changed_flags) OVERRIDE; 241 virtual base::TimeTicks GetLastSelectedTime() const OVERRIDE; 242 virtual void WasShown() OVERRIDE; 243 virtual void WasHidden() OVERRIDE; 244 virtual bool NeedToFireBeforeUnload() OVERRIDE; 245 virtual void Stop() OVERRIDE; 246 virtual WebContents* Clone() OVERRIDE; 247 virtual void FocusThroughTabTraversal(bool reverse) OVERRIDE; 248 virtual bool ShowingInterstitialPage() const OVERRIDE; 249 virtual InterstitialPage* GetInterstitialPage() const OVERRIDE; 250 virtual bool IsSavable() OVERRIDE; 251 virtual void OnSavePage() OVERRIDE; 252 virtual bool SavePage(const base::FilePath& main_file, 253 const base::FilePath& dir_path, 254 SavePageType save_type) OVERRIDE; 255 virtual void GenerateMHTML( 256 const base::FilePath& file, 257 const base::Callback<void(const base::FilePath&, int64)>& callback) 258 OVERRIDE; 259 virtual bool IsActiveEntry(int32 page_id) OVERRIDE; 260 261 virtual const std::string& GetContentsMimeType() const OVERRIDE; 262 virtual bool WillNotifyDisconnection() const OVERRIDE; 263 virtual void SetOverrideEncoding(const std::string& encoding) OVERRIDE; 264 virtual void ResetOverrideEncoding() OVERRIDE; 265 virtual RendererPreferences* GetMutableRendererPrefs() OVERRIDE; 266 virtual void SetNewTabStartTime(const base::TimeTicks& time) OVERRIDE; 267 virtual base::TimeTicks GetNewTabStartTime() const OVERRIDE; 268 virtual void Close() OVERRIDE; 269 virtual void OnCloseStarted() OVERRIDE; 270 virtual void SystemDragEnded() OVERRIDE; 271 virtual void UserGestureDone() OVERRIDE; 272 virtual void SetClosedByUserGesture(bool value) OVERRIDE; 273 virtual bool GetClosedByUserGesture() const OVERRIDE; 274 virtual double GetZoomLevel() const OVERRIDE; 275 virtual int GetZoomPercent(bool* enable_increment, 276 bool* enable_decrement) const OVERRIDE; 277 virtual void ViewSource() OVERRIDE; 278 virtual void ViewFrameSource(const GURL& url, 279 const PageState& page_state) OVERRIDE; 280 virtual int GetMinimumZoomPercent() const OVERRIDE; 281 virtual int GetMaximumZoomPercent() const OVERRIDE; 282 virtual gfx::Size GetPreferredSize() const OVERRIDE; 283 virtual int GetContentRestrictions() const OVERRIDE; 284 virtual bool GotResponseToLockMouseRequest(bool allowed) OVERRIDE; 285 virtual bool HasOpener() const OVERRIDE; 286 virtual void DidChooseColorInColorChooser(SkColor color) OVERRIDE; 287 virtual void DidEndColorChooser() OVERRIDE; 288 virtual int DownloadImage(const GURL& url, 289 bool is_favicon, 290 int image_size, 291 const ImageDownloadCallback& callback) OVERRIDE; 292 293 // Implementation of PageNavigator. 294 virtual WebContents* OpenURL(const OpenURLParams& params) OVERRIDE; 295 296 // Implementation of IPC::Sender. 297 virtual bool Send(IPC::Message* message) OVERRIDE; 298 299 // RenderViewHostDelegate ---------------------------------------------------- 300 301 virtual RenderViewHostDelegateView* GetDelegateView() OVERRIDE; 302 virtual RenderViewHostDelegate::RendererManagement* 303 GetRendererManagementDelegate() OVERRIDE; 304 virtual bool OnMessageReceived(RenderViewHost* render_view_host, 305 const IPC::Message& message) OVERRIDE; 306 virtual const GURL& GetURL() const OVERRIDE; 307 virtual const GURL& GetActiveURL() const OVERRIDE; 308 virtual const GURL& GetLastCommittedURL() const OVERRIDE; 309 virtual WebContents* GetAsWebContents() OVERRIDE; 310 virtual gfx::Rect GetRootWindowResizerRect() const OVERRIDE; 311 virtual void RenderViewCreated(RenderViewHost* render_view_host) OVERRIDE; 312 virtual void RenderViewReady(RenderViewHost* render_view_host) OVERRIDE; 313 virtual void RenderViewTerminated(RenderViewHost* render_view_host, 314 base::TerminationStatus status, 315 int error_code) OVERRIDE; 316 virtual void RenderViewDeleted(RenderViewHost* render_view_host) OVERRIDE; 317 virtual void DidStartProvisionalLoadForFrame( 318 RenderViewHost* render_view_host, 319 int64 frame_id, 320 int64 parent_frame_id, 321 bool main_frame, 322 const GURL& url) OVERRIDE; 323 virtual void DidRedirectProvisionalLoad( 324 RenderViewHost* render_view_host, 325 int32 page_id, 326 const GURL& source_url, 327 const GURL& target_url) OVERRIDE; 328 virtual void DidFailProvisionalLoadWithError( 329 RenderViewHost* render_view_host, 330 const ViewHostMsg_DidFailProvisionalLoadWithError_Params& params) 331 OVERRIDE; 332 virtual void DidNavigate( 333 RenderViewHost* render_view_host, 334 const ViewHostMsg_FrameNavigate_Params& params) OVERRIDE; 335 virtual void UpdateState(RenderViewHost* render_view_host, 336 int32 page_id, 337 const PageState& page_state) OVERRIDE; 338 virtual void UpdateTitle(RenderViewHost* render_view_host, 339 int32 page_id, 340 const string16& title, 341 base::i18n::TextDirection title_direction) OVERRIDE; 342 virtual void UpdateEncoding(RenderViewHost* render_view_host, 343 const std::string& encoding) OVERRIDE; 344 virtual void UpdateTargetURL(int32 page_id, const GURL& url) OVERRIDE; 345 virtual void Close(RenderViewHost* render_view_host) OVERRIDE; 346 virtual void RequestMove(const gfx::Rect& new_bounds) OVERRIDE; 347 virtual void SwappedOut(RenderViewHost* render_view_host) OVERRIDE; 348 virtual void DidStartLoading(RenderViewHost* render_view_host) OVERRIDE; 349 virtual void DidStopLoading(RenderViewHost* render_view_host) OVERRIDE; 350 virtual void DidCancelLoading() OVERRIDE; 351 virtual void DidChangeLoadProgress(double progress) OVERRIDE; 352 virtual void DidDisownOpener(RenderViewHost* rvh) OVERRIDE; 353 virtual void DocumentAvailableInMainFrame( 354 RenderViewHost* render_view_host) OVERRIDE; 355 virtual void DocumentOnLoadCompletedInMainFrame( 356 RenderViewHost* render_view_host, 357 int32 page_id) OVERRIDE; 358 virtual void RequestOpenURL(RenderViewHost* rvh, 359 const GURL& url, 360 const Referrer& referrer, 361 WindowOpenDisposition disposition, 362 int64 source_frame_id, 363 bool is_cross_site_redirect) OVERRIDE; 364 virtual void RequestTransferURL( 365 const GURL& url, 366 const Referrer& referrer, 367 WindowOpenDisposition disposition, 368 int64 source_frame_id, 369 const GlobalRequestID& transferred_global_request_id, 370 bool is_cross_site_redirect) OVERRIDE; 371 virtual void RouteCloseEvent(RenderViewHost* rvh) OVERRIDE; 372 virtual void RouteMessageEvent( 373 RenderViewHost* rvh, 374 const ViewMsg_PostMessage_Params& params) OVERRIDE; 375 virtual void RunJavaScriptMessage(RenderViewHost* rvh, 376 const string16& message, 377 const string16& default_prompt, 378 const GURL& frame_url, 379 JavaScriptMessageType type, 380 IPC::Message* reply_msg, 381 bool* did_suppress_message) OVERRIDE; 382 virtual void RunBeforeUnloadConfirm(RenderViewHost* rvh, 383 const string16& message, 384 bool is_reload, 385 IPC::Message* reply_msg) OVERRIDE; 386 virtual bool AddMessageToConsole(int32 level, 387 const string16& message, 388 int32 line_no, 389 const string16& source_id) OVERRIDE; 390 virtual RendererPreferences GetRendererPrefs( 391 BrowserContext* browser_context) const OVERRIDE; 392 virtual WebPreferences GetWebkitPrefs() OVERRIDE; 393 virtual void OnUserGesture() OVERRIDE; 394 virtual void OnIgnoredUIEvent() OVERRIDE; 395 virtual void RendererUnresponsive(RenderViewHost* render_view_host, 396 bool is_during_unload) OVERRIDE; 397 virtual void RendererResponsive(RenderViewHost* render_view_host) OVERRIDE; 398 virtual void LoadStateChanged(const GURL& url, 399 const net::LoadStateWithParam& load_state, 400 uint64 upload_position, 401 uint64 upload_size) OVERRIDE; 402 virtual void WorkerCrashed() OVERRIDE; 403 virtual void Activate() OVERRIDE; 404 virtual void Deactivate() OVERRIDE; 405 virtual void LostCapture() OVERRIDE; 406 virtual void HandleMouseDown() OVERRIDE; 407 virtual void HandleMouseUp() OVERRIDE; 408 virtual void HandlePointerActivate() OVERRIDE; 409 virtual void HandleGestureBegin() OVERRIDE; 410 virtual void HandleGestureEnd() OVERRIDE; 411 virtual void RunFileChooser( 412 RenderViewHost* render_view_host, 413 const FileChooserParams& params) OVERRIDE; 414 virtual void ToggleFullscreenMode(bool enter_fullscreen) OVERRIDE; 415 virtual bool IsFullscreenForCurrentTab() const OVERRIDE; 416 virtual void UpdatePreferredSize(const gfx::Size& pref_size) OVERRIDE; 417 virtual void ResizeDueToAutoResize(const gfx::Size& new_size) OVERRIDE; 418 virtual void RequestToLockMouse(bool user_gesture, 419 bool last_unlocked_by_target) OVERRIDE; 420 virtual void LostMouseLock() OVERRIDE; 421 virtual void CreateNewWindow( 422 int route_id, 423 const ViewHostMsg_CreateWindow_Params& params, 424 SessionStorageNamespace* session_storage_namespace) OVERRIDE; 425 virtual void CreateNewWidget(int route_id, 426 WebKit::WebPopupType popup_type) OVERRIDE; 427 virtual void CreateNewFullscreenWidget(int route_id) OVERRIDE; 428 virtual void ShowCreatedWindow(int route_id, 429 WindowOpenDisposition disposition, 430 const gfx::Rect& initial_pos, 431 bool user_gesture) OVERRIDE; 432 virtual void ShowCreatedWidget(int route_id, 433 const gfx::Rect& initial_pos) OVERRIDE; 434 virtual void ShowCreatedFullscreenWidget(int route_id) OVERRIDE; 435 virtual void ShowContextMenu( 436 const ContextMenuParams& params, 437 ContextMenuSourceType type) OVERRIDE; 438 virtual void RequestMediaAccessPermission( 439 const MediaStreamRequest& request, 440 const MediaResponseCallback& callback) OVERRIDE; 441 442 // RenderWidgetHostDelegate -------------------------------------------------- 443 444 virtual void RenderWidgetDeleted( 445 RenderWidgetHostImpl* render_widget_host) OVERRIDE; 446 virtual bool PreHandleKeyboardEvent( 447 const NativeWebKeyboardEvent& event, 448 bool* is_keyboard_shortcut) OVERRIDE; 449 virtual void HandleKeyboardEvent( 450 const NativeWebKeyboardEvent& event) OVERRIDE; 451 virtual bool PreHandleWheelEvent( 452 const WebKit::WebMouseWheelEvent& event) OVERRIDE; 453 virtual void DidSendScreenRects(RenderWidgetHostImpl* rwh) OVERRIDE; 454#if defined(OS_WIN) && defined(USE_AURA) 455 virtual gfx::NativeViewAccessible GetParentNativeViewAccessible() OVERRIDE; 456#endif 457 458 // RenderViewHostManager::Delegate ------------------------------------------- 459 460 virtual bool CreateRenderViewForRenderManager( 461 RenderViewHost* render_view_host, int opener_route_id) OVERRIDE; 462 virtual void BeforeUnloadFiredFromRenderManager( 463 bool proceed, const base::TimeTicks& proceed_time, 464 bool* proceed_to_fire_unload) OVERRIDE; 465 virtual void RenderViewGoneFromRenderManager( 466 RenderViewHost* render_view_host) OVERRIDE; 467 virtual void UpdateRenderViewSizeForRenderManager() OVERRIDE; 468 virtual void NotifySwappedFromRenderManager( 469 RenderViewHost* old_render_view_host) OVERRIDE; 470 virtual int CreateOpenerRenderViewsForRenderManager( 471 SiteInstance* instance) OVERRIDE; 472 virtual NavigationControllerImpl& 473 GetControllerForRenderManager() OVERRIDE; 474 virtual WebUIImpl* CreateWebUIForRenderManager(const GURL& url) OVERRIDE; 475 virtual NavigationEntry* 476 GetLastCommittedNavigationEntryForRenderManager() OVERRIDE; 477 virtual bool FocusLocationBarByDefault() OVERRIDE; 478 virtual void SetFocusToLocationBar(bool select_all) OVERRIDE; 479 virtual void CreateViewAndSetSizeForRVH(RenderViewHost* rvh) OVERRIDE; 480 481 // NotificationObserver ------------------------------------------------------ 482 483 virtual void Observe(int type, 484 const NotificationSource& source, 485 const NotificationDetails& details) OVERRIDE; 486 487 488 private: 489 friend class NavigationControllerImpl; 490 friend class WebContentsObserver; 491 friend class WebContents; // To implement factory methods. 492 493 FRIEND_TEST_ALL_PREFIXES(WebContentsImplTest, NoJSMessageOnInterstitials); 494 FRIEND_TEST_ALL_PREFIXES(WebContentsImplTest, UpdateTitle); 495 FRIEND_TEST_ALL_PREFIXES(WebContentsImplTest, FindOpenerRVHWhenPending); 496 FRIEND_TEST_ALL_PREFIXES(WebContentsImplTest, 497 CrossSiteCantPreemptAfterUnload); 498 FRIEND_TEST_ALL_PREFIXES(WebContentsImplTest, PendingContents); 499 FRIEND_TEST_ALL_PREFIXES(WebContentsImplTest, FrameTreeShape); 500 FRIEND_TEST_ALL_PREFIXES(FormStructureBrowserTest, HTMLFiles); 501 FRIEND_TEST_ALL_PREFIXES(NavigationControllerTest, HistoryNavigate); 502 FRIEND_TEST_ALL_PREFIXES(RenderViewHostManagerTest, PageDoesBackAndReload); 503 504 // So InterstitialPageImpl can access SetIsLoading. 505 friend class InterstitialPageImpl; 506 507 // TODO(brettw) TestWebContents shouldn't exist! 508 friend class TestWebContents; 509 510 class DestructionObserver; 511 512 // See WebContents::Create for a description of these parameters. 513 WebContentsImpl(BrowserContext* browser_context, 514 WebContentsImpl* opener); 515 516 // Add and remove observers for page navigation notifications. Adding or 517 // removing multiple times has no effect. The order in which notifications 518 // are sent to observers is undefined. Clients must be sure to remove the 519 // observer before they go away. 520 void AddObserver(WebContentsObserver* observer); 521 void RemoveObserver(WebContentsObserver* observer); 522 523 // Clears this tab's opener if it has been closed. 524 void OnWebContentsDestroyed(WebContentsImpl* web_contents); 525 526 // Creates and adds to the map a destruction observer watching |web_contents|. 527 // No-op if such an observer already exists. 528 void AddDestructionObserver(WebContentsImpl* web_contents); 529 530 // Deletes and removes from the map a destruction observer 531 // watching |web_contents|. No-op if there is no such observer. 532 void RemoveDestructionObserver(WebContentsImpl* web_contents); 533 534 // Callback function when showing JS dialogs. 535 void OnDialogClosed(RenderViewHost* rvh, 536 IPC::Message* reply_msg, 537 bool success, 538 const string16& user_input); 539 540 // Callback function when requesting permission to access the PPAPI broker. 541 // |result| is true if permission was granted. 542 void OnPpapiBrokerPermissionResult(int request_id, bool result); 543 544 // IPC message handlers. 545 void OnDidLoadResourceFromMemoryCache(const GURL& url, 546 const std::string& security_info, 547 const std::string& http_request, 548 const std::string& mime_type, 549 ResourceType::Type resource_type); 550 void OnDidDisplayInsecureContent(); 551 void OnDidRunInsecureContent(const std::string& security_origin, 552 const GURL& target_url); 553 void OnDocumentLoadedInFrame(int64 frame_id); 554 void OnDidFinishLoad(int64 frame_id, 555 const GURL& url, 556 bool is_main_frame); 557 void OnDidFailLoadWithError(int64 frame_id, 558 const GURL& url, 559 bool is_main_frame, 560 int error_code, 561 const string16& error_description); 562 void OnUpdateContentRestrictions(int restrictions); 563 void OnGoToEntryAtOffset(int offset); 564 void OnUpdateZoomLimits(int minimum_percent, 565 int maximum_percent, 566 bool remember); 567 void OnSaveURL(const GURL& url, const Referrer& referrer); 568 void OnEnumerateDirectory(int request_id, const base::FilePath& path); 569 void OnJSOutOfMemory(); 570 571 void OnRegisterProtocolHandler(const std::string& protocol, 572 const GURL& url, 573 const string16& title, 574 bool user_gesture); 575 void OnFindReply(int request_id, 576 int number_of_matches, 577 const gfx::Rect& selection_rect, 578 int active_match_ordinal, 579 bool final_update); 580 void OnDidProgrammaticallyScroll(const gfx::Vector2d& scroll_point); 581#if defined(OS_ANDROID) 582 void OnFindMatchRectsReply(int version, 583 const std::vector<gfx::RectF>& rects, 584 const gfx::RectF& active_rect); 585 586 void OnOpenDateTimeDialog( 587 const ViewHostMsg_DateTimeDialogValue_Params& value); 588#endif 589 void OnCrashedPlugin(const base::FilePath& plugin_path, 590 base::ProcessId plugin_pid); 591 void OnAppCacheAccessed(const GURL& manifest_url, bool blocked_by_policy); 592 void OnOpenColorChooser(int color_chooser_id, SkColor color); 593 void OnEndColorChooser(int color_chooser_id); 594 void OnSetSelectedColorInColorChooser(int color_chooser_id, SkColor color); 595 void OnPepperPluginHung(int plugin_child_id, 596 const base::FilePath& path, 597 bool is_hung); 598 void OnWebUISend(const GURL& source_url, 599 const std::string& name, 600 const base::ListValue& args); 601 void OnRequestPpapiBrokerPermission(int request_id, 602 const GURL& url, 603 const base::FilePath& plugin_path); 604 void OnBrowserPluginMessage(const IPC::Message& message); 605 void OnDidDownloadImage(int id, 606 int http_status_code, 607 const GURL& image_url, 608 int requested_size, 609 const std::vector<SkBitmap>& bitmaps); 610 void OnUpdateFaviconURL(int32 page_id, 611 const std::vector<FaviconURL>& candidates); 612 void OnFrameAttached(int64 parent_frame_id, 613 int64 frame_id, 614 const std::string& frame_name); 615 void OnFrameDetached(int64 parent_frame_id, int64 frame_id); 616 617 // Changes the IsLoading state and notifies delegate as needed 618 // |details| is used to provide details on the load that just finished 619 // (but can be null if not applicable). Can be overridden. 620 void SetIsLoading(bool is_loading, 621 LoadNotificationDetails* details); 622 623 // Called by derived classes to indicate that we're no longer waiting for a 624 // response. This won't actually update the throbber, but it will get picked 625 // up at the next animation step if the throbber is going. 626 void SetNotWaitingForResponse() { waiting_for_response_ = false; } 627 628 // Navigation helpers -------------------------------------------------------- 629 // 630 // These functions are helpers for Navigate() and DidNavigate(). 631 632 // Handles post-navigation tasks in DidNavigate AFTER the entry has been 633 // committed to the navigation controller. Note that the navigation entry is 634 // not provided since it may be invalid/changed after being committed. The 635 // current navigation entry is in the NavigationController at this point. 636 void DidNavigateMainFramePostCommit( 637 const LoadCommittedDetails& details, 638 const ViewHostMsg_FrameNavigate_Params& params); 639 void DidNavigateAnyFramePostCommit( 640 RenderViewHost* render_view_host, 641 const LoadCommittedDetails& details, 642 const ViewHostMsg_FrameNavigate_Params& params); 643 644 // If our controller was restored, update the max page ID associated with the 645 // given RenderViewHost to be larger than the number of restored entries. 646 // This is called in CreateRenderView before any navigations in the RenderView 647 // have begun, to prevent any races in updating RenderView::next_page_id. 648 void UpdateMaxPageIDIfNecessary(RenderViewHost* rvh); 649 650 // Saves the given title to the navigation entry and does associated work. It 651 // will update history and the view for the new title, and also synthesize 652 // titles for file URLs that have none (so we require that the URL of the 653 // entry already be set). 654 // 655 // This is used as the backend for state updates, which include a new title, 656 // or the dedicated set title message. It returns true if the new title is 657 // different and was therefore updated. 658 bool UpdateTitleForEntry(NavigationEntryImpl* entry, 659 const string16& title); 660 661 // Causes the WebContentsImpl to navigate in the right renderer to |entry|, 662 // which must be already part of the entries in the navigation controller. 663 // This does not change the NavigationController state. 664 bool NavigateToEntry(const NavigationEntryImpl& entry, 665 NavigationController::ReloadType reload_type); 666 667 // Sets the history for this WebContentsImpl to |history_length| entries, and 668 // moves the current page_id to the last entry in the list if it's valid. 669 // This is mainly used when a prerendered page is swapped into the current 670 // tab. The method is virtual for testing. 671 virtual void SetHistoryLengthAndPrune( 672 const SiteInstance* site_instance, 673 int merge_history_length, 674 int32 minimum_page_id); 675 676 // Recursively creates swapped out RenderViews for this tab's opener chain 677 // (including this tab) in the given SiteInstance, allowing other tabs to send 678 // cross-process JavaScript calls to their opener(s). Returns the route ID of 679 // this tab's RenderView for |instance|. 680 int CreateOpenerRenderViews(SiteInstance* instance); 681 682 // Helper for CreateNewWidget/CreateNewFullscreenWidget. 683 void CreateNewWidget(int route_id, 684 bool is_fullscreen, 685 WebKit::WebPopupType popup_type); 686 687 // Helper for ShowCreatedWidget/ShowCreatedFullscreenWidget. 688 void ShowCreatedWidget(int route_id, 689 bool is_fullscreen, 690 const gfx::Rect& initial_pos); 691 692 // Finds the new RenderWidgetHost and returns it. Note that this can only be 693 // called once as this call also removes it from the internal map. 694 RenderWidgetHostView* GetCreatedWidget(int route_id); 695 696 // Finds the new WebContentsImpl by route_id, initializes it for 697 // renderer-initiated creation, and returns it. Note that this can only be 698 // called once as this call also removes it from the internal map. 699 WebContentsImpl* GetCreatedWindow(int route_id); 700 701 // Returns the RenderWidgetHostView that is associated with a native window 702 // and can be used in showing created widgets. 703 // If this WebContents belongs to a browser plugin guest, there is no native 704 // window 'view' associated with this WebContents. This method returns the 705 // 'view' of the embedder instead. 706 RenderWidgetHostViewPort* GetRenderWidgetHostViewPort() const; 707 708 // Misc non-view stuff ------------------------------------------------------- 709 710 // Helper functions for sending notifications. 711 void NotifySwapped(RenderViewHost* old_render_view_host); 712 void NotifyConnected(); 713 void NotifyDisconnected(); 714 715 void SetEncoding(const std::string& encoding); 716 717 // Save a URL to the local filesystem. 718 void SaveURL(const GURL& url, 719 const Referrer& referrer, 720 bool is_main_frame); 721 722 RenderViewHostImpl* GetRenderViewHostImpl(); 723 724 FrameTreeNode* FindFrameTreeNodeByID(int64 frame_id); 725 726 // Removes browser plugin embedder if there is one. 727 void RemoveBrowserPluginEmbedder(); 728 729 // Data for core operation --------------------------------------------------- 730 731 // Delegate for notifying our owner about stuff. Not owned by us. 732 WebContentsDelegate* delegate_; 733 734 // Handles the back/forward list and loading. 735 NavigationControllerImpl controller_; 736 737 // The corresponding view. 738 scoped_ptr<WebContentsViewPort> view_; 739 740 // The view of the RVHD. Usually this is our WebContentsView implementation, 741 // but if an embedder uses a different WebContentsView, they'll need to 742 // provide this. 743 RenderViewHostDelegateView* render_view_host_delegate_view_; 744 745 // Tracks created WebContentsImpl objects that have not been shown yet. They 746 // are identified by the route ID passed to CreateNewWindow. 747 typedef std::map<int, WebContentsImpl*> PendingContents; 748 PendingContents pending_contents_; 749 750 // These maps hold on to the widgets that we created on behalf of the renderer 751 // that haven't shown yet. 752 typedef std::map<int, RenderWidgetHostView*> PendingWidgetViews; 753 PendingWidgetViews pending_widget_views_; 754 755 typedef std::map<WebContentsImpl*, DestructionObserver*> DestructionObservers; 756 DestructionObservers destruction_observers_; 757 758 // A list of observers notified when page state changes. Weak references. 759 // This MUST be listed above render_manager_ since at destruction time the 760 // latter might cause RenderViewHost's destructor to call us and we might use 761 // the observer list then. 762 ObserverList<WebContentsObserver> observers_; 763 764 // The tab that opened this tab, if any. Will be set to null if the opener 765 // is closed. 766 WebContentsImpl* opener_; 767 768#if defined(OS_WIN) && defined(USE_AURA) 769 gfx::NativeViewAccessible accessible_parent_; 770#endif 771 772 // Helper classes ------------------------------------------------------------ 773 774 // Manages creation and swapping of render views. 775 RenderViewHostManager render_manager_; 776 777#if defined(ENABLE_JAVA_BRIDGE) 778 // Manages injecting Java objects into all RenderViewHosts associated with 779 // this WebContentsImpl. 780 scoped_ptr<JavaBridgeDispatcherHostManager> 781 java_bridge_dispatcher_host_manager_; 782#endif 783 784 // SavePackage, lazily created. 785 scoped_refptr<SavePackage> save_package_; 786 787 // Data for loading state ---------------------------------------------------- 788 789 // Indicates whether we're currently loading a resource. 790 bool is_loading_; 791 792 // Indicates if the tab is considered crashed. 793 base::TerminationStatus crashed_status_; 794 int crashed_error_code_; 795 796 // Whether this WebContents is waiting for a first-response for the 797 // main resource of the page. This controls whether the throbber state is 798 // "waiting" or "loading." 799 bool waiting_for_response_; 800 801 // Map of SiteInstance ID to max page ID for this tab. A page ID is specific 802 // to a given tab and SiteInstance, and must be valid for the lifetime of the 803 // WebContentsImpl. 804 std::map<int32, int32> max_page_ids_; 805 806 // System time at which the current load was started. 807 base::TimeTicks current_load_start_; 808 809 // The current load state and the URL associated with it. 810 net::LoadStateWithParam load_state_; 811 string16 load_state_host_; 812 // Upload progress, for displaying in the status bar. 813 // Set to zero when there is no significant upload happening. 814 uint64 upload_size_; 815 uint64 upload_position_; 816 817 // Data for current page ----------------------------------------------------- 818 819 // When a title cannot be taken from any entry, this title will be used. 820 string16 page_title_when_no_navigation_entry_; 821 822 // When a navigation occurs, we record its contents MIME type. It can be 823 // used to check whether we can do something for some special contents. 824 std::string contents_mime_type_; 825 826 // Character encoding. 827 std::string encoding_; 828 829 // True if this is a secure page which displayed insecure content. 830 bool displayed_insecure_content_; 831 832 // The frame tree structure of the current page. 833 scoped_ptr<FrameTreeNode> frame_tree_root_; 834 835 // Data for misc internal state ---------------------------------------------- 836 837 // When > 0, the WebContents is currently being captured (e.g., for 838 // screenshots or mirroring); and the underlying RenderWidgetHost should not 839 // be told it is hidden. 840 int capturer_count_; 841 842 // Tracks whether RWHV should be visible once capturer_count_ becomes zero. 843 bool should_normally_be_visible_; 844 845 // See getter above. 846 bool is_being_destroyed_; 847 848 // Indicates whether we should notify about disconnection of this 849 // WebContentsImpl. This is used to ensure disconnection notifications only 850 // happen if a connection notification has happened and that they happen only 851 // once. 852 bool notify_disconnection_; 853 854 // Pointer to the JavaScript dialog manager, lazily assigned. Used because the 855 // delegate of this WebContentsImpl is nulled before its destructor is called. 856 JavaScriptDialogManager* dialog_manager_; 857 858 // Set to true when there is an active "before unload" dialog. When true, 859 // we've forced the throbber to start in Navigate, and we need to remember to 860 // turn it off in OnJavaScriptMessageBoxClosed if the navigation is canceled. 861 bool is_showing_before_unload_dialog_; 862 863 // Settings that get passed to the renderer process. 864 RendererPreferences renderer_preferences_; 865 866 // The time that we started to create the new tab page. 867 base::TimeTicks new_tab_start_time_; 868 869 // The time that we started to close this WebContents. 870 base::TimeTicks close_start_time_; 871 872 // The time when onbeforeunload ended. 873 base::TimeTicks before_unload_end_time_; 874 875 // The time that this tab was last selected. 876 base::TimeTicks last_selected_time_; 877 878 // See description above setter. 879 bool closed_by_user_gesture_; 880 881 // Minimum/maximum zoom percent. 882 int minimum_zoom_percent_; 883 int maximum_zoom_percent_; 884 // If true, the default zoom limits have been overriden for this tab, in which 885 // case we don't want saved settings to apply to it and we don't want to 886 // remember it. 887 bool temporary_zoom_settings_; 888 889 // The intrinsic size of the page. 890 gfx::Size preferred_size_; 891 892 // Content restrictions, used to disable print/copy etc based on content's 893 // (full-page plugins for now only) permissions. 894 int content_restrictions_; 895 896#if defined(OS_ANDROID) 897 // Date time chooser opened by this tab. 898 // Only used in Android since all other platforms use a multi field UI. 899 scoped_ptr<DateTimeChooserAndroid> date_time_chooser_; 900#endif 901 902 // Color chooser that was opened by this tab. 903 scoped_ptr<ColorChooser> color_chooser_; 904 905 // A unique identifier for the current color chooser. Identifiers are unique 906 // across a renderer process. This avoids race conditions in synchronizing 907 // the browser and renderer processes. For example, if a renderer closes one 908 // chooser and opens another, and simultaneously the user picks a color in the 909 // first chooser, the IDs can be used to drop the "chose a color" message 910 // rather than erroneously tell the renderer that the user picked a color in 911 // the second chooser. 912 int color_chooser_identifier_; 913 914 // Manages the embedder state for browser plugins, if this WebContents is an 915 // embedder; NULL otherwise. 916 scoped_ptr<BrowserPluginEmbedder> browser_plugin_embedder_; 917 // Manages the guest state for browser plugin, if this WebContents is a guest; 918 // NULL otherwise. 919 scoped_ptr<BrowserPluginGuest> browser_plugin_guest_; 920 921 // This must be at the end, or else we might get notifications and use other 922 // member variables that are gone. 923 NotificationRegistrar registrar_; 924 925 // Used during IPC message dispatching so that the handlers can get a pointer 926 // to the RVH through which the message was received. 927 RenderViewHost* message_source_; 928 929 // All live RenderWidgetHostImpls that are created by this object and may 930 // outlive it. 931 std::set<RenderWidgetHostImpl*> created_widgets_; 932 933 // Routing id of the shown fullscreen widget or MSG_ROUTING_NONE otherwise. 934 int fullscreen_widget_routing_id_; 935 936 // Maps the ids of pending image downloads to their callbacks 937 typedef std::map<int, ImageDownloadCallback> ImageDownloadMap; 938 ImageDownloadMap image_download_map_; 939 940 DISALLOW_COPY_AND_ASSIGN(WebContentsImpl); 941}; 942 943} // namespace content 944 945#endif // CONTENT_BROWSER_WEB_CONTENTS_WEB_CONTENTS_IMPL_H_ 946