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