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_weak_ref.h"
11 #include "base/callback_forward.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/strings/string16.h"
14 #include "chrome/browser/sync/glue/synced_tab_delegate_android.h"
15 #include "chrome/browser/ui/search/search_tab_helper_delegate.h"
16 #include "chrome/browser/ui/tab_contents/core_tab_helper_delegate.h"
17 #include "chrome/browser/ui/toolbar/toolbar_model.h"
18 #include "components/sessions/session_id.h"
19 #include "content/public/browser/notification_observer.h"
20 #include "content/public/browser/notification_registrar.h"
27 struct NavigateParams
;
32 class ChromeWebContentsDelegateAndroid
;
37 class ContentViewCore
;
42 class PrerenderManager
;
45 class TabAndroid
: public CoreTabHelperDelegate
,
46 public SearchTabHelperDelegate
,
47 public content::NotificationObserver
{
50 #define DEFINE_TAB_LOAD_STATUS(name, value) name = value,
51 #include "chrome/browser/android/tab_load_status.h"
52 #undef DEFINE_TAB_LOAD_STATUS
55 // Convenience method to retrieve the Tab associated with the passed
56 // WebContents. Can return NULL.
57 static TabAndroid
* FromWebContents(content::WebContents
* web_contents
);
59 // Returns the native TabAndroid stored in the Java Tab represented by
61 static TabAndroid
* GetNativeTab(JNIEnv
* env
, jobject obj
);
63 // Function to attach helpers to the contentView.
64 static void AttachTabHelpers(content::WebContents
* web_contents
);
66 TabAndroid(JNIEnv
* env
, jobject obj
);
67 virtual ~TabAndroid();
69 base::android::ScopedJavaLocalRef
<jobject
> GetJavaObject();
71 // Return the WebContents, if any, currently owned by this TabAndroid.
72 content::WebContents
* web_contents() const { return web_contents_
.get(); }
74 // Return specific id information regarding this TabAndroid.
75 const SessionID
& session_id() const { return session_tab_id_
; }
76 int GetAndroidId() const;
77 int GetSyncId() const;
79 // Return the tab title.
80 base::string16
GetTitle() const;
82 // Return the tab url.
85 // Load the tab if it was unloaded from memory.
88 // Helper methods to make it easier to access objects from the associated
89 // WebContents. Can return NULL.
90 content::ContentViewCore
* GetContentViewCore() const;
91 Profile
* GetProfile() const;
92 browser_sync::SyncedTabDelegate
* GetSyncedTabDelegate() const;
94 void SetWindowSessionID(SessionID::id_type window_id
);
95 void SetSyncId(int sync_id
);
97 virtual void HandlePopupNavigation(chrome::NavigateParams
* params
);
99 // Called to determine if chrome://welcome should contain links to the terms
100 // of service and the privacy notice.
101 virtual bool ShouldWelcomePageLinkToTermsOfService();
103 bool HasPrerenderedUrl(GURL gurl
);
105 void MakeLoadURLParams(
106 chrome::NavigateParams
* params
,
107 content::NavigationController::LoadURLParams
* load_url_params
);
109 // CoreTabHelperDelegate ----------------------------------------------------
111 virtual void SwapTabContents(content::WebContents
* old_contents
,
112 content::WebContents
* new_contents
,
114 bool did_finish_load
) OVERRIDE
;
116 // Overridden from SearchTabHelperDelegate:
117 virtual void OnWebContentsInstantSupportDisabled(
118 const content::WebContents
* web_contents
) OVERRIDE
;
120 // NotificationObserver -----------------------------------------------------
121 virtual void Observe(int type
,
122 const content::NotificationSource
& source
,
123 const content::NotificationDetails
& details
) OVERRIDE
;
125 // Methods called from Java via JNI -----------------------------------------
127 virtual void Destroy(JNIEnv
* env
, jobject obj
);
128 virtual void InitWebContents(JNIEnv
* env
,
131 jobject jcontent_view_core
,
132 jobject jweb_contents_delegate
,
133 jobject jcontext_menu_populator
);
134 virtual void DestroyWebContents(JNIEnv
* env
,
136 jboolean delete_native
);
137 base::android::ScopedJavaLocalRef
<jobject
> GetProfileAndroid(JNIEnv
* env
,
139 virtual TabLoadStatus
LoadUrl(JNIEnv
* env
,
142 jstring j_extra_headers
,
143 jbyteArray j_post_data
,
144 jint page_transition
,
145 jstring j_referrer_url
,
146 jint referrer_policy
,
147 jboolean is_renderer_initiated
);
148 ToolbarModel::SecurityLevel
GetSecurityLevel(JNIEnv
* env
, jobject obj
);
149 void SetActiveNavigationEntryTitleForUrl(JNIEnv
* env
,
153 bool Print(JNIEnv
* env
, jobject obj
);
154 // Called to get favicon of current tab, return null if no favicon is
155 // avaliable for current tab.
156 base::android::ScopedJavaLocalRef
<jobject
> GetFavicon(JNIEnv
* env
,
158 jboolean
IsFaviconValid(JNIEnv
* env
, jobject jobj
);
160 // Register the Tab's native methods through JNI.
161 static bool RegisterTabAndroid(JNIEnv
* env
);
164 prerender::PrerenderManager
* GetPrerenderManager() const;
166 JavaObjectWeakGlobalRef weak_java_tab_
;
168 // The identifier used by session restore for this tab.
169 SessionID session_tab_id_
;
171 // Identifier of the window the tab is in.
172 SessionID session_window_id_
;
174 content::NotificationRegistrar notification_registrar_
;
176 scoped_ptr
<content::WebContents
> web_contents_
;
177 scoped_ptr
<chrome::android::ChromeWebContentsDelegateAndroid
>
178 web_contents_delegate_
;
180 scoped_ptr
<browser_sync::SyncedTabDelegateAndroid
> synced_tab_delegate_
;
182 DISALLOW_COPY_AND_ASSIGN(TabAndroid
);
185 #endif // CHROME_BROWSER_ANDROID_TAB_ANDROID_H_