| 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_PROCESS_H_ |
| 6 #define CHROME_BROWSER_ANDROID_WEBAPPS_ADD_TO_HOMESCREEN_DIALOG_HELPER_H_ | 6 #define CHROME_BROWSER_ANDROID_WEBAPPS_ADD_TO_HOMESCREEN_PROCESS_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; |
| 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 // AddToHomescreenProcess is the C++ counterpart of |
| 26 // org.chromium.chrome.browser's AddToHomescreenDialogHelper in Java. The object | 28 // org.chromium.chrome.browser's AddToHomescreenProcess 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 AddToHomescreenProcess : public AddToHomescreenDataFetcher::Observer { |
| 30 public AddToHomescreenDataFetcher::Observer { | |
| 31 public: | 32 public: |
| 32 AddToHomescreenDialogHelper(JNIEnv* env, | 33 AddToHomescreenProcess(JNIEnv* env, jobject obj); |
| 33 jobject obj, | 34 |
| 34 content::WebContents* web_contents); | 35 // Registers JNI hooks. |
| 36 static bool Register(JNIEnv* env); |
| 35 | 37 |
| 36 // Called by the Java counterpart to destroy its native half. | 38 // Called by the Java counterpart to destroy its native half. |
| 37 void Destroy(JNIEnv* env, const base::android::JavaParamRef<jobject>& obj); | 39 void Destroy(JNIEnv* env, const base::android::JavaParamRef<jobject>& obj); |
| 38 | 40 |
| 39 // Registers JNI hooks. | |
| 40 static bool RegisterAddToHomescreenDialogHelper(JNIEnv* env); | |
| 41 | |
| 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 |
| 47 // AddToHomescreenDataFetcher::Observer | 46 // Starts add-to-homescreen process. |
| 48 void OnUserTitleAvailable(const base::string16& user_title) override; | 47 void Start(content::WebContents* web_contents); |
| 49 void OnDataAvailable(const ShortcutInfo& info, const SkBitmap& icon) override; | |
| 50 SkBitmap FinalizeLauncherIconInBackground(const SkBitmap& icon, | |
| 51 const GURL& url, | |
| 52 bool* is_generated) override; | |
| 53 | 48 |
| 54 private: | 49 private: |
| 55 virtual ~AddToHomescreenDialogHelper(); | 50 ~AddToHomescreenProcess() 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 // Shows alert to prompt user for name of home screen shortcut. |
| 62 void ShowDialog(); |
| 63 |
| 64 // Starts fetching home screen shortcut data (like Web Manifest and home |
| 65 // screen icon). |
| 66 void StartFetchingInfoForShortcut(content::WebContents* web_contents); |
| 56 | 67 |
| 57 // Called only when the AddToHomescreenDataFetcher has retrieved all of the | 68 // Called only when the AddToHomescreenDataFetcher has retrieved all of the |
| 58 // data needed to add the shortcut. | 69 // data needed to add the shortcut. |
| 59 void AddShortcut(const ShortcutInfo& info, const SkBitmap& icon); | 70 void AddShortcut(const ShortcutInfo& info, const SkBitmap& icon); |
| 60 | 71 |
| 61 void RecordAddToHomescreen(); | 72 void RecordAddToHomescreen(); |
| 62 | 73 |
| 74 // AddToHomescreenDataFetcher::Observer |
| 75 void OnUserTitleAvailable(const base::string16& user_title) override; |
| 76 void OnDataAvailable(const ShortcutInfo& info, const SkBitmap& icon) override; |
| 77 SkBitmap FinalizeLauncherIconInBackground(const SkBitmap& icon, |
| 78 const GURL& url, |
| 79 bool* is_generated) override; |
| 80 |
| 63 // Points to the Java object. | 81 // Points to the Java object. |
| 64 base::android::ScopedJavaGlobalRef<jobject> java_ref_; | 82 base::android::ScopedJavaGlobalRef<jobject> java_ref_; |
| 65 | 83 |
| 66 // Whether the user has requested that a shortcut be added while a fetch was | 84 // Whether the user has requested that a shortcut be added while a fetch was |
| 67 // in progress. | 85 // in progress. |
| 68 bool add_shortcut_pending_; | 86 bool add_shortcut_pending_; |
| 69 | 87 |
| 70 // Fetches data required to add a shortcut. | 88 // Fetches data required to add a shortcut. |
| 71 scoped_refptr<AddToHomescreenDataFetcher> data_fetcher_; | 89 scoped_refptr<AddToHomescreenDataFetcher> data_fetcher_; |
| 72 | 90 |
| 73 DISALLOW_COPY_AND_ASSIGN(AddToHomescreenDialogHelper); | 91 base::WeakPtrFactory<AddToHomescreenProcess> weak_ptr_factory_; |
| 92 |
| 93 DISALLOW_COPY_AND_ASSIGN(AddToHomescreenProcess); |
| 74 }; | 94 }; |
| 75 | 95 |
| 76 #endif // CHROME_BROWSER_ANDROID_WEBAPPS_ADD_TO_HOMESCREEN_DIALOG_HELPER_H_ | 96 #endif // CHROME_BROWSER_ANDROID_WEBAPPS_ADD_TO_HOMESCREEN_PROCESS_H_ |
| OLD | NEW |