Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / android / provider / chrome_browser_provider.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_PROVIDER_CHROME_BROWSER_PROVIDER_H_
6 #define CHROME_BROWSER_ANDROID_PROVIDER_CHROME_BROWSER_PROVIDER_H_
7
8 #include "base/android/jni_weak_ref.h"
9 #include "base/android/scoped_java_ref.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/scoped_observer.h"
12 #include "base/synchronization/waitable_event.h"
13 #include "base/task/cancelable_task_tracker.h"
14 #include "components/bookmarks/browser/base_bookmark_model_observer.h"
15 #include "components/history/core/android/android_history_types.h"
16 #include "components/history/core/browser/history_service_observer.h"
17 #include "content/public/browser/notification_observer.h"
18 #include "content/public/browser/notification_registrar.h"
19
20 class AndroidHistoryProviderService;
21 class FaviconService;
22 class Profile;
23
24 namespace history {
25 class TopSites;
26 }
27
28 namespace sql {
29 class Statement;
30 }
31
32 // This class implements the native methods of ChromeBrowserProvider.java
33 class ChromeBrowserProvider : public BaseBookmarkModelObserver,
34                               public content::NotificationObserver,
35                               public history::HistoryServiceObserver {
36  public:
37   ChromeBrowserProvider(JNIEnv* env, jobject obj);
38   void Destroy(JNIEnv*, jobject);
39
40   // JNI registration.
41   static bool RegisterChromeBrowserProvider(JNIEnv* env);
42
43   // Adds either a new bookmark or bookmark folder based on |is_folder|.  The
44   // bookmark is added to the beginning of the specified parent and if the
45   // parent ID is not valid (i.e. < 0) then it will be added to the bookmark
46   // bar.
47   jlong AddBookmark(JNIEnv* env, jobject,
48                     jstring jurl,
49                     jstring jtitle,
50                     jboolean is_folder,
51                     jlong parent_id);
52
53   // Removes a bookmark (or folder) with the specified ID.
54   jint RemoveBookmark(JNIEnv*, jobject, jlong id);
55
56   // Updates a bookmark (or folder) with the the new title and new URL.
57   // The |url| field will be ignored if the bookmark node is a folder.
58   // If a valid |parent_id| (>= 0) different from the currently specified
59   // parent is given, the node will be moved to that folder as the first
60   // child.
61   jint UpdateBookmark(JNIEnv* env,
62                       jobject,
63                       jlong id,
64                       jstring url,
65                       jstring title,
66                       jlong parent_id);
67
68   // The below are methods to support Android public API.
69   // Bookmark and history APIs. -----------------------------------------------
70   jlong AddBookmarkFromAPI(JNIEnv* env,
71                            jobject obj,
72                            jstring url,
73                            jobject created,
74                            jobject isBookmark,
75                            jobject date,
76                            jbyteArray favicon,
77                            jstring title,
78                            jobject visits,
79                            jlong parent_id);
80
81   base::android::ScopedJavaLocalRef<jobject> QueryBookmarkFromAPI(
82       JNIEnv* env,
83       jobject obj,
84       jobjectArray projection,
85       jstring selections,
86       jobjectArray selection_args,
87       jstring sort_order);
88
89   jint UpdateBookmarkFromAPI(JNIEnv* env,
90                              jobject obj,
91                              jstring url,
92                              jobject created,
93                              jobject isBookmark,
94                              jobject date,
95                              jbyteArray favicon,
96                              jstring title,
97                              jobject visits,
98                              jlong parent_id,
99                              jstring selections,
100                              jobjectArray selection_args);
101
102   jint RemoveBookmarkFromAPI(JNIEnv* env,
103                              jobject obj,
104                              jstring selections,
105                              jobjectArray selection_args);
106
107   jint RemoveHistoryFromAPI(JNIEnv* env,
108                             jobject obj,
109                             jstring selections,
110                             jobjectArray selection_args);
111
112   jlong AddSearchTermFromAPI(JNIEnv* env,
113                              jobject obj,
114                              jstring search_term,
115                              jobject date);
116
117   base::android::ScopedJavaLocalRef<jobject> QuerySearchTermFromAPI(
118       JNIEnv* env,
119       jobject obj,
120       jobjectArray projection,
121       jstring selections,
122       jobjectArray selection_args,
123       jstring sort_order);
124
125   jint RemoveSearchTermFromAPI(JNIEnv* env,
126                                jobject obj,
127                                jstring selections,
128                                jobjectArray selection_args);
129
130   jint UpdateSearchTermFromAPI(JNIEnv* env,
131                                jobject obj,
132                                jstring search_term,
133                                jobject date,
134                                jstring selections,
135                                jobjectArray selection_args);
136
137   // Custom provider API methods. ---------------------------------------------
138   jlong CreateBookmarksFolderOnce(JNIEnv* env,
139                                   jobject obj,
140                                   jstring title,
141                                   jlong parent_id);
142
143   void RemoveAllUserBookmarks(JNIEnv* env, jobject obj);
144
145   base::android::ScopedJavaLocalRef<jobject> GetEditableBookmarkFolders(
146       JNIEnv* env,
147       jobject obj);
148
149   base::android::ScopedJavaLocalRef<jobject> GetBookmarkNode(
150       JNIEnv* env,
151       jobject obj,
152       jlong id,
153       jboolean get_parent,
154       jboolean get_children);
155
156   base::android::ScopedJavaLocalRef<jobject> GetMobileBookmarksFolder(
157       JNIEnv* env,
158       jobject obj);
159
160   jboolean IsBookmarkInMobileBookmarksBranch(JNIEnv* env,
161                                              jobject obj,
162                                              jlong id);
163
164   jboolean BookmarkNodeExists(JNIEnv* env,
165                               jobject obj,
166                               jlong id);
167
168   base::android::ScopedJavaLocalRef<jbyteArray> GetFaviconOrTouchIcon(
169       JNIEnv* env,
170       jobject obj,
171       jstring url);
172
173   base::android::ScopedJavaLocalRef<jbyteArray> GetThumbnail(JNIEnv* env,
174                                                              jobject obj,
175                                                              jstring url);
176
177  private:
178   virtual ~ChromeBrowserProvider();
179
180   // Override BaseBookmarkModelObserver.
181   virtual void BookmarkModelChanged() override;
182   virtual void ExtensiveBookmarkChangesBeginning(BookmarkModel* model) override;
183   virtual void ExtensiveBookmarkChangesEnded(BookmarkModel* model) override;
184
185   // Deals with updates to the history service.
186   void OnHistoryChanged();
187
188   // Override HistoryServiceObserver.
189   virtual void OnURLVisited(HistoryService* history_service,
190                             ui::PageTransition transition,
191                             const history::URLRow& row,
192                             const history::RedirectList& redirects,
193                             base::Time visit_time) override;
194
195   // Override NotificationObserver.
196   virtual void Observe(int type,
197                        const content::NotificationSource& source,
198                        const content::NotificationDetails& details) override;
199
200   JavaObjectWeakGlobalRef weak_java_provider_;
201
202   // Profile must outlive this object.
203   //
204   // BookmarkModel, HistoryService and history::TopSites lifetime is bound to
205   // the lifetime of Profile, they are safe to use as long as the Profile is
206   // alive.
207   Profile* profile_;
208   BookmarkModel* bookmark_model_;
209   history::TopSites* top_sites_;
210
211   scoped_ptr<AndroidHistoryProviderService> service_;
212
213   base::CancelableTaskTracker cancelable_task_tracker_;
214
215   // Used to register/unregister notification observer.
216   content::NotificationRegistrar notification_registrar_;
217   ScopedObserver<HistoryService, HistoryServiceObserver>
218       history_service_observer_;
219
220   bool handling_extensive_changes_;
221
222   DISALLOW_COPY_AND_ASSIGN(ChromeBrowserProvider);
223 };
224
225 #endif  // CHROME_BROWSER_ANDROID_PROVIDER_CHROME_BROWSER_PROVIDER_H_