Home | History | Annotate | Download | only in android
      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_ANDROID_TAB_ANDROID_H_
      6 #define CHROME_BROWSER_ANDROID_TAB_ANDROID_H_
      7 
      8 #include <jni.h>
      9 
     10 #include "base/android/jni_helper.h"
     11 #include "base/callback_forward.h"
     12 #include "base/strings/string16.h"
     13 #include "chrome/browser/sessions/session_id.h"
     14 #include "chrome/browser/ui/toolbar/toolbar_model.h"
     15 
     16 class GURL;
     17 class SkBitmap;
     18 
     19 namespace browser_sync {
     20 class SyncedTabDelegate;
     21 }
     22 
     23 namespace content {
     24 struct ContextMenuParams;
     25 class WebContents;
     26 }
     27 
     28 class TabAndroid {
     29  public:
     30   TabAndroid(JNIEnv* env, jobject obj);
     31 
     32   // Convenience method to retrieve the Tab associated with the passed
     33   // WebContents.  Can return NULL.
     34   static TabAndroid* FromWebContents(content::WebContents* web_contents);
     35 
     36   static TabAndroid* GetNativeTab(JNIEnv* env, jobject obj);
     37 
     38   // TODO(tedchoc): Make pure virtual once all derived classes can be updated.
     39   virtual content::WebContents* GetWebContents();
     40 
     41   virtual browser_sync::SyncedTabDelegate* GetSyncedTabDelegate() = 0;
     42 
     43   virtual ToolbarModel::SecurityLevel GetSecurityLevel();
     44 
     45   const SessionID& id() const { return tab_id_; }
     46 
     47   virtual void OnReceivedHttpAuthRequest(jobject auth_handler,
     48                                          const string16& host,
     49                                          const string16& realm) = 0;
     50 
     51   // Called to show the regular context menu that is triggered by a long press.
     52   virtual void ShowContextMenu(const content::ContextMenuParams& params) = 0;
     53 
     54   // Called to show a custom context menu. Used by the NTP.
     55   virtual void ShowCustomContextMenu(
     56       const content::ContextMenuParams& params,
     57       const base::Callback<void(int)>& callback) = 0;
     58 
     59   // Called when context menu option to create the bookmark shortcut on
     60   // homescreen is called.
     61   virtual void AddShortcutToBookmark(
     62       const GURL& url, const string16& title, const SkBitmap& skbitmap,
     63       int r_value, int g_value, int b_value) = 0;
     64 
     65   // Called when a bookmark node should be edited.
     66   virtual void EditBookmark(int64 node_id, bool is_folder) = 0;
     67 
     68   // Called to show the sync settings menu.
     69   virtual void ShowSyncSettings() = 0;
     70 
     71   // Called to show a dialog with the terms of service.
     72   virtual void ShowTermsOfService() = 0;
     73 
     74   // Called to determine if chrome://welcome should contain links to the terms
     75   // of service and the privacy notice.
     76   virtual bool ShouldWelcomePageLinkToTermsOfService() = 0;
     77 
     78   // Called to notify that the new tab page has completely rendered.
     79   virtual void OnNewTabPageReady() = 0;
     80 
     81   // Called when the common ExternalProtocolHandler wants to
     82   // run the external protocol dialog.
     83   // TODO(jknotten): Remove this method. Making it non-abstract, so that
     84   // derived classes may remove their implementation first.
     85   virtual void RunExternalProtocolDialog(const GURL& url);
     86 
     87   // Used by sync to get/set the sync id of tab.
     88   virtual int GetSyncId() const = 0;
     89   virtual void SetSyncId(int sync_id) = 0;
     90 
     91   static bool RegisterTabAndroid(JNIEnv* env);
     92 
     93  protected:
     94   virtual ~TabAndroid();
     95 
     96   static void InitTabHelpers(content::WebContents* web_contents);
     97 
     98   content::WebContents* InitWebContentsFromView(JNIEnv* env,
     99                                                 jobject content_view);
    100 
    101   SessionID tab_id_;
    102 
    103  private:
    104   JavaObjectWeakGlobalRef weak_java_tab_;
    105 };
    106 
    107 #endif  // CHROME_BROWSER_ANDROID_TAB_ANDROID_H_
    108