| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CONTENT_BROWSER_WEB_CONTENTS_WEB_CONTENTS_IMPL_H_ | 5 #ifndef CONTENT_BROWSER_WEB_CONTENTS_WEB_CONTENTS_IMPL_H_ |
| 6 #define CONTENT_BROWSER_WEB_CONTENTS_WEB_CONTENTS_IMPL_H_ | 6 #define CONTENT_BROWSER_WEB_CONTENTS_WEB_CONTENTS_IMPL_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 #include <string> | 10 #include <string> |
| 11 | 11 |
| 12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 13 #include "base/gtest_prod_util.h" | 13 #include "base/gtest_prod_util.h" |
| 14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/observer_list.h" | 15 #include "base/observer_list.h" |
| 16 #include "base/property_bag.h" | 16 #include "base/property_bag.h" |
| 17 #include "content/browser/browser_plugin/browser_plugin_web_contents_observer.h" | 17 #include "content/browser/browser_plugin/browser_plugin_web_contents_observer.h" |
| 18 #include "content/browser/renderer_host/java/java_bridge_dispatcher_host_manager
.h" | 18 #include "content/browser/renderer_host/java/java_bridge_dispatcher_host_manager
.h" |
| 19 #include "content/browser/web_contents/navigation_controller_impl.h" | 19 #include "content/browser/web_contents/navigation_controller_impl.h" |
| 20 #include "content/browser/web_contents/render_view_host_manager.h" | 20 #include "content/browser/web_contents/render_view_host_manager.h" |
| 21 #include "content/common/content_export.h" | 21 #include "content/common/content_export.h" |
| 22 #include "content/public/browser/notification_observer.h" |
| 23 #include "content/public/browser/notification_registrar.h" |
| 22 #include "content/public/browser/render_view_host_delegate.h" | 24 #include "content/public/browser/render_view_host_delegate.h" |
| 23 #include "content/public/browser/web_contents.h" | 25 #include "content/public/browser/web_contents.h" |
| 24 #include "content/public/common/renderer_preferences.h" | 26 #include "content/public/common/renderer_preferences.h" |
| 25 #include "net/base/load_states.h" | 27 #include "net/base/load_states.h" |
| 26 #include "ui/gfx/size.h" | 28 #include "ui/gfx/size.h" |
| 27 #include "webkit/glue/resource_type.h" | 29 #include "webkit/glue/resource_type.h" |
| 28 | 30 |
| 29 #if defined(OS_WIN) | 31 #if defined(OS_WIN) |
| 30 #include "base/win/scoped_handle.h" | 32 #include "base/win/scoped_handle.h" |
| 31 #endif | 33 #endif |
| (...skipping 17 matching lines...) Expand all Loading... |
| 49 struct LoadNotificationDetails; | 51 struct LoadNotificationDetails; |
| 50 } | 52 } |
| 51 | 53 |
| 52 namespace webkit_glue { | 54 namespace webkit_glue { |
| 53 struct WebIntentData; | 55 struct WebIntentData; |
| 54 } | 56 } |
| 55 | 57 |
| 56 class CONTENT_EXPORT WebContentsImpl | 58 class CONTENT_EXPORT WebContentsImpl |
| 57 : public NON_EXPORTED_BASE(content::WebContents), | 59 : public NON_EXPORTED_BASE(content::WebContents), |
| 58 public content::RenderViewHostDelegate, | 60 public content::RenderViewHostDelegate, |
| 59 public RenderViewHostManager::Delegate { | 61 public RenderViewHostManager::Delegate, |
| 62 public content::NotificationObserver { |
| 60 public: | 63 public: |
| 61 // See WebContents::Create for a description of these parameters. | 64 // See WebContents::Create for a description of these parameters. |
| 62 WebContentsImpl(content::BrowserContext* browser_context, | 65 WebContentsImpl(content::BrowserContext* browser_context, |
| 63 content::SiteInstance* site_instance, | 66 content::SiteInstance* site_instance, |
| 64 int routing_id, | 67 int routing_id, |
| 65 const WebContentsImpl* base_web_contents, | 68 const WebContentsImpl* base_web_contents, |
| 69 WebContentsImpl* opener, |
| 66 SessionStorageNamespaceImpl* session_storage_namespace); | 70 SessionStorageNamespaceImpl* session_storage_namespace); |
| 67 virtual ~WebContentsImpl(); | 71 virtual ~WebContentsImpl(); |
| 68 | 72 |
| 69 // Returns the content specific prefs for the given RVH. | 73 // Returns the content specific prefs for the given RVH. |
| 70 static WebPreferences GetWebkitPrefs( | 74 static WebPreferences GetWebkitPrefs( |
| 71 content::RenderViewHost* rvh, const GURL& url); | 75 content::RenderViewHost* rvh, const GURL& url); |
| 72 | 76 |
| 73 // Returns the SavePackage which manages the page saving job. May be NULL. | 77 // Returns the SavePackage which manages the page saving job. May be NULL. |
| 74 SavePackage* save_package() const { return save_package_.get(); } | 78 SavePackage* save_package() const { return save_package_.get(); } |
| 75 | 79 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 | 114 |
| 111 // Unsets the currently showing interstitial. | 115 // Unsets the currently showing interstitial. |
| 112 void remove_interstitial_page() { | 116 void remove_interstitial_page() { |
| 113 render_manager_.remove_interstitial_page(); | 117 render_manager_.remove_interstitial_page(); |
| 114 } | 118 } |
| 115 | 119 |
| 116 void set_opener_web_ui_type(content::WebUI::TypeID opener_web_ui_type) { | 120 void set_opener_web_ui_type(content::WebUI::TypeID opener_web_ui_type) { |
| 117 opener_web_ui_type_ = opener_web_ui_type; | 121 opener_web_ui_type_ = opener_web_ui_type; |
| 118 } | 122 } |
| 119 | 123 |
| 120 void set_has_opener(bool has_opener) { | |
| 121 has_opener_ = has_opener; | |
| 122 } | |
| 123 | |
| 124 JavaBridgeDispatcherHostManager* java_bridge_dispatcher_host_manager() const { | 124 JavaBridgeDispatcherHostManager* java_bridge_dispatcher_host_manager() const { |
| 125 return java_bridge_dispatcher_host_manager_.get(); | 125 return java_bridge_dispatcher_host_manager_.get(); |
| 126 } | 126 } |
| 127 | 127 |
| 128 content::BrowserPluginWebContentsObserver* | 128 content::BrowserPluginWebContentsObserver* |
| 129 browser_plugin_web_contents_observer() const { | 129 browser_plugin_web_contents_observer() const { |
| 130 return browser_plugin_web_contents_observer_.get(); | 130 return browser_plugin_web_contents_observer_.get(); |
| 131 } | 131 } |
| 132 | 132 |
| 133 // Like GetController from WebContents, but returns the concrete object. | 133 // Like GetController from WebContents, but returns the concrete object. |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 333 virtual void ToggleFullscreenMode(bool enter_fullscreen) OVERRIDE; | 333 virtual void ToggleFullscreenMode(bool enter_fullscreen) OVERRIDE; |
| 334 virtual bool IsFullscreenForCurrentTab() const OVERRIDE; | 334 virtual bool IsFullscreenForCurrentTab() const OVERRIDE; |
| 335 virtual void UpdatePreferredSize(const gfx::Size& pref_size) OVERRIDE; | 335 virtual void UpdatePreferredSize(const gfx::Size& pref_size) OVERRIDE; |
| 336 virtual void ResizeDueToAutoResize(const gfx::Size& new_size) OVERRIDE; | 336 virtual void ResizeDueToAutoResize(const gfx::Size& new_size) OVERRIDE; |
| 337 virtual void RequestToLockMouse(bool user_gesture) OVERRIDE; | 337 virtual void RequestToLockMouse(bool user_gesture) OVERRIDE; |
| 338 virtual void LostMouseLock() OVERRIDE; | 338 virtual void LostMouseLock() OVERRIDE; |
| 339 | 339 |
| 340 // RenderViewHostManager::Delegate ------------------------------------------- | 340 // RenderViewHostManager::Delegate ------------------------------------------- |
| 341 | 341 |
| 342 virtual bool CreateRenderViewForRenderManager( | 342 virtual bool CreateRenderViewForRenderManager( |
| 343 content::RenderViewHost* render_view_host) OVERRIDE; | 343 content::RenderViewHost* render_view_host, int opener_route_id) OVERRIDE; |
| 344 virtual void BeforeUnloadFiredFromRenderManager( | 344 virtual void BeforeUnloadFiredFromRenderManager( |
| 345 bool proceed, | 345 bool proceed, |
| 346 bool* proceed_to_fire_unload) OVERRIDE; | 346 bool* proceed_to_fire_unload) OVERRIDE; |
| 347 virtual void DidStartLoadingFromRenderManager( | 347 virtual void DidStartLoadingFromRenderManager( |
| 348 content::RenderViewHost* render_view_host) OVERRIDE; | 348 content::RenderViewHost* render_view_host) OVERRIDE; |
| 349 virtual void RenderViewGoneFromRenderManager( | 349 virtual void RenderViewGoneFromRenderManager( |
| 350 content::RenderViewHost* render_view_host) OVERRIDE; | 350 content::RenderViewHost* render_view_host) OVERRIDE; |
| 351 virtual void UpdateRenderViewSizeForRenderManager() OVERRIDE; | 351 virtual void UpdateRenderViewSizeForRenderManager() OVERRIDE; |
| 352 virtual void NotifySwappedFromRenderManager() OVERRIDE; | 352 virtual void NotifySwappedFromRenderManager() OVERRIDE; |
| 353 virtual int CreateOpenerRenderViewsForRenderManager( |
| 354 content::SiteInstance* instance) OVERRIDE; |
| 353 virtual NavigationControllerImpl& GetControllerForRenderManager() OVERRIDE; | 355 virtual NavigationControllerImpl& GetControllerForRenderManager() OVERRIDE; |
| 354 virtual WebUIImpl* CreateWebUIForRenderManager(const GURL& url) OVERRIDE; | 356 virtual WebUIImpl* CreateWebUIForRenderManager(const GURL& url) OVERRIDE; |
| 355 virtual content::NavigationEntry* | 357 virtual content::NavigationEntry* |
| 356 GetLastCommittedNavigationEntryForRenderManager() OVERRIDE; | 358 GetLastCommittedNavigationEntryForRenderManager() OVERRIDE; |
| 357 virtual bool FocusLocationBarByDefault() OVERRIDE; | 359 virtual bool FocusLocationBarByDefault() OVERRIDE; |
| 358 virtual void SetFocusToLocationBar(bool select_all) OVERRIDE; | 360 virtual void SetFocusToLocationBar(bool select_all) OVERRIDE; |
| 359 virtual void CreateViewAndSetSizeForRVH( | 361 virtual void CreateViewAndSetSizeForRVH( |
| 360 content::RenderViewHost* rvh) OVERRIDE; | 362 content::RenderViewHost* rvh) OVERRIDE; |
| 361 | 363 |
| 364 // content::NotificationObserver --------------------------------------------- |
| 365 |
| 366 virtual void Observe(int type, |
| 367 const content::NotificationSource& source, |
| 368 const content::NotificationDetails& details) OVERRIDE; |
| 369 |
| 362 protected: | 370 protected: |
| 363 friend class content::WebContentsObserver; | 371 friend class content::WebContentsObserver; |
| 364 | 372 |
| 365 // Add and remove observers for page navigation notifications. Adding or | 373 // Add and remove observers for page navigation notifications. Adding or |
| 366 // removing multiple times has no effect. The order in which notifications | 374 // removing multiple times has no effect. The order in which notifications |
| 367 // are sent to observers is undefined. Clients must be sure to remove the | 375 // are sent to observers is undefined. Clients must be sure to remove the |
| 368 // observer before they go away. | 376 // observer before they go away. |
| 369 void AddObserver(content::WebContentsObserver* observer); | 377 void AddObserver(content::WebContentsObserver* observer); |
| 370 void RemoveObserver(content::WebContentsObserver* observer); | 378 void RemoveObserver(content::WebContentsObserver* observer); |
| 371 | 379 |
| 372 private: | 380 private: |
| 373 friend class NavigationControllerImpl; | 381 friend class NavigationControllerImpl; |
| 374 | 382 |
| 375 FRIEND_TEST_ALL_PREFIXES(WebContentsImplTest, NoJSMessageOnInterstitials); | 383 FRIEND_TEST_ALL_PREFIXES(WebContentsImplTest, NoJSMessageOnInterstitials); |
| 376 FRIEND_TEST_ALL_PREFIXES(WebContentsImplTest, UpdateTitle); | 384 FRIEND_TEST_ALL_PREFIXES(WebContentsImplTest, UpdateTitle); |
| 377 FRIEND_TEST_ALL_PREFIXES(WebContentsImplTest, | 385 FRIEND_TEST_ALL_PREFIXES(WebContentsImplTest, |
| 378 CrossSiteCantPreemptAfterUnload); | 386 CrossSiteCantPreemptAfterUnload); |
| 379 FRIEND_TEST_ALL_PREFIXES(FormStructureBrowserTest, HTMLFiles); | 387 FRIEND_TEST_ALL_PREFIXES(FormStructureBrowserTest, HTMLFiles); |
| 380 FRIEND_TEST_ALL_PREFIXES(NavigationControllerTest, HistoryNavigate); | 388 FRIEND_TEST_ALL_PREFIXES(NavigationControllerTest, HistoryNavigate); |
| 381 FRIEND_TEST_ALL_PREFIXES(RenderViewHostManagerTest, PageDoesBackAndReload); | 389 FRIEND_TEST_ALL_PREFIXES(RenderViewHostManagerTest, PageDoesBackAndReload); |
| 382 | 390 |
| 383 // So InterstitialPageImpl can access SetIsLoading. | 391 // So InterstitialPageImpl can access SetIsLoading. |
| 384 friend class InterstitialPageImpl; | 392 friend class InterstitialPageImpl; |
| 385 | 393 |
| 386 // TODO(brettw) TestWebContents shouldn't exist! | 394 // TODO(brettw) TestWebContents shouldn't exist! |
| 387 friend class content::TestWebContents; | 395 friend class content::TestWebContents; |
| 388 | 396 |
| 397 // Clears this tab's opener if it has been closed. |
| 398 void OnWebContentsDestroyed(content::WebContents* web_contents); |
| 399 |
| 389 // Callback function when showing JS dialogs. | 400 // Callback function when showing JS dialogs. |
| 390 void OnDialogClosed(content::RenderViewHost* rvh, | 401 void OnDialogClosed(content::RenderViewHost* rvh, |
| 391 IPC::Message* reply_msg, | 402 IPC::Message* reply_msg, |
| 392 bool success, | 403 bool success, |
| 393 const string16& user_input); | 404 const string16& user_input); |
| 394 | 405 |
| 395 // IPC message handlers. | 406 // IPC message handlers. |
| 396 void OnRegisterIntentService(const string16& action, | 407 void OnRegisterIntentService(const string16& action, |
| 397 const string16& type, | 408 const string16& type, |
| 398 const string16& href, | 409 const string16& href, |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 505 | 516 |
| 506 // Sets the history for this WebContentsImpl to |history_length| entries, and | 517 // Sets the history for this WebContentsImpl to |history_length| entries, and |
| 507 // moves the current page_id to the last entry in the list if it's valid. | 518 // moves the current page_id to the last entry in the list if it's valid. |
| 508 // This is mainly used when a prerendered page is swapped into the current | 519 // This is mainly used when a prerendered page is swapped into the current |
| 509 // tab. The method is virtual for testing. | 520 // tab. The method is virtual for testing. |
| 510 virtual void SetHistoryLengthAndPrune( | 521 virtual void SetHistoryLengthAndPrune( |
| 511 const content::SiteInstance* site_instance, | 522 const content::SiteInstance* site_instance, |
| 512 int merge_history_length, | 523 int merge_history_length, |
| 513 int32 minimum_page_id); | 524 int32 minimum_page_id); |
| 514 | 525 |
| 526 // Recursively creates swapped out RenderViews for this tab's opener chain |
| 527 // (including this tab) in the given SiteInstance, allowing other tabs to send |
| 528 // cross-process JavaScript calls to their opener(s). Returns the route ID of |
| 529 // this tab's RenderView for |instance|. |
| 530 int CreateOpenerRenderViews(content::SiteInstance* instance); |
| 531 |
| 515 // Misc non-view stuff ------------------------------------------------------- | 532 // Misc non-view stuff ------------------------------------------------------- |
| 516 | 533 |
| 517 // Helper functions for sending notifications. | 534 // Helper functions for sending notifications. |
| 518 void NotifySwapped(); | 535 void NotifySwapped(); |
| 519 void NotifyConnected(); | 536 void NotifyConnected(); |
| 520 void NotifyDisconnected(); | 537 void NotifyDisconnected(); |
| 521 | 538 |
| 522 void SetEncoding(const std::string& encoding); | 539 void SetEncoding(const std::string& encoding); |
| 523 | 540 |
| 524 // Save a URL to the local filesystem. | 541 // Save a URL to the local filesystem. |
| 525 void SaveURL(const GURL& url, const GURL& referrer, bool is_main_frame); | 542 void SaveURL(const GURL& url, const GURL& referrer, bool is_main_frame); |
| 526 | 543 |
| 527 content::RenderViewHostImpl* GetRenderViewHostImpl(); | 544 content::RenderViewHostImpl* GetRenderViewHostImpl(); |
| 528 | 545 |
| 529 // Stores random bits of data for others to associate with this object. | 546 // Stores random bits of data for others to associate with this object. |
| 530 // WARNING: this needs to be deleted after NavigationController. | 547 // WARNING: this needs to be deleted after NavigationController. |
| 531 base::PropertyBag property_bag_; | 548 base::PropertyBag property_bag_; |
| 532 | 549 |
| 550 // Listen for notifications as well. |
| 551 content::NotificationRegistrar registrar_; |
| 552 |
| 533 // Data for core operation --------------------------------------------------- | 553 // Data for core operation --------------------------------------------------- |
| 534 | 554 |
| 535 // Delegate for notifying our owner about stuff. Not owned by us. | 555 // Delegate for notifying our owner about stuff. Not owned by us. |
| 536 content::WebContentsDelegate* delegate_; | 556 content::WebContentsDelegate* delegate_; |
| 537 | 557 |
| 538 // Handles the back/forward list and loading. | 558 // Handles the back/forward list and loading. |
| 539 NavigationControllerImpl controller_; | 559 NavigationControllerImpl controller_; |
| 540 | 560 |
| 541 // The corresponding view. | 561 // The corresponding view. |
| 542 scoped_ptr<content::WebContentsView> view_; | 562 scoped_ptr<content::WebContentsView> view_; |
| 543 | 563 |
| 544 // A list of observers notified when page state changes. Weak references. | 564 // A list of observers notified when page state changes. Weak references. |
| 545 // This MUST be listed above render_manager_ since at destruction time the | 565 // This MUST be listed above render_manager_ since at destruction time the |
| 546 // latter might cause RenderViewHost's destructor to call us and we might use | 566 // latter might cause RenderViewHost's destructor to call us and we might use |
| 547 // the observer list then. | 567 // the observer list then. |
| 548 ObserverList<content::WebContentsObserver> observers_; | 568 ObserverList<content::WebContentsObserver> observers_; |
| 549 | 569 |
| 570 // The tab that opened this tab, if any. Will be set to null if the opener |
| 571 // is closed. |
| 572 WebContentsImpl* opener_; |
| 573 |
| 550 // Helper classes ------------------------------------------------------------ | 574 // Helper classes ------------------------------------------------------------ |
| 551 | 575 |
| 552 // Manages creation and swapping of render views. | 576 // Manages creation and swapping of render views. |
| 553 RenderViewHostManager render_manager_; | 577 RenderViewHostManager render_manager_; |
| 554 | 578 |
| 555 // Manages injecting Java objects into all RenderViewHosts associated with | 579 // Manages injecting Java objects into all RenderViewHosts associated with |
| 556 // this WebContentsImpl. | 580 // this WebContentsImpl. |
| 557 scoped_ptr<JavaBridgeDispatcherHostManager> | 581 scoped_ptr<JavaBridgeDispatcherHostManager> |
| 558 java_bridge_dispatcher_host_manager_; | 582 java_bridge_dispatcher_host_manager_; |
| 559 | 583 |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 667 // The intrinsic size of the page. | 691 // The intrinsic size of the page. |
| 668 gfx::Size preferred_size_; | 692 gfx::Size preferred_size_; |
| 669 | 693 |
| 670 // Content restrictions, used to disable print/copy etc based on content's | 694 // Content restrictions, used to disable print/copy etc based on content's |
| 671 // (full-page plugins for now only) permissions. | 695 // (full-page plugins for now only) permissions. |
| 672 int content_restrictions_; | 696 int content_restrictions_; |
| 673 | 697 |
| 674 // Our view type. Default is VIEW_TYPE_WEB_CONTENTS. | 698 // Our view type. Default is VIEW_TYPE_WEB_CONTENTS. |
| 675 content::ViewType view_type_; | 699 content::ViewType view_type_; |
| 676 | 700 |
| 677 // Is there an opener associated with this? | |
| 678 bool has_opener_; | |
| 679 | |
| 680 // Color chooser that was opened by this tab. | 701 // Color chooser that was opened by this tab. |
| 681 content::ColorChooser* color_chooser_; | 702 content::ColorChooser* color_chooser_; |
| 682 | 703 |
| 683 DISALLOW_COPY_AND_ASSIGN(WebContentsImpl); | 704 DISALLOW_COPY_AND_ASSIGN(WebContentsImpl); |
| 684 }; | 705 }; |
| 685 | 706 |
| 686 #endif // CONTENT_BROWSER_WEB_CONTENTS_WEB_CONTENTS_IMPL_H_ | 707 #endif // CONTENT_BROWSER_WEB_CONTENTS_WEB_CONTENTS_IMPL_H_ |
| OLD | NEW |