Popular sites on the NTP: check that experiment group StartsWith (rather than IS...
[chromium-blink-merge.git] / chrome / browser / android / tab_android.h
blobd12ce98d13bf63c0d538d2968947ed867c1e7561
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_
8 #include <jni.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/search/instant_service_observer.h"
15 #include "chrome/browser/sync/glue/synced_tab_delegate_android.h"
16 #include "chrome/browser/ui/search/search_tab_helper_delegate.h"
17 #include "chrome/browser/ui/tab_contents/core_tab_helper_delegate.h"
18 #include "components/favicon/core/favicon_driver_observer.h"
19 #include "components/infobars/core/infobar_manager.h"
20 #include "components/sessions/session_id.h"
21 #include "components/toolbar/toolbar_model.h"
22 #include "content/public/browser/notification_observer.h"
23 #include "content/public/browser/notification_registrar.h"
25 class GURL;
26 class Profile;
27 class SkBitmap;
29 namespace cc {
30 class Layer;
33 namespace chrome {
34 struct NavigateParams;
37 namespace chrome {
38 namespace android {
39 class ChromeWebContentsDelegateAndroid;
40 class TabContentManager;
44 namespace content {
45 class ContentViewCore;
46 class WebContents;
49 namespace infobars {
50 class InfoBar;
53 namespace offline_pages {
54 struct OfflinePageItem;
57 namespace prerender {
58 class PrerenderManager;
61 class TabAndroid : public CoreTabHelperDelegate,
62 public InstantServiceObserver,
63 public SearchTabHelperDelegate,
64 public content::NotificationObserver,
65 public favicon::FaviconDriverObserver {
66 public:
67 // A Java counterpart will be generated for this enum.
68 // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.chrome.browser
69 enum TabLoadStatus {
70 PAGE_LOAD_FAILED = 0,
71 DEFAULT_PAGE_LOAD = 1,
72 PARTIAL_PRERENDERED_PAGE_LOAD = 2,
73 FULL_PRERENDERED_PAGE_LOAD = 3,
76 // Convenience method to retrieve the Tab associated with the passed
77 // WebContents. Can return NULL.
78 static TabAndroid* FromWebContents(content::WebContents* web_contents);
80 // Returns the native TabAndroid stored in the Java Tab represented by
81 // |obj|.
82 static TabAndroid* GetNativeTab(JNIEnv* env, jobject obj);
84 // Function to attach helpers to the contentView.
85 static void AttachTabHelpers(content::WebContents* web_contents);
87 TabAndroid(JNIEnv* env, jobject obj);
88 ~TabAndroid() override;
90 base::android::ScopedJavaLocalRef<jobject> GetJavaObject();
92 // Return the WebContents, if any, currently owned by this TabAndroid.
93 content::WebContents* web_contents() const { return web_contents_.get(); }
95 // Return the cc::Layer that represents the content for this TabAndroid.
96 scoped_refptr<cc::Layer> GetContentLayer() const;
98 // Return specific id information regarding this TabAndroid.
99 const SessionID& session_id() const { return session_tab_id_; }
100 int GetAndroidId() const;
101 int GetSyncId() const;
103 // Return the tab title.
104 base::string16 GetTitle() const;
106 // Return the tab url.
107 GURL GetURL() const;
109 // Load the tab if it was unloaded from memory.
110 bool LoadIfNeeded();
112 // Helper methods to make it easier to access objects from the associated
113 // WebContents. Can return NULL.
114 content::ContentViewCore* GetContentViewCore() const;
115 Profile* GetProfile() const;
116 browser_sync::SyncedTabDelegate* GetSyncedTabDelegate() const;
118 void SetWindowSessionID(SessionID::id_type window_id);
119 void SetSyncId(int sync_id);
121 void HandlePopupNavigation(chrome::NavigateParams* params);
123 bool HasPrerenderedUrl(GURL gurl);
125 void OnRendererUnresponsive(JNIEnv* env, jobject obj);
126 void OnRendererResponsive(JNIEnv* env, jobject obj);
128 void MakeLoadURLParams(
129 chrome::NavigateParams* params,
130 content::NavigationController::LoadURLParams* load_url_params);
132 // Overridden from CoreTabHelperDelegate:
133 void SwapTabContents(content::WebContents* old_contents,
134 content::WebContents* new_contents,
135 bool did_start_load,
136 bool did_finish_load) override;
138 // Overridden from InstantServiceObserver:
139 void DefaultSearchProviderChanged(
140 bool google_base_url_domain_changed) override;
142 // Overridden from SearchTabHelperDelegate:
143 void OnWebContentsInstantSupportDisabled(
144 const content::WebContents* web_contents) override;
146 // Overridden from NotificationObserver:
147 void Observe(int type,
148 const content::NotificationSource& source,
149 const content::NotificationDetails& details) override;
151 // Overridden from favicon::FaviconDriverObserver:
152 void OnFaviconAvailable(const gfx::Image& image) override;
153 void OnFaviconUpdated(favicon::FaviconDriver* favicon_driver,
154 bool icon_url_changed) override;
156 // Methods called from Java via JNI -----------------------------------------
158 void Destroy(JNIEnv* env, jobject obj);
159 void InitWebContents(JNIEnv* env,
160 jobject obj,
161 jboolean incognito,
162 jobject jcontent_view_core,
163 jobject jweb_contents_delegate,
164 jobject jcontext_menu_populator);
165 void DestroyWebContents(JNIEnv* env, jobject obj, jboolean delete_native);
166 base::android::ScopedJavaLocalRef<jobject> GetProfileAndroid(JNIEnv* env,
167 jobject obj);
168 TabLoadStatus LoadUrl(JNIEnv* env,
169 jobject obj,
170 jstring url,
171 jstring j_extra_headers,
172 jbyteArray j_post_data,
173 jint page_transition,
174 jstring j_referrer_url,
175 jint referrer_policy,
176 jboolean is_renderer_initiated,
177 jboolean should_replace_current_entry,
178 jlong intent_received_timestamp,
179 jboolean has_user_gesture);
180 void SetActiveNavigationEntryTitleForUrl(JNIEnv* env,
181 jobject obj,
182 jstring jurl,
183 jstring jtitle);
184 bool Print(JNIEnv* env, jobject obj);
186 // Sets the tab as content to be printed through JNI.
187 void SetPendingPrint();
189 // Called to get default favicon of current tab, return null if no
190 // favicon is avaliable for current tab.
191 base::android::ScopedJavaLocalRef<jobject> GetFavicon(JNIEnv* env,
192 jobject obj);
194 void CreateHistoricalTab(JNIEnv* env, jobject obj);
196 static void CreateHistoricalTabFromContents(
197 content::WebContents* web_contents);
199 void UpdateTopControlsState(JNIEnv* env,
200 jobject obj,
201 jint constraints,
202 jint current,
203 jboolean animate);
205 void LoadOriginalImage(JNIEnv* env, jobject obj);
207 void SearchByImageInNewTabAsync(JNIEnv* env, jobject obj);
209 jlong GetBookmarkId(JNIEnv* env, jobject obj, jboolean only_editable);
211 jboolean IsOfflinePage(JNIEnv* env, jobject obj);
213 base::android::ScopedJavaLocalRef<jstring> GetOfflinePageOriginalUrl(
214 JNIEnv* env,
215 jobject obj);
217 void SetInterceptNavigationDelegate(JNIEnv* env,
218 jobject obj,
219 jobject delegate);
221 // TODO(dtrainor): Remove this, pull content_layer() on demand.
222 void AttachToTabContentManager(JNIEnv* env,
223 jobject obj,
224 jobject jtab_content_manager);
226 void AttachOverlayContentViewCore(JNIEnv* env,
227 jobject obj,
228 jobject jcontent_view_core,
229 jboolean visible);
231 void DetachOverlayContentViewCore(JNIEnv* env,
232 jobject obj,
233 jobject jcontent_view_core);
235 bool HasPrerenderedUrl(JNIEnv* env, jobject obj, jstring url);
237 // Register the Tab's native methods through JNI.
238 static bool RegisterTabAndroid(JNIEnv* env);
240 private:
241 prerender::PrerenderManager* GetPrerenderManager() const;
243 const offline_pages::OfflinePageItem* GetOfflinePage(const GURL& url) const;
245 JavaObjectWeakGlobalRef weak_java_tab_;
247 // The identifier used by session restore for this tab.
248 SessionID session_tab_id_;
250 // Identifier of the window the tab is in.
251 SessionID session_window_id_;
253 content::NotificationRegistrar notification_registrar_;
255 scoped_refptr<cc::Layer> content_layer_;
256 chrome::android::TabContentManager* tab_content_manager_;
258 scoped_ptr<content::WebContents> web_contents_;
259 scoped_ptr<chrome::android::ChromeWebContentsDelegateAndroid>
260 web_contents_delegate_;
262 scoped_ptr<browser_sync::SyncedTabDelegateAndroid> synced_tab_delegate_;
264 DISALLOW_COPY_AND_ASSIGN(TabAndroid);
267 #endif // CHROME_BROWSER_ANDROID_TAB_ANDROID_H_