[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef CONTENT_BROWSER_TAB_CONTENTS_TAB_CONTENTS_H_ |
| 6 | #define CONTENT_BROWSER_TAB_CONTENTS_TAB_CONTENTS_H_ |
| 7 | #pragma once |
| 8 | |
| 9 | #include <deque> |
| 10 | #include <map> |
| 11 | #include <string> |
| 12 | #include <vector> |
| 13 | |
| 14 | #include "base/basictypes.h" |
| 15 | #include "base/gtest_prod_util.h" |
[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame^] | 16 | #include "base/memory/scoped_ptr.h" |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 17 | #include "base/string16.h" |
| 18 | #include "chrome/browser/download/save_package.h" |
| 19 | #include "chrome/browser/extensions/image_loading_tracker.h" |
[email protected] | 34952d1 | 2011-03-14 19:45:13 | [diff] [blame] | 20 | #include "chrome/browser/favicon_helper.h" |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 21 | #include "chrome/browser/prefs/pref_change_registrar.h" |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 22 | #include "chrome/browser/tab_contents/tab_specific_content_settings.h" |
| 23 | #include "chrome/browser/ui/app_modal_dialogs/js_modal_dialog.h" |
[email protected] | 1c9c7fb | 2011-03-11 16:38:38 | [diff] [blame] | 24 | #include "chrome/common/instant_types.h" |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 25 | #include "chrome/common/translate_errors.h" |
| 26 | #include "chrome/common/web_apps.h" |
[email protected] | 5de63471 | 2011-03-02 00:20:19 | [diff] [blame] | 27 | #include "content/browser/renderer_host/render_view_host_delegate.h" |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 28 | #include "content/browser/tab_contents/constrained_window.h" |
| 29 | #include "content/browser/tab_contents/language_state.h" |
| 30 | #include "content/browser/tab_contents/navigation_controller.h" |
| 31 | #include "content/browser/tab_contents/navigation_entry.h" |
| 32 | #include "content/browser/tab_contents/page_navigator.h" |
| 33 | #include "content/browser/tab_contents/render_view_host_manager.h" |
[email protected] | 67fc039 | 2011-02-25 02:56:57 | [diff] [blame] | 34 | #include "content/browser/webui/web_ui_factory.h" |
[email protected] | 7f070d4 | 2011-03-09 20:25:32 | [diff] [blame] | 35 | #include "content/common/notification_registrar.h" |
[email protected] | 15a5fa5 | 2011-03-10 20:16:04 | [diff] [blame] | 36 | #include "content/common/property_bag.h" |
[email protected] | 6091604 | 2011-03-19 00:43:36 | [diff] [blame] | 37 | #include "content/common/renderer_preferences.h" |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 38 | #include "net/base/load_states.h" |
[email protected] | 232a581 | 2011-03-04 22:42:08 | [diff] [blame] | 39 | #include "net/base/network_change_notifier.h" |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 40 | #include "ui/gfx/native_widget_types.h" |
| 41 | |
| 42 | #if defined(OS_WIN) |
| 43 | #include "base/win/scoped_handle.h" |
| 44 | #endif |
| 45 | |
| 46 | namespace gfx { |
| 47 | class Rect; |
| 48 | } |
| 49 | |
| 50 | namespace history { |
| 51 | class HistoryAddPageArgs; |
| 52 | } |
| 53 | |
| 54 | namespace prerender { |
| 55 | class PrerenderManager; |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 56 | } |
| 57 | |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 58 | namespace safe_browsing { |
| 59 | class ClientSideDetectionHost; |
| 60 | } |
| 61 | |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 62 | class BlockedContentContainer; |
| 63 | class WebUI; |
| 64 | class DesktopNotificationHandlerForTC; |
| 65 | class DownloadItem; |
| 66 | class Extension; |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 67 | class InfoBarDelegate; |
| 68 | class LoadNotificationDetails; |
| 69 | class OmniboxSearchHint; |
| 70 | class PluginObserver; |
| 71 | class Profile; |
| 72 | class RenderViewHost; |
| 73 | class SessionStorageNamespace; |
| 74 | class SiteInstance; |
| 75 | class SkBitmap; |
| 76 | class TabContents; |
| 77 | class TabContentsDelegate; |
| 78 | class TabContentsObserver; |
| 79 | class TabContentsSSLHelper; |
| 80 | class TabContentsView; |
| 81 | class URLPattern; |
| 82 | struct RendererPreferences; |
| 83 | struct ThumbnailScore; |
| 84 | struct ViewHostMsg_DomMessage_Params; |
| 85 | struct ViewHostMsg_FrameNavigate_Params; |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 86 | struct WebPreferences; |
| 87 | |
| 88 | // Describes what goes in the main content area of a tab. TabContents is |
| 89 | // the only type of TabContents, and these should be merged together. |
| 90 | class TabContents : public PageNavigator, |
| 91 | public NotificationObserver, |
| 92 | public RenderViewHostDelegate, |
| 93 | public RenderViewHostManager::Delegate, |
| 94 | public JavaScriptAppModalDialogDelegate, |
| 95 | public ImageLoadingTracker::Observer, |
[email protected] | 232a581 | 2011-03-04 22:42:08 | [diff] [blame] | 96 | public TabSpecificContentSettings::Delegate, |
| 97 | public net::NetworkChangeNotifier::OnlineStateObserver { |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 98 | public: |
| 99 | // Flags passed to the TabContentsDelegate.NavigationStateChanged to tell it |
| 100 | // what has changed. Combine them to update more than one thing. |
| 101 | enum InvalidateTypes { |
| 102 | INVALIDATE_URL = 1 << 0, // The URL has changed. |
| 103 | INVALIDATE_TAB = 1 << 1, // The favicon, app icon, or crashed |
| 104 | // state changed. |
| 105 | INVALIDATE_LOAD = 1 << 2, // The loading state has changed. |
| 106 | INVALIDATE_PAGE_ACTIONS = 1 << 3, // Page action icons have changed. |
| 107 | INVALIDATE_BOOKMARK_BAR = 1 << 4, // State of ShouldShowBookmarkBar |
| 108 | // changed. |
| 109 | INVALIDATE_TITLE = 1 << 5, // The title changed. |
| 110 | }; |
| 111 | |
| 112 | // |base_tab_contents| is used if we want to size the new tab contents view |
| 113 | // based on an existing tab contents view. This can be NULL if not needed. |
| 114 | // |
| 115 | // The session storage namespace parameter allows multiple render views and |
| 116 | // tab contentses to share the same session storage (part of the WebStorage |
| 117 | // spec) space. This is useful when restoring tabs, but most callers should |
| 118 | // pass in NULL which will cause a new SessionStorageNamespace to be created. |
| 119 | TabContents(Profile* profile, |
| 120 | SiteInstance* site_instance, |
| 121 | int routing_id, |
| 122 | const TabContents* base_tab_contents, |
| 123 | SessionStorageNamespace* session_storage_namespace); |
| 124 | virtual ~TabContents(); |
| 125 | |
| 126 | // Intrinsic tab state ------------------------------------------------------- |
| 127 | |
| 128 | // Returns the property bag for this tab contents, where callers can add |
| 129 | // extra data they may wish to associate with the tab. Returns a pointer |
| 130 | // rather than a reference since the PropertyAccessors expect this. |
| 131 | const PropertyBag* property_bag() const { return &property_bag_; } |
| 132 | PropertyBag* property_bag() { return &property_bag_; } |
| 133 | |
| 134 | TabContentsDelegate* delegate() const { return delegate_; } |
| 135 | void set_delegate(TabContentsDelegate* d) { delegate_ = d; } |
| 136 | |
| 137 | // Gets the controller for this tab contents. |
| 138 | NavigationController& controller() { return controller_; } |
| 139 | const NavigationController& controller() const { return controller_; } |
| 140 | |
| 141 | // Returns the user profile associated with this TabContents (via the |
| 142 | // NavigationController). |
| 143 | Profile* profile() const { return controller_.profile(); } |
| 144 | |
| 145 | // Returns true if contains content rendered by an extension. |
| 146 | bool HostsExtension() const; |
| 147 | |
| 148 | // Returns the TabContentsSSLHelper, creating it if necessary. |
| 149 | TabContentsSSLHelper* GetSSLHelper(); |
| 150 | |
| 151 | // Returns the SavePackage which manages the page saving job. May be NULL. |
| 152 | SavePackage* save_package() const { return save_package_.get(); } |
| 153 | |
| 154 | // Return the currently active RenderProcessHost and RenderViewHost. Each of |
| 155 | // these may change over time. |
| 156 | RenderProcessHost* GetRenderProcessHost() const; |
| 157 | RenderViewHost* render_view_host() const { |
| 158 | return render_manager_.current_host(); |
| 159 | } |
| 160 | |
| 161 | WebUI* web_ui() const { |
| 162 | return render_manager_.web_ui() ? render_manager_.web_ui() |
| 163 | : render_manager_.pending_web_ui(); |
| 164 | } |
| 165 | |
| 166 | // Returns the currently active RenderWidgetHostView. This may change over |
| 167 | // time and can be NULL (during setup and teardown). |
| 168 | RenderWidgetHostView* GetRenderWidgetHostView() const { |
| 169 | return render_manager_.GetRenderWidgetHostView(); |
| 170 | } |
| 171 | |
| 172 | // The TabContentsView will never change and is guaranteed non-NULL. |
| 173 | TabContentsView* view() const { |
| 174 | return view_.get(); |
| 175 | } |
| 176 | |
[email protected] | 34952d1 | 2011-03-14 19:45:13 | [diff] [blame] | 177 | // Returns the FaviconHelper of this TabContents. |
[email protected] | 16be5c3 | 2011-03-15 17:52:03 | [diff] [blame] | 178 | FaviconHelper& favicon_helper() { |
| 179 | return *favicon_helper_.get(); |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | // App extensions ------------------------------------------------------------ |
| 183 | |
| 184 | // Sets the extension denoting this as an app. If |extension| is non-null this |
| 185 | // tab becomes an app-tab. TabContents does not listen for unload events for |
| 186 | // the extension. It's up to consumers of TabContents to do that. |
| 187 | // |
| 188 | // NOTE: this should only be manipulated before the tab is added to a browser. |
| 189 | // TODO(sky): resolve if this is the right way to identify an app tab. If it |
| 190 | // is, than this should be passed in the constructor. |
| 191 | void SetExtensionApp(const Extension* extension); |
| 192 | |
| 193 | // Convenience for setting the app extension by id. This does nothing if |
| 194 | // |extension_app_id| is empty, or an extension can't be found given the |
| 195 | // specified id. |
| 196 | void SetExtensionAppById(const std::string& extension_app_id); |
| 197 | |
| 198 | const Extension* extension_app() const { return extension_app_; } |
| 199 | bool is_app() const { return extension_app_ != NULL; } |
| 200 | |
| 201 | // If an app extension has been explicitly set for this TabContents its icon |
| 202 | // is returned. |
| 203 | // |
| 204 | // NOTE: the returned icon is larger than 16x16 (its size is |
| 205 | // Extension::EXTENSION_ICON_SMALLISH). |
| 206 | SkBitmap* GetExtensionAppIcon(); |
| 207 | |
| 208 | // Tab navigation state ------------------------------------------------------ |
| 209 | |
| 210 | // Returns the current navigation properties, which if a navigation is |
| 211 | // pending may be provisional (e.g., the navigation could result in a |
| 212 | // download, in which case the URL would revert to what it was previously). |
| 213 | virtual const GURL& GetURL() const; |
| 214 | virtual const string16& GetTitle() const; |
| 215 | |
| 216 | // The max PageID of any page that this TabContents has loaded. PageIDs |
| 217 | // increase with each new page that is loaded by a tab. If this is a |
| 218 | // TabContents, then the max PageID is kept separately on each SiteInstance. |
| 219 | // Returns -1 if no PageIDs have yet been seen. |
| 220 | int32 GetMaxPageID(); |
| 221 | |
| 222 | // Updates the max PageID to be at least the given PageID. |
| 223 | void UpdateMaxPageID(int32 page_id); |
| 224 | |
| 225 | // Returns the site instance associated with the current page. By default, |
| 226 | // there is no site instance. TabContents overrides this to provide proper |
| 227 | // access to its site instance. |
| 228 | virtual SiteInstance* GetSiteInstance() const; |
| 229 | |
| 230 | // Defines whether this tab's URL should be displayed in the browser's URL |
| 231 | // bar. Normally this is true so you can see the URL. This is set to false |
| 232 | // for the new tab page and related pages so that the URL bar is empty and |
| 233 | // the user is invited to type into it. |
| 234 | virtual bool ShouldDisplayURL(); |
| 235 | |
| 236 | // Returns the favicon for this tab, or an isNull() bitmap if the tab does not |
| 237 | // have a favicon. The default implementation uses the current navigation |
| 238 | // entry. |
[email protected] | 9b488bda | 2011-03-15 14:42:27 | [diff] [blame] | 239 | SkBitmap GetFavicon() const; |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 240 | |
| 241 | // Returns true if we are not using the default favicon. |
[email protected] | d8e74e8 | 2011-03-15 19:38:48 | [diff] [blame] | 242 | bool FaviconIsValid() const; |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 243 | |
| 244 | // Returns whether the favicon should be displayed. If this returns false, no |
| 245 | // space is provided for the favicon, and the favicon is never displayed. |
[email protected] | d8e74e8 | 2011-03-15 19:38:48 | [diff] [blame] | 246 | virtual bool ShouldDisplayFavicon(); |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 247 | |
| 248 | // Add and remove observers for page navigation notifications. Adding or |
| 249 | // removing multiple times has no effect. The order in which notifications |
| 250 | // are sent to observers is undefined. Clients must be sure to remove the |
| 251 | // observer before they go away. |
| 252 | void AddObserver(TabContentsObserver* observer); |
| 253 | void RemoveObserver(TabContentsObserver* observer); |
| 254 | |
| 255 | // Return whether this tab contents is loading a resource. |
| 256 | bool is_loading() const { return is_loading_; } |
| 257 | |
| 258 | // Returns whether this tab contents is waiting for a first-response for the |
| 259 | // main resource of the page. This controls whether the throbber state is |
| 260 | // "waiting" or "loading." |
| 261 | bool waiting_for_response() const { return waiting_for_response_; } |
| 262 | |
| 263 | net::LoadState load_state() const { return load_state_; } |
| 264 | string16 load_state_host() const { return load_state_host_; } |
| 265 | uint64 upload_size() const { return upload_size_; } |
| 266 | uint64 upload_position() const { return upload_position_; } |
| 267 | |
| 268 | const std::string& encoding() const { return encoding_; } |
| 269 | void set_encoding(const std::string& encoding); |
| 270 | void reset_encoding() { |
| 271 | encoding_.clear(); |
| 272 | } |
| 273 | |
| 274 | const WebApplicationInfo& web_app_info() const { |
| 275 | return web_app_info_; |
| 276 | } |
| 277 | |
| 278 | const SkBitmap& app_icon() const { return app_icon_; } |
| 279 | |
| 280 | // Sets an app icon associated with TabContents and fires an INVALIDATE_TITLE |
| 281 | // navigation state change to trigger repaint of title. |
| 282 | void SetAppIcon(const SkBitmap& app_icon); |
| 283 | |
| 284 | bool displayed_insecure_content() const { |
| 285 | return displayed_insecure_content_; |
| 286 | } |
| 287 | |
| 288 | // Internal state ------------------------------------------------------------ |
| 289 | |
| 290 | // This flag indicates whether the tab contents is currently being |
| 291 | // screenshotted by the DraggedTabController. |
| 292 | bool capturing_contents() const { return capturing_contents_; } |
| 293 | void set_capturing_contents(bool cap) { capturing_contents_ = cap; } |
| 294 | |
| 295 | // Indicates whether this tab should be considered crashed. The setter will |
| 296 | // also notify the delegate when the flag is changed. |
| 297 | bool is_crashed() const { |
| 298 | return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED || |
| 299 | crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION || |
| 300 | crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED); |
| 301 | } |
| 302 | base::TerminationStatus crashed_status() const { return crashed_status_; } |
| 303 | int crashed_error_code() const { return crashed_error_code_; } |
| 304 | void SetIsCrashed(base::TerminationStatus status, int error_code); |
| 305 | |
| 306 | // Call this after updating a page action to notify clients about the changes. |
| 307 | void PageActionStateChanged(); |
| 308 | |
| 309 | // Whether the tab is in the process of being destroyed. |
| 310 | // Added as a tentative work-around for focus related bug #4633. This allows |
| 311 | // us not to store focus when a tab is being closed. |
| 312 | bool is_being_destroyed() const { return is_being_destroyed_; } |
| 313 | |
| 314 | // Convenience method for notifying the delegate of a navigation state |
| 315 | // change. See TabContentsDelegate. |
| 316 | void NotifyNavigationStateChanged(unsigned changed_flags); |
| 317 | |
| 318 | // Invoked when the tab contents becomes selected. If you override, be sure |
| 319 | // and invoke super's implementation. |
| 320 | virtual void DidBecomeSelected(); |
| 321 | base::TimeTicks last_selected_time() const { |
| 322 | return last_selected_time_; |
| 323 | } |
| 324 | |
| 325 | // Invoked when the tab contents becomes hidden. |
| 326 | // NOTE: If you override this, call the superclass version too! |
| 327 | virtual void WasHidden(); |
| 328 | |
| 329 | // Activates this contents within its containing window, bringing that window |
| 330 | // to the foreground if necessary. |
| 331 | void Activate(); |
| 332 | |
| 333 | // Deactivates this contents by deactivating its containing window. |
| 334 | void Deactivate(); |
| 335 | |
| 336 | // TODO(brettw) document these. |
| 337 | virtual void ShowContents(); |
| 338 | virtual void HideContents(); |
| 339 | |
| 340 | // Returns true if the before unload and unload listeners need to be |
| 341 | // fired. The value of this changes over time. For example, if true and the |
| 342 | // before unload listener is executed and allows the user to exit, then this |
| 343 | // returns false. |
| 344 | bool NeedToFireBeforeUnload(); |
| 345 | |
| 346 | #ifdef UNIT_TEST |
| 347 | // Expose the render manager for testing. |
| 348 | RenderViewHostManager* render_manager() { return &render_manager_; } |
| 349 | #endif |
| 350 | |
| 351 | // In the underlying RenderViewHostManager, swaps in the provided |
| 352 | // RenderViewHost to replace the current RenderViewHost. The current RVH |
| 353 | // will be shutdown and ultimately deleted. |
| 354 | void SwapInRenderViewHost(RenderViewHost* rvh); |
| 355 | |
| 356 | // Commands ------------------------------------------------------------------ |
| 357 | |
| 358 | // Implementation of PageNavigator. |
| 359 | virtual void OpenURL(const GURL& url, const GURL& referrer, |
| 360 | WindowOpenDisposition disposition, |
| 361 | PageTransition::Type transition); |
| 362 | |
| 363 | // Called by the NavigationController to cause the TabContents to navigate to |
| 364 | // the current pending entry. The NavigationController should be called back |
| 365 | // with CommitPendingEntry/RendererDidNavigate on success or |
| 366 | // DiscardPendingEntry. The callbacks can be inside of this function, or at |
| 367 | // some future time. |
| 368 | // |
| 369 | // The entry has a PageID of -1 if newly created (corresponding to navigation |
| 370 | // to a new URL). |
| 371 | // |
| 372 | // If this method returns false, then the navigation is discarded (equivalent |
| 373 | // to calling DiscardPendingEntry on the NavigationController). |
| 374 | virtual bool NavigateToPendingEntry( |
| 375 | NavigationController::ReloadType reload_type); |
| 376 | |
| 377 | // Stop any pending navigation. |
| 378 | virtual void Stop(); |
| 379 | |
| 380 | // Called on a TabContents when it isn't a popup, but a new window. |
| 381 | virtual void DisassociateFromPopupCount(); |
| 382 | |
| 383 | // Creates a new TabContents with the same state as this one. The returned |
| 384 | // heap-allocated pointer is owned by the caller. |
| 385 | virtual TabContents* Clone(); |
| 386 | |
| 387 | // Shows the page info. |
| 388 | void ShowPageInfo(const GURL& url, |
| 389 | const NavigationEntry::SSLStatus& ssl, |
| 390 | bool show_history); |
| 391 | |
| 392 | // Saves the favicon for the current page. |
| 393 | void SaveFavicon(); |
| 394 | |
| 395 | // Window management --------------------------------------------------------- |
| 396 | |
| 397 | // Create a new window constrained to this TabContents' clip and visibility. |
| 398 | // The window is initialized by using the supplied delegate to obtain basic |
| 399 | // window characteristics, and the supplied view for the content. Note that |
| 400 | // the returned ConstrainedWindow might not yet be visible. |
| 401 | ConstrainedWindow* CreateConstrainedDialog( |
| 402 | ConstrainedWindowDelegate* delegate); |
| 403 | |
| 404 | // Adds a new tab or window with the given already-created contents |
| 405 | void AddNewContents(TabContents* new_contents, |
| 406 | WindowOpenDisposition disposition, |
| 407 | const gfx::Rect& initial_pos, |
| 408 | bool user_gesture); |
| 409 | |
| 410 | // Execute code in this tab. Returns true if the message was successfully |
| 411 | // sent. |
| 412 | bool ExecuteCode(int request_id, const std::string& extension_id, |
| 413 | bool is_js_code, const std::string& code_string, |
| 414 | bool all_frames); |
| 415 | |
| 416 | // Called when the blocked popup notification is shown or hidden. |
| 417 | virtual void PopupNotificationVisibilityChanged(bool visible); |
| 418 | |
| 419 | // Returns the number of constrained windows in this tab. Used by tests. |
| 420 | size_t constrained_window_count() { return child_windows_.size(); } |
| 421 | |
| 422 | typedef std::deque<ConstrainedWindow*> ConstrainedWindowList; |
| 423 | |
| 424 | // Return an iterator for the first constrained window in this tab contents. |
| 425 | ConstrainedWindowList::iterator constrained_window_begin() |
| 426 | { return child_windows_.begin(); } |
| 427 | |
| 428 | // Return an iterator for the last constrained window in this tab contents. |
| 429 | ConstrainedWindowList::iterator constrained_window_end() |
| 430 | { return child_windows_.end(); } |
| 431 | |
| 432 | // Views and focus ----------------------------------------------------------- |
| 433 | // TODO(brettw): Most of these should be removed and the caller should call |
| 434 | // the view directly. |
| 435 | |
| 436 | // Returns the actual window that is focused when this TabContents is shown. |
| 437 | gfx::NativeView GetContentNativeView() const; |
| 438 | |
| 439 | // Returns the NativeView associated with this TabContents. Outside of |
| 440 | // automation in the context of the UI, this is required to be implemented. |
| 441 | gfx::NativeView GetNativeView() const; |
| 442 | |
| 443 | // Returns the bounds of this TabContents in the screen coordinate system. |
| 444 | void GetContainerBounds(gfx::Rect *out) const; |
| 445 | |
| 446 | // Makes the tab the focused window. |
| 447 | void Focus(); |
| 448 | |
| 449 | // Focuses the first (last if |reverse| is true) element in the page. |
| 450 | // Invoked when this tab is getting the focus through tab traversal (|reverse| |
| 451 | // is true when using Shift-Tab). |
| 452 | void FocusThroughTabTraversal(bool reverse); |
| 453 | |
| 454 | // These next two functions are declared on RenderViewHostManager::Delegate |
| 455 | // but also accessed directly by other callers. |
| 456 | |
| 457 | // Returns true if the location bar should be focused by default rather than |
| 458 | // the page contents. The view calls this function when the tab is focused |
| 459 | // to see what it should do. |
| 460 | virtual bool FocusLocationBarByDefault(); |
| 461 | |
| 462 | // Focuses the location bar. |
| 463 | virtual void SetFocusToLocationBar(bool select_all); |
| 464 | |
| 465 | // Creates a view and sets the size for the specified RVH. |
| 466 | virtual void CreateViewAndSetSizeForRVH(RenderViewHost* rvh); |
| 467 | |
| 468 | // Infobars ------------------------------------------------------------------ |
| 469 | |
| 470 | // Adds an InfoBar for the specified |delegate|. |
[email protected] | dc83fcbd | 2011-02-23 23:26:52 | [diff] [blame] | 471 | void AddInfoBar(InfoBarDelegate* delegate); |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 472 | |
| 473 | // Removes the InfoBar for the specified |delegate|. |
| 474 | void RemoveInfoBar(InfoBarDelegate* delegate); |
| 475 | |
| 476 | // Replaces one infobar with another, without any animation in between. |
| 477 | void ReplaceInfoBar(InfoBarDelegate* old_delegate, |
| 478 | InfoBarDelegate* new_delegate); |
| 479 | |
| 480 | // Enumeration and access functions. |
| 481 | size_t infobar_count() const { return infobar_delegates_.size(); } |
| 482 | // WARNING: This does not sanity-check |index|! |
| 483 | InfoBarDelegate* GetInfoBarDelegateAt(size_t index) { |
| 484 | return infobar_delegates_[index]; |
| 485 | } |
| 486 | |
| 487 | // Toolbars and such --------------------------------------------------------- |
| 488 | |
| 489 | // Returns true if a Bookmark Bar should be shown for this tab. |
| 490 | virtual bool ShouldShowBookmarkBar(); |
| 491 | |
| 492 | // Notifies the delegate that a download is about to be started. |
| 493 | // This notification is fired before a local temporary file has been created. |
| 494 | bool CanDownload(int request_id); |
| 495 | |
| 496 | // Notifies the delegate that a download started. |
| 497 | void OnStartDownload(DownloadItem* download); |
| 498 | |
| 499 | // Notify our delegate that some of our content has animated. |
| 500 | void ToolbarSizeChanged(bool is_animating); |
| 501 | |
| 502 | // Called when a ConstrainedWindow we own is about to be closed. |
| 503 | void WillClose(ConstrainedWindow* window); |
| 504 | |
| 505 | // Called when a BlockedContentContainer we own is about to be closed. |
| 506 | void WillCloseBlockedContentContainer(BlockedContentContainer* container); |
| 507 | |
| 508 | // Called when a ConstrainedWindow we own is moved or resized. |
| 509 | void DidMoveOrResize(ConstrainedWindow* window); |
| 510 | |
| 511 | // Interstitials ------------------------------------------------------------- |
| 512 | |
| 513 | // Various other systems need to know about our interstitials. |
| 514 | bool showing_interstitial_page() const { |
| 515 | return render_manager_.interstitial_page() != NULL; |
| 516 | } |
| 517 | |
| 518 | // Sets the passed passed interstitial as the currently showing interstitial. |
| 519 | // |interstitial_page| should be non NULL (use the remove_interstitial_page |
| 520 | // method to unset the interstitial) and no interstitial page should be set |
| 521 | // when there is already a non NULL interstitial page set. |
| 522 | void set_interstitial_page(InterstitialPage* interstitial_page) { |
| 523 | render_manager_.set_interstitial_page(interstitial_page); |
| 524 | } |
| 525 | |
| 526 | // Unsets the currently showing interstitial. |
| 527 | void remove_interstitial_page() { |
| 528 | render_manager_.remove_interstitial_page(); |
| 529 | } |
| 530 | |
| 531 | // Returns the currently showing interstitial, NULL if no interstitial is |
| 532 | // showing. |
| 533 | InterstitialPage* interstitial_page() const { |
| 534 | return render_manager_.interstitial_page(); |
| 535 | } |
| 536 | |
| 537 | // Misc state & callbacks ---------------------------------------------------- |
| 538 | |
| 539 | // Set whether the contents should block javascript message boxes or not. |
| 540 | // Default is not to block any message boxes. |
| 541 | void set_suppress_javascript_messages(bool suppress_javascript_messages) { |
| 542 | suppress_javascript_messages_ = suppress_javascript_messages; |
| 543 | } |
| 544 | |
| 545 | // Prepare for saving the current web page to disk. |
| 546 | void OnSavePage(); |
| 547 | |
| 548 | // Save page with the main HTML file path, the directory for saving resources, |
| 549 | // and the save type: HTML only or complete web page. Returns true if the |
| 550 | // saving process has been initiated successfully. |
| 551 | bool SavePage(const FilePath& main_file, const FilePath& dir_path, |
| 552 | SavePackage::SavePackageType save_type); |
| 553 | |
| 554 | // Tells the user's email client to open a compose window containing the |
| 555 | // current page's URL. |
| 556 | void EmailPageLocation(); |
| 557 | |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 558 | // Prints the current document immediately. Since the rendering is |
| 559 | // asynchronous, the actual printing will not be completed on the return of |
| 560 | // this function. Returns false if printing is impossible at the moment. |
| 561 | bool PrintNow(); |
| 562 | |
| 563 | // Notify the completion of a printing job. |
| 564 | void PrintingDone(int document_cookie, bool success); |
| 565 | |
| 566 | // Returns true if the active NavigationEntry's page_id equals page_id. |
| 567 | bool IsActiveEntry(int32 page_id); |
| 568 | |
| 569 | const std::string& contents_mime_type() const { |
| 570 | return contents_mime_type_; |
| 571 | } |
| 572 | |
| 573 | // Returns true if this TabContents will notify about disconnection. |
| 574 | bool notify_disconnection() const { return notify_disconnection_; } |
| 575 | |
| 576 | // Override the encoding and reload the page by sending down |
| 577 | // ViewMsg_SetPageEncoding to the renderer. |UpdateEncoding| is kinda |
| 578 | // the opposite of this, by which 'browser' is notified of |
| 579 | // the encoding of the current tab from 'renderer' (determined by |
| 580 | // auto-detect, http header, meta, bom detection, etc). |
| 581 | void SetOverrideEncoding(const std::string& encoding); |
| 582 | |
| 583 | // Remove any user-defined override encoding and reload by sending down |
| 584 | // ViewMsg_ResetPageEncodingToDefault to the renderer. |
| 585 | void ResetOverrideEncoding(); |
| 586 | |
| 587 | void WindowMoveOrResizeStarted(); |
| 588 | |
| 589 | // Sets whether all TabContents added by way of |AddNewContents| should be |
| 590 | // blocked. Transitioning from all blocked to not all blocked results in |
| 591 | // reevaluating any blocked TabContents, which may result in unblocking some |
| 592 | // of the blocked TabContents. |
| 593 | void SetAllContentsBlocked(bool value); |
| 594 | |
| 595 | BlockedContentContainer* blocked_content_container() const { |
| 596 | return blocked_contents_; |
| 597 | } |
| 598 | |
| 599 | RendererPreferences* GetMutableRendererPrefs() { |
| 600 | return &renderer_preferences_; |
| 601 | } |
| 602 | |
| 603 | void set_opener_web_ui_type(WebUITypeID opener_web_ui_type) { |
| 604 | opener_web_ui_type_ = opener_web_ui_type; |
| 605 | } |
| 606 | |
| 607 | // We want to time how long it takes to create a new tab page. This method |
| 608 | // gets called as parts of the new tab page have loaded. |
| 609 | void LogNewTabTime(const std::string& event_name); |
| 610 | |
| 611 | // Set the time when we started to create the new tab page. This time is |
| 612 | // from before we created this TabContents. |
| 613 | void set_new_tab_start_time(const base::TimeTicks& time) { |
| 614 | new_tab_start_time_ = time; |
| 615 | } |
| 616 | |
| 617 | // Notification that tab closing has started. This can be called multiple |
| 618 | // times, subsequent calls are ignored. |
| 619 | void OnCloseStarted(); |
| 620 | |
| 621 | LanguageState& language_state() { |
| 622 | return language_state_; |
| 623 | } |
| 624 | |
| 625 | // Returns true if underlying TabContentsView should accept drag-n-drop. |
| 626 | bool ShouldAcceptDragAndDrop() const; |
| 627 | |
| 628 | // A render view-originated drag has ended. Informs the render view host and |
| 629 | // tab contents delegate. |
| 630 | void SystemDragEnded(); |
| 631 | |
| 632 | // Indicates if this tab was explicitly closed by the user (control-w, close |
| 633 | // tab menu item...). This is false for actions that indirectly close the tab, |
| 634 | // such as closing the window. The setter is maintained by TabStripModel, and |
| 635 | // the getter only useful from within TAB_CLOSED notification |
| 636 | void set_closed_by_user_gesture(bool value) { |
| 637 | closed_by_user_gesture_ = value; |
| 638 | } |
| 639 | bool closed_by_user_gesture() const { return closed_by_user_gesture_; } |
| 640 | |
| 641 | // Overridden from JavaScriptAppModalDialogDelegate: |
| 642 | virtual void OnMessageBoxClosed(IPC::Message* reply_msg, |
| 643 | bool success, |
| 644 | const std::wstring& prompt); |
| 645 | virtual void SetSuppressMessageBoxes(bool suppress_message_boxes); |
| 646 | virtual gfx::NativeWindow GetMessageBoxRootWindow(); |
| 647 | virtual TabContents* AsTabContents(); |
| 648 | virtual ExtensionHost* AsExtensionHost(); |
| 649 | |
| 650 | // The BookmarkDragDelegate is used to forward bookmark drag and drop events |
| 651 | // to extensions. |
| 652 | virtual RenderViewHostDelegate::BookmarkDrag* GetBookmarkDragDelegate(); |
| 653 | |
| 654 | // It is up to callers to call SetBookmarkDragDelegate(NULL) when |
| 655 | // |bookmark_drag| is deleted since this class does not take ownership of |
| 656 | // |bookmark_drag|. |
| 657 | virtual void SetBookmarkDragDelegate( |
| 658 | RenderViewHostDelegate::BookmarkDrag* bookmark_drag); |
| 659 | |
| 660 | // The TabSpecificContentSettings object is used to query the blocked content |
| 661 | // state by various UI elements. |
| 662 | TabSpecificContentSettings* GetTabSpecificContentSettings() const; |
| 663 | |
| 664 | // Updates history with the specified navigation. This is called by |
| 665 | // OnMsgNavigate to update history state. |
| 666 | void UpdateHistoryForNavigation( |
| 667 | scoped_refptr<history::HistoryAddPageArgs> add_page_args); |
| 668 | |
| 669 | // Sends the page title to the history service. This is called when we receive |
| 670 | // the page title and we know we want to update history. |
| 671 | void UpdateHistoryPageTitle(const NavigationEntry& entry); |
| 672 | |
| 673 | // Gets the zoom level for this tab. |
| 674 | double GetZoomLevel() const; |
| 675 | |
| 676 | // Gets the zoom percent for this tab. |
| 677 | int GetZoomPercent(bool* enable_increment, bool* enable_decrement); |
| 678 | |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 679 | // Opens view-source tab for this contents. |
| 680 | void ViewSource(); |
| 681 | |
[email protected] | 932b7a1 | 2011-03-09 12:50:27 | [diff] [blame] | 682 | void ViewFrameSource(const GURL& url, |
| 683 | const std::string& content_state); |
| 684 | |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 685 | // Gets the minimum/maximum zoom percent. |
| 686 | int minimum_zoom_percent() const { return minimum_zoom_percent_; } |
| 687 | int maximum_zoom_percent() const { return maximum_zoom_percent_; } |
| 688 | |
| 689 | int content_restrictions() const { return content_restrictions_; } |
[email protected] | c40d623 | 2011-03-25 00:16:21 | [diff] [blame] | 690 | void SetContentRestrictions(int restrictions); |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 691 | |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 692 | safe_browsing::ClientSideDetectionHost* safebrowsing_detection_host() { |
| 693 | return safebrowsing_detection_host_.get(); |
| 694 | } |
| 695 | |
| 696 | protected: |
| 697 | // from RenderViewHostDelegate. |
| 698 | virtual bool OnMessageReceived(const IPC::Message& message); |
| 699 | |
| 700 | private: |
| 701 | friend class NavigationController; |
| 702 | // Used to access the child_windows_ (ConstrainedWindowList) for testing |
| 703 | // automation purposes. |
| 704 | friend class TestingAutomationProvider; |
| 705 | |
| 706 | FRIEND_TEST_ALL_PREFIXES(TabContentsTest, NoJSMessageOnInterstitials); |
| 707 | FRIEND_TEST_ALL_PREFIXES(TabContentsTest, UpdateTitle); |
| 708 | FRIEND_TEST_ALL_PREFIXES(TabContentsTest, CrossSiteCantPreemptAfterUnload); |
[email protected] | aed5960 | 2011-02-28 22:57:33 | [diff] [blame] | 709 | FRIEND_TEST_ALL_PREFIXES(TabContentsTest, ConstrainedWindows); |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 710 | FRIEND_TEST_ALL_PREFIXES(FormStructureBrowserTest, HTMLFiles); |
| 711 | FRIEND_TEST_ALL_PREFIXES(NavigationControllerTest, HistoryNavigate); |
| 712 | FRIEND_TEST_ALL_PREFIXES(RenderViewHostManagerTest, PageDoesBackAndReload); |
| 713 | |
| 714 | // Temporary until the view/contents separation is complete. |
| 715 | friend class TabContentsView; |
| 716 | #if defined(OS_WIN) |
| 717 | friend class TabContentsViewWin; |
| 718 | #elif defined(OS_MACOSX) |
| 719 | friend class TabContentsViewMac; |
| 720 | #elif defined(TOOLKIT_USES_GTK) |
| 721 | friend class TabContentsViewGtk; |
| 722 | #endif |
| 723 | |
| 724 | // So InterstitialPage can access SetIsLoading. |
| 725 | friend class InterstitialPage; |
| 726 | |
| 727 | // TODO(brettw) TestTabContents shouldn't exist! |
| 728 | friend class TestTabContents; |
| 729 | |
| 730 | // Used to access the CreateHistoryAddPageArgs member function. |
| 731 | friend class ExternalTabContainer; |
| 732 | |
| 733 | // Used to access RVH Delegates. |
| 734 | friend class prerender::PrerenderManager; |
| 735 | |
| 736 | // Add all the TabContentObservers. |
| 737 | void AddObservers(); |
| 738 | |
| 739 | // Message handlers. |
| 740 | void OnDidStartProvisionalLoadForFrame(int64 frame_id, |
| 741 | bool main_frame, |
| 742 | const GURL& url); |
| 743 | void OnDidRedirectProvisionalLoad(int32 page_id, |
| 744 | const GURL& source_url, |
| 745 | const GURL& target_url); |
| 746 | void OnDidFailProvisionalLoadWithError(int64 frame_id, |
| 747 | bool main_frame, |
| 748 | int error_code, |
| 749 | const GURL& url, |
| 750 | bool showing_repost_interstitial); |
| 751 | void OnDidLoadResourceFromMemoryCache(const GURL& url, |
| 752 | const std::string& security_info); |
| 753 | void OnDidDisplayInsecureContent(); |
| 754 | void OnDidRunInsecureContent(const std::string& security_origin, |
| 755 | const GURL& target_url); |
| 756 | void OnDocumentLoadedInFrame(int64 frame_id); |
| 757 | void OnDidFinishLoad(int64 frame_id); |
| 758 | void OnUpdateContentRestrictions(int restrictions); |
| 759 | void OnPDFHasUnsupportedFeature(); |
| 760 | |
| 761 | void OnGoToEntryAtOffset(int offset); |
| 762 | void OnDidGetApplicationInfo(int32 page_id, const WebApplicationInfo& info); |
| 763 | void OnInstallApplication(const WebApplicationInfo& info); |
| 764 | void OnPageContents(const GURL& url, |
| 765 | int32 page_id, |
| 766 | const string16& contents, |
| 767 | const std::string& language, |
| 768 | bool page_translatable); |
| 769 | void OnPageTranslated(int32 page_id, |
| 770 | const std::string& original_lang, |
| 771 | const std::string& translated_lang, |
| 772 | TranslateErrors::Type error_type); |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 773 | |
| 774 | // Changes the IsLoading state and notifies delegate as needed |
| 775 | // |details| is used to provide details on the load that just finished |
| 776 | // (but can be null if not applicable). Can be overridden. |
| 777 | void SetIsLoading(bool is_loading, |
| 778 | LoadNotificationDetails* details); |
| 779 | |
| 780 | // Adds the incoming |new_contents| to the |blocked_contents_| container. |
| 781 | void AddPopup(TabContents* new_contents, |
| 782 | const gfx::Rect& initial_pos); |
| 783 | |
| 784 | // Called by derived classes to indicate that we're no longer waiting for a |
| 785 | // response. This won't actually update the throbber, but it will get picked |
| 786 | // up at the next animation step if the throbber is going. |
| 787 | void SetNotWaitingForResponse() { waiting_for_response_ = false; } |
| 788 | |
| 789 | ConstrainedWindowList child_windows_; |
| 790 | |
| 791 | // Expires InfoBars that need to be expired, according to the state carried |
| 792 | // in |details|, in response to a new NavigationEntry being committed (the |
| 793 | // user navigated to another page). |
| 794 | void ExpireInfoBars( |
| 795 | const NavigationController::LoadCommittedDetails& details); |
| 796 | |
| 797 | // Returns the WebUI for the current state of the tab. This will either be |
| 798 | // the pending WebUI, the committed WebUI, or NULL. |
| 799 | WebUI* GetWebUIForCurrentState(); |
| 800 | |
| 801 | // Navigation helpers -------------------------------------------------------- |
| 802 | // |
| 803 | // These functions are helpers for Navigate() and DidNavigate(). |
| 804 | |
| 805 | // Handles post-navigation tasks in DidNavigate AFTER the entry has been |
| 806 | // committed to the navigation controller. Note that the navigation entry is |
| 807 | // not provided since it may be invalid/changed after being committed. The |
| 808 | // current navigation entry is in the NavigationController at this point. |
| 809 | void DidNavigateMainFramePostCommit( |
| 810 | const NavigationController::LoadCommittedDetails& details, |
| 811 | const ViewHostMsg_FrameNavigate_Params& params); |
| 812 | void DidNavigateAnyFramePostCommit( |
| 813 | RenderViewHost* render_view_host, |
| 814 | const NavigationController::LoadCommittedDetails& details, |
| 815 | const ViewHostMsg_FrameNavigate_Params& params); |
| 816 | |
| 817 | // Closes all constrained windows. |
| 818 | void CloseConstrainedWindows(); |
| 819 | |
| 820 | // Send the alternate error page URL to the renderer. This method is virtual |
| 821 | // so special html pages can override this (e.g., the new tab page). |
| 822 | virtual void UpdateAlternateErrorPageURL(); |
| 823 | |
| 824 | // Send webkit specific settings to the renderer. |
| 825 | void UpdateWebPreferences(); |
| 826 | |
| 827 | // Instruct the renderer to update the zoom level. |
| 828 | void UpdateZoomLevel(); |
| 829 | |
| 830 | // If our controller was restored and the page id is > than the site |
| 831 | // instance's page id, the site instances page id is updated as well as the |
| 832 | // renderers max page id. |
| 833 | void UpdateMaxPageIDIfNecessary(SiteInstance* site_instance, |
| 834 | RenderViewHost* rvh); |
| 835 | |
| 836 | // Returns the history::HistoryAddPageArgs to use for adding a page to |
| 837 | // history. |
| 838 | scoped_refptr<history::HistoryAddPageArgs> CreateHistoryAddPageArgs( |
| 839 | const GURL& virtual_url, |
| 840 | const NavigationController::LoadCommittedDetails& details, |
| 841 | const ViewHostMsg_FrameNavigate_Params& params); |
| 842 | |
| 843 | // Saves the given title to the navigation entry and does associated work. It |
| 844 | // will update history and the view for the new title, and also synthesize |
| 845 | // titles for file URLs that have none (so we require that the URL of the |
| 846 | // entry already be set). |
| 847 | // |
| 848 | // This is used as the backend for state updates, which include a new title, |
| 849 | // or the dedicated set title message. It returns true if the new title is |
| 850 | // different and was therefore updated. |
| 851 | bool UpdateTitleForEntry(NavigationEntry* entry, const std::wstring& title); |
| 852 | |
| 853 | // Causes the TabContents to navigate in the right renderer to |entry|, which |
| 854 | // must be already part of the entries in the navigation controller. |
| 855 | // This does not change the NavigationController state. |
| 856 | bool NavigateToEntry(const NavigationEntry& entry, |
| 857 | NavigationController::ReloadType reload_type); |
| 858 | |
| 859 | // Misc non-view stuff ------------------------------------------------------- |
| 860 | |
| 861 | // Helper functions for sending notifications. |
| 862 | void NotifySwapped(); |
| 863 | void NotifyConnected(); |
| 864 | void NotifyDisconnected(); |
| 865 | |
| 866 | // TabSpecificContentSettings::Delegate implementation. |
| 867 | virtual void OnContentSettingsAccessed(bool content_was_blocked); |
| 868 | |
| 869 | // RenderViewHostDelegate ---------------------------------------------------- |
| 870 | |
| 871 | // RenderViewHostDelegate implementation. |
| 872 | virtual RenderViewHostDelegate::View* GetViewDelegate(); |
| 873 | virtual RenderViewHostDelegate::RendererManagement* |
| 874 | GetRendererManagementDelegate(); |
| 875 | virtual RenderViewHostDelegate::ContentSettings* GetContentSettingsDelegate(); |
| 876 | virtual RenderViewHostDelegate::SSL* GetSSLDelegate(); |
| 877 | virtual AutomationResourceRoutingDelegate* |
| 878 | GetAutomationResourceRoutingDelegate(); |
| 879 | virtual TabContents* GetAsTabContents(); |
| 880 | virtual ViewType::Type GetRenderViewType() const; |
| 881 | virtual int GetBrowserWindowID() const; |
| 882 | virtual void RenderViewCreated(RenderViewHost* render_view_host); |
| 883 | virtual void RenderViewReady(RenderViewHost* render_view_host); |
| 884 | virtual void RenderViewGone(RenderViewHost* render_view_host, |
| 885 | base::TerminationStatus status, |
| 886 | int error_code); |
| 887 | virtual void RenderViewDeleted(RenderViewHost* render_view_host); |
| 888 | virtual void DidNavigate(RenderViewHost* render_view_host, |
| 889 | const ViewHostMsg_FrameNavigate_Params& params); |
| 890 | virtual void UpdateState(RenderViewHost* render_view_host, |
| 891 | int32 page_id, |
| 892 | const std::string& state); |
| 893 | virtual void UpdateTitle(RenderViewHost* render_view_host, |
| 894 | int32 page_id, |
| 895 | const std::wstring& title); |
| 896 | virtual void UpdateEncoding(RenderViewHost* render_view_host, |
| 897 | const std::string& encoding); |
| 898 | virtual void UpdateTargetURL(int32 page_id, const GURL& url); |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 899 | virtual void UpdateInspectorSetting(const std::string& key, |
| 900 | const std::string& value); |
| 901 | virtual void ClearInspectorSettings(); |
| 902 | virtual void Close(RenderViewHost* render_view_host); |
| 903 | virtual void RequestMove(const gfx::Rect& new_bounds); |
| 904 | virtual void DidStartLoading(); |
| 905 | virtual void DidStopLoading(); |
| 906 | virtual void DidChangeLoadProgress(double progress); |
| 907 | virtual void DocumentOnLoadCompletedInMainFrame( |
| 908 | RenderViewHost* render_view_host, |
| 909 | int32 page_id); |
| 910 | virtual void RequestOpenURL(const GURL& url, const GURL& referrer, |
| 911 | WindowOpenDisposition disposition); |
| 912 | virtual void DomOperationResponse(const std::string& json_string, |
| 913 | int automation_id); |
| 914 | virtual void ProcessWebUIMessage(const ViewHostMsg_DomMessage_Params& params); |
| 915 | virtual void ProcessExternalHostMessage(const std::string& message, |
| 916 | const std::string& origin, |
| 917 | const std::string& target); |
| 918 | virtual void RunJavaScriptMessage(const std::wstring& message, |
| 919 | const std::wstring& default_prompt, |
| 920 | const GURL& frame_url, |
| 921 | const int flags, |
| 922 | IPC::Message* reply_msg, |
| 923 | bool* did_suppress_message); |
| 924 | virtual void RunBeforeUnloadConfirm(const std::wstring& message, |
| 925 | IPC::Message* reply_msg); |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 926 | virtual GURL GetAlternateErrorPageURL() const; |
| 927 | virtual RendererPreferences GetRendererPrefs(Profile* profile) const; |
| 928 | virtual WebPreferences GetWebkitPrefs(); |
| 929 | virtual void OnUserGesture(); |
| 930 | virtual void OnIgnoredUIEvent(); |
| 931 | virtual void OnCrossSiteResponse(int new_render_process_host_id, |
| 932 | int new_request_id); |
| 933 | virtual void RendererUnresponsive(RenderViewHost* render_view_host, |
| 934 | bool is_during_unload); |
| 935 | virtual void RendererResponsive(RenderViewHost* render_view_host); |
| 936 | virtual void LoadStateChanged(const GURL& url, net::LoadState load_state, |
| 937 | uint64 upload_position, uint64 upload_size); |
| 938 | virtual bool IsExternalTabContainer() const; |
| 939 | virtual void DidInsertCSS(); |
| 940 | virtual void FocusedNodeChanged(bool is_editable_node); |
| 941 | virtual void UpdateZoomLimits(int minimum_percent, |
| 942 | int maximum_percent, |
| 943 | bool remember); |
| 944 | virtual void WorkerCrashed(); |
| 945 | |
| 946 | // RenderViewHostManager::Delegate ------------------------------------------- |
| 947 | |
| 948 | // Blocks/unblocks interaction with renderer process. |
| 949 | void BlockTabContent(bool blocked); |
| 950 | |
| 951 | virtual void BeforeUnloadFiredFromRenderManager( |
| 952 | bool proceed, |
| 953 | bool* proceed_to_fire_unload); |
| 954 | virtual void DidStartLoadingFromRenderManager( |
| 955 | RenderViewHost* render_view_host); |
| 956 | virtual void RenderViewGoneFromRenderManager( |
| 957 | RenderViewHost* render_view_host); |
| 958 | virtual void UpdateRenderViewSizeForRenderManager(); |
| 959 | virtual void NotifySwappedFromRenderManager(); |
| 960 | virtual NavigationController& GetControllerForRenderManager(); |
| 961 | virtual WebUI* CreateWebUIForRenderManager(const GURL& url); |
| 962 | virtual NavigationEntry* GetLastCommittedNavigationEntryForRenderManager(); |
| 963 | |
| 964 | // Initializes the given renderer if necessary and creates the view ID |
| 965 | // corresponding to this view host. If this method is not called and the |
| 966 | // process is not shared, then the TabContents will act as though the renderer |
| 967 | // is not running (i.e., it will render "sad tab"). This method is |
| 968 | // automatically called from LoadURL. |
| 969 | // |
| 970 | // If you are attaching to an already-existing RenderView, you should call |
| 971 | // InitWithExistingID. |
| 972 | virtual bool CreateRenderViewForRenderManager( |
| 973 | RenderViewHost* render_view_host); |
| 974 | |
| 975 | // NotificationObserver ------------------------------------------------------ |
| 976 | |
| 977 | virtual void Observe(NotificationType type, |
| 978 | const NotificationSource& source, |
| 979 | const NotificationDetails& details); |
| 980 | |
| 981 | // App extensions related methods: |
| 982 | |
| 983 | // Returns the first extension whose extent contains |url|. |
| 984 | const Extension* GetExtensionContaining(const GURL& url); |
| 985 | |
| 986 | // Resets app_icon_ and if |extension| is non-null creates a new |
| 987 | // ImageLoadingTracker to load the extension's image. |
| 988 | void UpdateExtensionAppIcon(const Extension* extension); |
| 989 | |
| 990 | // ImageLoadingTracker::Observer. |
[email protected] | bd5174d | 2011-03-11 01:02:56 | [diff] [blame] | 991 | virtual void OnImageLoaded(SkBitmap* image, const ExtensionResource& resource, |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 992 | int index); |
| 993 | |
[email protected] | 232a581 | 2011-03-04 22:42:08 | [diff] [blame] | 994 | // NetworkChangeNotifier::OnlineStateObserver: |
| 995 | virtual void OnOnlineStateChanged(bool online); |
| 996 | |
[email protected] | aed5960 | 2011-02-28 22:57:33 | [diff] [blame] | 997 | // Adds the given window to the list of child windows. The window will notify |
| 998 | // via WillClose() when it is being destroyed. |
| 999 | void AddConstrainedDialog(ConstrainedWindow* window); |
| 1000 | |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 1001 | // Data for core operation --------------------------------------------------- |
| 1002 | |
| 1003 | // Delegate for notifying our owner about stuff. Not owned by us. |
| 1004 | TabContentsDelegate* delegate_; |
| 1005 | |
| 1006 | // Handles the back/forward list and loading. |
| 1007 | NavigationController controller_; |
| 1008 | |
| 1009 | // The corresponding view. |
| 1010 | scoped_ptr<TabContentsView> view_; |
| 1011 | |
| 1012 | // Helper classes ------------------------------------------------------------ |
| 1013 | |
| 1014 | // Manages creation and swapping of render views. |
| 1015 | RenderViewHostManager render_manager_; |
| 1016 | |
| 1017 | // Stores random bits of data for others to associate with this object. |
| 1018 | PropertyBag property_bag_; |
| 1019 | |
| 1020 | // Registers and unregisters us for notifications. |
| 1021 | NotificationRegistrar registrar_; |
| 1022 | |
| 1023 | // Registers and unregisters for pref notifications. |
| 1024 | PrefChangeRegistrar pref_change_registrar_; |
| 1025 | |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 1026 | // SavePackage, lazily created. |
| 1027 | scoped_refptr<SavePackage> save_package_; |
| 1028 | |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 1029 | // Handles plugin messages. |
| 1030 | scoped_ptr<PluginObserver> plugin_observer_; |
| 1031 | |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 1032 | // TabContentsSSLHelper, lazily created. |
| 1033 | scoped_ptr<TabContentsSSLHelper> ssl_helper_; |
| 1034 | |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 1035 | // Handles drag and drop event forwarding to extensions. |
| 1036 | BookmarkDrag* bookmark_drag_; |
| 1037 | |
| 1038 | // Handles downloading favicons. |
[email protected] | 16be5c3 | 2011-03-15 17:52:03 | [diff] [blame] | 1039 | scoped_ptr<FaviconHelper> favicon_helper_; |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 1040 | |
| 1041 | // Cached web app info data. |
| 1042 | WebApplicationInfo web_app_info_; |
| 1043 | |
| 1044 | // Cached web app icon. |
| 1045 | SkBitmap app_icon_; |
| 1046 | |
| 1047 | // RenderViewHost::ContentSettingsDelegate. |
| 1048 | scoped_ptr<TabSpecificContentSettings> content_settings_delegate_; |
| 1049 | |
| 1050 | // Handles desktop notification IPCs. |
| 1051 | scoped_ptr<DesktopNotificationHandlerForTC> desktop_notification_handler_; |
| 1052 | |
| 1053 | // Handles IPCs related to SafeBrowsing client-side phishing detection. |
| 1054 | scoped_ptr<safe_browsing::ClientSideDetectionHost> |
| 1055 | safebrowsing_detection_host_; |
| 1056 | |
| 1057 | // Data for loading state ---------------------------------------------------- |
| 1058 | |
| 1059 | // Indicates whether we're currently loading a resource. |
| 1060 | bool is_loading_; |
| 1061 | |
| 1062 | // Indicates if the tab is considered crashed. |
| 1063 | base::TerminationStatus crashed_status_; |
| 1064 | int crashed_error_code_; |
| 1065 | |
| 1066 | // See waiting_for_response() above. |
| 1067 | bool waiting_for_response_; |
| 1068 | |
| 1069 | // Indicates the largest PageID we've seen. This field is ignored if we are |
| 1070 | // a TabContents, in which case the max page ID is stored separately with |
| 1071 | // each SiteInstance. |
| 1072 | // TODO(brettw) this seems like it can be removed according to the comment. |
| 1073 | int32 max_page_id_; |
| 1074 | |
| 1075 | // System time at which the current load was started. |
| 1076 | base::TimeTicks current_load_start_; |
| 1077 | |
| 1078 | // The current load state and the URL associated with it. |
| 1079 | net::LoadState load_state_; |
| 1080 | string16 load_state_host_; |
| 1081 | // Upload progress, for displaying in the status bar. |
| 1082 | // Set to zero when there is no significant upload happening. |
| 1083 | uint64 upload_size_; |
| 1084 | uint64 upload_position_; |
| 1085 | |
| 1086 | // Data for current page ----------------------------------------------------- |
| 1087 | |
| 1088 | // Whether we have a (non-empty) title for the current page. |
| 1089 | // Used to prevent subsequent title updates from affecting history. This |
| 1090 | // prevents some weirdness because some AJAXy apps use titles for status |
| 1091 | // messages. |
| 1092 | bool received_page_title_; |
| 1093 | |
| 1094 | // When a navigation occurs, we record its contents MIME type. It can be |
| 1095 | // used to check whether we can do something for some special contents. |
| 1096 | std::string contents_mime_type_; |
| 1097 | |
| 1098 | // Character encoding. |
| 1099 | std::string encoding_; |
| 1100 | |
| 1101 | // Object that holds any blocked TabContents spawned from this TabContents. |
| 1102 | BlockedContentContainer* blocked_contents_; |
| 1103 | |
| 1104 | // Should we block all child TabContents this attempts to spawn. |
| 1105 | bool all_contents_blocked_; |
| 1106 | |
| 1107 | // TODO(pkasting): Hack to try and fix Linux browser tests. |
| 1108 | bool dont_notify_render_view_; |
| 1109 | |
| 1110 | // True if this is a secure page which displayed insecure content. |
| 1111 | bool displayed_insecure_content_; |
| 1112 | |
| 1113 | // Data for shelves and stuff ------------------------------------------------ |
| 1114 | |
| 1115 | // Delegates for InfoBars associated with this TabContents. |
| 1116 | std::vector<InfoBarDelegate*> infobar_delegates_; |
| 1117 | |
| 1118 | // Data for app extensions --------------------------------------------------- |
| 1119 | |
| 1120 | // If non-null this tab is an app tab and this is the extension the tab was |
| 1121 | // created for. |
| 1122 | const Extension* extension_app_; |
| 1123 | |
| 1124 | // Icon for extension_app_ (if non-null) or extension_for_current_page_. |
| 1125 | SkBitmap extension_app_icon_; |
| 1126 | |
| 1127 | // Used for loading extension_app_icon_. |
| 1128 | scoped_ptr<ImageLoadingTracker> extension_app_image_loader_; |
| 1129 | |
| 1130 | // Data for misc internal state ---------------------------------------------- |
| 1131 | |
| 1132 | // See capturing_contents() above. |
| 1133 | bool capturing_contents_; |
| 1134 | |
| 1135 | // See getter above. |
| 1136 | bool is_being_destroyed_; |
| 1137 | |
| 1138 | // Indicates whether we should notify about disconnection of this |
| 1139 | // TabContents. This is used to ensure disconnection notifications only |
| 1140 | // happen if a connection notification has happened and that they happen only |
| 1141 | // once. |
| 1142 | bool notify_disconnection_; |
| 1143 | |
| 1144 | // Maps from handle to page_id. |
| 1145 | typedef std::map<FaviconService::Handle, int32> HistoryRequestMap; |
| 1146 | HistoryRequestMap history_requests_; |
| 1147 | |
| 1148 | #if defined(OS_WIN) |
| 1149 | // Handle to an event that's set when the page is showing a message box (or |
| 1150 | // equivalent constrained window). Plugin processes check this to know if |
| 1151 | // they should pump messages then. |
| 1152 | base::win::ScopedHandle message_box_active_; |
| 1153 | #endif |
| 1154 | |
| 1155 | // The time that the last javascript message was dismissed. |
| 1156 | base::TimeTicks last_javascript_message_dismissal_; |
| 1157 | |
| 1158 | // True if the user has decided to block future javascript messages. This is |
| 1159 | // reset on navigations to false on navigations. |
| 1160 | bool suppress_javascript_messages_; |
| 1161 | |
| 1162 | // Set to true when there is an active "before unload" dialog. When true, |
| 1163 | // we've forced the throbber to start in Navigate, and we need to remember to |
| 1164 | // turn it off in OnJavaScriptMessageBoxClosed if the navigation is canceled. |
| 1165 | bool is_showing_before_unload_dialog_; |
| 1166 | |
| 1167 | // Shows an info-bar to users when they search from a known search engine and |
| 1168 | // have never used the monibox for search before. |
| 1169 | scoped_ptr<OmniboxSearchHint> omnibox_search_hint_; |
| 1170 | |
| 1171 | // Settings that get passed to the renderer process. |
| 1172 | RendererPreferences renderer_preferences_; |
| 1173 | |
| 1174 | // If this tab was created from a renderer using window.open, this will be |
| 1175 | // non-NULL and represent the WebUI of the opening renderer. |
| 1176 | WebUITypeID opener_web_ui_type_; |
| 1177 | |
| 1178 | // The time that we started to create the new tab page. |
| 1179 | base::TimeTicks new_tab_start_time_; |
| 1180 | |
| 1181 | // The time that we started to close the tab. |
| 1182 | base::TimeTicks tab_close_start_time_; |
| 1183 | |
| 1184 | // The time that this tab was last selected. |
| 1185 | base::TimeTicks last_selected_time_; |
| 1186 | |
| 1187 | // Information about the language the page is in and has been translated to. |
| 1188 | LanguageState language_state_; |
| 1189 | |
| 1190 | // See description above setter. |
| 1191 | bool closed_by_user_gesture_; |
| 1192 | |
| 1193 | // Minimum/maximum zoom percent. |
| 1194 | int minimum_zoom_percent_; |
| 1195 | int maximum_zoom_percent_; |
| 1196 | // If true, the default zoom limits have been overriden for this tab, in which |
| 1197 | // case we don't want saved settings to apply to it and we don't want to |
| 1198 | // remember it. |
| 1199 | bool temporary_zoom_settings_; |
| 1200 | |
| 1201 | // A list of observers notified when page state changes. Weak references. |
| 1202 | ObserverList<TabContentsObserver> observers_; |
| 1203 | |
| 1204 | // Content restrictions, used to disable print/copy etc based on content's |
| 1205 | // (full-page plugins for now only) permissions. |
| 1206 | int content_restrictions_; |
| 1207 | |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 1208 | DISALLOW_COPY_AND_ASSIGN(TabContents); |
| 1209 | }; |
| 1210 | |
| 1211 | #endif // CONTENT_BROWSER_TAB_CONTENTS_TAB_CONTENTS_H_ |