Home | History | Annotate | Download | only in tab_model
      1 // Copyright (c) 2012 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_UI_ANDROID_TAB_MODEL_TAB_MODEL_H_
      6 #define CHROME_BROWSER_UI_ANDROID_TAB_MODEL_TAB_MODEL_H_
      7 
      8 #include "base/memory/scoped_ptr.h"
      9 #include "chrome/browser/sessions/session_id.h"
     10 #include "chrome/browser/sync/glue/synced_tab_delegate.h"
     11 #include "chrome/browser/ui/toolbar/toolbar_model.h"
     12 #include "chrome/browser/ui/toolbar/toolbar_model_delegate.h"
     13 #include "content/public/browser/notification_observer.h"
     14 #include "content/public/browser/notification_registrar.h"
     15 
     16 namespace browser_sync {
     17 class SyncedWindowDelegate;
     18 class SyncedWindowDelegateAndroid;
     19 class SyncedTabDelegate;
     20 }
     21 
     22 namespace content {
     23 class WebContents;
     24 }
     25 
     26 class Profile;
     27 
     28 // Abstract representation of a Tab Model for Android.  Since Android does
     29 // not use Browser/BrowserList, this is required to allow Chrome to interact
     30 // with Android's Tabs and Tab Model.
     31 class TabModel : public content::NotificationObserver,
     32                  public ToolbarModelDelegate {
     33  public:
     34   explicit TabModel(Profile* profile);
     35   // Deprecated: This constructor is deprecated and should be removed once
     36   // downstream Android uses new constructor. See crbug.com/159704.
     37   TabModel();
     38   virtual ~TabModel();
     39 
     40   // Implementation of ToolbarDelegate
     41   virtual content::WebContents* GetActiveWebContents() const OVERRIDE;
     42 
     43   virtual Profile* GetProfile() const;
     44   virtual bool IsOffTheRecord() const;
     45   virtual browser_sync::SyncedWindowDelegate* GetSyncedWindowDelegate() const;
     46   virtual SessionID::id_type GetSessionId() const;
     47 
     48   virtual int GetTabCount() const = 0;
     49   virtual int GetActiveIndex() const = 0;
     50   virtual content::WebContents* GetWebContentsAt(int index) const = 0;
     51   virtual browser_sync::SyncedTabDelegate* GetTabAt(int index) const = 0;
     52 
     53   // Used for restoring tabs from synced foreign sessions.
     54   virtual void CreateTab(content::WebContents* web_contents) = 0;
     55 
     56   // Used for creating a new tab with a given URL.
     57   virtual content::WebContents* CreateTabForTesting(const GURL& url) = 0;
     58 
     59   // Return true if we are currently restoring sessions asynchronously.
     60   virtual bool IsSessionRestoreInProgress() const = 0;
     61 
     62   virtual void OpenClearBrowsingData() const = 0;
     63 
     64   ToolbarModel::SecurityLevel GetSecurityLevelForCurrentTab();
     65 
     66   // Returns search terms extracted from the current url if possible.
     67   string16 GetSearchTermsForCurrentTab();
     68 
     69   // Returns the parameter that is used to trigger query extraction.
     70   std::string GetQueryExtractionParam();
     71 
     72   // Calls through to the ToolbarModel's GetCorpusNameForMobile -- see
     73   // comments in toolbar_model.h.
     74   string16 GetCorpusNameForCurrentTab();
     75 
     76  protected:
     77   // Instructs the TabModel to broadcast a notification that all tabs are now
     78   // loaded from storage.
     79   void BroadcastSessionRestoreComplete();
     80 
     81   ToolbarModel* GetToolbarModel();
     82 
     83  private:
     84   // Determines how TabModel will interact with the profile.
     85   virtual void Observe(int type,
     86                        const content::NotificationSource& source,
     87                        const content::NotificationDetails& details) OVERRIDE;
     88 
     89   // The profile associated with this TabModel.
     90   Profile* profile_;
     91 
     92   // Describes if this TabModel contains an off-the-record profile.
     93   bool is_off_the_record_;
     94 
     95   // The SyncedWindowDelegate associated with this TabModel.
     96   scoped_ptr<browser_sync::SyncedWindowDelegateAndroid> synced_window_delegate_;
     97 
     98   scoped_ptr<ToolbarModel> toolbar_model_;
     99 
    100   // Unique identifier of this TabModel for session restore. This id is only
    101   // unique within the current session, and is not guaranteed to be unique
    102   // across sessions.
    103   SessionID session_id_;
    104 
    105   // The Registrar used to register TabModel for notifications.
    106   content::NotificationRegistrar registrar_;
    107 
    108   DISALLOW_COPY_AND_ASSIGN(TabModel);
    109 };
    110 
    111 #endif  // CHROME_BROWSER_UI_ANDROID_TAB_MODEL_TAB_MODEL_H_
    112