web_contents_impl.h revision 5f1c94371a64b3196d4be9466099bb892df9b88e
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/frame_host/frame_tree.h" 19#include "content/browser/frame_host/navigation_controller_delegate.h" 20#include "content/browser/frame_host/navigation_controller_impl.h" 21#include "content/browser/frame_host/navigator_delegate.h" 22#include "content/browser/frame_host/render_frame_host_delegate.h" 23#include "content/browser/frame_host/render_frame_host_manager.h" 24#include "content/browser/renderer_host/render_view_host_delegate.h" 25#include "content/browser/renderer_host/render_widget_host_delegate.h" 26#include "content/common/accessibility_mode_enums.h" 27#include "content/common/content_export.h" 28#include "content/public/browser/color_chooser.h" 29#include "content/public/browser/notification_observer.h" 30#include "content/public/browser/notification_registrar.h" 31#include "content/public/browser/web_contents.h" 32#include "content/public/common/page_transition_types.h" 33#include "content/public/common/renderer_preferences.h" 34#include "content/public/common/resource_type.h" 35#include "content/public/common/three_d_api_types.h" 36#include "net/base/load_states.h" 37#include "net/http/http_response_headers.h" 38#include "third_party/WebKit/public/web/WebDragOperation.h" 39#include "ui/gfx/rect_f.h" 40#include "ui/gfx/size.h" 41 42struct BrowserPluginHostMsg_ResizeGuest_Params; 43struct ViewHostMsg_DateTimeDialogValue_Params; 44struct ViewMsg_PostMessage_Params; 45 46namespace content { 47class BrowserPluginEmbedder; 48class BrowserPluginGuest; 49class BrowserPluginGuestManager; 50class DateTimeChooserAndroid; 51class DownloadItem; 52class GeolocationDispatcherHost; 53class InterstitialPageImpl; 54class JavaScriptDialogManager; 55class MidiDispatcherHost; 56class PowerSaveBlocker; 57class RenderViewHost; 58class RenderViewHostDelegateView; 59class RenderViewHostImpl; 60class RenderWidgetHostImpl; 61class SavePackage; 62class ScreenOrientationDispatcherHost; 63class SiteInstance; 64class TestWebContents; 65class WebContentsDelegate; 66class WebContentsImpl; 67class WebContentsObserver; 68class WebContentsView; 69class WebContentsViewDelegate; 70struct AXEventNotificationDetails; 71struct ColorSuggestion; 72struct FaviconURL; 73struct LoadNotificationDetails; 74struct ResourceRedirectDetails; 75struct ResourceRequestDetails; 76 77// Factory function for the implementations that content knows about. Takes 78// ownership of |delegate|. 79WebContentsView* CreateWebContentsView( 80 WebContentsImpl* web_contents, 81 WebContentsViewDelegate* delegate, 82 RenderViewHostDelegateView** render_view_host_delegate_view); 83 84class CONTENT_EXPORT WebContentsImpl 85 : public NON_EXPORTED_BASE(WebContents), 86 public NON_EXPORTED_BASE(RenderFrameHostDelegate), 87 public RenderViewHostDelegate, 88 public RenderWidgetHostDelegate, 89 public RenderFrameHostManager::Delegate, 90 public NotificationObserver, 91 public NON_EXPORTED_BASE(NavigationControllerDelegate), 92 public NON_EXPORTED_BASE(NavigatorDelegate) { 93 public: 94 virtual ~WebContentsImpl(); 95 96 static WebContentsImpl* CreateWithOpener( 97 const WebContents::CreateParams& params, 98 WebContentsImpl* opener); 99 100 static std::vector<WebContentsImpl*> GetAllWebContents(); 101 102 // Returns the opener WebContentsImpl, if any. This can be set to null if the 103 // opener is closed or the page clears its window.opener. 104 WebContentsImpl* opener() const { return opener_; } 105 106 // Creates a swapped out RenderView. This is used by the browser plugin to 107 // create a swapped out RenderView in the embedder render process for the 108 // guest, to expose the guest's window object to the embedder. 109 // This returns the routing ID of the newly created swapped out RenderView. 110 int CreateSwappedOutRenderView(SiteInstance* instance); 111 112 // Complex initialization here. Specifically needed to avoid having 113 // members call back into our virtual functions in the constructor. 114 virtual void Init(const WebContents::CreateParams& params); 115 116 // Returns the SavePackage which manages the page saving job. May be NULL. 117 SavePackage* save_package() const { return save_package_.get(); } 118 119#if defined(OS_ANDROID) 120 // In Android WebView, the RenderView needs created even there is no 121 // navigation entry, this allows Android WebViews to use 122 // javascript: URLs that load into the DOMWindow before the first page 123 // load. This is not safe to do in any context that a web page could get a 124 // reference to the DOMWindow before the first page load. 125 bool CreateRenderViewForInitialEmptyDocument(); 126#endif 127 128 // Expose the render manager for testing. 129 // TODO(creis): Remove this now that we can get to it via FrameTreeNode. 130 RenderFrameHostManager* GetRenderManagerForTesting(); 131 132 // Returns guest browser plugin object, or NULL if this WebContents is not a 133 // guest. 134 BrowserPluginGuest* GetBrowserPluginGuest() const; 135 136 // Sets a BrowserPluginGuest object for this WebContents. If this WebContents 137 // has a BrowserPluginGuest then that implies that it is being hosted by 138 // a BrowserPlugin object in an embedder renderer process. 139 void SetBrowserPluginGuest(BrowserPluginGuest* guest); 140 141 // Returns embedder browser plugin object, or NULL if this WebContents is not 142 // an embedder. 143 BrowserPluginEmbedder* GetBrowserPluginEmbedder() const; 144 145 // Gets the current fullscreen render widget's routing ID. Returns 146 // MSG_ROUTING_NONE when there is no fullscreen render widget. 147 int GetFullscreenWidgetRoutingID() const; 148 149 // Invoked when visible SSL state (as defined by SSLStatus) changes. 150 void DidChangeVisibleSSLState(); 151 152 // Informs the render view host and the BrowserPluginEmbedder, if present, of 153 // a Drag Source End. 154 void DragSourceEndedAt(int client_x, int client_y, int screen_x, 155 int screen_y, blink::WebDragOperation operation); 156 157 // A response has been received for a resource request. 158 void DidGetResourceResponseStart( 159 const ResourceRequestDetails& details); 160 161 // A redirect was received while requesting a resource. 162 void DidGetRedirectForResourceRequest( 163 RenderViewHost* render_view_host, 164 const ResourceRedirectDetails& details); 165 166 WebContentsView* GetView() const; 167 168 GeolocationDispatcherHost* geolocation_dispatcher_host() { 169 return geolocation_dispatcher_host_.get(); 170 } 171 172 ScreenOrientationDispatcherHost* screen_orientation_dispatcher_host() { 173 return screen_orientation_dispatcher_host_.get(); 174 } 175 176 bool should_normally_be_visible() { return should_normally_be_visible_; } 177 178 // Broadcasts the mode change to all frames. 179 void SetAccessibilityMode(AccessibilityMode mode); 180 181 // Adds the given accessibility mode to the current accessibility mode 182 // bitmap. 183 void AddAccessibilityMode(AccessibilityMode mode); 184 185 // Removes the given accessibility mode from the current accessibility 186 // mode bitmap, managing the bits that are shared with other modes such 187 // that a bit will only be turned off when all modes that depend on it 188 // have been removed. 189 void RemoveAccessibilityMode(AccessibilityMode mode); 190 191 // WebContents ------------------------------------------------------ 192 virtual WebContentsDelegate* GetDelegate() OVERRIDE; 193 virtual void SetDelegate(WebContentsDelegate* delegate) OVERRIDE; 194 virtual NavigationControllerImpl& GetController() OVERRIDE; 195 virtual const NavigationControllerImpl& GetController() const OVERRIDE; 196 virtual BrowserContext* GetBrowserContext() const OVERRIDE; 197 virtual const GURL& GetURL() const OVERRIDE; 198 virtual const GURL& GetVisibleURL() const OVERRIDE; 199 virtual const GURL& GetLastCommittedURL() const OVERRIDE; 200 virtual RenderProcessHost* GetRenderProcessHost() const OVERRIDE; 201 virtual RenderFrameHost* GetMainFrame() OVERRIDE; 202 virtual RenderFrameHost* GetFocusedFrame() OVERRIDE; 203 virtual void ForEachFrame( 204 const base::Callback<void(RenderFrameHost*)>& on_frame) OVERRIDE; 205 virtual void SendToAllFrames(IPC::Message* message) OVERRIDE; 206 virtual RenderViewHost* GetRenderViewHost() const OVERRIDE; 207 virtual int GetRoutingID() const OVERRIDE; 208 virtual RenderWidgetHostView* GetRenderWidgetHostView() const OVERRIDE; 209 virtual RenderWidgetHostView* GetFullscreenRenderWidgetHostView() const 210 OVERRIDE; 211 virtual WebUI* CreateWebUI(const GURL& url) OVERRIDE; 212 virtual WebUI* GetWebUI() const OVERRIDE; 213 virtual WebUI* GetCommittedWebUI() const OVERRIDE; 214 virtual void SetUserAgentOverride(const std::string& override) OVERRIDE; 215 virtual const std::string& GetUserAgentOverride() const OVERRIDE; 216 virtual void EnableTreeOnlyAccessibilityMode() OVERRIDE; 217 virtual bool IsTreeOnlyAccessibilityModeForTesting() const OVERRIDE; 218 virtual bool IsFullAccessibilityModeForTesting() const OVERRIDE; 219#if defined(OS_WIN) 220 virtual void SetParentNativeViewAccessible( 221 gfx::NativeViewAccessible accessible_parent) OVERRIDE; 222#endif 223 virtual const base::string16& GetTitle() const OVERRIDE; 224 virtual int32 GetMaxPageID() OVERRIDE; 225 virtual int32 GetMaxPageIDForSiteInstance( 226 SiteInstance* site_instance) OVERRIDE; 227 virtual SiteInstance* GetSiteInstance() const OVERRIDE; 228 virtual SiteInstance* GetPendingSiteInstance() const OVERRIDE; 229 virtual bool IsLoading() const OVERRIDE; 230 virtual bool IsLoadingToDifferentDocument() const OVERRIDE; 231 virtual bool IsWaitingForResponse() const OVERRIDE; 232 virtual const net::LoadStateWithParam& GetLoadState() const OVERRIDE; 233 virtual const base::string16& GetLoadStateHost() const OVERRIDE; 234 virtual uint64 GetUploadSize() const OVERRIDE; 235 virtual uint64 GetUploadPosition() const OVERRIDE; 236 virtual std::set<GURL> GetSitesInTab() const OVERRIDE; 237 virtual const std::string& GetEncoding() const OVERRIDE; 238 virtual bool DisplayedInsecureContent() const OVERRIDE; 239 virtual void IncrementCapturerCount(const gfx::Size& capture_size) OVERRIDE; 240 virtual void DecrementCapturerCount() OVERRIDE; 241 virtual int GetCapturerCount() const OVERRIDE; 242 virtual bool IsCrashed() const OVERRIDE; 243 virtual void SetIsCrashed(base::TerminationStatus status, 244 int error_code) OVERRIDE; 245 virtual base::TerminationStatus GetCrashedStatus() const OVERRIDE; 246 virtual bool IsBeingDestroyed() const OVERRIDE; 247 virtual void NotifyNavigationStateChanged(unsigned changed_flags) OVERRIDE; 248 virtual base::TimeTicks GetLastActiveTime() const OVERRIDE; 249 virtual void WasShown() OVERRIDE; 250 virtual void WasHidden() OVERRIDE; 251 virtual bool NeedToFireBeforeUnload() OVERRIDE; 252 virtual void DispatchBeforeUnload(bool for_cross_site_transition) OVERRIDE; 253 virtual void Stop() OVERRIDE; 254 virtual WebContents* Clone() OVERRIDE; 255 virtual void ReloadFocusedFrame(bool ignore_cache) OVERRIDE; 256 virtual void Undo() OVERRIDE; 257 virtual void Redo() OVERRIDE; 258 virtual void Cut() OVERRIDE; 259 virtual void Copy() OVERRIDE; 260 virtual void CopyToFindPboard() OVERRIDE; 261 virtual void Paste() OVERRIDE; 262 virtual void PasteAndMatchStyle() OVERRIDE; 263 virtual void Delete() OVERRIDE; 264 virtual void SelectAll() OVERRIDE; 265 virtual void Unselect() OVERRIDE; 266 virtual void Replace(const base::string16& word) OVERRIDE; 267 virtual void ReplaceMisspelling(const base::string16& word) OVERRIDE; 268 virtual void NotifyContextMenuClosed( 269 const CustomContextMenuContext& context) OVERRIDE; 270 virtual void ExecuteCustomContextMenuCommand( 271 int action, const CustomContextMenuContext& context) OVERRIDE; 272 virtual gfx::NativeView GetNativeView() OVERRIDE; 273 virtual gfx::NativeView GetContentNativeView() OVERRIDE; 274 virtual gfx::NativeWindow GetTopLevelNativeWindow() OVERRIDE; 275 virtual gfx::Rect GetContainerBounds() OVERRIDE; 276 virtual gfx::Rect GetViewBounds() OVERRIDE; 277 virtual DropData* GetDropData() OVERRIDE; 278 virtual void Focus() OVERRIDE; 279 virtual void SetInitialFocus() OVERRIDE; 280 virtual void StoreFocus() OVERRIDE; 281 virtual void RestoreFocus() OVERRIDE; 282 virtual void FocusThroughTabTraversal(bool reverse) OVERRIDE; 283 virtual bool ShowingInterstitialPage() const OVERRIDE; 284 virtual InterstitialPage* GetInterstitialPage() const OVERRIDE; 285 virtual bool IsSavable() OVERRIDE; 286 virtual void OnSavePage() OVERRIDE; 287 virtual bool SavePage(const base::FilePath& main_file, 288 const base::FilePath& dir_path, 289 SavePageType save_type) OVERRIDE; 290 virtual void SaveFrame(const GURL& url, 291 const Referrer& referrer) OVERRIDE; 292 virtual void GenerateMHTML( 293 const base::FilePath& file, 294 const base::Callback<void(int64)>& callback) 295 OVERRIDE; 296 virtual const std::string& GetContentsMimeType() const OVERRIDE; 297 virtual bool WillNotifyDisconnection() const OVERRIDE; 298 virtual void SetOverrideEncoding(const std::string& encoding) OVERRIDE; 299 virtual void ResetOverrideEncoding() OVERRIDE; 300 virtual RendererPreferences* GetMutableRendererPrefs() OVERRIDE; 301 virtual void Close() OVERRIDE; 302 virtual void SystemDragEnded() OVERRIDE; 303 virtual void UserGestureDone() OVERRIDE; 304 virtual void SetClosedByUserGesture(bool value) OVERRIDE; 305 virtual bool GetClosedByUserGesture() const OVERRIDE; 306 virtual void ViewSource() OVERRIDE; 307 virtual void ViewFrameSource(const GURL& url, 308 const PageState& page_state) OVERRIDE; 309 virtual int GetMinimumZoomPercent() const OVERRIDE; 310 virtual int GetMaximumZoomPercent() const OVERRIDE; 311 virtual gfx::Size GetPreferredSize() const OVERRIDE; 312 virtual bool GotResponseToLockMouseRequest(bool allowed) OVERRIDE; 313 virtual bool HasOpener() const OVERRIDE; 314 virtual void DidChooseColorInColorChooser(SkColor color) OVERRIDE; 315 virtual void DidEndColorChooser() OVERRIDE; 316 virtual int DownloadImage(const GURL& url, 317 bool is_favicon, 318 uint32_t max_bitmap_size, 319 const ImageDownloadCallback& callback) OVERRIDE; 320 virtual bool IsSubframe() const OVERRIDE; 321 virtual void Find(int request_id, 322 const base::string16& search_text, 323 const blink::WebFindOptions& options) OVERRIDE; 324 virtual void StopFinding(StopFindAction action) OVERRIDE; 325 virtual void InsertCSS(const std::string& css) OVERRIDE; 326#if defined(OS_ANDROID) 327 virtual base::android::ScopedJavaLocalRef<jobject> GetJavaWebContents() 328 OVERRIDE; 329#elif defined(OS_MACOSX) 330 virtual void SetAllowOverlappingViews(bool overlapping) OVERRIDE; 331 virtual bool GetAllowOverlappingViews() OVERRIDE; 332 virtual void SetAllowOtherViews(bool allow) OVERRIDE; 333 virtual bool GetAllowOtherViews() OVERRIDE; 334#endif 335 336 // Implementation of PageNavigator. 337 virtual WebContents* OpenURL(const OpenURLParams& params) OVERRIDE; 338 339 // Implementation of IPC::Sender. 340 virtual bool Send(IPC::Message* message) OVERRIDE; 341 342 // RenderFrameHostDelegate --------------------------------------------------- 343 virtual bool OnMessageReceived(RenderFrameHost* render_frame_host, 344 const IPC::Message& message) OVERRIDE; 345 virtual const GURL& GetMainFrameLastCommittedURL() const OVERRIDE; 346 virtual void RenderFrameCreated(RenderFrameHost* render_frame_host) OVERRIDE; 347 virtual void RenderFrameDeleted(RenderFrameHost* render_frame_host) OVERRIDE; 348 virtual void DidStartLoading(RenderFrameHost* render_frame_host, 349 bool to_different_document) OVERRIDE; 350 virtual void SwappedOut(RenderFrameHost* render_frame_host) OVERRIDE; 351 virtual void DidDeferAfterResponseStarted( 352 const scoped_refptr<net::HttpResponseHeaders>& headers, 353 const GURL& url) OVERRIDE; 354 virtual bool WillHandleDeferAfterResponseStarted() OVERRIDE; 355 virtual void WorkerCrashed(RenderFrameHost* render_frame_host) OVERRIDE; 356 virtual void ShowContextMenu(RenderFrameHost* render_frame_host, 357 const ContextMenuParams& params) OVERRIDE; 358 virtual void RunJavaScriptMessage(RenderFrameHost* render_frame_host, 359 const base::string16& message, 360 const base::string16& default_prompt, 361 const GURL& frame_url, 362 JavaScriptMessageType type, 363 IPC::Message* reply_msg) OVERRIDE; 364 virtual void RunBeforeUnloadConfirm(RenderFrameHost* render_frame_host, 365 const base::string16& message, 366 bool is_reload, 367 IPC::Message* reply_msg) OVERRIDE; 368 virtual void DidAccessInitialDocument() OVERRIDE; 369 virtual void DidDisownOpener(RenderFrameHost* render_frame_host) OVERRIDE; 370 virtual void DocumentOnLoadCompleted( 371 RenderFrameHost* render_frame_host) OVERRIDE; 372 virtual void UpdateTitle(RenderFrameHost* render_frame_host, 373 int32 page_id, 374 const base::string16& title, 375 base::i18n::TextDirection title_direction) OVERRIDE; 376 virtual void UpdateEncoding(RenderFrameHost* render_frame_host, 377 const std::string& encoding) OVERRIDE; 378 virtual WebContents* GetAsWebContents() OVERRIDE; 379 virtual bool IsNeverVisible() OVERRIDE; 380 virtual AccessibilityMode GetAccessibilityMode() const OVERRIDE; 381 virtual void AccessibilityEventReceived( 382 const std::vector<AXEventNotificationDetails>& details) OVERRIDE; 383#if defined(OS_WIN) 384 virtual gfx::NativeViewAccessible GetParentNativeViewAccessible() OVERRIDE; 385#endif 386 387 // RenderViewHostDelegate ---------------------------------------------------- 388 virtual RenderViewHostDelegateView* GetDelegateView() OVERRIDE; 389 virtual bool OnMessageReceived(RenderViewHost* render_view_host, 390 const IPC::Message& message) OVERRIDE; 391 // RenderFrameHostDelegate has the same method, so list it there because this 392 // interface is going away. 393 // virtual WebContents* GetAsWebContents() OVERRIDE; 394 virtual gfx::Rect GetRootWindowResizerRect() const OVERRIDE; 395 virtual void RenderViewCreated(RenderViewHost* render_view_host) OVERRIDE; 396 virtual void RenderViewReady(RenderViewHost* render_view_host) OVERRIDE; 397 virtual void RenderViewTerminated(RenderViewHost* render_view_host, 398 base::TerminationStatus status, 399 int error_code) OVERRIDE; 400 virtual void RenderViewDeleted(RenderViewHost* render_view_host) OVERRIDE; 401 virtual void UpdateState(RenderViewHost* render_view_host, 402 int32 page_id, 403 const PageState& page_state) OVERRIDE; 404 virtual void UpdateTargetURL(int32 page_id, const GURL& url) OVERRIDE; 405 virtual void Close(RenderViewHost* render_view_host) OVERRIDE; 406 virtual void RequestMove(const gfx::Rect& new_bounds) OVERRIDE; 407 virtual void DidCancelLoading() OVERRIDE; 408 virtual void DocumentAvailableInMainFrame( 409 RenderViewHost* render_view_host) OVERRIDE; 410 virtual void RouteCloseEvent(RenderViewHost* rvh) OVERRIDE; 411 virtual void RouteMessageEvent( 412 RenderViewHost* rvh, 413 const ViewMsg_PostMessage_Params& params) OVERRIDE; 414 virtual bool AddMessageToConsole(int32 level, 415 const base::string16& message, 416 int32 line_no, 417 const base::string16& source_id) OVERRIDE; 418 virtual RendererPreferences GetRendererPrefs( 419 BrowserContext* browser_context) const OVERRIDE; 420 virtual WebPreferences GetWebkitPrefs() OVERRIDE; 421 virtual void OnUserGesture() OVERRIDE; 422 virtual void OnIgnoredUIEvent() OVERRIDE; 423 virtual void RendererUnresponsive(RenderViewHost* render_view_host, 424 bool is_during_beforeunload, 425 bool is_during_unload) OVERRIDE; 426 virtual void RendererResponsive(RenderViewHost* render_view_host) OVERRIDE; 427 virtual void LoadStateChanged(const GURL& url, 428 const net::LoadStateWithParam& load_state, 429 uint64 upload_position, 430 uint64 upload_size) OVERRIDE; 431 virtual void Activate() OVERRIDE; 432 virtual void Deactivate() OVERRIDE; 433 virtual void LostCapture() OVERRIDE; 434 virtual void HandleMouseDown() OVERRIDE; 435 virtual void HandleMouseUp() OVERRIDE; 436 virtual void HandlePointerActivate() OVERRIDE; 437 virtual void HandleGestureBegin() OVERRIDE; 438 virtual void HandleGestureEnd() OVERRIDE; 439 virtual void RunFileChooser( 440 RenderViewHost* render_view_host, 441 const FileChooserParams& params) OVERRIDE; 442 virtual void ToggleFullscreenMode(bool enter_fullscreen) OVERRIDE; 443 virtual bool IsFullscreenForCurrentTab() const OVERRIDE; 444 virtual void UpdatePreferredSize(const gfx::Size& pref_size) OVERRIDE; 445 virtual void ResizeDueToAutoResize(const gfx::Size& new_size) OVERRIDE; 446 virtual void RequestToLockMouse(bool user_gesture, 447 bool last_unlocked_by_target) OVERRIDE; 448 virtual void LostMouseLock() OVERRIDE; 449 virtual void CreateNewWindow( 450 int render_process_id, 451 int route_id, 452 int main_frame_route_id, 453 const ViewHostMsg_CreateWindow_Params& params, 454 SessionStorageNamespace* session_storage_namespace) OVERRIDE; 455 virtual void CreateNewWidget(int render_process_id, 456 int route_id, 457 blink::WebPopupType popup_type) OVERRIDE; 458 virtual void CreateNewFullscreenWidget(int render_process_id, 459 int route_id) OVERRIDE; 460 virtual void ShowCreatedWindow(int route_id, 461 WindowOpenDisposition disposition, 462 const gfx::Rect& initial_pos, 463 bool user_gesture) OVERRIDE; 464 virtual void ShowCreatedWidget(int route_id, 465 const gfx::Rect& initial_pos) OVERRIDE; 466 virtual void ShowCreatedFullscreenWidget(int route_id) OVERRIDE; 467 virtual void RequestMediaAccessPermission( 468 const MediaStreamRequest& request, 469 const MediaResponseCallback& callback) OVERRIDE; 470 virtual SessionStorageNamespace* GetSessionStorageNamespace( 471 SiteInstance* instance) OVERRIDE; 472 virtual SessionStorageNamespaceMap GetSessionStorageNamespaceMap() OVERRIDE; 473 virtual FrameTree* GetFrameTree() OVERRIDE; 474 475 // NavigatorDelegate --------------------------------------------------------- 476 477 virtual void DidStartProvisionalLoad( 478 RenderFrameHostImpl* render_frame_host, 479 const GURL& validated_url, 480 bool is_error_page, 481 bool is_iframe_srcdoc) OVERRIDE; 482 virtual void DidStartNavigationTransition( 483 RenderFrameHostImpl* render_frame_host) OVERRIDE; 484 virtual void DidFailProvisionalLoadWithError( 485 RenderFrameHostImpl* render_frame_host, 486 const FrameHostMsg_DidFailProvisionalLoadWithError_Params& params) 487 OVERRIDE; 488 virtual void DidFailLoadWithError( 489 RenderFrameHostImpl* render_frame_host, 490 const GURL& url, 491 int error_code, 492 const base::string16& error_description) OVERRIDE; 493 virtual void DidRedirectProvisionalLoad( 494 RenderFrameHostImpl* render_frame_host, 495 const GURL& validated_target_url) OVERRIDE; 496 virtual void DidCommitProvisionalLoad( 497 RenderFrameHostImpl* render_frame_host, 498 const GURL& url, 499 PageTransition transition_type) OVERRIDE; 500 virtual void DidNavigateMainFramePreCommit( 501 bool navigation_is_within_page) OVERRIDE; 502 virtual void DidNavigateMainFramePostCommit( 503 const LoadCommittedDetails& details, 504 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) OVERRIDE; 505 virtual void DidNavigateAnyFramePostCommit( 506 RenderFrameHostImpl* render_frame_host, 507 const LoadCommittedDetails& details, 508 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) OVERRIDE; 509 virtual void SetMainFrameMimeType(const std::string& mime_type) OVERRIDE; 510 virtual bool CanOverscrollContent() const OVERRIDE; 511 virtual void NotifyChangedNavigationState( 512 InvalidateTypes changed_flags) OVERRIDE; 513 virtual void AboutToNavigateRenderFrame( 514 RenderFrameHostImpl* render_frame_host) OVERRIDE; 515 virtual void DidStartNavigationToPendingEntry( 516 RenderFrameHostImpl* render_frame_host, 517 const GURL& url, 518 NavigationController::ReloadType reload_type) OVERRIDE; 519 virtual void RequestOpenURL(RenderFrameHostImpl* render_frame_host, 520 const OpenURLParams& params) OVERRIDE; 521 virtual bool ShouldPreserveAbortedURLs() OVERRIDE; 522 523 // RenderWidgetHostDelegate -------------------------------------------------- 524 525 virtual void RenderWidgetDeleted( 526 RenderWidgetHostImpl* render_widget_host) OVERRIDE; 527 virtual bool PreHandleKeyboardEvent( 528 const NativeWebKeyboardEvent& event, 529 bool* is_keyboard_shortcut) OVERRIDE; 530 virtual void HandleKeyboardEvent( 531 const NativeWebKeyboardEvent& event) OVERRIDE; 532 virtual bool HandleWheelEvent( 533 const blink::WebMouseWheelEvent& event) OVERRIDE; 534 virtual bool PreHandleGestureEvent( 535 const blink::WebGestureEvent& event) OVERRIDE; 536 virtual bool HandleGestureEvent( 537 const blink::WebGestureEvent& event) OVERRIDE; 538 virtual void DidSendScreenRects(RenderWidgetHostImpl* rwh) OVERRIDE; 539 virtual void OnTouchEmulationEnabled(bool enabled) OVERRIDE; 540 virtual BrowserAccessibilityManager* GetRootBrowserAccessibilityManager() 541 OVERRIDE; 542 virtual BrowserAccessibilityManager* 543 GetOrCreateRootBrowserAccessibilityManager() OVERRIDE; 544 545 // RenderFrameHostManager::Delegate ------------------------------------------ 546 547 virtual bool CreateRenderViewForRenderManager( 548 RenderViewHost* render_view_host, 549 int opener_route_id, 550 int proxy_routing_id, 551 bool for_main_frame_navigation) OVERRIDE; 552 virtual bool CreateRenderFrameForRenderManager( 553 RenderFrameHost* render_frame_host, 554 int parent_routing_id) OVERRIDE; 555 virtual void BeforeUnloadFiredFromRenderManager( 556 bool proceed, const base::TimeTicks& proceed_time, 557 bool* proceed_to_fire_unload) OVERRIDE; 558 virtual void RenderProcessGoneFromRenderManager( 559 RenderViewHost* render_view_host) OVERRIDE; 560 virtual void UpdateRenderViewSizeForRenderManager() OVERRIDE; 561 virtual void CancelModalDialogsForRenderManager() OVERRIDE; 562 virtual void NotifySwappedFromRenderManager(RenderFrameHost* old_host, 563 RenderFrameHost* new_host, 564 bool is_main_frame) OVERRIDE; 565 virtual int CreateOpenerRenderViewsForRenderManager( 566 SiteInstance* instance) OVERRIDE; 567 virtual NavigationControllerImpl& 568 GetControllerForRenderManager() OVERRIDE; 569 virtual WebUIImpl* CreateWebUIForRenderManager(const GURL& url) OVERRIDE; 570 virtual NavigationEntry* 571 GetLastCommittedNavigationEntryForRenderManager() OVERRIDE; 572 virtual bool FocusLocationBarByDefault() OVERRIDE; 573 virtual void SetFocusToLocationBar(bool select_all) OVERRIDE; 574 virtual void CreateViewAndSetSizeForRVH(RenderViewHost* rvh) OVERRIDE; 575 virtual bool IsHidden() OVERRIDE; 576 577 // NotificationObserver ------------------------------------------------------ 578 579 virtual void Observe(int type, 580 const NotificationSource& source, 581 const NotificationDetails& details) OVERRIDE; 582 583 // NavigationControllerDelegate ---------------------------------------------- 584 585 virtual WebContents* GetWebContents() OVERRIDE; 586 virtual void NotifyNavigationEntryCommitted( 587 const LoadCommittedDetails& load_details) OVERRIDE; 588 589 // Invoked before a form repost warning is shown. 590 virtual void NotifyBeforeFormRepostWarningShow() OVERRIDE; 591 592 // Activate this WebContents and show a form repost warning. 593 virtual void ActivateAndShowRepostFormWarningDialog() OVERRIDE; 594 595 // Whether the initial empty page of this view has been accessed by another 596 // page, making it unsafe to show the pending URL. Always false after the 597 // first commit. 598 virtual bool HasAccessedInitialDocument() OVERRIDE; 599 600 // Updates the max page ID for the current SiteInstance in this 601 // WebContentsImpl to be at least |page_id|. 602 virtual void UpdateMaxPageID(int32 page_id) OVERRIDE; 603 604 // Updates the max page ID for the given SiteInstance in this WebContentsImpl 605 // to be at least |page_id|. 606 virtual void UpdateMaxPageIDForSiteInstance(SiteInstance* site_instance, 607 int32 page_id) OVERRIDE; 608 609 // Copy the current map of SiteInstance ID to max page ID from another tab. 610 // This is necessary when this tab adopts the NavigationEntries from 611 // |web_contents|. 612 virtual void CopyMaxPageIDsFrom(WebContents* web_contents) OVERRIDE; 613 614 // Called by the NavigationController to cause the WebContentsImpl to navigate 615 // to the current pending entry. The NavigationController should be called 616 // back with RendererDidNavigate on success or DiscardPendingEntry on failure. 617 // The callbacks can be inside of this function, or at some future time. 618 // 619 // The entry has a PageID of -1 if newly created (corresponding to navigation 620 // to a new URL). 621 // 622 // If this method returns false, then the navigation is discarded (equivalent 623 // to calling DiscardPendingEntry on the NavigationController). 624 virtual bool NavigateToPendingEntry( 625 NavigationController::ReloadType reload_type) OVERRIDE; 626 627 // Sets the history for this WebContentsImpl to |history_length| entries, and 628 // moves the current page_id to the last entry in the list if it's valid. 629 // This is mainly used when a prerendered page is swapped into the current 630 // tab. The method is virtual for testing. 631 virtual void SetHistoryLengthAndPrune( 632 const SiteInstance* site_instance, 633 int merge_history_length, 634 int32 minimum_page_id) OVERRIDE; 635 636 // Called by InterstitialPageImpl when it creates a RenderFrameHost. 637 virtual void RenderFrameForInterstitialPageCreated( 638 RenderFrameHost* render_frame_host) OVERRIDE; 639 640 // Sets the passed interstitial as the currently showing interstitial. 641 // No interstitial page should already be attached. 642 virtual void AttachInterstitialPage( 643 InterstitialPageImpl* interstitial_page) OVERRIDE; 644 645 // Unsets the currently showing interstitial. 646 virtual void DetachInterstitialPage() OVERRIDE; 647 648 // Changes the IsLoading state and notifies the delegate as needed. 649 // |details| is used to provide details on the load that just finished 650 // (but can be null if not applicable). 651 virtual void SetIsLoading(RenderViewHost* render_view_host, 652 bool is_loading, 653 bool to_different_document, 654 LoadNotificationDetails* details) OVERRIDE; 655 656 typedef base::Callback<void(WebContents*)> CreatedCallback; 657 658 // Requests the renderer to select the region between two points in the 659 // currently focused frame. 660 void SelectRange(const gfx::Point& start, const gfx::Point& end); 661 662 // Notifies the main frame that it can continue navigation (if it was deferred 663 // immediately at first response). 664 void ResumeResponseDeferredAtStart(); 665 666 private: 667 friend class TestNavigationObserver; 668 friend class WebContentsAddedObserver; 669 friend class WebContentsObserver; 670 friend class WebContents; // To implement factory methods. 671 672 FRIEND_TEST_ALL_PREFIXES(WebContentsImplTest, NoJSMessageOnInterstitials); 673 FRIEND_TEST_ALL_PREFIXES(WebContentsImplTest, UpdateTitle); 674 FRIEND_TEST_ALL_PREFIXES(WebContentsImplTest, FindOpenerRVHWhenPending); 675 FRIEND_TEST_ALL_PREFIXES(WebContentsImplTest, 676 CrossSiteCantPreemptAfterUnload); 677 FRIEND_TEST_ALL_PREFIXES(WebContentsImplTest, PendingContents); 678 FRIEND_TEST_ALL_PREFIXES(WebContentsImplTest, FrameTreeShape); 679 FRIEND_TEST_ALL_PREFIXES(WebContentsImplTest, GetLastActiveTime); 680 FRIEND_TEST_ALL_PREFIXES(FormStructureBrowserTest, HTMLFiles); 681 FRIEND_TEST_ALL_PREFIXES(NavigationControllerTest, HistoryNavigate); 682 FRIEND_TEST_ALL_PREFIXES(RenderFrameHostManagerTest, PageDoesBackAndReload); 683 FRIEND_TEST_ALL_PREFIXES(SitePerProcessBrowserTest, CrossSiteIframe); 684 685 // So InterstitialPageImpl can access SetIsLoading. 686 friend class InterstitialPageImpl; 687 688 // TODO(brettw) TestWebContents shouldn't exist! 689 friend class TestWebContents; 690 691 class DestructionObserver; 692 693 // See WebContents::Create for a description of these parameters. 694 WebContentsImpl(BrowserContext* browser_context, 695 WebContentsImpl* opener); 696 697 // Add and remove observers for page navigation notifications. The order in 698 // which notifications are sent to observers is undefined. Clients must be 699 // sure to remove the observer before they go away. 700 void AddObserver(WebContentsObserver* observer); 701 void RemoveObserver(WebContentsObserver* observer); 702 703 // Clears this tab's opener if it has been closed. 704 void OnWebContentsDestroyed(WebContentsImpl* web_contents); 705 706 // Creates and adds to the map a destruction observer watching |web_contents|. 707 // No-op if such an observer already exists. 708 void AddDestructionObserver(WebContentsImpl* web_contents); 709 710 // Deletes and removes from the map a destruction observer 711 // watching |web_contents|. No-op if there is no such observer. 712 void RemoveDestructionObserver(WebContentsImpl* web_contents); 713 714 // Traverses all the RenderFrameHosts in the FrameTree and creates a set 715 // all the unique RenderWidgetHostViews. 716 std::set<RenderWidgetHostView*> GetRenderWidgetHostViewsInTree(); 717 718 // Callback function when showing JavaScript dialogs. Takes in a routing ID 719 // pair to identify the RenderFrameHost that opened the dialog, because it's 720 // possible for the RenderFrameHost to be deleted by the time this is called. 721 void OnDialogClosed(int render_process_id, 722 int render_frame_id, 723 IPC::Message* reply_msg, 724 bool dialog_was_suppressed, 725 bool success, 726 const base::string16& user_input); 727 728 // Callback function when requesting permission to access the PPAPI broker. 729 // |result| is true if permission was granted. 730 void OnPpapiBrokerPermissionResult(int routing_id, bool result); 731 732 bool OnMessageReceived(RenderViewHost* render_view_host, 733 RenderFrameHost* render_frame_host, 734 const IPC::Message& message); 735 736 // IPC message handlers. 737 void OnThemeColorChanged(SkColor theme_color); 738 void OnDidLoadResourceFromMemoryCache(const GURL& url, 739 const std::string& security_info, 740 const std::string& http_request, 741 const std::string& mime_type, 742 ResourceType resource_type); 743 void OnDidDisplayInsecureContent(); 744 void OnDidRunInsecureContent(const std::string& security_origin, 745 const GURL& target_url); 746 void OnDocumentLoadedInFrame(); 747 void OnDidFinishLoad(const GURL& url); 748 void OnDidStartLoading(bool to_different_document); 749 void OnDidStopLoading(); 750 void OnDidChangeLoadProgress(double load_progress); 751 void OnGoToEntryAtOffset(int offset); 752 void OnUpdateZoomLimits(int minimum_percent, 753 int maximum_percent); 754 void OnEnumerateDirectory(int request_id, const base::FilePath& path); 755 756 void OnRegisterProtocolHandler(const std::string& protocol, 757 const GURL& url, 758 const base::string16& title, 759 bool user_gesture); 760 void OnUnregisterProtocolHandler(const std::string& protocol, 761 const GURL& url, 762 bool user_gesture); 763 void OnFindReply(int request_id, 764 int number_of_matches, 765 const gfx::Rect& selection_rect, 766 int active_match_ordinal, 767 bool final_update); 768#if defined(OS_ANDROID) 769 void OnFindMatchRectsReply(int version, 770 const std::vector<gfx::RectF>& rects, 771 const gfx::RectF& active_rect); 772 773 void OnOpenDateTimeDialog( 774 const ViewHostMsg_DateTimeDialogValue_Params& value); 775#endif 776 void OnPepperPluginHung(int plugin_child_id, 777 const base::FilePath& path, 778 bool is_hung); 779 void OnPluginCrashed(const base::FilePath& plugin_path, 780 base::ProcessId plugin_pid); 781 void OnDomOperationResponse(const std::string& json_string, 782 int automation_id); 783 void OnAppCacheAccessed(const GURL& manifest_url, bool blocked_by_policy); 784 void OnOpenColorChooser(int color_chooser_id, 785 SkColor color, 786 const std::vector<ColorSuggestion>& suggestions); 787 void OnEndColorChooser(int color_chooser_id); 788 void OnSetSelectedColorInColorChooser(int color_chooser_id, SkColor color); 789 void OnWebUISend(const GURL& source_url, 790 const std::string& name, 791 const base::ListValue& args); 792 void OnRequestPpapiBrokerPermission(int routing_id, 793 const GURL& url, 794 const base::FilePath& plugin_path); 795 void OnBrowserPluginMessage(const IPC::Message& message); 796 void OnDidDownloadImage(int id, 797 int http_status_code, 798 const GURL& image_url, 799 const std::vector<SkBitmap>& bitmaps, 800 const std::vector<gfx::Size>& original_bitmap_sizes); 801 void OnUpdateFaviconURL(const std::vector<FaviconURL>& candidates); 802 void OnFirstVisuallyNonEmptyPaint(); 803 void OnMediaPlayingNotification(int64 player_cookie, 804 bool has_video, 805 bool has_audio); 806 void OnMediaPausedNotification(int64 player_cookie); 807 void OnShowValidationMessage(const gfx::Rect& anchor_in_root_view, 808 const base::string16& main_text, 809 const base::string16& sub_text); 810 void OnHideValidationMessage(); 811 void OnMoveValidationMessage(const gfx::Rect& anchor_in_root_view); 812 813 // Called by derived classes to indicate that we're no longer waiting for a 814 // response. This won't actually update the throbber, but it will get picked 815 // up at the next animation step if the throbber is going. 816 void SetNotWaitingForResponse() { waiting_for_response_ = false; } 817 818 // Navigation helpers -------------------------------------------------------- 819 // 820 // These functions are helpers for Navigate() and DidNavigate(). 821 822 // Handles post-navigation tasks in DidNavigate AFTER the entry has been 823 // committed to the navigation controller. Note that the navigation entry is 824 // not provided since it may be invalid/changed after being committed. The 825 // current navigation entry is in the NavigationController at this point. 826 827 // If our controller was restored, update the max page ID associated with the 828 // given RenderViewHost to be larger than the number of restored entries. 829 // This is called in CreateRenderView before any navigations in the RenderView 830 // have begun, to prevent any races in updating RenderView::next_page_id. 831 void UpdateMaxPageIDIfNecessary(RenderViewHost* rvh); 832 833 // Saves the given title to the navigation entry and does associated work. It 834 // will update history and the view for the new title, and also synthesize 835 // titles for file URLs that have none (so we require that the URL of the 836 // entry already be set). 837 // 838 // This is used as the backend for state updates, which include a new title, 839 // or the dedicated set title message. It returns true if the new title is 840 // different and was therefore updated. 841 bool UpdateTitleForEntry(NavigationEntryImpl* entry, 842 const base::string16& title); 843 844 // Recursively creates swapped out RenderViews for this tab's opener chain 845 // (including this tab) in the given SiteInstance, allowing other tabs to send 846 // cross-process JavaScript calls to their opener(s). Returns the route ID of 847 // this tab's RenderView for |instance|. 848 int CreateOpenerRenderViews(SiteInstance* instance); 849 850 // Helper for CreateNewWidget/CreateNewFullscreenWidget. 851 void CreateNewWidget(int render_process_id, 852 int route_id, 853 bool is_fullscreen, 854 blink::WebPopupType popup_type); 855 856 // Helper for ShowCreatedWidget/ShowCreatedFullscreenWidget. 857 void ShowCreatedWidget(int route_id, 858 bool is_fullscreen, 859 const gfx::Rect& initial_pos); 860 861 // Finds the new RenderWidgetHost and returns it. Note that this can only be 862 // called once as this call also removes it from the internal map. 863 RenderWidgetHostView* GetCreatedWidget(int route_id); 864 865 // Finds the new WebContentsImpl by route_id, initializes it for 866 // renderer-initiated creation, and returns it. Note that this can only be 867 // called once as this call also removes it from the internal map. 868 WebContentsImpl* GetCreatedWindow(int route_id); 869 870 // Tracking loading progress ------------------------------------------------- 871 872 // Resets the tracking state of the current load. 873 void ResetLoadProgressState(); 874 875 // Calculates the progress of the current load and notifies the delegate. 876 void SendLoadProgressChanged(); 877 878 // Called once when the last frame on the page has stopped loading. 879 void DidStopLoading(RenderFrameHost* render_frame_host); 880 881 // Misc non-view stuff ------------------------------------------------------- 882 883 // Helper functions for sending notifications. 884 void NotifyViewSwapped(RenderViewHost* old_host, RenderViewHost* new_host); 885 void NotifyFrameSwapped(RenderFrameHost* old_host, RenderFrameHost* new_host); 886 void NotifyDisconnected(); 887 888 void SetEncoding(const std::string& encoding); 889 890 // TODO(creis): This should take in a FrameTreeNode to know which node's 891 // render manager to return. For now, we just return the root's. 892 RenderFrameHostManager* GetRenderManager() const; 893 894 RenderViewHostImpl* GetRenderViewHostImpl(); 895 896 // Removes browser plugin embedder if there is one. 897 void RemoveBrowserPluginEmbedder(); 898 899 // Clear |render_frame_host|'s PowerSaveBlockers. 900 void ClearPowerSaveBlockers(RenderFrameHost* render_frame_host); 901 902 // Clear all PowerSaveBlockers, leave power_save_blocker_ empty. 903 void ClearAllPowerSaveBlockers(); 904 905 // Helper function to invoke WebContentsDelegate::GetSizeForNewRenderView(). 906 gfx::Size GetSizeForNewRenderView(); 907 908 void OnFrameRemoved(RenderFrameHost* render_frame_host); 909 910 // Helper method that's called whenever |preferred_size_| or 911 // |preferred_size_for_capture_| changes, to propagate the new value to the 912 // |delegate_|. 913 void OnPreferredSizeChanged(const gfx::Size& old_size); 914 915 // Adds/removes a callback called on creation of each new WebContents. 916 // Deprecated, about to remove. 917 static void AddCreatedCallback(const CreatedCallback& callback); 918 static void RemoveCreatedCallback(const CreatedCallback& callback); 919 920 // Data for core operation --------------------------------------------------- 921 922 // Delegate for notifying our owner about stuff. Not owned by us. 923 WebContentsDelegate* delegate_; 924 925 // Handles the back/forward list and loading. 926 NavigationControllerImpl controller_; 927 928 // The corresponding view. 929 scoped_ptr<WebContentsView> view_; 930 931 // The view of the RVHD. Usually this is our WebContentsView implementation, 932 // but if an embedder uses a different WebContentsView, they'll need to 933 // provide this. 934 RenderViewHostDelegateView* render_view_host_delegate_view_; 935 936 // Tracks created WebContentsImpl objects that have not been shown yet. They 937 // are identified by the route ID passed to CreateNewWindow. 938 typedef std::map<int, WebContentsImpl*> PendingContents; 939 PendingContents pending_contents_; 940 941 // These maps hold on to the widgets that we created on behalf of the renderer 942 // that haven't shown yet. 943 typedef std::map<int, RenderWidgetHostView*> PendingWidgetViews; 944 PendingWidgetViews pending_widget_views_; 945 946 typedef std::map<WebContentsImpl*, DestructionObserver*> DestructionObservers; 947 DestructionObservers destruction_observers_; 948 949 // A list of observers notified when page state changes. Weak references. 950 // This MUST be listed above frame_tree_ since at destruction time the 951 // latter might cause RenderViewHost's destructor to call us and we might use 952 // the observer list then. 953 ObserverList<WebContentsObserver> observers_; 954 955 // The tab that opened this tab, if any. Will be set to null if the opener 956 // is closed. 957 WebContentsImpl* opener_; 958 959 // True if this tab was opened by another tab. This is not unset if the opener 960 // is closed. 961 bool created_with_opener_; 962 963#if defined(OS_WIN) 964 gfx::NativeViewAccessible accessible_parent_; 965#endif 966 967 // Helper classes ------------------------------------------------------------ 968 969 // Maps the RenderFrameHost to its media_player_cookie and PowerSaveBlocker 970 // pairs. Key is the RenderFrameHost, value is the map which maps 971 // player_cookie on to PowerSaveBlocker. 972 typedef std::map<RenderFrameHost*, std::map<int64, PowerSaveBlocker*> > 973 PowerSaveBlockerMap; 974 PowerSaveBlockerMap power_save_blockers_; 975 976 // Manages the frame tree of the page and process swaps in each node. 977 FrameTree frame_tree_; 978 979 // SavePackage, lazily created. 980 scoped_refptr<SavePackage> save_package_; 981 982 // Data for loading state ---------------------------------------------------- 983 984 // Indicates whether we're currently loading a resource. 985 bool is_loading_; 986 987 // Indicates whether the current load is to a different document. Only valid 988 // if is_loading_ is true. 989 bool is_load_to_different_document_; 990 991 // Indicates if the tab is considered crashed. 992 base::TerminationStatus crashed_status_; 993 int crashed_error_code_; 994 995 // Whether this WebContents is waiting for a first-response for the 996 // main resource of the page. This controls whether the throbber state is 997 // "waiting" or "loading." 998 bool waiting_for_response_; 999 1000 // Map of SiteInstance ID to max page ID for this tab. A page ID is specific 1001 // to a given tab and SiteInstance, and must be valid for the lifetime of the 1002 // WebContentsImpl. 1003 std::map<int32, int32> max_page_ids_; 1004 1005 // The current load state and the URL associated with it. 1006 net::LoadStateWithParam load_state_; 1007 base::string16 load_state_host_; 1008 1009 // LoadingProgressMap maps FrameTreeNode IDs to a double representing that 1010 // frame's completion (from 0 to 1). 1011 typedef base::hash_map<int64, double> LoadingProgressMap; 1012 LoadingProgressMap loading_progresses_; 1013 double loading_total_progress_; 1014 1015 base::TimeTicks loading_last_progress_update_; 1016 1017 base::WeakPtrFactory<WebContentsImpl> loading_weak_factory_; 1018 1019 // Counter to track how many frames have sent start notifications but not 1020 // stop notifications. 1021 int loading_frames_in_progress_; 1022 1023 // Upload progress, for displaying in the status bar. 1024 // Set to zero when there is no significant upload happening. 1025 uint64 upload_size_; 1026 uint64 upload_position_; 1027 1028 // Data for current page ----------------------------------------------------- 1029 1030 // When a title cannot be taken from any entry, this title will be used. 1031 base::string16 page_title_when_no_navigation_entry_; 1032 1033 // When a navigation occurs, we record its contents MIME type. It can be 1034 // used to check whether we can do something for some special contents. 1035 std::string contents_mime_type_; 1036 1037 // The last reported character encoding, not canonicalized. 1038 std::string last_reported_encoding_; 1039 1040 // The canonicalized character encoding. 1041 std::string canonical_encoding_; 1042 1043 // True if this is a secure page which displayed insecure content. 1044 bool displayed_insecure_content_; 1045 1046 // Whether the initial empty page has been accessed by another page, making it 1047 // unsafe to show the pending URL. Usually false unless another window tries 1048 // to modify the blank page. Always false after the first commit. 1049 bool has_accessed_initial_document_; 1050 1051 // Data for misc internal state ---------------------------------------------- 1052 1053 // When > 0, the WebContents is currently being captured (e.g., for 1054 // screenshots or mirroring); and the underlying RenderWidgetHost should not 1055 // be told it is hidden. 1056 int capturer_count_; 1057 1058 // Tracks whether RWHV should be visible once capturer_count_ becomes zero. 1059 bool should_normally_be_visible_; 1060 1061 // See getter above. 1062 bool is_being_destroyed_; 1063 1064 // Indicates whether we should notify about disconnection of this 1065 // WebContentsImpl. This is used to ensure disconnection notifications only 1066 // happen if a connection notification has happened and that they happen only 1067 // once. 1068 bool notify_disconnection_; 1069 1070 // Pointer to the JavaScript dialog manager, lazily assigned. Used because the 1071 // delegate of this WebContentsImpl is nulled before its destructor is called. 1072 JavaScriptDialogManager* dialog_manager_; 1073 1074 // Set to true when there is an active "before unload" dialog. When true, 1075 // we've forced the throbber to start in Navigate, and we need to remember to 1076 // turn it off in OnJavaScriptMessageBoxClosed if the navigation is canceled. 1077 bool is_showing_before_unload_dialog_; 1078 1079 // Settings that get passed to the renderer process. 1080 RendererPreferences renderer_preferences_; 1081 1082 // The time that this WebContents was last made active. The initial value is 1083 // the WebContents creation time. 1084 base::TimeTicks last_active_time_; 1085 1086 // See description above setter. 1087 bool closed_by_user_gesture_; 1088 1089 // Minimum/maximum zoom percent. 1090 int minimum_zoom_percent_; 1091 int maximum_zoom_percent_; 1092 1093 // The raw accumulated zoom value and the actual zoom increments made for an 1094 // an in-progress pinch gesture. 1095 float totalPinchGestureAmount_; 1096 int currentPinchZoomStepDelta_; 1097 1098 // The intrinsic size of the page. 1099 gfx::Size preferred_size_; 1100 1101 // The preferred size for content screen capture. When |capturer_count_| > 0, 1102 // this overrides |preferred_size_|. 1103 gfx::Size preferred_size_for_capture_; 1104 1105#if defined(OS_ANDROID) 1106 // Date time chooser opened by this tab. 1107 // Only used in Android since all other platforms use a multi field UI. 1108 scoped_ptr<DateTimeChooserAndroid> date_time_chooser_; 1109#endif 1110 1111 // Holds information about a current color chooser dialog, if one is visible. 1112 struct ColorChooserInfo { 1113 ColorChooserInfo(int render_process_id, 1114 int render_frame_id, 1115 ColorChooser* chooser, 1116 int identifier); 1117 ~ColorChooserInfo(); 1118 1119 int render_process_id; 1120 int render_frame_id; 1121 1122 // Color chooser that was opened by this tab. 1123 scoped_ptr<ColorChooser> chooser; 1124 1125 // A unique identifier for the current color chooser. Identifiers are 1126 // unique across a renderer process. This avoids race conditions in 1127 // synchronizing the browser and renderer processes. For example, if a 1128 // renderer closes one chooser and opens another, and simultaneously the 1129 // user picks a color in the first chooser, the IDs can be used to drop the 1130 // "chose a color" message rather than erroneously tell the renderer that 1131 // the user picked a color in the second chooser. 1132 int identifier; 1133 }; 1134 1135 scoped_ptr<ColorChooserInfo> color_chooser_info_; 1136 1137 // Manages the embedder state for browser plugins, if this WebContents is an 1138 // embedder; NULL otherwise. 1139 scoped_ptr<BrowserPluginEmbedder> browser_plugin_embedder_; 1140 // Manages the guest state for browser plugin, if this WebContents is a guest; 1141 // NULL otherwise. 1142 scoped_ptr<BrowserPluginGuest> browser_plugin_guest_; 1143 1144 // This must be at the end, or else we might get notifications and use other 1145 // member variables that are gone. 1146 NotificationRegistrar registrar_; 1147 1148 // Used during IPC message dispatching from the RenderView/RenderFrame so that 1149 // the handlers can get a pointer to the RVH through which the message was 1150 // received. 1151 RenderViewHost* render_view_message_source_; 1152 RenderFrameHost* render_frame_message_source_; 1153 1154 // All live RenderWidgetHostImpls that are created by this object and may 1155 // outlive it. 1156 std::set<RenderWidgetHostImpl*> created_widgets_; 1157 1158 // Routing id of the shown fullscreen widget or MSG_ROUTING_NONE otherwise. 1159 int fullscreen_widget_routing_id_; 1160 1161 // At the time the fullscreen widget was being shut down, did it have focus? 1162 // This is used to restore focus to the WebContentsView after both: 1) the 1163 // fullscreen widget is destroyed, and 2) the WebContentsDelegate has 1164 // completed making layout changes to effect an exit from fullscreen mode. 1165 bool fullscreen_widget_had_focus_at_shutdown_; 1166 1167 // Maps the ids of pending image downloads to their callbacks 1168 typedef std::map<int, ImageDownloadCallback> ImageDownloadMap; 1169 ImageDownloadMap image_download_map_; 1170 1171 // Whether this WebContents is responsible for displaying a subframe in a 1172 // different process from its parent page. 1173 bool is_subframe_; 1174 1175 // Whether touch emulation is enabled in RenderWidgetHost. 1176 bool touch_emulation_enabled_; 1177 1178 // Whether the last JavaScript dialog shown was suppressed. Used for testing. 1179 bool last_dialog_suppressed_; 1180 1181 scoped_ptr<GeolocationDispatcherHost> geolocation_dispatcher_host_; 1182 1183 scoped_ptr<MidiDispatcherHost> midi_dispatcher_host_; 1184 1185 scoped_ptr<ScreenOrientationDispatcherHost> 1186 screen_orientation_dispatcher_host_; 1187 1188 // The accessibility mode for all frames. This is queried when each frame 1189 // is created, and broadcast to all frames when it changes. 1190 AccessibilityMode accessibility_mode_; 1191 1192 DISALLOW_COPY_AND_ASSIGN(WebContentsImpl); 1193}; 1194 1195} // namespace content 1196 1197#endif // CONTENT_BROWSER_WEB_CONTENTS_WEB_CONTENTS_IMPL_H_ 1198