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
;
41 class PrerenderManager
;
44 class TabAndroid
: public CoreTabHelperDelegate
,
45 public content::NotificationObserver
{
48 #define DEFINE_TAB_LOAD_STATUS(name, value) name = value,
49 #include "chrome/browser/android/tab_load_status.h"
50 #undef DEFINE_TAB_LOAD_STATUS
53 // Convenience method to retrieve the Tab associated with the passed
54 // WebContents. Can return NULL.
55 static TabAndroid
* FromWebContents(content::WebContents
* web_contents
);
57 // Returns the native TabAndroid stored in the Java Tab represented by
59 static TabAndroid
* GetNativeTab(JNIEnv
* env
, jobject obj
);
61 // Function to attach helpers to the contentView.
62 static void AttachTabHelpers(content::WebContents
* web_contents
);
64 TabAndroid(JNIEnv
* env
, jobject obj
);
65 virtual ~TabAndroid();
67 base::android::ScopedJavaLocalRef
<jobject
> GetJavaObject();
69 // Return the WebContents, if any, currently owned by this TabAndroid.
70 content::WebContents
* web_contents() const { return web_contents_
.get(); }
72 // Return specific id information regarding this TabAndroid.
73 const SessionID
& session_id() const { return session_tab_id_
; }
74 int GetAndroidId() const;
75 int GetSyncId() const;
77 // Return the tab title.
78 base::string16
GetTitle() const;
80 // Return the tab url.
83 // Restore the tab if it was unloaded from memory.
84 bool RestoreIfNeeded();
86 // Helper methods to make it easier to access objects from the associated
87 // WebContents. Can return NULL.
88 content::ContentViewCore
* GetContentViewCore() const;
89 Profile
* GetProfile() const;
90 browser_sync::SyncedTabDelegate
* GetSyncedTabDelegate() const;
92 void SetWindowSessionID(SessionID::id_type window_id
);
93 void SetSyncId(int sync_id
);
95 virtual void HandlePopupNavigation(chrome::NavigateParams
* params
);
97 virtual void OnReceivedHttpAuthRequest(jobject auth_handler
,
98 const base::string16
& host
,
99 const base::string16
& realm
);
101 // Called when context menu option to create the bookmark shortcut on
102 // homescreen is called.
103 virtual void AddShortcutToBookmark(const GURL
& url
,
104 const base::string16
& title
,
105 const SkBitmap
& skbitmap
,
110 // Called when a bookmark node should be edited.
111 virtual void EditBookmark(int64 node_id
,
112 const base::string16
& node_title
,
114 bool is_partner_bookmark
);
116 // Called to notify that the new tab page has completely rendered.
117 virtual void OnNewTabPageReady();
119 // Called to determine if chrome://welcome should contain links to the terms
120 // of service and the privacy notice.
121 virtual bool ShouldWelcomePageLinkToTermsOfService();
123 bool HasPrerenderedUrl(GURL gurl
);
125 // CoreTabHelperDelegate ----------------------------------------------------
127 virtual void SwapTabContents(content::WebContents
* old_contents
,
128 content::WebContents
* new_contents
,
130 bool did_finish_load
) OVERRIDE
;
132 // NotificationObserver -----------------------------------------------------
133 virtual void Observe(int type
,
134 const content::NotificationSource
& source
,
135 const content::NotificationDetails
& details
) OVERRIDE
;
137 // Methods called from Java via JNI -----------------------------------------
139 virtual void Destroy(JNIEnv
* env
, jobject obj
);
140 virtual void InitWebContents(JNIEnv
* env
,
143 jobject jcontent_view_core
,
144 jobject jweb_contents_delegate
,
145 jobject jcontext_menu_populator
);
146 virtual void DestroyWebContents(JNIEnv
* env
,
148 jboolean delete_native
);
149 base::android::ScopedJavaLocalRef
<jobject
> GetWebContents(JNIEnv
* env
,
151 base::android::ScopedJavaLocalRef
<jobject
> GetProfileAndroid(JNIEnv
* env
,
153 virtual TabLoadStatus
LoadUrl(JNIEnv
* env
,
156 jstring j_extra_headers
,
157 jbyteArray j_post_data
,
158 jint page_transition
,
159 jstring j_referrer_url
,
160 jint referrer_policy
);
161 ToolbarModel::SecurityLevel
GetSecurityLevel(JNIEnv
* env
, jobject obj
);
162 void SetActiveNavigationEntryTitleForUrl(JNIEnv
* env
,
166 bool Print(JNIEnv
* env
, jobject obj
);
168 // Register the Tab's native methods through JNI.
169 static bool RegisterTabAndroid(JNIEnv
* env
);
172 prerender::PrerenderManager
* GetPrerenderManager() const;
174 JavaObjectWeakGlobalRef weak_java_tab_
;
176 // The identifier used by session restore for this tab.
177 SessionID session_tab_id_
;
179 // Identifier of the window the tab is in.
180 SessionID session_window_id_
;
182 content::NotificationRegistrar notification_registrar_
;
184 scoped_ptr
<content::WebContents
> web_contents_
;
185 scoped_ptr
<chrome::android::ChromeWebContentsDelegateAndroid
>
186 web_contents_delegate_
;
188 scoped_ptr
<browser_sync::SyncedTabDelegateAndroid
> synced_tab_delegate_
;
190 DISALLOW_COPY_AND_ASSIGN(TabAndroid
);
193 #endif // CHROME_BROWSER_ANDROID_TAB_ANDROID_H_