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