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