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_
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/sessions/session_id.h"
20 #include "components/toolbar/toolbar_model.h"
21 #include "content/public/browser/notification_observer.h"
22 #include "content/public/browser/notification_registrar.h"
33 struct NavigateParams
;
38 class ChromeWebContentsDelegateAndroid
;
39 class TabContentManager
;
44 class ContentViewCore
;
48 namespace offline_pages
{
49 struct OfflinePageItem
;
53 class PrerenderManager
;
56 class TabAndroid
: public CoreTabHelperDelegate
,
57 public InstantServiceObserver
,
58 public SearchTabHelperDelegate
,
59 public content::NotificationObserver
,
60 public favicon::FaviconDriverObserver
{
62 // A Java counterpart will be generated for this enum.
63 // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.chrome.browser
66 DEFAULT_PAGE_LOAD
= 1,
67 PARTIAL_PRERENDERED_PAGE_LOAD
= 2,
68 FULL_PRERENDERED_PAGE_LOAD
= 3,
71 // Convenience method to retrieve the Tab associated with the passed
72 // WebContents. Can return NULL.
73 static TabAndroid
* FromWebContents(content::WebContents
* web_contents
);
75 // Returns the native TabAndroid stored in the Java Tab represented by
77 static TabAndroid
* GetNativeTab(JNIEnv
* env
, jobject obj
);
79 // Function to attach helpers to the contentView.
80 static void AttachTabHelpers(content::WebContents
* web_contents
);
82 TabAndroid(JNIEnv
* env
, jobject obj
);
83 ~TabAndroid() override
;
85 base::android::ScopedJavaLocalRef
<jobject
> GetJavaObject();
87 // Return the WebContents, if any, currently owned by this TabAndroid.
88 content::WebContents
* web_contents() const { return web_contents_
.get(); }
90 // Return the cc::Layer that represents the content for this TabAndroid.
91 scoped_refptr
<cc::Layer
> GetContentLayer() const;
93 // Return specific id information regarding this TabAndroid.
94 const SessionID
& session_id() const { return session_tab_id_
; }
95 int GetAndroidId() const;
96 int GetSyncId() const;
98 // Return the tab title.
99 base::string16
GetTitle() const;
101 // Return the tab url.
104 // Load the tab if it was unloaded from memory.
107 // Helper methods to make it easier to access objects from the associated
108 // WebContents. Can return NULL.
109 content::ContentViewCore
* GetContentViewCore() const;
110 Profile
* GetProfile() const;
111 browser_sync::SyncedTabDelegate
* GetSyncedTabDelegate() const;
113 void SetWindowSessionID(SessionID::id_type window_id
);
114 void SetSyncId(int sync_id
);
116 void HandlePopupNavigation(chrome::NavigateParams
* params
);
118 bool HasPrerenderedUrl(GURL gurl
);
120 void MakeLoadURLParams(
121 chrome::NavigateParams
* params
,
122 content::NavigationController::LoadURLParams
* load_url_params
);
124 // CoreTabHelperDelegate ----------------------------------------------------
126 void SwapTabContents(content::WebContents
* old_contents
,
127 content::WebContents
* new_contents
,
129 bool did_finish_load
) override
;
131 // Overridden from InstantServiceObserver:
132 void DefaultSearchProviderChanged(
133 bool google_base_url_domain_changed
) override
;
135 // Overridden from SearchTabHelperDelegate:
136 void OnWebContentsInstantSupportDisabled(
137 const content::WebContents
* web_contents
) override
;
139 // NotificationObserver -----------------------------------------------------
140 void Observe(int type
,
141 const content::NotificationSource
& source
,
142 const content::NotificationDetails
& details
) override
;
144 // favicon::FaviconDriverObserver -------------------------------------------
145 void OnFaviconAvailable(const gfx::Image
& image
) override
;
146 void OnFaviconUpdated(favicon::FaviconDriver
* favicon_driver
,
147 bool icon_url_changed
) override
;
149 // Methods called from Java via JNI -----------------------------------------
151 void Destroy(JNIEnv
* env
, jobject obj
);
152 void InitWebContents(JNIEnv
* env
,
155 jobject jcontent_view_core
,
156 jobject jweb_contents_delegate
,
157 jobject jcontext_menu_populator
);
158 void DestroyWebContents(JNIEnv
* env
, jobject obj
, jboolean delete_native
);
159 base::android::ScopedJavaLocalRef
<jobject
> GetProfileAndroid(JNIEnv
* env
,
161 TabLoadStatus
LoadUrl(JNIEnv
* env
,
164 jstring j_extra_headers
,
165 jbyteArray j_post_data
,
166 jint page_transition
,
167 jstring j_referrer_url
,
168 jint referrer_policy
,
169 jboolean is_renderer_initiated
,
170 jboolean should_replace_current_entry
,
171 jlong intent_received_timestamp
,
172 jboolean has_user_gesture
);
173 void SetActiveNavigationEntryTitleForUrl(JNIEnv
* env
,
177 bool Print(JNIEnv
* env
, jobject obj
);
179 // Sets the tab as content to be printed through JNI.
180 void SetPendingPrint();
182 // Called to get default favicon of current tab, return null if no
183 // favicon is avaliable for current tab.
184 base::android::ScopedJavaLocalRef
<jobject
> GetFavicon(JNIEnv
* env
,
187 void CreateHistoricalTab(JNIEnv
* env
, jobject obj
);
189 static void CreateHistoricalTabFromContents(
190 content::WebContents
* web_contents
);
192 void UpdateTopControlsState(JNIEnv
* env
,
198 void LoadOriginalImage(JNIEnv
* env
, jobject obj
);
200 void SearchByImageInNewTabAsync(JNIEnv
* env
, jobject obj
);
202 jlong
GetBookmarkId(JNIEnv
* env
, jobject obj
, jboolean only_editable
);
204 jboolean
IsOfflinePage(JNIEnv
* env
, jobject obj
);
206 void SetInterceptNavigationDelegate(JNIEnv
* env
,
210 // TODO(dtrainor): Remove this, pull content_layer() on demand.
211 void AttachToTabContentManager(JNIEnv
* env
,
213 jobject jtab_content_manager
);
215 void AttachOverlayContentViewCore(JNIEnv
* env
,
217 jobject jcontent_view_core
,
220 void DetachOverlayContentViewCore(JNIEnv
* env
,
222 jobject jcontent_view_core
);
224 bool HasPrerenderedUrl(JNIEnv
* env
, jobject obj
, jstring url
);
226 // Register the Tab's native methods through JNI.
227 static bool RegisterTabAndroid(JNIEnv
* env
);
230 prerender::PrerenderManager
* GetPrerenderManager() const;
232 const offline_pages::OfflinePageItem
* GetOfflinePage(const GURL
& url
) const;
234 JavaObjectWeakGlobalRef weak_java_tab_
;
236 // The identifier used by session restore for this tab.
237 SessionID session_tab_id_
;
239 // Identifier of the window the tab is in.
240 SessionID session_window_id_
;
242 content::NotificationRegistrar notification_registrar_
;
244 scoped_refptr
<cc::Layer
> content_layer_
;
245 chrome::android::TabContentManager
* tab_content_manager_
;
247 scoped_ptr
<content::WebContents
> web_contents_
;
248 scoped_ptr
<chrome::android::ChromeWebContentsDelegateAndroid
>
249 web_contents_delegate_
;
251 scoped_ptr
<browser_sync::SyncedTabDelegateAndroid
> synced_tab_delegate_
;
253 DISALLOW_COPY_AND_ASSIGN(TabAndroid
);
256 #endif // CHROME_BROWSER_ANDROID_TAB_ANDROID_H_