OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_WEBAPPS_ADD_TO_HOMESCREEN_DIALOG_HELPER_H_ | 5 #ifndef CHROME_BROWSER_ANDROID_WEBAPPS_ADD_TO_HOMESCREEN_MANAGER_H_ |
6 #define CHROME_BROWSER_ANDROID_WEBAPPS_ADD_TO_HOMESCREEN_DIALOG_HELPER_H_ | 6 #define CHROME_BROWSER_ANDROID_WEBAPPS_ADD_TO_HOMESCREEN_MANAGER_H_ |
7 | 7 |
8 #include "base/android/jni_android.h" | 8 #include "base/android/jni_android.h" |
9 #include "base/android/scoped_java_ref.h" | 9 #include "base/android/scoped_java_ref.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "base/memory/weak_ptr.h" | |
11 #include "chrome/browser/android/webapps/add_to_homescreen_data_fetcher.h" | 12 #include "chrome/browser/android/webapps/add_to_homescreen_data_fetcher.h" |
12 #include "third_party/skia/include/core/SkBitmap.h" | |
13 | 13 |
14 namespace content { | 14 namespace content { |
15 class WebContents; | 15 class WebContents; |
16 } | 16 } |
17 | 17 |
18 namespace IPC { | 18 namespace IPC { |
19 class Message; | 19 class Message; |
dominickn
2016/08/29 00:13:37
Nit: Looks like this isn't used any more, delete.
| |
20 } | 20 } |
21 | 21 |
22 class GURL; | 22 class GURL; |
23 class SkBitmap; | |
24 struct InstallableData; | |
23 struct ShortcutInfo; | 25 struct ShortcutInfo; |
24 | 26 |
25 // AddToHomescreenDialogHelper is the C++ counterpart of | 27 // AddToHomescreenManager is the C++ counterpart of |
26 // org.chromium.chrome.browser's AddToHomescreenDialogHelper in Java. The object | 28 // org.chromium.chrome.browser's AddToHomescreenManager in Java. The object |
27 // is owned by the Java object. It is created from there via a JNI (Initialize) | 29 // is owned by the Java object. It is created from there via a JNI |
28 // call and MUST BE DESTROYED via Destroy(). | 30 // (InitializeAndStart) call and MUST BE DESTROYED via Destroy(). |
29 class AddToHomescreenDialogHelper : | 31 class AddToHomescreenManager : public AddToHomescreenDataFetcher::Observer { |
30 public AddToHomescreenDataFetcher::Observer { | |
31 public: | 32 public: |
33 AddToHomescreenManager(JNIEnv* env, jobject obj); | |
34 | |
32 // Registers JNI hooks. | 35 // Registers JNI hooks. |
33 static bool RegisterAddToHomescreenDialogHelper(JNIEnv* env); | 36 static bool Register(JNIEnv* env); |
34 | |
35 AddToHomescreenDialogHelper(JNIEnv* env, | |
36 jobject obj, | |
37 content::WebContents* web_contents); | |
38 | 37 |
39 // Called by the Java counterpart to destroy its native half. | 38 // Called by the Java counterpart to destroy its native half. |
40 void Destroy(JNIEnv* env, const base::android::JavaParamRef<jobject>& obj); | 39 void Destroy(JNIEnv* env, const base::android::JavaParamRef<jobject>& obj); |
41 | 40 |
42 // Adds a shortcut to the current URL to the Android home screen. | 41 // Adds a shortcut to the current URL to the Android home screen. |
43 void AddShortcut(JNIEnv* env, | 42 void AddShortcut(JNIEnv* env, |
44 const base::android::JavaParamRef<jobject>& obj, | 43 const base::android::JavaParamRef<jobject>& obj, |
45 const base::android::JavaParamRef<jstring>& title); | 44 const base::android::JavaParamRef<jstring>& title); |
46 | 45 |
46 // Starts add-to-homescreen process. | |
47 void Start(content::WebContents* web_contents); | |
48 | |
47 private: | 49 private: |
48 virtual ~AddToHomescreenDialogHelper(); | 50 ~AddToHomescreenManager() override; |
51 | |
52 // Checks whether the current page in |web_contents| can be made into a | |
53 // WebAPK. | |
54 void CheckWebApkCompatible(content::WebContents* web_contents); | |
55 | |
56 // Called once the request for "installability data" started by | |
57 // CheckWebApkCompatible() has completed. | |
58 void OnGotWebApkCompatibilityData(content::WebContents* web_contents, | |
59 const InstallableData& installable_data); | |
60 | |
61 // Called once it has been determined whether the current page in | |
62 // |web_contents| can be made into a WebAPK. | |
63 void OnDeterminedWebApkCompatibility(content::WebContents* web_contents, | |
64 bool is_compatible); | |
65 | |
66 // Shows alert to prompt user for name of home screen shortcut. | |
67 void ShowDialog(); | |
68 | |
69 // Starts fetching home screen shortcut data (like Web Manifest and home | |
70 // screen icon). | |
71 void StartFetchingInfoForShortcut(content::WebContents* web_contents); | |
49 | 72 |
50 // Called only when the AddToHomescreenDataFetcher has retrieved all of the | 73 // Called only when the AddToHomescreenDataFetcher has retrieved all of the |
51 // data needed to add the shortcut. | 74 // data needed to add the shortcut. |
52 void AddShortcut(const ShortcutInfo& info, const SkBitmap& icon); | 75 void AddShortcut(const ShortcutInfo& info, const SkBitmap& icon); |
53 | 76 |
54 void RecordAddToHomescreen(); | 77 void RecordAddToHomescreen(); |
55 | 78 |
56 // AddToHomescreenDataFetcher::Observer: | 79 // AddToHomescreenDataFetcher::Observer: |
57 void OnUserTitleAvailable(const base::string16& user_title) override; | 80 void OnUserTitleAvailable(const base::string16& user_title) override; |
58 void OnDataAvailable(const ShortcutInfo& info, const SkBitmap& icon) override; | 81 void OnDataAvailable(const ShortcutInfo& info, const SkBitmap& icon) override; |
59 SkBitmap FinalizeLauncherIconInBackground(const SkBitmap& icon, | 82 SkBitmap FinalizeLauncherIconInBackground(const SkBitmap& icon, |
60 const GURL& url, | 83 const GURL& url, |
61 bool* is_generated) override; | 84 bool* is_generated) override; |
62 | 85 |
63 // Points to the Java object. | 86 // Points to the Java object. |
64 base::android::ScopedJavaGlobalRef<jobject> java_ref_; | 87 base::android::ScopedJavaGlobalRef<jobject> java_ref_; |
65 | 88 |
66 // Whether the user has requested that a shortcut be added while a fetch was | 89 // Whether the user has requested that a shortcut be added while a fetch was |
67 // in progress. | 90 // in progress. |
68 bool add_shortcut_pending_; | 91 bool add_shortcut_pending_; |
69 | 92 |
70 // Fetches data required to add a shortcut. | 93 // Fetches data required to add a shortcut. |
71 scoped_refptr<AddToHomescreenDataFetcher> data_fetcher_; | 94 scoped_refptr<AddToHomescreenDataFetcher> data_fetcher_; |
72 | 95 |
73 DISALLOW_COPY_AND_ASSIGN(AddToHomescreenDialogHelper); | 96 base::WeakPtrFactory<AddToHomescreenManager> weak_ptr_factory_; |
97 | |
98 DISALLOW_COPY_AND_ASSIGN(AddToHomescreenManager); | |
74 }; | 99 }; |
75 | 100 |
76 #endif // CHROME_BROWSER_ANDROID_WEBAPPS_ADD_TO_HOMESCREEN_DIALOG_HELPER_H_ | 101 #endif // CHROME_BROWSER_ANDROID_WEBAPPS_ADD_TO_HOMESCREEN_MANAGER_H_ |
OLD | NEW |