Add more checks to investigate SupervisedUserPrefStore crash at startup.
[chromium-blink-merge.git] / chrome / browser / android / tab_android.h
blob8bb80a4745f437b3556365d9ee3debf3edd61f7f
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 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 FaviconTabHelperObserver {
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 virtual 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 // FaviconTabHelperObserver -----------------------------------------------
141 void OnFaviconAvailable(const gfx::Image& image) override;
143 // Methods called from Java via JNI -----------------------------------------
145 virtual void Destroy(JNIEnv* env, jobject obj);
146 virtual void InitWebContents(JNIEnv* env,
147 jobject obj,
148 jboolean incognito,
149 jobject jcontent_view_core,
150 jobject jweb_contents_delegate,
151 jobject jcontext_menu_populator);
152 virtual void DestroyWebContents(JNIEnv* env,
153 jobject obj,
154 jboolean delete_native);
155 base::android::ScopedJavaLocalRef<jobject> GetProfileAndroid(JNIEnv* env,
156 jobject obj);
157 virtual 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 SearchByImageInNewTabAsync(JNIEnv* env, jobject obj);
194 jlong GetBookmarkId(JNIEnv* env, jobject obj, jboolean only_editable);
196 void SetInterceptNavigationDelegate(JNIEnv* env,
197 jobject obj,
198 jobject delegate);
200 // TODO(dtrainor): Remove this, pull content_layer() on demand.
201 void AttachToTabContentManager(JNIEnv* env,
202 jobject obj,
203 jobject jtab_content_manager);
205 void AttachOverlayContentViewCore(JNIEnv* env,
206 jobject obj,
207 jobject jcontent_view_core,
208 jboolean visible);
210 void DetachOverlayContentViewCore(JNIEnv* env,
211 jobject obj,
212 jobject jcontent_view_core);
214 // Register the Tab's native methods through JNI.
215 static bool RegisterTabAndroid(JNIEnv* env);
217 private:
218 prerender::PrerenderManager* GetPrerenderManager() const;
220 JavaObjectWeakGlobalRef weak_java_tab_;
222 // The identifier used by session restore for this tab.
223 SessionID session_tab_id_;
225 // Identifier of the window the tab is in.
226 SessionID session_window_id_;
228 content::NotificationRegistrar notification_registrar_;
230 scoped_refptr<cc::Layer> content_layer_;
231 chrome::android::TabContentManager* tab_content_manager_;
233 scoped_ptr<content::WebContents> web_contents_;
234 scoped_ptr<chrome::android::ChromeWebContentsDelegateAndroid>
235 web_contents_delegate_;
237 scoped_ptr<browser_sync::SyncedTabDelegateAndroid> synced_tab_delegate_;
239 DISALLOW_COPY_AND_ASSIGN(TabAndroid);
242 #endif // CHROME_BROWSER_ANDROID_TAB_ANDROID_H_