tab_contents.h revision 3f50c38dc070f4bb515c1b64450dae14f316474e
1// Copyright (c) 2011 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef 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/profiles/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 "base/string16.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/prefs/pref_change_registrar.h"
57#include "chrome/browser/renderer_host/render_view_host_delegate.h"
58#include "chrome/browser/tab_contents/constrained_window.h"
59#include "chrome/browser/tab_contents/language_state.h"
60#include "chrome/browser/tab_contents/navigation_controller.h"
61#include "chrome/browser/tab_contents/navigation_entry.h"
62#include "chrome/browser/tab_contents/page_navigator.h"
63#include "chrome/browser/tab_contents/render_view_host_manager.h"
64#include "chrome/browser/tab_contents/tab_specific_content_settings.h"
65#include "chrome/browser/ui/app_modal_dialogs/js_modal_dialog.h"
66#include "chrome/browser/ui/find_bar/find_bar_controller.h"
67#include "chrome/browser/ui/find_bar/find_notification_details.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
76#if defined(OS_WIN)
77#include "base/win/scoped_handle.h"
78#endif
79
80namespace gfx {
81class Rect;
82}
83
84namespace history {
85class HistoryAddPageArgs;
86}
87
88namespace printing {
89class PrintViewManager;
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;
108class PrerenderManager;
109struct RendererPreferences;
110class RenderViewHost;
111class SessionStorageNamespace;
112class SiteInstance;
113class SkBitmap;
114class TabContents;
115class TabContentsDelegate;
116class TabContentsSSLHelper;
117class TabContentsView;
118class URLPattern;
119struct ThumbnailScore;
120struct ViewHostMsg_DomMessage_Params;
121struct ViewHostMsg_FrameNavigate_Params;
122class WebNavigationObserver;
123struct WebPreferences;
124
125// Describes what goes in the main content area of a tab. TabContents is
126// the only type of TabContents, and these should be merged together.
127class TabContents : public PageNavigator,
128                    public NotificationObserver,
129                    public RenderViewHostDelegate,
130                    public RenderViewHostDelegate::BrowserIntegration,
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 string16 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  // Message handlers.
822  void OnDidStartProvisionalLoadForFrame(int64 frame_id,
823                                         bool main_frame,
824                                         const GURL& url);
825  void OnDidRedirectProvisionalLoad(int32 page_id,
826                                    const GURL& source_url,
827                                    const GURL& target_url);
828  void OnDidFailProvisionalLoadWithError(int64 frame_id,
829                                         bool main_frame,
830                                         int error_code,
831                                         const GURL& url,
832                                         bool showing_repost_interstitial);
833  void OnDidLoadResourceFromMemoryCache(const GURL& url,
834                                        const std::string& frame_origin,
835                                        const std::string& main_frame_origin,
836                                        const std::string& security_info);
837  void OnDidDisplayInsecureContent();
838  void OnDidRunInsecureContent(const std::string& security_origin);
839  void OnDocumentLoadedInFrame(int64 frame_id);
840  void OnDidFinishLoad(int64 frame_id);
841
842  // Changes the IsLoading state and notifies delegate as needed
843  // |details| is used to provide details on the load that just finished
844  // (but can be null if not applicable). Can be overridden.
845  void SetIsLoading(bool is_loading,
846                    LoadNotificationDetails* details);
847
848  // Adds the incoming |new_contents| to the |blocked_contents_| container.
849  void AddPopup(TabContents* new_contents,
850                const gfx::Rect& initial_pos);
851
852  // Called by derived classes to indicate that we're no longer waiting for a
853  // response. This won't actually update the throbber, but it will get picked
854  // up at the next animation step if the throbber is going.
855  void SetNotWaitingForResponse() { waiting_for_response_ = false; }
856
857  ConstrainedWindowList child_windows_;
858
859  // Expires InfoBars that need to be expired, according to the state carried
860  // in |details|, in response to a new NavigationEntry being committed (the
861  // user navigated to another page).
862  void ExpireInfoBars(
863      const NavigationController::LoadCommittedDetails& details);
864
865  // Returns the DOMUI for the current state of the tab. This will either be
866  // the pending DOMUI, the committed DOMUI, or NULL.
867  DOMUI* GetDOMUIForCurrentState();
868
869  // Navigation helpers --------------------------------------------------------
870  //
871  // These functions are helpers for Navigate() and DidNavigate().
872
873  // Handles post-navigation tasks in DidNavigate AFTER the entry has been
874  // committed to the navigation controller. Note that the navigation entry is
875  // not provided since it may be invalid/changed after being committed. The
876  // current navigation entry is in the NavigationController at this point.
877  void DidNavigateMainFramePostCommit(
878      const NavigationController::LoadCommittedDetails& details,
879      const ViewHostMsg_FrameNavigate_Params& params);
880  void DidNavigateAnyFramePostCommit(
881      RenderViewHost* render_view_host,
882      const NavigationController::LoadCommittedDetails& details,
883      const ViewHostMsg_FrameNavigate_Params& params);
884
885  // Closes all constrained windows.
886  void CloseConstrainedWindows();
887
888  // Updates the starred state from the bookmark bar model. If the state has
889  // changed, the delegate is notified.
890  void UpdateStarredStateForCurrentURL();
891
892  // Send the alternate error page URL to the renderer. This method is virtual
893  // so special html pages can override this (e.g., the new tab page).
894  virtual void UpdateAlternateErrorPageURL();
895
896  // Send webkit specific settings to the renderer.
897  void UpdateWebPreferences();
898
899  // Instruct the renderer to update the zoom level.
900  void UpdateZoomLevel();
901
902  // If our controller was restored and the page id is > than the site
903  // instance's page id, the site instances page id is updated as well as the
904  // renderers max page id.
905  void UpdateMaxPageIDIfNecessary(SiteInstance* site_instance,
906                                  RenderViewHost* rvh);
907
908  // Returns the history::HistoryAddPageArgs to use for adding a page to
909  // history.
910  scoped_refptr<history::HistoryAddPageArgs> CreateHistoryAddPageArgs(
911      const GURL& virtual_url,
912      const NavigationController::LoadCommittedDetails& details,
913      const ViewHostMsg_FrameNavigate_Params& params);
914
915  // Saves the given title to the navigation entry and does associated work. It
916  // will update history and the view for the new title, and also synthesize
917  // titles for file URLs that have none (so we require that the URL of the
918  // entry already be set).
919  //
920  // This is used as the backend for state updates, which include a new title,
921  // or the dedicated set title message. It returns true if the new title is
922  // different and was therefore updated.
923  bool UpdateTitleForEntry(NavigationEntry* entry, const std::wstring& title);
924
925  // Causes the TabContents to navigate in the right renderer to |entry|, which
926  // must be already part of the entries in the navigation controller.
927  // This does not change the NavigationController state.
928  bool NavigateToEntry(const NavigationEntry& entry,
929                       NavigationController::ReloadType reload_type);
930
931  // Misc non-view stuff -------------------------------------------------------
932
933  // Helper functions for sending notifications.
934  void NotifySwapped();
935  void NotifyConnected();
936  void NotifyDisconnected();
937
938  // If params has a searchable form, this tries to create a new keyword.
939  void GenerateKeywordIfNecessary(
940      const ViewHostMsg_FrameNavigate_Params& params);
941
942  // TabSpecificContentSettings::Delegate implementation.
943  virtual void OnContentSettingsAccessed(bool content_was_blocked);
944
945  // RenderViewHostDelegate ----------------------------------------------------
946
947  // RenderViewHostDelegate::BrowserIntegration implementation.
948  virtual void OnUserGesture();
949  virtual void OnFindReply(int request_id,
950                           int number_of_matches,
951                           const gfx::Rect& selection_rect,
952                           int active_match_ordinal,
953                           bool final_update);
954  virtual void GoToEntryAtOffset(int offset);
955  virtual void OnMissingPluginStatus(int status);
956  virtual void OnCrashedPlugin(const FilePath& plugin_path);
957  virtual void OnCrashedWorker();
958  virtual void OnDidGetApplicationInfo(int32 page_id,
959                                       const WebApplicationInfo& info);
960  virtual void OnInstallApplication(const WebApplicationInfo& info);
961  virtual void OnBlockedOutdatedPlugin(const string16& name,
962                                       const GURL& update_url);
963  virtual void OnPageContents(const GURL& url,
964                              int renderer_process_id,
965                              int32 page_id,
966                              const string16& contents,
967                              const std::string& language,
968                              bool page_translatable);
969  virtual void OnPageTranslated(int32 page_id,
970                                const std::string& original_lang,
971                                const std::string& translated_lang,
972                                TranslateErrors::Type error_type);
973  virtual void OnSetSuggestions(int32 page_id,
974                                const std::vector<std::string>& suggestions);
975  virtual void OnInstantSupportDetermined(int32 page_id, bool result);
976
977  // RenderViewHostDelegate implementation.
978  virtual RenderViewHostDelegate::View* GetViewDelegate();
979  virtual RenderViewHostDelegate::RendererManagement*
980      GetRendererManagementDelegate();
981  virtual RenderViewHostDelegate::BrowserIntegration*
982      GetBrowserIntegrationDelegate();
983  virtual RenderViewHostDelegate::ContentSettings* GetContentSettingsDelegate();
984  virtual RenderViewHostDelegate::Save* GetSaveDelegate();
985  virtual RenderViewHostDelegate::Printing* GetPrintingDelegate();
986  virtual RenderViewHostDelegate::FavIcon* GetFavIconDelegate();
987  virtual RenderViewHostDelegate::Autocomplete* GetAutocompleteDelegate();
988  virtual RenderViewHostDelegate::AutoFill* GetAutoFillDelegate();
989  virtual RenderViewHostDelegate::SSL* GetSSLDelegate();
990  virtual RenderViewHostDelegate::FileSelect* GetFileSelectDelegate();
991  virtual AutomationResourceRoutingDelegate*
992      GetAutomationResourceRoutingDelegate();
993  virtual TabContents* GetAsTabContents();
994  virtual bool OnMessageReceived(const IPC::Message& message);
995  virtual ViewType::Type GetRenderViewType() const;
996  virtual int GetBrowserWindowID() const;
997  virtual void RenderViewCreated(RenderViewHost* render_view_host);
998  virtual void RenderViewReady(RenderViewHost* render_view_host);
999  virtual void RenderViewGone(RenderViewHost* render_view_host,
1000                              base::TerminationStatus status,
1001                              int error_code);
1002  virtual void RenderViewDeleted(RenderViewHost* render_view_host);
1003  virtual void DidNavigate(RenderViewHost* render_view_host,
1004                           const ViewHostMsg_FrameNavigate_Params& params);
1005  virtual void UpdateState(RenderViewHost* render_view_host,
1006                           int32 page_id,
1007                           const std::string& state);
1008  virtual void UpdateTitle(RenderViewHost* render_view_host,
1009                           int32 page_id,
1010                           const std::wstring& title);
1011  virtual void UpdateEncoding(RenderViewHost* render_view_host,
1012                              const std::string& encoding);
1013  virtual void UpdateTargetURL(int32 page_id, const GURL& url);
1014  virtual void UpdateThumbnail(const GURL& url,
1015                               const SkBitmap& bitmap,
1016                               const ThumbnailScore& score);
1017  virtual void UpdateInspectorSetting(const std::string& key,
1018                                      const std::string& value);
1019  virtual void ClearInspectorSettings();
1020  virtual void Close(RenderViewHost* render_view_host);
1021  virtual void RequestMove(const gfx::Rect& new_bounds);
1022  virtual void DidStartLoading();
1023  virtual void DidStopLoading();
1024  virtual void DidChangeLoadProgress(double progress);
1025  virtual void DocumentOnLoadCompletedInMainFrame(
1026      RenderViewHost* render_view_host,
1027      int32 page_id);
1028  virtual void RequestOpenURL(const GURL& url, const GURL& referrer,
1029                              WindowOpenDisposition disposition);
1030  virtual void DomOperationResponse(const std::string& json_string,
1031                                    int automation_id);
1032  virtual void ProcessDOMUIMessage(const ViewHostMsg_DomMessage_Params& params);
1033  virtual void ProcessExternalHostMessage(const std::string& message,
1034                                          const std::string& origin,
1035                                          const std::string& target);
1036  virtual void RunJavaScriptMessage(const std::wstring& message,
1037                                    const std::wstring& default_prompt,
1038                                    const GURL& frame_url,
1039                                    const int flags,
1040                                    IPC::Message* reply_msg,
1041                                    bool* did_suppress_message);
1042  virtual void RunBeforeUnloadConfirm(const std::wstring& message,
1043                                      IPC::Message* reply_msg);
1044  virtual void ShowModalHTMLDialog(const GURL& url, int width, int height,
1045                                   const std::string& json_arguments,
1046                                   IPC::Message* reply_msg);
1047  virtual void PasswordFormsFound(
1048      const std::vector<webkit_glue::PasswordForm>& forms);
1049  virtual void PasswordFormsVisible(
1050      const std::vector<webkit_glue::PasswordForm>& visible_forms);
1051  virtual void PageHasOSDD(RenderViewHost* render_view_host,
1052                           int32 page_id,
1053                           const GURL& url,
1054                           const ViewHostMsg_PageHasOSDD_Type& provider_type);
1055  virtual GURL GetAlternateErrorPageURL() const;
1056  virtual RendererPreferences GetRendererPrefs(Profile* profile) const;
1057  virtual WebPreferences GetWebkitPrefs();
1058  virtual void OnIgnoredUIEvent();
1059  virtual void OnJSOutOfMemory();
1060  virtual void OnCrossSiteResponse(int new_render_process_host_id,
1061                                   int new_request_id);
1062  virtual void RendererUnresponsive(RenderViewHost* render_view_host,
1063                                    bool is_during_unload);
1064  virtual void RendererResponsive(RenderViewHost* render_view_host);
1065  virtual void LoadStateChanged(const GURL& url, net::LoadState load_state,
1066                                uint64 upload_position, uint64 upload_size);
1067  virtual bool IsExternalTabContainer() const;
1068  virtual void DidInsertCSS();
1069  virtual void FocusedNodeChanged(bool is_editable_node);
1070  virtual void UpdateZoomLimits(int minimum_percent,
1071                                int maximum_percent,
1072                                bool remember);
1073  virtual void UpdateContentRestrictions(int restrictions);
1074
1075  // RenderViewHostManager::Delegate -------------------------------------------
1076
1077  // Blocks/unblocks interaction with renderer process.
1078  void BlockTabContent(bool blocked);
1079
1080  virtual void BeforeUnloadFiredFromRenderManager(
1081      bool proceed,
1082      bool* proceed_to_fire_unload);
1083  virtual void DidStartLoadingFromRenderManager(
1084      RenderViewHost* render_view_host);
1085  virtual void RenderViewGoneFromRenderManager(
1086      RenderViewHost* render_view_host);
1087  virtual void UpdateRenderViewSizeForRenderManager();
1088  virtual void NotifySwappedFromRenderManager();
1089  virtual NavigationController& GetControllerForRenderManager();
1090  virtual DOMUI* CreateDOMUIForRenderManager(const GURL& url);
1091  virtual NavigationEntry* GetLastCommittedNavigationEntryForRenderManager();
1092
1093  // Initializes the given renderer if necessary and creates the view ID
1094  // corresponding to this view host. If this method is not called and the
1095  // process is not shared, then the TabContents will act as though the renderer
1096  // is not running (i.e., it will render "sad tab"). This method is
1097  // automatically called from LoadURL.
1098  //
1099  // If you are attaching to an already-existing RenderView, you should call
1100  // InitWithExistingID.
1101  virtual bool CreateRenderViewForRenderManager(
1102      RenderViewHost* render_view_host);
1103
1104  // NotificationObserver ------------------------------------------------------
1105
1106  virtual void Observe(NotificationType type,
1107                       const NotificationSource& source,
1108                       const NotificationDetails& details);
1109
1110  // App extensions related methods:
1111
1112  // Returns the first extension whose extent contains |url|.
1113  const Extension* GetExtensionContaining(const GURL& url);
1114
1115  // Resets app_icon_ and if |extension| is non-null creates a new
1116  // ImageLoadingTracker to load the extension's image.
1117  void UpdateExtensionAppIcon(const Extension* extension);
1118
1119  // ImageLoadingTracker::Observer.
1120  virtual void OnImageLoaded(SkBitmap* image, ExtensionResource resource,
1121                             int index);
1122
1123  // Data for core operation ---------------------------------------------------
1124
1125  // Delegate for notifying our owner about stuff. Not owned by us.
1126  TabContentsDelegate* delegate_;
1127
1128  // Handles the back/forward list and loading.
1129  NavigationController controller_;
1130
1131  // The corresponding view.
1132  scoped_ptr<TabContentsView> view_;
1133
1134  // Helper classes ------------------------------------------------------------
1135
1136  // Manages creation and swapping of render views.
1137  RenderViewHostManager render_manager_;
1138
1139  // Stores random bits of data for others to associate with this object.
1140  PropertyBag property_bag_;
1141
1142  // Registers and unregisters us for notifications.
1143  NotificationRegistrar registrar_;
1144
1145  // Registers and unregisters for pref notifications.
1146  PrefChangeRegistrar pref_change_registrar_;
1147
1148  // Handles print preview and print job for this contents.
1149  scoped_ptr<printing::PrintViewManager> printing_;
1150
1151  // SavePackage, lazily created.
1152  scoped_refptr<SavePackage> save_package_;
1153
1154  // AutocompleteHistoryManager, lazily created.
1155  scoped_ptr<AutocompleteHistoryManager> autocomplete_history_manager_;
1156
1157  // AutoFillManager, lazily created.
1158  scoped_ptr<AutoFillManager> autofill_manager_;
1159
1160  // PluginInstaller, lazily created.
1161  scoped_ptr<PluginInstaller> plugin_installer_;
1162
1163  // TabContentsSSLHelper, lazily created.
1164  scoped_ptr<TabContentsSSLHelper> ssl_helper_;
1165
1166  // FileSelectHelper, lazily created.
1167  scoped_ptr<FileSelectHelper> file_select_helper_;
1168
1169  // Handles drag and drop event forwarding to extensions.
1170  BookmarkDrag* bookmark_drag_;
1171
1172  // Handles downloading favicons.
1173  FavIconHelper fav_icon_helper_;
1174
1175  // Cached web app info data.
1176  WebApplicationInfo web_app_info_;
1177
1178  // Cached web app icon.
1179  SkBitmap app_icon_;
1180
1181  // RenderViewHost::ContentSettingsDelegate.
1182  scoped_ptr<TabSpecificContentSettings> content_settings_delegate_;
1183
1184  // Data for loading state ----------------------------------------------------
1185
1186  // Indicates whether we're currently loading a resource.
1187  bool is_loading_;
1188
1189  // Indicates if the tab is considered crashed.
1190  base::TerminationStatus crashed_status_;
1191  int crashed_error_code_;
1192
1193  // See waiting_for_response() above.
1194  bool waiting_for_response_;
1195
1196  // Indicates the largest PageID we've seen.  This field is ignored if we are
1197  // a TabContents, in which case the max page ID is stored separately with
1198  // each SiteInstance.
1199  // TODO(brettw) this seems like it can be removed according to the comment.
1200  int32 max_page_id_;
1201
1202  // System time at which the current load was started.
1203  base::TimeTicks current_load_start_;
1204
1205  // The current load state and the URL associated with it.
1206  net::LoadState load_state_;
1207  string16 load_state_host_;
1208  // Upload progress, for displaying in the status bar.
1209  // Set to zero when there is no significant upload happening.
1210  uint64 upload_size_;
1211  uint64 upload_position_;
1212
1213  // Data for current page -----------------------------------------------------
1214
1215  // Whether we have a (non-empty) title for the current page.
1216  // Used to prevent subsequent title updates from affecting history. This
1217  // prevents some weirdness because some AJAXy apps use titles for status
1218  // messages.
1219  bool received_page_title_;
1220
1221  // Whether the current URL is starred
1222  bool is_starred_;
1223
1224  // When a navigation occurs, we record its contents MIME type. It can be
1225  // used to check whether we can do something for some special contents.
1226  std::string contents_mime_type_;
1227
1228  // Character encoding.
1229  std::string encoding_;
1230
1231  // Object that holds any blocked TabContents spawned from this TabContents.
1232  BlockedContentContainer* blocked_contents_;
1233
1234  // Should we block all child TabContents this attempts to spawn.
1235  bool all_contents_blocked_;
1236
1237  // TODO(pkasting): Hack to try and fix Linux browser tests.
1238  bool dont_notify_render_view_;
1239
1240  // True if this is a secure page which displayed insecure content.
1241  bool displayed_insecure_content_;
1242
1243  // Data for shelves and stuff ------------------------------------------------
1244
1245  // Delegates for InfoBars associated with this TabContents.
1246  std::vector<InfoBarDelegate*> infobar_delegates_;
1247
1248  // Data for find in page -----------------------------------------------------
1249
1250  // TODO(brettw) this should be separated into a helper class.
1251
1252  // Each time a search request comes in we assign it an id before passing it
1253  // over the IPC so that when the results come in we can evaluate whether we
1254  // still care about the results of the search (in some cases we don't because
1255  // the user has issued a new search).
1256  static int find_request_id_counter_;
1257
1258  // True if the Find UI is active for this Tab.
1259  bool find_ui_active_;
1260
1261  // True if a Find operation was aborted. This can happen if the Find box is
1262  // closed or if the search term inside the Find box is erased while a search
1263  // is in progress. This can also be set if a page has been reloaded, and will
1264  // on FindNext result in a full Find operation so that the highlighting for
1265  // inactive matches can be repainted.
1266  bool find_op_aborted_;
1267
1268  // This variable keeps track of what the most recent request id is.
1269  int current_find_request_id_;
1270
1271  // The current string we are/just finished searching for. This is used to
1272  // figure out if this is a Find or a FindNext operation (FindNext should not
1273  // increase the request id).
1274  string16 find_text_;
1275
1276  // The string we searched for before |find_text_|.
1277  string16 previous_find_text_;
1278
1279  // Whether the last search was case sensitive or not.
1280  bool last_search_case_sensitive_;
1281
1282  // The last find result. This object contains details about the number of
1283  // matches, the find selection rectangle, etc. The UI can access this
1284  // information to build its presentation.
1285  FindNotificationDetails last_search_result_;
1286
1287  // Data for app extensions ---------------------------------------------------
1288
1289  // If non-null this tab is an app tab and this is the extension the tab was
1290  // created for.
1291  const Extension* extension_app_;
1292
1293  // Icon for extension_app_ (if non-null) or extension_for_current_page_.
1294  SkBitmap extension_app_icon_;
1295
1296  // Used for loading extension_app_icon_.
1297  scoped_ptr<ImageLoadingTracker> extension_app_image_loader_;
1298
1299  // Data for misc internal state ----------------------------------------------
1300
1301  // See capturing_contents() above.
1302  bool capturing_contents_;
1303
1304  // See getter above.
1305  bool is_being_destroyed_;
1306
1307  // Indicates whether we should notify about disconnection of this
1308  // TabContents. This is used to ensure disconnection notifications only
1309  // happen if a connection notification has happened and that they happen only
1310  // once.
1311  bool notify_disconnection_;
1312
1313  // Maps from handle to page_id.
1314  typedef std::map<FaviconService::Handle, int32> HistoryRequestMap;
1315  HistoryRequestMap history_requests_;
1316
1317#if defined(OS_WIN)
1318  // Handle to an event that's set when the page is showing a message box (or
1319  // equivalent constrained window).  Plugin processes check this to know if
1320  // they should pump messages then.
1321  base::win::ScopedHandle message_box_active_;
1322#endif
1323
1324  // The time that the last javascript message was dismissed.
1325  base::TimeTicks last_javascript_message_dismissal_;
1326
1327  // True if the user has decided to block future javascript messages. This is
1328  // reset on navigations to false on navigations.
1329  bool suppress_javascript_messages_;
1330
1331  // Set to true when there is an active "before unload" dialog.  When true,
1332  // we've forced the throbber to start in Navigate, and we need to remember to
1333  // turn it off in OnJavaScriptMessageBoxClosed if the navigation is canceled.
1334  bool is_showing_before_unload_dialog_;
1335
1336  // Shows an info-bar to users when they search from a known search engine and
1337  // have never used the monibox for search before.
1338  scoped_ptr<OmniboxSearchHint> omnibox_search_hint_;
1339
1340  // Settings that get passed to the renderer process.
1341  RendererPreferences renderer_preferences_;
1342
1343  // If this tab was created from a renderer using window.open, this will be
1344  // non-NULL and represent the DOMUI of the opening renderer.
1345  DOMUITypeID opener_dom_ui_type_;
1346
1347  // The time that we started to create the new tab page.
1348  base::TimeTicks new_tab_start_time_;
1349
1350  // The time that we started to close the tab.
1351  base::TimeTicks tab_close_start_time_;
1352
1353  // The time that this tab was last selected.
1354  base::TimeTicks last_selected_time_;
1355
1356  // Information about the language the page is in and has been translated to.
1357  LanguageState language_state_;
1358
1359  // See description above setter.
1360  bool closed_by_user_gesture_;
1361
1362  // Minimum/maximum zoom percent.
1363  int minimum_zoom_percent_;
1364  int maximum_zoom_percent_;
1365  // If true, the default zoom limits have been overriden for this tab, in which
1366  // case we don't want saved settings to apply to it and we don't want to
1367  // remember it.
1368  bool temporary_zoom_settings_;
1369
1370  // A list of observers notified when page state changes. Weak references.
1371  ObserverList<WebNavigationObserver> web_navigation_observers_;
1372
1373  // Content restrictions, used to disable print/copy etc based on content's
1374  // (full-page plugins for now only) permissions.
1375  int content_restrictions_;
1376
1377  // ---------------------------------------------------------------------------
1378
1379  DISALLOW_COPY_AND_ASSIGN(TabContents);
1380};
1381
1382#endif // !ANDROID
1383
1384#endif  // CHROME_BROWSER_TAB_CONTENTS_TAB_CONTENTS_H_
1385