• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/memory/scoped_ptr.h"
13 #include "base/strings/string16.h"
14 #include "chrome/browser/sessions/session_id.h"
15 #include "chrome/browser/sync/glue/synced_tab_delegate_android.h"
16 #include "chrome/browser/ui/tab_contents/core_tab_helper_delegate.h"
17 #include "chrome/browser/ui/toolbar/toolbar_model.h"
18 #include "content/public/browser/notification_observer.h"
19 #include "content/public/browser/notification_registrar.h"
20 
21 class GURL;
22 class Profile;
23 class SkBitmap;
24 
25 namespace chrome {
26 struct NavigateParams;
27 }
28 
29 namespace chrome {
30 namespace android {
31 class ChromeWebContentsDelegateAndroid;
32 }
33 }
34 
35 namespace content {
36 class ContentViewCore;
37 class WebContents;
38 }
39 
40 class TabAndroid : public CoreTabHelperDelegate,
41                    public content::NotificationObserver {
42  public:
43   // Convenience method to retrieve the Tab associated with the passed
44   // WebContents.  Can return NULL.
45   static TabAndroid* FromWebContents(content::WebContents* web_contents);
46 
47   // Returns the native TabAndroid stored in the Java TabBase represented by
48   // |obj|.
49   static TabAndroid* GetNativeTab(JNIEnv* env, jobject obj);
50 
51   TabAndroid(JNIEnv* env, jobject obj);
52 
53   // Return the WebContents, if any, currently owned by this TabAndroid.
web_contents()54   content::WebContents* web_contents() const { return web_contents_.get(); }
55 
56   // Return specific id information regarding this TabAndroid.
session_id()57   const SessionID& session_id() const { return session_tab_id_; }
58   int GetAndroidId() const;
59   int GetSyncId() const;
60 
61   // Return the tab title.
62   base::string16 GetTitle() const;
63 
64   // Return the tab url.
65   GURL GetURL() const;
66 
67   // Restore the tab if it was unloaded from memory.
68   bool RestoreIfNeeded();
69 
70   // Helper methods to make it easier to access objects from the associated
71   // WebContents.  Can return NULL.
72   content::ContentViewCore* GetContentViewCore() const;
73   Profile* GetProfile() const;
74   browser_sync::SyncedTabDelegate* GetSyncedTabDelegate() const;
75 
76   void SetSyncId(int sync_id);
77 
78   virtual void HandlePopupNavigation(chrome::NavigateParams* params) = 0;
79 
80   virtual void OnReceivedHttpAuthRequest(jobject auth_handler,
81                                          const base::string16& host,
82                                          const base::string16& realm) = 0;
83 
84   // Called when context menu option to create the bookmark shortcut on
85   // homescreen is called.
86   virtual void AddShortcutToBookmark(
87       const GURL& url, const base::string16& title, const SkBitmap& skbitmap,
88       int r_value, int g_value, int b_value) = 0;
89 
90   // Called when a bookmark node should be edited.
91   virtual void EditBookmark(int64 node_id,
92                             const base::string16& node_title,
93                             bool is_folder,
94                             bool is_partner_bookmark) = 0;
95 
96   // Called to determine if chrome://welcome should contain links to the terms
97   // of service and the privacy notice.
98   virtual bool ShouldWelcomePageLinkToTermsOfService() = 0;
99 
100   // Called to notify that the new tab page has completely rendered.
101   virtual void OnNewTabPageReady() = 0;
102 
103   static void InitTabHelpers(content::WebContents* web_contents);
104 
105   // Register the Tab's native methods through JNI.
106   static bool RegisterTabAndroid(JNIEnv* env);
107 
108   // CoreTabHelperDelegate ----------------------------------------------------
109 
110   virtual void SwapTabContents(content::WebContents* old_contents,
111                                content::WebContents* new_contents) OVERRIDE;
112 
113   // NotificationObserver -----------------------------------------------------
114   virtual void Observe(int type,
115                        const content::NotificationSource& source,
116                        const content::NotificationDetails& details) OVERRIDE;
117 
118   // Methods called from Java via JNI -----------------------------------------
119 
120   virtual void InitWebContents(JNIEnv* env,
121                                jobject obj,
122                                jboolean incognito,
123                                jobject jcontent_view_core,
124                                jobject jweb_contents_delegate,
125                                jobject jcontext_menu_populator);
126 
127   virtual void DestroyWebContents(JNIEnv* env,
128                                   jobject obj,
129                                   jboolean delete_native);
130   base::android::ScopedJavaLocalRef<jobject> GetProfileAndroid(JNIEnv* env,
131                                                                jobject obj);
132   ToolbarModel::SecurityLevel GetSecurityLevel(JNIEnv* env, jobject obj);
133   void SetActiveNavigationEntryTitleForUrl(JNIEnv* env,
134                                            jobject obj,
135                                            jstring jurl,
136                                            jstring jtitle);
137   bool Print(JNIEnv* env, jobject obj);
138 
139  protected:
140   virtual ~TabAndroid();
141 
142  private:
143   JavaObjectWeakGlobalRef weak_java_tab_;
144 
145   SessionID session_tab_id_;
146 
147   content::NotificationRegistrar notification_registrar_;
148 
149   scoped_ptr<content::WebContents> web_contents_;
150   scoped_ptr<chrome::android::ChromeWebContentsDelegateAndroid>
151       web_contents_delegate_;
152 
153   scoped_ptr<browser_sync::SyncedTabDelegateAndroid> synced_tab_delegate_;
154 
155   DISALLOW_COPY_AND_ASSIGN(TabAndroid);
156 };
157 
158 #endif  // CHROME_BROWSER_ANDROID_TAB_ANDROID_H_
159