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