Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / android / tab_android.h
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.
4
5 #ifndef CHROME_BROWSER_ANDROID_TAB_ANDROID_H_
6 #define CHROME_BROWSER_ANDROID_TAB_ANDROID_H_
7
8 #include <jni.h>
9
10 #include "base/android/jni_helper.h"
11 #include "base/callback_forward.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/strings/string16.h"
14 #include "chrome/browser/sessions/session_id.h"
15 #include "chrome/browser/sync/glue/synced_tab_delegate_android.h"
16 #include "chrome/browser/ui/tab_contents/core_tab_helper_delegate.h"
17 #include "chrome/browser/ui/toolbar/toolbar_model.h"
18 #include "content/public/browser/notification_observer.h"
19 #include "content/public/browser/notification_registrar.h"
20
21 class GURL;
22 class Profile;
23 class SkBitmap;
24
25 namespace chrome {
26 struct NavigateParams;
27 }
28
29 namespace chrome {
30 namespace android {
31 class ChromeWebContentsDelegateAndroid;
32 }
33 }
34
35 namespace content {
36 class ContentViewCore;
37 class WebContents;
38 }
39
40 class TabAndroid : public CoreTabHelperDelegate,
41                    public content::NotificationObserver {
42  public:
43   // Convenience method to retrieve the Tab associated with the passed
44   // WebContents.  Can return NULL.
45   static TabAndroid* FromWebContents(content::WebContents* web_contents);
46
47   // Returns the native TabAndroid stored in the Java TabBase represented by
48   // |obj|.
49   static TabAndroid* GetNativeTab(JNIEnv* env, jobject obj);
50
51   TabAndroid(JNIEnv* env, jobject obj);
52   virtual ~TabAndroid();
53
54   base::android::ScopedJavaLocalRef<jobject> GetJavaObject();
55
56   // Return the WebContents, if any, currently owned by this TabAndroid.
57   content::WebContents* web_contents() const { return web_contents_.get(); }
58
59   // Return specific id information regarding this TabAndroid.
60   const SessionID& session_id() const { return session_tab_id_; }
61   int GetAndroidId() const;
62   int GetSyncId() const;
63
64   // Return the tab title.
65   base::string16 GetTitle() const;
66
67   // Return the tab url.
68   GURL GetURL() const;
69
70   // Restore the tab if it was unloaded from memory.
71   bool RestoreIfNeeded();
72
73   // Helper methods to make it easier to access objects from the associated
74   // WebContents.  Can return NULL.
75   content::ContentViewCore* GetContentViewCore() const;
76   Profile* GetProfile() const;
77   browser_sync::SyncedTabDelegate* GetSyncedTabDelegate() const;
78
79   void SetSyncId(int sync_id);
80
81   virtual void HandlePopupNavigation(chrome::NavigateParams* params);
82
83   virtual void OnReceivedHttpAuthRequest(jobject auth_handler,
84                                          const base::string16& host,
85                                          const base::string16& realm);
86
87   // Called when context menu option to create the bookmark shortcut on
88   // homescreen is called.
89   virtual void AddShortcutToBookmark(const GURL& url,
90                                      const base::string16& title,
91                                      const SkBitmap& skbitmap,
92                                      int r_value,
93                                      int g_value,
94                                      int b_value);
95
96   // Called when a bookmark node should be edited.
97   virtual void EditBookmark(int64 node_id,
98                             const base::string16& node_title,
99                             bool is_folder,
100                             bool is_partner_bookmark);
101
102   // Called to notify that the new tab page has completely rendered.
103   virtual void OnNewTabPageReady();
104
105   // Called to determine if chrome://welcome should contain links to the terms
106   // of service and the privacy notice.
107   virtual bool ShouldWelcomePageLinkToTermsOfService();
108
109   // Register the Tab's native methods through JNI.
110   static bool RegisterTabAndroid(JNIEnv* env);
111
112   // CoreTabHelperDelegate ----------------------------------------------------
113
114   virtual void SwapTabContents(content::WebContents* old_contents,
115                                content::WebContents* new_contents,
116                                bool did_start_load,
117                                bool did_finish_load) OVERRIDE;
118
119   // NotificationObserver -----------------------------------------------------
120   virtual void Observe(int type,
121                        const content::NotificationSource& source,
122                        const content::NotificationDetails& details) OVERRIDE;
123
124   // Methods called from Java via JNI -----------------------------------------
125
126   virtual void Destroy(JNIEnv* env, jobject obj);
127   virtual void InitWebContents(JNIEnv* env,
128                                jobject obj,
129                                jboolean incognito,
130                                jobject jcontent_view_core,
131                                jobject jweb_contents_delegate,
132                                jobject jcontext_menu_populator);
133   virtual void DestroyWebContents(JNIEnv* env,
134                                   jobject obj,
135                                   jboolean delete_native);
136   base::android::ScopedJavaLocalRef<jobject> GetWebContents(JNIEnv* env,
137                                                             jobject obj);
138   base::android::ScopedJavaLocalRef<jobject> GetProfileAndroid(JNIEnv* env,
139                                                                jobject obj);
140   ToolbarModel::SecurityLevel GetSecurityLevel(JNIEnv* env, jobject obj);
141   void SetActiveNavigationEntryTitleForUrl(JNIEnv* env,
142                                            jobject obj,
143                                            jstring jurl,
144                                            jstring jtitle);
145   bool Print(JNIEnv* env, jobject obj);
146
147  private:
148   JavaObjectWeakGlobalRef weak_java_tab_;
149
150   SessionID session_tab_id_;
151
152   content::NotificationRegistrar notification_registrar_;
153
154   scoped_ptr<content::WebContents> web_contents_;
155   scoped_ptr<chrome::android::ChromeWebContentsDelegateAndroid>
156       web_contents_delegate_;
157
158   scoped_ptr<browser_sync::SyncedTabDelegateAndroid> synced_tab_delegate_;
159
160   DISALLOW_COPY_AND_ASSIGN(TabAndroid);
161 };
162
163 #endif  // CHROME_BROWSER_ANDROID_TAB_ANDROID_H_