Move Webstore URL concepts to //extensions and out
[chromium-blink-merge.git] / chrome / browser / android / tab_android.h
blobf4378e3e8dc847d0a7b676c472bb7f29acc9d0a2
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/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"
22 class GURL;
23 class Profile;
24 class SkBitmap;
26 namespace chrome {
27 struct NavigateParams;
30 namespace chrome {
31 namespace android {
32 class ChromeWebContentsDelegateAndroid;
36 namespace content {
37 class ContentViewCore;
38 class WebContents;
41 namespace prerender {
42 class PrerenderManager;
45 class TabAndroid : public CoreTabHelperDelegate,
46 public SearchTabHelperDelegate,
47 public content::NotificationObserver {
48 public:
49 enum TabLoadStatus {
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
60 // |obj|.
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.
83 GURL GetURL() const;
85 // Load the tab if it was unloaded from memory.
86 bool LoadIfNeeded();
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,
113 bool did_start_load,
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,
129 jobject obj,
130 jboolean incognito,
131 jobject jcontent_view_core,
132 jobject jweb_contents_delegate,
133 jobject jcontext_menu_populator);
134 virtual void DestroyWebContents(JNIEnv* env,
135 jobject obj,
136 jboolean delete_native);
137 base::android::ScopedJavaLocalRef<jobject> GetProfileAndroid(JNIEnv* env,
138 jobject obj);
139 virtual TabLoadStatus LoadUrl(JNIEnv* env,
140 jobject obj,
141 jstring url,
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,
150 jobject obj,
151 jstring jurl,
152 jstring jtitle);
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,
157 jobject obj);
158 jboolean IsFaviconValid(JNIEnv* env, jobject jobj);
160 // Register the Tab's native methods through JNI.
161 static bool RegisterTabAndroid(JNIEnv* env);
163 private:
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_