diff options
71 files changed, 4554 insertions, 4216 deletions
@@ -309,6 +309,7 @@ skip_child_includes = [ "gears", "native_client", "o3d", + "pdf", "sdch", "skia", "testing", diff --git a/chrome/DEPS b/chrome/DEPS index 752b1c60..a64c1c0 100644 --- a/chrome/DEPS +++ b/chrome/DEPS @@ -1,5 +1,6 @@ include_rules = [ "+app", + "+content", "+gpu", "+net", "+printing", diff --git a/chrome/browser/prefs/browser_prefs.cc b/chrome/browser/prefs/browser_prefs.cc index a4f2f26..c29c2d1 100644 --- a/chrome/browser/prefs/browser_prefs.cc +++ b/chrome/browser/prefs/browser_prefs.cc @@ -46,11 +46,11 @@ #include "chrome/browser/search_engines/template_url_prepopulate_data.h" #include "chrome/browser/ssl/ssl_manager.h" #include "chrome/browser/sync/signin_manager.h" -#include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/browser/tabs/pinned_tab_codec.h" #include "chrome/browser/task_manager/task_manager.h" #include "chrome/browser/translate/translate_prefs.h" #include "chrome/browser/ui/browser.h" +#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" #include "chrome/browser/upgrade_detector.h" #include "chrome/browser/webui/flags_ui.h" #include "chrome/common/pref_names.h" @@ -124,7 +124,7 @@ void RegisterUserPrefs(PrefService* user_prefs) { chrome_browser_net::RegisterUserPrefs(user_prefs); DownloadPrefs::RegisterUserPrefs(user_prefs); bookmark_utils::RegisterUserPrefs(user_prefs); - TabContents::RegisterUserPrefs(user_prefs); + TabContentsWrapper::RegisterUserPrefs(user_prefs); TemplateURLPrepopulateData::RegisterUserPrefs(user_prefs); ExtensionWebUI::RegisterUserPrefs(user_prefs); ExtensionsUI::RegisterUserPrefs(user_prefs); diff --git a/chrome/browser/renderer_host/render_view_host.cc b/chrome/browser/renderer_host/render_view_host.cc index 88c4746..9c96e6f 100644 --- a/chrome/browser/renderer_host/render_view_host.cc +++ b/chrome/browser/renderer_host/render_view_host.cc @@ -792,8 +792,6 @@ bool RenderViewHost::OnMessageReceived(const IPC::Message& msg) { OnRequestUndockDevToolsWindow) IPC_MESSAGE_HANDLER(ViewHostMsg_DevToolsRuntimePropertyChanged, OnDevToolsRuntimePropertyChanged) - IPC_MESSAGE_FORWARD(ViewHostMsg_JSOutOfMemory, delegate_, - RenderViewHostDelegate::OnJSOutOfMemory) IPC_MESSAGE_HANDLER(ViewHostMsg_ShouldClose_ACK, OnMsgShouldCloseACK) IPC_MESSAGE_HANDLER(ViewHostMsg_ExtensionRequest, OnExtensionRequest) IPC_MESSAGE_HANDLER(ViewHostMsg_SelectionChanged, OnMsgSelectionChanged) diff --git a/chrome/browser/renderer_host/render_view_host_delegate.h b/chrome/browser/renderer_host/render_view_host_delegate.h index 123b2b8c..b98e7ea 100644 --- a/chrome/browser/renderer_host/render_view_host_delegate.h +++ b/chrome/browser/renderer_host/render_view_host_delegate.h @@ -546,9 +546,6 @@ class RenderViewHostDelegate : public IPC::Channel::Listener { // refocus on the modal dialog, flash title etc). virtual void OnIgnoredUIEvent() {} - // Notification from the renderer that JS runs out of memory. - virtual void OnJSOutOfMemory() {} - // Notification that the renderer has become unresponsive. The // delegate can use this notification to show a warning to the user. virtual void RendererUnresponsive(RenderViewHost* render_view_host, diff --git a/chrome/browser/tab_contents/background_contents.h b/chrome/browser/tab_contents/background_contents.h index 11aa3e2..ea0d6ab 100644 --- a/chrome/browser/tab_contents/background_contents.h +++ b/chrome/browser/tab_contents/background_contents.h @@ -6,181 +6,7 @@ #define CHROME_BROWSER_TAB_CONTENTS_BACKGROUND_CONTENTS_H_ #pragma once -#include <string> -#include <vector> - -#include "chrome/browser/renderer_host/render_view_host_delegate.h" -#include "chrome/browser/tab_contents/render_view_host_delegate_helper.h" -#include "chrome/browser/ui/app_modal_dialogs/js_modal_dialog.h" -#include "chrome/common/notification_registrar.h" -#include "chrome/common/view_types.h" -#include "chrome/common/window_container_type.h" -#include "webkit/glue/window_open_disposition.h" - -class TabContents; -struct WebPreferences; -class DesktopNotificationHandler; - -namespace gfx { -class Rect; -} - -// This class is a peer of TabContents. It can host a renderer, but does not -// have any visible display. Its navigation is not managed by a -// NavigationController because is has no facility for navigating (other than -// programatically view window.location.href) or RenderViewHostManager because -// it is never allowed to navigate across a SiteInstance boundary. -class BackgroundContents : public RenderViewHostDelegate, - public RenderViewHostDelegate::View, - public NotificationObserver, - public JavaScriptAppModalDialogDelegate { - public: - class Delegate { - public: - // Called by ShowCreatedWindow. Asks the delegate to attach the opened - // TabContents to a suitable container (e.g. browser) or to show it if it's - // a popup window. - virtual void AddTabContents(TabContents* new_contents, - WindowOpenDisposition disposition, - const gfx::Rect& initial_pos, - bool user_gesture) = 0; - - protected: - virtual ~Delegate() {} - }; - - BackgroundContents(SiteInstance* site_instance, - int routing_id, - Delegate* delegate); - virtual ~BackgroundContents(); - - // Provide access to the RenderViewHost for the - // RenderViewHostDelegateViewHelper - RenderViewHost* render_view_host() { return render_view_host_; } - - // RenderViewHostDelegate implementation. - virtual BackgroundContents* GetAsBackgroundContents(); - virtual RenderViewHostDelegate::View* GetViewDelegate(); - virtual const GURL& GetURL() const; - virtual ViewType::Type GetRenderViewType() const; - virtual int GetBrowserWindowID() const; - virtual void DidNavigate(RenderViewHost* render_view_host, - const ViewHostMsg_FrameNavigate_Params& params); - virtual WebPreferences GetWebkitPrefs(); - virtual void ProcessWebUIMessage(const ViewHostMsg_DomMessage_Params& params); - virtual void RunJavaScriptMessage(const std::wstring& message, - const std::wstring& default_prompt, - const GURL& frame_url, - const int flags, - IPC::Message* reply_msg, - bool* did_suppress_message); - virtual void Close(RenderViewHost* render_view_host); - virtual RendererPreferences GetRendererPrefs(Profile* profile) const; - virtual void RenderViewGone(RenderViewHost* rvh, - base::TerminationStatus status, - int error_code); - virtual bool OnMessageReceived(const IPC::Message& message); - - // RenderViewHostDelegate::View - virtual void CreateNewWindow( - int route_id, - const ViewHostMsg_CreateWindow_Params& params); - virtual void CreateNewWidget(int route_id, WebKit::WebPopupType popup_type); - virtual void CreateNewFullscreenWidget(int route_id); - virtual void ShowCreatedWindow(int route_id, - WindowOpenDisposition disposition, - const gfx::Rect& initial_pos, - bool user_gesture); - virtual void ShowCreatedWidget(int route_id, - const gfx::Rect& initial_pos); - virtual void ShowCreatedFullscreenWidget(int route_id); - virtual void ShowContextMenu(const ContextMenuParams& params) {} - virtual void ShowPopupMenu(const gfx::Rect& bounds, - int item_height, - double item_font_size, - int selected_item, - const std::vector<WebMenuItem>& items, - bool right_aligned) {} - virtual void StartDragging(const WebDropData& drop_data, - WebKit::WebDragOperationsMask allowed_operations, - const SkBitmap& image, - const gfx::Point& image_offset) {} - virtual void UpdateDragCursor(WebKit::WebDragOperation operation) {} - virtual void GotFocus() {} - virtual void TakeFocus(bool reverse) {} - virtual void LostCapture() {} - virtual void Activate() {} - virtual void Deactivate() {} - virtual bool PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event, - bool* is_keyboard_shortcut); - virtual void HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {} - virtual void HandleMouseMove() {} - virtual void HandleMouseDown() {} - virtual void HandleMouseLeave() {} - virtual void HandleMouseUp() {} - virtual void HandleMouseActivate() {} - virtual void UpdatePreferredSize(const gfx::Size& new_size) {} - - // NotificationObserver - virtual void Observe(NotificationType type, - const NotificationSource& source, - const NotificationDetails& details); - - // Overridden from JavaScriptAppModalDialogDelegate: - virtual void OnMessageBoxClosed(IPC::Message* reply_msg, - bool success, - const std::wstring& prompt); - virtual void SetSuppressMessageBoxes(bool suppress_message_boxes) {} - virtual gfx::NativeWindow GetMessageBoxRootWindow(); - virtual TabContents* AsTabContents(); - virtual ExtensionHost* AsExtensionHost(); - - virtual void UpdateInspectorSetting(const std::string& key, - const std::string& value); - virtual void ClearInspectorSettings(); - - // Helper to find the BackgroundContents that originated the given request. - // Can be NULL if the page has been closed or some other error occurs. - // Should only be called from the UI thread, since it accesses - // BackgroundContents. - static BackgroundContents* GetBackgroundContentsByID(int render_process_id, - int render_view_id); - - protected: - // Exposed for testing. - BackgroundContents(); - - private: - // The delegate for this BackgroundContents. - Delegate* delegate_; - - // The host for our HTML content. - RenderViewHost* render_view_host_; - - // Common implementations of some RenderViewHostDelegate::View methods. - RenderViewHostDelegateViewHelper delegate_view_helper_; - - // The URL being hosted. - GURL url_; - - NotificationRegistrar registrar_; - - // Handles desktop notification IPCs. - scoped_ptr<DesktopNotificationHandler> desktop_notification_handler_; - - DISALLOW_COPY_AND_ASSIGN(BackgroundContents); -}; - -// This is the data sent out as the details with BACKGROUND_CONTENTS_OPENED. -struct BackgroundContentsOpenedDetails { - // The BackgroundContents object that has just been opened. - BackgroundContents* contents; - - // The name of the parent frame for these contents. - const string16& frame_name; - - // The ID of the parent application (if any). - const string16& application_id; -}; +// TODO(jam): remove this file when all files have been converted. +#include "content/browser/tab_contents/background_contents.h" #endif // CHROME_BROWSER_TAB_CONTENTS_BACKGROUND_CONTENTS_H_ diff --git a/chrome/browser/tab_contents/constrained_window.h b/chrome/browser/tab_contents/constrained_window.h index 2143e99..b20a60e 100644 --- a/chrome/browser/tab_contents/constrained_window.h +++ b/chrome/browser/tab_contents/constrained_window.h @@ -6,57 +6,7 @@ #define CHROME_BROWSER_TAB_CONTENTS_CONSTRAINED_WINDOW_H_ #pragma once -#include "build/build_config.h" - -// The different platform specific subclasses use different delegates for their -// dialogs. -#if defined(OS_WIN) -namespace views { -class WindowDelegate; -class DialogDelegate; -} -typedef views::WindowDelegate ConstrainedWindowDelegate; -typedef views::DialogDelegate ConstrainedDialogDelegate; -#elif defined(OS_MACOSX) -class ConstrainedWindowMacDelegate; -class ConstrainedWindowMacDelegateSystemSheet; -typedef ConstrainedWindowMacDelegate ConstrainedWindowDelegate; -typedef ConstrainedWindowMacDelegateSystemSheet ConstrainedDialogDelegate; -#elif defined(TOOLKIT_USES_GTK) -class ConstrainedWindowGtkDelegate; -typedef ConstrainedWindowGtkDelegate ConstrainedWindowDelegate; -typedef ConstrainedWindowGtkDelegate ConstrainedDialogDelegate; -#endif - -class TabContents; - -/////////////////////////////////////////////////////////////////////////////// -// ConstrainedWindow -// -// This interface represents a window that is constrained to a TabContents' -// bounds. -// -class ConstrainedWindow { - public: - // Create a Constrained Window that contains a platform specific client - // area. Typical uses include the HTTP Basic Auth prompt. The caller must - // provide a delegate to describe the content area and to respond to events. - static ConstrainedWindow* CreateConstrainedDialog( - TabContents* owner, - ConstrainedWindowDelegate* delegate); - - // Makes the Constrained Window visible. Only one Constrained Window is shown - // at a time per tab. - virtual void ShowConstrainedWindow() = 0; - - // Closes the Constrained Window. - virtual void CloseConstrainedWindow() = 0; - - // Sets focus on the Constrained Window. - virtual void FocusConstrainedWindow() {} - - protected: - virtual ~ConstrainedWindow() {} -}; +// TODO(jam): remove this file when all files have been converted. +#include "content/browser/tab_contents/constrained_window.h" #endif // CHROME_BROWSER_TAB_CONTENTS_CONSTRAINED_WINDOW_H_ diff --git a/chrome/browser/tab_contents/infobar_delegate.cc b/chrome/browser/tab_contents/infobar_delegate.cc index b6115d1..8b9ed7e 100644 --- a/chrome/browser/tab_contents/infobar_delegate.cc +++ b/chrome/browser/tab_contents/infobar_delegate.cc @@ -12,79 +12,6 @@ #include "grit/generated_resources.h" #include "ui/base/l10n/l10n_util.h" -// InfoBarDelegate ------------------------------------------------------------ - -InfoBarDelegate::~InfoBarDelegate() { -} - -bool InfoBarDelegate::EqualsDelegate(InfoBarDelegate* delegate) const { - return false; -} - -bool InfoBarDelegate::ShouldExpire( - const NavigationController::LoadCommittedDetails& details) const { - return (contents_unique_id_ != details.entry->unique_id()) || - (PageTransition::StripQualifier(details.entry->transition_type()) == - PageTransition::RELOAD); -} - -void InfoBarDelegate::InfoBarDismissed() { -} - -void InfoBarDelegate::InfoBarClosed() { -} - -SkBitmap* InfoBarDelegate::GetIcon() const { - return NULL; -} - -InfoBarDelegate::Type InfoBarDelegate::GetInfoBarType() const { - return WARNING_TYPE; -} - -ConfirmInfoBarDelegate* InfoBarDelegate::AsConfirmInfoBarDelegate() { - return NULL; -} - -CrashedExtensionInfoBarDelegate* - InfoBarDelegate::AsCrashedExtensionInfoBarDelegate() { - return NULL; -} - -ExtensionInfoBarDelegate* InfoBarDelegate::AsExtensionInfoBarDelegate() { - return NULL; -} - -LinkInfoBarDelegate* InfoBarDelegate::AsLinkInfoBarDelegate() { - return NULL; -} - -PluginInstallerInfoBarDelegate* - InfoBarDelegate::AsPluginInstallerInfoBarDelegate() { - return NULL; -} - -ThemeInstalledInfoBarDelegate* - InfoBarDelegate::AsThemePreviewInfobarDelegate() { - return NULL; -} - -TranslateInfoBarDelegate* InfoBarDelegate::AsTranslateInfoBarDelegate() { - return NULL; -} - -InfoBarDelegate::InfoBarDelegate(TabContents* contents) - : contents_unique_id_(0) { - if (contents) - StoreActiveEntryUniqueID(contents); -} - -void InfoBarDelegate::StoreActiveEntryUniqueID(TabContents* contents) { - NavigationEntry* active_entry = contents->controller().GetActiveEntry(); - contents_unique_id_ = active_entry ? active_entry->unique_id() : 0; -} - - // LinkInfoBarDelegate -------------------------------------------------------- string16 LinkInfoBarDelegate::GetMessageTextWithOffset( diff --git a/chrome/browser/tab_contents/infobar_delegate.h b/chrome/browser/tab_contents/infobar_delegate.h index 04b58b2..2408ec3 100644 --- a/chrome/browser/tab_contents/infobar_delegate.h +++ b/chrome/browser/tab_contents/infobar_delegate.h @@ -6,114 +6,7 @@ #define CHROME_BROWSER_TAB_CONTENTS_INFOBAR_DELEGATE_H_ #pragma once -#include "base/basictypes.h" -#include "base/string16.h" -#include "chrome/browser/tab_contents/navigation_controller.h" -#include "webkit/glue/window_open_disposition.h" - -class ConfirmInfoBarDelegate; -class CrashedExtensionInfoBarDelegate; -class ExtensionInfoBarDelegate; -class InfoBar; -class LinkInfoBarDelegate; -class PluginInstallerInfoBarDelegate; -class SkBitmap; -class ThemeInstalledInfoBarDelegate; -class TranslateInfoBarDelegate; - -// An interface implemented by objects wishing to control an InfoBar. -// Implementing this interface is not sufficient to use an InfoBar, since it -// does not map to a specific InfoBar type. Instead, you must implement either -// LinkInfoBarDelegate or ConfirmInfoBarDelegate, or override with your own -// delegate for your own InfoBar variety. -// -// --- WARNING --- -// When creating your InfoBarDelegate subclass, it is recommended that you -// design it such that you instantiate a brand new delegate for every call to -// AddInfoBar, rather than re-using/sharing a delegate object. Otherwise, -// you need to consider the fact that more than one InfoBar instance can exist -// and reference the same delegate -- even though it is also true that we only -// ever fully show one infobar (they don't stack). The dual-references occur -// because a second InfoBar can be added while the first one is in the process -// of closing (the animations). This can cause problems because when the first -// one does finally fully close InfoBarDelegate::InfoBarClosed() is called, -// and the delegate is free to clean itself up or reset state, which may have -// fatal consequences for the InfoBar that was in the process of opening (or is -// now fully opened) -- it is referencing a delegate that may not even exist -// anymore. -// As such, it is generally much safer to dedicate a delegate instance to -// AddInfoBar! -class InfoBarDelegate { - public: - // The type of the infobar. It controls its appearance, such as its background - // color. - enum Type { - WARNING_TYPE, - PAGE_ACTION_TYPE, - }; - - virtual ~InfoBarDelegate(); - - // Called to create the InfoBar. Implementation of this method is - // platform-specific. - virtual InfoBar* CreateInfoBar() = 0; - - // Returns true if the supplied |delegate| is equal to this one. Equality is - // left to the implementation to define. This function is called by the - // TabContents when determining whether or not a delegate should be added - // because a matching one already exists. If this function returns true, the - // TabContents will not add the new delegate because it considers one to - // already be present. - virtual bool EqualsDelegate(InfoBarDelegate* delegate) const; - - // Returns true if the InfoBar should be closed automatically after the page - // is navigated. The default behavior is to return true if the page is - // navigated somewhere else or reloaded. - virtual bool ShouldExpire( - const NavigationController::LoadCommittedDetails& details) const; - - // Called when the user clicks on the close button to dismiss the infobar. - virtual void InfoBarDismissed(); - - // Called after the InfoBar is closed. The delegate is free to delete itself - // at this point. - virtual void InfoBarClosed(); - - // Return the icon to be shown for this InfoBar. If the returned bitmap is - // NULL, no icon is shown. - virtual SkBitmap* GetIcon() const; - - // Returns the type of the infobar. The type determines the appearance (such - // as background color) of the infobar. - virtual Type GetInfoBarType() const; - - // Type-checking downcast routines: - virtual ConfirmInfoBarDelegate* AsConfirmInfoBarDelegate(); - virtual CrashedExtensionInfoBarDelegate* AsCrashedExtensionInfoBarDelegate(); - virtual ExtensionInfoBarDelegate* AsExtensionInfoBarDelegate(); - virtual LinkInfoBarDelegate* AsLinkInfoBarDelegate(); - virtual PluginInstallerInfoBarDelegate* AsPluginInstallerInfoBarDelegate(); - virtual ThemeInstalledInfoBarDelegate* AsThemePreviewInfobarDelegate(); - virtual TranslateInfoBarDelegate* AsTranslateInfoBarDelegate(); - - protected: - // Provided to subclasses as a convenience to initialize the state of this - // object. If |contents| is non-NULL, its active entry's unique ID will be - // stored using StoreActiveEntryUniqueID automatically. - explicit InfoBarDelegate(TabContents* contents); - - // Store the unique id for the active entry in the specified TabContents, to - // be used later upon navigation to determine if this InfoBarDelegate should - // be expired from |contents_|. - void StoreActiveEntryUniqueID(TabContents* contents); - - private: - // The unique id of the active NavigationEntry of the TabContents that we were - // opened for. Used to help expire on navigations. - int contents_unique_id_; - - DISALLOW_COPY_AND_ASSIGN(InfoBarDelegate); -}; +#include "content/browser/tab_contents/infobar_delegate.h" // An interface derived from InfoBarDelegate implemented by objects wishing to // control a LinkInfoBar. diff --git a/chrome/browser/tab_contents/interstitial_page.h b/chrome/browser/tab_contents/interstitial_page.h index f7d1edd..6a1ddb9 100644 --- a/chrome/browser/tab_contents/interstitial_page.h +++ b/chrome/browser/tab_contents/interstitial_page.h @@ -6,240 +6,7 @@ #define CHROME_BROWSER_TAB_CONTENTS_INTERSTITIAL_PAGE_H_ #pragma once -#include <map> -#include <string> - -#include "base/process_util.h" -#include "base/scoped_ptr.h" -#include "chrome/browser/renderer_host/render_view_host_delegate.h" -#include "chrome/common/notification_observer.h" -#include "chrome/common/notification_registrar.h" -#include "chrome/common/renderer_preferences.h" -#include "googleurl/src/gurl.h" -#include "ui/gfx/size.h" - -class NavigationEntry; -class TabContents; -class TabContentsView; - -// This class is a base class for interstitial pages, pages that show some -// informative message asking for user validation before reaching the target -// page. (Navigating to a page served over bad HTTPS or a page containing -// malware are typical cases where an interstitial is required.) -// -// If specified in its constructor, this class creates a navigation entry so -// that when the interstitial shows, the current entry is the target URL. -// -// InterstitialPage instances take care of deleting themselves when closed -// through a navigation, the TabContents closing them or the tab containing them -// being closed. - -enum ResourceRequestAction { - BLOCK, - RESUME, - CANCEL -}; - -class InterstitialPage : public NotificationObserver, - public RenderViewHostDelegate { - public: - // The different state of actions the user can take in an interstitial. - enum ActionState { - NO_ACTION, // No action has been taken yet. - PROCEED_ACTION, // "Proceed" was selected. - DONT_PROCEED_ACTION // "Don't proceed" was selected. - }; - - // Creates an interstitial page to show in |tab|. |new_navigation| should be - // set to true when the interstitial is caused by loading a new page, in which - // case a temporary navigation entry is created with the URL |url| and - // added to the navigation controller (so the interstitial page appears as a - // new navigation entry). |new_navigation| should be false when the - // interstitial was triggered by a loading a sub-resource in a page. - InterstitialPage(TabContents* tab, bool new_navigation, const GURL& url); - virtual ~InterstitialPage(); - - // Shows the interstitial page in the tab. - virtual void Show(); - - // Hides the interstitial page. Warning: this deletes the InterstitialPage. - void Hide(); - - // Retrieves the InterstitialPage if any associated with the specified - // |tab_contents| (used by ui tests). - static InterstitialPage* GetInterstitialPage(TabContents* tab_contents); - - // Sub-classes should return the HTML that should be displayed in the page. - virtual std::string GetHTMLContents(); - - // Reverts to the page showing before the interstitial. - // Sub-classes should call this method when the user has chosen NOT to proceed - // to the target URL. - // Warning: if |new_navigation| was set to true in the constructor, 'this' - // will be deleted when this method returns. - virtual void DontProceed(); - - // Sub-classes should call this method when the user has chosen to proceed to - // the target URL. - // Warning: 'this' has been deleted when this method returns. - virtual void Proceed(); - - // Allows the user to navigate away by disabling the interstitial, canceling - // the pending request, and unblocking the hidden renderer. The interstitial - // will stay visible until the navigation completes. - void CancelForNavigation(); - - // Sizes the RenderViewHost showing the actual interstitial page contents. - void SetSize(const gfx::Size& size); - - ActionState action_taken() const { return action_taken_; } - - // Sets the focus to the interstitial. - void Focus(); - - // Focus the first (last if reverse is true) element in the interstitial page. - // Called when tab traversing. - void FocusThroughTabTraversal(bool reverse); - - virtual ViewType::Type GetRenderViewType() const; - virtual int GetBrowserWindowID() const; - - // See description above field. - void set_reload_on_dont_proceed(bool value) { - reload_on_dont_proceed_ = value; - } - bool reload_on_dont_proceed() const { return reload_on_dont_proceed_; } - - virtual void UpdateInspectorSetting(const std::string& key, - const std::string& value); - virtual void ClearInspectorSettings(); - - protected: - // NotificationObserver method: - virtual void Observe(NotificationType type, - const NotificationSource& source, - const NotificationDetails& details); - - // RenderViewHostDelegate implementation: - virtual View* GetViewDelegate(); - virtual const GURL& GetURL() const; - virtual void RenderViewGone(RenderViewHost* render_view_host, - base::TerminationStatus status, - int error_code); - virtual void DidNavigate(RenderViewHost* render_view_host, - const ViewHostMsg_FrameNavigate_Params& params); - virtual void UpdateTitle(RenderViewHost* render_view_host, - int32 page_id, - const std::wstring& title); - virtual void DomOperationResponse(const std::string& json_string, - int automation_id); - virtual RendererPreferences GetRendererPrefs(Profile* profile) const; - - // Invoked when the page sent a command through DOMAutomation. - virtual void CommandReceived(const std::string& command) {} - - // Invoked with the NavigationEntry that is going to be added to the - // navigation controller. - // Gives an opportunity to sub-classes to set states on the |entry|. - // Note that this is only called if the InterstitialPage was constructed with - // |create_navigation_entry| set to true. - virtual void UpdateEntry(NavigationEntry* entry) {} - - TabContents* tab() const { return tab_; } - const GURL& url() const { return url_; } - RenderViewHost* render_view_host() const { return render_view_host_; } - - // Creates the RenderViewHost containing the interstitial content. - // Overriden in unit tests. - virtual RenderViewHost* CreateRenderViewHost(); - - // Creates the TabContentsView that shows the interstitial RVH. - // Overriden in unit tests. - virtual TabContentsView* CreateTabContentsView(); - - private: - // AutomationProvider needs access to Proceed and DontProceed to simulate - // user actions. - friend class AutomationProvider; - - class InterstitialPageRVHViewDelegate; - - // Initializes tab_to_interstitial_page_ in a thread-safe manner. - // Should be called before accessing tab_to_interstitial_page_. - static void InitInterstitialPageMap(); - - // Disable the interstitial: - // - if it is not yet showing, then it won't be shown. - // - any command sent by the RenderViewHost will be ignored. - void Disable(); - - // Executes the passed action on the ResourceDispatcher (on the IO thread). - // Used to block/resume/cancel requests for the RenderViewHost hidden by this - // interstitial. - void TakeActionOnResourceDispatcher(ResourceRequestAction action); - - // The tab in which we are displayed. - TabContents* tab_; - - // The URL that is shown when the interstitial is showing. - GURL url_; - - // Whether this interstitial is shown as a result of a new navigation (in - // which case a transient navigation entry is created). - bool new_navigation_; - - // Whether we should discard the pending navigation entry when not proceeding. - // This is to deal with cases where |new_navigation_| is true but a new - // pending entry was created since this interstitial was shown and we should - // not discard it. - bool should_discard_pending_nav_entry_; - - // If true and the user chooses not to proceed the target NavigationController - // is reloaded. This is used when two NavigationControllers are merged - // (CopyStateFromAndPrune). - // The default is false. - bool reload_on_dont_proceed_; - - // Whether this interstitial is enabled. See Disable() for more info. - bool enabled_; - - // Whether the Proceed or DontProceed methods have been called yet. - ActionState action_taken_; - - // Notification magic. - NotificationRegistrar notification_registrar_; - - // The RenderViewHost displaying the interstitial contents. - RenderViewHost* render_view_host_; - - // The IDs for the Render[View|Process]Host hidden by this interstitial. - int original_child_id_; - int original_rvh_id_; - - // Whether or not we should change the title of the tab when hidden (to revert - // it to its original value). - bool should_revert_tab_title_; - - // Whether the ResourceDispatcherHost has been notified to cancel/resume the - // resource requests blocked for the RenderViewHost. - bool resource_dispatcher_host_notified_; - - // The original title of the tab that should be reverted to when the - // interstitial is hidden. - std::wstring original_tab_title_; - - // Our RenderViewHostViewDelegate, necessary for accelerators to work. - scoped_ptr<InterstitialPageRVHViewDelegate> rvh_view_delegate_; - - // We keep a map of the various blocking pages shown as the UI tests need to - // be able to retrieve them. - typedef std::map<TabContents*, InterstitialPage*> InterstitialPageMap; - static InterstitialPageMap* tab_to_interstitial_page_; - - // Settings passed to the renderer. - RendererPreferences renderer_preferences_; - - DISALLOW_COPY_AND_ASSIGN(InterstitialPage); -}; +// TODO(jam): remove this file when all files have been converted. +#include "content/browser/tab_contents/interstitial_page.h" #endif // CHROME_BROWSER_TAB_CONTENTS_INTERSTITIAL_PAGE_H_ diff --git a/chrome/browser/tab_contents/language_state.h b/chrome/browser/tab_contents/language_state.h index b3728a3..6c35545 100644 --- a/chrome/browser/tab_contents/language_state.h +++ b/chrome/browser/tab_contents/language_state.h @@ -6,105 +6,8 @@ #define CHROME_BROWSER_TAB_CONTENTS_LANGUAGE_STATE_H_ #pragma once -#include <string> - -#include "base/basictypes.h" -#include "chrome/browser/tab_contents/navigation_controller.h" - -// This class holds the language state of the current page. -// There is one LanguageState instance per TabContents. -// It is used to determine when navigating to a new page whether it should -// automatically be translated. -// This auto-translate behavior is the expected behavior when: -// - user is on page in language A that they had translated to language B. -// - user clicks a link in that page that takes them to a page also in language -// A. - -class LanguageState { - public: - explicit LanguageState(NavigationController* nav_controller); - ~LanguageState(); - - // Should be called when the page did a new navigation (whether it is a main - // frame or sub-frame navigation). - void DidNavigate(const NavigationController::LoadCommittedDetails& details); - - // Should be called when the language of the page has been determined. - // |page_translatable| when false indicates that the browser should not offer - // to translate the page. - void LanguageDetermined(const std::string& page_language, - bool page_translatable); - - // Returns the language the current page should be translated to, based on the - // previous page languages and the transition. This should be called after - // the language page has been determined. - // Returns an empty string if the page should not be auto-translated. - std::string AutoTranslateTo() const; - - // Returns true if the current page in the associated tab has been translated. - bool IsPageTranslated() const { return original_lang_ != current_lang_; } - - const std::string& original_language() const { return original_lang_; } - - void set_current_language(const std::string& language) { - current_lang_ = language; - } - const std::string& current_language() const { return current_lang_; } - - bool page_translatable() const { return page_translatable_; } - - // Whether the page is currently in the process of being translated. - bool translation_pending() const { return translation_pending_; } - void set_translation_pending(bool value) { translation_pending_ = value; } - - // Whether the user has already declined to translate the page. - bool translation_declined() const { return translation_declined_; } - void set_translation_declined(bool value) { translation_declined_ = value; } - - // Whether the current page was navigated through an in-page (fragment) - // navigation. - bool in_page_navigation() const { return in_page_navigation_; } - - private: - // The languages this page is in. Note that current_lang_ is different from - // original_lang_ when the page has been translated. - // Note that these might be empty if the page language has not been determined - // yet. - std::string original_lang_; - std::string current_lang_; - - // Same as above but for the previous page. - std::string prev_original_lang_; - std::string prev_current_lang_; - - // The navigation controller of the tab we are associated with. - NavigationController* navigation_controller_; - - // Whether it is OK to offer to translate the page. Some pages explictly - // specify that they should not be translated by the browser (this is the case - // for GMail for example, which provides its own translation features). - bool page_translatable_; - - // Whether a translation is currently pending (TabContents waiting for the - // PAGE_TRANSLATED notification). This is needed to avoid sending duplicate - // translate requests to a page. TranslateManager initiates translations - // when it received the LANGUAGE_DETERMINED notification. This is sent by - // the renderer with the page contents, every time the load stops for the - // main frame, so we may get several. - // TODO(jcampan): make the renderer send the language just once per navigation - // then we can get rid of that state. - bool translation_pending_; - - // Whether the user has declined to translate the page (by closing the infobar - // for example). This is necessary as a new infobar could be shown if a new - // load happens in the page after the user closed the infobar. - bool translation_declined_; - - // Whether the current navigation is a fragment navigation (in page). - bool in_page_navigation_; - - DISALLOW_COPY_AND_ASSIGN(LanguageState); -}; +// TODO(jam): remove this file when all files have been converted. +#include "content/browser/tab_contents/language_state.h" #endif // CHROME_BROWSER_TAB_CONTENTS_LANGUAGE_STATE_H_ diff --git a/chrome/browser/tab_contents/navigation_controller.h b/chrome/browser/tab_contents/navigation_controller.h index adbc348..7eb9d11 100644 --- a/chrome/browser/tab_contents/navigation_controller.h +++ b/chrome/browser/tab_contents/navigation_controller.h @@ -6,598 +6,7 @@ #define CHROME_BROWSER_TAB_CONTENTS_NAVIGATION_CONTROLLER_H_ #pragma once -#include "build/build_config.h" - -#include <string> -#include <vector> - -#include "base/linked_ptr.h" -#include "base/time.h" -#include "googleurl/src/gurl.h" -#include "chrome/browser/sessions/session_id.h" -#include "chrome/browser/ssl/ssl_manager.h" -#include "chrome/common/navigation_types.h" -#include "chrome/common/page_transition_types.h" - -class NavigationEntry; -class Profile; -class SessionStorageNamespace; -class SiteInstance; -class TabContents; -class TabNavigation; -struct ViewHostMsg_FrameNavigate_Params; - -// A NavigationController maintains the back-forward list for a single tab and -// manages all navigation within that list. -// -// The NavigationController also owns all TabContents for the tab. This is to -// make sure that we have at most one TabContents instance per type. -class NavigationController { - public: - // Notification details ------------------------------------------------------ - - // Provides the details for a NOTIFY_NAV_ENTRY_CHANGED notification. - struct EntryChangedDetails { - // The changed navigation entry after it has been updated. - const NavigationEntry* changed_entry; - - // Indicates the current index in the back/forward list of the entry. - int index; - }; - - // Provides the details for a NOTIFY_NAV_ENTRY_COMMITTED notification. - // TODO(brettw) this mostly duplicates ProvisionalLoadDetails, it would be - // nice to unify these somehow. - struct LoadCommittedDetails { - // By default, the entry will be filled according to a new main frame - // navigation. - LoadCommittedDetails() - : entry(NULL), - type(NavigationType::UNKNOWN), - previous_entry_index(-1), - is_auto(false), - did_replace_entry(false), - is_in_page(false), - is_main_frame(true), - is_content_filtered(false), - http_status_code(0) { - } - - // The committed entry. This will be the active entry in the controller. - NavigationEntry* entry; - - // The type of navigation that just occurred. Note that not all types of - // navigations in the enum are valid here, since some of them don't actually - // cause a "commit" and won't generate this notification. - NavigationType::Type type; - - // The index of the previously committed navigation entry. This will be -1 - // if there are no previous entries. - int previous_entry_index; - - // The previous URL that the user was on. This may be empty if none. - GURL previous_url; - - // True when this load was non-user initated. This corresponds to a - // a NavigationGestureAuto call from WebKit (see webview_delegate.h). - // We also count reloads and meta-refreshes as "auto" to account for the - // fact that WebKit doesn't always set the user gesture properly in these - // cases (see bug 1051891). - bool is_auto; - - // True if the committed entry has replaced the exisiting one. - // A non-user initiated redirect causes such replacement. - // This is somewhat similiar to is_auto, but not exactly the same. - bool did_replace_entry; - - // True if the navigation was in-page. This means that the active entry's - // URL and the |previous_url| are the same except for reference fragments. - bool is_in_page; - - // True when the main frame was navigated. False means the navigation was a - // sub-frame. - bool is_main_frame; - - // Whether the content of this frame has been altered/blocked because it was - // unsafe. - bool is_content_filtered; - - // When the committed load is a web page from the renderer, this string - // specifies the security state if the page is secure. - // See ViewHostMsg_FrameNavigate_Params.security_info, where it comes from. - // Use SSLManager::DeserializeSecurityInfo to decode it. - std::string serialized_security_info; - - // Returns whether the user probably felt like they navigated somewhere new. - // We often need this logic for showing or hiding something, and this - // returns true only for main frame loads that the user initiated, that go - // to a new page. - bool is_user_initiated_main_frame_load() const { - return !is_auto && !is_in_page && is_main_frame; - } - - // The HTTP status code for this entry.. - int http_status_code; - }; - - // Details sent for NOTIFY_NAV_LIST_PRUNED. - struct PrunedDetails { - // If true, count items were removed from the front of the list, otherwise - // count items were removed from the back of the list. - bool from_front; - - // Number of items removed. - int count; - }; - - enum ReloadType { - NO_RELOAD, // Normal load. - RELOAD, // Normal (cache-validating) reload. - RELOAD_IGNORING_CACHE // Reload bypassing the cache, aka shift-reload. - }; - - // --------------------------------------------------------------------------- - - NavigationController(TabContents* tab_contents, - Profile* profile, - SessionStorageNamespace* session_storage_namespace); - ~NavigationController(); - - // Returns the profile for this controller. It can never be NULL. - Profile* profile() const { - return profile_; - } - - // Sets the profile for this controller. - void set_profile(Profile* profile) { - profile_ = profile; - } - - // Initializes this NavigationController with the given saved navigations, - // using selected_navigation as the currently loaded entry. Before this call - // the controller should be unused (there should be no current entry). If - // from_last_session is true, navigations are from the previous session, - // otherwise they are from the current session (undo tab close). - // This is used for session restore. - void RestoreFromState(const std::vector<TabNavigation>& navigations, - int selected_navigation, bool from_last_session); - - // Active entry -------------------------------------------------------------- - - // Returns the active entry, which is the transient entry if any, the pending - // entry if a navigation is in progress or the last committed entry otherwise. - // NOTE: This can be NULL!! - // - // If you are trying to get the current state of the NavigationController, - // this is the method you will typically want to call. - NavigationEntry* GetActiveEntry() const; - - // Returns the index from which we would go back/forward or reload. This is - // the last_committed_entry_index_ if pending_entry_index_ is -1. Otherwise, - // it is the pending_entry_index_. - int GetCurrentEntryIndex() const; - - // Returns the last committed entry, which may be null if there are no - // committed entries. - NavigationEntry* GetLastCommittedEntry() const; - - // Returns true if the source for the current entry can be viewed. - bool CanViewSource() const; - - // Returns the index of the last committed entry. - int last_committed_entry_index() const { - return last_committed_entry_index_; - } - - // Navigation list ----------------------------------------------------------- - - // Returns the number of entries in the NavigationController, excluding - // the pending entry if there is one, but including the transient entry if - // any. - int entry_count() const { - return static_cast<int>(entries_.size()); - } - - NavigationEntry* GetEntryAtIndex(int index) const { - return entries_.at(index).get(); - } - - // Returns the entry at the specified offset from current. Returns NULL - // if out of bounds. - NavigationEntry* GetEntryAtOffset(int offset) const; - - // Returns the index of the specified entry, or -1 if entry is not contained - // in this NavigationController. - int GetIndexOfEntry(const NavigationEntry* entry) const; - - // Return the index of the entry with the corresponding instance and page_id, - // or -1 if not found. - int GetEntryIndexWithPageID(SiteInstance* instance, - int32 page_id) const; - - // Return the entry with the corresponding instance and page_id, or NULL if - // not found. - NavigationEntry* GetEntryWithPageID(SiteInstance* instance, - int32 page_id) const; - - // Pending entry ------------------------------------------------------------- - - // Commits the current pending entry and issues the NOTIFY_NAV_ENTRY_COMMIT - // notification. No changes are made to the entry during this process, it is - // just moved from pending to committed. This is an alternative to - // RendererDidNavigate for simple TabContents types. - // - // When the pending entry is a new navigation, it will have a page ID of -1. - // The caller should leave this as-is. CommitPendingEntry will generate a - // new page ID for you and update the TabContents with that ID. - void CommitPendingEntry(); - - // Discards the pending and transient entries if any. - void DiscardNonCommittedEntries(); - - // Returns the pending entry corresponding to the navigation that is - // currently in progress, or null if there is none. - NavigationEntry* pending_entry() const { - return pending_entry_; - } - - // Returns the index of the pending entry or -1 if the pending entry - // corresponds to a new navigation (created via LoadURL). - int pending_entry_index() const { - return pending_entry_index_; - } - - // Transient entry ----------------------------------------------------------- - - // Adds an entry that is returned by GetActiveEntry(). The entry is - // transient: any navigation causes it to be removed and discarded. - // The NavigationController becomes the owner of |entry| and deletes it when - // it discards it. This is useful with interstitial page that need to be - // represented as an entry, but should go away when the user navigates away - // from them. - // Note that adding a transient entry does not change the active contents. - void AddTransientEntry(NavigationEntry* entry); - - // Returns the transient entry if any. Note that the returned entry is owned - // by the navigation controller and may be deleted at any time. - NavigationEntry* GetTransientEntry() const; - - // New navigations ----------------------------------------------------------- - - // Loads the specified URL. - void LoadURL(const GURL& url, const GURL& referrer, - PageTransition::Type type); - - // Loads the current page if this NavigationController was restored from - // history and the current page has not loaded yet. - void LoadIfNecessary(); - - // Renavigation -------------------------------------------------------------- - - // Navigation relative to the "current entry" - bool CanGoBack() const; - bool CanGoForward() const; - void GoBack(); - void GoForward(); - - // Navigates to the specified absolute index. - void GoToIndex(int index); - - // Navigates to the specified offset from the "current entry". Does nothing if - // the offset is out of bounds. - void GoToOffset(int offset); - - // Reloads the current entry. If |check_for_repost| is true and the current - // entry has POST data the user is prompted to see if they really want to - // reload the page. In nearly all cases pass in true. - void Reload(bool check_for_repost); - // Like Reload(), but don't use caches (aka "shift-reload"). - void ReloadIgnoringCache(bool check_for_repost); - - // Removing of entries ------------------------------------------------------- - - // Removes the entry at the specified |index|. This call dicards any pending - // and transient entries. |default_url| is the URL that the navigation - // controller navigates to if there are no more entries after the removal. - // If |default_url| is empty, we default to "about:blank". - void RemoveEntryAtIndex(int index, const GURL& default_url); - - // TabContents --------------------------------------------------------------- - - // Returns the tab contents associated with this controller. Non-NULL except - // during set-up of the tab. - TabContents* tab_contents() const { - // This currently returns the active tab contents which should be renamed to - // tab_contents. - return tab_contents_; - } - - // Called when a document has been loaded in a frame. - void DocumentLoadedInFrame(); - - // For use by TabContents ---------------------------------------------------- - - // Handles updating the navigation state after the renderer has navigated. - // This is used by the TabContents. Simpler tab contents types can use - // CommitPendingEntry below. - // - // If a new entry is created, it will return true and will have filled the - // given details structure and broadcast the NOTIFY_NAV_ENTRY_COMMITTED - // notification. The caller can then use the details without worrying about - // listening for the notification. - // - // In the case that nothing has changed, the details structure is undefined - // and it will return false. - // - // |extra_invalidate_flags| are an additional set of flags (InvalidateTypes) - // added to the flags sent to the delegate's NotifyNavigationStateChanged. - bool RendererDidNavigate(const ViewHostMsg_FrameNavigate_Params& params, - int extra_invalidate_flags, - LoadCommittedDetails* details); - - // Notifies us that we just became active. This is used by the TabContents - // so that we know to load URLs that were pending as "lazy" loads. - void SetActive(bool is_active); - - // Broadcasts the NOTIFY_NAV_ENTRY_CHANGED notification for the given entry - // (which must be at the given index). This will keep things in sync like - // the saved session. - void NotifyEntryChanged(const NavigationEntry* entry, int index); - - // Returns true if the given URL would be an in-page navigation (i.e. only - // the reference fragment is different) from the "last committed entry". We do - // not compare it against the "active entry" since the active entry can be - // pending and in page navigations only happen on committed pages. If there - // is no last committed entry, then nothing will be in-page. - // - // Special note: if the URLs are the same, it does NOT count as an in-page - // navigation. Neither does an input URL that has no ref, even if the rest is - // the same. This may seem weird, but when we're considering whether a - // navigation happened without loading anything, the same URL would be a - // reload, while only a different ref would be in-page (pages can't clear - // refs without reload, only change to "#" which we don't count as empty). - bool IsURLInPageNavigation(const GURL& url) const; - - // Copies the navigation state from the given controller to this one. This - // one should be empty (just created). - void CopyStateFrom(const NavigationController& source); - - // A variant of CopyStateFrom. Removes all entries from this except the last - // entry, inserts all entries from |source| before and including the active - // entry. This method is intended for use when the last entry of |this| is the - // active entry. For example: - // source: A B *C* D - // this: E F *G* (last must be active or pending) - // result: A B *G* - // This ignores the transient index of the source and honors that of 'this'. - void CopyStateFromAndPrune(NavigationController* source); - - // Removes all the entries except the active entry. If there is a new pending - // navigation it is preserved. - void PruneAllButActive(); - - // Random data --------------------------------------------------------------- - - // Returns the identifier used by session restore. - const SessionID& session_id() const { return session_id_; } - - // Identifier of the window we're in. - void SetWindowID(const SessionID& id); - const SessionID& window_id() const { return window_id_; } - - SSLManager* ssl_manager() { return &ssl_manager_; } - - // Returns true if a reload happens when activated (SetActive(true) is - // invoked). This is true for session/tab restore and cloned tabs. - bool needs_reload() const { return needs_reload_; } - - // Sets the max restored page ID this NavigationController has seen, if it - // was restored from a previous session. - void set_max_restored_page_id(int32 max_id) { - max_restored_page_id_ = max_id; - } - - // Returns the largest restored page ID seen in this navigation controller, - // if it was restored from a previous session. (-1 otherwise) - int32 max_restored_page_id() const { return max_restored_page_id_; } - - // The session storage namespace that all child render views should use. - SessionStorageNamespace* session_storage_namespace() const { - return session_storage_namespace_; - } - - // Disables checking for a repost and prompting the user. This is used during - // testing. - static void DisablePromptOnRepost(); - - // Maximum number of entries before we start removing entries from the front. -#ifdef UNIT_TEST - static void set_max_entry_count(size_t max_entry_count) { - max_entry_count_ = max_entry_count; - } -#endif - static size_t max_entry_count() { return max_entry_count_; } - - // Cancels a repost that brought up a warning. - void CancelPendingReload(); - // Continues a repost that brought up a warning. - void ContinuePendingReload(); - - // Returns true if we are navigating to the URL the tab is opened with. - bool IsInitialNavigation(); - - // Creates navigation entry and translates the virtual url to a real one. - // Used when restoring a tab from a TabNavigation object and when navigating - // to a new URL using LoadURL. - static NavigationEntry* CreateNavigationEntry(const GURL& url, - const GURL& referrer, - PageTransition::Type transition, - Profile* profile); - - private: - class RestoreHelper; - friend class RestoreHelper; - friend class TabContents; // For invoking OnReservedPageIDRange. - - // Classifies the given renderer navigation (see the NavigationType enum). - NavigationType::Type ClassifyNavigation( - const ViewHostMsg_FrameNavigate_Params& params) const; - - // Causes the controller to load the specified entry. The function assumes - // ownership of the pointer since it is put in the navigation list. - // NOTE: Do not pass an entry that the controller already owns! - void LoadEntry(NavigationEntry* entry); - - // Handlers for the different types of navigation types. They will actually - // handle the navigations corresponding to the different NavClasses above. - // They will NOT broadcast the commit notification, that should be handled by - // the caller. - // - // RendererDidNavigateAutoSubframe is special, it may not actually change - // anything if some random subframe is loaded. It will return true if anything - // changed, or false if not. - // - // The functions taking |did_replace_entry| will fill into the given variable - // whether the last entry has been replaced or not. - // See LoadCommittedDetails.did_replace_entry. - void RendererDidNavigateToNewPage( - const ViewHostMsg_FrameNavigate_Params& params, bool* did_replace_entry); - void RendererDidNavigateToExistingPage( - const ViewHostMsg_FrameNavigate_Params& params); - void RendererDidNavigateToSamePage( - const ViewHostMsg_FrameNavigate_Params& params); - void RendererDidNavigateInPage( - const ViewHostMsg_FrameNavigate_Params& params, bool* did_replace_entry); - void RendererDidNavigateNewSubframe( - const ViewHostMsg_FrameNavigate_Params& params); - bool RendererDidNavigateAutoSubframe( - const ViewHostMsg_FrameNavigate_Params& params); - - // Helper function for code shared between Reload() and ReloadIgnoringCache(). - void ReloadInternal(bool check_for_repost, ReloadType reload_type); - - // Actually issues the navigation held in pending_entry. - void NavigateToPendingEntry(ReloadType reload_type); - - // Allows the derived class to issue notifications that a load has been - // committed. This will fill in the active entry to the details structure. - // - // |extra_invalidate_flags| are an additional set of flags (InvalidateTypes) - // added to the flags sent to the delegate's NotifyNavigationStateChanged. - void NotifyNavigationEntryCommitted(LoadCommittedDetails* details, - int extra_invalidate_flags); - - // Updates the virtual URL of an entry to match a new URL, for cases where - // the real renderer URL is derived from the virtual URL, like view-source: - void UpdateVirtualURLToURL(NavigationEntry* entry, const GURL& new_url); - - // Invoked after session/tab restore or cloning a tab. Resets the transition - // type of the entries, updates the max page id and creates the active - // contents. See RestoreFromState for a description of from_last_session. - void FinishRestore(int selected_index, bool from_last_session); - - // Inserts a new entry or replaces the current entry with a new one, removing - // all entries after it. The new entry will become the active one. - void InsertOrReplaceEntry(NavigationEntry* entry, bool replace); - - // Discards the pending and transient entries. - void DiscardNonCommittedEntriesInternal(); - - // Discards the transient entry. - void DiscardTransientEntry(); - - // Returns true if the navigation is redirect. - bool IsRedirect(const ViewHostMsg_FrameNavigate_Params& params); - - // Returns true if the navigation is likley to be automatic rather than - // user-initiated. - bool IsLikelyAutoNavigation(base::TimeTicks now); - - // Creates a new NavigationEntry for each TabNavigation in navigations, adding - // the NavigationEntry to entries. This is used during session restore. - void CreateNavigationEntriesFromTabNavigations( - const std::vector<TabNavigation>& navigations, - std::vector<linked_ptr<NavigationEntry> >* entries); - - // Inserts up to |max_index| entries from |source| into this. This does NOT - // adjust any of the members that reference entries_ - // (last_committed_entry_index_, pending_entry_index_ or - // transient_entry_index_). - void InsertEntriesFrom(const NavigationController& source, int max_index); - - // --------------------------------------------------------------------------- - - // The user profile associated with this controller - Profile* profile_; - - // List of NavigationEntry for this tab - typedef std::vector<linked_ptr<NavigationEntry> > NavigationEntries; - NavigationEntries entries_; - - // An entry we haven't gotten a response for yet. This will be discarded - // when we navigate again. It's used only so we know what the currently - // displayed tab is. - // - // This may refer to an item in the entries_ list if the pending_entry_index_ - // == -1, or it may be its own entry that should be deleted. Be careful with - // the memory management. - NavigationEntry* pending_entry_; - - // currently visible entry - int last_committed_entry_index_; - - // index of pending entry if it is in entries_, or -1 if pending_entry_ is a - // new entry (created by LoadURL). - int pending_entry_index_; - - // The index for the entry that is shown until a navigation occurs. This is - // used for interstitial pages. -1 if there are no such entry. - // Note that this entry really appears in the list of entries, but only - // temporarily (until the next navigation). Any index pointing to an entry - // after the transient entry will become invalid if you navigate forward. - int transient_entry_index_; - - // The tab contents associated with the controller. Possibly NULL during - // setup. - TabContents* tab_contents_; - - // The max restored page ID in this controller, if it was restored. We must - // store this so that TabContents can tell any renderer in charge of one of - // the restored entries to update its max page ID. - int32 max_restored_page_id_; - - // Manages the SSL security UI - SSLManager ssl_manager_; - - // Whether we need to be reloaded when made active. - bool needs_reload_; - - // Unique identifier of this controller for session restore. This id is only - // unique within the current session, and is not guaranteed to be unique - // across sessions. - SessionID session_id_; - - // Unique identifier of the window we're in. Used by session restore. - SessionID window_id_; - - // The time ticks at which the last document was loaded. - base::TimeTicks last_document_loaded_; - - // The session storage id that any (indirectly) owned RenderView should use. - scoped_refptr<SessionStorageNamespace> session_storage_namespace_; - - // Should Reload check for post data? The default is true, but is set to false - // when testing. - static bool check_for_repost_; - - // The maximum number of entries that a navigation controller can store. - static size_t max_entry_count_; - - // If a repost is pending, its type (RELOAD or RELOAD_IGNORING_CACHE), - // NO_RELOAD otherwise. - ReloadType pending_reload_; - - DISALLOW_COPY_AND_ASSIGN(NavigationController); -}; +// TODO(jam): remove this file when all files have been converted. +#include "content/browser/tab_contents/navigation_controller.h" #endif // CHROME_BROWSER_TAB_CONTENTS_NAVIGATION_CONTROLLER_H_ diff --git a/chrome/browser/tab_contents/navigation_entry.h b/chrome/browser/tab_contents/navigation_entry.h index 57d93c4..a9f0cc0 100644 --- a/chrome/browser/tab_contents/navigation_entry.h +++ b/chrome/browser/tab_contents/navigation_entry.h @@ -6,424 +6,7 @@ #define CHROME_BROWSER_TAB_CONTENTS_NAVIGATION_ENTRY_H_ #pragma once -#include <string> - -#include "base/basictypes.h" -#include "base/ref_counted.h" -#include "chrome/common/page_type.h" -#include "chrome/common/page_transition_types.h" -#include "chrome/common/security_style.h" -#include "googleurl/src/gurl.h" -#include "third_party/skia/include/core/SkBitmap.h" - -class SiteInstance; - -//////////////////////////////////////////////////////////////////////////////// -// -// NavigationEntry class -// -// A NavigationEntry is a data structure that captures all the information -// required to recreate a browsing state. This includes some opaque binary -// state as provided by the TabContents as well as some clear text title and -// URL which is used for our user interface. -// -//////////////////////////////////////////////////////////////////////////////// -class NavigationEntry { - public: - // SSL ----------------------------------------------------------------------- - - // Collects the SSL information for this NavigationEntry. - class SSLStatus { - public: - // Flags used for the page security content status. - enum ContentStatusFlags { - // HTTP page, or HTTPS page with no insecure content. - NORMAL_CONTENT = 0, - - // HTTPS page containing "displayed" HTTP resources (e.g. images, CSS). - DISPLAYED_INSECURE_CONTENT = 1 << 0, - - // HTTPS page containing "executed" HTTP resources (i.e. script). - // Also currently used for HTTPS page containing broken-HTTPS resources; - // this is wrong and should be fixed (see comments in - // SSLPolicy::OnRequestStarted()). - RAN_INSECURE_CONTENT = 1 << 1, - }; - - SSLStatus(); - - bool Equals(const SSLStatus& status) const { - return security_style_ == status.security_style_ && - cert_id_ == status.cert_id_ && - cert_status_ == status.cert_status_ && - security_bits_ == status.security_bits_ && - content_status_ == status.content_status_; - } - - void set_security_style(SecurityStyle security_style) { - security_style_ = security_style; - } - SecurityStyle security_style() const { - return security_style_; - } - - void set_cert_id(int ssl_cert_id) { - cert_id_ = ssl_cert_id; - } - int cert_id() const { - return cert_id_; - } - - void set_cert_status(int ssl_cert_status) { - cert_status_ = ssl_cert_status; - } - int cert_status() const { - return cert_status_; - } - - void set_security_bits(int security_bits) { - security_bits_ = security_bits; - } - int security_bits() const { - return security_bits_; - } - - void set_displayed_insecure_content() { - content_status_ |= DISPLAYED_INSECURE_CONTENT; - } - bool displayed_insecure_content() const { - return (content_status_ & DISPLAYED_INSECURE_CONTENT) != 0; - } - - void set_ran_insecure_content() { - content_status_ |= RAN_INSECURE_CONTENT; - } - bool ran_insecure_content() const { - return (content_status_ & RAN_INSECURE_CONTENT) != 0; - } - - void set_connection_status(int connection_status) { - connection_status_ = connection_status; - } - int connection_status() const { - return connection_status_; - } - - // Raw accessors for all the content status flags. This contains a - // combination of any of the ContentStatusFlags defined above. It is used - // by some tests for checking and for certain copying. Use the per-status - // functions for normal usage. - void set_content_status(int content_status) { - content_status_ = content_status; - } - int content_status() const { - return content_status_; - } - - private: - // See the accessors above for descriptions. - SecurityStyle security_style_; - int cert_id_; - int cert_status_; - int security_bits_; - int connection_status_; - int content_status_; - - // Copy and assignment is explicitly allowed for this class. - }; - - // Favicon ------------------------------------------------------------------- - - // Collects the favicon related information for a NavigationEntry. - class FaviconStatus { - public: - FaviconStatus(); - - // Indicates whether we've gotten an official favicon for the page, or are - // just using the default favicon. - void set_is_valid(bool is_valid) { - valid_ = is_valid; - } - bool is_valid() const { - return valid_; - } - - // The URL of the favicon which was used to load it off the web. - void set_url(const GURL& favicon_url) { - url_ = favicon_url; - } - const GURL& url() const { - return url_; - } - - // The favicon bitmap for the page. If the favicon has not been explicitly - // set or it empty, it will return the default favicon. Note that this is - // loaded asynchronously, so even if the favicon URL is valid we may return - // the default favicon if we haven't gotten the data yet. - void set_bitmap(const SkBitmap& bitmap) { - bitmap_ = bitmap; - } - const SkBitmap& bitmap() const { - return bitmap_; - } - - private: - // See the accessors above for descriptions. - bool valid_; - GURL url_; - SkBitmap bitmap_; - - // Copy and assignment is explicitly allowed for this class. - }; - - // --------------------------------------------------------------------------- - - NavigationEntry(); - NavigationEntry(SiteInstance* instance, - int page_id, - const GURL& url, - const GURL& referrer, - const string16& title, - PageTransition::Type transition_type); - ~NavigationEntry(); - - // Page-related stuff -------------------------------------------------------- - - // A unique ID is preserved across commits and redirects, which means that - // sometimes a NavigationEntry's unique ID needs to be set (e.g. when - // creating a committed entry to correspond to a to-be-deleted pending entry, - // the pending entry's ID must be copied). - void set_unique_id(int unique_id) { - unique_id_ = unique_id; - } - int unique_id() const { - return unique_id_; - } - - // The SiteInstance tells us how to share sub-processes when the tab type is - // TAB_CONTENTS_WEB. This will be NULL otherwise. This is a reference counted - // pointer to a shared site instance. - // - // Note that the SiteInstance should usually not be changed after it is set, - // but this may happen if the NavigationEntry was cloned and needs to use a - // different SiteInstance. - void set_site_instance(SiteInstance* site_instance); - SiteInstance* site_instance() const { - return site_instance_; - } - - // The page type tells us if this entry is for an interstitial or error page. - // See the PageType enum above. - void set_page_type(PageType page_type) { - page_type_ = page_type; - } - PageType page_type() const { - return page_type_; - } - - // The actual URL of the page. For some about pages, this may be a scary - // data: URL or something like that. Use virtual_url() below for showing to - // the user. - void set_url(const GURL& url) { - url_ = url; - cached_display_title_.clear(); - } - const GURL& url() const { - return url_; - } - - // The referring URL. Can be empty. - void set_referrer(const GURL& referrer) { - referrer_ = referrer; - } - const GURL& referrer() const { - return referrer_; - } - - // The virtual URL, when nonempty, will override the actual URL of the page - // when we display it to the user. This allows us to have nice and friendly - // URLs that the user sees for things like about: URLs, but actually feed - // the renderer a data URL that results in the content loading. - // - // virtual_url() will return the URL to display to the user in all cases, so - // if there is no overridden display URL, it will return the actual one. - void set_virtual_url(const GURL& url) { - virtual_url_ = (url == url_) ? GURL() : url; - cached_display_title_.clear(); - } - bool has_virtual_url() const { - return !virtual_url_.is_empty(); - } - const GURL& virtual_url() const { - return virtual_url_.is_empty() ? url_ : virtual_url_; - } - - bool update_virtual_url_with_url() const { - return update_virtual_url_with_url_; - } - void set_update_virtual_url_with_url(bool update) { - update_virtual_url_with_url_ = update; - } - - // The title as set by the page. This will be empty if there is no title set. - // The caller is responsible for detecting when there is no title and - // displaying the appropriate "Untitled" label if this is being displayed to - // the user. - void set_title(const string16& title) { - title_ = title; - cached_display_title_.clear(); - } - const string16& title() const { - return title_; - } - - // The favicon data and tracking information. See FaviconStatus above. - const FaviconStatus& favicon() const { - return favicon_; - } - FaviconStatus& favicon() { - return favicon_; - } - - // Content state is an opaque blob created by WebKit that represents the - // state of the page. This includes form entries and scroll position for each - // frame. We store it so that we can supply it back to WebKit to restore form - // state properly when the user goes back and forward. - // - // WARNING: This state is saved to the file and used to restore previous - // states. If the format is modified in the future, we should still be able to - // deal with older versions. - void set_content_state(const std::string& state) { - content_state_ = state; - } - const std::string& content_state() const { - return content_state_; - } - - // Describes the current page that the tab represents. For web pages - // (TAB_CONTENTS_WEB) this is the ID that the renderer generated for the page - // and is how we can tell new versus renavigations. - void set_page_id(int page_id) { - page_id_ = page_id; - } - int32 page_id() const { - return page_id_; - } - - // All the SSL flags and state. See SSLStatus above. - const SSLStatus& ssl() const { - return ssl_; - } - SSLStatus& ssl() { - return ssl_; - } - - // Page-related helpers ------------------------------------------------------ - - // Returns the title to be displayed on the tab. This could be the title of - // the page if it is available or the URL. |languages| is the list of - // accpeted languages (e.g., prefs::kAcceptLanguages) or empty if proper - // URL formatting isn't needed (e.g., unit tests). - const string16& GetTitleForDisplay(const std::string& languages); - - // Returns true if the current tab is in view source mode. This will be false - // if there is no navigation. - bool IsViewSourceMode() const; - - // Tracking stuff ------------------------------------------------------------ - - // The transition type indicates what the user did to move to this page from - // the previous page. - void set_transition_type(PageTransition::Type transition_type) { - transition_type_ = transition_type; - } - PageTransition::Type transition_type() const { - return transition_type_; - } - - // The user typed URL was the URL that the user initiated the navigation - // with, regardless of any redirects. This is used to generate keywords, for - // example, based on "what the user thinks the site is called" rather than - // what it's actually called. For example, if the user types "foo.com", that - // may redirect somewhere arbitrary like "bar.com/foo", and we want to use - // the name that the user things of the site as having. - // - // This URL will be is_empty() if the URL was navigated to some other way. - // Callers should fall back on using the regular or display URL in this case. - void set_user_typed_url(const GURL& user_typed_url) { - user_typed_url_ = user_typed_url; - } - const GURL& user_typed_url() const { - return user_typed_url_; - } - - // Post data is form data that was posted to get to this page. The data will - // have to be reposted to reload the page properly. This flag indicates - // whether the page had post data. - // - // The actual post data is stored in the content_state and is extracted by - // WebKit to actually make the request. - void set_has_post_data(bool has_post_data) { - has_post_data_ = has_post_data; - } - bool has_post_data() const { - return has_post_data_; - } - - // Enumerations of the possible restore types. - enum RestoreType { - // The entry has been restored is from the last session. - RESTORE_LAST_SESSION, - - // The entry has been restored from the current session. This is used when - // the user issues 'reopen closed tab'. - RESTORE_CURRENT_SESSION, - - // The entry was not restored. - RESTORE_NONE - }; - - // The RestoreType for this entry. This is set if the entry was retored. This - // is set to RESTORE_NONE once the entry is loaded. - void set_restore_type(RestoreType type) { - restore_type_ = type; - } - RestoreType restore_type() const { - return restore_type_; - } - - private: - // WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING - // Session/Tab restore save portions of this class so that it can be recreated - // later. If you add a new field that needs to be persisted you'll have to - // update SessionService/TabRestoreService appropriately. - // WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING - - // See the accessors above for descriptions. - int unique_id_; - scoped_refptr<SiteInstance> site_instance_; - PageType page_type_; - GURL url_; - GURL referrer_; - GURL virtual_url_; - bool update_virtual_url_with_url_; - string16 title_; - FaviconStatus favicon_; - std::string content_state_; - int32 page_id_; - SSLStatus ssl_; - PageTransition::Type transition_type_; - GURL user_typed_url_; - bool has_post_data_; - RestoreType restore_type_; - - // This is a cached version of the result of GetTitleForDisplay. It prevents - // us from having to do URL formatting on the URL evey time the title is - // displayed. When the URL, virtual URL, or title is set, this should be - // cleared to force a refresh. - string16 cached_display_title_; - - // Copy and assignment is explicitly allowed for this class. -}; +// TODO(jam): remove this file when all files have been converted. +#include "content/browser/tab_contents/navigation_entry.h" #endif // CHROME_BROWSER_TAB_CONTENTS_NAVIGATION_ENTRY_H_ diff --git a/chrome/browser/tab_contents/page_navigator.h b/chrome/browser/tab_contents/page_navigator.h index 8773146..62c0333 100644 --- a/chrome/browser/tab_contents/page_navigator.h +++ b/chrome/browser/tab_contents/page_navigator.h @@ -2,29 +2,11 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// PageNavigator defines an interface that can be used to express the user's -// intention to navigate to a particular URL. The implementing class should -// perform the navigation. - #ifndef CHROME_BROWSER_TAB_CONTENTS_PAGE_NAVIGATOR_H_ #define CHROME_BROWSER_TAB_CONTENTS_PAGE_NAVIGATOR_H_ #pragma once -#include "chrome/common/page_transition_types.h" -#include "webkit/glue/window_open_disposition.h" - -class GURL; - -class PageNavigator { - public: - // Opens a URL with the given disposition. The transition specifies how this - // navigation should be recorded in the history system (for example, typed). - virtual void OpenURL(const GURL& url, const GURL& referrer, - WindowOpenDisposition disposition, - PageTransition::Type transition) = 0; - - protected: - virtual ~PageNavigator() {} -}; +// TODO(jam): remove this file when all files have been converted. +#include "content/browser/tab_contents/page_navigator.h" #endif // CHROME_BROWSER_TAB_CONTENTS_PAGE_NAVIGATOR_H_ diff --git a/chrome/browser/tab_contents/provisional_load_details.h b/chrome/browser/tab_contents/provisional_load_details.h index 732d52c..1ee04248 100644 --- a/chrome/browser/tab_contents/provisional_load_details.h +++ b/chrome/browser/tab_contents/provisional_load_details.h @@ -6,77 +6,7 @@ #define CHROME_BROWSER_TAB_CONTENTS_PROVISIONAL_LOAD_DETAILS_H_ #pragma once -#include <string> - -#include "base/basictypes.h" -#include "chrome/common/page_transition_types.h" -#include "googleurl/src/gurl.h" - -// This class captures some of the information associated to the provisional -// load of a frame. It is provided as Details with the -// NOTIFY_FRAME_PROVISIONAL_LOAD_START, NOTIFY_FRAME_PROVISIONAL_LOAD_COMMITTED -// and NOTIFY_FAIL_PROVISIONAL_LOAD_WITH_ERROR notifications -// (see notification_types.h). - -// TODO(brettw) this mostly duplicates -// NavigationController::LoadCommittedDetails, it would be nice to unify these -// somehow. -class ProvisionalLoadDetails { - public: - ProvisionalLoadDetails(bool main_frame, - bool in_page_navigation, - const GURL& url, - const std::string& security_info, - bool is_filtered, - bool is_error_page, - int64 frame_id); - virtual ~ProvisionalLoadDetails() { } - - void set_error_code(int error_code) { error_code_ = error_code; } - int error_code() const { return error_code_; } - - void set_transition_type(PageTransition::Type transition_type) { - transition_type_ = transition_type; - } - PageTransition::Type transition_type() const { - return transition_type_; - } - - const GURL& url() const { return url_; } - - bool main_frame() const { return is_main_frame_; } - - bool in_page_navigation() const { return is_in_page_navigation_; } - - int ssl_cert_id() const { return ssl_cert_id_; } - - int ssl_cert_status() const { return ssl_cert_status_; } - - int ssl_security_bits() const { return ssl_security_bits_; } - - int ssl_connection_status() const { return ssl_connection_status_; } - - bool is_content_filtered() const { return is_content_filtered_; } - - bool is_error_page() const { return is_error_page_; } - - int64 frame_id() const { return frame_id_; } - - private: - int error_code_; - PageTransition::Type transition_type_; - GURL url_; - bool is_main_frame_; - bool is_in_page_navigation_; - int ssl_cert_id_; - int ssl_cert_status_; - int ssl_security_bits_; - int ssl_connection_status_; - bool is_content_filtered_; - bool is_error_page_; - int64 frame_id_; - - DISALLOW_COPY_AND_ASSIGN(ProvisionalLoadDetails); -}; +// TODO(jam): remove this file when all files have been converted. +#include "content/browser/tab_contents/provisional_load_details.h" #endif // CHROME_BROWSER_TAB_CONTENTS_PROVISIONAL_LOAD_DETAILS_H_ diff --git a/chrome/browser/tab_contents/render_view_host_manager.h b/chrome/browser/tab_contents/render_view_host_manager.h index 23fb866..7f1be04 100644 --- a/chrome/browser/tab_contents/render_view_host_manager.h +++ b/chrome/browser/tab_contents/render_view_host_manager.h @@ -6,268 +6,7 @@ #define CHROME_BROWSER_TAB_CONTENTS_RENDER_VIEW_HOST_MANAGER_H_ #pragma once -#include "base/basictypes.h" -#include "base/logging.h" -#include "base/scoped_ptr.h" -#include "chrome/browser/renderer_host/render_view_host_delegate.h" -#include "chrome/common/notification_registrar.h" - -class WebUI; -class InterstitialPage; -class NavigationController; -class NavigationEntry; -class Profile; -class RenderWidgetHostView; -class RenderViewHost; -class SiteInstance; - -// Manages RenderViewHosts for a TabContents. Normally there is only one and -// it is easy to do. But we can also have transitions of processes (and hence -// RenderViewHosts) that can get complex. -class RenderViewHostManager - : public RenderViewHostDelegate::RendererManagement { - public: - // Functions implemented by our owner that we need. - // - // TODO(brettw) Clean this up! These are all the functions in TabContents that - // are required to run this class. The design should probably be better such - // that these are more clear. - // - // There is additional complexity that some of the functions we need in - // TabContents are inherited and non-virtual. These are named with - // "RenderManager" so that the duplicate implementation of them will be clear. - class Delegate { - public: - // See tab_contents.h's implementation for more. - virtual bool CreateRenderViewForRenderManager( - RenderViewHost* render_view_host) = 0; - virtual void BeforeUnloadFiredFromRenderManager( - bool proceed, bool* proceed_to_fire_unload) = 0; - virtual void DidStartLoadingFromRenderManager( - RenderViewHost* render_view_host) = 0; - virtual void RenderViewGoneFromRenderManager( - RenderViewHost* render_view_host) = 0; - virtual void UpdateRenderViewSizeForRenderManager() = 0; - virtual void NotifySwappedFromRenderManager() = 0; - virtual NavigationController& GetControllerForRenderManager() = 0; - - // Creates a WebUI object for the given URL if one applies. Ownership of the - // returned pointer will be passed to the caller. If no WebUI applies, - // returns NULL. - virtual WebUI* CreateWebUIForRenderManager(const GURL& url) = 0; - - // Returns the navigation entry of the current navigation, or NULL if there - // is none. - virtual NavigationEntry* - GetLastCommittedNavigationEntryForRenderManager() = 0; - - // Returns true if the location bar should be focused by default rather than - // the page contents. - virtual bool FocusLocationBarByDefault() = 0; - - // Focuses the location bar. - virtual void SetFocusToLocationBar(bool select_all) = 0; - - // Creates a view and sets the size for the specified RVH. - virtual void CreateViewAndSetSizeForRVH(RenderViewHost* rvh) = 0; - - protected: - virtual ~Delegate() {} - }; - - // Both delegate pointers must be non-NULL and are not owned by this class. - // They must outlive this class. The RenderViewHostDelegate is what will be - // installed into all RenderViewHosts that are created. - // - // You must call Init() before using this class. - RenderViewHostManager(RenderViewHostDelegate* render_view_delegate, - Delegate* delegate); - virtual ~RenderViewHostManager(); - - // For arguments, see TabContents constructor. - void Init(Profile* profile, - SiteInstance* site_instance, - int routing_id); - - // Returns the currently actuive RenderViewHost. - // - // This will be non-NULL between Init() and Shutdown(). You may want to NULL - // check it in many cases, however. Windows can send us messages during the - // destruction process after it has been shut down. - RenderViewHost* current_host() const { - return render_view_host_; - } - - // Returns the view associated with the current RenderViewHost, or NULL if - // there is no current one. - RenderWidgetHostView* GetRenderWidgetHostView() const; - - // Returns the pending render view host, or NULL if there is no pending one. - RenderViewHost* pending_render_view_host() const { - return pending_render_view_host_; - } - - // Returns the current committed Web UI or NULL if none applies. - WebUI* web_ui() const { return web_ui_.get(); } - - // Returns the Web UI for the pending navigation, or NULL of none applies. - WebUI* pending_web_ui() const { return pending_web_ui_.get(); } - - // Called when we want to instruct the renderer to navigate to the given - // navigation entry. It may create a new RenderViewHost or re-use an existing - // one. The RenderViewHost to navigate will be returned. Returns NULL if one - // could not be created. - RenderViewHost* Navigate(const NavigationEntry& entry); - - // Instructs the various live views to stop. Called when the user directed the - // page to stop loading. - void Stop(); - - // Notifies the regular and pending RenderViewHosts that a load is or is not - // happening. Even though the message is only for one of them, we don't know - // which one so we tell both. - void SetIsLoading(bool is_loading); - - // Whether to close the tab or not when there is a hang during an unload - // handler. If we are mid-crosssite navigation, then we should proceed - // with the navigation instead of closing the tab. - bool ShouldCloseTabOnUnresponsiveRenderer(); - - // Called when a renderer's main frame navigates. - void DidNavigateMainFrame(RenderViewHost* render_view_host); - - // Set the WebUI after committing a page load. This is useful for navigations - // initiated from a renderer, where we want to give the new renderer WebUI - // privileges from the originating renderer. - void SetWebUIPostCommit(WebUI* web_ui); - - // Called when a provisional load on the given renderer is aborted. - void RendererAbortedProvisionalLoad(RenderViewHost* render_view_host); - - // Sets the passed passed interstitial as the currently showing interstitial. - // |interstitial_page| should be non NULL (use the remove_interstitial_page - // method to unset the interstitial) and no interstitial page should be set - // when there is already a non NULL interstitial page set. - void set_interstitial_page(InterstitialPage* interstitial_page) { - DCHECK(!interstitial_page_ && interstitial_page); - interstitial_page_ = interstitial_page; - } - - // Unsets the currently showing interstitial. - void remove_interstitial_page() { - DCHECK(interstitial_page_); - interstitial_page_ = NULL; - } - - // Returns the currently showing interstitial, NULL if no interstitial is - // showing. - InterstitialPage* interstitial_page() const { - return interstitial_page_; - } - - // RenderViewHostDelegate::RendererManagement implementation. - virtual void ShouldClosePage(bool for_cross_site_transition, bool proceed); - virtual void OnCrossSiteResponse(int new_render_process_host_id, - int new_request_id); - virtual void OnCrossSiteNavigationCanceled(); - - // Called when a RenderViewHost is about to be deleted. - void RenderViewDeleted(RenderViewHost* rvh); - - // Allows a caller to swap in a provided RenderViewHost to replace the - // current RenderViewHost. The current RVH will be shutdown and ultimately - // deleted. - void SwapInRenderViewHost(RenderViewHost* rvh); - - private: - friend class TestTabContents; - friend class RenderViewHostManagerTest; - - // Returns whether this tab should transition to a new renderer for - // cross-site URLs. Enabled unless we see the --process-per-tab command line - // switch. Can be overridden in unit tests. - bool ShouldTransitionCrossSite(); - - // Returns true if the two navigation entries are incompatible in some way - // other than site instances. Cases where this can happen include Web UI - // to regular web pages. It will cause us to swap RenderViewHosts (and hence - // RenderProcessHosts) even if the site instance would otherwise be the same. - // As part of this, we'll also force new SiteInstances and BrowsingInstances. - // Either of the entries may be NULL. - bool ShouldSwapProcessesForNavigation( - const NavigationEntry* cur_entry, - const NavigationEntry* new_entry) const; - - // Returns an appropriate SiteInstance object for the given NavigationEntry, - // possibly reusing the current SiteInstance. - // Never called if --process-per-tab is used. - SiteInstance* GetSiteInstanceForEntry(const NavigationEntry& entry, - SiteInstance* curr_instance); - - // Helper method to create a pending RenderViewHost for a cross-site - // navigation. - bool CreatePendingRenderView(const NavigationEntry& entry, - SiteInstance* instance); - - // Sets up the necessary state for a new RenderViewHost navigating to the - // given entry. - bool InitRenderView(RenderViewHost* render_view_host, - const NavigationEntry& entry); - - // Sets the pending RenderViewHost/WebUI to be the active one. Note that this - // doesn't require the pending render_view_host_ pointer to be non-NULL, since - // there could be Web UI switching as well. Call this for every commit. - void CommitPending(); - - // Helper method to terminate the pending RenderViewHost. - void CancelPending(); - - RenderViewHost* UpdateRendererStateForNavigate(const NavigationEntry& entry); - - // Our delegate, not owned by us. Guaranteed non-NULL. - Delegate* delegate_; - - // Whether a navigation requiring different RenderView's is pending. This is - // either cross-site request is (in the new process model), or when required - // for the view type (like view source versus not). - bool cross_navigation_pending_; - - // Implemented by the owner of this class, this delegate is installed into all - // the RenderViewHosts that we create. - RenderViewHostDelegate* render_view_delegate_; - - // Our RenderView host and its associated Web UI (if any, will be NULL for - // non-DOM-UI pages). This object is responsible for all communication with - // a child RenderView instance. - RenderViewHost* render_view_host_; - scoped_ptr<WebUI> web_ui_; - - // A RenderViewHost used to load a cross-site page. This remains hidden - // while a cross-site request is pending until it calls DidNavigate. It may - // have an associated Web UI, in which case the Web UI pointer will be non- - // NULL. - // - // The pending_web_ui may be non-NULL even when the pending_render_view_host_ - // is. This will happen when we're transitioning between two Web UI pages: - // the RVH won't be swapped, so the pending pointer will be unused, but there - // will be a pending Web UI associated with the navigation. - RenderViewHost* pending_render_view_host_; - scoped_ptr<WebUI> pending_web_ui_; - - // The intersitial page currently shown if any, not own by this class - // (the InterstitialPage is self-owned, it deletes itself when hidden). - InterstitialPage* interstitial_page_; - - NotificationRegistrar registrar_; - - DISALLOW_COPY_AND_ASSIGN(RenderViewHostManager); -}; - -// The "details" for a NOTIFY_RENDER_VIEW_HOST_CHANGED notification. The old -// host can be NULL when the first RenderViewHost is set. -struct RenderViewHostSwitchedDetails { - RenderViewHost* old_host; - RenderViewHost* new_host; -}; +// TODO(jam): remove this file when all files have been converted. +#include "content/browser/tab_contents/render_view_host_manager.h" #endif // CHROME_BROWSER_TAB_CONTENTS_RENDER_VIEW_HOST_MANAGER_H_ diff --git a/chrome/browser/tab_contents/tab_contents.h b/chrome/browser/tab_contents/tab_contents.h index dcadb15..e8dcbdb 100644 --- a/chrome/browser/tab_contents/tab_contents.h +++ b/chrome/browser/tab_contents/tab_contents.h @@ -6,1257 +6,7 @@ #define CHROME_BROWSER_TAB_CONTENTS_TAB_CONTENTS_H_ #pragma once -#include <deque> -#include <map> -#include <string> -#include <vector> - -#include "base/basictypes.h" -#include "base/gtest_prod_util.h" -#include "base/scoped_ptr.h" -#include "base/string16.h" -#include "chrome/browser/download/save_package.h" -#include "chrome/browser/extensions/image_loading_tracker.h" -#include "chrome/browser/fav_icon_helper.h" -#include "chrome/browser/prefs/pref_change_registrar.h" -#include "chrome/browser/renderer_host/render_view_host_delegate.h" -#include "chrome/browser/tab_contents/constrained_window.h" -#include "chrome/browser/tab_contents/language_state.h" -#include "chrome/browser/tab_contents/navigation_controller.h" -#include "chrome/browser/tab_contents/navigation_entry.h" -#include "chrome/browser/tab_contents/page_navigator.h" -#include "chrome/browser/tab_contents/render_view_host_manager.h" -#include "chrome/browser/tab_contents/tab_specific_content_settings.h" -#include "chrome/browser/ui/app_modal_dialogs/js_modal_dialog.h" -#include "chrome/browser/webui/web_ui_factory.h" -#include "chrome/common/notification_registrar.h" -#include "chrome/common/property_bag.h" -#include "chrome/common/renderer_preferences.h" -#include "chrome/common/translate_errors.h" -#include "chrome/common/web_apps.h" -#include "net/base/load_states.h" -#include "ui/gfx/native_widget_types.h" - -#if defined(OS_WIN) -#include "base/win/scoped_handle.h" -#endif - -namespace gfx { -class Rect; -} - -namespace history { -class HistoryAddPageArgs; -} - -namespace prerender { -class PrerenderManager; -class PrerenderPLTRecorder; -} - -namespace printing { -class PrintPreviewMessageHandler; -class PrintViewManager; -} - -namespace safe_browsing { -class ClientSideDetectionHost; -} - -class AutocompleteHistoryManager; -class AutoFillManager; -class BlockedContentContainer; -class WebUI; -class DesktopNotificationHandlerForTC; -class DownloadItem; -class Extension; -class FileSelectHelper; -class InfoBarDelegate; -class LoadNotificationDetails; -class OmniboxSearchHint; -class PluginObserver; -class Profile; -class RenderViewHost; -class SessionStorageNamespace; -class SiteInstance; -class SkBitmap; -class TabContents; -class TabContentsDelegate; -class TabContentsObserver; -class TabContentsSSLHelper; -class TabContentsView; -class URLPattern; -struct RendererPreferences; -struct ThumbnailScore; -struct ViewHostMsg_DomMessage_Params; -struct ViewHostMsg_FrameNavigate_Params; -struct ViewHostMsg_RunFileChooser_Params; -struct WebPreferences; - -// Describes what goes in the main content area of a tab. TabContents is -// the only type of TabContents, and these should be merged together. -class TabContents : public PageNavigator, - public NotificationObserver, - public RenderViewHostDelegate, - public RenderViewHostManager::Delegate, - public JavaScriptAppModalDialogDelegate, - public ImageLoadingTracker::Observer, - public TabSpecificContentSettings::Delegate { - public: - // Flags passed to the TabContentsDelegate.NavigationStateChanged to tell it - // what has changed. Combine them to update more than one thing. - enum InvalidateTypes { - INVALIDATE_URL = 1 << 0, // The URL has changed. - INVALIDATE_TAB = 1 << 1, // The favicon, app icon, or crashed - // state changed. - INVALIDATE_LOAD = 1 << 2, // The loading state has changed. - INVALIDATE_PAGE_ACTIONS = 1 << 3, // Page action icons have changed. - INVALIDATE_BOOKMARK_BAR = 1 << 4, // State of ShouldShowBookmarkBar - // changed. - INVALIDATE_TITLE = 1 << 5, // The title changed. - }; - - // |base_tab_contents| is used if we want to size the new tab contents view - // based on an existing tab contents view. This can be NULL if not needed. - // - // The session storage namespace parameter allows multiple render views and - // tab contentses to share the same session storage (part of the WebStorage - // spec) space. This is useful when restoring tabs, but most callers should - // pass in NULL which will cause a new SessionStorageNamespace to be created. - TabContents(Profile* profile, - SiteInstance* site_instance, - int routing_id, - const TabContents* base_tab_contents, - SessionStorageNamespace* session_storage_namespace); - virtual ~TabContents(); - - static void RegisterUserPrefs(PrefService* prefs); - - // Intrinsic tab state ------------------------------------------------------- - - // Returns the property bag for this tab contents, where callers can add - // extra data they may wish to associate with the tab. Returns a pointer - // rather than a reference since the PropertyAccessors expect this. - const PropertyBag* property_bag() const { return &property_bag_; } - PropertyBag* property_bag() { return &property_bag_; } - - TabContentsDelegate* delegate() const { return delegate_; } - void set_delegate(TabContentsDelegate* d) { delegate_ = d; } - - // Gets the controller for this tab contents. - NavigationController& controller() { return controller_; } - const NavigationController& controller() const { return controller_; } - - // Returns the user profile associated with this TabContents (via the - // NavigationController). - Profile* profile() const { return controller_.profile(); } - - // Returns true if contains content rendered by an extension. - bool HostsExtension() const; - - // Returns the TabContentsSSLHelper, creating it if necessary. - TabContentsSSLHelper* GetSSLHelper(); - - // Returns the SavePackage which manages the page saving job. May be NULL. - SavePackage* save_package() const { return save_package_.get(); } - - // Return the currently active RenderProcessHost and RenderViewHost. Each of - // these may change over time. - RenderProcessHost* GetRenderProcessHost() const; - RenderViewHost* render_view_host() const { - return render_manager_.current_host(); - } - - WebUI* web_ui() const { - return render_manager_.web_ui() ? render_manager_.web_ui() - : render_manager_.pending_web_ui(); - } - - // Returns the currently active RenderWidgetHostView. This may change over - // time and can be NULL (during setup and teardown). - RenderWidgetHostView* GetRenderWidgetHostView() const { - return render_manager_.GetRenderWidgetHostView(); - } - - // The TabContentsView will never change and is guaranteed non-NULL. - TabContentsView* view() const { - return view_.get(); - } - - // Returns the FavIconHelper of this TabContents. - FavIconHelper& fav_icon_helper() { - return *fav_icon_helper_.get(); - } - - // App extensions ------------------------------------------------------------ - - // Sets the extension denoting this as an app. If |extension| is non-null this - // tab becomes an app-tab. TabContents does not listen for unload events for - // the extension. It's up to consumers of TabContents to do that. - // - // NOTE: this should only be manipulated before the tab is added to a browser. - // TODO(sky): resolve if this is the right way to identify an app tab. If it - // is, than this should be passed in the constructor. - void SetExtensionApp(const Extension* extension); - - // Convenience for setting the app extension by id. This does nothing if - // |extension_app_id| is empty, or an extension can't be found given the - // specified id. - void SetExtensionAppById(const std::string& extension_app_id); - - const Extension* extension_app() const { return extension_app_; } - bool is_app() const { return extension_app_ != NULL; } - - // If an app extension has been explicitly set for this TabContents its icon - // is returned. - // - // NOTE: the returned icon is larger than 16x16 (its size is - // Extension::EXTENSION_ICON_SMALLISH). - SkBitmap* GetExtensionAppIcon(); - - // Tab navigation state ------------------------------------------------------ - - // Returns the current navigation properties, which if a navigation is - // pending may be provisional (e.g., the navigation could result in a - // download, in which case the URL would revert to what it was previously). - virtual const GURL& GetURL() const; - virtual const string16& GetTitle() const; - - // Initial title assigned to NavigationEntries from Navigate. - static string16 GetDefaultTitle(); - - // The max PageID of any page that this TabContents has loaded. PageIDs - // increase with each new page that is loaded by a tab. If this is a - // TabContents, then the max PageID is kept separately on each SiteInstance. - // Returns -1 if no PageIDs have yet been seen. - int32 GetMaxPageID(); - - // Updates the max PageID to be at least the given PageID. - void UpdateMaxPageID(int32 page_id); - - // Returns the site instance associated with the current page. By default, - // there is no site instance. TabContents overrides this to provide proper - // access to its site instance. - virtual SiteInstance* GetSiteInstance() const; - - // Defines whether this tab's URL should be displayed in the browser's URL - // bar. Normally this is true so you can see the URL. This is set to false - // for the new tab page and related pages so that the URL bar is empty and - // the user is invited to type into it. - virtual bool ShouldDisplayURL(); - - // Returns the favicon for this tab, or an isNull() bitmap if the tab does not - // have a favicon. The default implementation uses the current navigation - // entry. - SkBitmap GetFavIcon() const; - - // Returns true if we are not using the default favicon. - bool FavIconIsValid() const; - - // Returns whether the favicon should be displayed. If this returns false, no - // space is provided for the favicon, and the favicon is never displayed. - virtual bool ShouldDisplayFavIcon(); - - // Returns a human-readable description the tab's loading state. - virtual string16 GetStatusText() const; - - // Add and remove observers for page navigation notifications. Adding or - // removing multiple times has no effect. The order in which notifications - // are sent to observers is undefined. Clients must be sure to remove the - // observer before they go away. - void AddObserver(TabContentsObserver* observer); - void RemoveObserver(TabContentsObserver* observer); - - // Return whether this tab contents is loading a resource. - bool is_loading() const { return is_loading_; } - - // Returns whether this tab contents is waiting for a first-response for the - // main resource of the page. This controls whether the throbber state is - // "waiting" or "loading." - bool waiting_for_response() const { return waiting_for_response_; } - - const std::string& encoding() const { return encoding_; } - void set_encoding(const std::string& encoding); - void reset_encoding() { - encoding_.clear(); - } - - const WebApplicationInfo& web_app_info() const { - return web_app_info_; - } - - const SkBitmap& app_icon() const { return app_icon_; } - - // Sets an app icon associated with TabContents and fires an INVALIDATE_TITLE - // navigation state change to trigger repaint of title. - void SetAppIcon(const SkBitmap& app_icon); - - bool displayed_insecure_content() const { - return displayed_insecure_content_; - } - - // Internal state ------------------------------------------------------------ - - // This flag indicates whether the tab contents is currently being - // screenshotted by the DraggedTabController. - bool capturing_contents() const { return capturing_contents_; } - void set_capturing_contents(bool cap) { capturing_contents_ = cap; } - - // Indicates whether this tab should be considered crashed. The setter will - // also notify the delegate when the flag is changed. - bool is_crashed() const { - return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED || - crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION || - crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED); - } - base::TerminationStatus crashed_status() const { return crashed_status_; } - int crashed_error_code() const { return crashed_error_code_; } - void SetIsCrashed(base::TerminationStatus status, int error_code); - - // Call this after updating a page action to notify clients about the changes. - void PageActionStateChanged(); - - // Whether the tab is in the process of being destroyed. - // Added as a tentative work-around for focus related bug #4633. This allows - // us not to store focus when a tab is being closed. - bool is_being_destroyed() const { return is_being_destroyed_; } - - // Convenience method for notifying the delegate of a navigation state - // change. See TabContentsDelegate. - void NotifyNavigationStateChanged(unsigned changed_flags); - - // Invoked when the tab contents becomes selected. If you override, be sure - // and invoke super's implementation. - virtual void DidBecomeSelected(); - base::TimeTicks last_selected_time() const { - return last_selected_time_; - } - - // Invoked when the tab contents becomes hidden. - // NOTE: If you override this, call the superclass version too! - virtual void WasHidden(); - - // Activates this contents within its containing window, bringing that window - // to the foreground if necessary. - void Activate(); - - // Deactivates this contents by deactivating its containing window. - void Deactivate(); - - // TODO(brettw) document these. - virtual void ShowContents(); - virtual void HideContents(); - - // Returns true if the before unload and unload listeners need to be - // fired. The value of this changes over time. For example, if true and the - // before unload listener is executed and allows the user to exit, then this - // returns false. - bool NeedToFireBeforeUnload(); - -#ifdef UNIT_TEST - // Expose the render manager for testing. - RenderViewHostManager* render_manager() { return &render_manager_; } -#endif - - // In the underlying RenderViewHostManager, swaps in the provided - // RenderViewHost to replace the current RenderViewHost. The current RVH - // will be shutdown and ultimately deleted. - void SwapInRenderViewHost(RenderViewHost* rvh); - - // Commands ------------------------------------------------------------------ - - // Implementation of PageNavigator. - virtual void OpenURL(const GURL& url, const GURL& referrer, - WindowOpenDisposition disposition, - PageTransition::Type transition); - - // Called by the NavigationController to cause the TabContents to navigate to - // the current pending entry. The NavigationController should be called back - // with CommitPendingEntry/RendererDidNavigate on success or - // DiscardPendingEntry. The callbacks can be inside of this function, or at - // some future time. - // - // The entry has a PageID of -1 if newly created (corresponding to navigation - // to a new URL). - // - // If this method returns false, then the navigation is discarded (equivalent - // to calling DiscardPendingEntry on the NavigationController). - virtual bool NavigateToPendingEntry( - NavigationController::ReloadType reload_type); - - // Stop any pending navigation. - virtual void Stop(); - - // Called on a TabContents when it isn't a popup, but a new window. - virtual void DisassociateFromPopupCount(); - - // Creates a new TabContents with the same state as this one. The returned - // heap-allocated pointer is owned by the caller. - virtual TabContents* Clone(); - - // Shows the page info. - void ShowPageInfo(const GURL& url, - const NavigationEntry::SSLStatus& ssl, - bool show_history); - - // Saves the favicon for the current page. - void SaveFavicon(); - - // Window management --------------------------------------------------------- - - // Create a new window constrained to this TabContents' clip and visibility. - // The window is initialized by using the supplied delegate to obtain basic - // window characteristics, and the supplied view for the content. Note that - // the returned ConstrainedWindow might not yet be visible. - ConstrainedWindow* CreateConstrainedDialog( - ConstrainedWindowDelegate* delegate); - - // Adds a new tab or window with the given already-created contents - void AddNewContents(TabContents* new_contents, - WindowOpenDisposition disposition, - const gfx::Rect& initial_pos, - bool user_gesture); - - // Execute code in this tab. Returns true if the message was successfully - // sent. - bool ExecuteCode(int request_id, const std::string& extension_id, - bool is_js_code, const std::string& code_string, - bool all_frames); - - // Called when the blocked popup notification is shown or hidden. - virtual void PopupNotificationVisibilityChanged(bool visible); - - // Returns the number of constrained windows in this tab. Used by tests. - size_t constrained_window_count() { return child_windows_.size(); } - - typedef std::deque<ConstrainedWindow*> ConstrainedWindowList; - - // Return an iterator for the first constrained window in this tab contents. - ConstrainedWindowList::iterator constrained_window_begin() - { return child_windows_.begin(); } - - // Return an iterator for the last constrained window in this tab contents. - ConstrainedWindowList::iterator constrained_window_end() - { return child_windows_.end(); } - - // Views and focus ----------------------------------------------------------- - // TODO(brettw): Most of these should be removed and the caller should call - // the view directly. - - // Returns the actual window that is focused when this TabContents is shown. - gfx::NativeView GetContentNativeView() const; - - // Returns the NativeView associated with this TabContents. Outside of - // automation in the context of the UI, this is required to be implemented. - gfx::NativeView GetNativeView() const; - - // Returns the bounds of this TabContents in the screen coordinate system. - void GetContainerBounds(gfx::Rect *out) const; - - // Makes the tab the focused window. - void Focus(); - - // Focuses the first (last if |reverse| is true) element in the page. - // Invoked when this tab is getting the focus through tab traversal (|reverse| - // is true when using Shift-Tab). - void FocusThroughTabTraversal(bool reverse); - - // These next two functions are declared on RenderViewHostManager::Delegate - // but also accessed directly by other callers. - - // Returns true if the location bar should be focused by default rather than - // the page contents. The view calls this function when the tab is focused - // to see what it should do. - virtual bool FocusLocationBarByDefault(); - - // Focuses the location bar. - virtual void SetFocusToLocationBar(bool select_all); - - // Creates a view and sets the size for the specified RVH. - virtual void CreateViewAndSetSizeForRVH(RenderViewHost* rvh); - - // Infobars ------------------------------------------------------------------ - - // Adds an InfoBar for the specified |delegate|. - virtual void AddInfoBar(InfoBarDelegate* delegate); - - // Removes the InfoBar for the specified |delegate|. - void RemoveInfoBar(InfoBarDelegate* delegate); - - // Replaces one infobar with another, without any animation in between. - void ReplaceInfoBar(InfoBarDelegate* old_delegate, - InfoBarDelegate* new_delegate); - - // Enumeration and access functions. - size_t infobar_count() const { return infobar_delegates_.size(); } - // WARNING: This does not sanity-check |index|! - InfoBarDelegate* GetInfoBarDelegateAt(size_t index) { - return infobar_delegates_[index]; - } - - // Toolbars and such --------------------------------------------------------- - - // Returns true if a Bookmark Bar should be shown for this tab. - virtual bool ShouldShowBookmarkBar(); - - // Notifies the delegate that a download is about to be started. - // This notification is fired before a local temporary file has been created. - bool CanDownload(int request_id); - - // Notifies the delegate that a download started. - void OnStartDownload(DownloadItem* download); - - // Notify our delegate that some of our content has animated. - void ToolbarSizeChanged(bool is_animating); - - // Called when a ConstrainedWindow we own is about to be closed. - void WillClose(ConstrainedWindow* window); - - // Called when a BlockedContentContainer we own is about to be closed. - void WillCloseBlockedContentContainer(BlockedContentContainer* container); - - // Called when a ConstrainedWindow we own is moved or resized. - void DidMoveOrResize(ConstrainedWindow* window); - - // Interstitials ------------------------------------------------------------- - - // Various other systems need to know about our interstitials. - bool showing_interstitial_page() const { - return render_manager_.interstitial_page() != NULL; - } - - // Sets the passed passed interstitial as the currently showing interstitial. - // |interstitial_page| should be non NULL (use the remove_interstitial_page - // method to unset the interstitial) and no interstitial page should be set - // when there is already a non NULL interstitial page set. - void set_interstitial_page(InterstitialPage* interstitial_page) { - render_manager_.set_interstitial_page(interstitial_page); - } - - // Unsets the currently showing interstitial. - void remove_interstitial_page() { - render_manager_.remove_interstitial_page(); - } - - // Returns the currently showing interstitial, NULL if no interstitial is - // showing. - InterstitialPage* interstitial_page() const { - return render_manager_.interstitial_page(); - } - - // Misc state & callbacks ---------------------------------------------------- - - // Set whether the contents should block javascript message boxes or not. - // Default is not to block any message boxes. - void set_suppress_javascript_messages(bool suppress_javascript_messages) { - suppress_javascript_messages_ = suppress_javascript_messages; - } - - // Prepare for saving the current web page to disk. - void OnSavePage(); - - // Save page with the main HTML file path, the directory for saving resources, - // and the save type: HTML only or complete web page. Returns true if the - // saving process has been initiated successfully. - bool SavePage(const FilePath& main_file, const FilePath& dir_path, - SavePackage::SavePackageType save_type); - - // Tells the user's email client to open a compose window containing the - // current page's URL. - void EmailPageLocation(); - - // Displays asynchronously a print preview (generated by the renderer) if not - // already displayed and ask the user for its preferred print settings with - // the "Print..." dialog box. (managed by the print worker thread). - // TODO(maruel): Creates a snapshot of the renderer to be used for the new - // tab for the printing facility. - void PrintPreview(); - - // Prints the current document immediately. Since the rendering is - // asynchronous, the actual printing will not be completed on the return of - // this function. Returns false if printing is impossible at the moment. - bool PrintNow(); - - // Notify the completion of a printing job. - void PrintingDone(int document_cookie, bool success); - - // Returns true if the active NavigationEntry's page_id equals page_id. - bool IsActiveEntry(int32 page_id); - - const std::string& contents_mime_type() const { - return contents_mime_type_; - } - - // Returns true if this TabContents will notify about disconnection. - bool notify_disconnection() const { return notify_disconnection_; } - - // Override the encoding and reload the page by sending down - // ViewMsg_SetPageEncoding to the renderer. |UpdateEncoding| is kinda - // the opposite of this, by which 'browser' is notified of - // the encoding of the current tab from 'renderer' (determined by - // auto-detect, http header, meta, bom detection, etc). - void SetOverrideEncoding(const std::string& encoding); - - // Remove any user-defined override encoding and reload by sending down - // ViewMsg_ResetPageEncodingToDefault to the renderer. - void ResetOverrideEncoding(); - - void WindowMoveOrResizeStarted(); - - // Sets whether all TabContents added by way of |AddNewContents| should be - // blocked. Transitioning from all blocked to not all blocked results in - // reevaluating any blocked TabContents, which may result in unblocking some - // of the blocked TabContents. - void SetAllContentsBlocked(bool value); - - BlockedContentContainer* blocked_content_container() const { - return blocked_contents_; - } - - RendererPreferences* GetMutableRendererPrefs() { - return &renderer_preferences_; - } - - void set_opener_web_ui_type(WebUITypeID opener_web_ui_type) { - opener_web_ui_type_ = opener_web_ui_type; - } - - // We want to time how long it takes to create a new tab page. This method - // gets called as parts of the new tab page have loaded. - void LogNewTabTime(const std::string& event_name); - - // Set the time when we started to create the new tab page. This time is - // from before we created this TabContents. - void set_new_tab_start_time(const base::TimeTicks& time) { - new_tab_start_time_ = time; - } - - // Notification that tab closing has started. This can be called multiple - // times, subsequent calls are ignored. - void OnCloseStarted(); - - LanguageState& language_state() { - return language_state_; - } - - // Returns true if underlying TabContentsView should accept drag-n-drop. - bool ShouldAcceptDragAndDrop() const; - - // A render view-originated drag has ended. Informs the render view host and - // tab contents delegate. - void SystemDragEnded(); - - // Indicates if this tab was explicitly closed by the user (control-w, close - // tab menu item...). This is false for actions that indirectly close the tab, - // such as closing the window. The setter is maintained by TabStripModel, and - // the getter only useful from within TAB_CLOSED notification - void set_closed_by_user_gesture(bool value) { - closed_by_user_gesture_ = value; - } - bool closed_by_user_gesture() const { return closed_by_user_gesture_; } - - // Overridden from JavaScriptAppModalDialogDelegate: - virtual void OnMessageBoxClosed(IPC::Message* reply_msg, - bool success, - const std::wstring& prompt); - virtual void SetSuppressMessageBoxes(bool suppress_message_boxes); - virtual gfx::NativeWindow GetMessageBoxRootWindow(); - virtual TabContents* AsTabContents(); - virtual ExtensionHost* AsExtensionHost(); - - // The BookmarkDragDelegate is used to forward bookmark drag and drop events - // to extensions. - virtual RenderViewHostDelegate::BookmarkDrag* GetBookmarkDragDelegate(); - - // It is up to callers to call SetBookmarkDragDelegate(NULL) when - // |bookmark_drag| is deleted since this class does not take ownership of - // |bookmark_drag|. - virtual void SetBookmarkDragDelegate( - RenderViewHostDelegate::BookmarkDrag* bookmark_drag); - - // The TabSpecificContentSettings object is used to query the blocked content - // state by various UI elements. - TabSpecificContentSettings* GetTabSpecificContentSettings() const; - - // Updates history with the specified navigation. This is called by - // OnMsgNavigate to update history state. - void UpdateHistoryForNavigation( - scoped_refptr<history::HistoryAddPageArgs> add_page_args); - - // Sends the page title to the history service. This is called when we receive - // the page title and we know we want to update history. - void UpdateHistoryPageTitle(const NavigationEntry& entry); - - // Gets the zoom level for this tab. - double GetZoomLevel() const; - - // Gets the zoom percent for this tab. - int GetZoomPercent(bool* enable_increment, bool* enable_decrement); - - // Shows a fade effect over this tab contents. Repeated calls will be ignored - // until the fade is canceled. If |animate| is true the fade should animate. - void FadeForInstant(bool animate); - - // Immediately removes the fade. - void CancelInstantFade(); - - // Opens view-source tab for this contents. - void ViewSource(); - - // Gets the minimum/maximum zoom percent. - int minimum_zoom_percent() const { return minimum_zoom_percent_; } - int maximum_zoom_percent() const { return maximum_zoom_percent_; } - - int content_restrictions() const { return content_restrictions_; } - - AutocompleteHistoryManager* autocomplete_history_manager() { - return autocomplete_history_manager_.get(); - } - AutoFillManager* autofill_manager() { return autofill_manager_.get(); } - - safe_browsing::ClientSideDetectionHost* safebrowsing_detection_host() { - return safebrowsing_detection_host_.get(); - } - - protected: - // from RenderViewHostDelegate. - virtual bool OnMessageReceived(const IPC::Message& message); - - private: - friend class NavigationController; - // Used to access the child_windows_ (ConstrainedWindowList) for testing - // automation purposes. - friend class TestingAutomationProvider; - - FRIEND_TEST_ALL_PREFIXES(TabContentsTest, NoJSMessageOnInterstitials); - FRIEND_TEST_ALL_PREFIXES(TabContentsTest, UpdateTitle); - FRIEND_TEST_ALL_PREFIXES(TabContentsTest, CrossSiteCantPreemptAfterUnload); - FRIEND_TEST_ALL_PREFIXES(FormStructureBrowserTest, HTMLFiles); - FRIEND_TEST_ALL_PREFIXES(NavigationControllerTest, HistoryNavigate); - FRIEND_TEST_ALL_PREFIXES(RenderViewHostManagerTest, PageDoesBackAndReload); - - // Temporary until the view/contents separation is complete. - friend class TabContentsView; -#if defined(OS_WIN) - friend class TabContentsViewWin; -#elif defined(OS_MACOSX) - friend class TabContentsViewMac; -#elif defined(TOOLKIT_USES_GTK) - friend class TabContentsViewGtk; -#endif - - // So InterstitialPage can access SetIsLoading. - friend class InterstitialPage; - - // TODO(brettw) TestTabContents shouldn't exist! - friend class TestTabContents; - - // Used to access the CreateHistoryAddPageArgs member function. - friend class ExternalTabContainer; - - // Used to access RVH Delegates. - friend class prerender::PrerenderManager; - - // Add all the TabContentObservers. - void AddObservers(); - - // Message handlers. - void OnDidStartProvisionalLoadForFrame(int64 frame_id, - bool main_frame, - const GURL& url); - void OnDidRedirectProvisionalLoad(int32 page_id, - const GURL& source_url, - const GURL& target_url); - void OnDidFailProvisionalLoadWithError(int64 frame_id, - bool main_frame, - int error_code, - const GURL& url, - bool showing_repost_interstitial); - void OnDidLoadResourceFromMemoryCache(const GURL& url, - const std::string& security_info); - void OnDidDisplayInsecureContent(); - void OnDidRunInsecureContent(const std::string& security_origin, - const GURL& target_url); - void OnDocumentLoadedInFrame(int64 frame_id); - void OnDidFinishLoad(int64 frame_id); - void OnUpdateContentRestrictions(int restrictions); - void OnPDFHasUnsupportedFeature(); - - void OnGoToEntryAtOffset(int offset); - void OnDidGetApplicationInfo(int32 page_id, const WebApplicationInfo& info); - void OnInstallApplication(const WebApplicationInfo& info); - void OnPageContents(const GURL& url, - int32 page_id, - const string16& contents, - const std::string& language, - bool page_translatable); - void OnPageTranslated(int32 page_id, - const std::string& original_lang, - const std::string& translated_lang, - TranslateErrors::Type error_type); - void OnSetSuggestions(int32 page_id, - const std::vector<std::string>& suggestions); - void OnInstantSupportDetermined(int32 page_id, bool result); - void OnRunFileChooser(const ViewHostMsg_RunFileChooser_Params& params); - - // Changes the IsLoading state and notifies delegate as needed - // |details| is used to provide details on the load that just finished - // (but can be null if not applicable). Can be overridden. - void SetIsLoading(bool is_loading, - LoadNotificationDetails* details); - - // Adds the incoming |new_contents| to the |blocked_contents_| container. - void AddPopup(TabContents* new_contents, - const gfx::Rect& initial_pos); - - // Called by derived classes to indicate that we're no longer waiting for a - // response. This won't actually update the throbber, but it will get picked - // up at the next animation step if the throbber is going. - void SetNotWaitingForResponse() { waiting_for_response_ = false; } - - ConstrainedWindowList child_windows_; - - // Expires InfoBars that need to be expired, according to the state carried - // in |details|, in response to a new NavigationEntry being committed (the - // user navigated to another page). - void ExpireInfoBars( - const NavigationController::LoadCommittedDetails& details); - - // Returns the WebUI for the current state of the tab. This will either be - // the pending WebUI, the committed WebUI, or NULL. - WebUI* GetWebUIForCurrentState(); - - // Navigation helpers -------------------------------------------------------- - // - // These functions are helpers for Navigate() and DidNavigate(). - - // Handles post-navigation tasks in DidNavigate AFTER the entry has been - // committed to the navigation controller. Note that the navigation entry is - // not provided since it may be invalid/changed after being committed. The - // current navigation entry is in the NavigationController at this point. - void DidNavigateMainFramePostCommit( - const NavigationController::LoadCommittedDetails& details, - const ViewHostMsg_FrameNavigate_Params& params); - void DidNavigateAnyFramePostCommit( - RenderViewHost* render_view_host, - const NavigationController::LoadCommittedDetails& details, - const ViewHostMsg_FrameNavigate_Params& params); - - // Closes all constrained windows. - void CloseConstrainedWindows(); - - // Send the alternate error page URL to the renderer. This method is virtual - // so special html pages can override this (e.g., the new tab page). - virtual void UpdateAlternateErrorPageURL(); - - // Send webkit specific settings to the renderer. - void UpdateWebPreferences(); - - // Instruct the renderer to update the zoom level. - void UpdateZoomLevel(); - - // If our controller was restored and the page id is > than the site - // instance's page id, the site instances page id is updated as well as the - // renderers max page id. - void UpdateMaxPageIDIfNecessary(SiteInstance* site_instance, - RenderViewHost* rvh); - - // Returns the history::HistoryAddPageArgs to use for adding a page to - // history. - scoped_refptr<history::HistoryAddPageArgs> CreateHistoryAddPageArgs( - const GURL& virtual_url, - const NavigationController::LoadCommittedDetails& details, - const ViewHostMsg_FrameNavigate_Params& params); - - // Saves the given title to the navigation entry and does associated work. It - // will update history and the view for the new title, and also synthesize - // titles for file URLs that have none (so we require that the URL of the - // entry already be set). - // - // This is used as the backend for state updates, which include a new title, - // or the dedicated set title message. It returns true if the new title is - // different and was therefore updated. - bool UpdateTitleForEntry(NavigationEntry* entry, const std::wstring& title); - - // Causes the TabContents to navigate in the right renderer to |entry|, which - // must be already part of the entries in the navigation controller. - // This does not change the NavigationController state. - bool NavigateToEntry(const NavigationEntry& entry, - NavigationController::ReloadType reload_type); - - // Misc non-view stuff ------------------------------------------------------- - - // Helper functions for sending notifications. - void NotifySwapped(); - void NotifyConnected(); - void NotifyDisconnected(); - - // TabSpecificContentSettings::Delegate implementation. - virtual void OnContentSettingsAccessed(bool content_was_blocked); - - // RenderViewHostDelegate ---------------------------------------------------- - - // RenderViewHostDelegate implementation. - virtual RenderViewHostDelegate::View* GetViewDelegate(); - virtual RenderViewHostDelegate::RendererManagement* - GetRendererManagementDelegate(); - virtual RenderViewHostDelegate::ContentSettings* GetContentSettingsDelegate(); - virtual RenderViewHostDelegate::SSL* GetSSLDelegate(); - virtual AutomationResourceRoutingDelegate* - GetAutomationResourceRoutingDelegate(); - virtual TabContents* GetAsTabContents(); - virtual ViewType::Type GetRenderViewType() const; - virtual int GetBrowserWindowID() const; - virtual void RenderViewCreated(RenderViewHost* render_view_host); - virtual void RenderViewReady(RenderViewHost* render_view_host); - virtual void RenderViewGone(RenderViewHost* render_view_host, - base::TerminationStatus status, - int error_code); - virtual void RenderViewDeleted(RenderViewHost* render_view_host); - virtual void DidNavigate(RenderViewHost* render_view_host, - const ViewHostMsg_FrameNavigate_Params& params); - virtual void UpdateState(RenderViewHost* render_view_host, - int32 page_id, - const std::string& state); - virtual void UpdateTitle(RenderViewHost* render_view_host, - int32 page_id, - const std::wstring& title); - virtual void UpdateEncoding(RenderViewHost* render_view_host, - const std::string& encoding); - virtual void UpdateTargetURL(int32 page_id, const GURL& url); - virtual void UpdateThumbnail(const GURL& url, - const SkBitmap& bitmap, - const ThumbnailScore& score); - virtual void UpdateInspectorSetting(const std::string& key, - const std::string& value); - virtual void ClearInspectorSettings(); - virtual void Close(RenderViewHost* render_view_host); - virtual void RequestMove(const gfx::Rect& new_bounds); - virtual void DidStartLoading(); - virtual void DidStopLoading(); - virtual void DidChangeLoadProgress(double progress); - virtual void DocumentOnLoadCompletedInMainFrame( - RenderViewHost* render_view_host, - int32 page_id); - virtual void RequestOpenURL(const GURL& url, const GURL& referrer, - WindowOpenDisposition disposition); - virtual void DomOperationResponse(const std::string& json_string, - int automation_id); - virtual void ProcessWebUIMessage(const ViewHostMsg_DomMessage_Params& params); - virtual void ProcessExternalHostMessage(const std::string& message, - const std::string& origin, - const std::string& target); - virtual void RunJavaScriptMessage(const std::wstring& message, - const std::wstring& default_prompt, - const GURL& frame_url, - const int flags, - IPC::Message* reply_msg, - bool* did_suppress_message); - virtual void RunBeforeUnloadConfirm(const std::wstring& message, - IPC::Message* reply_msg); - virtual void ShowModalHTMLDialog(const GURL& url, int width, int height, - const std::string& json_arguments, - IPC::Message* reply_msg); - virtual GURL GetAlternateErrorPageURL() const; - virtual RendererPreferences GetRendererPrefs(Profile* profile) const; - virtual WebPreferences GetWebkitPrefs(); - virtual void OnUserGesture(); - virtual void OnIgnoredUIEvent(); - virtual void OnJSOutOfMemory(); - virtual void OnCrossSiteResponse(int new_render_process_host_id, - int new_request_id); - virtual void RendererUnresponsive(RenderViewHost* render_view_host, - bool is_during_unload); - virtual void RendererResponsive(RenderViewHost* render_view_host); - virtual void LoadStateChanged(const GURL& url, net::LoadState load_state, - uint64 upload_position, uint64 upload_size); - virtual bool IsExternalTabContainer() const; - virtual void DidInsertCSS(); - virtual void FocusedNodeChanged(bool is_editable_node); - virtual void UpdateZoomLimits(int minimum_percent, - int maximum_percent, - bool remember); - virtual void WorkerCrashed(); - - // RenderViewHostManager::Delegate ------------------------------------------- - - // Blocks/unblocks interaction with renderer process. - void BlockTabContent(bool blocked); - - virtual void BeforeUnloadFiredFromRenderManager( - bool proceed, - bool* proceed_to_fire_unload); - virtual void DidStartLoadingFromRenderManager( - RenderViewHost* render_view_host); - virtual void RenderViewGoneFromRenderManager( - RenderViewHost* render_view_host); - virtual void UpdateRenderViewSizeForRenderManager(); - virtual void NotifySwappedFromRenderManager(); - virtual NavigationController& GetControllerForRenderManager(); - virtual WebUI* CreateWebUIForRenderManager(const GURL& url); - virtual NavigationEntry* GetLastCommittedNavigationEntryForRenderManager(); - - // Initializes the given renderer if necessary and creates the view ID - // corresponding to this view host. If this method is not called and the - // process is not shared, then the TabContents will act as though the renderer - // is not running (i.e., it will render "sad tab"). This method is - // automatically called from LoadURL. - // - // If you are attaching to an already-existing RenderView, you should call - // InitWithExistingID. - virtual bool CreateRenderViewForRenderManager( - RenderViewHost* render_view_host); - - // NotificationObserver ------------------------------------------------------ - - virtual void Observe(NotificationType type, - const NotificationSource& source, - const NotificationDetails& details); - - // App extensions related methods: - - // Returns the first extension whose extent contains |url|. - const Extension* GetExtensionContaining(const GURL& url); - - // Resets app_icon_ and if |extension| is non-null creates a new - // ImageLoadingTracker to load the extension's image. - void UpdateExtensionAppIcon(const Extension* extension); - - // ImageLoadingTracker::Observer. - virtual void OnImageLoaded(SkBitmap* image, ExtensionResource resource, - int index); - - // Checks with the PrerenderManager if the specified URL has been preloaded, - // and if so, swap the RenderViewHost with the preload into this TabContents - // object. - bool MaybeUsePreloadedPage(const GURL& url); - - // Data for core operation --------------------------------------------------- - - // Delegate for notifying our owner about stuff. Not owned by us. - TabContentsDelegate* delegate_; - - // Handles the back/forward list and loading. - NavigationController controller_; - - // The corresponding view. - scoped_ptr<TabContentsView> view_; - - // Helper classes ------------------------------------------------------------ - - // Manages creation and swapping of render views. - RenderViewHostManager render_manager_; - - // Stores random bits of data for others to associate with this object. - PropertyBag property_bag_; - - // Registers and unregisters us for notifications. - NotificationRegistrar registrar_; - - // Registers and unregisters for pref notifications. - PrefChangeRegistrar pref_change_registrar_; - - // Handles print job for this contents. - scoped_ptr<printing::PrintViewManager> printing_; - - // Handles print preview for this contents. - scoped_ptr<printing::PrintPreviewMessageHandler> print_preview_; - - // SavePackage, lazily created. - scoped_refptr<SavePackage> save_package_; - - // AutocompleteHistoryManager. - scoped_ptr<AutocompleteHistoryManager> autocomplete_history_manager_; - - // AutoFillManager. - scoped_ptr<AutoFillManager> autofill_manager_; - - // Handles plugin messages. - scoped_ptr<PluginObserver> plugin_observer_; - - // Prerender PageLoadTime Recorder. - scoped_ptr<prerender::PrerenderPLTRecorder> prerender_plt_recorder_; - - // TabContentsSSLHelper, lazily created. - scoped_ptr<TabContentsSSLHelper> ssl_helper_; - - // FileSelectHelper, lazily created. - scoped_ptr<FileSelectHelper> file_select_helper_; - - // Handles drag and drop event forwarding to extensions. - BookmarkDrag* bookmark_drag_; - - // Handles downloading favicons. - scoped_ptr<FavIconHelper> fav_icon_helper_; - - // Cached web app info data. - WebApplicationInfo web_app_info_; - - // Cached web app icon. - SkBitmap app_icon_; - - // RenderViewHost::ContentSettingsDelegate. - scoped_ptr<TabSpecificContentSettings> content_settings_delegate_; - - // Handles desktop notification IPCs. - scoped_ptr<DesktopNotificationHandlerForTC> desktop_notification_handler_; - - // Handles IPCs related to SafeBrowsing client-side phishing detection. - scoped_ptr<safe_browsing::ClientSideDetectionHost> - safebrowsing_detection_host_; - - // Data for loading state ---------------------------------------------------- - - // Indicates whether we're currently loading a resource. - bool is_loading_; - - // Indicates if the tab is considered crashed. - base::TerminationStatus crashed_status_; - int crashed_error_code_; - - // See waiting_for_response() above. - bool waiting_for_response_; - - // Indicates the largest PageID we've seen. This field is ignored if we are - // a TabContents, in which case the max page ID is stored separately with - // each SiteInstance. - // TODO(brettw) this seems like it can be removed according to the comment. - int32 max_page_id_; - - // System time at which the current load was started. - base::TimeTicks current_load_start_; - - // The current load state and the URL associated with it. - net::LoadState load_state_; - string16 load_state_host_; - // Upload progress, for displaying in the status bar. - // Set to zero when there is no significant upload happening. - uint64 upload_size_; - uint64 upload_position_; - - // Data for current page ----------------------------------------------------- - - // Whether we have a (non-empty) title for the current page. - // Used to prevent subsequent title updates from affecting history. This - // prevents some weirdness because some AJAXy apps use titles for status - // messages. - bool received_page_title_; - - // When a navigation occurs, we record its contents MIME type. It can be - // used to check whether we can do something for some special contents. - std::string contents_mime_type_; - - // Character encoding. - std::string encoding_; - - // Object that holds any blocked TabContents spawned from this TabContents. - BlockedContentContainer* blocked_contents_; - - // Should we block all child TabContents this attempts to spawn. - bool all_contents_blocked_; - - // TODO(pkasting): Hack to try and fix Linux browser tests. - bool dont_notify_render_view_; - - // True if this is a secure page which displayed insecure content. - bool displayed_insecure_content_; - - // Data for shelves and stuff ------------------------------------------------ - - // Delegates for InfoBars associated with this TabContents. - std::vector<InfoBarDelegate*> infobar_delegates_; - - // Data for app extensions --------------------------------------------------- - - // If non-null this tab is an app tab and this is the extension the tab was - // created for. - const Extension* extension_app_; - - // Icon for extension_app_ (if non-null) or extension_for_current_page_. - SkBitmap extension_app_icon_; - - // Used for loading extension_app_icon_. - scoped_ptr<ImageLoadingTracker> extension_app_image_loader_; - - // Data for misc internal state ---------------------------------------------- - - // See capturing_contents() above. - bool capturing_contents_; - - // See getter above. - bool is_being_destroyed_; - - // Indicates whether we should notify about disconnection of this - // TabContents. This is used to ensure disconnection notifications only - // happen if a connection notification has happened and that they happen only - // once. - bool notify_disconnection_; - - // Maps from handle to page_id. - typedef std::map<FaviconService::Handle, int32> HistoryRequestMap; - HistoryRequestMap history_requests_; - -#if defined(OS_WIN) - // Handle to an event that's set when the page is showing a message box (or - // equivalent constrained window). Plugin processes check this to know if - // they should pump messages then. - base::win::ScopedHandle message_box_active_; -#endif - - // The time that the last javascript message was dismissed. - base::TimeTicks last_javascript_message_dismissal_; - - // True if the user has decided to block future javascript messages. This is - // reset on navigations to false on navigations. - bool suppress_javascript_messages_; - - // Set to true when there is an active "before unload" dialog. When true, - // we've forced the throbber to start in Navigate, and we need to remember to - // turn it off in OnJavaScriptMessageBoxClosed if the navigation is canceled. - bool is_showing_before_unload_dialog_; - - // Shows an info-bar to users when they search from a known search engine and - // have never used the monibox for search before. - scoped_ptr<OmniboxSearchHint> omnibox_search_hint_; - - // Settings that get passed to the renderer process. - RendererPreferences renderer_preferences_; - - // If this tab was created from a renderer using window.open, this will be - // non-NULL and represent the WebUI of the opening renderer. - WebUITypeID opener_web_ui_type_; - - // The time that we started to create the new tab page. - base::TimeTicks new_tab_start_time_; - - // The time that we started to close the tab. - base::TimeTicks tab_close_start_time_; - - // The time that this tab was last selected. - base::TimeTicks last_selected_time_; - - // Information about the language the page is in and has been translated to. - LanguageState language_state_; - - // See description above setter. - bool closed_by_user_gesture_; - - // Minimum/maximum zoom percent. - int minimum_zoom_percent_; - int maximum_zoom_percent_; - // If true, the default zoom limits have been overriden for this tab, in which - // case we don't want saved settings to apply to it and we don't want to - // remember it. - bool temporary_zoom_settings_; - - // A list of observers notified when page state changes. Weak references. - ObserverList<TabContentsObserver> observers_; - - // Content restrictions, used to disable print/copy etc based on content's - // (full-page plugins for now only) permissions. - int content_restrictions_; - - DISALLOW_COPY_AND_ASSIGN(TabContents); -}; +// TODO(jam): remove this file when all files have been converted. +#include "content/browser/tab_contents/tab_contents.h" #endif // CHROME_BROWSER_TAB_CONTENTS_TAB_CONTENTS_H_ diff --git a/chrome/browser/tab_contents/tab_contents_delegate.h b/chrome/browser/tab_contents/tab_contents_delegate.h index 10891a5..23d5803 100644 --- a/chrome/browser/tab_contents/tab_contents_delegate.h +++ b/chrome/browser/tab_contents/tab_contents_delegate.h @@ -6,323 +6,7 @@ #define CHROME_BROWSER_TAB_CONTENTS_TAB_CONTENTS_DELEGATE_H_ #pragma once -#include <string> -#include <vector> - -#include "base/basictypes.h" -#include "chrome/browser/automation/automation_resource_routing_delegate.h" -#include "chrome/browser/tab_contents/navigation_entry.h" -#include "chrome/common/content_settings_types.h" -#include "chrome/common/navigation_types.h" -#include "chrome/common/page_transition_types.h" -#include "ui/gfx/native_widget_types.h" -#include "webkit/glue/window_open_disposition.h" - -namespace gfx { -class Point; -class Rect; -class Size; -} - -namespace history { -class HistoryAddPageArgs; -} - -struct ContextMenuParams; -class DownloadItem; -class GURL; -class HtmlDialogUIDelegate; -struct NativeWebKeyboardEvent; -class Profile; -class RenderViewHost; -class TabContents; -struct WebApplicationInfo; - -// Objects implement this interface to get notified about changes in the -// TabContents and to provide necessary functionality. -class TabContentsDelegate : public AutomationResourceRoutingDelegate { - public: - // Opens a new URL inside the passed in TabContents (if source is 0 open - // in the current front-most tab), unless |disposition| indicates the url - // should be opened in a new tab or window. - // - // A NULL source indicates the current tab (callers should probably use - // OpenURL() for these cases which does it for you). - virtual void OpenURLFromTab(TabContents* source, - const GURL& url, const GURL& referrer, - WindowOpenDisposition disposition, - PageTransition::Type transition) = 0; - - // Called to inform the delegate that the tab content's navigation state - // changed. The |changed_flags| indicates the parts of the navigation state - // that have been updated, and is any combination of the - // |TabContents::InvalidateTypes| bits. - virtual void NavigationStateChanged(const TabContents* source, - unsigned changed_flags) = 0; - - // Returns the set of headers to add to the navigation request. Use - // net::HttpUtil::AppendHeaderIfMissing to build the set of headers. - virtual std::string GetNavigationHeaders(const GURL& url); - - // Creates a new tab with the already-created TabContents 'new_contents'. - // The window for the added contents should be reparented correctly when this - // method returns. If |disposition| is NEW_POPUP, |pos| should hold the - // initial position. - virtual void AddNewContents(TabContents* source, - TabContents* new_contents, - WindowOpenDisposition disposition, - const gfx::Rect& initial_pos, - bool user_gesture) = 0; - - // Selects the specified contents, bringing its container to the front. - virtual void ActivateContents(TabContents* contents) = 0; - - // Deactivates the specified contents by deactivating its container and - // potentialy moving it to the back of the Z order. - virtual void DeactivateContents(TabContents* contents) = 0; - - // Notifies the delegate that this contents is starting or is done loading - // some resource. The delegate should use this notification to represent - // loading feedback. See TabContents::is_loading() - virtual void LoadingStateChanged(TabContents* source) = 0; - - // Notifies the delegate that the page has made some progress loading. - // |progress| is a value between 0.0 (nothing loaded) to 1.0 (page fully - // loaded). - // Note that to receive this notification, you must have called - // SetReportLoadProgressEnabled(true) in the render view. - virtual void LoadProgressChanged(double progress); - - // Request the delegate to close this tab contents, and do whatever cleanup - // it needs to do. - virtual void CloseContents(TabContents* source) = 0; - - // Request the delegate to move this tab contents to the specified position - // in screen coordinates. - virtual void MoveContents(TabContents* source, const gfx::Rect& pos) = 0; - - // Causes the delegate to detach |source| and clean up any internal data - // pointing to it. After this call ownership of |source| passes to the - // caller, and it is safe to call "source->set_delegate(someone_else);". - virtual void DetachContents(TabContents* source); - - // Called to determine if the TabContents is contained in a popup window. - virtual bool IsPopup(const TabContents* source) const; - - // If |source| is constrained, returns the tab containing it. Otherwise - // returns |source|. - virtual TabContents* GetConstrainingContents(TabContents* source); - - // Returns true if constrained windows should be focused. Default is true. - virtual bool ShouldFocusConstrainedWindow(); - - // Invoked prior to the TabContents showing a constrained window. - virtual void WillShowConstrainedWindow(TabContents* source); - - // Notification that some of our content has changed size as - // part of an animation. - virtual void ToolbarSizeChanged(TabContents* source, bool is_animating) = 0; - - // Notification that the target URL has changed. - virtual void UpdateTargetURL(TabContents* source, const GURL& url) = 0; - - // Notification that there was a mouse event, along with the absolute - // coordinates of the mouse pointer and whether it was a normal motion event - // (otherwise, the pointer left the contents area). - virtual void ContentsMouseEvent( - TabContents* source, const gfx::Point& location, bool motion); - - // Request the delegate to change the zoom level of the current tab. - virtual void ContentsZoomChange(bool zoom_in); - - // Notifies the delegate that something has changed about what content the - // TabContents is blocking. Interested parties should call - // TabContents::IsContentBlocked() to see if something they care about has - // changed. - virtual void OnContentSettingsChange(TabContents* source); - - // Check whether this contents is inside a window dedicated to running a web - // application. - virtual bool IsApplication() const; - - // Detach the given tab and convert it to a "webapp" view. The tab must be - // a TabContents with a valid WebApp set. - virtual void ConvertContentsToApplication(TabContents* source); - - // Whether the specified tab can be reloaded. - // Reloading can be disabled e. g. for the DevTools window. - virtual bool CanReloadContents(TabContents* source) const; - - // Show a dialog with HTML content. |delegate| contains a pointer to the - // delegate who knows how to display the dialog (which file URL and JSON - // string input to use during initialization). |parent_window| is the window - // that should be parent of the dialog, or NULL for the default. - virtual void ShowHtmlDialog(HtmlDialogUIDelegate* delegate, - gfx::NativeWindow parent_window); - - // Invoked prior to showing before unload handler confirmation dialog. - virtual void WillRunBeforeUnloadConfirm(); - - // Returns true if javascript dialogs and unload alerts are suppressed. - // Default is false. - virtual bool ShouldSuppressDialogs(); - - // Tells us that we've finished firing this tab's beforeunload event. - // The proceed bool tells us whether the user chose to proceed closing the - // tab. Returns true if the tab can continue on firing it's unload event. - // If we're closing the entire browser, then we'll want to delay firing - // unload events until all the beforeunload events have fired. - virtual void BeforeUnloadFired(TabContents* tab, - bool proceed, - bool* proceed_to_fire_unload); - - // Send IPC to external host. Default implementation is do nothing. - virtual void ForwardMessageToExternalHost(const std::string& message, - const std::string& origin, - const std::string& target); - - // If the delegate is hosting tabs externally. - virtual bool IsExternalTabContainer() const; - - // Sets focus to the location bar or some other place that is appropriate. - // This is called when the tab wants to encourage user input, like for the - // new tab page. - virtual void SetFocusToLocationBar(bool select_all); - - // Returns whether the page should be focused when transitioning from crashed - // to live. Default is true. - virtual bool ShouldFocusPageAfterCrash(); - - // Called when a popup select is about to be displayed. The delegate can use - // this to disable inactive rendering for the frame in the window the select - // is opened within if necessary. - virtual void RenderWidgetShowing(); - - // This is called when WebKit tells us that it is done tabbing through - // controls on the page. Provides a way for TabContentsDelegates to handle - // this. Returns true if the delegate successfully handled it. - virtual bool TakeFocus(bool reverse); - - // Invoked when the page loses mouse capture. - virtual void LostCapture(); - - // Changes the blocked state of the tab at |index|. TabContents are - // considered blocked while displaying a tab modal dialog. During that time - // renderer host will ignore any UI interaction within TabContent outside of - // the currently displaying dialog. - virtual void SetTabContentBlocked(TabContents* contents, bool blocked); - - // Notification that |tab_contents| has gained focus. - virtual void TabContentsFocused(TabContents* tab_content); - - // Return much extra vertical space should be allotted to the - // render view widget during various animations (e.g. infobar closing). - // This is used to make painting look smoother. - virtual int GetExtraRenderViewHeight() const; - - virtual bool CanDownload(int request_id); - - virtual void OnStartDownload(DownloadItem* download, TabContents* tab); - - // Returns true if the context menu operation was handled by the delegate. - virtual bool HandleContextMenu(const ContextMenuParams& params); - - // Returns true if the context menu command was handled - virtual bool ExecuteContextMenuCommand(int command); - - // Shows the page info using the specified information. - // |url| is the url of the page/frame the info applies to, |ssl| is the SSL - // information for that page/frame. If |show_history| is true, a section - // showing how many times that URL has been visited is added to the page info. - virtual void ShowPageInfo(Profile* profile, - const GURL& url, - const NavigationEntry::SSLStatus& ssl, - bool show_history); - - // Opens source view for given tab contents that is navigated to the given - // page url. - virtual void ViewSourceForTab(TabContents* source, const GURL& page_url); - - // Allows delegates to handle keyboard events before sending to the renderer. - // Returns true if the |event| was handled. Otherwise, if the |event| would be - // handled in HandleKeyboardEvent() method as a normal keyboard shortcut, - // |*is_keyboard_shortcut| should be set to true. - virtual bool PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event, - bool* is_keyboard_shortcut); - - // Allows delegates to handle unhandled keyboard messages coming back from - // the renderer. - virtual void HandleKeyboardEvent(const NativeWebKeyboardEvent& event); - - virtual void HandleMouseUp(); - virtual void HandleMouseActivate(); - - // Render view drag n drop ended. - virtual void DragEnded(); - - // Shows the repost form confirmation dialog box. - virtual void ShowRepostFormWarningDialog(TabContents* tab_contents); - - // Shows the Content Settings dialog for a given content type. - virtual void ShowContentSettingsWindow(ContentSettingsType content_type); - - // Shows the cookies collected in the tab contents. - virtual void ShowCollectedCookiesDialog(TabContents* tab_contents); - - // Allows delegate to override navigation to the history entries. - // Returns true to allow TabContents to continue with the default processing. - virtual bool OnGoToEntryOffset(int offset); - - // Returns whether this tab contents should add the specified navigation to - // history. - virtual bool ShouldAddNavigationToHistory( - const history::HistoryAddPageArgs& add_page_args, - NavigationType::Type navigation_type); - - // Notification that a user's request to install an application has completed. - virtual void OnDidGetApplicationInfo(TabContents* tab_contents, - int32 page_id); - - // Notification when an application programmatically requests installation. - virtual void OnInstallApplication(TabContents* tab_contents, - const WebApplicationInfo& app_info); - - // Returns the native window framing the view containing the tab contents. - virtual gfx::NativeWindow GetFrameNativeWindow(); - - // Notifies the delegate about the creation of a new TabContents. This - // typically happens when popups are created. - virtual void TabContentsCreated(TabContents* new_contents); - - // Returns whether infobars are enabled. Overrideable by child classes. - virtual bool infobars_enabled(); - - // Whether the renderer should report its preferred size when it changes by - // calling UpdatePreferredSize(). - // Note that this is set when the RenderViewHost is created and cannot be - // changed after that. - virtual bool ShouldEnablePreferredSizeNotifications(); - - // Notification that the preferred size of the contents has changed. - // Only called if ShouldEnablePreferredSizeNotifications() returns true. - virtual void UpdatePreferredSize(const gfx::Size& pref_size); - - // Notifies the delegate that the page has a suggest result. - virtual void OnSetSuggestions(int32 page_id, - const std::vector<std::string>& result); - - // Notifies the delegate whether the page supports instant-style interaction. - virtual void OnInstantSupportDetermined(int32 page_id, bool result); - - // Notifies the delegate that the content restrictions for this tab has - // changed. - virtual void ContentRestrictionsChanged(TabContents* source); - - // Returns true if the hung renderer dialog should be shown. Default is true. - virtual bool ShouldShowHungRendererDialog(); - - protected: - virtual ~TabContentsDelegate(); -}; +// TODO(jam): remove this file when all files have been converted. +#include "content/browser/tab_contents/tab_contents_delegate.h" #endif // CHROME_BROWSER_TAB_CONTENTS_TAB_CONTENTS_DELEGATE_H_ diff --git a/chrome/browser/tab_contents/tab_contents_observer.h b/chrome/browser/tab_contents/tab_contents_observer.h index 55a609c..0af56b32 100644 --- a/chrome/browser/tab_contents/tab_contents_observer.h +++ b/chrome/browser/tab_contents/tab_contents_observer.h @@ -5,65 +5,7 @@ #ifndef CHROME_BROWSER_TAB_CONTENTS_TAB_CONTENTS_OBSERVER_H_ #define CHROME_BROWSER_TAB_CONTENTS_TAB_CONTENTS_OBSERVER_H_ -#include "chrome/browser/tab_contents/navigation_controller.h" -#include "ipc/ipc_channel.h" - -struct ViewHostMsg_FrameNavigate_Params; - -// An observer API implemented by classes which are interested in various page -// load events from TabContents. They also get a chance to filter IPC messages. -class TabContentsObserver : public IPC::Channel::Listener { - public: - virtual void NavigateToPendingEntry() { } - - virtual void DidNavigateMainFramePostCommit( - const NavigationController::LoadCommittedDetails& details, - const ViewHostMsg_FrameNavigate_Params& params) { } - virtual void DidNavigateAnyFramePostCommit( - const NavigationController::LoadCommittedDetails& details, - const ViewHostMsg_FrameNavigate_Params& params) { } - - virtual void DidStartLoading() { } - virtual void DidStopLoading() { } - -#if 0 - // For unifying with delegate... - - // Notifies the delegate that this contents is starting or is done loading - // some resource. The delegate should use this notification to represent - // loading feedback. See TabContents::is_loading() - virtual void LoadingStateChanged(TabContents* contents) { } - // Called to inform the delegate that the tab content's navigation state - // changed. The |changed_flags| indicates the parts of the navigation state - // that have been updated, and is any combination of the - // |TabContents::InvalidateTypes| bits. - virtual void NavigationStateChanged(const TabContents* source, - unsigned changed_flags) { } -#endif - - protected: - TabContentsObserver(TabContents* tab_contents); - virtual ~TabContentsObserver(); - - // IPC::Channel::Listener implementation. - virtual bool OnMessageReceived(const IPC::Message& message); - - // IPC::Message::Sender implementation. - virtual bool Send(IPC::Message* message); - - TabContents* tab_contents() { return tab_contents_; } - int routing_id() { return routing_id_; } - - private: - friend class TabContents; - - void set_tab_contents(TabContents* tc) { tab_contents_ = tc; } - - TabContents* tab_contents_; - // The routing ID of the associated TabContents. - int routing_id_; - - DISALLOW_COPY_AND_ASSIGN(TabContentsObserver); -}; +// TODO(jam): remove this file when all files have been converted. +#include "content/browser/tab_contents/tab_contents_observer.h" #endif // CHROME_BROWSER_TAB_CONTENTS_TAB_CONTENTS_OBSERVER_H_ diff --git a/chrome/browser/tab_contents/tab_contents_view.h b/chrome/browser/tab_contents/tab_contents_view.h index a25b13f..a703cf2 100644 --- a/chrome/browser/tab_contents/tab_contents_view.h +++ b/chrome/browser/tab_contents/tab_contents_view.h @@ -6,213 +6,7 @@ #define CHROME_BROWSER_TAB_CONTENTS_TAB_CONTENTS_VIEW_H_ #pragma once -#include <map> -#include <string> - -#include "base/basictypes.h" -#include "chrome/browser/renderer_host/render_view_host_delegate.h" -#include "chrome/browser/tab_contents/render_view_host_delegate_helper.h" -#include "ui/gfx/native_widget_types.h" -#include "ui/gfx/rect.h" -#include "ui/gfx/size.h" - -class RenderViewHost; -class RenderWidgetHost; -class RenderWidgetHostView; -class TabContents; - -// The TabContentsView is an interface that is implemented by the platform- -// dependent web contents views. The TabContents uses this interface to talk to -// them. View-related messages will also get forwarded directly to this class -// from RenderViewHost via RenderViewHostDelegate::View. -// -// It contains a small amount of logic with respect to creating new sub-view -// that should be the same for all platforms. -class TabContentsView : public RenderViewHostDelegate::View { - public: - explicit TabContentsView(TabContents* tab_contents); - virtual ~TabContentsView(); - - // Creates the appropriate type of TabContentsView for the current system. - // The return value is a new heap allocated view with ownership passing to - // the caller. - static TabContentsView* Create(TabContents* tab_contents); - - TabContents* tab_contents() const { return tab_contents_; } - - virtual void CreateView(const gfx::Size& initial_size) = 0; - - // Sets up the View that holds the rendered web page, receives messages for - // it and contains page plugins. The host view should be sized to the current - // size of the TabContents. - virtual RenderWidgetHostView* CreateViewForWidget( - RenderWidgetHost* render_widget_host) = 0; - - // Returns the native widget that contains the contents of the tab. - virtual gfx::NativeView GetNativeView() const = 0; - - // Returns the native widget with the main content of the tab (i.e. the main - // render view host, though there may be many popups in the tab as children of - // the container). - virtual gfx::NativeView GetContentNativeView() const = 0; - - // Returns the outermost native view. This will be used as the parent for - // dialog boxes. - virtual gfx::NativeWindow GetTopLevelNativeWindow() const = 0; - - // Computes the rectangle for the native widget that contains the contents of - // the tab relative to its parent. - virtual void GetContainerBounds(gfx::Rect *out) const = 0; - - // Helper function for GetContainerBounds. Most callers just want to know the - // size, and this makes it more clear. - gfx::Size GetContainerSize() const { - gfx::Rect rc; - GetContainerBounds(&rc); - return gfx::Size(rc.width(), rc.height()); - } - - // Sets the page title for the native widgets corresponding to the view. This - // is not strictly necessary and isn't expected to be displayed anywhere, but - // can aid certain debugging tools such as Spy++ on Windows where you are - // trying to find a specific window. - virtual void SetPageTitle(const std::wstring& title) = 0; - - // Used to notify the view that a tab has crashed so each platform can - // prepare the sad tab. - virtual void OnTabCrashed(base::TerminationStatus status, - int error_code) = 0; - - // TODO(brettw) this is a hack. It's used in two places at the time of this - // writing: (1) when render view hosts switch, we need to size the replaced - // one to be correct, since it wouldn't have known about sizes that happened - // while it was hidden; (2) in constrained windows. - // - // (1) will be fixed once interstitials are cleaned up. (2) seems like it - // should be cleaned up or done some other way, since this works for normal - // TabContents without the special code. - virtual void SizeContents(const gfx::Size& size) = 0; - - // Invoked from the platform dependent web contents view when a - // RenderWidgetHost is deleted. Removes |host| from internal maps. - void RenderWidgetHostDestroyed(RenderWidgetHost* host); - - // Invoked when the TabContents is notified that the RenderView has been - // fully created. The default implementation does nothing; override - // for platform-specific behavior is needed. - virtual void RenderViewCreated(RenderViewHost* host); - - // Sets focus to the native widget for this tab. - virtual void Focus() = 0; - - // Sets focus to the appropriate element when the tab contents is shown the - // first time. - virtual void SetInitialFocus() = 0; - - // Stores the currently focused view. - virtual void StoreFocus() = 0; - - // Restores focus to the last focus view. If StoreFocus has not yet been - // invoked, SetInitialFocus is invoked. - virtual void RestoreFocus() = 0; - - // RenderViewHostDelegate::View method. Forwards to the TabContentsDelegate. - virtual void LostCapture(); - - // Keyboard events forwarding from the RenderViewHost. - // The default implementation just forward the events to the - // TabContentsDelegate object. - virtual bool PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event, - bool* is_keyboard_shortcut); - - // Keyboard events forwarding from the RenderViewHost. - // The default implementation just forward the events to the - // TabContentsDelegate object. - virtual void HandleKeyboardEvent(const NativeWebKeyboardEvent& event); - - // Simple mouse event forwarding from the RenderViewHost. - virtual void HandleMouseMove() {} - virtual void HandleMouseDown() {} - virtual void HandleMouseLeave() {} - virtual void HandleMouseUp(); - virtual void HandleMouseActivate(); - - // Notification that the preferred size of the contents has changed. - virtual void UpdatePreferredSize(const gfx::Size& pref_size); - - // If we try to close the tab while a drag is in progress, we crash. These - // methods allow the tab contents to determine if a drag is in progress and - // postpone the tab closing. - virtual bool IsDoingDrag() const; - virtual void CancelDragAndCloseTab() {} - - // If we close the tab while a UI control is in an event-tracking - // loop, the control may message freed objects and crash. - // TabContents::Close() calls IsEventTracking(), and if it returns - // true CloseTabAfterEventTracking() is called and the close is not - // completed. - virtual bool IsEventTracking() const; - virtual void CloseTabAfterEventTracking() {} - - // Get the bounds of the View, relative to the parent. - virtual void GetViewBounds(gfx::Rect* out) const = 0; - - protected: - TabContentsView(); // Abstract interface. - - // Internal functions used to support the CreateNewWidget() method. If a - // platform requires plugging into widget creation at a lower level then a - // subclass might want to override these functions, but otherwise they should - // be fine just implementing RenderWidgetHostView::InitAsPopup(). - // - // The Create function returns the newly created widget so it can be - // associated with the given route. When the widget needs to be shown later, - // we'll look it up again and pass the object to the Show functions rather - // than the route ID. - virtual RenderWidgetHostView* CreateNewWidgetInternal( - int route_id, - WebKit::WebPopupType popup_type); - virtual void ShowCreatedWidgetInternal(RenderWidgetHostView* widget_host_view, - const gfx::Rect& initial_pos); - virtual void ShowCreatedFullscreenWidgetInternal( - RenderWidgetHostView* widget_host_view); - virtual RenderWidgetHostView* CreateNewFullscreenWidgetInternal(int route_id); - - // Common implementations of some RenderViewHostDelegate::View methods. - RenderViewHostDelegateViewHelper delegate_view_helper_; - - private: - // We implement these functions on RenderViewHostDelegate::View directly and - // do some book-keeping associated with the request. The request is then - // forwarded to *Internal which does platform-specific work. - virtual void CreateNewWindow( - int route_id, - const ViewHostMsg_CreateWindow_Params& params); - virtual void CreateNewWidget(int route_id, WebKit::WebPopupType popup_type); - virtual void CreateNewFullscreenWidget(int route_id); - virtual void ShowCreatedWindow(int route_id, - WindowOpenDisposition disposition, - const gfx::Rect& initial_pos, - bool user_gesture); - virtual void ShowCreatedWidget(int route_id, const gfx::Rect& initial_pos); - virtual void Activate(); - virtual void Deactivate(); - virtual void ShowCreatedFullscreenWidget(int route_id); - - // The TabContents whose contents we display. - TabContents* tab_contents_; - - // Tracks created TabContents objects that have not been shown yet. They are - // identified by the route ID passed to CreateNewWindow. - typedef std::map<int, TabContents*> PendingContents; - PendingContents pending_contents_; - - // These maps hold on to the widgets that we created on behalf of the - // renderer that haven't shown yet. - typedef std::map<int, RenderWidgetHostView*> PendingWidgetViews; - PendingWidgetViews pending_widget_views_; - - DISALLOW_COPY_AND_ASSIGN(TabContentsView); -}; +// TODO(jam): remove this file when all files have been converted. +#include "content/browser/tab_contents/tab_contents_view.h" #endif // CHROME_BROWSER_TAB_CONTENTS_TAB_CONTENTS_VIEW_H_ diff --git a/chrome/browser/tab_contents/test_tab_contents.h b/chrome/browser/tab_contents/test_tab_contents.h index 729730b..583bd81 100644 --- a/chrome/browser/tab_contents/test_tab_contents.h +++ b/chrome/browser/tab_contents/test_tab_contents.h @@ -6,76 +6,7 @@ #define CHROME_BROWSER_TAB_CONTENTS_TEST_TAB_CONTENTS_H_ #pragma once -#include "chrome/browser/tab_contents/tab_contents.h" -#include "chrome/common/notification_registrar.h" -#include "webkit/glue/webpreferences.h" - -class Profile; -class TestRenderViewHost; - -// Subclass TabContents to ensure it creates TestRenderViewHosts and does -// not do anything involving views. -class TestTabContents : public TabContents { - public: - // The render view host factory will be passed on to the - TestTabContents(Profile* profile, SiteInstance* instance); - - TestRenderViewHost* pending_rvh() const; - - // State accessor. - bool cross_navigation_pending() { - return render_manager_.cross_navigation_pending_; - } - - // Overrides TabContents::ShouldTransitionCrossSite so that we can test both - // alternatives without using command-line switches. - bool ShouldTransitionCrossSite() { return transition_cross_site; } - - // Overrides TabContents::Observe. We are listening to infobar related - // notifications so we can call InfoBarClosed() on the infobar delegates to - // prevent them from leaking. - virtual void Observe(NotificationType type, - const NotificationSource& source, - const NotificationDetails& details); - - // Promote DidNavigate to public. - void TestDidNavigate(RenderViewHost* render_view_host, - const ViewHostMsg_FrameNavigate_Params& params) { - DidNavigate(render_view_host, params); - } - - // Promote GetWebkitPrefs to public. - WebPreferences TestGetWebkitPrefs() { - return GetWebkitPrefs(); - } - - // Prevent interaction with views. - virtual bool CreateRenderViewForRenderManager( - RenderViewHost* render_view_host); - virtual void UpdateRenderViewSizeForRenderManager() {} - - // Returns a clone of this TestTabContents. The returned object is also a - // TestTabContents. The caller owns the returned object. - virtual TabContents* Clone(); - - // Creates a pending navigation to the given URL with the default parameters - // and then commits the load with a page ID one larger than any seen. This - // emulates what happens on a new navigation. - void NavigateAndCommit(const GURL& url); - - // Simulates the appropriate RenderView (pending if any, current otherwise) - // sending a navigate notification for the NavigationController pending entry. - void CommitPendingNavigation(); - - // Simulates the current RVH notifying that it has unloaded so that the - // pending RVH navigation can proceed. - // Does nothing if no cross-navigation is pending. - void ProceedWithCrossSiteNavigation(); - - // Set by individual tests. - bool transition_cross_site; - - NotificationRegistrar registrar_; -}; +// TODO(jam): remove this file when all files have been converted. +#include "content/browser/tab_contents/test_tab_contents.h" #endif // CHROME_BROWSER_TAB_CONTENTS_TEST_TAB_CONTENTS_H_ diff --git a/chrome/browser/ui/browser.cc b/chrome/browser/ui/browser.cc index 8075796..e75750a 100644 --- a/chrome/browser/ui/browser.cc +++ b/chrome/browser/ui/browser.cc @@ -102,6 +102,7 @@ #include "chrome/common/profiling.h" #include "chrome/common/url_constants.h" #include "chrome/common/web_apps.h" +#include "content/browser/tab_contents/infobar_delegate.h" #include "grit/chromium_strings.h" #include "grit/generated_resources.h" #include "grit/locale_settings.h" @@ -825,7 +826,7 @@ string16 Browser::GetWindowTitleForCurrentTab() const { FormatTitleForDisplay(&title); } if (title.empty()) - title = TabContents::GetDefaultTitle(); + title = TabContentsWrapper::GetDefaultTitle(); #if defined(OS_MACOSX) || defined(OS_CHROMEOS) // On Mac or ChromeOS, we don't want to suffix the page title with @@ -2746,7 +2747,7 @@ void Browser::TabSelectedAt(TabContentsWrapper* old_contents, status_bubble->Hide(); // Show the loading state (if any). - status_bubble->SetStatus(GetSelectedTabContents()->GetStatusText()); + status_bubble->SetStatus(GetSelectedTabContentsWrapper()->GetStatusText()); } if (HasFindBarController()) { @@ -2917,7 +2918,8 @@ void Browser::LoadingStateChanged(TabContents* source) { if (source == selected_contents) { UpdateReloadStopState(source->is_loading(), false); if (GetStatusBubble()) { - GetStatusBubble()->SetStatus(GetSelectedTabContents()->GetStatusText()); + GetStatusBubble()->SetStatus( + GetSelectedTabContentsWrapper()->GetStatusText()); } if (!source->is_loading() && @@ -3267,6 +3269,14 @@ void Browser::ContentRestrictionsChanged(TabContents* source) { UpdateCommandsForContentRestrictionState(); } +void Browser::WorkerCrashed() { + TabContents* tab_contents = GetSelectedTabContents(); + if (!tab_contents) + return; + tab_contents->AddInfoBar(new SimpleAlertInfoBarDelegate(tab_contents, NULL, + l10n_util::GetStringUTF16(IDS_WEBWORKER_CRASHED_PROMPT), true)); +} + /////////////////////////////////////////////////////////////////////////////// // Browser, TabContentsWrapperDelegate implementation: @@ -3884,8 +3894,10 @@ void Browser::ProcessPendingUIUpdates() { window()->GetLocationBar()->UpdatePageActions(); // Updating the URL happens synchronously in ScheduleUIUpdate. - if (flags & TabContents::INVALIDATE_LOAD && GetStatusBubble()) - GetStatusBubble()->SetStatus(contents->GetStatusText()); + if (flags & TabContents::INVALIDATE_LOAD && GetStatusBubble()) { + GetStatusBubble()->SetStatus( + GetSelectedTabContentsWrapper()->GetStatusText()); + } if (flags & (TabContents::INVALIDATE_TAB | TabContents::INVALIDATE_TITLE)) { diff --git a/chrome/browser/ui/browser.h b/chrome/browser/ui/browser.h index 7c073ef..ba4a6cd 100644 --- a/chrome/browser/ui/browser.h +++ b/chrome/browser/ui/browser.h @@ -807,6 +807,7 @@ class Browser : public TabHandlerDelegate, virtual void OnInstallApplication(TabContents* tab_contents, const WebApplicationInfo& app_info); virtual void ContentRestrictionsChanged(TabContents* source); + virtual void WorkerCrashed(); // Overridden from TabContentsWrapperDelegate: virtual void URLStarredChanged(TabContentsWrapper* source, diff --git a/chrome/browser/ui/cocoa/hung_renderer_controller.mm b/chrome/browser/ui/cocoa/hung_renderer_controller.mm index 2853658..652fc08 100644 --- a/chrome/browser/ui/cocoa/hung_renderer_controller.mm +++ b/chrome/browser/ui/cocoa/hung_renderer_controller.mm @@ -15,6 +15,7 @@ #include "chrome/browser/renderer_host/render_view_host.h" #include "chrome/browser/tab_contents/tab_contents.h" #import "chrome/browser/ui/cocoa/multi_key_equivalent_button.h" +#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" #include "chrome/common/logging_chrome.h" #include "chrome/common/result_codes.h" #include "grit/chromium_strings.h" @@ -139,7 +140,7 @@ HungRendererController* g_instance = NULL; if (it->GetRenderProcessHost() == hungContents_->GetRenderProcessHost()) { string16 title = (*it)->GetTitle(); if (title.empty()) - title = TabContents::GetDefaultTitle(); + title = TabContentsWrapper::GetDefaultTitle(); [titles addObject:base::SysUTF16ToNSString(title)]; // TabContents can return a null SkBitmap if it has no favicon. If this diff --git a/chrome/browser/ui/gtk/hung_renderer_dialog_gtk.cc b/chrome/browser/ui/gtk/hung_renderer_dialog_gtk.cc index fc41e24..b2bf521 100644 --- a/chrome/browser/ui/gtk/hung_renderer_dialog_gtk.cc +++ b/chrome/browser/ui/gtk/hung_renderer_dialog_gtk.cc @@ -13,6 +13,7 @@ #include "chrome/browser/renderer_host/render_view_host.h" #include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/browser/ui/gtk/gtk_util.h" +#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" #include "chrome/common/logging_chrome.h" #include "chrome/common/result_codes.h" #include "grit/chromium_strings.h" @@ -152,7 +153,7 @@ void HungRendererDialogGtk::ShowForTabContents(TabContents* hung_contents) { gtk_list_store_append(model_, &tree_iter); std::string title = UTF16ToUTF8(it->GetTitle()); if (title.empty()) - title = UTF16ToUTF8(TabContents::GetDefaultTitle()); + title = UTF16ToUTF8(TabContentsWrapper::GetDefaultTitle()); SkBitmap favicon = it->GetFavIcon(); GdkPixbuf* pixbuf = NULL; diff --git a/chrome/browser/ui/gtk/tabs/tab_renderer_gtk.cc b/chrome/browser/ui/gtk/tabs/tab_renderer_gtk.cc index 3abd11b..19b20a5 100644 --- a/chrome/browser/ui/gtk/tabs/tab_renderer_gtk.cc +++ b/chrome/browser/ui/gtk/tabs/tab_renderer_gtk.cc @@ -16,6 +16,7 @@ #include "chrome/browser/ui/gtk/custom_button.h" #include "chrome/browser/ui/gtk/gtk_theme_provider.h" #include "chrome/browser/ui/gtk/gtk_util.h" +#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" #include "chrome/common/notification_service.h" #include "grit/app_resources.h" #include "grit/generated_resources.h" @@ -808,7 +809,7 @@ void TabRendererGtk::PaintTitle(gfx::Canvas* canvas) { if (title.empty()) { title = data_.loading ? l10n_util::GetStringUTF16(IDS_TAB_LOADING_TITLE) : - TabContents::GetDefaultTitle(); + TabContentsWrapper::GetDefaultTitle(); } else { Browser::FormatTitleForDisplay(&title); } diff --git a/chrome/browser/ui/tab_contents/tab_contents_wrapper.cc b/chrome/browser/ui/tab_contents/tab_contents_wrapper.cc index d1d46bfd..8541170 100644 --- a/chrome/browser/ui/tab_contents/tab_contents_wrapper.cc +++ b/chrome/browser/ui/tab_contents/tab_contents_wrapper.cc @@ -8,12 +8,21 @@ #include "chrome/browser/bookmarks/bookmark_model.h" #include "chrome/browser/password_manager/password_manager.h" #include "chrome/browser/password_manager_delegate_impl.h" +#include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/profiles/profile.h" -#include "chrome/browser/tab_contents/tab_contents.h" +#include "chrome/browser/tab_contents/infobar_delegate.h" #include "chrome/browser/ui/find_bar/find_tab_helper.h" #include "chrome/browser/ui/search_engines/search_engine_tab_helper.h" #include "chrome/browser/ui/tab_contents/tab_contents_wrapper_delegate.h" #include "chrome/common/notification_service.h" +#include "chrome/common/pref_names.h" +#include "chrome/common/render_messages.h" +#include "content/browser/tab_contents/tab_contents.h" +#include "grit/locale_settings.h" +#include "grit/generated_resources.h" +#include "grit/platform_locale_settings.h" +#include "ui/base/l10n/l10n_util.h" +#include "webkit/glue/webpreferences.h" static base::LazyInstance<PropertyAccessor<TabContentsWrapper*> > g_tab_contents_wrapper_property_accessor(base::LINKER_INITIALIZED); @@ -54,6 +63,106 @@ PropertyAccessor<TabContentsWrapper*>* TabContentsWrapper::property_accessor() { return g_tab_contents_wrapper_property_accessor.Pointer(); } +void TabContentsWrapper::RegisterUserPrefs(PrefService* prefs) { + prefs->RegisterBooleanPref(prefs::kAlternateErrorPagesEnabled, true); + + WebPreferences pref_defaults; + prefs->RegisterBooleanPref(prefs::kWebKitJavascriptEnabled, + pref_defaults.javascript_enabled); + prefs->RegisterBooleanPref(prefs::kWebKitWebSecurityEnabled, + pref_defaults.web_security_enabled); + prefs->RegisterBooleanPref( + prefs::kWebKitJavascriptCanOpenWindowsAutomatically, true); + prefs->RegisterBooleanPref(prefs::kWebKitLoadsImagesAutomatically, + pref_defaults.loads_images_automatically); + prefs->RegisterBooleanPref(prefs::kWebKitPluginsEnabled, + pref_defaults.plugins_enabled); + prefs->RegisterBooleanPref(prefs::kWebKitDomPasteEnabled, + pref_defaults.dom_paste_enabled); + prefs->RegisterBooleanPref(prefs::kWebKitShrinksStandaloneImagesToFit, + pref_defaults.shrinks_standalone_images_to_fit); + prefs->RegisterDictionaryPref(prefs::kWebKitInspectorSettings); + prefs->RegisterBooleanPref(prefs::kWebKitTextAreasAreResizable, + pref_defaults.text_areas_are_resizable); + prefs->RegisterBooleanPref(prefs::kWebKitJavaEnabled, + pref_defaults.java_enabled); + prefs->RegisterBooleanPref(prefs::kWebkitTabsToLinks, + pref_defaults.tabs_to_links); + + prefs->RegisterLocalizedStringPref(prefs::kAcceptLanguages, + IDS_ACCEPT_LANGUAGES); + prefs->RegisterLocalizedStringPref(prefs::kDefaultCharset, + IDS_DEFAULT_ENCODING); + prefs->RegisterLocalizedBooleanPref(prefs::kWebKitStandardFontIsSerif, + IDS_STANDARD_FONT_IS_SERIF); + prefs->RegisterLocalizedStringPref(prefs::kWebKitFixedFontFamily, + IDS_FIXED_FONT_FAMILY); + prefs->RegisterLocalizedStringPref(prefs::kWebKitSerifFontFamily, + IDS_SERIF_FONT_FAMILY); + prefs->RegisterLocalizedStringPref(prefs::kWebKitSansSerifFontFamily, + IDS_SANS_SERIF_FONT_FAMILY); + prefs->RegisterLocalizedStringPref(prefs::kWebKitCursiveFontFamily, + IDS_CURSIVE_FONT_FAMILY); + prefs->RegisterLocalizedStringPref(prefs::kWebKitFantasyFontFamily, + IDS_FANTASY_FONT_FAMILY); + prefs->RegisterLocalizedIntegerPref(prefs::kWebKitDefaultFontSize, + IDS_DEFAULT_FONT_SIZE); + prefs->RegisterLocalizedIntegerPref(prefs::kWebKitDefaultFixedFontSize, + IDS_DEFAULT_FIXED_FONT_SIZE); + prefs->RegisterLocalizedIntegerPref(prefs::kWebKitMinimumFontSize, + IDS_MINIMUM_FONT_SIZE); + prefs->RegisterLocalizedIntegerPref(prefs::kWebKitMinimumLogicalFontSize, + IDS_MINIMUM_LOGICAL_FONT_SIZE); + prefs->RegisterLocalizedBooleanPref(prefs::kWebKitUsesUniversalDetector, + IDS_USES_UNIVERSAL_DETECTOR); + prefs->RegisterLocalizedStringPref(prefs::kStaticEncodings, + IDS_STATIC_ENCODING_LIST); +} + +string16 TabContentsWrapper::GetDefaultTitle() { + return l10n_util::GetStringUTF16(IDS_DEFAULT_TAB_TITLE); +} + +string16 TabContentsWrapper::GetStatusText() const { + if (!tab_contents()->is_loading() || + tab_contents()->load_state() == net::LOAD_STATE_IDLE) { + return string16(); + } + + switch (tab_contents()->load_state()) { + case net::LOAD_STATE_WAITING_FOR_CACHE: + return l10n_util::GetStringUTF16(IDS_LOAD_STATE_WAITING_FOR_CACHE); + case net::LOAD_STATE_ESTABLISHING_PROXY_TUNNEL: + return + l10n_util::GetStringUTF16(IDS_LOAD_STATE_ESTABLISHING_PROXY_TUNNEL); + case net::LOAD_STATE_RESOLVING_PROXY_FOR_URL: + return l10n_util::GetStringUTF16(IDS_LOAD_STATE_RESOLVING_PROXY_FOR_URL); + case net::LOAD_STATE_RESOLVING_HOST: + return l10n_util::GetStringUTF16(IDS_LOAD_STATE_RESOLVING_HOST); + case net::LOAD_STATE_CONNECTING: + return l10n_util::GetStringUTF16(IDS_LOAD_STATE_CONNECTING); + case net::LOAD_STATE_SSL_HANDSHAKE: + return l10n_util::GetStringUTF16(IDS_LOAD_STATE_SSL_HANDSHAKE); + case net::LOAD_STATE_SENDING_REQUEST: + if (tab_contents()->upload_size()) + return l10n_util::GetStringFUTF16Int( + IDS_LOAD_STATE_SENDING_REQUEST_WITH_PROGRESS, + static_cast<int>((100 * tab_contents()->upload_position()) / + tab_contents()->upload_size())); + else + return l10n_util::GetStringUTF16(IDS_LOAD_STATE_SENDING_REQUEST); + case net::LOAD_STATE_WAITING_FOR_RESPONSE: + return l10n_util::GetStringFUTF16(IDS_LOAD_STATE_WAITING_FOR_RESPONSE, + tab_contents()->load_state_host()); + // Ignore net::LOAD_STATE_READING_RESPONSE and net::LOAD_STATE_IDLE + case net::LOAD_STATE_IDLE: + case net::LOAD_STATE_READING_RESPONSE: + break; + } + + return string16(); +} + TabContentsWrapper* TabContentsWrapper::Clone() { TabContents* new_contents = tab_contents()->Clone(); TabContentsWrapper* new_wrapper = new TabContentsWrapper(new_contents); @@ -77,6 +186,15 @@ void TabContentsWrapper::DidNavigateMainFramePostCommit( UpdateStarredStateForCurrentURL(); } +bool TabContentsWrapper::OnMessageReceived(const IPC::Message& message) { + bool handled = true; + IPC_BEGIN_MESSAGE_MAP(TabContentsWrapper, message) + IPC_MESSAGE_HANDLER(ViewHostMsg_JSOutOfMemory, OnJSOutOfMemory) + IPC_MESSAGE_UNHANDLED(handled = false) + IPC_END_MESSAGE_MAP() + return handled; +} + //////////////////////////////////////////////////////////////////////////////// // TabContentsWrapper, NotificationObserver implementation: @@ -105,6 +223,11 @@ void TabContentsWrapper::Observe(NotificationType type, //////////////////////////////////////////////////////////////////////////////// // Internal helpers +void TabContentsWrapper::OnJSOutOfMemory() { + tab_contents()->AddInfoBar(new SimpleAlertInfoBarDelegate(tab_contents(), + NULL, l10n_util::GetStringUTF16(IDS_JS_OUT_OF_MEMORY_PROMPT), true)); +} + void TabContentsWrapper::UpdateStarredStateForCurrentURL() { BookmarkModel* model = tab_contents()->profile()->GetBookmarkModel(); const bool old_state = is_starred_; diff --git a/chrome/browser/ui/tab_contents/tab_contents_wrapper.h b/chrome/browser/ui/tab_contents/tab_contents_wrapper.h index 510fb76..faaf5b8 100644 --- a/chrome/browser/ui/tab_contents/tab_contents_wrapper.h +++ b/chrome/browser/ui/tab_contents/tab_contents_wrapper.h @@ -39,6 +39,14 @@ class TabContentsWrapper : public NotificationObserver, // its property bag to avoid adding additional interfaces. static PropertyAccessor<TabContentsWrapper*>* property_accessor(); + static void RegisterUserPrefs(PrefService* prefs); + + // Initial title assigned to NavigationEntries from Navigate. + static string16 GetDefaultTitle(); + + // Returns a human-readable description the tab's loading state. + string16 GetStatusText() const; + // Create a TabContentsWrapper with the same state as this one. The returned // heap-allocated pointer is owned by the caller. TabContentsWrapper* Clone(); @@ -88,6 +96,7 @@ class TabContentsWrapper : public NotificationObserver, virtual void DidNavigateMainFramePostCommit( const NavigationController::LoadCommittedDetails& details, const ViewHostMsg_FrameNavigate_Params& params) OVERRIDE; + virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; // NotificationObserver overrides: virtual void Observe(NotificationType type, @@ -97,6 +106,9 @@ class TabContentsWrapper : public NotificationObserver, private: // Internal helpers ---------------------------------------------------------- + // Message handlers. + void OnJSOutOfMemory(); + // Updates the starred state from the bookmark bar model. If the state has // changed, the delegate is notified. void UpdateStarredStateForCurrentURL(); diff --git a/chrome/browser/ui/views/hung_renderer_view.cc b/chrome/browser/ui/views/hung_renderer_view.cc index ffefd9f..65a3478 100644 --- a/chrome/browser/ui/views/hung_renderer_view.cc +++ b/chrome/browser/ui/views/hung_renderer_view.cc @@ -10,6 +10,7 @@ #include "chrome/browser/renderer_host/render_process_host.h" #include "chrome/browser/renderer_host/render_view_host.h" #include "chrome/browser/tab_contents/tab_contents.h" +#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" #include "chrome/common/chrome_constants.h" #include "chrome/common/logging_chrome.h" #include "chrome/common/result_codes.h" @@ -93,7 +94,7 @@ string16 HungPagesTableModel::GetText(int row, int column_id) { DCHECK(row >= 0 && row < RowCount()); string16 title = tab_contentses_[row]->GetTitle(); if (title.empty()) - title = TabContents::GetDefaultTitle(); + title = TabContentsWrapper::GetDefaultTitle(); // TODO(xji): Consider adding a special case if the title text is a URL, // since those should always have LTR directionality. Please refer to // http://crbug.com/6726 for more information. diff --git a/chrome/browser/ui/views/tabs/base_tab.cc b/chrome/browser/ui/views/tabs/base_tab.cc index 53d66ec..4350d04 100644 --- a/chrome/browser/ui/views/tabs/base_tab.cc +++ b/chrome/browser/ui/views/tabs/base_tab.cc @@ -12,6 +12,7 @@ #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/view_ids.h" #include "chrome/browser/ui/views/tabs/tab_controller.h" +#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" #include "chrome/common/chrome_switches.h" #include "grit/app_resources.h" #include "grit/generated_resources.h" @@ -437,7 +438,7 @@ void BaseTab::PaintTitle(gfx::Canvas* canvas, SkColor title_color) { if (title.empty()) { title = data().loading ? l10n_util::GetStringUTF16(IDS_TAB_LOADING_TITLE) : - TabContents::GetDefaultTitle(); + TabContentsWrapper::GetDefaultTitle(); } else { Browser::FormatTitleForDisplay(&title); } diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp index 6b78cae..3af5e70 100644 --- a/chrome/chrome.gyp +++ b/chrome/chrome.gyp @@ -1624,7 +1624,7 @@ '../app/app.gyp:*', '../base/base.gyp:*', '../chrome_frame/chrome_frame.gyp:*', - '../ui/gfx/gfx.gyp:*', + '../content/content.gyp:*', '../ipc/ipc.gyp:*', '../media/media.gyp:*', '../net/net.gyp:*', @@ -1649,6 +1649,7 @@ '../third_party/qcms/qcms.gyp:*', '../third_party/sqlite/sqlite.gyp:*', '../third_party/zlib/zlib.gyp:*', + '../ui/gfx/gfx.gyp:*', '../webkit/support/webkit_support.gyp:*', '../webkit/webkit.gyp:*', diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index f12073e..4d232df 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -27,6 +27,7 @@ 'userfeedback_proto', '../app/app.gyp:app_resources', '../app/app.gyp:app_strings', + '../content/content.gyp:content_browser', '../media/media.gyp:media', '../ppapi/ppapi.gyp:ppapi_proxy', # For PpapiMsg_LoadPlugin '../printing/printing.gyp:printing', @@ -2288,24 +2289,10 @@ 'browser/sync/token_migrator.h', 'browser/tab_closeable_state_watcher.cc', 'browser/tab_closeable_state_watcher.h', - 'browser/tab_contents/background_contents.cc', - 'browser/tab_contents/background_contents.h', - 'browser/tab_contents/constrained_window.h', 'browser/tab_contents/infobar_delegate.cc', 'browser/tab_contents/infobar_delegate.h', - 'browser/tab_contents/interstitial_page.cc', - 'browser/tab_contents/interstitial_page.h', - 'browser/tab_contents/language_state.cc', - 'browser/tab_contents/language_state.h', - 'browser/tab_contents/navigation_controller.cc', - 'browser/tab_contents/navigation_controller.h', - 'browser/tab_contents/navigation_entry.cc', - 'browser/tab_contents/navigation_entry.h', - 'browser/tab_contents/page_navigator.h', 'browser/tab_contents/popup_menu_helper_mac.h', 'browser/tab_contents/popup_menu_helper_mac.mm', - 'browser/tab_contents/provisional_load_details.cc', - 'browser/tab_contents/provisional_load_details.h', 'browser/tab_contents/render_view_context_menu.cc', 'browser/tab_contents/render_view_context_menu.h', 'browser/tab_contents/render_view_context_menu_gtk.cc', @@ -2314,18 +2301,8 @@ 'browser/tab_contents/render_view_context_menu_mac.mm', 'browser/tab_contents/render_view_host_delegate_helper.cc', 'browser/tab_contents/render_view_host_delegate_helper.h', - 'browser/tab_contents/render_view_host_manager.cc', - 'browser/tab_contents/render_view_host_manager.h', - 'browser/tab_contents/tab_contents.cc', - 'browser/tab_contents/tab_contents.h', - 'browser/tab_contents/tab_contents_delegate.cc', - 'browser/tab_contents/tab_contents_delegate.h', - 'browser/tab_contents/tab_contents_observer.cc', - 'browser/tab_contents/tab_contents_observer.h', 'browser/tab_contents/tab_contents_ssl_helper.cc', 'browser/tab_contents/tab_contents_ssl_helper.h', - 'browser/tab_contents/tab_contents_view.cc', - 'browser/tab_contents/tab_contents_view.h', 'browser/tab_contents/tab_contents_view_gtk.cc', 'browser/tab_contents/tab_contents_view_gtk.h', 'browser/tab_contents/tab_contents_view_mac.h', diff --git a/chrome/chrome_common.gypi b/chrome/chrome_common.gypi index 2c4025b..618364b 100644 --- a/chrome/chrome_common.gypi +++ b/chrome/chrome_common.gypi @@ -216,6 +216,8 @@ '../base/base.gyp:base', '../base/base.gyp:base_i18n', '../build/temp_gyp/googleurl.gyp:googleurl', + # Don't include now since it's empty and so will cause a linker error. + #'../content/content.gyp:content_common', '../ipc/ipc.gyp:ipc', '../net/net.gyp:net', '../printing/printing.gyp:printing', diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index 8c7545b..1d7e6c5 100644 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -95,8 +95,6 @@ 'browser/sync/profile_sync_service_mock.h', 'browser/sync/syncable/syncable_mock.cc', 'browser/sync/syncable/syncable_mock.h', - 'browser/tab_contents/test_tab_contents.cc', - 'browser/tab_contents/test_tab_contents.h', 'browser/ui/browser.h', 'browser/ui/cocoa/browser_test_helper.h', 'browser/ui/tab_contents/test_tab_contents_wrapper.cc', @@ -182,6 +180,8 @@ 'test/unit/chrome_test_suite.h', 'test/values_test_util.cc', 'test/values_test_util.h', + '../content/browser/tab_contents/test_tab_contents.cc', + '../content/browser/tab_contents/test_tab_contents.h', ], 'conditions': [ ['OS=="linux"', { @@ -1548,9 +1548,6 @@ 'browser/sync/test_profile_sync_service.cc', 'browser/sync/util/cryptographer_unittest.cc', 'browser/sync/util/nigori_unittest.cc', - 'browser/tab_contents/navigation_controller_unittest.cc', - 'browser/tab_contents/navigation_entry_unittest.cc', - 'browser/tab_contents/render_view_host_manager_unittest.cc', 'browser/tab_contents/tab_specific_content_settings_unittest.cc', 'browser/tab_contents/thumbnail_generator_unittest.cc', 'browser/tab_contents/web_contents_unittest.cc', @@ -1848,6 +1845,9 @@ 'test/v8_unit_test.cc', 'test/v8_unit_test.h', 'tools/convert_dict/convert_dict_unittest.cc', + '../content/browser/tab_contents/navigation_controller_unittest.cc', + '../content/browser/tab_contents/navigation_entry_unittest.cc', + '../content/browser/tab_contents/render_view_host_manager_unittest.cc', '../testing/gtest_mac_unittest.mm', '../third_party/cld/encodings/compact_lang_det/compact_lang_det_unittest_small.cc', '../webkit/fileapi/file_system_dir_url_request_job_unittest.cc', diff --git a/content/DEPS b/content/DEPS new file mode 100644 index 0000000..fb297a3 --- /dev/null +++ b/content/DEPS @@ -0,0 +1,23 @@ +# Do NOT add chrome to the list below. We shouldn't be including files from +# src/chrome in src/content. +include_rules = [ + "+app", + + # TEMPORARY ONLY WHILE WE REDUCE THE DEPENDENCIES. + # When the src\content refactoring is complete, this will be unnecessary (and + # in fact, a layering violation). + "+chrome", + + "+grit", + "+net", + + # Don't allow inclusion of these other libs we shouldn't be calling directly. + "-v8", + "-tools", + + # Allow inclusion of WebKit API files. + "+third_party/WebKit/Source/WebKit/chromium", + + "+ui", + "+webkit", +] diff --git a/content/OWNERS b/content/OWNERS new file mode 100644 index 0000000..f8773be --- /dev/null +++ b/content/OWNERS @@ -0,0 +1,4 @@ +ben@chromium.org +darin@chromium.org +jam@chromium.org +brettw@chromium.org diff --git a/chrome/browser/tab_contents/background_contents.cc b/content/browser/tab_contents/background_contents.cc index 059d393..d8c11e0 100644 --- a/chrome/browser/tab_contents/background_contents.cc +++ b/content/browser/tab_contents/background_contents.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/browser/tab_contents/background_contents.h" +#include "content/browser/tab_contents/background_contents.h" #include "chrome/browser/background_contents_service.h" #include "chrome/browser/browsing_instance.h" diff --git a/content/browser/tab_contents/background_contents.h b/content/browser/tab_contents/background_contents.h new file mode 100644 index 0000000..e4455fb --- /dev/null +++ b/content/browser/tab_contents/background_contents.h @@ -0,0 +1,186 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CONTENT_BROWSER_TAB_CONTENTS_BACKGROUND_CONTENTS_H_ +#define CONTENT_BROWSER_TAB_CONTENTS_BACKGROUND_CONTENTS_H_ +#pragma once + +#include <string> +#include <vector> + +#include "chrome/browser/renderer_host/render_view_host_delegate.h" +#include "chrome/browser/tab_contents/render_view_host_delegate_helper.h" +#include "chrome/browser/ui/app_modal_dialogs/js_modal_dialog.h" +#include "chrome/common/notification_registrar.h" +#include "chrome/common/view_types.h" +#include "chrome/common/window_container_type.h" +#include "webkit/glue/window_open_disposition.h" + +class TabContents; +struct WebPreferences; +class DesktopNotificationHandler; + +namespace gfx { +class Rect; +} + +// This class is a peer of TabContents. It can host a renderer, but does not +// have any visible display. Its navigation is not managed by a +// NavigationController because is has no facility for navigating (other than +// programatically view window.location.href) or RenderViewHostManager because +// it is never allowed to navigate across a SiteInstance boundary. +class BackgroundContents : public RenderViewHostDelegate, + public RenderViewHostDelegate::View, + public NotificationObserver, + public JavaScriptAppModalDialogDelegate { + public: + class Delegate { + public: + // Called by ShowCreatedWindow. Asks the delegate to attach the opened + // TabContents to a suitable container (e.g. browser) or to show it if it's + // a popup window. + virtual void AddTabContents(TabContents* new_contents, + WindowOpenDisposition disposition, + const gfx::Rect& initial_pos, + bool user_gesture) = 0; + + protected: + virtual ~Delegate() {} + }; + + BackgroundContents(SiteInstance* site_instance, + int routing_id, + Delegate* delegate); + virtual ~BackgroundContents(); + + // Provide access to the RenderViewHost for the + // RenderViewHostDelegateViewHelper + RenderViewHost* render_view_host() { return render_view_host_; } + + // RenderViewHostDelegate implementation. + virtual BackgroundContents* GetAsBackgroundContents(); + virtual RenderViewHostDelegate::View* GetViewDelegate(); + virtual const GURL& GetURL() const; + virtual ViewType::Type GetRenderViewType() const; + virtual int GetBrowserWindowID() const; + virtual void DidNavigate(RenderViewHost* render_view_host, + const ViewHostMsg_FrameNavigate_Params& params); + virtual WebPreferences GetWebkitPrefs(); + virtual void ProcessWebUIMessage(const ViewHostMsg_DomMessage_Params& params); + virtual void RunJavaScriptMessage(const std::wstring& message, + const std::wstring& default_prompt, + const GURL& frame_url, + const int flags, + IPC::Message* reply_msg, + bool* did_suppress_message); + virtual void Close(RenderViewHost* render_view_host); + virtual RendererPreferences GetRendererPrefs(Profile* profile) const; + virtual void RenderViewGone(RenderViewHost* rvh, + base::TerminationStatus status, + int error_code); + virtual bool OnMessageReceived(const IPC::Message& message); + + // RenderViewHostDelegate::View + virtual void CreateNewWindow( + int route_id, + const ViewHostMsg_CreateWindow_Params& params); + virtual void CreateNewWidget(int route_id, WebKit::WebPopupType popup_type); + virtual void CreateNewFullscreenWidget(int route_id); + virtual void ShowCreatedWindow(int route_id, + WindowOpenDisposition disposition, + const gfx::Rect& initial_pos, + bool user_gesture); + virtual void ShowCreatedWidget(int route_id, + const gfx::Rect& initial_pos); + virtual void ShowCreatedFullscreenWidget(int route_id); + virtual void ShowContextMenu(const ContextMenuParams& params) {} + virtual void ShowPopupMenu(const gfx::Rect& bounds, + int item_height, + double item_font_size, + int selected_item, + const std::vector<WebMenuItem>& items, + bool right_aligned) {} + virtual void StartDragging(const WebDropData& drop_data, + WebKit::WebDragOperationsMask allowed_operations, + const SkBitmap& image, + const gfx::Point& image_offset) {} + virtual void UpdateDragCursor(WebKit::WebDragOperation operation) {} + virtual void GotFocus() {} + virtual void TakeFocus(bool reverse) {} + virtual void LostCapture() {} + virtual void Activate() {} + virtual void Deactivate() {} + virtual bool PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event, + bool* is_keyboard_shortcut); + virtual void HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {} + virtual void HandleMouseMove() {} + virtual void HandleMouseDown() {} + virtual void HandleMouseLeave() {} + virtual void HandleMouseUp() {} + virtual void HandleMouseActivate() {} + virtual void UpdatePreferredSize(const gfx::Size& new_size) {} + + // NotificationObserver + virtual void Observe(NotificationType type, + const NotificationSource& source, + const NotificationDetails& details); + + // Overridden from JavaScriptAppModalDialogDelegate: + virtual void OnMessageBoxClosed(IPC::Message* reply_msg, + bool success, + const std::wstring& prompt); + virtual void SetSuppressMessageBoxes(bool suppress_message_boxes) {} + virtual gfx::NativeWindow GetMessageBoxRootWindow(); + virtual TabContents* AsTabContents(); + virtual ExtensionHost* AsExtensionHost(); + + virtual void UpdateInspectorSetting(const std::string& key, + const std::string& value); + virtual void ClearInspectorSettings(); + + // Helper to find the BackgroundContents that originated the given request. + // Can be NULL if the page has been closed or some other error occurs. + // Should only be called from the UI thread, since it accesses + // BackgroundContents. + static BackgroundContents* GetBackgroundContentsByID(int render_process_id, + int render_view_id); + + protected: + // Exposed for testing. + BackgroundContents(); + + private: + // The delegate for this BackgroundContents. + Delegate* delegate_; + + // The host for our HTML content. + RenderViewHost* render_view_host_; + + // Common implementations of some RenderViewHostDelegate::View methods. + RenderViewHostDelegateViewHelper delegate_view_helper_; + + // The URL being hosted. + GURL url_; + + NotificationRegistrar registrar_; + + // Handles desktop notification IPCs. + scoped_ptr<DesktopNotificationHandler> desktop_notification_handler_; + + DISALLOW_COPY_AND_ASSIGN(BackgroundContents); +}; + +// This is the data sent out as the details with BACKGROUND_CONTENTS_OPENED. +struct BackgroundContentsOpenedDetails { + // The BackgroundContents object that has just been opened. + BackgroundContents* contents; + + // The name of the parent frame for these contents. + const string16& frame_name; + + // The ID of the parent application (if any). + const string16& application_id; +}; + +#endif // CONTENT_BROWSER_TAB_CONTENTS_BACKGROUND_CONTENTS_H_ diff --git a/content/browser/tab_contents/constrained_window.h b/content/browser/tab_contents/constrained_window.h new file mode 100644 index 0000000..7dd0b40 --- /dev/null +++ b/content/browser/tab_contents/constrained_window.h @@ -0,0 +1,62 @@ +// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CONTENT_BROWSER_TAB_CONTENTS_CONSTRAINED_WINDOW_H_ +#define CONTENT_BROWSER_TAB_CONTENTS_CONSTRAINED_WINDOW_H_ +#pragma once + +#include "build/build_config.h" + +// The different platform specific subclasses use different delegates for their +// dialogs. +#if defined(OS_WIN) +namespace views { +class WindowDelegate; +class DialogDelegate; +} +typedef views::WindowDelegate ConstrainedWindowDelegate; +typedef views::DialogDelegate ConstrainedDialogDelegate; +#elif defined(OS_MACOSX) +class ConstrainedWindowMacDelegate; +class ConstrainedWindowMacDelegateSystemSheet; +typedef ConstrainedWindowMacDelegate ConstrainedWindowDelegate; +typedef ConstrainedWindowMacDelegateSystemSheet ConstrainedDialogDelegate; +#elif defined(TOOLKIT_USES_GTK) +class ConstrainedWindowGtkDelegate; +typedef ConstrainedWindowGtkDelegate ConstrainedWindowDelegate; +typedef ConstrainedWindowGtkDelegate ConstrainedDialogDelegate; +#endif + +class TabContents; + +/////////////////////////////////////////////////////////////////////////////// +// ConstrainedWindow +// +// This interface represents a window that is constrained to a TabContents' +// bounds. +// +class ConstrainedWindow { + public: + // Create a Constrained Window that contains a platform specific client + // area. Typical uses include the HTTP Basic Auth prompt. The caller must + // provide a delegate to describe the content area and to respond to events. + static ConstrainedWindow* CreateConstrainedDialog( + TabContents* owner, + ConstrainedWindowDelegate* delegate); + + // Makes the Constrained Window visible. Only one Constrained Window is shown + // at a time per tab. + virtual void ShowConstrainedWindow() = 0; + + // Closes the Constrained Window. + virtual void CloseConstrainedWindow() = 0; + + // Sets focus on the Constrained Window. + virtual void FocusConstrainedWindow() {} + + protected: + virtual ~ConstrainedWindow() {} +}; + +#endif // CONTENT_BROWSER_TAB_CONTENTS_CONSTRAINED_WINDOW_H_ diff --git a/content/browser/tab_contents/infobar_delegate.cc b/content/browser/tab_contents/infobar_delegate.cc new file mode 100644 index 0000000..77b76c9 --- /dev/null +++ b/content/browser/tab_contents/infobar_delegate.cc @@ -0,0 +1,83 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "content/browser/tab_contents/infobar_delegate.h" + +#include "base/logging.h" +#include "build/build_config.h" +#include "content/browser/tab_contents/navigation_entry.h" +#include "content/browser/tab_contents/navigation_controller.h" +#include "content/browser/tab_contents/tab_contents.h" + +// InfoBarDelegate ------------------------------------------------------------ + +InfoBarDelegate::~InfoBarDelegate() { +} + +bool InfoBarDelegate::EqualsDelegate(InfoBarDelegate* delegate) const { + return false; +} + +bool InfoBarDelegate::ShouldExpire( + const NavigationController::LoadCommittedDetails& details) const { + return (contents_unique_id_ != details.entry->unique_id()) || + (PageTransition::StripQualifier(details.entry->transition_type()) == + PageTransition::RELOAD); +} + +void InfoBarDelegate::InfoBarDismissed() { +} + +void InfoBarDelegate::InfoBarClosed() { +} + +SkBitmap* InfoBarDelegate::GetIcon() const { + return NULL; +} + +InfoBarDelegate::Type InfoBarDelegate::GetInfoBarType() const { + return WARNING_TYPE; +} + +ConfirmInfoBarDelegate* InfoBarDelegate::AsConfirmInfoBarDelegate() { + return NULL; +} + +CrashedExtensionInfoBarDelegate* + InfoBarDelegate::AsCrashedExtensionInfoBarDelegate() { + return NULL; +} + +ExtensionInfoBarDelegate* InfoBarDelegate::AsExtensionInfoBarDelegate() { + return NULL; +} + +LinkInfoBarDelegate* InfoBarDelegate::AsLinkInfoBarDelegate() { + return NULL; +} + +PluginInstallerInfoBarDelegate* + InfoBarDelegate::AsPluginInstallerInfoBarDelegate() { + return NULL; +} + +ThemeInstalledInfoBarDelegate* + InfoBarDelegate::AsThemePreviewInfobarDelegate() { + return NULL; +} + +TranslateInfoBarDelegate* InfoBarDelegate::AsTranslateInfoBarDelegate() { + return NULL; +} + +InfoBarDelegate::InfoBarDelegate(TabContents* contents) + : contents_unique_id_(0) { + if (contents) + StoreActiveEntryUniqueID(contents); +} + +void InfoBarDelegate::StoreActiveEntryUniqueID(TabContents* contents) { + NavigationEntry* active_entry = contents->controller().GetActiveEntry(); + contents_unique_id_ = active_entry ? active_entry->unique_id() : 0; +} diff --git a/content/browser/tab_contents/infobar_delegate.h b/content/browser/tab_contents/infobar_delegate.h new file mode 100644 index 0000000..b4c6921 --- /dev/null +++ b/content/browser/tab_contents/infobar_delegate.h @@ -0,0 +1,118 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CONTENT_BROWSER_TAB_CONTENTS_INFOBAR_DELEGATE_H_ +#define CONTENT_BROWSER_TAB_CONTENTS_INFOBAR_DELEGATE_H_ +#pragma once + +#include "base/basictypes.h" +#include "base/string16.h" +#include "content/browser/tab_contents/navigation_controller.h" +#include "webkit/glue/window_open_disposition.h" + +class ConfirmInfoBarDelegate; +class CrashedExtensionInfoBarDelegate; +class ExtensionInfoBarDelegate; +class InfoBar; +class LinkInfoBarDelegate; +class PluginInstallerInfoBarDelegate; +class SkBitmap; +class ThemeInstalledInfoBarDelegate; +class TranslateInfoBarDelegate; + +// An interface implemented by objects wishing to control an InfoBar. +// Implementing this interface is not sufficient to use an InfoBar, since it +// does not map to a specific InfoBar type. Instead, you must implement either +// LinkInfoBarDelegate or ConfirmInfoBarDelegate, or override with your own +// delegate for your own InfoBar variety. +// +// --- WARNING --- +// When creating your InfoBarDelegate subclass, it is recommended that you +// design it such that you instantiate a brand new delegate for every call to +// AddInfoBar, rather than re-using/sharing a delegate object. Otherwise, +// you need to consider the fact that more than one InfoBar instance can exist +// and reference the same delegate -- even though it is also true that we only +// ever fully show one infobar (they don't stack). The dual-references occur +// because a second InfoBar can be added while the first one is in the process +// of closing (the animations). This can cause problems because when the first +// one does finally fully close InfoBarDelegate::InfoBarClosed() is called, +// and the delegate is free to clean itself up or reset state, which may have +// fatal consequences for the InfoBar that was in the process of opening (or is +// now fully opened) -- it is referencing a delegate that may not even exist +// anymore. +// As such, it is generally much safer to dedicate a delegate instance to +// AddInfoBar! +class InfoBarDelegate { + public: + // The type of the infobar. It controls its appearance, such as its background + // color. + enum Type { + WARNING_TYPE, + PAGE_ACTION_TYPE, + }; + + virtual ~InfoBarDelegate(); + + // Called to create the InfoBar. Implementation of this method is + // platform-specific. + virtual InfoBar* CreateInfoBar() = 0; + + // Returns true if the supplied |delegate| is equal to this one. Equality is + // left to the implementation to define. This function is called by the + // TabContents when determining whether or not a delegate should be added + // because a matching one already exists. If this function returns true, the + // TabContents will not add the new delegate because it considers one to + // already be present. + virtual bool EqualsDelegate(InfoBarDelegate* delegate) const; + + // Returns true if the InfoBar should be closed automatically after the page + // is navigated. The default behavior is to return true if the page is + // navigated somewhere else or reloaded. + virtual bool ShouldExpire( + const NavigationController::LoadCommittedDetails& details) const; + + // Called when the user clicks on the close button to dismiss the infobar. + virtual void InfoBarDismissed(); + + // Called after the InfoBar is closed. The delegate is free to delete itself + // at this point. + virtual void InfoBarClosed(); + + // Return the icon to be shown for this InfoBar. If the returned bitmap is + // NULL, no icon is shown. + virtual SkBitmap* GetIcon() const; + + // Returns the type of the infobar. The type determines the appearance (such + // as background color) of the infobar. + virtual Type GetInfoBarType() const; + + // Type-checking downcast routines: + virtual ConfirmInfoBarDelegate* AsConfirmInfoBarDelegate(); + virtual CrashedExtensionInfoBarDelegate* AsCrashedExtensionInfoBarDelegate(); + virtual ExtensionInfoBarDelegate* AsExtensionInfoBarDelegate(); + virtual LinkInfoBarDelegate* AsLinkInfoBarDelegate(); + virtual PluginInstallerInfoBarDelegate* AsPluginInstallerInfoBarDelegate(); + virtual ThemeInstalledInfoBarDelegate* AsThemePreviewInfobarDelegate(); + virtual TranslateInfoBarDelegate* AsTranslateInfoBarDelegate(); + + protected: + // Provided to subclasses as a convenience to initialize the state of this + // object. If |contents| is non-NULL, its active entry's unique ID will be + // stored using StoreActiveEntryUniqueID automatically. + explicit InfoBarDelegate(TabContents* contents); + + // Store the unique id for the active entry in the specified TabContents, to + // be used later upon navigation to determine if this InfoBarDelegate should + // be expired from |contents_|. + void StoreActiveEntryUniqueID(TabContents* contents); + + private: + // The unique id of the active NavigationEntry of the TabContents that we were + // opened for. Used to help expire on navigations. + int contents_unique_id_; + + DISALLOW_COPY_AND_ASSIGN(InfoBarDelegate); +}; + +#endif // CONTENT_BROWSER_TAB_CONTENTS_INFOBAR_DELEGATE_H_ diff --git a/chrome/browser/tab_contents/interstitial_page.cc b/content/browser/tab_contents/interstitial_page.cc index 47fb774..d13965e 100644 --- a/chrome/browser/tab_contents/interstitial_page.cc +++ b/content/browser/tab_contents/interstitial_page.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/browser/tab_contents/interstitial_page.h" +#include "content/browser/tab_contents/interstitial_page.h" #include <vector> @@ -22,15 +22,14 @@ #include "chrome/browser/renderer_host/resource_dispatcher_host.h" #include "chrome/browser/renderer_host/site_instance.h" #include "chrome/browser/renderer_preferences_util.h" -#include "chrome/browser/tab_contents/navigation_controller.h" -#include "chrome/browser/tab_contents/navigation_entry.h" -#include "chrome/browser/tab_contents/tab_contents.h" -#include "chrome/browser/tab_contents/tab_contents_view.h" #include "chrome/common/bindings_policy.h" #include "chrome/common/dom_storage_common.h" #include "chrome/common/net/url_request_context_getter.h" #include "chrome/common/notification_source.h" -#include "grit/browser_resources.h" +#include "content/browser/tab_contents/navigation_controller.h" +#include "content/browser/tab_contents/navigation_entry.h" +#include "content/browser/tab_contents/tab_contents.h" +#include "content/browser/tab_contents/tab_contents_view.h" #include "net/base/escape.h" #if defined(TOOLKIT_GTK) diff --git a/content/browser/tab_contents/interstitial_page.h b/content/browser/tab_contents/interstitial_page.h new file mode 100644 index 0000000..b3f9e1c --- /dev/null +++ b/content/browser/tab_contents/interstitial_page.h @@ -0,0 +1,245 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CONTENT_BROWSER_TAB_CONTENTS_INTERSTITIAL_PAGE_H_ +#define CONTENT_BROWSER_TAB_CONTENTS_INTERSTITIAL_PAGE_H_ +#pragma once + +#include <map> +#include <string> + +#include "base/process_util.h" +#include "base/scoped_ptr.h" +#include "chrome/browser/renderer_host/render_view_host_delegate.h" +#include "chrome/common/notification_observer.h" +#include "chrome/common/notification_registrar.h" +#include "chrome/common/renderer_preferences.h" +#include "googleurl/src/gurl.h" +#include "ui/gfx/size.h" + +class NavigationEntry; +class TabContents; +class TabContentsView; + +// This class is a base class for interstitial pages, pages that show some +// informative message asking for user validation before reaching the target +// page. (Navigating to a page served over bad HTTPS or a page containing +// malware are typical cases where an interstitial is required.) +// +// If specified in its constructor, this class creates a navigation entry so +// that when the interstitial shows, the current entry is the target URL. +// +// InterstitialPage instances take care of deleting themselves when closed +// through a navigation, the TabContents closing them or the tab containing them +// being closed. + +enum ResourceRequestAction { + BLOCK, + RESUME, + CANCEL +}; + +class InterstitialPage : public NotificationObserver, + public RenderViewHostDelegate { + public: + // The different state of actions the user can take in an interstitial. + enum ActionState { + NO_ACTION, // No action has been taken yet. + PROCEED_ACTION, // "Proceed" was selected. + DONT_PROCEED_ACTION // "Don't proceed" was selected. + }; + + // Creates an interstitial page to show in |tab|. |new_navigation| should be + // set to true when the interstitial is caused by loading a new page, in which + // case a temporary navigation entry is created with the URL |url| and + // added to the navigation controller (so the interstitial page appears as a + // new navigation entry). |new_navigation| should be false when the + // interstitial was triggered by a loading a sub-resource in a page. + InterstitialPage(TabContents* tab, bool new_navigation, const GURL& url); + virtual ~InterstitialPage(); + + // Shows the interstitial page in the tab. + virtual void Show(); + + // Hides the interstitial page. Warning: this deletes the InterstitialPage. + void Hide(); + + // Retrieves the InterstitialPage if any associated with the specified + // |tab_contents| (used by ui tests). + static InterstitialPage* GetInterstitialPage(TabContents* tab_contents); + + // Sub-classes should return the HTML that should be displayed in the page. + virtual std::string GetHTMLContents(); + + // Reverts to the page showing before the interstitial. + // Sub-classes should call this method when the user has chosen NOT to proceed + // to the target URL. + // Warning: if |new_navigation| was set to true in the constructor, 'this' + // will be deleted when this method returns. + virtual void DontProceed(); + + // Sub-classes should call this method when the user has chosen to proceed to + // the target URL. + // Warning: 'this' has been deleted when this method returns. + virtual void Proceed(); + + // Allows the user to navigate away by disabling the interstitial, canceling + // the pending request, and unblocking the hidden renderer. The interstitial + // will stay visible until the navigation completes. + void CancelForNavigation(); + + // Sizes the RenderViewHost showing the actual interstitial page contents. + void SetSize(const gfx::Size& size); + + ActionState action_taken() const { return action_taken_; } + + // Sets the focus to the interstitial. + void Focus(); + + // Focus the first (last if reverse is true) element in the interstitial page. + // Called when tab traversing. + void FocusThroughTabTraversal(bool reverse); + + virtual ViewType::Type GetRenderViewType() const; + virtual int GetBrowserWindowID() const; + + // See description above field. + void set_reload_on_dont_proceed(bool value) { + reload_on_dont_proceed_ = value; + } + bool reload_on_dont_proceed() const { return reload_on_dont_proceed_; } + + virtual void UpdateInspectorSetting(const std::string& key, + const std::string& value); + virtual void ClearInspectorSettings(); + + protected: + // NotificationObserver method: + virtual void Observe(NotificationType type, + const NotificationSource& source, + const NotificationDetails& details); + + // RenderViewHostDelegate implementation: + virtual View* GetViewDelegate(); + virtual const GURL& GetURL() const; + virtual void RenderViewGone(RenderViewHost* render_view_host, + base::TerminationStatus status, + int error_code); + virtual void DidNavigate(RenderViewHost* render_view_host, + const ViewHostMsg_FrameNavigate_Params& params); + virtual void UpdateTitle(RenderViewHost* render_view_host, + int32 page_id, + const std::wstring& title); + virtual void DomOperationResponse(const std::string& json_string, + int automation_id); + virtual RendererPreferences GetRendererPrefs(Profile* profile) const; + + // Invoked when the page sent a command through DOMAutomation. + virtual void CommandReceived(const std::string& command) {} + + // Invoked with the NavigationEntry that is going to be added to the + // navigation controller. + // Gives an opportunity to sub-classes to set states on the |entry|. + // Note that this is only called if the InterstitialPage was constructed with + // |create_navigation_entry| set to true. + virtual void UpdateEntry(NavigationEntry* entry) {} + + TabContents* tab() const { return tab_; } + const GURL& url() const { return url_; } + RenderViewHost* render_view_host() const { return render_view_host_; } + + // Creates the RenderViewHost containing the interstitial content. + // Overriden in unit tests. + virtual RenderViewHost* CreateRenderViewHost(); + + // Creates the TabContentsView that shows the interstitial RVH. + // Overriden in unit tests. + virtual TabContentsView* CreateTabContentsView(); + + private: + // AutomationProvider needs access to Proceed and DontProceed to simulate + // user actions. + friend class AutomationProvider; + + class InterstitialPageRVHViewDelegate; + + // Initializes tab_to_interstitial_page_ in a thread-safe manner. + // Should be called before accessing tab_to_interstitial_page_. + static void InitInterstitialPageMap(); + + // Disable the interstitial: + // - if it is not yet showing, then it won't be shown. + // - any command sent by the RenderViewHost will be ignored. + void Disable(); + + // Executes the passed action on the ResourceDispatcher (on the IO thread). + // Used to block/resume/cancel requests for the RenderViewHost hidden by this + // interstitial. + void TakeActionOnResourceDispatcher(ResourceRequestAction action); + + // The tab in which we are displayed. + TabContents* tab_; + + // The URL that is shown when the interstitial is showing. + GURL url_; + + // Whether this interstitial is shown as a result of a new navigation (in + // which case a transient navigation entry is created). + bool new_navigation_; + + // Whether we should discard the pending navigation entry when not proceeding. + // This is to deal with cases where |new_navigation_| is true but a new + // pending entry was created since this interstitial was shown and we should + // not discard it. + bool should_discard_pending_nav_entry_; + + // If true and the user chooses not to proceed the target NavigationController + // is reloaded. This is used when two NavigationControllers are merged + // (CopyStateFromAndPrune). + // The default is false. + bool reload_on_dont_proceed_; + + // Whether this interstitial is enabled. See Disable() for more info. + bool enabled_; + + // Whether the Proceed or DontProceed methods have been called yet. + ActionState action_taken_; + + // Notification magic. + NotificationRegistrar notification_registrar_; + + // The RenderViewHost displaying the interstitial contents. + RenderViewHost* render_view_host_; + + // The IDs for the Render[View|Process]Host hidden by this interstitial. + int original_child_id_; + int original_rvh_id_; + + // Whether or not we should change the title of the tab when hidden (to revert + // it to its original value). + bool should_revert_tab_title_; + + // Whether the ResourceDispatcherHost has been notified to cancel/resume the + // resource requests blocked for the RenderViewHost. + bool resource_dispatcher_host_notified_; + + // The original title of the tab that should be reverted to when the + // interstitial is hidden. + std::wstring original_tab_title_; + + // Our RenderViewHostViewDelegate, necessary for accelerators to work. + scoped_ptr<InterstitialPageRVHViewDelegate> rvh_view_delegate_; + + // We keep a map of the various blocking pages shown as the UI tests need to + // be able to retrieve them. + typedef std::map<TabContents*, InterstitialPage*> InterstitialPageMap; + static InterstitialPageMap* tab_to_interstitial_page_; + + // Settings passed to the renderer. + RendererPreferences renderer_preferences_; + + DISALLOW_COPY_AND_ASSIGN(InterstitialPage); +}; + +#endif // CONTENT_BROWSER_TAB_CONTENTS_INTERSTITIAL_PAGE_H_ diff --git a/chrome/browser/tab_contents/language_state.cc b/content/browser/tab_contents/language_state.cc index 5f78876..86712d1 100644 --- a/chrome/browser/tab_contents/language_state.cc +++ b/content/browser/tab_contents/language_state.cc @@ -2,10 +2,10 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/browser/tab_contents/language_state.h" +#include "content/browser/tab_contents/language_state.h" -#include "chrome/browser/tab_contents/navigation_controller.h" -#include "chrome/browser/tab_contents/navigation_entry.h" +#include "content/browser/tab_contents/navigation_controller.h" +#include "content/browser/tab_contents/navigation_entry.h" LanguageState::LanguageState(NavigationController* nav_controller) : navigation_controller_(nav_controller), diff --git a/content/browser/tab_contents/language_state.h b/content/browser/tab_contents/language_state.h new file mode 100644 index 0000000..d0c6204 --- /dev/null +++ b/content/browser/tab_contents/language_state.h @@ -0,0 +1,109 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CONTENT_BROWSER_TAB_CONTENTS_LANGUAGE_STATE_H_ +#define CONTENT_BROWSER_TAB_CONTENTS_LANGUAGE_STATE_H_ +#pragma once + +#include <string> + +#include "base/basictypes.h" +#include "content/browser/tab_contents/navigation_controller.h" + +// This class holds the language state of the current page. +// There is one LanguageState instance per TabContents. +// It is used to determine when navigating to a new page whether it should +// automatically be translated. +// This auto-translate behavior is the expected behavior when: +// - user is on page in language A that they had translated to language B. +// - user clicks a link in that page that takes them to a page also in language +// A. + +class LanguageState { + public: + explicit LanguageState(NavigationController* nav_controller); + ~LanguageState(); + + // Should be called when the page did a new navigation (whether it is a main + // frame or sub-frame navigation). + void DidNavigate(const NavigationController::LoadCommittedDetails& details); + + // Should be called when the language of the page has been determined. + // |page_translatable| when false indicates that the browser should not offer + // to translate the page. + void LanguageDetermined(const std::string& page_language, + bool page_translatable); + + // Returns the language the current page should be translated to, based on the + // previous page languages and the transition. This should be called after + // the language page has been determined. + // Returns an empty string if the page should not be auto-translated. + std::string AutoTranslateTo() const; + + // Returns true if the current page in the associated tab has been translated. + bool IsPageTranslated() const { return original_lang_ != current_lang_; } + + const std::string& original_language() const { return original_lang_; } + + void set_current_language(const std::string& language) { + current_lang_ = language; + } + const std::string& current_language() const { return current_lang_; } + + bool page_translatable() const { return page_translatable_; } + + // Whether the page is currently in the process of being translated. + bool translation_pending() const { return translation_pending_; } + void set_translation_pending(bool value) { translation_pending_ = value; } + + // Whether the user has already declined to translate the page. + bool translation_declined() const { return translation_declined_; } + void set_translation_declined(bool value) { translation_declined_ = value; } + + // Whether the current page was navigated through an in-page (fragment) + // navigation. + bool in_page_navigation() const { return in_page_navigation_; } + + private: + // The languages this page is in. Note that current_lang_ is different from + // original_lang_ when the page has been translated. + // Note that these might be empty if the page language has not been determined + // yet. + std::string original_lang_; + std::string current_lang_; + + // Same as above but for the previous page. + std::string prev_original_lang_; + std::string prev_current_lang_; + + // The navigation controller of the tab we are associated with. + NavigationController* navigation_controller_; + + // Whether it is OK to offer to translate the page. Some pages explictly + // specify that they should not be translated by the browser (this is the case + // for GMail for example, which provides its own translation features). + bool page_translatable_; + + // Whether a translation is currently pending (TabContents waiting for the + // PAGE_TRANSLATED notification). This is needed to avoid sending duplicate + // translate requests to a page. TranslateManager initiates translations + // when it received the LANGUAGE_DETERMINED notification. This is sent by + // the renderer with the page contents, every time the load stops for the + // main frame, so we may get several. + // TODO(jcampan): make the renderer send the language just once per navigation + // then we can get rid of that state. + bool translation_pending_; + + // Whether the user has declined to translate the page (by closing the infobar + // for example). This is necessary as a new infobar could be shown if a new + // load happens in the page after the user closed the infobar. + bool translation_declined_; + + // Whether the current navigation is a fragment navigation (in page). + bool in_page_navigation_; + + DISALLOW_COPY_AND_ASSIGN(LanguageState); +}; + +#endif // CONTENT_BROWSER_TAB_CONTENTS_LANGUAGE_STATE_H_ diff --git a/chrome/browser/tab_contents/navigation_controller.cc b/content/browser/tab_contents/navigation_controller.cc index f294535..2ac9aba 100644 --- a/chrome/browser/tab_contents/navigation_controller.cc +++ b/content/browser/tab_contents/navigation_controller.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/browser/tab_contents/navigation_controller.h" +#include "content/browser/tab_contents/navigation_controller.h" #include "base/file_util.h" #include "base/logging.h" @@ -16,16 +16,16 @@ #include "chrome/browser/profiles/profile.h" #include "chrome/browser/renderer_host/site_instance.h" #include "chrome/browser/sessions/session_types.h" -#include "chrome/browser/tab_contents/interstitial_page.h" -#include "chrome/browser/tab_contents/navigation_entry.h" -#include "chrome/browser/tab_contents/tab_contents.h" -#include "chrome/browser/tab_contents/tab_contents_delegate.h" #include "chrome/common/chrome_constants.h" #include "chrome/common/navigation_types.h" #include "chrome/common/notification_service.h" #include "chrome/common/pref_names.h" #include "chrome/common/render_messages_params.h" #include "chrome/common/url_constants.h" +#include "content/browser/tab_contents/interstitial_page.h" +#include "content/browser/tab_contents/navigation_entry.h" +#include "content/browser/tab_contents/tab_contents.h" +#include "content/browser/tab_contents/tab_contents_delegate.h" #include "grit/app_resources.h" #include "net/base/escape.h" #include "net/base/net_util.h" diff --git a/content/browser/tab_contents/navigation_controller.h b/content/browser/tab_contents/navigation_controller.h new file mode 100644 index 0000000..f348368 --- /dev/null +++ b/content/browser/tab_contents/navigation_controller.h @@ -0,0 +1,603 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CONTENT_BROWSER_TAB_CONTENTS_NAVIGATION_CONTROLLER_H_ +#define CONTENT_BROWSER_TAB_CONTENTS_NAVIGATION_CONTROLLER_H_ +#pragma once + +#include "build/build_config.h" + +#include <string> +#include <vector> + +#include "base/linked_ptr.h" +#include "base/time.h" +#include "googleurl/src/gurl.h" +#include "chrome/browser/sessions/session_id.h" +#include "chrome/browser/ssl/ssl_manager.h" +#include "chrome/common/navigation_types.h" +#include "chrome/common/page_transition_types.h" + +class NavigationEntry; +class Profile; +class SessionStorageNamespace; +class SiteInstance; +class TabContents; +class TabNavigation; +struct ViewHostMsg_FrameNavigate_Params; + +// A NavigationController maintains the back-forward list for a single tab and +// manages all navigation within that list. +// +// The NavigationController also owns all TabContents for the tab. This is to +// make sure that we have at most one TabContents instance per type. +class NavigationController { + public: + // Notification details ------------------------------------------------------ + + // Provides the details for a NOTIFY_NAV_ENTRY_CHANGED notification. + struct EntryChangedDetails { + // The changed navigation entry after it has been updated. + const NavigationEntry* changed_entry; + + // Indicates the current index in the back/forward list of the entry. + int index; + }; + + // Provides the details for a NOTIFY_NAV_ENTRY_COMMITTED notification. + // TODO(brettw) this mostly duplicates ProvisionalLoadDetails, it would be + // nice to unify these somehow. + struct LoadCommittedDetails { + // By default, the entry will be filled according to a new main frame + // navigation. + LoadCommittedDetails() + : entry(NULL), + type(NavigationType::UNKNOWN), + previous_entry_index(-1), + is_auto(false), + did_replace_entry(false), + is_in_page(false), + is_main_frame(true), + is_content_filtered(false), + http_status_code(0) { + } + + // The committed entry. This will be the active entry in the controller. + NavigationEntry* entry; + + // The type of navigation that just occurred. Note that not all types of + // navigations in the enum are valid here, since some of them don't actually + // cause a "commit" and won't generate this notification. + NavigationType::Type type; + + // The index of the previously committed navigation entry. This will be -1 + // if there are no previous entries. + int previous_entry_index; + + // The previous URL that the user was on. This may be empty if none. + GURL previous_url; + + // True when this load was non-user initated. This corresponds to a + // a NavigationGestureAuto call from WebKit (see webview_delegate.h). + // We also count reloads and meta-refreshes as "auto" to account for the + // fact that WebKit doesn't always set the user gesture properly in these + // cases (see bug 1051891). + bool is_auto; + + // True if the committed entry has replaced the exisiting one. + // A non-user initiated redirect causes such replacement. + // This is somewhat similiar to is_auto, but not exactly the same. + bool did_replace_entry; + + // True if the navigation was in-page. This means that the active entry's + // URL and the |previous_url| are the same except for reference fragments. + bool is_in_page; + + // True when the main frame was navigated. False means the navigation was a + // sub-frame. + bool is_main_frame; + + // Whether the content of this frame has been altered/blocked because it was + // unsafe. + bool is_content_filtered; + + // When the committed load is a web page from the renderer, this string + // specifies the security state if the page is secure. + // See ViewHostMsg_FrameNavigate_Params.security_info, where it comes from. + // Use SSLManager::DeserializeSecurityInfo to decode it. + std::string serialized_security_info; + + // Returns whether the user probably felt like they navigated somewhere new. + // We often need this logic for showing or hiding something, and this + // returns true only for main frame loads that the user initiated, that go + // to a new page. + bool is_user_initiated_main_frame_load() const { + return !is_auto && !is_in_page && is_main_frame; + } + + // The HTTP status code for this entry.. + int http_status_code; + }; + + // Details sent for NOTIFY_NAV_LIST_PRUNED. + struct PrunedDetails { + // If true, count items were removed from the front of the list, otherwise + // count items were removed from the back of the list. + bool from_front; + + // Number of items removed. + int count; + }; + + enum ReloadType { + NO_RELOAD, // Normal load. + RELOAD, // Normal (cache-validating) reload. + RELOAD_IGNORING_CACHE // Reload bypassing the cache, aka shift-reload. + }; + + // --------------------------------------------------------------------------- + + NavigationController(TabContents* tab_contents, + Profile* profile, + SessionStorageNamespace* session_storage_namespace); + ~NavigationController(); + + // Returns the profile for this controller. It can never be NULL. + Profile* profile() const { + return profile_; + } + + // Sets the profile for this controller. + void set_profile(Profile* profile) { + profile_ = profile; + } + + // Initializes this NavigationController with the given saved navigations, + // using selected_navigation as the currently loaded entry. Before this call + // the controller should be unused (there should be no current entry). If + // from_last_session is true, navigations are from the previous session, + // otherwise they are from the current session (undo tab close). + // This is used for session restore. + void RestoreFromState(const std::vector<TabNavigation>& navigations, + int selected_navigation, bool from_last_session); + + // Active entry -------------------------------------------------------------- + + // Returns the active entry, which is the transient entry if any, the pending + // entry if a navigation is in progress or the last committed entry otherwise. + // NOTE: This can be NULL!! + // + // If you are trying to get the current state of the NavigationController, + // this is the method you will typically want to call. + NavigationEntry* GetActiveEntry() const; + + // Returns the index from which we would go back/forward or reload. This is + // the last_committed_entry_index_ if pending_entry_index_ is -1. Otherwise, + // it is the pending_entry_index_. + int GetCurrentEntryIndex() const; + + // Returns the last committed entry, which may be null if there are no + // committed entries. + NavigationEntry* GetLastCommittedEntry() const; + + // Returns true if the source for the current entry can be viewed. + bool CanViewSource() const; + + // Returns the index of the last committed entry. + int last_committed_entry_index() const { + return last_committed_entry_index_; + } + + // Navigation list ----------------------------------------------------------- + + // Returns the number of entries in the NavigationController, excluding + // the pending entry if there is one, but including the transient entry if + // any. + int entry_count() const { + return static_cast<int>(entries_.size()); + } + + NavigationEntry* GetEntryAtIndex(int index) const { + return entries_.at(index).get(); + } + + // Returns the entry at the specified offset from current. Returns NULL + // if out of bounds. + NavigationEntry* GetEntryAtOffset(int offset) const; + + // Returns the index of the specified entry, or -1 if entry is not contained + // in this NavigationController. + int GetIndexOfEntry(const NavigationEntry* entry) const; + + // Return the index of the entry with the corresponding instance and page_id, + // or -1 if not found. + int GetEntryIndexWithPageID(SiteInstance* instance, + int32 page_id) const; + + // Return the entry with the corresponding instance and page_id, or NULL if + // not found. + NavigationEntry* GetEntryWithPageID(SiteInstance* instance, + int32 page_id) const; + + // Pending entry ------------------------------------------------------------- + + // Commits the current pending entry and issues the NOTIFY_NAV_ENTRY_COMMIT + // notification. No changes are made to the entry during this process, it is + // just moved from pending to committed. This is an alternative to + // RendererDidNavigate for simple TabContents types. + // + // When the pending entry is a new navigation, it will have a page ID of -1. + // The caller should leave this as-is. CommitPendingEntry will generate a + // new page ID for you and update the TabContents with that ID. + void CommitPendingEntry(); + + // Discards the pending and transient entries if any. + void DiscardNonCommittedEntries(); + + // Returns the pending entry corresponding to the navigation that is + // currently in progress, or null if there is none. + NavigationEntry* pending_entry() const { + return pending_entry_; + } + + // Returns the index of the pending entry or -1 if the pending entry + // corresponds to a new navigation (created via LoadURL). + int pending_entry_index() const { + return pending_entry_index_; + } + + // Transient entry ----------------------------------------------------------- + + // Adds an entry that is returned by GetActiveEntry(). The entry is + // transient: any navigation causes it to be removed and discarded. + // The NavigationController becomes the owner of |entry| and deletes it when + // it discards it. This is useful with interstitial page that need to be + // represented as an entry, but should go away when the user navigates away + // from them. + // Note that adding a transient entry does not change the active contents. + void AddTransientEntry(NavigationEntry* entry); + + // Returns the transient entry if any. Note that the returned entry is owned + // by the navigation controller and may be deleted at any time. + NavigationEntry* GetTransientEntry() const; + + // New navigations ----------------------------------------------------------- + + // Loads the specified URL. + void LoadURL(const GURL& url, const GURL& referrer, + PageTransition::Type type); + + // Loads the current page if this NavigationController was restored from + // history and the current page has not loaded yet. + void LoadIfNecessary(); + + // Renavigation -------------------------------------------------------------- + + // Navigation relative to the "current entry" + bool CanGoBack() const; + bool CanGoForward() const; + void GoBack(); + void GoForward(); + + // Navigates to the specified absolute index. + void GoToIndex(int index); + + // Navigates to the specified offset from the "current entry". Does nothing if + // the offset is out of bounds. + void GoToOffset(int offset); + + // Reloads the current entry. If |check_for_repost| is true and the current + // entry has POST data the user is prompted to see if they really want to + // reload the page. In nearly all cases pass in true. + void Reload(bool check_for_repost); + // Like Reload(), but don't use caches (aka "shift-reload"). + void ReloadIgnoringCache(bool check_for_repost); + + // Removing of entries ------------------------------------------------------- + + // Removes the entry at the specified |index|. This call dicards any pending + // and transient entries. |default_url| is the URL that the navigation + // controller navigates to if there are no more entries after the removal. + // If |default_url| is empty, we default to "about:blank". + void RemoveEntryAtIndex(int index, const GURL& default_url); + + // TabContents --------------------------------------------------------------- + + // Returns the tab contents associated with this controller. Non-NULL except + // during set-up of the tab. + TabContents* tab_contents() const { + // This currently returns the active tab contents which should be renamed to + // tab_contents. + return tab_contents_; + } + + // Called when a document has been loaded in a frame. + void DocumentLoadedInFrame(); + + // For use by TabContents ---------------------------------------------------- + + // Handles updating the navigation state after the renderer has navigated. + // This is used by the TabContents. Simpler tab contents types can use + // CommitPendingEntry below. + // + // If a new entry is created, it will return true and will have filled the + // given details structure and broadcast the NOTIFY_NAV_ENTRY_COMMITTED + // notification. The caller can then use the details without worrying about + // listening for the notification. + // + // In the case that nothing has changed, the details structure is undefined + // and it will return false. + // + // |extra_invalidate_flags| are an additional set of flags (InvalidateTypes) + // added to the flags sent to the delegate's NotifyNavigationStateChanged. + bool RendererDidNavigate(const ViewHostMsg_FrameNavigate_Params& params, + int extra_invalidate_flags, + LoadCommittedDetails* details); + + // Notifies us that we just became active. This is used by the TabContents + // so that we know to load URLs that were pending as "lazy" loads. + void SetActive(bool is_active); + + // Broadcasts the NOTIFY_NAV_ENTRY_CHANGED notification for the given entry + // (which must be at the given index). This will keep things in sync like + // the saved session. + void NotifyEntryChanged(const NavigationEntry* entry, int index); + + // Returns true if the given URL would be an in-page navigation (i.e. only + // the reference fragment is different) from the "last committed entry". We do + // not compare it against the "active entry" since the active entry can be + // pending and in page navigations only happen on committed pages. If there + // is no last committed entry, then nothing will be in-page. + // + // Special note: if the URLs are the same, it does NOT count as an in-page + // navigation. Neither does an input URL that has no ref, even if the rest is + // the same. This may seem weird, but when we're considering whether a + // navigation happened without loading anything, the same URL would be a + // reload, while only a different ref would be in-page (pages can't clear + // refs without reload, only change to "#" which we don't count as empty). + bool IsURLInPageNavigation(const GURL& url) const; + + // Copies the navigation state from the given controller to this one. This + // one should be empty (just created). + void CopyStateFrom(const NavigationController& source); + + // A variant of CopyStateFrom. Removes all entries from this except the last + // entry, inserts all entries from |source| before and including the active + // entry. This method is intended for use when the last entry of |this| is the + // active entry. For example: + // source: A B *C* D + // this: E F *G* (last must be active or pending) + // result: A B *G* + // This ignores the transient index of the source and honors that of 'this'. + void CopyStateFromAndPrune(NavigationController* source); + + // Removes all the entries except the active entry. If there is a new pending + // navigation it is preserved. + void PruneAllButActive(); + + // Random data --------------------------------------------------------------- + + // Returns the identifier used by session restore. + const SessionID& session_id() const { return session_id_; } + + // Identifier of the window we're in. + void SetWindowID(const SessionID& id); + const SessionID& window_id() const { return window_id_; } + + SSLManager* ssl_manager() { return &ssl_manager_; } + + // Returns true if a reload happens when activated (SetActive(true) is + // invoked). This is true for session/tab restore and cloned tabs. + bool needs_reload() const { return needs_reload_; } + + // Sets the max restored page ID this NavigationController has seen, if it + // was restored from a previous session. + void set_max_restored_page_id(int32 max_id) { + max_restored_page_id_ = max_id; + } + + // Returns the largest restored page ID seen in this navigation controller, + // if it was restored from a previous session. (-1 otherwise) + int32 max_restored_page_id() const { return max_restored_page_id_; } + + // The session storage namespace that all child render views should use. + SessionStorageNamespace* session_storage_namespace() const { + return session_storage_namespace_; + } + + // Disables checking for a repost and prompting the user. This is used during + // testing. + static void DisablePromptOnRepost(); + + // Maximum number of entries before we start removing entries from the front. +#ifdef UNIT_TEST + static void set_max_entry_count(size_t max_entry_count) { + max_entry_count_ = max_entry_count; + } +#endif + static size_t max_entry_count() { return max_entry_count_; } + + // Cancels a repost that brought up a warning. + void CancelPendingReload(); + // Continues a repost that brought up a warning. + void ContinuePendingReload(); + + // Returns true if we are navigating to the URL the tab is opened with. + bool IsInitialNavigation(); + + // Creates navigation entry and translates the virtual url to a real one. + // Used when restoring a tab from a TabNavigation object and when navigating + // to a new URL using LoadURL. + static NavigationEntry* CreateNavigationEntry(const GURL& url, + const GURL& referrer, + PageTransition::Type transition, + Profile* profile); + + private: + class RestoreHelper; + friend class RestoreHelper; + friend class TabContents; // For invoking OnReservedPageIDRange. + + // Classifies the given renderer navigation (see the NavigationType enum). + NavigationType::Type ClassifyNavigation( + const ViewHostMsg_FrameNavigate_Params& params) const; + + // Causes the controller to load the specified entry. The function assumes + // ownership of the pointer since it is put in the navigation list. + // NOTE: Do not pass an entry that the controller already owns! + void LoadEntry(NavigationEntry* entry); + + // Handlers for the different types of navigation types. They will actually + // handle the navigations corresponding to the different NavClasses above. + // They will NOT broadcast the commit notification, that should be handled by + // the caller. + // + // RendererDidNavigateAutoSubframe is special, it may not actually change + // anything if some random subframe is loaded. It will return true if anything + // changed, or false if not. + // + // The functions taking |did_replace_entry| will fill into the given variable + // whether the last entry has been replaced or not. + // See LoadCommittedDetails.did_replace_entry. + void RendererDidNavigateToNewPage( + const ViewHostMsg_FrameNavigate_Params& params, bool* did_replace_entry); + void RendererDidNavigateToExistingPage( + const ViewHostMsg_FrameNavigate_Params& params); + void RendererDidNavigateToSamePage( + const ViewHostMsg_FrameNavigate_Params& params); + void RendererDidNavigateInPage( + const ViewHostMsg_FrameNavigate_Params& params, bool* did_replace_entry); + void RendererDidNavigateNewSubframe( + const ViewHostMsg_FrameNavigate_Params& params); + bool RendererDidNavigateAutoSubframe( + const ViewHostMsg_FrameNavigate_Params& params); + + // Helper function for code shared between Reload() and ReloadIgnoringCache(). + void ReloadInternal(bool check_for_repost, ReloadType reload_type); + + // Actually issues the navigation held in pending_entry. + void NavigateToPendingEntry(ReloadType reload_type); + + // Allows the derived class to issue notifications that a load has been + // committed. This will fill in the active entry to the details structure. + // + // |extra_invalidate_flags| are an additional set of flags (InvalidateTypes) + // added to the flags sent to the delegate's NotifyNavigationStateChanged. + void NotifyNavigationEntryCommitted(LoadCommittedDetails* details, + int extra_invalidate_flags); + + // Updates the virtual URL of an entry to match a new URL, for cases where + // the real renderer URL is derived from the virtual URL, like view-source: + void UpdateVirtualURLToURL(NavigationEntry* entry, const GURL& new_url); + + // Invoked after session/tab restore or cloning a tab. Resets the transition + // type of the entries, updates the max page id and creates the active + // contents. See RestoreFromState for a description of from_last_session. + void FinishRestore(int selected_index, bool from_last_session); + + // Inserts a new entry or replaces the current entry with a new one, removing + // all entries after it. The new entry will become the active one. + void InsertOrReplaceEntry(NavigationEntry* entry, bool replace); + + // Discards the pending and transient entries. + void DiscardNonCommittedEntriesInternal(); + + // Discards the transient entry. + void DiscardTransientEntry(); + + // Returns true if the navigation is redirect. + bool IsRedirect(const ViewHostMsg_FrameNavigate_Params& params); + + // Returns true if the navigation is likley to be automatic rather than + // user-initiated. + bool IsLikelyAutoNavigation(base::TimeTicks now); + + // Creates a new NavigationEntry for each TabNavigation in navigations, adding + // the NavigationEntry to entries. This is used during session restore. + void CreateNavigationEntriesFromTabNavigations( + const std::vector<TabNavigation>& navigations, + std::vector<linked_ptr<NavigationEntry> >* entries); + + // Inserts up to |max_index| entries from |source| into this. This does NOT + // adjust any of the members that reference entries_ + // (last_committed_entry_index_, pending_entry_index_ or + // transient_entry_index_). + void InsertEntriesFrom(const NavigationController& source, int max_index); + + // --------------------------------------------------------------------------- + + // The user profile associated with this controller + Profile* profile_; + + // List of NavigationEntry for this tab + typedef std::vector<linked_ptr<NavigationEntry> > NavigationEntries; + NavigationEntries entries_; + + // An entry we haven't gotten a response for yet. This will be discarded + // when we navigate again. It's used only so we know what the currently + // displayed tab is. + // + // This may refer to an item in the entries_ list if the pending_entry_index_ + // == -1, or it may be its own entry that should be deleted. Be careful with + // the memory management. + NavigationEntry* pending_entry_; + + // currently visible entry + int last_committed_entry_index_; + + // index of pending entry if it is in entries_, or -1 if pending_entry_ is a + // new entry (created by LoadURL). + int pending_entry_index_; + + // The index for the entry that is shown until a navigation occurs. This is + // used for interstitial pages. -1 if there are no such entry. + // Note that this entry really appears in the list of entries, but only + // temporarily (until the next navigation). Any index pointing to an entry + // after the transient entry will become invalid if you navigate forward. + int transient_entry_index_; + + // The tab contents associated with the controller. Possibly NULL during + // setup. + TabContents* tab_contents_; + + // The max restored page ID in this controller, if it was restored. We must + // store this so that TabContents can tell any renderer in charge of one of + // the restored entries to update its max page ID. + int32 max_restored_page_id_; + + // Manages the SSL security UI + SSLManager ssl_manager_; + + // Whether we need to be reloaded when made active. + bool needs_reload_; + + // Unique identifier of this controller for session restore. This id is only + // unique within the current session, and is not guaranteed to be unique + // across sessions. + SessionID session_id_; + + // Unique identifier of the window we're in. Used by session restore. + SessionID window_id_; + + // The time ticks at which the last document was loaded. + base::TimeTicks last_document_loaded_; + + // The session storage id that any (indirectly) owned RenderView should use. + scoped_refptr<SessionStorageNamespace> session_storage_namespace_; + + // Should Reload check for post data? The default is true, but is set to false + // when testing. + static bool check_for_repost_; + + // The maximum number of entries that a navigation controller can store. + static size_t max_entry_count_; + + // If a repost is pending, its type (RELOAD or RELOAD_IGNORING_CACHE), + // NO_RELOAD otherwise. + ReloadType pending_reload_; + + DISALLOW_COPY_AND_ASSIGN(NavigationController); +}; + +#endif // CONTENT_BROWSER_TAB_CONTENTS_NAVIGATION_CONTROLLER_H_ diff --git a/chrome/browser/tab_contents/navigation_controller_unittest.cc b/content/browser/tab_contents/navigation_controller_unittest.cc index 2691305..2691305 100644 --- a/chrome/browser/tab_contents/navigation_controller_unittest.cc +++ b/content/browser/tab_contents/navigation_controller_unittest.cc diff --git a/chrome/browser/tab_contents/navigation_entry.cc b/content/browser/tab_contents/navigation_entry.cc index 25af057..147461b 100644 --- a/chrome/browser/tab_contents/navigation_entry.cc +++ b/content/browser/tab_contents/navigation_entry.cc @@ -2,15 +2,15 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/browser/tab_contents/navigation_entry.h" +#include "content/browser/tab_contents/navigation_entry.h" #include "base/string_util.h" #include "base/utf_string_conversions.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/renderer_host/site_instance.h" -#include "chrome/browser/tab_contents/navigation_controller.h" #include "chrome/common/chrome_constants.h" #include "chrome/common/url_constants.h" +#include "content/browser/tab_contents/navigation_controller.h" #include "grit/app_resources.h" #include "net/base/net_util.h" #include "ui/base/resource/resource_bundle.h" diff --git a/content/browser/tab_contents/navigation_entry.h b/content/browser/tab_contents/navigation_entry.h new file mode 100644 index 0000000..84db5ef2 --- /dev/null +++ b/content/browser/tab_contents/navigation_entry.h @@ -0,0 +1,429 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CONTENT_BROWSER_TAB_CONTENTS_NAVIGATION_ENTRY_H_ +#define CONTENT_BROWSER_TAB_CONTENTS_NAVIGATION_ENTRY_H_ +#pragma once + +#include <string> + +#include "base/basictypes.h" +#include "base/ref_counted.h" +#include "chrome/common/page_type.h" +#include "chrome/common/page_transition_types.h" +#include "chrome/common/security_style.h" +#include "googleurl/src/gurl.h" +#include "third_party/skia/include/core/SkBitmap.h" + +class SiteInstance; + +//////////////////////////////////////////////////////////////////////////////// +// +// NavigationEntry class +// +// A NavigationEntry is a data structure that captures all the information +// required to recreate a browsing state. This includes some opaque binary +// state as provided by the TabContents as well as some clear text title and +// URL which is used for our user interface. +// +//////////////////////////////////////////////////////////////////////////////// +class NavigationEntry { + public: + // SSL ----------------------------------------------------------------------- + + // Collects the SSL information for this NavigationEntry. + class SSLStatus { + public: + // Flags used for the page security content status. + enum ContentStatusFlags { + // HTTP page, or HTTPS page with no insecure content. + NORMAL_CONTENT = 0, + + // HTTPS page containing "displayed" HTTP resources (e.g. images, CSS). + DISPLAYED_INSECURE_CONTENT = 1 << 0, + + // HTTPS page containing "executed" HTTP resources (i.e. script). + // Also currently used for HTTPS page containing broken-HTTPS resources; + // this is wrong and should be fixed (see comments in + // SSLPolicy::OnRequestStarted()). + RAN_INSECURE_CONTENT = 1 << 1, + }; + + SSLStatus(); + + bool Equals(const SSLStatus& status) const { + return security_style_ == status.security_style_ && + cert_id_ == status.cert_id_ && + cert_status_ == status.cert_status_ && + security_bits_ == status.security_bits_ && + content_status_ == status.content_status_; + } + + void set_security_style(SecurityStyle security_style) { + security_style_ = security_style; + } + SecurityStyle security_style() const { + return security_style_; + } + + void set_cert_id(int ssl_cert_id) { + cert_id_ = ssl_cert_id; + } + int cert_id() const { + return cert_id_; + } + + void set_cert_status(int ssl_cert_status) { + cert_status_ = ssl_cert_status; + } + int cert_status() const { + return cert_status_; + } + + void set_security_bits(int security_bits) { + security_bits_ = security_bits; + } + int security_bits() const { + return security_bits_; + } + + void set_displayed_insecure_content() { + content_status_ |= DISPLAYED_INSECURE_CONTENT; + } + bool displayed_insecure_content() const { + return (content_status_ & DISPLAYED_INSECURE_CONTENT) != 0; + } + + void set_ran_insecure_content() { + content_status_ |= RAN_INSECURE_CONTENT; + } + bool ran_insecure_content() const { + return (content_status_ & RAN_INSECURE_CONTENT) != 0; + } + + void set_connection_status(int connection_status) { + connection_status_ = connection_status; + } + int connection_status() const { + return connection_status_; + } + + // Raw accessors for all the content status flags. This contains a + // combination of any of the ContentStatusFlags defined above. It is used + // by some tests for checking and for certain copying. Use the per-status + // functions for normal usage. + void set_content_status(int content_status) { + content_status_ = content_status; + } + int content_status() const { + return content_status_; + } + + private: + // See the accessors above for descriptions. + SecurityStyle security_style_; + int cert_id_; + int cert_status_; + int security_bits_; + int connection_status_; + int content_status_; + + // Copy and assignment is explicitly allowed for this class. + }; + + // Favicon ------------------------------------------------------------------- + + // Collects the favicon related information for a NavigationEntry. + class FaviconStatus { + public: + FaviconStatus(); + + // Indicates whether we've gotten an official favicon for the page, or are + // just using the default favicon. + void set_is_valid(bool is_valid) { + valid_ = is_valid; + } + bool is_valid() const { + return valid_; + } + + // The URL of the favicon which was used to load it off the web. + void set_url(const GURL& favicon_url) { + url_ = favicon_url; + } + const GURL& url() const { + return url_; + } + + // The favicon bitmap for the page. If the favicon has not been explicitly + // set or it empty, it will return the default favicon. Note that this is + // loaded asynchronously, so even if the favicon URL is valid we may return + // the default favicon if we haven't gotten the data yet. + void set_bitmap(const SkBitmap& bitmap) { + bitmap_ = bitmap; + } + const SkBitmap& bitmap() const { + return bitmap_; + } + + private: + // See the accessors above for descriptions. + bool valid_; + GURL url_; + SkBitmap bitmap_; + + // Copy and assignment is explicitly allowed for this class. + }; + + // --------------------------------------------------------------------------- + + NavigationEntry(); + NavigationEntry(SiteInstance* instance, + int page_id, + const GURL& url, + const GURL& referrer, + const string16& title, + PageTransition::Type transition_type); + ~NavigationEntry(); + + // Page-related stuff -------------------------------------------------------- + + // A unique ID is preserved across commits and redirects, which means that + // sometimes a NavigationEntry's unique ID needs to be set (e.g. when + // creating a committed entry to correspond to a to-be-deleted pending entry, + // the pending entry's ID must be copied). + void set_unique_id(int unique_id) { + unique_id_ = unique_id; + } + int unique_id() const { + return unique_id_; + } + + // The SiteInstance tells us how to share sub-processes when the tab type is + // TAB_CONTENTS_WEB. This will be NULL otherwise. This is a reference counted + // pointer to a shared site instance. + // + // Note that the SiteInstance should usually not be changed after it is set, + // but this may happen if the NavigationEntry was cloned and needs to use a + // different SiteInstance. + void set_site_instance(SiteInstance* site_instance); + SiteInstance* site_instance() const { + return site_instance_; + } + + // The page type tells us if this entry is for an interstitial or error page. + // See the PageType enum above. + void set_page_type(PageType page_type) { + page_type_ = page_type; + } + PageType page_type() const { + return page_type_; + } + + // The actual URL of the page. For some about pages, this may be a scary + // data: URL or something like that. Use virtual_url() below for showing to + // the user. + void set_url(const GURL& url) { + url_ = url; + cached_display_title_.clear(); + } + const GURL& url() const { + return url_; + } + + // The referring URL. Can be empty. + void set_referrer(const GURL& referrer) { + referrer_ = referrer; + } + const GURL& referrer() const { + return referrer_; + } + + // The virtual URL, when nonempty, will override the actual URL of the page + // when we display it to the user. This allows us to have nice and friendly + // URLs that the user sees for things like about: URLs, but actually feed + // the renderer a data URL that results in the content loading. + // + // virtual_url() will return the URL to display to the user in all cases, so + // if there is no overridden display URL, it will return the actual one. + void set_virtual_url(const GURL& url) { + virtual_url_ = (url == url_) ? GURL() : url; + cached_display_title_.clear(); + } + bool has_virtual_url() const { + return !virtual_url_.is_empty(); + } + const GURL& virtual_url() const { + return virtual_url_.is_empty() ? url_ : virtual_url_; + } + + bool update_virtual_url_with_url() const { + return update_virtual_url_with_url_; + } + void set_update_virtual_url_with_url(bool update) { + update_virtual_url_with_url_ = update; + } + + // The title as set by the page. This will be empty if there is no title set. + // The caller is responsible for detecting when there is no title and + // displaying the appropriate "Untitled" label if this is being displayed to + // the user. + void set_title(const string16& title) { + title_ = title; + cached_display_title_.clear(); + } + const string16& title() const { + return title_; + } + + // The favicon data and tracking information. See FaviconStatus above. + const FaviconStatus& favicon() const { + return favicon_; + } + FaviconStatus& favicon() { + return favicon_; + } + + // Content state is an opaque blob created by WebKit that represents the + // state of the page. This includes form entries and scroll position for each + // frame. We store it so that we can supply it back to WebKit to restore form + // state properly when the user goes back and forward. + // + // WARNING: This state is saved to the file and used to restore previous + // states. If the format is modified in the future, we should still be able to + // deal with older versions. + void set_content_state(const std::string& state) { + content_state_ = state; + } + const std::string& content_state() const { + return content_state_; + } + + // Describes the current page that the tab represents. For web pages + // (TAB_CONTENTS_WEB) this is the ID that the renderer generated for the page + // and is how we can tell new versus renavigations. + void set_page_id(int page_id) { + page_id_ = page_id; + } + int32 page_id() const { + return page_id_; + } + + // All the SSL flags and state. See SSLStatus above. + const SSLStatus& ssl() const { + return ssl_; + } + SSLStatus& ssl() { + return ssl_; + } + + // Page-related helpers ------------------------------------------------------ + + // Returns the title to be displayed on the tab. This could be the title of + // the page if it is available or the URL. |languages| is the list of + // accpeted languages (e.g., prefs::kAcceptLanguages) or empty if proper + // URL formatting isn't needed (e.g., unit tests). + const string16& GetTitleForDisplay(const std::string& languages); + + // Returns true if the current tab is in view source mode. This will be false + // if there is no navigation. + bool IsViewSourceMode() const; + + // Tracking stuff ------------------------------------------------------------ + + // The transition type indicates what the user did to move to this page from + // the previous page. + void set_transition_type(PageTransition::Type transition_type) { + transition_type_ = transition_type; + } + PageTransition::Type transition_type() const { + return transition_type_; + } + + // The user typed URL was the URL that the user initiated the navigation + // with, regardless of any redirects. This is used to generate keywords, for + // example, based on "what the user thinks the site is called" rather than + // what it's actually called. For example, if the user types "foo.com", that + // may redirect somewhere arbitrary like "bar.com/foo", and we want to use + // the name that the user things of the site as having. + // + // This URL will be is_empty() if the URL was navigated to some other way. + // Callers should fall back on using the regular or display URL in this case. + void set_user_typed_url(const GURL& user_typed_url) { + user_typed_url_ = user_typed_url; + } + const GURL& user_typed_url() const { + return user_typed_url_; + } + + // Post data is form data that was posted to get to this page. The data will + // have to be reposted to reload the page properly. This flag indicates + // whether the page had post data. + // + // The actual post data is stored in the content_state and is extracted by + // WebKit to actually make the request. + void set_has_post_data(bool has_post_data) { + has_post_data_ = has_post_data; + } + bool has_post_data() const { + return has_post_data_; + } + + // Enumerations of the possible restore types. + enum RestoreType { + // The entry has been restored is from the last session. + RESTORE_LAST_SESSION, + + // The entry has been restored from the current session. This is used when + // the user issues 'reopen closed tab'. + RESTORE_CURRENT_SESSION, + + // The entry was not restored. + RESTORE_NONE + }; + + // The RestoreType for this entry. This is set if the entry was retored. This + // is set to RESTORE_NONE once the entry is loaded. + void set_restore_type(RestoreType type) { + restore_type_ = type; + } + RestoreType restore_type() const { + return restore_type_; + } + + private: + // WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING + // Session/Tab restore save portions of this class so that it can be recreated + // later. If you add a new field that needs to be persisted you'll have to + // update SessionService/TabRestoreService appropriately. + // WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING + + // See the accessors above for descriptions. + int unique_id_; + scoped_refptr<SiteInstance> site_instance_; + PageType page_type_; + GURL url_; + GURL referrer_; + GURL virtual_url_; + bool update_virtual_url_with_url_; + string16 title_; + FaviconStatus favicon_; + std::string content_state_; + int32 page_id_; + SSLStatus ssl_; + PageTransition::Type transition_type_; + GURL user_typed_url_; + bool has_post_data_; + RestoreType restore_type_; + + // This is a cached version of the result of GetTitleForDisplay. It prevents + // us from having to do URL formatting on the URL evey time the title is + // displayed. When the URL, virtual URL, or title is set, this should be + // cleared to force a refresh. + string16 cached_display_title_; + + // Copy and assignment is explicitly allowed for this class. +}; + +#endif // CONTENT_BROWSER_TAB_CONTENTS_NAVIGATION_ENTRY_H_ diff --git a/chrome/browser/tab_contents/navigation_entry_unittest.cc b/content/browser/tab_contents/navigation_entry_unittest.cc index 014817c..014817c 100644 --- a/chrome/browser/tab_contents/navigation_entry_unittest.cc +++ b/content/browser/tab_contents/navigation_entry_unittest.cc diff --git a/content/browser/tab_contents/page_navigator.h b/content/browser/tab_contents/page_navigator.h new file mode 100644 index 0000000..e411c24 --- /dev/null +++ b/content/browser/tab_contents/page_navigator.h @@ -0,0 +1,30 @@ +// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// PageNavigator defines an interface that can be used to express the user's +// intention to navigate to a particular URL. The implementing class should +// perform the navigation. + +#ifndef CONTENT_BROWSER_TAB_CONTENTS_PAGE_NAVIGATOR_H_ +#define CONTENT_BROWSER_TAB_CONTENTS_PAGE_NAVIGATOR_H_ +#pragma once + +#include "chrome/common/page_transition_types.h" +#include "webkit/glue/window_open_disposition.h" + +class GURL; + +class PageNavigator { + public: + // Opens a URL with the given disposition. The transition specifies how this + // navigation should be recorded in the history system (for example, typed). + virtual void OpenURL(const GURL& url, const GURL& referrer, + WindowOpenDisposition disposition, + PageTransition::Type transition) = 0; + + protected: + virtual ~PageNavigator() {} +}; + +#endif // CONTENT_BROWSER_TAB_CONTENTS_PAGE_NAVIGATOR_H_ diff --git a/chrome/browser/tab_contents/provisional_load_details.cc b/content/browser/tab_contents/provisional_load_details.cc index 3cd59a7e..d85d846 100644 --- a/chrome/browser/tab_contents/provisional_load_details.cc +++ b/content/browser/tab_contents/provisional_load_details.cc @@ -3,7 +3,7 @@ // found in the LICENSE file. -#include "chrome/browser/tab_contents/provisional_load_details.h" +#include "content/browser/tab_contents/provisional_load_details.h" #include "chrome/browser/ssl/ssl_manager.h" diff --git a/content/browser/tab_contents/provisional_load_details.h b/content/browser/tab_contents/provisional_load_details.h new file mode 100644 index 0000000..54fe887 --- /dev/null +++ b/content/browser/tab_contents/provisional_load_details.h @@ -0,0 +1,82 @@ +// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CONTENT_BROWSER_TAB_CONTENTS_PROVISIONAL_LOAD_DETAILS_H_ +#define CONTENT_BROWSER_TAB_CONTENTS_PROVISIONAL_LOAD_DETAILS_H_ +#pragma once + +#include <string> + +#include "base/basictypes.h" +#include "chrome/common/page_transition_types.h" +#include "googleurl/src/gurl.h" + +// This class captures some of the information associated to the provisional +// load of a frame. It is provided as Details with the +// NOTIFY_FRAME_PROVISIONAL_LOAD_START, NOTIFY_FRAME_PROVISIONAL_LOAD_COMMITTED +// and NOTIFY_FAIL_PROVISIONAL_LOAD_WITH_ERROR notifications +// (see notification_types.h). + +// TODO(brettw) this mostly duplicates +// NavigationController::LoadCommittedDetails, it would be nice to unify these +// somehow. +class ProvisionalLoadDetails { + public: + ProvisionalLoadDetails(bool main_frame, + bool in_page_navigation, + const GURL& url, + const std::string& security_info, + bool is_filtered, + bool is_error_page, + int64 frame_id); + virtual ~ProvisionalLoadDetails() { } + + void set_error_code(int error_code) { error_code_ = error_code; } + int error_code() const { return error_code_; } + + void set_transition_type(PageTransition::Type transition_type) { + transition_type_ = transition_type; + } + PageTransition::Type transition_type() const { + return transition_type_; + } + + const GURL& url() const { return url_; } + + bool main_frame() const { return is_main_frame_; } + + bool in_page_navigation() const { return is_in_page_navigation_; } + + int ssl_cert_id() const { return ssl_cert_id_; } + + int ssl_cert_status() const { return ssl_cert_status_; } + + int ssl_security_bits() const { return ssl_security_bits_; } + + int ssl_connection_status() const { return ssl_connection_status_; } + + bool is_content_filtered() const { return is_content_filtered_; } + + bool is_error_page() const { return is_error_page_; } + + int64 frame_id() const { return frame_id_; } + + private: + int error_code_; + PageTransition::Type transition_type_; + GURL url_; + bool is_main_frame_; + bool is_in_page_navigation_; + int ssl_cert_id_; + int ssl_cert_status_; + int ssl_security_bits_; + int ssl_connection_status_; + bool is_content_filtered_; + bool is_error_page_; + int64 frame_id_; + + DISALLOW_COPY_AND_ASSIGN(ProvisionalLoadDetails); +}; + +#endif // CONTENT_BROWSER_TAB_CONTENTS_PROVISIONAL_LOAD_DETAILS_H_ diff --git a/chrome/browser/tab_contents/render_view_host_manager.cc b/content/browser/tab_contents/render_view_host_manager.cc index 55902d8..556c3b7 100644 --- a/chrome/browser/tab_contents/render_view_host_manager.cc +++ b/content/browser/tab_contents/render_view_host_manager.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/browser/tab_contents/render_view_host_manager.h" +#include "content/browser/tab_contents/render_view_host_manager.h" #include "base/command_line.h" #include "base/logging.h" @@ -13,9 +13,6 @@ #include "chrome/browser/renderer_host/render_view_host_factory.h" #include "chrome/browser/renderer_host/render_widget_host_view.h" #include "chrome/browser/renderer_host/site_instance.h" -#include "chrome/browser/tab_contents/navigation_controller.h" -#include "chrome/browser/tab_contents/navigation_entry.h" -#include "chrome/browser/tab_contents/tab_contents_view.h" #include "chrome/browser/webui/web_ui.h" #include "chrome/browser/webui/web_ui_factory.h" #include "chrome/common/chrome_switches.h" @@ -24,6 +21,9 @@ #include "chrome/common/render_messages.h" #include "chrome/common/render_messages_params.h" #include "chrome/common/url_constants.h" +#include "content/browser/tab_contents/navigation_controller.h" +#include "content/browser/tab_contents/navigation_entry.h" +#include "content/browser/tab_contents/tab_contents_view.h" namespace base { class WaitableEvent; diff --git a/content/browser/tab_contents/render_view_host_manager.h b/content/browser/tab_contents/render_view_host_manager.h new file mode 100644 index 0000000..04e4109 --- /dev/null +++ b/content/browser/tab_contents/render_view_host_manager.h @@ -0,0 +1,273 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CONTENT_BROWSER_TAB_CONTENTS_RENDER_VIEW_HOST_MANAGER_H_ +#define CONTENT_BROWSER_TAB_CONTENTS_RENDER_VIEW_HOST_MANAGER_H_ +#pragma once + +#include "base/basictypes.h" +#include "base/logging.h" +#include "base/scoped_ptr.h" +#include "chrome/browser/renderer_host/render_view_host_delegate.h" +#include "chrome/common/notification_registrar.h" + +class WebUI; +class InterstitialPage; +class NavigationController; +class NavigationEntry; +class Profile; +class RenderWidgetHostView; +class RenderViewHost; +class SiteInstance; + +// Manages RenderViewHosts for a TabContents. Normally there is only one and +// it is easy to do. But we can also have transitions of processes (and hence +// RenderViewHosts) that can get complex. +class RenderViewHostManager + : public RenderViewHostDelegate::RendererManagement { + public: + // Functions implemented by our owner that we need. + // + // TODO(brettw) Clean this up! These are all the functions in TabContents that + // are required to run this class. The design should probably be better such + // that these are more clear. + // + // There is additional complexity that some of the functions we need in + // TabContents are inherited and non-virtual. These are named with + // "RenderManager" so that the duplicate implementation of them will be clear. + class Delegate { + public: + // See tab_contents.h's implementation for more. + virtual bool CreateRenderViewForRenderManager( + RenderViewHost* render_view_host) = 0; + virtual void BeforeUnloadFiredFromRenderManager( + bool proceed, bool* proceed_to_fire_unload) = 0; + virtual void DidStartLoadingFromRenderManager( + RenderViewHost* render_view_host) = 0; + virtual void RenderViewGoneFromRenderManager( + RenderViewHost* render_view_host) = 0; + virtual void UpdateRenderViewSizeForRenderManager() = 0; + virtual void NotifySwappedFromRenderManager() = 0; + virtual NavigationController& GetControllerForRenderManager() = 0; + + // Creates a WebUI object for the given URL if one applies. Ownership of the + // returned pointer will be passed to the caller. If no WebUI applies, + // returns NULL. + virtual WebUI* CreateWebUIForRenderManager(const GURL& url) = 0; + + // Returns the navigation entry of the current navigation, or NULL if there + // is none. + virtual NavigationEntry* + GetLastCommittedNavigationEntryForRenderManager() = 0; + + // Returns true if the location bar should be focused by default rather than + // the page contents. + virtual bool FocusLocationBarByDefault() = 0; + + // Focuses the location bar. + virtual void SetFocusToLocationBar(bool select_all) = 0; + + // Creates a view and sets the size for the specified RVH. + virtual void CreateViewAndSetSizeForRVH(RenderViewHost* rvh) = 0; + + protected: + virtual ~Delegate() {} + }; + + // Both delegate pointers must be non-NULL and are not owned by this class. + // They must outlive this class. The RenderViewHostDelegate is what will be + // installed into all RenderViewHosts that are created. + // + // You must call Init() before using this class. + RenderViewHostManager(RenderViewHostDelegate* render_view_delegate, + Delegate* delegate); + virtual ~RenderViewHostManager(); + + // For arguments, see TabContents constructor. + void Init(Profile* profile, + SiteInstance* site_instance, + int routing_id); + + // Returns the currently actuive RenderViewHost. + // + // This will be non-NULL between Init() and Shutdown(). You may want to NULL + // check it in many cases, however. Windows can send us messages during the + // destruction process after it has been shut down. + RenderViewHost* current_host() const { + return render_view_host_; + } + + // Returns the view associated with the current RenderViewHost, or NULL if + // there is no current one. + RenderWidgetHostView* GetRenderWidgetHostView() const; + + // Returns the pending render view host, or NULL if there is no pending one. + RenderViewHost* pending_render_view_host() const { + return pending_render_view_host_; + } + + // Returns the current committed Web UI or NULL if none applies. + WebUI* web_ui() const { return web_ui_.get(); } + + // Returns the Web UI for the pending navigation, or NULL of none applies. + WebUI* pending_web_ui() const { return pending_web_ui_.get(); } + + // Called when we want to instruct the renderer to navigate to the given + // navigation entry. It may create a new RenderViewHost or re-use an existing + // one. The RenderViewHost to navigate will be returned. Returns NULL if one + // could not be created. + RenderViewHost* Navigate(const NavigationEntry& entry); + + // Instructs the various live views to stop. Called when the user directed the + // page to stop loading. + void Stop(); + + // Notifies the regular and pending RenderViewHosts that a load is or is not + // happening. Even though the message is only for one of them, we don't know + // which one so we tell both. + void SetIsLoading(bool is_loading); + + // Whether to close the tab or not when there is a hang during an unload + // handler. If we are mid-crosssite navigation, then we should proceed + // with the navigation instead of closing the tab. + bool ShouldCloseTabOnUnresponsiveRenderer(); + + // Called when a renderer's main frame navigates. + void DidNavigateMainFrame(RenderViewHost* render_view_host); + + // Set the WebUI after committing a page load. This is useful for navigations + // initiated from a renderer, where we want to give the new renderer WebUI + // privileges from the originating renderer. + void SetWebUIPostCommit(WebUI* web_ui); + + // Called when a provisional load on the given renderer is aborted. + void RendererAbortedProvisionalLoad(RenderViewHost* render_view_host); + + // Sets the passed passed interstitial as the currently showing interstitial. + // |interstitial_page| should be non NULL (use the remove_interstitial_page + // method to unset the interstitial) and no interstitial page should be set + // when there is already a non NULL interstitial page set. + void set_interstitial_page(InterstitialPage* interstitial_page) { + DCHECK(!interstitial_page_ && interstitial_page); + interstitial_page_ = interstitial_page; + } + + // Unsets the currently showing interstitial. + void remove_interstitial_page() { + DCHECK(interstitial_page_); + interstitial_page_ = NULL; + } + + // Returns the currently showing interstitial, NULL if no interstitial is + // showing. + InterstitialPage* interstitial_page() const { + return interstitial_page_; + } + + // RenderViewHostDelegate::RendererManagement implementation. + virtual void ShouldClosePage(bool for_cross_site_transition, bool proceed); + virtual void OnCrossSiteResponse(int new_render_process_host_id, + int new_request_id); + virtual void OnCrossSiteNavigationCanceled(); + + // Called when a RenderViewHost is about to be deleted. + void RenderViewDeleted(RenderViewHost* rvh); + + // Allows a caller to swap in a provided RenderViewHost to replace the + // current RenderViewHost. The current RVH will be shutdown and ultimately + // deleted. + void SwapInRenderViewHost(RenderViewHost* rvh); + + private: + friend class TestTabContents; + friend class RenderViewHostManagerTest; + + // Returns whether this tab should transition to a new renderer for + // cross-site URLs. Enabled unless we see the --process-per-tab command line + // switch. Can be overridden in unit tests. + bool ShouldTransitionCrossSite(); + + // Returns true if the two navigation entries are incompatible in some way + // other than site instances. Cases where this can happen include Web UI + // to regular web pages. It will cause us to swap RenderViewHosts (and hence + // RenderProcessHosts) even if the site instance would otherwise be the same. + // As part of this, we'll also force new SiteInstances and BrowsingInstances. + // Either of the entries may be NULL. + bool ShouldSwapProcessesForNavigation( + const NavigationEntry* cur_entry, + const NavigationEntry* new_entry) const; + + // Returns an appropriate SiteInstance object for the given NavigationEntry, + // possibly reusing the current SiteInstance. + // Never called if --process-per-tab is used. + SiteInstance* GetSiteInstanceForEntry(const NavigationEntry& entry, + SiteInstance* curr_instance); + + // Helper method to create a pending RenderViewHost for a cross-site + // navigation. + bool CreatePendingRenderView(const NavigationEntry& entry, + SiteInstance* instance); + + // Sets up the necessary state for a new RenderViewHost navigating to the + // given entry. + bool InitRenderView(RenderViewHost* render_view_host, + const NavigationEntry& entry); + + // Sets the pending RenderViewHost/WebUI to be the active one. Note that this + // doesn't require the pending render_view_host_ pointer to be non-NULL, since + // there could be Web UI switching as well. Call this for every commit. + void CommitPending(); + + // Helper method to terminate the pending RenderViewHost. + void CancelPending(); + + RenderViewHost* UpdateRendererStateForNavigate(const NavigationEntry& entry); + + // Our delegate, not owned by us. Guaranteed non-NULL. + Delegate* delegate_; + + // Whether a navigation requiring different RenderView's is pending. This is + // either cross-site request is (in the new process model), or when required + // for the view type (like view source versus not). + bool cross_navigation_pending_; + + // Implemented by the owner of this class, this delegate is installed into all + // the RenderViewHosts that we create. + RenderViewHostDelegate* render_view_delegate_; + + // Our RenderView host and its associated Web UI (if any, will be NULL for + // non-DOM-UI pages). This object is responsible for all communication with + // a child RenderView instance. + RenderViewHost* render_view_host_; + scoped_ptr<WebUI> web_ui_; + + // A RenderViewHost used to load a cross-site page. This remains hidden + // while a cross-site request is pending until it calls DidNavigate. It may + // have an associated Web UI, in which case the Web UI pointer will be non- + // NULL. + // + // The pending_web_ui may be non-NULL even when the pending_render_view_host_ + // is. This will happen when we're transitioning between two Web UI pages: + // the RVH won't be swapped, so the pending pointer will be unused, but there + // will be a pending Web UI associated with the navigation. + RenderViewHost* pending_render_view_host_; + scoped_ptr<WebUI> pending_web_ui_; + + // The intersitial page currently shown if any, not own by this class + // (the InterstitialPage is self-owned, it deletes itself when hidden). + InterstitialPage* interstitial_page_; + + NotificationRegistrar registrar_; + + DISALLOW_COPY_AND_ASSIGN(RenderViewHostManager); +}; + +// The "details" for a NOTIFY_RENDER_VIEW_HOST_CHANGED notification. The old +// host can be NULL when the first RenderViewHost is set. +struct RenderViewHostSwitchedDetails { + RenderViewHost* old_host; + RenderViewHost* new_host; +}; + +#endif // CONTENT_BROWSER_TAB_CONTENTS_RENDER_VIEW_HOST_MANAGER_H_ diff --git a/chrome/browser/tab_contents/render_view_host_manager_unittest.cc b/content/browser/tab_contents/render_view_host_manager_unittest.cc index a4b82d8..a4b82d8 100644 --- a/chrome/browser/tab_contents/render_view_host_manager_unittest.cc +++ b/content/browser/tab_contents/render_view_host_manager_unittest.cc diff --git a/chrome/browser/tab_contents/tab_contents.cc b/content/browser/tab_contents/tab_contents.cc index 62666c9..30b91e9 100644 --- a/chrome/browser/tab_contents/tab_contents.cc +++ b/content/browser/tab_contents/tab_contents.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/browser/tab_contents/tab_contents.h" +#include "content/browser/tab_contents/tab_contents.h" #include <cmath> @@ -49,7 +49,6 @@ #include "chrome/browser/pdf_unsupported_feature.h" #include "chrome/browser/platform_util.h" #include "chrome/browser/plugin_observer.h" -#include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/prerender/prerender_manager.h" #include "chrome/browser/prerender/prerender_plt_recorder.h" #include "chrome/browser/printing/print_preview_message_handler.h" @@ -65,14 +64,7 @@ #include "chrome/browser/renderer_preferences_util.h" #include "chrome/browser/safe_browsing/client_side_detection_host.h" #include "chrome/browser/sessions/session_types.h" -#include "chrome/browser/tab_contents/infobar_delegate.h" -#include "chrome/browser/tab_contents/interstitial_page.h" -#include "chrome/browser/tab_contents/navigation_entry.h" -#include "chrome/browser/tab_contents/provisional_load_details.h" -#include "chrome/browser/tab_contents/tab_contents_delegate.h" -#include "chrome/browser/tab_contents/tab_contents_observer.h" #include "chrome/browser/tab_contents/tab_contents_ssl_helper.h" -#include "chrome/browser/tab_contents/tab_contents_view.h" #include "chrome/browser/tab_contents/thumbnail_generator.h" #include "chrome/browser/translate/page_translated_details.h" #include "chrome/browser/ui/app_modal_dialogs/message_box_handler.h" @@ -92,15 +84,16 @@ #include "chrome/common/render_messages.h" #include "chrome/common/render_messages_params.h" #include "chrome/common/url_constants.h" -#include "grit/chromium_strings.h" -#include "grit/generated_resources.h" -#include "grit/locale_settings.h" -#include "grit/platform_locale_settings.h" -#include "grit/theme_resources.h" +#include "content/browser/tab_contents/infobar_delegate.h" +#include "content/browser/tab_contents/interstitial_page.h" +#include "content/browser/tab_contents/navigation_entry.h" +#include "content/browser/tab_contents/provisional_load_details.h" +#include "content/browser/tab_contents/tab_contents_delegate.h" +#include "content/browser/tab_contents/tab_contents_observer.h" +#include "content/browser/tab_contents/tab_contents_view.h" #include "net/base/net_util.h" #include "net/base/registry_controlled_domain.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" -#include "ui/base/l10n/l10n_util.h" #include "ui/base/resource/resource_bundle.h" #include "ui/gfx/codec/png_codec.h" #include "webkit/glue/password_form.h" @@ -417,63 +410,6 @@ void TabContents::AddObservers() { this)); } -// static -void TabContents::RegisterUserPrefs(PrefService* prefs) { - prefs->RegisterBooleanPref(prefs::kAlternateErrorPagesEnabled, true); - - WebPreferences pref_defaults; - prefs->RegisterBooleanPref(prefs::kWebKitJavascriptEnabled, - pref_defaults.javascript_enabled); - prefs->RegisterBooleanPref(prefs::kWebKitWebSecurityEnabled, - pref_defaults.web_security_enabled); - prefs->RegisterBooleanPref( - prefs::kWebKitJavascriptCanOpenWindowsAutomatically, true); - prefs->RegisterBooleanPref(prefs::kWebKitLoadsImagesAutomatically, - pref_defaults.loads_images_automatically); - prefs->RegisterBooleanPref(prefs::kWebKitPluginsEnabled, - pref_defaults.plugins_enabled); - prefs->RegisterBooleanPref(prefs::kWebKitDomPasteEnabled, - pref_defaults.dom_paste_enabled); - prefs->RegisterBooleanPref(prefs::kWebKitShrinksStandaloneImagesToFit, - pref_defaults.shrinks_standalone_images_to_fit); - prefs->RegisterDictionaryPref(prefs::kWebKitInspectorSettings); - prefs->RegisterBooleanPref(prefs::kWebKitTextAreasAreResizable, - pref_defaults.text_areas_are_resizable); - prefs->RegisterBooleanPref(prefs::kWebKitJavaEnabled, - pref_defaults.java_enabled); - prefs->RegisterBooleanPref(prefs::kWebkitTabsToLinks, - pref_defaults.tabs_to_links); - - prefs->RegisterLocalizedStringPref(prefs::kAcceptLanguages, - IDS_ACCEPT_LANGUAGES); - prefs->RegisterLocalizedStringPref(prefs::kDefaultCharset, - IDS_DEFAULT_ENCODING); - prefs->RegisterLocalizedBooleanPref(prefs::kWebKitStandardFontIsSerif, - IDS_STANDARD_FONT_IS_SERIF); - prefs->RegisterLocalizedStringPref(prefs::kWebKitFixedFontFamily, - IDS_FIXED_FONT_FAMILY); - prefs->RegisterLocalizedStringPref(prefs::kWebKitSerifFontFamily, - IDS_SERIF_FONT_FAMILY); - prefs->RegisterLocalizedStringPref(prefs::kWebKitSansSerifFontFamily, - IDS_SANS_SERIF_FONT_FAMILY); - prefs->RegisterLocalizedStringPref(prefs::kWebKitCursiveFontFamily, - IDS_CURSIVE_FONT_FAMILY); - prefs->RegisterLocalizedStringPref(prefs::kWebKitFantasyFontFamily, - IDS_FANTASY_FONT_FAMILY); - prefs->RegisterLocalizedIntegerPref(prefs::kWebKitDefaultFontSize, - IDS_DEFAULT_FONT_SIZE); - prefs->RegisterLocalizedIntegerPref(prefs::kWebKitDefaultFixedFontSize, - IDS_DEFAULT_FIXED_FONT_SIZE); - prefs->RegisterLocalizedIntegerPref(prefs::kWebKitMinimumFontSize, - IDS_MINIMUM_FONT_SIZE); - prefs->RegisterLocalizedIntegerPref(prefs::kWebKitMinimumLogicalFontSize, - IDS_MINIMUM_LOGICAL_FONT_SIZE); - prefs->RegisterLocalizedBooleanPref(prefs::kWebKitUsesUniversalDetector, - IDS_USES_UNIVERSAL_DETECTOR); - prefs->RegisterLocalizedStringPref(prefs::kStaticEncodings, - IDS_STATIC_ENCODING_LIST); -} - bool TabContents::OnMessageReceived(const IPC::Message& message) { ObserverListBase<TabContentsObserver>::Iterator it(observers_); TabContentsObserver* observer; @@ -612,11 +548,6 @@ const string16& TabContents::GetTitle() const { return EmptyString16(); } -// static -string16 TabContents::GetDefaultTitle() { - return l10n_util::GetStringUTF16(IDS_DEFAULT_TAB_TITLE); -} - int32 TabContents::GetMaxPageID() { if (GetSiteInstance()) return GetSiteInstance()->max_page_id(); @@ -691,43 +622,6 @@ bool TabContents::ShouldDisplayFavIcon() { return true; } -string16 TabContents::GetStatusText() const { - if (!is_loading() || load_state_ == net::LOAD_STATE_IDLE) - return string16(); - - switch (load_state_) { - case net::LOAD_STATE_WAITING_FOR_CACHE: - return l10n_util::GetStringUTF16(IDS_LOAD_STATE_WAITING_FOR_CACHE); - case net::LOAD_STATE_ESTABLISHING_PROXY_TUNNEL: - return - l10n_util::GetStringUTF16(IDS_LOAD_STATE_ESTABLISHING_PROXY_TUNNEL); - case net::LOAD_STATE_RESOLVING_PROXY_FOR_URL: - return l10n_util::GetStringUTF16(IDS_LOAD_STATE_RESOLVING_PROXY_FOR_URL); - case net::LOAD_STATE_RESOLVING_HOST: - return l10n_util::GetStringUTF16(IDS_LOAD_STATE_RESOLVING_HOST); - case net::LOAD_STATE_CONNECTING: - return l10n_util::GetStringUTF16(IDS_LOAD_STATE_CONNECTING); - case net::LOAD_STATE_SSL_HANDSHAKE: - return l10n_util::GetStringUTF16(IDS_LOAD_STATE_SSL_HANDSHAKE); - case net::LOAD_STATE_SENDING_REQUEST: - if (upload_size_) - return l10n_util::GetStringFUTF16Int( - IDS_LOAD_STATE_SENDING_REQUEST_WITH_PROGRESS, - static_cast<int>((100 * upload_position_) / upload_size_)); - else - return l10n_util::GetStringUTF16(IDS_LOAD_STATE_SENDING_REQUEST); - case net::LOAD_STATE_WAITING_FOR_RESPONSE: - return l10n_util::GetStringFUTF16(IDS_LOAD_STATE_WAITING_FOR_RESPONSE, - load_state_host_); - // Ignore net::LOAD_STATE_READING_RESPONSE and net::LOAD_STATE_IDLE - case net::LOAD_STATE_IDLE: - case net::LOAD_STATE_READING_RESPONSE: - break; - } - - return string16(); -} - void TabContents::AddObserver(TabContentsObserver* observer) { observers_.AddObserver(observer); } @@ -2641,11 +2535,6 @@ void TabContents::OnIgnoredUIEvent() { } } -void TabContents::OnJSOutOfMemory() { - AddInfoBar(new SimpleAlertInfoBarDelegate(this, NULL, - l10n_util::GetStringUTF16(IDS_JS_OUT_OF_MEMORY_PROMPT), true)); -} - void TabContents::OnCrossSiteResponse(int new_render_process_host_id, int new_request_id) { // Allows the TabContents to react when a cross-site response is ready to be @@ -2728,8 +2617,8 @@ void TabContents::UpdateZoomLimits(int minimum_percent, } void TabContents::WorkerCrashed() { - AddInfoBar(new SimpleAlertInfoBarDelegate(this, NULL, - l10n_util::GetStringUTF16(IDS_WEBWORKER_CRASHED_PROMPT), true)); + if (delegate()) + delegate()->WorkerCrashed(); } void TabContents::BeforeUnloadFiredFromRenderManager( diff --git a/content/browser/tab_contents/tab_contents.h b/content/browser/tab_contents/tab_contents.h new file mode 100644 index 0000000..318e9fc --- /dev/null +++ b/content/browser/tab_contents/tab_contents.h @@ -0,0 +1,1258 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CONTENT_BROWSER_TAB_CONTENTS_TAB_CONTENTS_H_ +#define CONTENT_BROWSER_TAB_CONTENTS_TAB_CONTENTS_H_ +#pragma once + +#include <deque> +#include <map> +#include <string> +#include <vector> + +#include "base/basictypes.h" +#include "base/gtest_prod_util.h" +#include "base/scoped_ptr.h" +#include "base/string16.h" +#include "chrome/browser/download/save_package.h" +#include "chrome/browser/extensions/image_loading_tracker.h" +#include "chrome/browser/fav_icon_helper.h" +#include "chrome/browser/prefs/pref_change_registrar.h" +#include "chrome/browser/renderer_host/render_view_host_delegate.h" +#include "chrome/browser/tab_contents/tab_specific_content_settings.h" +#include "chrome/browser/ui/app_modal_dialogs/js_modal_dialog.h" +#include "chrome/browser/webui/web_ui_factory.h" +#include "chrome/common/notification_registrar.h" +#include "chrome/common/property_bag.h" +#include "chrome/common/renderer_preferences.h" +#include "chrome/common/translate_errors.h" +#include "chrome/common/web_apps.h" +#include "content/browser/tab_contents/constrained_window.h" +#include "content/browser/tab_contents/language_state.h" +#include "content/browser/tab_contents/navigation_controller.h" +#include "content/browser/tab_contents/navigation_entry.h" +#include "content/browser/tab_contents/page_navigator.h" +#include "content/browser/tab_contents/render_view_host_manager.h" +#include "net/base/load_states.h" +#include "ui/gfx/native_widget_types.h" + +#if defined(OS_WIN) +#include "base/win/scoped_handle.h" +#endif + +namespace gfx { +class Rect; +} + +namespace history { +class HistoryAddPageArgs; +} + +namespace prerender { +class PrerenderManager; +class PrerenderPLTRecorder; +} + +namespace printing { +class PrintPreviewMessageHandler; +class PrintViewManager; +} + +namespace safe_browsing { +class ClientSideDetectionHost; +} + +class AutocompleteHistoryManager; +class AutoFillManager; +class BlockedContentContainer; +class WebUI; +class DesktopNotificationHandlerForTC; +class DownloadItem; +class Extension; +class FileSelectHelper; +class InfoBarDelegate; +class LoadNotificationDetails; +class OmniboxSearchHint; +class PluginObserver; +class Profile; +class RenderViewHost; +class SessionStorageNamespace; +class SiteInstance; +class SkBitmap; +class TabContents; +class TabContentsDelegate; +class TabContentsObserver; +class TabContentsSSLHelper; +class TabContentsView; +class URLPattern; +struct RendererPreferences; +struct ThumbnailScore; +struct ViewHostMsg_DomMessage_Params; +struct ViewHostMsg_FrameNavigate_Params; +struct ViewHostMsg_RunFileChooser_Params; +struct WebPreferences; + +// Describes what goes in the main content area of a tab. TabContents is +// the only type of TabContents, and these should be merged together. +class TabContents : public PageNavigator, + public NotificationObserver, + public RenderViewHostDelegate, + public RenderViewHostManager::Delegate, + public JavaScriptAppModalDialogDelegate, + public ImageLoadingTracker::Observer, + public TabSpecificContentSettings::Delegate { + public: + // Flags passed to the TabContentsDelegate.NavigationStateChanged to tell it + // what has changed. Combine them to update more than one thing. + enum InvalidateTypes { + INVALIDATE_URL = 1 << 0, // The URL has changed. + INVALIDATE_TAB = 1 << 1, // The favicon, app icon, or crashed + // state changed. + INVALIDATE_LOAD = 1 << 2, // The loading state has changed. + INVALIDATE_PAGE_ACTIONS = 1 << 3, // Page action icons have changed. + INVALIDATE_BOOKMARK_BAR = 1 << 4, // State of ShouldShowBookmarkBar + // changed. + INVALIDATE_TITLE = 1 << 5, // The title changed. + }; + + // |base_tab_contents| is used if we want to size the new tab contents view + // based on an existing tab contents view. This can be NULL if not needed. + // + // The session storage namespace parameter allows multiple render views and + // tab contentses to share the same session storage (part of the WebStorage + // spec) space. This is useful when restoring tabs, but most callers should + // pass in NULL which will cause a new SessionStorageNamespace to be created. + TabContents(Profile* profile, + SiteInstance* site_instance, + int routing_id, + const TabContents* base_tab_contents, + SessionStorageNamespace* session_storage_namespace); + virtual ~TabContents(); + + // Intrinsic tab state ------------------------------------------------------- + + // Returns the property bag for this tab contents, where callers can add + // extra data they may wish to associate with the tab. Returns a pointer + // rather than a reference since the PropertyAccessors expect this. + const PropertyBag* property_bag() const { return &property_bag_; } + PropertyBag* property_bag() { return &property_bag_; } + + TabContentsDelegate* delegate() const { return delegate_; } + void set_delegate(TabContentsDelegate* d) { delegate_ = d; } + + // Gets the controller for this tab contents. + NavigationController& controller() { return controller_; } + const NavigationController& controller() const { return controller_; } + + // Returns the user profile associated with this TabContents (via the + // NavigationController). + Profile* profile() const { return controller_.profile(); } + + // Returns true if contains content rendered by an extension. + bool HostsExtension() const; + + // Returns the TabContentsSSLHelper, creating it if necessary. + TabContentsSSLHelper* GetSSLHelper(); + + // Returns the SavePackage which manages the page saving job. May be NULL. + SavePackage* save_package() const { return save_package_.get(); } + + // Return the currently active RenderProcessHost and RenderViewHost. Each of + // these may change over time. + RenderProcessHost* GetRenderProcessHost() const; + RenderViewHost* render_view_host() const { + return render_manager_.current_host(); + } + + WebUI* web_ui() const { + return render_manager_.web_ui() ? render_manager_.web_ui() + : render_manager_.pending_web_ui(); + } + + // Returns the currently active RenderWidgetHostView. This may change over + // time and can be NULL (during setup and teardown). + RenderWidgetHostView* GetRenderWidgetHostView() const { + return render_manager_.GetRenderWidgetHostView(); + } + + // The TabContentsView will never change and is guaranteed non-NULL. + TabContentsView* view() const { + return view_.get(); + } + + // Returns the FavIconHelper of this TabContents. + FavIconHelper& fav_icon_helper() { + return *fav_icon_helper_.get(); + } + + // App extensions ------------------------------------------------------------ + + // Sets the extension denoting this as an app. If |extension| is non-null this + // tab becomes an app-tab. TabContents does not listen for unload events for + // the extension. It's up to consumers of TabContents to do that. + // + // NOTE: this should only be manipulated before the tab is added to a browser. + // TODO(sky): resolve if this is the right way to identify an app tab. If it + // is, than this should be passed in the constructor. + void SetExtensionApp(const Extension* extension); + + // Convenience for setting the app extension by id. This does nothing if + // |extension_app_id| is empty, or an extension can't be found given the + // specified id. + void SetExtensionAppById(const std::string& extension_app_id); + + const Extension* extension_app() const { return extension_app_; } + bool is_app() const { return extension_app_ != NULL; } + + // If an app extension has been explicitly set for this TabContents its icon + // is returned. + // + // NOTE: the returned icon is larger than 16x16 (its size is + // Extension::EXTENSION_ICON_SMALLISH). + SkBitmap* GetExtensionAppIcon(); + + // Tab navigation state ------------------------------------------------------ + + // Returns the current navigation properties, which if a navigation is + // pending may be provisional (e.g., the navigation could result in a + // download, in which case the URL would revert to what it was previously). + virtual const GURL& GetURL() const; + virtual const string16& GetTitle() const; + + // The max PageID of any page that this TabContents has loaded. PageIDs + // increase with each new page that is loaded by a tab. If this is a + // TabContents, then the max PageID is kept separately on each SiteInstance. + // Returns -1 if no PageIDs have yet been seen. + int32 GetMaxPageID(); + + // Updates the max PageID to be at least the given PageID. + void UpdateMaxPageID(int32 page_id); + + // Returns the site instance associated with the current page. By default, + // there is no site instance. TabContents overrides this to provide proper + // access to its site instance. + virtual SiteInstance* GetSiteInstance() const; + + // Defines whether this tab's URL should be displayed in the browser's URL + // bar. Normally this is true so you can see the URL. This is set to false + // for the new tab page and related pages so that the URL bar is empty and + // the user is invited to type into it. + virtual bool ShouldDisplayURL(); + + // Returns the favicon for this tab, or an isNull() bitmap if the tab does not + // have a favicon. The default implementation uses the current navigation + // entry. + SkBitmap GetFavIcon() const; + + // Returns true if we are not using the default favicon. + bool FavIconIsValid() const; + + // Returns whether the favicon should be displayed. If this returns false, no + // space is provided for the favicon, and the favicon is never displayed. + virtual bool ShouldDisplayFavIcon(); + + // Add and remove observers for page navigation notifications. Adding or + // removing multiple times has no effect. The order in which notifications + // are sent to observers is undefined. Clients must be sure to remove the + // observer before they go away. + void AddObserver(TabContentsObserver* observer); + void RemoveObserver(TabContentsObserver* observer); + + // Return whether this tab contents is loading a resource. + bool is_loading() const { return is_loading_; } + + // Returns whether this tab contents is waiting for a first-response for the + // main resource of the page. This controls whether the throbber state is + // "waiting" or "loading." + bool waiting_for_response() const { return waiting_for_response_; } + + net::LoadState load_state() const { return load_state_; } + string16 load_state_host() const { return load_state_host_; } + uint64 upload_size() const { return upload_size_; } + uint64 upload_position() const { return upload_position_; } + + const std::string& encoding() const { return encoding_; } + void set_encoding(const std::string& encoding); + void reset_encoding() { + encoding_.clear(); + } + + const WebApplicationInfo& web_app_info() const { + return web_app_info_; + } + + const SkBitmap& app_icon() const { return app_icon_; } + + // Sets an app icon associated with TabContents and fires an INVALIDATE_TITLE + // navigation state change to trigger repaint of title. + void SetAppIcon(const SkBitmap& app_icon); + + bool displayed_insecure_content() const { + return displayed_insecure_content_; + } + + // Internal state ------------------------------------------------------------ + + // This flag indicates whether the tab contents is currently being + // screenshotted by the DraggedTabController. + bool capturing_contents() const { return capturing_contents_; } + void set_capturing_contents(bool cap) { capturing_contents_ = cap; } + + // Indicates whether this tab should be considered crashed. The setter will + // also notify the delegate when the flag is changed. + bool is_crashed() const { + return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED || + crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION || + crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED); + } + base::TerminationStatus crashed_status() const { return crashed_status_; } + int crashed_error_code() const { return crashed_error_code_; } + void SetIsCrashed(base::TerminationStatus status, int error_code); + + // Call this after updating a page action to notify clients about the changes. + void PageActionStateChanged(); + + // Whether the tab is in the process of being destroyed. + // Added as a tentative work-around for focus related bug #4633. This allows + // us not to store focus when a tab is being closed. + bool is_being_destroyed() const { return is_being_destroyed_; } + + // Convenience method for notifying the delegate of a navigation state + // change. See TabContentsDelegate. + void NotifyNavigationStateChanged(unsigned changed_flags); + + // Invoked when the tab contents becomes selected. If you override, be sure + // and invoke super's implementation. + virtual void DidBecomeSelected(); + base::TimeTicks last_selected_time() const { + return last_selected_time_; + } + + // Invoked when the tab contents becomes hidden. + // NOTE: If you override this, call the superclass version too! + virtual void WasHidden(); + + // Activates this contents within its containing window, bringing that window + // to the foreground if necessary. + void Activate(); + + // Deactivates this contents by deactivating its containing window. + void Deactivate(); + + // TODO(brettw) document these. + virtual void ShowContents(); + virtual void HideContents(); + + // Returns true if the before unload and unload listeners need to be + // fired. The value of this changes over time. For example, if true and the + // before unload listener is executed and allows the user to exit, then this + // returns false. + bool NeedToFireBeforeUnload(); + +#ifdef UNIT_TEST + // Expose the render manager for testing. + RenderViewHostManager* render_manager() { return &render_manager_; } +#endif + + // In the underlying RenderViewHostManager, swaps in the provided + // RenderViewHost to replace the current RenderViewHost. The current RVH + // will be shutdown and ultimately deleted. + void SwapInRenderViewHost(RenderViewHost* rvh); + + // Commands ------------------------------------------------------------------ + + // Implementation of PageNavigator. + virtual void OpenURL(const GURL& url, const GURL& referrer, + WindowOpenDisposition disposition, + PageTransition::Type transition); + + // Called by the NavigationController to cause the TabContents to navigate to + // the current pending entry. The NavigationController should be called back + // with CommitPendingEntry/RendererDidNavigate on success or + // DiscardPendingEntry. The callbacks can be inside of this function, or at + // some future time. + // + // The entry has a PageID of -1 if newly created (corresponding to navigation + // to a new URL). + // + // If this method returns false, then the navigation is discarded (equivalent + // to calling DiscardPendingEntry on the NavigationController). + virtual bool NavigateToPendingEntry( + NavigationController::ReloadType reload_type); + + // Stop any pending navigation. + virtual void Stop(); + + // Called on a TabContents when it isn't a popup, but a new window. + virtual void DisassociateFromPopupCount(); + + // Creates a new TabContents with the same state as this one. The returned + // heap-allocated pointer is owned by the caller. + virtual TabContents* Clone(); + + // Shows the page info. + void ShowPageInfo(const GURL& url, + const NavigationEntry::SSLStatus& ssl, + bool show_history); + + // Saves the favicon for the current page. + void SaveFavicon(); + + // Window management --------------------------------------------------------- + + // Create a new window constrained to this TabContents' clip and visibility. + // The window is initialized by using the supplied delegate to obtain basic + // window characteristics, and the supplied view for the content. Note that + // the returned ConstrainedWindow might not yet be visible. + ConstrainedWindow* CreateConstrainedDialog( + ConstrainedWindowDelegate* delegate); + + // Adds a new tab or window with the given already-created contents + void AddNewContents(TabContents* new_contents, + WindowOpenDisposition disposition, + const gfx::Rect& initial_pos, + bool user_gesture); + + // Execute code in this tab. Returns true if the message was successfully + // sent. + bool ExecuteCode(int request_id, const std::string& extension_id, + bool is_js_code, const std::string& code_string, + bool all_frames); + + // Called when the blocked popup notification is shown or hidden. + virtual void PopupNotificationVisibilityChanged(bool visible); + + // Returns the number of constrained windows in this tab. Used by tests. + size_t constrained_window_count() { return child_windows_.size(); } + + typedef std::deque<ConstrainedWindow*> ConstrainedWindowList; + + // Return an iterator for the first constrained window in this tab contents. + ConstrainedWindowList::iterator constrained_window_begin() + { return child_windows_.begin(); } + + // Return an iterator for the last constrained window in this tab contents. + ConstrainedWindowList::iterator constrained_window_end() + { return child_windows_.end(); } + + // Views and focus ----------------------------------------------------------- + // TODO(brettw): Most of these should be removed and the caller should call + // the view directly. + + // Returns the actual window that is focused when this TabContents is shown. + gfx::NativeView GetContentNativeView() const; + + // Returns the NativeView associated with this TabContents. Outside of + // automation in the context of the UI, this is required to be implemented. + gfx::NativeView GetNativeView() const; + + // Returns the bounds of this TabContents in the screen coordinate system. + void GetContainerBounds(gfx::Rect *out) const; + + // Makes the tab the focused window. + void Focus(); + + // Focuses the first (last if |reverse| is true) element in the page. + // Invoked when this tab is getting the focus through tab traversal (|reverse| + // is true when using Shift-Tab). + void FocusThroughTabTraversal(bool reverse); + + // These next two functions are declared on RenderViewHostManager::Delegate + // but also accessed directly by other callers. + + // Returns true if the location bar should be focused by default rather than + // the page contents. The view calls this function when the tab is focused + // to see what it should do. + virtual bool FocusLocationBarByDefault(); + + // Focuses the location bar. + virtual void SetFocusToLocationBar(bool select_all); + + // Creates a view and sets the size for the specified RVH. + virtual void CreateViewAndSetSizeForRVH(RenderViewHost* rvh); + + // Infobars ------------------------------------------------------------------ + + // Adds an InfoBar for the specified |delegate|. + virtual void AddInfoBar(InfoBarDelegate* delegate); + + // Removes the InfoBar for the specified |delegate|. + void RemoveInfoBar(InfoBarDelegate* delegate); + + // Replaces one infobar with another, without any animation in between. + void ReplaceInfoBar(InfoBarDelegate* old_delegate, + InfoBarDelegate* new_delegate); + + // Enumeration and access functions. + size_t infobar_count() const { return infobar_delegates_.size(); } + // WARNING: This does not sanity-check |index|! + InfoBarDelegate* GetInfoBarDelegateAt(size_t index) { + return infobar_delegates_[index]; + } + + // Toolbars and such --------------------------------------------------------- + + // Returns true if a Bookmark Bar should be shown for this tab. + virtual bool ShouldShowBookmarkBar(); + + // Notifies the delegate that a download is about to be started. + // This notification is fired before a local temporary file has been created. + bool CanDownload(int request_id); + + // Notifies the delegate that a download started. + void OnStartDownload(DownloadItem* download); + + // Notify our delegate that some of our content has animated. + void ToolbarSizeChanged(bool is_animating); + + // Called when a ConstrainedWindow we own is about to be closed. + void WillClose(ConstrainedWindow* window); + + // Called when a BlockedContentContainer we own is about to be closed. + void WillCloseBlockedContentContainer(BlockedContentContainer* container); + + // Called when a ConstrainedWindow we own is moved or resized. + void DidMoveOrResize(ConstrainedWindow* window); + + // Interstitials ------------------------------------------------------------- + + // Various other systems need to know about our interstitials. + bool showing_interstitial_page() const { + return render_manager_.interstitial_page() != NULL; + } + + // Sets the passed passed interstitial as the currently showing interstitial. + // |interstitial_page| should be non NULL (use the remove_interstitial_page + // method to unset the interstitial) and no interstitial page should be set + // when there is already a non NULL interstitial page set. + void set_interstitial_page(InterstitialPage* interstitial_page) { + render_manager_.set_interstitial_page(interstitial_page); + } + + // Unsets the currently showing interstitial. + void remove_interstitial_page() { + render_manager_.remove_interstitial_page(); + } + + // Returns the currently showing interstitial, NULL if no interstitial is + // showing. + InterstitialPage* interstitial_page() const { + return render_manager_.interstitial_page(); + } + + // Misc state & callbacks ---------------------------------------------------- + + // Set whether the contents should block javascript message boxes or not. + // Default is not to block any message boxes. + void set_suppress_javascript_messages(bool suppress_javascript_messages) { + suppress_javascript_messages_ = suppress_javascript_messages; + } + + // Prepare for saving the current web page to disk. + void OnSavePage(); + + // Save page with the main HTML file path, the directory for saving resources, + // and the save type: HTML only or complete web page. Returns true if the + // saving process has been initiated successfully. + bool SavePage(const FilePath& main_file, const FilePath& dir_path, + SavePackage::SavePackageType save_type); + + // Tells the user's email client to open a compose window containing the + // current page's URL. + void EmailPageLocation(); + + // Displays asynchronously a print preview (generated by the renderer) if not + // already displayed and ask the user for its preferred print settings with + // the "Print..." dialog box. (managed by the print worker thread). + // TODO(maruel): Creates a snapshot of the renderer to be used for the new + // tab for the printing facility. + void PrintPreview(); + + // Prints the current document immediately. Since the rendering is + // asynchronous, the actual printing will not be completed on the return of + // this function. Returns false if printing is impossible at the moment. + bool PrintNow(); + + // Notify the completion of a printing job. + void PrintingDone(int document_cookie, bool success); + + // Returns true if the active NavigationEntry's page_id equals page_id. + bool IsActiveEntry(int32 page_id); + + const std::string& contents_mime_type() const { + return contents_mime_type_; + } + + // Returns true if this TabContents will notify about disconnection. + bool notify_disconnection() const { return notify_disconnection_; } + + // Override the encoding and reload the page by sending down + // ViewMsg_SetPageEncoding to the renderer. |UpdateEncoding| is kinda + // the opposite of this, by which 'browser' is notified of + // the encoding of the current tab from 'renderer' (determined by + // auto-detect, http header, meta, bom detection, etc). + void SetOverrideEncoding(const std::string& encoding); + + // Remove any user-defined override encoding and reload by sending down + // ViewMsg_ResetPageEncodingToDefault to the renderer. + void ResetOverrideEncoding(); + + void WindowMoveOrResizeStarted(); + + // Sets whether all TabContents added by way of |AddNewContents| should be + // blocked. Transitioning from all blocked to not all blocked results in + // reevaluating any blocked TabContents, which may result in unblocking some + // of the blocked TabContents. + void SetAllContentsBlocked(bool value); + + BlockedContentContainer* blocked_content_container() const { + return blocked_contents_; + } + + RendererPreferences* GetMutableRendererPrefs() { + return &renderer_preferences_; + } + + void set_opener_web_ui_type(WebUITypeID opener_web_ui_type) { + opener_web_ui_type_ = opener_web_ui_type; + } + + // We want to time how long it takes to create a new tab page. This method + // gets called as parts of the new tab page have loaded. + void LogNewTabTime(const std::string& event_name); + + // Set the time when we started to create the new tab page. This time is + // from before we created this TabContents. + void set_new_tab_start_time(const base::TimeTicks& time) { + new_tab_start_time_ = time; + } + + // Notification that tab closing has started. This can be called multiple + // times, subsequent calls are ignored. + void OnCloseStarted(); + + LanguageState& language_state() { + return language_state_; + } + + // Returns true if underlying TabContentsView should accept drag-n-drop. + bool ShouldAcceptDragAndDrop() const; + + // A render view-originated drag has ended. Informs the render view host and + // tab contents delegate. + void SystemDragEnded(); + + // Indicates if this tab was explicitly closed by the user (control-w, close + // tab menu item...). This is false for actions that indirectly close the tab, + // such as closing the window. The setter is maintained by TabStripModel, and + // the getter only useful from within TAB_CLOSED notification + void set_closed_by_user_gesture(bool value) { + closed_by_user_gesture_ = value; + } + bool closed_by_user_gesture() const { return closed_by_user_gesture_; } + + // Overridden from JavaScriptAppModalDialogDelegate: + virtual void OnMessageBoxClosed(IPC::Message* reply_msg, + bool success, + const std::wstring& prompt); + virtual void SetSuppressMessageBoxes(bool suppress_message_boxes); + virtual gfx::NativeWindow GetMessageBoxRootWindow(); + virtual TabContents* AsTabContents(); + virtual ExtensionHost* AsExtensionHost(); + + // The BookmarkDragDelegate is used to forward bookmark drag and drop events + // to extensions. + virtual RenderViewHostDelegate::BookmarkDrag* GetBookmarkDragDelegate(); + + // It is up to callers to call SetBookmarkDragDelegate(NULL) when + // |bookmark_drag| is deleted since this class does not take ownership of + // |bookmark_drag|. + virtual void SetBookmarkDragDelegate( + RenderViewHostDelegate::BookmarkDrag* bookmark_drag); + + // The TabSpecificContentSettings object is used to query the blocked content + // state by various UI elements. + TabSpecificContentSettings* GetTabSpecificContentSettings() const; + + // Updates history with the specified navigation. This is called by + // OnMsgNavigate to update history state. + void UpdateHistoryForNavigation( + scoped_refptr<history::HistoryAddPageArgs> add_page_args); + + // Sends the page title to the history service. This is called when we receive + // the page title and we know we want to update history. + void UpdateHistoryPageTitle(const NavigationEntry& entry); + + // Gets the zoom level for this tab. + double GetZoomLevel() const; + + // Gets the zoom percent for this tab. + int GetZoomPercent(bool* enable_increment, bool* enable_decrement); + + // Shows a fade effect over this tab contents. Repeated calls will be ignored + // until the fade is canceled. If |animate| is true the fade should animate. + void FadeForInstant(bool animate); + + // Immediately removes the fade. + void CancelInstantFade(); + + // Opens view-source tab for this contents. + void ViewSource(); + + // Gets the minimum/maximum zoom percent. + int minimum_zoom_percent() const { return minimum_zoom_percent_; } + int maximum_zoom_percent() const { return maximum_zoom_percent_; } + + int content_restrictions() const { return content_restrictions_; } + + AutocompleteHistoryManager* autocomplete_history_manager() { + return autocomplete_history_manager_.get(); + } + AutoFillManager* autofill_manager() { return autofill_manager_.get(); } + + safe_browsing::ClientSideDetectionHost* safebrowsing_detection_host() { + return safebrowsing_detection_host_.get(); + } + + protected: + // from RenderViewHostDelegate. + virtual bool OnMessageReceived(const IPC::Message& message); + + private: + friend class NavigationController; + // Used to access the child_windows_ (ConstrainedWindowList) for testing + // automation purposes. + friend class TestingAutomationProvider; + + FRIEND_TEST_ALL_PREFIXES(TabContentsTest, NoJSMessageOnInterstitials); + FRIEND_TEST_ALL_PREFIXES(TabContentsTest, UpdateTitle); + FRIEND_TEST_ALL_PREFIXES(TabContentsTest, CrossSiteCantPreemptAfterUnload); + FRIEND_TEST_ALL_PREFIXES(FormStructureBrowserTest, HTMLFiles); + FRIEND_TEST_ALL_PREFIXES(NavigationControllerTest, HistoryNavigate); + FRIEND_TEST_ALL_PREFIXES(RenderViewHostManagerTest, PageDoesBackAndReload); + + // Temporary until the view/contents separation is complete. + friend class TabContentsView; +#if defined(OS_WIN) + friend class TabContentsViewWin; +#elif defined(OS_MACOSX) + friend class TabContentsViewMac; +#elif defined(TOOLKIT_USES_GTK) + friend class TabContentsViewGtk; +#endif + + // So InterstitialPage can access SetIsLoading. + friend class InterstitialPage; + + // TODO(brettw) TestTabContents shouldn't exist! + friend class TestTabContents; + + // Used to access the CreateHistoryAddPageArgs member function. + friend class ExternalTabContainer; + + // Used to access RVH Delegates. + friend class prerender::PrerenderManager; + + // Add all the TabContentObservers. + void AddObservers(); + + // Message handlers. + void OnDidStartProvisionalLoadForFrame(int64 frame_id, + bool main_frame, + const GURL& url); + void OnDidRedirectProvisionalLoad(int32 page_id, + const GURL& source_url, + const GURL& target_url); + void OnDidFailProvisionalLoadWithError(int64 frame_id, + bool main_frame, + int error_code, + const GURL& url, + bool showing_repost_interstitial); + void OnDidLoadResourceFromMemoryCache(const GURL& url, + const std::string& security_info); + void OnDidDisplayInsecureContent(); + void OnDidRunInsecureContent(const std::string& security_origin, + const GURL& target_url); + void OnDocumentLoadedInFrame(int64 frame_id); + void OnDidFinishLoad(int64 frame_id); + void OnUpdateContentRestrictions(int restrictions); + void OnPDFHasUnsupportedFeature(); + + void OnGoToEntryAtOffset(int offset); + void OnDidGetApplicationInfo(int32 page_id, const WebApplicationInfo& info); + void OnInstallApplication(const WebApplicationInfo& info); + void OnPageContents(const GURL& url, + int32 page_id, + const string16& contents, + const std::string& language, + bool page_translatable); + void OnPageTranslated(int32 page_id, + const std::string& original_lang, + const std::string& translated_lang, + TranslateErrors::Type error_type); + void OnSetSuggestions(int32 page_id, + const std::vector<std::string>& suggestions); + void OnInstantSupportDetermined(int32 page_id, bool result); + void OnRunFileChooser(const ViewHostMsg_RunFileChooser_Params& params); + + // Changes the IsLoading state and notifies delegate as needed + // |details| is used to provide details on the load that just finished + // (but can be null if not applicable). Can be overridden. + void SetIsLoading(bool is_loading, + LoadNotificationDetails* details); + + // Adds the incoming |new_contents| to the |blocked_contents_| container. + void AddPopup(TabContents* new_contents, + const gfx::Rect& initial_pos); + + // Called by derived classes to indicate that we're no longer waiting for a + // response. This won't actually update the throbber, but it will get picked + // up at the next animation step if the throbber is going. + void SetNotWaitingForResponse() { waiting_for_response_ = false; } + + ConstrainedWindowList child_windows_; + + // Expires InfoBars that need to be expired, according to the state carried + // in |details|, in response to a new NavigationEntry being committed (the + // user navigated to another page). + void ExpireInfoBars( + const NavigationController::LoadCommittedDetails& details); + + // Returns the WebUI for the current state of the tab. This will either be + // the pending WebUI, the committed WebUI, or NULL. + WebUI* GetWebUIForCurrentState(); + + // Navigation helpers -------------------------------------------------------- + // + // These functions are helpers for Navigate() and DidNavigate(). + + // Handles post-navigation tasks in DidNavigate AFTER the entry has been + // committed to the navigation controller. Note that the navigation entry is + // not provided since it may be invalid/changed after being committed. The + // current navigation entry is in the NavigationController at this point. + void DidNavigateMainFramePostCommit( + const NavigationController::LoadCommittedDetails& details, + const ViewHostMsg_FrameNavigate_Params& params); + void DidNavigateAnyFramePostCommit( + RenderViewHost* render_view_host, + const NavigationController::LoadCommittedDetails& details, + const ViewHostMsg_FrameNavigate_Params& params); + + // Closes all constrained windows. + void CloseConstrainedWindows(); + + // Send the alternate error page URL to the renderer. This method is virtual + // so special html pages can override this (e.g., the new tab page). + virtual void UpdateAlternateErrorPageURL(); + + // Send webkit specific settings to the renderer. + void UpdateWebPreferences(); + + // Instruct the renderer to update the zoom level. + void UpdateZoomLevel(); + + // If our controller was restored and the page id is > than the site + // instance's page id, the site instances page id is updated as well as the + // renderers max page id. + void UpdateMaxPageIDIfNecessary(SiteInstance* site_instance, + RenderViewHost* rvh); + + // Returns the history::HistoryAddPageArgs to use for adding a page to + // history. + scoped_refptr<history::HistoryAddPageArgs> CreateHistoryAddPageArgs( + const GURL& virtual_url, + const NavigationController::LoadCommittedDetails& details, + const ViewHostMsg_FrameNavigate_Params& params); + + // Saves the given title to the navigation entry and does associated work. It + // will update history and the view for the new title, and also synthesize + // titles for file URLs that have none (so we require that the URL of the + // entry already be set). + // + // This is used as the backend for state updates, which include a new title, + // or the dedicated set title message. It returns true if the new title is + // different and was therefore updated. + bool UpdateTitleForEntry(NavigationEntry* entry, const std::wstring& title); + + // Causes the TabContents to navigate in the right renderer to |entry|, which + // must be already part of the entries in the navigation controller. + // This does not change the NavigationController state. + bool NavigateToEntry(const NavigationEntry& entry, + NavigationController::ReloadType reload_type); + + // Misc non-view stuff ------------------------------------------------------- + + // Helper functions for sending notifications. + void NotifySwapped(); + void NotifyConnected(); + void NotifyDisconnected(); + + // TabSpecificContentSettings::Delegate implementation. + virtual void OnContentSettingsAccessed(bool content_was_blocked); + + // RenderViewHostDelegate ---------------------------------------------------- + + // RenderViewHostDelegate implementation. + virtual RenderViewHostDelegate::View* GetViewDelegate(); + virtual RenderViewHostDelegate::RendererManagement* + GetRendererManagementDelegate(); + virtual RenderViewHostDelegate::ContentSettings* GetContentSettingsDelegate(); + virtual RenderViewHostDelegate::SSL* GetSSLDelegate(); + virtual AutomationResourceRoutingDelegate* + GetAutomationResourceRoutingDelegate(); + virtual TabContents* GetAsTabContents(); + virtual ViewType::Type GetRenderViewType() const; + virtual int GetBrowserWindowID() const; + virtual void RenderViewCreated(RenderViewHost* render_view_host); + virtual void RenderViewReady(RenderViewHost* render_view_host); + virtual void RenderViewGone(RenderViewHost* render_view_host, + base::TerminationStatus status, + int error_code); + virtual void RenderViewDeleted(RenderViewHost* render_view_host); + virtual void DidNavigate(RenderViewHost* render_view_host, + const ViewHostMsg_FrameNavigate_Params& params); + virtual void UpdateState(RenderViewHost* render_view_host, + int32 page_id, + const std::string& state); + virtual void UpdateTitle(RenderViewHost* render_view_host, + int32 page_id, + const std::wstring& title); + virtual void UpdateEncoding(RenderViewHost* render_view_host, + const std::string& encoding); + virtual void UpdateTargetURL(int32 page_id, const GURL& url); + virtual void UpdateThumbnail(const GURL& url, + const SkBitmap& bitmap, + const ThumbnailScore& score); + virtual void UpdateInspectorSetting(const std::string& key, + const std::string& value); + virtual void ClearInspectorSettings(); + virtual void Close(RenderViewHost* render_view_host); + virtual void RequestMove(const gfx::Rect& new_bounds); + virtual void DidStartLoading(); + virtual void DidStopLoading(); + virtual void DidChangeLoadProgress(double progress); + virtual void DocumentOnLoadCompletedInMainFrame( + RenderViewHost* render_view_host, + int32 page_id); + virtual void RequestOpenURL(const GURL& url, const GURL& referrer, + WindowOpenDisposition disposition); + virtual void DomOperationResponse(const std::string& json_string, + int automation_id); + virtual void ProcessWebUIMessage(const ViewHostMsg_DomMessage_Params& params); + virtual void ProcessExternalHostMessage(const std::string& message, + const std::string& origin, + const std::string& target); + virtual void RunJavaScriptMessage(const std::wstring& message, + const std::wstring& default_prompt, + const GURL& frame_url, + const int flags, + IPC::Message* reply_msg, + bool* did_suppress_message); + virtual void RunBeforeUnloadConfirm(const std::wstring& message, + IPC::Message* reply_msg); + virtual void ShowModalHTMLDialog(const GURL& url, int width, int height, + const std::string& json_arguments, + IPC::Message* reply_msg); + virtual GURL GetAlternateErrorPageURL() const; + virtual RendererPreferences GetRendererPrefs(Profile* profile) const; + virtual WebPreferences GetWebkitPrefs(); + virtual void OnUserGesture(); + virtual void OnIgnoredUIEvent(); + virtual void OnCrossSiteResponse(int new_render_process_host_id, + int new_request_id); + virtual void RendererUnresponsive(RenderViewHost* render_view_host, + bool is_during_unload); + virtual void RendererResponsive(RenderViewHost* render_view_host); + virtual void LoadStateChanged(const GURL& url, net::LoadState load_state, + uint64 upload_position, uint64 upload_size); + virtual bool IsExternalTabContainer() const; + virtual void DidInsertCSS(); + virtual void FocusedNodeChanged(bool is_editable_node); + virtual void UpdateZoomLimits(int minimum_percent, + int maximum_percent, + bool remember); + virtual void WorkerCrashed(); + + // RenderViewHostManager::Delegate ------------------------------------------- + + // Blocks/unblocks interaction with renderer process. + void BlockTabContent(bool blocked); + + virtual void BeforeUnloadFiredFromRenderManager( + bool proceed, + bool* proceed_to_fire_unload); + virtual void DidStartLoadingFromRenderManager( + RenderViewHost* render_view_host); + virtual void RenderViewGoneFromRenderManager( + RenderViewHost* render_view_host); + virtual void UpdateRenderViewSizeForRenderManager(); + virtual void NotifySwappedFromRenderManager(); + virtual NavigationController& GetControllerForRenderManager(); + virtual WebUI* CreateWebUIForRenderManager(const GURL& url); + virtual NavigationEntry* GetLastCommittedNavigationEntryForRenderManager(); + + // Initializes the given renderer if necessary and creates the view ID + // corresponding to this view host. If this method is not called and the + // process is not shared, then the TabContents will act as though the renderer + // is not running (i.e., it will render "sad tab"). This method is + // automatically called from LoadURL. + // + // If you are attaching to an already-existing RenderView, you should call + // InitWithExistingID. + virtual bool CreateRenderViewForRenderManager( + RenderViewHost* render_view_host); + + // NotificationObserver ------------------------------------------------------ + + virtual void Observe(NotificationType type, + const NotificationSource& source, + const NotificationDetails& details); + + // App extensions related methods: + + // Returns the first extension whose extent contains |url|. + const Extension* GetExtensionContaining(const GURL& url); + + // Resets app_icon_ and if |extension| is non-null creates a new + // ImageLoadingTracker to load the extension's image. + void UpdateExtensionAppIcon(const Extension* extension); + + // ImageLoadingTracker::Observer. + virtual void OnImageLoaded(SkBitmap* image, ExtensionResource resource, + int index); + + // Checks with the PrerenderManager if the specified URL has been preloaded, + // and if so, swap the RenderViewHost with the preload into this TabContents + // object. + bool MaybeUsePreloadedPage(const GURL& url); + + // Data for core operation --------------------------------------------------- + + // Delegate for notifying our owner about stuff. Not owned by us. + TabContentsDelegate* delegate_; + + // Handles the back/forward list and loading. + NavigationController controller_; + + // The corresponding view. + scoped_ptr<TabContentsView> view_; + + // Helper classes ------------------------------------------------------------ + + // Manages creation and swapping of render views. + RenderViewHostManager render_manager_; + + // Stores random bits of data for others to associate with this object. + PropertyBag property_bag_; + + // Registers and unregisters us for notifications. + NotificationRegistrar registrar_; + + // Registers and unregisters for pref notifications. + PrefChangeRegistrar pref_change_registrar_; + + // Handles print job for this contents. + scoped_ptr<printing::PrintViewManager> printing_; + + // Handles print preview for this contents. + scoped_ptr<printing::PrintPreviewMessageHandler> print_preview_; + + // SavePackage, lazily created. + scoped_refptr<SavePackage> save_package_; + + // AutocompleteHistoryManager. + scoped_ptr<AutocompleteHistoryManager> autocomplete_history_manager_; + + // AutoFillManager. + scoped_ptr<AutoFillManager> autofill_manager_; + + // Handles plugin messages. + scoped_ptr<PluginObserver> plugin_observer_; + + // Prerender PageLoadTime Recorder. + scoped_ptr<prerender::PrerenderPLTRecorder> prerender_plt_recorder_; + + // TabContentsSSLHelper, lazily created. + scoped_ptr<TabContentsSSLHelper> ssl_helper_; + + // FileSelectHelper, lazily created. + scoped_ptr<FileSelectHelper> file_select_helper_; + + // Handles drag and drop event forwarding to extensions. + BookmarkDrag* bookmark_drag_; + + // Handles downloading favicons. + scoped_ptr<FavIconHelper> fav_icon_helper_; + + // Cached web app info data. + WebApplicationInfo web_app_info_; + + // Cached web app icon. + SkBitmap app_icon_; + + // RenderViewHost::ContentSettingsDelegate. + scoped_ptr<TabSpecificContentSettings> content_settings_delegate_; + + // Handles desktop notification IPCs. + scoped_ptr<DesktopNotificationHandlerForTC> desktop_notification_handler_; + + // Handles IPCs related to SafeBrowsing client-side phishing detection. + scoped_ptr<safe_browsing::ClientSideDetectionHost> + safebrowsing_detection_host_; + + // Data for loading state ---------------------------------------------------- + + // Indicates whether we're currently loading a resource. + bool is_loading_; + + // Indicates if the tab is considered crashed. + base::TerminationStatus crashed_status_; + int crashed_error_code_; + + // See waiting_for_response() above. + bool waiting_for_response_; + + // Indicates the largest PageID we've seen. This field is ignored if we are + // a TabContents, in which case the max page ID is stored separately with + // each SiteInstance. + // TODO(brettw) this seems like it can be removed according to the comment. + int32 max_page_id_; + + // System time at which the current load was started. + base::TimeTicks current_load_start_; + + // The current load state and the URL associated with it. + net::LoadState load_state_; + string16 load_state_host_; + // Upload progress, for displaying in the status bar. + // Set to zero when there is no significant upload happening. + uint64 upload_size_; + uint64 upload_position_; + + // Data for current page ----------------------------------------------------- + + // Whether we have a (non-empty) title for the current page. + // Used to prevent subsequent title updates from affecting history. This + // prevents some weirdness because some AJAXy apps use titles for status + // messages. + bool received_page_title_; + + // When a navigation occurs, we record its contents MIME type. It can be + // used to check whether we can do something for some special contents. + std::string contents_mime_type_; + + // Character encoding. + std::string encoding_; + + // Object that holds any blocked TabContents spawned from this TabContents. + BlockedContentContainer* blocked_contents_; + + // Should we block all child TabContents this attempts to spawn. + bool all_contents_blocked_; + + // TODO(pkasting): Hack to try and fix Linux browser tests. + bool dont_notify_render_view_; + + // True if this is a secure page which displayed insecure content. + bool displayed_insecure_content_; + + // Data for shelves and stuff ------------------------------------------------ + + // Delegates for InfoBars associated with this TabContents. + std::vector<InfoBarDelegate*> infobar_delegates_; + + // Data for app extensions --------------------------------------------------- + + // If non-null this tab is an app tab and this is the extension the tab was + // created for. + const Extension* extension_app_; + + // Icon for extension_app_ (if non-null) or extension_for_current_page_. + SkBitmap extension_app_icon_; + + // Used for loading extension_app_icon_. + scoped_ptr<ImageLoadingTracker> extension_app_image_loader_; + + // Data for misc internal state ---------------------------------------------- + + // See capturing_contents() above. + bool capturing_contents_; + + // See getter above. + bool is_being_destroyed_; + + // Indicates whether we should notify about disconnection of this + // TabContents. This is used to ensure disconnection notifications only + // happen if a connection notification has happened and that they happen only + // once. + bool notify_disconnection_; + + // Maps from handle to page_id. + typedef std::map<FaviconService::Handle, int32> HistoryRequestMap; + HistoryRequestMap history_requests_; + +#if defined(OS_WIN) + // Handle to an event that's set when the page is showing a message box (or + // equivalent constrained window). Plugin processes check this to know if + // they should pump messages then. + base::win::ScopedHandle message_box_active_; +#endif + + // The time that the last javascript message was dismissed. + base::TimeTicks last_javascript_message_dismissal_; + + // True if the user has decided to block future javascript messages. This is + // reset on navigations to false on navigations. + bool suppress_javascript_messages_; + + // Set to true when there is an active "before unload" dialog. When true, + // we've forced the throbber to start in Navigate, and we need to remember to + // turn it off in OnJavaScriptMessageBoxClosed if the navigation is canceled. + bool is_showing_before_unload_dialog_; + + // Shows an info-bar to users when they search from a known search engine and + // have never used the monibox for search before. + scoped_ptr<OmniboxSearchHint> omnibox_search_hint_; + + // Settings that get passed to the renderer process. + RendererPreferences renderer_preferences_; + + // If this tab was created from a renderer using window.open, this will be + // non-NULL and represent the WebUI of the opening renderer. + WebUITypeID opener_web_ui_type_; + + // The time that we started to create the new tab page. + base::TimeTicks new_tab_start_time_; + + // The time that we started to close the tab. + base::TimeTicks tab_close_start_time_; + + // The time that this tab was last selected. + base::TimeTicks last_selected_time_; + + // Information about the language the page is in and has been translated to. + LanguageState language_state_; + + // See description above setter. + bool closed_by_user_gesture_; + + // Minimum/maximum zoom percent. + int minimum_zoom_percent_; + int maximum_zoom_percent_; + // If true, the default zoom limits have been overriden for this tab, in which + // case we don't want saved settings to apply to it and we don't want to + // remember it. + bool temporary_zoom_settings_; + + // A list of observers notified when page state changes. Weak references. + ObserverList<TabContentsObserver> observers_; + + // Content restrictions, used to disable print/copy etc based on content's + // (full-page plugins for now only) permissions. + int content_restrictions_; + + DISALLOW_COPY_AND_ASSIGN(TabContents); +}; + +#endif // CONTENT_BROWSER_TAB_CONTENTS_TAB_CONTENTS_H_ diff --git a/chrome/browser/tab_contents/tab_contents_delegate.cc b/content/browser/tab_contents/tab_contents_delegate.cc index 7b0dc4b..0510adf 100644 --- a/chrome/browser/tab_contents/tab_contents_delegate.cc +++ b/content/browser/tab_contents/tab_contents_delegate.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/browser/tab_contents/tab_contents_delegate.h" +#include "content/browser/tab_contents/tab_contents_delegate.h" #include "chrome/common/url_constants.h" #include "ui/gfx/rect.h" @@ -220,5 +220,8 @@ bool TabContentsDelegate::ShouldShowHungRendererDialog() { return true; } +void TabContentsDelegate::WorkerCrashed() { +} + TabContentsDelegate::~TabContentsDelegate() { } diff --git a/content/browser/tab_contents/tab_contents_delegate.h b/content/browser/tab_contents/tab_contents_delegate.h new file mode 100644 index 0000000..8d2805b --- /dev/null +++ b/content/browser/tab_contents/tab_contents_delegate.h @@ -0,0 +1,331 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CONTENT_BROWSER_TAB_CONTENTS_TAB_CONTENTS_DELEGATE_H_ +#define CONTENT_BROWSER_TAB_CONTENTS_TAB_CONTENTS_DELEGATE_H_ +#pragma once + +#include <string> +#include <vector> + +#include "base/basictypes.h" +#include "chrome/browser/automation/automation_resource_routing_delegate.h" +#include "chrome/common/content_settings_types.h" +#include "chrome/common/navigation_types.h" +#include "chrome/common/page_transition_types.h" +#include "content/browser/tab_contents/navigation_entry.h" +#include "ui/gfx/native_widget_types.h" +#include "webkit/glue/window_open_disposition.h" + +namespace gfx { +class Point; +class Rect; +class Size; +} + +namespace history { +class HistoryAddPageArgs; +} + +struct ContextMenuParams; +class DownloadItem; +class GURL; +class HtmlDialogUIDelegate; +struct NativeWebKeyboardEvent; +class Profile; +class RenderViewHost; +class TabContents; +struct WebApplicationInfo; + +// Objects implement this interface to get notified about changes in the +// TabContents and to provide necessary functionality. +class TabContentsDelegate : public AutomationResourceRoutingDelegate { + public: + // Opens a new URL inside the passed in TabContents (if source is 0 open + // in the current front-most tab), unless |disposition| indicates the url + // should be opened in a new tab or window. + // + // A NULL source indicates the current tab (callers should probably use + // OpenURL() for these cases which does it for you). + virtual void OpenURLFromTab(TabContents* source, + const GURL& url, const GURL& referrer, + WindowOpenDisposition disposition, + PageTransition::Type transition) = 0; + + // Called to inform the delegate that the tab content's navigation state + // changed. The |changed_flags| indicates the parts of the navigation state + // that have been updated, and is any combination of the + // |TabContents::InvalidateTypes| bits. + virtual void NavigationStateChanged(const TabContents* source, + unsigned changed_flags) = 0; + + // Returns the set of headers to add to the navigation request. Use + // net::HttpUtil::AppendHeaderIfMissing to build the set of headers. + virtual std::string GetNavigationHeaders(const GURL& url); + + // Creates a new tab with the already-created TabContents 'new_contents'. + // The window for the added contents should be reparented correctly when this + // method returns. If |disposition| is NEW_POPUP, |pos| should hold the + // initial position. + virtual void AddNewContents(TabContents* source, + TabContents* new_contents, + WindowOpenDisposition disposition, + const gfx::Rect& initial_pos, + bool user_gesture) = 0; + + // Selects the specified contents, bringing its container to the front. + virtual void ActivateContents(TabContents* contents) = 0; + + // Deactivates the specified contents by deactivating its container and + // potentialy moving it to the back of the Z order. + virtual void DeactivateContents(TabContents* contents) = 0; + + // Notifies the delegate that this contents is starting or is done loading + // some resource. The delegate should use this notification to represent + // loading feedback. See TabContents::is_loading() + virtual void LoadingStateChanged(TabContents* source) = 0; + + // Notifies the delegate that the page has made some progress loading. + // |progress| is a value between 0.0 (nothing loaded) to 1.0 (page fully + // loaded). + // Note that to receive this notification, you must have called + // SetReportLoadProgressEnabled(true) in the render view. + virtual void LoadProgressChanged(double progress); + + // Request the delegate to close this tab contents, and do whatever cleanup + // it needs to do. + virtual void CloseContents(TabContents* source) = 0; + + // Request the delegate to move this tab contents to the specified position + // in screen coordinates. + virtual void MoveContents(TabContents* source, const gfx::Rect& pos) = 0; + + // Causes the delegate to detach |source| and clean up any internal data + // pointing to it. After this call ownership of |source| passes to the + // caller, and it is safe to call "source->set_delegate(someone_else);". + virtual void DetachContents(TabContents* source); + + // Called to determine if the TabContents is contained in a popup window. + virtual bool IsPopup(const TabContents* source) const; + + // If |source| is constrained, returns the tab containing it. Otherwise + // returns |source|. + virtual TabContents* GetConstrainingContents(TabContents* source); + + // Returns true if constrained windows should be focused. Default is true. + virtual bool ShouldFocusConstrainedWindow(); + + // Invoked prior to the TabContents showing a constrained window. + virtual void WillShowConstrainedWindow(TabContents* source); + + // Notification that some of our content has changed size as + // part of an animation. + virtual void ToolbarSizeChanged(TabContents* source, bool is_animating) = 0; + + // Notification that the target URL has changed. + virtual void UpdateTargetURL(TabContents* source, const GURL& url) = 0; + + // Notification that there was a mouse event, along with the absolute + // coordinates of the mouse pointer and whether it was a normal motion event + // (otherwise, the pointer left the contents area). + virtual void ContentsMouseEvent( + TabContents* source, const gfx::Point& location, bool motion); + + // Request the delegate to change the zoom level of the current tab. + virtual void ContentsZoomChange(bool zoom_in); + + // Notifies the delegate that something has changed about what content the + // TabContents is blocking. Interested parties should call + // TabContents::IsContentBlocked() to see if something they care about has + // changed. + virtual void OnContentSettingsChange(TabContents* source); + + // Check whether this contents is inside a window dedicated to running a web + // application. + virtual bool IsApplication() const; + + // Detach the given tab and convert it to a "webapp" view. The tab must be + // a TabContents with a valid WebApp set. + virtual void ConvertContentsToApplication(TabContents* source); + + // Whether the specified tab can be reloaded. + // Reloading can be disabled e. g. for the DevTools window. + virtual bool CanReloadContents(TabContents* source) const; + + // Show a dialog with HTML content. |delegate| contains a pointer to the + // delegate who knows how to display the dialog (which file URL and JSON + // string input to use during initialization). |parent_window| is the window + // that should be parent of the dialog, or NULL for the default. + virtual void ShowHtmlDialog(HtmlDialogUIDelegate* delegate, + gfx::NativeWindow parent_window); + + // Invoked prior to showing before unload handler confirmation dialog. + virtual void WillRunBeforeUnloadConfirm(); + + // Returns true if javascript dialogs and unload alerts are suppressed. + // Default is false. + virtual bool ShouldSuppressDialogs(); + + // Tells us that we've finished firing this tab's beforeunload event. + // The proceed bool tells us whether the user chose to proceed closing the + // tab. Returns true if the tab can continue on firing it's unload event. + // If we're closing the entire browser, then we'll want to delay firing + // unload events until all the beforeunload events have fired. + virtual void BeforeUnloadFired(TabContents* tab, + bool proceed, + bool* proceed_to_fire_unload); + + // Send IPC to external host. Default implementation is do nothing. + virtual void ForwardMessageToExternalHost(const std::string& message, + const std::string& origin, + const std::string& target); + + // If the delegate is hosting tabs externally. + virtual bool IsExternalTabContainer() const; + + // Sets focus to the location bar or some other place that is appropriate. + // This is called when the tab wants to encourage user input, like for the + // new tab page. + virtual void SetFocusToLocationBar(bool select_all); + + // Returns whether the page should be focused when transitioning from crashed + // to live. Default is true. + virtual bool ShouldFocusPageAfterCrash(); + + // Called when a popup select is about to be displayed. The delegate can use + // this to disable inactive rendering for the frame in the window the select + // is opened within if necessary. + virtual void RenderWidgetShowing(); + + // This is called when WebKit tells us that it is done tabbing through + // controls on the page. Provides a way for TabContentsDelegates to handle + // this. Returns true if the delegate successfully handled it. + virtual bool TakeFocus(bool reverse); + + // Invoked when the page loses mouse capture. + virtual void LostCapture(); + + // Changes the blocked state of the tab at |index|. TabContents are + // considered blocked while displaying a tab modal dialog. During that time + // renderer host will ignore any UI interaction within TabContent outside of + // the currently displaying dialog. + virtual void SetTabContentBlocked(TabContents* contents, bool blocked); + + // Notification that |tab_contents| has gained focus. + virtual void TabContentsFocused(TabContents* tab_content); + + // Return much extra vertical space should be allotted to the + // render view widget during various animations (e.g. infobar closing). + // This is used to make painting look smoother. + virtual int GetExtraRenderViewHeight() const; + + virtual bool CanDownload(int request_id); + + virtual void OnStartDownload(DownloadItem* download, TabContents* tab); + + // Returns true if the context menu operation was handled by the delegate. + virtual bool HandleContextMenu(const ContextMenuParams& params); + + // Returns true if the context menu command was handled + virtual bool ExecuteContextMenuCommand(int command); + + // Shows the page info using the specified information. + // |url| is the url of the page/frame the info applies to, |ssl| is the SSL + // information for that page/frame. If |show_history| is true, a section + // showing how many times that URL has been visited is added to the page info. + virtual void ShowPageInfo(Profile* profile, + const GURL& url, + const NavigationEntry::SSLStatus& ssl, + bool show_history); + + // Opens source view for given tab contents that is navigated to the given + // page url. + virtual void ViewSourceForTab(TabContents* source, const GURL& page_url); + + // Allows delegates to handle keyboard events before sending to the renderer. + // Returns true if the |event| was handled. Otherwise, if the |event| would be + // handled in HandleKeyboardEvent() method as a normal keyboard shortcut, + // |*is_keyboard_shortcut| should be set to true. + virtual bool PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event, + bool* is_keyboard_shortcut); + + // Allows delegates to handle unhandled keyboard messages coming back from + // the renderer. + virtual void HandleKeyboardEvent(const NativeWebKeyboardEvent& event); + + virtual void HandleMouseUp(); + virtual void HandleMouseActivate(); + + // Render view drag n drop ended. + virtual void DragEnded(); + + // Shows the repost form confirmation dialog box. + virtual void ShowRepostFormWarningDialog(TabContents* tab_contents); + + // Shows the Content Settings dialog for a given content type. + virtual void ShowContentSettingsWindow(ContentSettingsType content_type); + + // Shows the cookies collected in the tab contents. + virtual void ShowCollectedCookiesDialog(TabContents* tab_contents); + + // Allows delegate to override navigation to the history entries. + // Returns true to allow TabContents to continue with the default processing. + virtual bool OnGoToEntryOffset(int offset); + + // Returns whether this tab contents should add the specified navigation to + // history. + virtual bool ShouldAddNavigationToHistory( + const history::HistoryAddPageArgs& add_page_args, + NavigationType::Type navigation_type); + + // Notification that a user's request to install an application has completed. + virtual void OnDidGetApplicationInfo(TabContents* tab_contents, + int32 page_id); + + // Notification when an application programmatically requests installation. + virtual void OnInstallApplication(TabContents* tab_contents, + const WebApplicationInfo& app_info); + + // Returns the native window framing the view containing the tab contents. + virtual gfx::NativeWindow GetFrameNativeWindow(); + + // Notifies the delegate about the creation of a new TabContents. This + // typically happens when popups are created. + virtual void TabContentsCreated(TabContents* new_contents); + + // Returns whether infobars are enabled. Overrideable by child classes. + virtual bool infobars_enabled(); + + // Whether the renderer should report its preferred size when it changes by + // calling UpdatePreferredSize(). + // Note that this is set when the RenderViewHost is created and cannot be + // changed after that. + virtual bool ShouldEnablePreferredSizeNotifications(); + + // Notification that the preferred size of the contents has changed. + // Only called if ShouldEnablePreferredSizeNotifications() returns true. + virtual void UpdatePreferredSize(const gfx::Size& pref_size); + + // Notifies the delegate that the page has a suggest result. + virtual void OnSetSuggestions(int32 page_id, + const std::vector<std::string>& result); + + // Notifies the delegate whether the page supports instant-style interaction. + virtual void OnInstantSupportDetermined(int32 page_id, bool result); + + // Notifies the delegate that the content restrictions for this tab has + // changed. + virtual void ContentRestrictionsChanged(TabContents* source); + + // Returns true if the hung renderer dialog should be shown. Default is true. + virtual bool ShouldShowHungRendererDialog(); + + // Notification that a worker associated with this tab has crashed. + virtual void WorkerCrashed(); + + protected: + virtual ~TabContentsDelegate(); +}; + +#endif // CONTENT_BROWSER_TAB_CONTENTS_TAB_CONTENTS_DELEGATE_H_ diff --git a/chrome/browser/tab_contents/tab_contents_observer.cc b/content/browser/tab_contents/tab_contents_observer.cc index 738539a..00c8210 100644 --- a/chrome/browser/tab_contents/tab_contents_observer.cc +++ b/content/browser/tab_contents/tab_contents_observer.cc @@ -2,10 +2,10 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/browser/tab_contents/tab_contents_observer.h" +#include "content/browser/tab_contents/tab_contents_observer.h" #include "chrome/browser/renderer_host/render_view_host.h" -#include "chrome/browser/tab_contents/tab_contents.h" +#include "content/browser/tab_contents/tab_contents.h" TabContentsObserver::TabContentsObserver(TabContents* tab_contents) : tab_contents_(tab_contents), diff --git a/content/browser/tab_contents/tab_contents_observer.h b/content/browser/tab_contents/tab_contents_observer.h new file mode 100644 index 0000000..b8bb343 --- /dev/null +++ b/content/browser/tab_contents/tab_contents_observer.h @@ -0,0 +1,69 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CONTENT_BROWSER_TAB_CONTENTS_TAB_CONTENTS_OBSERVER_H_ +#define CONTENT_BROWSER_TAB_CONTENTS_TAB_CONTENTS_OBSERVER_H_ + +#include "content/browser/tab_contents/navigation_controller.h" +#include "ipc/ipc_channel.h" + +struct ViewHostMsg_FrameNavigate_Params; + +// An observer API implemented by classes which are interested in various page +// load events from TabContents. They also get a chance to filter IPC messages. +class TabContentsObserver : public IPC::Channel::Listener { + public: + virtual void NavigateToPendingEntry() { } + + virtual void DidNavigateMainFramePostCommit( + const NavigationController::LoadCommittedDetails& details, + const ViewHostMsg_FrameNavigate_Params& params) { } + virtual void DidNavigateAnyFramePostCommit( + const NavigationController::LoadCommittedDetails& details, + const ViewHostMsg_FrameNavigate_Params& params) { } + + virtual void DidStartLoading() { } + virtual void DidStopLoading() { } + +#if 0 + // For unifying with delegate... + + // Notifies the delegate that this contents is starting or is done loading + // some resource. The delegate should use this notification to represent + // loading feedback. See TabContents::is_loading() + virtual void LoadingStateChanged(TabContents* contents) { } + // Called to inform the delegate that the tab content's navigation state + // changed. The |changed_flags| indicates the parts of the navigation state + // that have been updated, and is any combination of the + // |TabContents::InvalidateTypes| bits. + virtual void NavigationStateChanged(const TabContents* source, + unsigned changed_flags) { } +#endif + + protected: + TabContentsObserver(TabContents* tab_contents); + virtual ~TabContentsObserver(); + + // IPC::Channel::Listener implementation. + virtual bool OnMessageReceived(const IPC::Message& message); + + // IPC::Message::Sender implementation. + virtual bool Send(IPC::Message* message); + + TabContents* tab_contents() { return tab_contents_; } + int routing_id() { return routing_id_; } + + private: + friend class TabContents; + + void set_tab_contents(TabContents* tc) { tab_contents_ = tc; } + + TabContents* tab_contents_; + // The routing ID of the associated TabContents. + int routing_id_; + + DISALLOW_COPY_AND_ASSIGN(TabContentsObserver); +}; + +#endif // CONTENT_BROWSER_TAB_CONTENTS_TAB_CONTENTS_OBSERVER_H_ diff --git a/chrome/browser/tab_contents/tab_contents_view.cc b/content/browser/tab_contents/tab_contents_view.cc index 9574a56..8c395af 100644 --- a/chrome/browser/tab_contents/tab_contents_view.cc +++ b/content/browser/tab_contents/tab_contents_view.cc @@ -2,17 +2,17 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/browser/tab_contents/tab_contents_view.h" +#include "content/browser/tab_contents/tab_contents_view.h" #include "chrome/browser/renderer_host/render_process_host.h" #include "chrome/browser/renderer_host/render_view_host.h" #include "chrome/browser/renderer_host/render_widget_host.h" #include "chrome/browser/renderer_host/render_view_host_delegate.h" #include "chrome/browser/renderer_host/render_widget_host_view.h" -#include "chrome/browser/tab_contents/tab_contents.h" -#include "chrome/browser/tab_contents/tab_contents_delegate.h" #include "chrome/common/notification_service.h" #include "chrome/common/render_messages_params.h" +#include "content/browser/tab_contents/tab_contents.h" +#include "content/browser/tab_contents/tab_contents_delegate.h" TabContentsView::TabContentsView(TabContents* tab_contents) : tab_contents_(tab_contents) { diff --git a/content/browser/tab_contents/tab_contents_view.h b/content/browser/tab_contents/tab_contents_view.h new file mode 100644 index 0000000..9d5a04f --- /dev/null +++ b/content/browser/tab_contents/tab_contents_view.h @@ -0,0 +1,218 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CONTENT_BROWSER_TAB_CONTENTS_TAB_CONTENTS_VIEW_H_ +#define CONTENT_BROWSER_TAB_CONTENTS_TAB_CONTENTS_VIEW_H_ +#pragma once + +#include <map> +#include <string> + +#include "base/basictypes.h" +#include "chrome/browser/renderer_host/render_view_host_delegate.h" +#include "chrome/browser/tab_contents/render_view_host_delegate_helper.h" +#include "ui/gfx/native_widget_types.h" +#include "ui/gfx/rect.h" +#include "ui/gfx/size.h" + +class RenderViewHost; +class RenderWidgetHost; +class RenderWidgetHostView; +class TabContents; + +// The TabContentsView is an interface that is implemented by the platform- +// dependent web contents views. The TabContents uses this interface to talk to +// them. View-related messages will also get forwarded directly to this class +// from RenderViewHost via RenderViewHostDelegate::View. +// +// It contains a small amount of logic with respect to creating new sub-view +// that should be the same for all platforms. +class TabContentsView : public RenderViewHostDelegate::View { + public: + explicit TabContentsView(TabContents* tab_contents); + virtual ~TabContentsView(); + + // Creates the appropriate type of TabContentsView for the current system. + // The return value is a new heap allocated view with ownership passing to + // the caller. + static TabContentsView* Create(TabContents* tab_contents); + + TabContents* tab_contents() const { return tab_contents_; } + + virtual void CreateView(const gfx::Size& initial_size) = 0; + + // Sets up the View that holds the rendered web page, receives messages for + // it and contains page plugins. The host view should be sized to the current + // size of the TabContents. + virtual RenderWidgetHostView* CreateViewForWidget( + RenderWidgetHost* render_widget_host) = 0; + + // Returns the native widget that contains the contents of the tab. + virtual gfx::NativeView GetNativeView() const = 0; + + // Returns the native widget with the main content of the tab (i.e. the main + // render view host, though there may be many popups in the tab as children of + // the container). + virtual gfx::NativeView GetContentNativeView() const = 0; + + // Returns the outermost native view. This will be used as the parent for + // dialog boxes. + virtual gfx::NativeWindow GetTopLevelNativeWindow() const = 0; + + // Computes the rectangle for the native widget that contains the contents of + // the tab relative to its parent. + virtual void GetContainerBounds(gfx::Rect *out) const = 0; + + // Helper function for GetContainerBounds. Most callers just want to know the + // size, and this makes it more clear. + gfx::Size GetContainerSize() const { + gfx::Rect rc; + GetContainerBounds(&rc); + return gfx::Size(rc.width(), rc.height()); + } + + // Sets the page title for the native widgets corresponding to the view. This + // is not strictly necessary and isn't expected to be displayed anywhere, but + // can aid certain debugging tools such as Spy++ on Windows where you are + // trying to find a specific window. + virtual void SetPageTitle(const std::wstring& title) = 0; + + // Used to notify the view that a tab has crashed so each platform can + // prepare the sad tab. + virtual void OnTabCrashed(base::TerminationStatus status, + int error_code) = 0; + + // TODO(brettw) this is a hack. It's used in two places at the time of this + // writing: (1) when render view hosts switch, we need to size the replaced + // one to be correct, since it wouldn't have known about sizes that happened + // while it was hidden; (2) in constrained windows. + // + // (1) will be fixed once interstitials are cleaned up. (2) seems like it + // should be cleaned up or done some other way, since this works for normal + // TabContents without the special code. + virtual void SizeContents(const gfx::Size& size) = 0; + + // Invoked from the platform dependent web contents view when a + // RenderWidgetHost is deleted. Removes |host| from internal maps. + void RenderWidgetHostDestroyed(RenderWidgetHost* host); + + // Invoked when the TabContents is notified that the RenderView has been + // fully created. The default implementation does nothing; override + // for platform-specific behavior is needed. + virtual void RenderViewCreated(RenderViewHost* host); + + // Sets focus to the native widget for this tab. + virtual void Focus() = 0; + + // Sets focus to the appropriate element when the tab contents is shown the + // first time. + virtual void SetInitialFocus() = 0; + + // Stores the currently focused view. + virtual void StoreFocus() = 0; + + // Restores focus to the last focus view. If StoreFocus has not yet been + // invoked, SetInitialFocus is invoked. + virtual void RestoreFocus() = 0; + + // RenderViewHostDelegate::View method. Forwards to the TabContentsDelegate. + virtual void LostCapture(); + + // Keyboard events forwarding from the RenderViewHost. + // The default implementation just forward the events to the + // TabContentsDelegate object. + virtual bool PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event, + bool* is_keyboard_shortcut); + + // Keyboard events forwarding from the RenderViewHost. + // The default implementation just forward the events to the + // TabContentsDelegate object. + virtual void HandleKeyboardEvent(const NativeWebKeyboardEvent& event); + + // Simple mouse event forwarding from the RenderViewHost. + virtual void HandleMouseMove() {} + virtual void HandleMouseDown() {} + virtual void HandleMouseLeave() {} + virtual void HandleMouseUp(); + virtual void HandleMouseActivate(); + + // Notification that the preferred size of the contents has changed. + virtual void UpdatePreferredSize(const gfx::Size& pref_size); + + // If we try to close the tab while a drag is in progress, we crash. These + // methods allow the tab contents to determine if a drag is in progress and + // postpone the tab closing. + virtual bool IsDoingDrag() const; + virtual void CancelDragAndCloseTab() {} + + // If we close the tab while a UI control is in an event-tracking + // loop, the control may message freed objects and crash. + // TabContents::Close() calls IsEventTracking(), and if it returns + // true CloseTabAfterEventTracking() is called and the close is not + // completed. + virtual bool IsEventTracking() const; + virtual void CloseTabAfterEventTracking() {} + + // Get the bounds of the View, relative to the parent. + virtual void GetViewBounds(gfx::Rect* out) const = 0; + + protected: + TabContentsView(); // Abstract interface. + + // Internal functions used to support the CreateNewWidget() method. If a + // platform requires plugging into widget creation at a lower level then a + // subclass might want to override these functions, but otherwise they should + // be fine just implementing RenderWidgetHostView::InitAsPopup(). + // + // The Create function returns the newly created widget so it can be + // associated with the given route. When the widget needs to be shown later, + // we'll look it up again and pass the object to the Show functions rather + // than the route ID. + virtual RenderWidgetHostView* CreateNewWidgetInternal( + int route_id, + WebKit::WebPopupType popup_type); + virtual void ShowCreatedWidgetInternal(RenderWidgetHostView* widget_host_view, + const gfx::Rect& initial_pos); + virtual void ShowCreatedFullscreenWidgetInternal( + RenderWidgetHostView* widget_host_view); + virtual RenderWidgetHostView* CreateNewFullscreenWidgetInternal(int route_id); + + // Common implementations of some RenderViewHostDelegate::View methods. + RenderViewHostDelegateViewHelper delegate_view_helper_; + + private: + // We implement these functions on RenderViewHostDelegate::View directly and + // do some book-keeping associated with the request. The request is then + // forwarded to *Internal which does platform-specific work. + virtual void CreateNewWindow( + int route_id, + const ViewHostMsg_CreateWindow_Params& params); + virtual void CreateNewWidget(int route_id, WebKit::WebPopupType popup_type); + virtual void CreateNewFullscreenWidget(int route_id); + virtual void ShowCreatedWindow(int route_id, + WindowOpenDisposition disposition, + const gfx::Rect& initial_pos, + bool user_gesture); + virtual void ShowCreatedWidget(int route_id, const gfx::Rect& initial_pos); + virtual void Activate(); + virtual void Deactivate(); + virtual void ShowCreatedFullscreenWidget(int route_id); + + // The TabContents whose contents we display. + TabContents* tab_contents_; + + // Tracks created TabContents objects that have not been shown yet. They are + // identified by the route ID passed to CreateNewWindow. + typedef std::map<int, TabContents*> PendingContents; + PendingContents pending_contents_; + + // These maps hold on to the widgets that we created on behalf of the + // renderer that haven't shown yet. + typedef std::map<int, RenderWidgetHostView*> PendingWidgetViews; + PendingWidgetViews pending_widget_views_; + + DISALLOW_COPY_AND_ASSIGN(TabContentsView); +}; + +#endif // CONTENT_BROWSER_TAB_CONTENTS_TAB_CONTENTS_VIEW_H_ diff --git a/chrome/browser/tab_contents/test_tab_contents.cc b/content/browser/tab_contents/test_tab_contents.cc index 69fc0cf..69fc0cf 100644 --- a/chrome/browser/tab_contents/test_tab_contents.cc +++ b/content/browser/tab_contents/test_tab_contents.cc diff --git a/content/browser/tab_contents/test_tab_contents.h b/content/browser/tab_contents/test_tab_contents.h new file mode 100644 index 0000000..83c251a --- /dev/null +++ b/content/browser/tab_contents/test_tab_contents.h @@ -0,0 +1,81 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CONTENT_BROWSER_TAB_CONTENTS_TEST_TAB_CONTENTS_H_ +#define CONTENT_BROWSER_TAB_CONTENTS_TEST_TAB_CONTENTS_H_ +#pragma once + +#include "chrome/browser/tab_contents/tab_contents.h" +#include "chrome/common/notification_registrar.h" +#include "webkit/glue/webpreferences.h" + +class Profile; +class TestRenderViewHost; + +// Subclass TabContents to ensure it creates TestRenderViewHosts and does +// not do anything involving views. +class TestTabContents : public TabContents { + public: + // The render view host factory will be passed on to the + TestTabContents(Profile* profile, SiteInstance* instance); + + TestRenderViewHost* pending_rvh() const; + + // State accessor. + bool cross_navigation_pending() { + return render_manager_.cross_navigation_pending_; + } + + // Overrides TabContents::ShouldTransitionCrossSite so that we can test both + // alternatives without using command-line switches. + bool ShouldTransitionCrossSite() { return transition_cross_site; } + + // Overrides TabContents::Observe. We are listening to infobar related + // notifications so we can call InfoBarClosed() on the infobar delegates to + // prevent them from leaking. + virtual void Observe(NotificationType type, + const NotificationSource& source, + const NotificationDetails& details); + + // Promote DidNavigate to public. + void TestDidNavigate(RenderViewHost* render_view_host, + const ViewHostMsg_FrameNavigate_Params& params) { + DidNavigate(render_view_host, params); + } + + // Promote GetWebkitPrefs to public. + WebPreferences TestGetWebkitPrefs() { + return GetWebkitPrefs(); + } + + // Prevent interaction with views. + virtual bool CreateRenderViewForRenderManager( + RenderViewHost* render_view_host); + virtual void UpdateRenderViewSizeForRenderManager() {} + + // Returns a clone of this TestTabContents. The returned object is also a + // TestTabContents. The caller owns the returned object. + virtual TabContents* Clone(); + + // Creates a pending navigation to the given URL with the default parameters + // and then commits the load with a page ID one larger than any seen. This + // emulates what happens on a new navigation. + void NavigateAndCommit(const GURL& url); + + // Simulates the appropriate RenderView (pending if any, current otherwise) + // sending a navigate notification for the NavigationController pending entry. + void CommitPendingNavigation(); + + // Simulates the current RVH notifying that it has unloaded so that the + // pending RVH navigation can proceed. + // Does nothing if no cross-navigation is pending. + void ProceedWithCrossSiteNavigation(); + + // Set by individual tests. + bool transition_cross_site; + + NotificationRegistrar registrar_; +}; + +#endif // CONTENT_BROWSER_TAB_CONTENTS_TEST_TAB_CONTENTS_H_ diff --git a/content/content.gyp b/content/content.gyp new file mode 100644 index 0000000..db71289 --- /dev/null +++ b/content/content.gyp @@ -0,0 +1,13 @@ +# Copyright (c) 2011 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +{ + 'variables': { + 'chromium_code': 1, # Use higher warning level. + }, + 'includes': [ + 'content_browser.gypi', + 'content_common.gypi', + ], +} diff --git a/content/content_browser.gypi b/content/content_browser.gypi new file mode 100644 index 0000000..51bf09c --- /dev/null +++ b/content/content_browser.gypi @@ -0,0 +1,60 @@ +# Copyright (c) 2011 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +{ + 'targets': [ + { + 'target_name': 'content_browser', + 'type': '<(library)', + 'dependencies': [ + # Don't include now since it's empty and so will cause a linker error. + #'content_common', + '../app/app.gyp:app_resources', + '../skia/skia.gyp:skia', + '../ui/ui.gyp:ui_base', + ], + 'include_dirs': [ + '..', + ], + 'sources': [ + 'browser/tab_contents/background_contents.cc', + 'browser/tab_contents/background_contents.h', + 'browser/tab_contents/constrained_window.h', + 'browser/tab_contents/infobar_delegate.cc', + 'browser/tab_contents/infobar_delegate.h', + 'browser/tab_contents/interstitial_page.cc', + 'browser/tab_contents/interstitial_page.h', + 'browser/tab_contents/language_state.cc', + 'browser/tab_contents/language_state.h', + 'browser/tab_contents/navigation_controller.cc', + 'browser/tab_contents/navigation_controller.h', + 'browser/tab_contents/navigation_entry.cc', + 'browser/tab_contents/navigation_entry.h', + 'browser/tab_contents/page_navigator.h', + 'browser/tab_contents/provisional_load_details.cc', + 'browser/tab_contents/provisional_load_details.h', + 'browser/tab_contents/render_view_host_manager.cc', + 'browser/tab_contents/render_view_host_manager.h', + 'browser/tab_contents/tab_contents.cc', + 'browser/tab_contents/tab_contents.h', + 'browser/tab_contents/tab_contents_delegate.cc', + 'browser/tab_contents/tab_contents_delegate.h', + 'browser/tab_contents/tab_contents_observer.cc', + 'browser/tab_contents/tab_contents_observer.h', + 'browser/tab_contents/tab_contents_view.cc', + 'browser/tab_contents/tab_contents_view.h', + ], + 'conditions': [ + ['OS=="win"', { + 'msvs_guid': '639DB58D-32C2-435A-A711-65A12F62E442', + }], + ['OS=="linux" or OS=="freebsd" or OS=="openbsd" or OS=="solaris"', { + 'dependencies': [ + '../build/linux/system.gyp:gtk', + ], + }], + ], + }, + ], +} diff --git a/content/content_common.gypi b/content/content_common.gypi new file mode 100644 index 0000000..0ef8194 --- /dev/null +++ b/content/content_common.gypi @@ -0,0 +1,25 @@ +# Copyright (c) 2011 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +{ + 'targets': [ + { + 'target_name': 'content_common', + 'type': '<(library)', + 'dependencies': [ + '../ipc/ipc.gyp:ipc', + ], + 'include_dirs': [ + '..', + ], + 'sources': [ + ], + 'conditions': [ + ['OS=="win"', { + 'msvs_guid': '062E9260-304A-4657-A74C-0D3AA1A0A0A4', + }], + ], + }, + ], +} diff --git a/ui/base/ui_base.gypi b/ui/base/ui_base.gypi index 71443f6..72bf8c1 100644 --- a/ui/base/ui_base.gypi +++ b/ui/base/ui_base.gypi @@ -51,6 +51,11 @@ '../third_party/icu/icu.gyp:icui18n', '../third_party/icu/icu.gyp:icuuc', ], + # Export these dependencies since text_elider.h includes ICU headers. + 'export_dependent_settings': [ + '../third_party/icu/icu.gyp:icui18n', + '../third_party/icu/icu.gyp:icuuc', + ], 'sources': [ 'animation/animation.cc', 'animation/animation.h', |