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.
5 #ifndef CHROME_BROWSER_ANDROID_TAB_ANDROID_H_
6 #define CHROME_BROWSER_ANDROID_TAB_ANDROID_H_
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"
26 struct NavigateParams;
31 class ChromeWebContentsDelegateAndroid;
36 class ContentViewCore;
40 class TabAndroid : public CoreTabHelperDelegate,
41 public content::NotificationObserver {
43 // Convenience method to retrieve the Tab associated with the passed
44 // WebContents. Can return NULL.
45 static TabAndroid* FromWebContents(content::WebContents* web_contents);
47 // Returns the native TabAndroid stored in the Java TabBase represented by
49 static TabAndroid* GetNativeTab(JNIEnv* env, jobject obj);
51 TabAndroid(JNIEnv* env, jobject obj);
52 virtual ~TabAndroid();
54 base::android::ScopedJavaLocalRef<jobject> GetJavaObject();
56 // Return the WebContents, if any, currently owned by this TabAndroid.
57 content::WebContents* web_contents() const { return web_contents_.get(); }
59 // Return specific id information regarding this TabAndroid.
60 const SessionID& session_id() const { return session_tab_id_; }
61 int GetAndroidId() const;
62 int GetSyncId() const;
64 // Return the tab title.
65 base::string16 GetTitle() const;
67 // Return the tab url.
70 // Restore the tab if it was unloaded from memory.
71 bool RestoreIfNeeded();
73 // Helper methods to make it easier to access objects from the associated
74 // WebContents. Can return NULL.
75 content::ContentViewCore* GetContentViewCore() const;
76 Profile* GetProfile() const;
77 browser_sync::SyncedTabDelegate* GetSyncedTabDelegate() const;
79 void SetSyncId(int sync_id);
81 virtual void HandlePopupNavigation(chrome::NavigateParams* params);
83 virtual void OnReceivedHttpAuthRequest(jobject auth_handler,
84 const base::string16& host,
85 const base::string16& realm);
87 // Called when context menu option to create the bookmark shortcut on
88 // homescreen is called.
89 virtual void AddShortcutToBookmark(const GURL& url,
90 const base::string16& title,
91 const SkBitmap& skbitmap,
96 // Called when a bookmark node should be edited.
97 virtual void EditBookmark(int64 node_id,
98 const base::string16& node_title,
100 bool is_partner_bookmark);
102 // Called to notify that the new tab page has completely rendered.
103 virtual void OnNewTabPageReady();
105 // Called to determine if chrome://welcome should contain links to the terms
106 // of service and the privacy notice.
107 virtual bool ShouldWelcomePageLinkToTermsOfService();
109 // Register the Tab's native methods through JNI.
110 static bool RegisterTabAndroid(JNIEnv* env);
112 // CoreTabHelperDelegate ----------------------------------------------------
114 virtual void SwapTabContents(content::WebContents* old_contents,
115 content::WebContents* new_contents,
117 bool did_finish_load) OVERRIDE;
119 // NotificationObserver -----------------------------------------------------
120 virtual void Observe(int type,
121 const content::NotificationSource& source,
122 const content::NotificationDetails& details) OVERRIDE;
124 // Methods called from Java via JNI -----------------------------------------
126 virtual void Destroy(JNIEnv* env, jobject obj);
127 virtual void InitWebContents(JNIEnv* env,
130 jobject jcontent_view_core,
131 jobject jweb_contents_delegate,
132 jobject jcontext_menu_populator);
133 virtual void DestroyWebContents(JNIEnv* env,
135 jboolean delete_native);
136 base::android::ScopedJavaLocalRef<jobject> GetWebContents(JNIEnv* env,
138 base::android::ScopedJavaLocalRef<jobject> GetProfileAndroid(JNIEnv* env,
140 ToolbarModel::SecurityLevel GetSecurityLevel(JNIEnv* env, jobject obj);
141 void SetActiveNavigationEntryTitleForUrl(JNIEnv* env,
145 bool Print(JNIEnv* env, jobject obj);
148 JavaObjectWeakGlobalRef weak_java_tab_;
150 SessionID session_tab_id_;
152 content::NotificationRegistrar notification_registrar_;
154 scoped_ptr<content::WebContents> web_contents_;
155 scoped_ptr<chrome::android::ChromeWebContentsDelegateAndroid>
156 web_contents_delegate_;
158 scoped_ptr<browser_sync::SyncedTabDelegateAndroid> synced_tab_delegate_;
160 DISALLOW_COPY_AND_ASSIGN(TabAndroid);
163 #endif // CHROME_BROWSER_ANDROID_TAB_ANDROID_H_