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