web_contents_impl.h revision 868fa2fe829687343ffae624259930155e16dbd8
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/render_view_host_delegate.h" 18#include "content/browser/renderer_host/render_widget_host_delegate.h" 19#include "content/browser/web_contents/frame_tree_node.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 OnCloseCanceled() OVERRIDE; 271 virtual void OnUnloadStarted() OVERRIDE; 272 virtual void OnUnloadDetachedStarted() OVERRIDE; 273 virtual void SystemDragEnded() OVERRIDE; 274 virtual void UserGestureDone() OVERRIDE; 275 virtual void SetClosedByUserGesture(bool value) OVERRIDE; 276 virtual bool GetClosedByUserGesture() const OVERRIDE; 277 virtual double GetZoomLevel() const OVERRIDE; 278 virtual int GetZoomPercent(bool* enable_increment, 279 bool* enable_decrement) const OVERRIDE; 280 virtual void ViewSource() OVERRIDE; 281 virtual void ViewFrameSource(const GURL& url, 282 const PageState& page_state) OVERRIDE; 283 virtual int GetMinimumZoomPercent() const OVERRIDE; 284 virtual int GetMaximumZoomPercent() const OVERRIDE; 285 virtual gfx::Size GetPreferredSize() const OVERRIDE; 286 virtual int GetContentRestrictions() const OVERRIDE; 287 virtual bool GotResponseToLockMouseRequest(bool allowed) OVERRIDE; 288 virtual bool HasOpener() const OVERRIDE; 289 virtual void DidChooseColorInColorChooser(SkColor color) OVERRIDE; 290 virtual void DidEndColorChooser() OVERRIDE; 291 virtual int DownloadImage(const GURL& url, 292 bool is_favicon, 293 int image_size, 294 const ImageDownloadCallback& callback) OVERRIDE; 295 296 // Implementation of PageNavigator. 297 virtual WebContents* OpenURL(const OpenURLParams& params) OVERRIDE; 298 299 // Implementation of IPC::Sender. 300 virtual bool Send(IPC::Message* message) OVERRIDE; 301 302 // RenderViewHostDelegate ---------------------------------------------------- 303 304 virtual RenderViewHostDelegateView* GetDelegateView() OVERRIDE; 305 virtual RenderViewHostDelegate::RendererManagement* 306 GetRendererManagementDelegate() OVERRIDE; 307 virtual bool OnMessageReceived(RenderViewHost* render_view_host, 308 const IPC::Message& message) OVERRIDE; 309 virtual const GURL& GetURL() const OVERRIDE; 310 virtual const GURL& GetActiveURL() const OVERRIDE; 311 virtual const GURL& GetLastCommittedURL() const OVERRIDE; 312 virtual WebContents* GetAsWebContents() OVERRIDE; 313 virtual gfx::Rect GetRootWindowResizerRect() const OVERRIDE; 314 virtual void RenderViewCreated(RenderViewHost* render_view_host) OVERRIDE; 315 virtual void RenderViewReady(RenderViewHost* render_view_host) OVERRIDE; 316 virtual void RenderViewTerminated(RenderViewHost* render_view_host, 317 base::TerminationStatus status, 318 int error_code) OVERRIDE; 319 virtual void RenderViewDeleted(RenderViewHost* render_view_host) OVERRIDE; 320 virtual void DidStartProvisionalLoadForFrame( 321 RenderViewHost* render_view_host, 322 int64 frame_id, 323 int64 parent_frame_id, 324 bool main_frame, 325 const GURL& url) OVERRIDE; 326 virtual void DidRedirectProvisionalLoad( 327 RenderViewHost* render_view_host, 328 int32 page_id, 329 const GURL& source_url, 330 const GURL& target_url) OVERRIDE; 331 virtual void DidFailProvisionalLoadWithError( 332 RenderViewHost* render_view_host, 333 const ViewHostMsg_DidFailProvisionalLoadWithError_Params& params) 334 OVERRIDE; 335 virtual void DidNavigate( 336 RenderViewHost* render_view_host, 337 const ViewHostMsg_FrameNavigate_Params& params) OVERRIDE; 338 virtual void UpdateState(RenderViewHost* render_view_host, 339 int32 page_id, 340 const PageState& page_state) OVERRIDE; 341 virtual void UpdateTitle(RenderViewHost* render_view_host, 342 int32 page_id, 343 const string16& title, 344 base::i18n::TextDirection title_direction) OVERRIDE; 345 virtual void UpdateEncoding(RenderViewHost* render_view_host, 346 const std::string& encoding) OVERRIDE; 347 virtual void UpdateTargetURL(int32 page_id, const GURL& url) OVERRIDE; 348 virtual void Close(RenderViewHost* render_view_host) OVERRIDE; 349 virtual void RequestMove(const gfx::Rect& new_bounds) OVERRIDE; 350 virtual void SwappedOut(RenderViewHost* render_view_host) OVERRIDE; 351 virtual void DidStartLoading(RenderViewHost* render_view_host) OVERRIDE; 352 virtual void DidStopLoading(RenderViewHost* render_view_host) OVERRIDE; 353 virtual void DidCancelLoading() OVERRIDE; 354 virtual void DidChangeLoadProgress(double progress) OVERRIDE; 355 virtual void DidDisownOpener(RenderViewHost* rvh) OVERRIDE; 356 virtual void DidAccessInitialDocument() OVERRIDE; 357 virtual void DocumentAvailableInMainFrame( 358 RenderViewHost* render_view_host) OVERRIDE; 359 virtual void DocumentOnLoadCompletedInMainFrame( 360 RenderViewHost* render_view_host, 361 int32 page_id) OVERRIDE; 362 virtual void RequestOpenURL(RenderViewHost* rvh, 363 const GURL& url, 364 const Referrer& referrer, 365 WindowOpenDisposition disposition, 366 int64 source_frame_id, 367 bool is_cross_site_redirect) OVERRIDE; 368 virtual void RequestTransferURL( 369 const GURL& url, 370 const Referrer& referrer, 371 WindowOpenDisposition disposition, 372 int64 source_frame_id, 373 const GlobalRequestID& transferred_global_request_id, 374 bool is_cross_site_redirect) OVERRIDE; 375 virtual void RouteCloseEvent(RenderViewHost* rvh) OVERRIDE; 376 virtual void RouteMessageEvent( 377 RenderViewHost* rvh, 378 const ViewMsg_PostMessage_Params& params) OVERRIDE; 379 virtual void RunJavaScriptMessage(RenderViewHost* rvh, 380 const string16& message, 381 const string16& default_prompt, 382 const GURL& frame_url, 383 JavaScriptMessageType type, 384 IPC::Message* reply_msg, 385 bool* did_suppress_message) OVERRIDE; 386 virtual void RunBeforeUnloadConfirm(RenderViewHost* rvh, 387 const string16& message, 388 bool is_reload, 389 IPC::Message* reply_msg) OVERRIDE; 390 virtual bool AddMessageToConsole(int32 level, 391 const string16& message, 392 int32 line_no, 393 const string16& source_id) OVERRIDE; 394 virtual RendererPreferences GetRendererPrefs( 395 BrowserContext* browser_context) const OVERRIDE; 396 virtual WebPreferences GetWebkitPrefs() OVERRIDE; 397 virtual void OnUserGesture() OVERRIDE; 398 virtual void OnIgnoredUIEvent() OVERRIDE; 399 virtual void RendererUnresponsive(RenderViewHost* render_view_host, 400 bool is_during_unload) OVERRIDE; 401 virtual void RendererResponsive(RenderViewHost* render_view_host) OVERRIDE; 402 virtual void LoadStateChanged(const GURL& url, 403 const net::LoadStateWithParam& load_state, 404 uint64 upload_position, 405 uint64 upload_size) OVERRIDE; 406 virtual void WorkerCrashed() OVERRIDE; 407 virtual void Activate() OVERRIDE; 408 virtual void Deactivate() OVERRIDE; 409 virtual void LostCapture() OVERRIDE; 410 virtual void HandleMouseDown() OVERRIDE; 411 virtual void HandleMouseUp() OVERRIDE; 412 virtual void HandlePointerActivate() OVERRIDE; 413 virtual void HandleGestureBegin() OVERRIDE; 414 virtual void HandleGestureEnd() OVERRIDE; 415 virtual void RunFileChooser( 416 RenderViewHost* render_view_host, 417 const FileChooserParams& params) OVERRIDE; 418 virtual void ToggleFullscreenMode(bool enter_fullscreen) OVERRIDE; 419 virtual bool IsFullscreenForCurrentTab() const OVERRIDE; 420 virtual void UpdatePreferredSize(const gfx::Size& pref_size) OVERRIDE; 421 virtual void ResizeDueToAutoResize(const gfx::Size& new_size) OVERRIDE; 422 virtual void RequestToLockMouse(bool user_gesture, 423 bool last_unlocked_by_target) OVERRIDE; 424 virtual void LostMouseLock() OVERRIDE; 425 virtual void CreateNewWindow( 426 int route_id, 427 int main_frame_route_id, 428 const ViewHostMsg_CreateWindow_Params& params, 429 SessionStorageNamespace* session_storage_namespace) OVERRIDE; 430 virtual void CreateNewWidget(int route_id, 431 WebKit::WebPopupType popup_type) OVERRIDE; 432 virtual void CreateNewFullscreenWidget(int route_id) OVERRIDE; 433 virtual void ShowCreatedWindow(int route_id, 434 WindowOpenDisposition disposition, 435 const gfx::Rect& initial_pos, 436 bool user_gesture) OVERRIDE; 437 virtual void ShowCreatedWidget(int route_id, 438 const gfx::Rect& initial_pos) OVERRIDE; 439 virtual void ShowCreatedFullscreenWidget(int route_id) OVERRIDE; 440 virtual void ShowContextMenu( 441 const ContextMenuParams& params, 442 ContextMenuSourceType type) OVERRIDE; 443 virtual void RequestMediaAccessPermission( 444 const MediaStreamRequest& request, 445 const MediaResponseCallback& callback) OVERRIDE; 446 447 // RenderWidgetHostDelegate -------------------------------------------------- 448 449 virtual void RenderWidgetDeleted( 450 RenderWidgetHostImpl* render_widget_host) OVERRIDE; 451 virtual bool PreHandleKeyboardEvent( 452 const NativeWebKeyboardEvent& event, 453 bool* is_keyboard_shortcut) OVERRIDE; 454 virtual void HandleKeyboardEvent( 455 const NativeWebKeyboardEvent& event) OVERRIDE; 456 virtual bool PreHandleWheelEvent( 457 const WebKit::WebMouseWheelEvent& event) OVERRIDE; 458 virtual void DidSendScreenRects(RenderWidgetHostImpl* rwh) OVERRIDE; 459#if defined(OS_WIN) && defined(USE_AURA) 460 virtual gfx::NativeViewAccessible GetParentNativeViewAccessible() OVERRIDE; 461#endif 462 463 // RenderViewHostManager::Delegate ------------------------------------------- 464 465 virtual bool CreateRenderViewForRenderManager( 466 RenderViewHost* render_view_host, int opener_route_id) OVERRIDE; 467 virtual void BeforeUnloadFiredFromRenderManager( 468 bool proceed, const base::TimeTicks& proceed_time, 469 bool* proceed_to_fire_unload) OVERRIDE; 470 virtual void RenderViewGoneFromRenderManager( 471 RenderViewHost* render_view_host) OVERRIDE; 472 virtual void UpdateRenderViewSizeForRenderManager() OVERRIDE; 473 virtual void NotifySwappedFromRenderManager( 474 RenderViewHost* old_render_view_host) OVERRIDE; 475 virtual int CreateOpenerRenderViewsForRenderManager( 476 SiteInstance* instance) OVERRIDE; 477 virtual NavigationControllerImpl& 478 GetControllerForRenderManager() OVERRIDE; 479 virtual WebUIImpl* CreateWebUIForRenderManager(const GURL& url) OVERRIDE; 480 virtual NavigationEntry* 481 GetLastCommittedNavigationEntryForRenderManager() OVERRIDE; 482 virtual bool FocusLocationBarByDefault() OVERRIDE; 483 virtual void SetFocusToLocationBar(bool select_all) OVERRIDE; 484 virtual void CreateViewAndSetSizeForRVH(RenderViewHost* rvh) OVERRIDE; 485 486 // NotificationObserver ------------------------------------------------------ 487 488 virtual void Observe(int type, 489 const NotificationSource& source, 490 const NotificationDetails& details) OVERRIDE; 491 492 493 private: 494 friend class NavigationControllerImpl; 495 friend class WebContentsObserver; 496 friend class WebContents; // To implement factory methods. 497 498 FRIEND_TEST_ALL_PREFIXES(WebContentsImplTest, NoJSMessageOnInterstitials); 499 FRIEND_TEST_ALL_PREFIXES(WebContentsImplTest, UpdateTitle); 500 FRIEND_TEST_ALL_PREFIXES(WebContentsImplTest, FindOpenerRVHWhenPending); 501 FRIEND_TEST_ALL_PREFIXES(WebContentsImplTest, 502 CrossSiteCantPreemptAfterUnload); 503 FRIEND_TEST_ALL_PREFIXES(WebContentsImplTest, PendingContents); 504 FRIEND_TEST_ALL_PREFIXES(WebContentsImplTest, FrameTreeShape); 505 FRIEND_TEST_ALL_PREFIXES(FormStructureBrowserTest, HTMLFiles); 506 FRIEND_TEST_ALL_PREFIXES(NavigationControllerTest, HistoryNavigate); 507 FRIEND_TEST_ALL_PREFIXES(RenderViewHostManagerTest, PageDoesBackAndReload); 508 509 // So InterstitialPageImpl can access SetIsLoading. 510 friend class InterstitialPageImpl; 511 512 // TODO(brettw) TestWebContents shouldn't exist! 513 friend class TestWebContents; 514 515 class DestructionObserver; 516 517 // See WebContents::Create for a description of these parameters. 518 WebContentsImpl(BrowserContext* browser_context, 519 WebContentsImpl* opener); 520 521 // Add and remove observers for page navigation notifications. Adding or 522 // removing multiple times has no effect. The order in which notifications 523 // are sent to observers is undefined. Clients must be sure to remove the 524 // observer before they go away. 525 void AddObserver(WebContentsObserver* observer); 526 void RemoveObserver(WebContentsObserver* observer); 527 528 // Clears this tab's opener if it has been closed. 529 void OnWebContentsDestroyed(WebContentsImpl* web_contents); 530 531 // Creates and adds to the map a destruction observer watching |web_contents|. 532 // No-op if such an observer already exists. 533 void AddDestructionObserver(WebContentsImpl* web_contents); 534 535 // Deletes and removes from the map a destruction observer 536 // watching |web_contents|. No-op if there is no such observer. 537 void RemoveDestructionObserver(WebContentsImpl* web_contents); 538 539 // Callback function when showing JS dialogs. 540 void OnDialogClosed(RenderViewHost* rvh, 541 IPC::Message* reply_msg, 542 bool success, 543 const string16& user_input); 544 545 // Callback function when requesting permission to access the PPAPI broker. 546 // |result| is true if permission was granted. 547 void OnPpapiBrokerPermissionResult(int request_id, bool result); 548 549 // IPC message handlers. 550 void OnDidLoadResourceFromMemoryCache(const GURL& url, 551 const std::string& security_info, 552 const std::string& http_request, 553 const std::string& mime_type, 554 ResourceType::Type resource_type); 555 void OnDidDisplayInsecureContent(); 556 void OnDidRunInsecureContent(const std::string& security_origin, 557 const GURL& target_url); 558 void OnDocumentLoadedInFrame(int64 frame_id); 559 void OnDidFinishLoad(int64 frame_id, 560 const GURL& url, 561 bool is_main_frame); 562 void OnDidFailLoadWithError(int64 frame_id, 563 const GURL& url, 564 bool is_main_frame, 565 int error_code, 566 const string16& error_description); 567 void OnUpdateContentRestrictions(int restrictions); 568 void OnGoToEntryAtOffset(int offset); 569 void OnUpdateZoomLimits(int minimum_percent, 570 int maximum_percent, 571 bool remember); 572 void OnSaveURL(const GURL& url, const Referrer& referrer); 573 void OnEnumerateDirectory(int request_id, const base::FilePath& path); 574 void OnJSOutOfMemory(); 575 576 void OnRegisterProtocolHandler(const std::string& protocol, 577 const GURL& url, 578 const string16& title, 579 bool user_gesture); 580 void OnFindReply(int request_id, 581 int number_of_matches, 582 const gfx::Rect& selection_rect, 583 int active_match_ordinal, 584 bool final_update); 585 void OnDidProgrammaticallyScroll(const gfx::Vector2d& scroll_point); 586#if defined(OS_ANDROID) 587 void OnFindMatchRectsReply(int version, 588 const std::vector<gfx::RectF>& rects, 589 const gfx::RectF& active_rect); 590 591 void OnOpenDateTimeDialog( 592 const ViewHostMsg_DateTimeDialogValue_Params& value); 593#endif 594 void OnCrashedPlugin(const base::FilePath& plugin_path, 595 base::ProcessId plugin_pid); 596 void OnAppCacheAccessed(const GURL& manifest_url, bool blocked_by_policy); 597 void OnOpenColorChooser(int color_chooser_id, SkColor color); 598 void OnEndColorChooser(int color_chooser_id); 599 void OnSetSelectedColorInColorChooser(int color_chooser_id, SkColor color); 600 void OnPepperPluginHung(int plugin_child_id, 601 const base::FilePath& path, 602 bool is_hung); 603 void OnWebUISend(const GURL& source_url, 604 const std::string& name, 605 const base::ListValue& args); 606 void OnRequestPpapiBrokerPermission(int request_id, 607 const GURL& url, 608 const base::FilePath& plugin_path); 609 void OnBrowserPluginMessage(const IPC::Message& message); 610 void OnDidDownloadImage(int id, 611 int http_status_code, 612 const GURL& image_url, 613 int requested_size, 614 const std::vector<SkBitmap>& bitmaps); 615 void OnUpdateFaviconURL(int32 page_id, 616 const std::vector<FaviconURL>& candidates); 617 void OnFrameAttached(int64 parent_frame_id, 618 int64 frame_id, 619 const std::string& frame_name); 620 void OnFrameDetached(int64 parent_frame_id, int64 frame_id); 621 622 // Changes the IsLoading state and notifies delegate as needed 623 // |details| is used to provide details on the load that just finished 624 // (but can be null if not applicable). Can be overridden. 625 void SetIsLoading(bool is_loading, 626 LoadNotificationDetails* details); 627 628 // Called by derived classes to indicate that we're no longer waiting for a 629 // response. This won't actually update the throbber, but it will get picked 630 // up at the next animation step if the throbber is going. 631 void SetNotWaitingForResponse() { waiting_for_response_ = false; } 632 633 // Navigation helpers -------------------------------------------------------- 634 // 635 // These functions are helpers for Navigate() and DidNavigate(). 636 637 // Handles post-navigation tasks in DidNavigate AFTER the entry has been 638 // committed to the navigation controller. Note that the navigation entry is 639 // not provided since it may be invalid/changed after being committed. The 640 // current navigation entry is in the NavigationController at this point. 641 void DidNavigateMainFramePostCommit( 642 const LoadCommittedDetails& details, 643 const ViewHostMsg_FrameNavigate_Params& params); 644 void DidNavigateAnyFramePostCommit( 645 RenderViewHost* render_view_host, 646 const LoadCommittedDetails& details, 647 const ViewHostMsg_FrameNavigate_Params& params); 648 649 // If our controller was restored, update the max page ID associated with the 650 // given RenderViewHost to be larger than the number of restored entries. 651 // This is called in CreateRenderView before any navigations in the RenderView 652 // have begun, to prevent any races in updating RenderView::next_page_id. 653 void UpdateMaxPageIDIfNecessary(RenderViewHost* rvh); 654 655 // Saves the given title to the navigation entry and does associated work. It 656 // will update history and the view for the new title, and also synthesize 657 // titles for file URLs that have none (so we require that the URL of the 658 // entry already be set). 659 // 660 // This is used as the backend for state updates, which include a new title, 661 // or the dedicated set title message. It returns true if the new title is 662 // different and was therefore updated. 663 bool UpdateTitleForEntry(NavigationEntryImpl* entry, 664 const string16& title); 665 666 // Causes the WebContentsImpl to navigate in the right renderer to |entry|, 667 // which must be already part of the entries in the navigation controller. 668 // This does not change the NavigationController state. 669 bool NavigateToEntry(const NavigationEntryImpl& entry, 670 NavigationController::ReloadType reload_type); 671 672 // Sets the history for this WebContentsImpl to |history_length| entries, and 673 // moves the current page_id to the last entry in the list if it's valid. 674 // This is mainly used when a prerendered page is swapped into the current 675 // tab. The method is virtual for testing. 676 virtual void SetHistoryLengthAndPrune( 677 const SiteInstance* site_instance, 678 int merge_history_length, 679 int32 minimum_page_id); 680 681 // Recursively creates swapped out RenderViews for this tab's opener chain 682 // (including this tab) in the given SiteInstance, allowing other tabs to send 683 // cross-process JavaScript calls to their opener(s). Returns the route ID of 684 // this tab's RenderView for |instance|. 685 int CreateOpenerRenderViews(SiteInstance* instance); 686 687 // Helper for CreateNewWidget/CreateNewFullscreenWidget. 688 void CreateNewWidget(int route_id, 689 bool is_fullscreen, 690 WebKit::WebPopupType popup_type); 691 692 // Helper for ShowCreatedWidget/ShowCreatedFullscreenWidget. 693 void ShowCreatedWidget(int route_id, 694 bool is_fullscreen, 695 const gfx::Rect& initial_pos); 696 697 // Finds the new RenderWidgetHost and returns it. Note that this can only be 698 // called once as this call also removes it from the internal map. 699 RenderWidgetHostView* GetCreatedWidget(int route_id); 700 701 // Finds the new WebContentsImpl by route_id, initializes it for 702 // renderer-initiated creation, and returns it. Note that this can only be 703 // called once as this call also removes it from the internal map. 704 WebContentsImpl* GetCreatedWindow(int route_id); 705 706 // Returns the RenderWidgetHostView that is associated with a native window 707 // and can be used in showing created widgets. 708 // If this WebContents belongs to a browser plugin guest, there is no native 709 // window 'view' associated with this WebContents. This method returns the 710 // 'view' of the embedder instead. 711 RenderWidgetHostViewPort* GetRenderWidgetHostViewPort() const; 712 713 // Misc non-view stuff ------------------------------------------------------- 714 715 // Helper functions for sending notifications. 716 void NotifySwapped(RenderViewHost* old_render_view_host); 717 void NotifyConnected(); 718 void NotifyDisconnected(); 719 void NotifyNavigationEntryCommitted(const LoadCommittedDetails& load_details); 720 721 void SetEncoding(const std::string& encoding); 722 723 // Save a URL to the local filesystem. 724 void SaveURL(const GURL& url, 725 const Referrer& referrer, 726 bool is_main_frame); 727 728 RenderViewHostImpl* GetRenderViewHostImpl(); 729 730 FrameTreeNode* FindFrameTreeNodeByID(int64 frame_id); 731 732 // Removes browser plugin embedder if there is one. 733 void RemoveBrowserPluginEmbedder(); 734 735 // Data for core operation --------------------------------------------------- 736 737 // Delegate for notifying our owner about stuff. Not owned by us. 738 WebContentsDelegate* delegate_; 739 740 // Handles the back/forward list and loading. 741 NavigationControllerImpl controller_; 742 743 // The corresponding view. 744 scoped_ptr<WebContentsViewPort> view_; 745 746 // The view of the RVHD. Usually this is our WebContentsView implementation, 747 // but if an embedder uses a different WebContentsView, they'll need to 748 // provide this. 749 RenderViewHostDelegateView* render_view_host_delegate_view_; 750 751 // Tracks created WebContentsImpl objects that have not been shown yet. They 752 // are identified by the route ID passed to CreateNewWindow. 753 typedef std::map<int, WebContentsImpl*> PendingContents; 754 PendingContents pending_contents_; 755 756 // These maps hold on to the widgets that we created on behalf of the renderer 757 // that haven't shown yet. 758 typedef std::map<int, RenderWidgetHostView*> PendingWidgetViews; 759 PendingWidgetViews pending_widget_views_; 760 761 typedef std::map<WebContentsImpl*, DestructionObserver*> DestructionObservers; 762 DestructionObservers destruction_observers_; 763 764 // A list of observers notified when page state changes. Weak references. 765 // This MUST be listed above render_manager_ since at destruction time the 766 // latter might cause RenderViewHost's destructor to call us and we might use 767 // the observer list then. 768 ObserverList<WebContentsObserver> observers_; 769 770 // The tab that opened this tab, if any. Will be set to null if the opener 771 // is closed. 772 WebContentsImpl* opener_; 773 774#if defined(OS_WIN) && defined(USE_AURA) 775 gfx::NativeViewAccessible accessible_parent_; 776#endif 777 778 // Helper classes ------------------------------------------------------------ 779 780 // Manages creation and swapping of render views. 781 RenderViewHostManager render_manager_; 782 783#if defined(ENABLE_JAVA_BRIDGE) 784 // Manages injecting Java objects into all RenderViewHosts associated with 785 // this WebContentsImpl. 786 scoped_ptr<JavaBridgeDispatcherHostManager> 787 java_bridge_dispatcher_host_manager_; 788#endif 789 790 // SavePackage, lazily created. 791 scoped_refptr<SavePackage> save_package_; 792 793 // Data for loading state ---------------------------------------------------- 794 795 // Indicates whether we're currently loading a resource. 796 bool is_loading_; 797 798 // Indicates if the tab is considered crashed. 799 base::TerminationStatus crashed_status_; 800 int crashed_error_code_; 801 802 // Whether this WebContents is waiting for a first-response for the 803 // main resource of the page. This controls whether the throbber state is 804 // "waiting" or "loading." 805 bool waiting_for_response_; 806 807 // Map of SiteInstance ID to max page ID for this tab. A page ID is specific 808 // to a given tab and SiteInstance, and must be valid for the lifetime of the 809 // WebContentsImpl. 810 std::map<int32, int32> max_page_ids_; 811 812 // System time at which the current load was started. 813 base::TimeTicks current_load_start_; 814 815 // The current load state and the URL associated with it. 816 net::LoadStateWithParam load_state_; 817 string16 load_state_host_; 818 // Upload progress, for displaying in the status bar. 819 // Set to zero when there is no significant upload happening. 820 uint64 upload_size_; 821 uint64 upload_position_; 822 823 // Data for current page ----------------------------------------------------- 824 825 // When a title cannot be taken from any entry, this title will be used. 826 string16 page_title_when_no_navigation_entry_; 827 828 // When a navigation occurs, we record its contents MIME type. It can be 829 // used to check whether we can do something for some special contents. 830 std::string contents_mime_type_; 831 832 // Character encoding. 833 std::string encoding_; 834 835 // True if this is a secure page which displayed insecure content. 836 bool displayed_insecure_content_; 837 838 // The frame tree structure of the current page. 839 scoped_ptr<FrameTreeNode> frame_tree_root_; 840 841 // Data for misc internal state ---------------------------------------------- 842 843 // When > 0, the WebContents is currently being captured (e.g., for 844 // screenshots or mirroring); and the underlying RenderWidgetHost should not 845 // be told it is hidden. 846 int capturer_count_; 847 848 // Tracks whether RWHV should be visible once capturer_count_ becomes zero. 849 bool should_normally_be_visible_; 850 851 // See getter above. 852 bool is_being_destroyed_; 853 854 // Indicates whether we should notify about disconnection of this 855 // WebContentsImpl. This is used to ensure disconnection notifications only 856 // happen if a connection notification has happened and that they happen only 857 // once. 858 bool notify_disconnection_; 859 860 // Pointer to the JavaScript dialog manager, lazily assigned. Used because the 861 // delegate of this WebContentsImpl is nulled before its destructor is called. 862 JavaScriptDialogManager* dialog_manager_; 863 864 // Set to true when there is an active "before unload" dialog. When true, 865 // we've forced the throbber to start in Navigate, and we need to remember to 866 // turn it off in OnJavaScriptMessageBoxClosed if the navigation is canceled. 867 bool is_showing_before_unload_dialog_; 868 869 // Settings that get passed to the renderer process. 870 RendererPreferences renderer_preferences_; 871 872 // The time that we started to create the new tab page. 873 base::TimeTicks new_tab_start_time_; 874 875 // The time that we started to close this WebContents. 876 base::TimeTicks close_start_time_; 877 878 // The time when onbeforeunload ended. 879 base::TimeTicks before_unload_end_time_; 880 881 // The time when the tab was removed from view during close. 882 base::TimeTicks unload_detached_start_time_; 883 884 // The time that this tab was last selected. 885 base::TimeTicks last_selected_time_; 886 887 // See description above setter. 888 bool closed_by_user_gesture_; 889 890 // Minimum/maximum zoom percent. 891 int minimum_zoom_percent_; 892 int maximum_zoom_percent_; 893 // If true, the default zoom limits have been overriden for this tab, in which 894 // case we don't want saved settings to apply to it and we don't want to 895 // remember it. 896 bool temporary_zoom_settings_; 897 898 // The intrinsic size of the page. 899 gfx::Size preferred_size_; 900 901 // Content restrictions, used to disable print/copy etc based on content's 902 // (full-page plugins for now only) permissions. 903 int content_restrictions_; 904 905#if defined(OS_ANDROID) 906 // Date time chooser opened by this tab. 907 // Only used in Android since all other platforms use a multi field UI. 908 scoped_ptr<DateTimeChooserAndroid> date_time_chooser_; 909#endif 910 911 // Color chooser that was opened by this tab. 912 scoped_ptr<ColorChooser> color_chooser_; 913 914 // A unique identifier for the current color chooser. Identifiers are unique 915 // across a renderer process. This avoids race conditions in synchronizing 916 // the browser and renderer processes. For example, if a renderer closes one 917 // chooser and opens another, and simultaneously the user picks a color in the 918 // first chooser, the IDs can be used to drop the "chose a color" message 919 // rather than erroneously tell the renderer that the user picked a color in 920 // the second chooser. 921 int color_chooser_identifier_; 922 923 // Manages the embedder state for browser plugins, if this WebContents is an 924 // embedder; NULL otherwise. 925 scoped_ptr<BrowserPluginEmbedder> browser_plugin_embedder_; 926 // Manages the guest state for browser plugin, if this WebContents is a guest; 927 // NULL otherwise. 928 scoped_ptr<BrowserPluginGuest> browser_plugin_guest_; 929 930 // This must be at the end, or else we might get notifications and use other 931 // member variables that are gone. 932 NotificationRegistrar registrar_; 933 934 // Used during IPC message dispatching so that the handlers can get a pointer 935 // to the RVH through which the message was received. 936 RenderViewHost* message_source_; 937 938 // All live RenderWidgetHostImpls that are created by this object and may 939 // outlive it. 940 std::set<RenderWidgetHostImpl*> created_widgets_; 941 942 // Routing id of the shown fullscreen widget or MSG_ROUTING_NONE otherwise. 943 int fullscreen_widget_routing_id_; 944 945 // Maps the ids of pending image downloads to their callbacks 946 typedef std::map<int, ImageDownloadCallback> ImageDownloadMap; 947 ImageDownloadMap image_download_map_; 948 949 DISALLOW_COPY_AND_ASSIGN(WebContentsImpl); 950}; 951 952} // namespace content 953 954#endif // CONTENT_BROWSER_WEB_CONTENTS_WEB_CONTENTS_IMPL_H_ 955