Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 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_WEBAPPS_ADD_TO_HOMESCREEN_DIALOG_HELPER_H_ | 5 #ifndef CHROME_BROWSER_ANDROID_WEBAPPS_ADD_TO_HOMESCREEN_DIALOG_HELPER_H_ |
| 6 #define CHROME_BROWSER_ANDROID_WEBAPPS_ADD_TO_HOMESCREEN_DIALOG_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/scoped_java_ref.h" | 9 #include "base/android/scoped_java_ref.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 26 // org.chromium.chrome.browser's AddToHomescreenDialogHelper in Java. The object | 26 // org.chromium.chrome.browser's AddToHomescreenDialogHelper in Java. The object |
| 27 // is owned by the Java object. It is created from there via a JNI (Initialize) | 27 // is owned by the Java object. It is created from there via a JNI (Initialize) |
| 28 // call and MUST BE DESTROYED via Destroy(). | 28 // call and MUST BE DESTROYED via Destroy(). |
| 29 class AddToHomescreenDialogHelper : | 29 class AddToHomescreenDialogHelper : |
| 30 public AddToHomescreenDataFetcher::Observer { | 30 public AddToHomescreenDataFetcher::Observer { |
| 31 public: | 31 public: |
| 32 AddToHomescreenDialogHelper(JNIEnv* env, | 32 AddToHomescreenDialogHelper(JNIEnv* env, |
| 33 jobject obj, | 33 jobject obj, |
| 34 content::WebContents* web_contents); | 34 content::WebContents* web_contents); |
| 35 | 35 |
| 36 // Registers JNI hooks. | |
|
dominickn
2016/08/24 22:58:16
Nit: I would order the static method above the con
pkotwicz
2016/08/24 23:14:50
Done.
| |
| 37 static bool RegisterAddToHomescreenDialogHelper(JNIEnv* env); | |
| 38 | |
| 36 // Called by the Java counterpart to destroy its native half. | 39 // Called by the Java counterpart to destroy its native half. |
| 37 void Destroy(JNIEnv* env, const base::android::JavaParamRef<jobject>& obj); | 40 void Destroy(JNIEnv* env, const base::android::JavaParamRef<jobject>& obj); |
| 38 | 41 |
| 39 // Registers JNI hooks. | |
| 40 static bool RegisterAddToHomescreenDialogHelper(JNIEnv* env); | |
| 41 | |
| 42 // 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. |
| 43 void AddShortcut(JNIEnv* env, | 43 void AddShortcut(JNIEnv* env, |
| 44 const base::android::JavaParamRef<jobject>& obj, | 44 const base::android::JavaParamRef<jobject>& obj, |
| 45 const base::android::JavaParamRef<jstring>& title); | 45 const base::android::JavaParamRef<jstring>& title); |
| 46 | 46 |
| 47 // AddToHomescreenDataFetcher::Observer | |
| 48 void OnUserTitleAvailable(const base::string16& user_title) override; | |
| 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 | |
| 54 private: | 47 private: |
| 55 virtual ~AddToHomescreenDialogHelper(); | 48 virtual ~AddToHomescreenDialogHelper(); |
|
dominickn
2016/08/24 22:58:16
Just realised that this has a private virtual dest
pkotwicz
2016/08/24 23:14:50
Making the destructor private seems like a common
dominickn
2016/08/25 00:16:04
I'm not fussed about the destructor being private
| |
| 56 | 49 |
| 57 // Called only when the AddToHomescreenDataFetcher has retrieved all of the | 50 // Called only when the AddToHomescreenDataFetcher has retrieved all of the |
| 58 // data needed to add the shortcut. | 51 // data needed to add the shortcut. |
| 59 void AddShortcut(const ShortcutInfo& info, const SkBitmap& icon); | 52 void AddShortcut(const ShortcutInfo& info, const SkBitmap& icon); |
| 60 | 53 |
| 61 void RecordAddToHomescreen(); | 54 void RecordAddToHomescreen(); |
| 62 | 55 |
| 56 // AddToHomescreenDataFetcher::Observer: | |
| 57 void OnUserTitleAvailable(const base::string16& user_title) override; | |
| 58 void OnDataAvailable(const ShortcutInfo& info, const SkBitmap& icon) override; | |
| 59 SkBitmap FinalizeLauncherIconInBackground(const SkBitmap& icon, | |
| 60 const GURL& url, | |
| 61 bool* is_generated) override; | |
| 62 | |
| 63 // Points to the Java object. | 63 // Points to the Java object. |
| 64 base::android::ScopedJavaGlobalRef<jobject> java_ref_; | 64 base::android::ScopedJavaGlobalRef<jobject> java_ref_; |
| 65 | 65 |
| 66 // Whether the user has requested that a shortcut be added while a fetch was | 66 // Whether the user has requested that a shortcut be added while a fetch was |
| 67 // in progress. | 67 // in progress. |
| 68 bool add_shortcut_pending_; | 68 bool add_shortcut_pending_; |
| 69 | 69 |
| 70 // Fetches data required to add a shortcut. | 70 // Fetches data required to add a shortcut. |
| 71 scoped_refptr<AddToHomescreenDataFetcher> data_fetcher_; | 71 scoped_refptr<AddToHomescreenDataFetcher> data_fetcher_; |
| 72 | 72 |
| 73 DISALLOW_COPY_AND_ASSIGN(AddToHomescreenDialogHelper); | 73 DISALLOW_COPY_AND_ASSIGN(AddToHomescreenDialogHelper); |
| 74 }; | 74 }; |
| 75 | 75 |
| 76 #endif // CHROME_BROWSER_ANDROID_WEBAPPS_ADD_TO_HOMESCREEN_DIALOG_HELPER_H_ | 76 #endif // CHROME_BROWSER_ANDROID_WEBAPPS_ADD_TO_HOMESCREEN_DIALOG_HELPER_H_ |
| OLD | NEW |