OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_ANDROID_SHORTCUT_HELPER_H_ | 5 #ifndef CHROME_BROWSER_ANDROID_WEBAPPS_ADD_TO_HOMESCREEN_DIALOG_HELPER_H_ |
6 #define CHROME_BROWSER_ANDROID_SHORTCUT_HELPER_H_ | 6 #define CHROME_BROWSER_ANDROID_WEBAPPS_ADD_TO_HOMESCREEN_DIALOG_HELPER_H_ |
7 | 7 |
8 #include "base/android/jni_android.h" | 8 #include "base/android/jni_android.h" |
9 #include "base/android/jni_weak_ref.h" | 9 #include "base/android/jni_weak_ref.h" |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "chrome/browser/android/shortcut_data_fetcher.h" | |
12 #include "chrome/browser/android/shortcut_info.h" | 11 #include "chrome/browser/android/shortcut_info.h" |
| 12 #include "chrome/browser/android/webapps/add_to_homescreen_data_fetcher.h" |
13 #include "content/public/common/manifest.h" | 13 #include "content/public/common/manifest.h" |
14 | 14 |
15 namespace content { | 15 namespace content { |
16 class WebContents; | 16 class WebContents; |
17 } // namespace content | 17 } // namespace content |
18 | 18 |
19 namespace IPC { | 19 namespace IPC { |
20 class Message; | 20 class Message; |
21 } | 21 } |
22 | 22 |
23 class GURL; | 23 class GURL; |
24 | 24 |
25 // ShortcutHelper is the C++ counterpart of org.chromium.chrome.browser's | 25 // AddToHomescreenDialogHelper is the C++ counterpart of |
26 // ShortcutHelper in Java. The object is owned by the Java object. It is created | 26 // org.chromium.chrome.browser's AddToHomescreenDialogHelper in Java. The object |
27 // from there via a JNI (Initialize) call and MUST BE DESTROYED via Destroy(). | 27 // is owned by the Java object. It is created from there via a JNI (Initialize) |
28 class ShortcutHelper : public ShortcutDataFetcher::Observer { | 28 // call and MUST BE DESTROYED via Destroy(). |
| 29 class AddToHomescreenDialogHelper : |
| 30 public AddToHomescreenDataFetcher::Observer { |
29 public: | 31 public: |
30 ShortcutHelper(JNIEnv* env, | 32 AddToHomescreenDialogHelper(JNIEnv* env, |
31 jobject obj, | 33 jobject obj, |
32 content::WebContents* web_contents); | 34 content::WebContents* web_contents); |
33 | 35 |
34 // Called by the Java counterpart to destroy its native half. | 36 // Called by the Java counterpart to destroy its native half. |
35 void Destroy(JNIEnv* env, jobject obj); | 37 void Destroy(JNIEnv* env, jobject obj); |
36 | 38 |
37 // Registers JNI hooks. | 39 // Registers JNI hooks. |
38 static bool RegisterShortcutHelper(JNIEnv* env); | 40 static bool RegisterAddToHomescreenDialogHelper(JNIEnv* env); |
39 | 41 |
40 // Adds a shortcut to the current URL to the Android home screen. | 42 // Adds a shortcut to the current URL to the Android home screen. |
41 void AddShortcut(JNIEnv* env, jobject obj, jstring title); | 43 void AddShortcut(JNIEnv* env, jobject obj, jstring title); |
42 | 44 |
43 // Adds a shortcut to the launcher using a SkBitmap. | 45 // AddToHomescreenDataFetcher::Observer |
44 // Must be called on the IO thread. | |
45 static void AddShortcutInBackgroundWithSkBitmap(const ShortcutInfo& info, | |
46 const SkBitmap& icon_bitmap); | |
47 | |
48 // ShortcutDataFetcher::Observer | |
49 void OnUserTitleAvailable(const base::string16& user_title) override; | 46 void OnUserTitleAvailable(const base::string16& user_title) override; |
50 void OnDataAvailable(const ShortcutInfo& info, const SkBitmap& icon) override; | 47 void OnDataAvailable(const ShortcutInfo& info, const SkBitmap& icon) override; |
51 SkBitmap FinalizeLauncherIcon(const SkBitmap& icon, const GURL& url) override; | 48 SkBitmap FinalizeLauncherIcon(const SkBitmap& icon, const GURL& url) override; |
52 | 49 |
53 private: | 50 private: |
54 virtual ~ShortcutHelper(); | 51 virtual ~AddToHomescreenDialogHelper(); |
55 | 52 |
56 // Called only when the ShortcutDataFetcher has retrieved all of the | 53 // Called only when the AddToHomescreenDataFetcher has retrieved all of the |
57 // data needed to add the shortcut. | 54 // data needed to add the shortcut. |
58 void AddShortcut(const ShortcutInfo& info, const SkBitmap& icon); | 55 void AddShortcut(const ShortcutInfo& info, const SkBitmap& icon); |
59 | 56 |
60 void RecordAddToHomescreen(); | 57 void RecordAddToHomescreen(); |
61 | 58 |
62 // Points to the Java object. | 59 // Points to the Java object. |
63 base::android::ScopedJavaGlobalRef<jobject> java_ref_; | 60 base::android::ScopedJavaGlobalRef<jobject> java_ref_; |
64 | 61 |
65 // Whether the user has requested that a shortcut be added while a fetch was | 62 // Whether the user has requested that a shortcut be added while a fetch was |
66 // in progress. | 63 // in progress. |
67 bool add_shortcut_pending_; | 64 bool add_shortcut_pending_; |
68 | 65 |
69 // Fetches data required to add a shortcut. | 66 // Fetches data required to add a shortcut. |
70 scoped_refptr<ShortcutDataFetcher> data_fetcher_; | 67 scoped_refptr<AddToHomescreenDataFetcher> data_fetcher_; |
71 | 68 |
72 DISALLOW_COPY_AND_ASSIGN(ShortcutHelper); | 69 DISALLOW_COPY_AND_ASSIGN(AddToHomescreenDialogHelper); |
73 }; | 70 }; |
74 | 71 |
75 #endif // CHROME_BROWSER_ANDROID_SHORTCUT_HELPER_H_ | 72 #endif // CHROME_BROWSER_ANDROID_WEBAPPS_ADD_TO_HOMESCREEN_DIALOG_HELPER_H_ |
OLD | NEW |