| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_ANDROID_WEBAPPS_ADD_TO_HOMESCREEN_DIALOG_HELPER_H_ | |
| 6 #define CHROME_BROWSER_ANDROID_WEBAPPS_ADD_TO_HOMESCREEN_DIALOG_HELPER_H_ | |
| 7 | |
| 8 #include "base/android/jni_android.h" | |
| 9 #include "base/android/scoped_java_ref.h" | |
| 10 #include "base/macros.h" | |
| 11 #include "chrome/browser/android/webapps/add_to_homescreen_data_fetcher.h" | |
| 12 #include "third_party/skia/include/core/SkBitmap.h" | |
| 13 | |
| 14 namespace content { | |
| 15 class WebContents; | |
| 16 } | |
| 17 | |
| 18 namespace IPC { | |
| 19 class Message; | |
| 20 } | |
| 21 | |
| 22 class GURL; | |
| 23 struct ShortcutInfo; | |
| 24 | |
| 25 // AddToHomescreenDialogHelper is the C++ counterpart of | |
| 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) | |
| 28 // call and MUST BE DESTROYED via Destroy(). | |
| 29 class AddToHomescreenDialogHelper : | |
| 30 public AddToHomescreenDataFetcher::Observer { | |
| 31 public: | |
| 32 // Registers JNI hooks. | |
| 33 static bool RegisterAddToHomescreenDialogHelper(JNIEnv* env); | |
| 34 | |
| 35 AddToHomescreenDialogHelper(JNIEnv* env, | |
| 36 jobject obj, | |
| 37 content::WebContents* web_contents); | |
| 38 | |
| 39 // Called by the Java counterpart to destroy its native half. | |
| 40 void Destroy(JNIEnv* env, const base::android::JavaParamRef<jobject>& obj); | |
| 41 | |
| 42 // Adds a shortcut to the current URL to the Android home screen. | |
| 43 void AddShortcut(JNIEnv* env, | |
| 44 const base::android::JavaParamRef<jobject>& obj, | |
| 45 const base::android::JavaParamRef<jstring>& title); | |
| 46 | |
| 47 private: | |
| 48 virtual ~AddToHomescreenDialogHelper(); | |
| 49 | |
| 50 // Called only when the AddToHomescreenDataFetcher has retrieved all of the | |
| 51 // data needed to add the shortcut. | |
| 52 void AddShortcut(const ShortcutInfo& info, const SkBitmap& icon); | |
| 53 | |
| 54 void RecordAddToHomescreen(); | |
| 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. | |
| 64 base::android::ScopedJavaGlobalRef<jobject> java_ref_; | |
| 65 | |
| 66 // Whether the user has requested that a shortcut be added while a fetch was | |
| 67 // in progress. | |
| 68 bool add_shortcut_pending_; | |
| 69 | |
| 70 // Fetches data required to add a shortcut. | |
| 71 scoped_refptr<AddToHomescreenDataFetcher> data_fetcher_; | |
| 72 | |
| 73 DISALLOW_COPY_AND_ASSIGN(AddToHomescreenDialogHelper); | |
| 74 }; | |
| 75 | |
| 76 #endif // CHROME_BROWSER_ANDROID_WEBAPPS_ADD_TO_HOMESCREEN_DIALOG_HELPER_H_ | |
| OLD | NEW |