Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / browser / android / tab_android.h
blob9f3ce69305c8b65efaf31372f48fa81671f38fea
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 "chrome/browser/ui/toolbar/toolbar_model.h"
19 #include "components/favicon/core/favicon_driver_observer.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 cc {
29 class Layer;
32 namespace chrome {
33 struct NavigateParams;
36 namespace chrome {
37 namespace android {
38 class ChromeWebContentsDelegateAndroid;
39 class TabContentManager;
43 namespace content {
44 class ContentViewCore;
45 class WebContents;
48 namespace prerender {
49 class PrerenderManager;
52 class TabAndroid : public CoreTabHelperDelegate,
53 public InstantServiceObserver,
54 public SearchTabHelperDelegate,
55 public content::NotificationObserver,
56 public favicon::FaviconDriverObserver {
57 public:
58 // A Java counterpart will be generated for this enum.
59 // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.chrome.browser
60 enum TabLoadStatus {
61 PAGE_LOAD_FAILED = 0,
62 DEFAULT_PAGE_LOAD = 1,
63 PARTIAL_PRERENDERED_PAGE_LOAD = 2,
64 FULL_PRERENDERED_PAGE_LOAD = 3,
67 // Convenience method to retrieve the Tab associated with the passed
68 // WebContents. Can return NULL.
69 static TabAndroid* FromWebContents(content::WebContents* web_contents);
71 // Returns the native TabAndroid stored in the Java Tab represented by
72 // |obj|.
73 static TabAndroid* GetNativeTab(JNIEnv* env, jobject obj);
75 // Function to attach helpers to the contentView.
76 static void AttachTabHelpers(content::WebContents* web_contents);
78 TabAndroid(JNIEnv* env, jobject obj);
79 ~TabAndroid() override;
81 base::android::ScopedJavaLocalRef<jobject> GetJavaObject();
83 // Return the WebContents, if any, currently owned by this TabAndroid.
84 content::WebContents* web_contents() const { return web_contents_.get(); }
86 // Return the cc::Layer that represents the content for this TabAndroid.
87 scoped_refptr<cc::Layer> GetContentLayer() const;
89 // Return specific id information regarding this TabAndroid.
90 const SessionID& session_id() const { return session_tab_id_; }
91 int GetAndroidId() const;
92 int GetSyncId() const;
94 // Return the tab title.
95 base::string16 GetTitle() const;
97 // Return the tab url.
98 GURL GetURL() const;
100 // Load the tab if it was unloaded from memory.
101 bool LoadIfNeeded();
103 // Helper methods to make it easier to access objects from the associated
104 // WebContents. Can return NULL.
105 content::ContentViewCore* GetContentViewCore() const;
106 Profile* GetProfile() const;
107 browser_sync::SyncedTabDelegate* GetSyncedTabDelegate() const;
109 void SetWindowSessionID(SessionID::id_type window_id);
110 void SetSyncId(int sync_id);
112 void HandlePopupNavigation(chrome::NavigateParams* params);
114 bool HasPrerenderedUrl(GURL gurl);
116 void MakeLoadURLParams(
117 chrome::NavigateParams* params,
118 content::NavigationController::LoadURLParams* load_url_params);
120 // CoreTabHelperDelegate ----------------------------------------------------
122 void SwapTabContents(content::WebContents* old_contents,
123 content::WebContents* new_contents,
124 bool did_start_load,
125 bool did_finish_load) override;
127 // Overridden from InstantServiceObserver:
128 void DefaultSearchProviderChanged(
129 bool google_base_url_domain_changed) override;
131 // Overridden from SearchTabHelperDelegate:
132 void OnWebContentsInstantSupportDisabled(
133 const content::WebContents* web_contents) override;
135 // NotificationObserver -----------------------------------------------------
136 void Observe(int type,
137 const content::NotificationSource& source,
138 const content::NotificationDetails& details) override;
140 // favicon::FaviconDriverObserver -------------------------------------------
141 void OnFaviconAvailable(const gfx::Image& image) override;
142 void OnFaviconUpdated(favicon::FaviconDriver* favicon_driver,
143 bool icon_url_changed) override;
145 // Methods called from Java via JNI -----------------------------------------
147 void Destroy(JNIEnv* env, jobject obj);
148 void InitWebContents(JNIEnv* env,
149 jobject obj,
150 jboolean incognito,
151 jobject jcontent_view_core,
152 jobject jweb_contents_delegate,
153 jobject jcontext_menu_populator);
154 void DestroyWebContents(JNIEnv* env, jobject obj, jboolean delete_native);
155 base::android::ScopedJavaLocalRef<jobject> GetProfileAndroid(JNIEnv* env,
156 jobject obj);
157 TabLoadStatus LoadUrl(JNIEnv* env,
158 jobject obj,
159 jstring url,
160 jstring j_extra_headers,
161 jbyteArray j_post_data,
162 jint page_transition,
163 jstring j_referrer_url,
164 jint referrer_policy,
165 jboolean is_renderer_initiated,
166 jlong intent_received_timestamp);
167 void SetActiveNavigationEntryTitleForUrl(JNIEnv* env,
168 jobject obj,
169 jstring jurl,
170 jstring jtitle);
171 bool Print(JNIEnv* env, jobject obj);
173 // Sets the tab as content to be printed through JNI.
174 void SetPendingPrint();
176 // Called to get default favicon of current tab, return null if no
177 // favicon is avaliable for current tab.
178 base::android::ScopedJavaLocalRef<jobject> GetFavicon(JNIEnv* env,
179 jobject obj);
181 void CreateHistoricalTab(JNIEnv* env, jobject obj);
183 static void CreateHistoricalTabFromContents(
184 content::WebContents* web_contents);
186 void UpdateTopControlsState(JNIEnv* env,
187 jobject obj,
188 jint constraints,
189 jint current,
190 jboolean animate);
192 void LoadOriginalImage(JNIEnv* env, jobject obj);
194 void SearchByImageInNewTabAsync(JNIEnv* env, jobject obj);
196 jlong GetBookmarkId(JNIEnv* env, jobject obj, jboolean only_editable);
198 void SetInterceptNavigationDelegate(JNIEnv* env,
199 jobject obj,
200 jobject delegate);
202 // TODO(dtrainor): Remove this, pull content_layer() on demand.
203 void AttachToTabContentManager(JNIEnv* env,
204 jobject obj,
205 jobject jtab_content_manager);
207 void AttachOverlayContentViewCore(JNIEnv* env,
208 jobject obj,
209 jobject jcontent_view_core,
210 jboolean visible);
212 void DetachOverlayContentViewCore(JNIEnv* env,
213 jobject obj,
214 jobject jcontent_view_core);
216 bool HasPrerenderedUrl(JNIEnv* env, jobject obj, jstring url);
218 // Register the Tab's native methods through JNI.
219 static bool RegisterTabAndroid(JNIEnv* env);
221 private:
222 prerender::PrerenderManager* GetPrerenderManager() const;
224 JavaObjectWeakGlobalRef weak_java_tab_;
226 // The identifier used by session restore for this tab.
227 SessionID session_tab_id_;
229 // Identifier of the window the tab is in.
230 SessionID session_window_id_;
232 content::NotificationRegistrar notification_registrar_;
234 scoped_refptr<cc::Layer> content_layer_;
235 chrome::android::TabContentManager* tab_content_manager_;
237 scoped_ptr<content::WebContents> web_contents_;
238 scoped_ptr<chrome::android::ChromeWebContentsDelegateAndroid>
239 web_contents_delegate_;
241 scoped_ptr<browser_sync::SyncedTabDelegateAndroid> synced_tab_delegate_;
243 DISALLOW_COPY_AND_ASSIGN(TabAndroid);
246 #endif // CHROME_BROWSER_ANDROID_TAB_ANDROID_H_