Fix UnlockEndpointIsDelayed again.
[chromium-blink-merge.git] / chrome / browser / android / tab_android.h
blob57c019b2d4337edabd2779aa0502deef8c31dfbd
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/favicon/favicon_tab_helper_observer.h"
15 #include "chrome/browser/search/instant_service_observer.h"
16 #include "chrome/browser/sync/glue/synced_tab_delegate_android.h"
17 #include "chrome/browser/ui/search/search_tab_helper_delegate.h"
18 #include "chrome/browser/ui/tab_contents/core_tab_helper_delegate.h"
19 #include "chrome/browser/ui/toolbar/toolbar_model.h"
20 #include "components/sessions/session_id.h"
21 #include "content/public/browser/notification_observer.h"
22 #include "content/public/browser/notification_registrar.h"
24 class GURL;
25 class Profile;
26 class SkBitmap;
28 namespace chrome {
29 struct NavigateParams;
32 namespace chrome {
33 namespace android {
34 class ChromeWebContentsDelegateAndroid;
38 namespace content {
39 class ContentViewCore;
40 class WebContents;
43 namespace prerender {
44 class PrerenderManager;
47 class TabAndroid : public CoreTabHelperDelegate,
48 public InstantServiceObserver,
49 public SearchTabHelperDelegate,
50 public content::NotificationObserver,
51 public FaviconTabHelperObserver {
52 public:
53 // A Java counterpart will be generated for this enum.
54 // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.chrome.browser
55 enum TabLoadStatus {
56 PAGE_LOAD_FAILED = 0,
57 DEFAULT_PAGE_LOAD = 1,
58 PARTIAL_PRERENDERED_PAGE_LOAD = 2,
59 FULL_PRERENDERED_PAGE_LOAD = 3,
62 // Convenience method to retrieve the Tab associated with the passed
63 // WebContents. Can return NULL.
64 static TabAndroid* FromWebContents(content::WebContents* web_contents);
66 // Returns the native TabAndroid stored in the Java Tab represented by
67 // |obj|.
68 static TabAndroid* GetNativeTab(JNIEnv* env, jobject obj);
70 // Function to attach helpers to the contentView.
71 static void AttachTabHelpers(content::WebContents* web_contents);
73 TabAndroid(JNIEnv* env, jobject obj);
74 virtual ~TabAndroid();
76 base::android::ScopedJavaLocalRef<jobject> GetJavaObject();
78 // Return the WebContents, if any, currently owned by this TabAndroid.
79 content::WebContents* web_contents() const { return web_contents_.get(); }
81 // Return specific id information regarding this TabAndroid.
82 const SessionID& session_id() const { return session_tab_id_; }
83 int GetAndroidId() const;
84 int GetSyncId() const;
86 // Return the tab title.
87 base::string16 GetTitle() const;
89 // Return the tab url.
90 GURL GetURL() const;
92 // Load the tab if it was unloaded from memory.
93 bool LoadIfNeeded();
95 // Helper methods to make it easier to access objects from the associated
96 // WebContents. Can return NULL.
97 content::ContentViewCore* GetContentViewCore() const;
98 Profile* GetProfile() const;
99 browser_sync::SyncedTabDelegate* GetSyncedTabDelegate() const;
101 void SetWindowSessionID(SessionID::id_type window_id);
102 void SetSyncId(int sync_id);
104 virtual void HandlePopupNavigation(chrome::NavigateParams* params);
106 bool HasPrerenderedUrl(GURL gurl);
108 void MakeLoadURLParams(
109 chrome::NavigateParams* params,
110 content::NavigationController::LoadURLParams* load_url_params);
112 // CoreTabHelperDelegate ----------------------------------------------------
114 virtual void SwapTabContents(content::WebContents* old_contents,
115 content::WebContents* new_contents,
116 bool did_start_load,
117 bool did_finish_load) override;
119 // Overridden from InstantServiceObserver:
120 void DefaultSearchProviderChanged() override;
122 // Overridden from SearchTabHelperDelegate:
123 virtual void OnWebContentsInstantSupportDisabled(
124 const content::WebContents* web_contents) override;
126 // NotificationObserver -----------------------------------------------------
127 virtual void Observe(int type,
128 const content::NotificationSource& source,
129 const content::NotificationDetails& details) override;
131 // FaviconTabHelperObserver -----------------------------------------------
132 virtual void OnFaviconAvailable(const gfx::Image& image) override;
134 // Methods called from Java via JNI -----------------------------------------
136 virtual void Destroy(JNIEnv* env, jobject obj);
137 virtual void InitWebContents(JNIEnv* env,
138 jobject obj,
139 jboolean incognito,
140 jobject jcontent_view_core,
141 jobject jweb_contents_delegate,
142 jobject jcontext_menu_populator);
143 virtual void DestroyWebContents(JNIEnv* env,
144 jobject obj,
145 jboolean delete_native);
146 base::android::ScopedJavaLocalRef<jobject> GetProfileAndroid(JNIEnv* env,
147 jobject obj);
148 virtual TabLoadStatus LoadUrl(JNIEnv* env,
149 jobject obj,
150 jstring url,
151 jstring j_extra_headers,
152 jbyteArray j_post_data,
153 jint page_transition,
154 jstring j_referrer_url,
155 jint referrer_policy,
156 jboolean is_renderer_initiated,
157 jlong intent_received_timestamp);
158 void SetActiveNavigationEntryTitleForUrl(JNIEnv* env,
159 jobject obj,
160 jstring jurl,
161 jstring jtitle);
162 bool Print(JNIEnv* env, jobject obj);
164 // Sets the tab as content to be printed through JNI.
165 void SetPendingPrint();
167 // Called to get default favicon of current tab, return null if no
168 // favicon is avaliable for current tab.
169 base::android::ScopedJavaLocalRef<jobject> GetFavicon(JNIEnv* env,
170 jobject obj);
172 void CreateHistoricalTab(JNIEnv* env, jobject obj);
174 static void CreateHistoricalTabFromContents(
175 content::WebContents* web_contents);
177 void UpdateTopControlsState(JNIEnv* env,
178 jobject obj,
179 jint constraints,
180 jint current,
181 jboolean animate);
183 void SearchByImageInNewTabAsync(JNIEnv* env, jobject obj);
185 void SetInterceptNavigationDelegate(JNIEnv* env,
186 jobject obj,
187 jobject delegate);
189 // Register the Tab's native methods through JNI.
190 static bool RegisterTabAndroid(JNIEnv* env);
192 private:
193 prerender::PrerenderManager* GetPrerenderManager() const;
195 JavaObjectWeakGlobalRef weak_java_tab_;
197 // The identifier used by session restore for this tab.
198 SessionID session_tab_id_;
200 // Identifier of the window the tab is in.
201 SessionID session_window_id_;
203 content::NotificationRegistrar notification_registrar_;
205 scoped_ptr<content::WebContents> web_contents_;
206 scoped_ptr<chrome::android::ChromeWebContentsDelegateAndroid>
207 web_contents_delegate_;
209 scoped_ptr<browser_sync::SyncedTabDelegateAndroid> synced_tab_delegate_;
211 DISALLOW_COPY_AND_ASSIGN(TabAndroid);
214 #endif // CHROME_BROWSER_ANDROID_TAB_ANDROID_H_