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