| 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_BANNERS_APP_BANNER_INFOBAR_DELEGATE_ANDROID_H_ | 5 #ifndef CHROME_BROWSER_ANDROID_BANNERS_APP_BANNER_INFOBAR_DELEGATE_ANDROID_H_ |
| 6 #define CHROME_BROWSER_ANDROID_BANNERS_APP_BANNER_INFOBAR_DELEGATE_ANDROID_H_ | 6 #define CHROME_BROWSER_ANDROID_BANNERS_APP_BANNER_INFOBAR_DELEGATE_ANDROID_H_ |
| 7 | 7 |
| 8 #include "base/android/scoped_java_ref.h" | 8 #include "base/android/scoped_java_ref.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
| 11 #include "base/strings/string16.h" | 11 #include "base/strings/string16.h" |
| 12 #include "chrome/browser/banners/app_banner_manager.h" | 12 #include "chrome/browser/banners/app_banner_manager.h" |
| 13 #include "components/infobars/core/confirm_infobar_delegate.h" | 13 #include "components/infobars/core/confirm_infobar_delegate.h" |
| 14 #include "content/public/common/manifest.h" | |
| 15 #include "ui/gfx/image/image.h" | 14 #include "ui/gfx/image/image.h" |
| 16 #include "url/gurl.h" | 15 #include "url/gurl.h" |
| 17 | 16 |
| 18 namespace content { | 17 namespace content { |
| 19 class WebContents; | 18 class WebContents; |
| 20 } | 19 } |
| 21 | 20 |
| 22 namespace infobars { | 21 namespace infobars { |
| 23 class InfoBarManager; | 22 class InfoBarManager; |
| 24 } | 23 } |
| 25 | 24 |
| 26 class AppBannerInfoBar; | 25 class AppBannerInfoBar; |
| 26 struct ShortcutInfo; |
| 27 | 27 |
| 28 namespace banners { | 28 namespace banners { |
| 29 | 29 |
| 30 // Manages installation of an app being promoted by a page. | 30 // Manages installation of an app being promoted by a page. |
| 31 class AppBannerInfoBarDelegateAndroid : public ConfirmInfoBarDelegate { | 31 class AppBannerInfoBarDelegateAndroid : public ConfirmInfoBarDelegate { |
| 32 public: | 32 public: |
| 33 // Delegate for promoting a web app. | 33 // Creates an infobar and delegate for promoting the installation of a web |
| 34 AppBannerInfoBarDelegateAndroid( | 34 // app, and adds the infobar to the InfoBarManager for |web_contents|. |
| 35 static bool Create( |
| 36 content::WebContents* web_contents, |
| 35 base::WeakPtr<AppBannerManager> weak_manager, | 37 base::WeakPtr<AppBannerManager> weak_manager, |
| 36 const base::string16& app_title, | 38 const base::string16& app_title, |
| 37 const GURL& manifest_url, | 39 std::unique_ptr<ShortcutInfo> info, |
| 38 const content::Manifest& manifest, | |
| 39 const GURL& icon_url, | |
| 40 std::unique_ptr<SkBitmap> icon, | 40 std::unique_ptr<SkBitmap> icon, |
| 41 int event_request_id, | 41 int event_request_id, |
| 42 bool is_webapk); | 42 bool is_webapk, |
| 43 bool start_install_webapk); |
| 43 | 44 |
| 44 // Delegate for promoting an Android app. | 45 // Creates and shows the infobar for an Android app. |
| 45 AppBannerInfoBarDelegateAndroid( | 46 // Creates an infobar and delegate for promoting the installation of an |
| 47 // Android app, and adds the infobar to the InfoBarManager for |web_contents|. |
| 48 static bool Create( |
| 49 content::WebContents* web_contents, |
| 46 const base::string16& app_title, | 50 const base::string16& app_title, |
| 47 const base::android::ScopedJavaGlobalRef<jobject>& native_app_data, | 51 const base::android::ScopedJavaGlobalRef<jobject>& native_app_data, |
| 48 std::unique_ptr<SkBitmap> icon, | 52 std::unique_ptr<SkBitmap> icon, |
| 49 const std::string& native_app_package, | 53 const std::string& native_app_package, |
| 50 const std::string& referrer, | 54 const std::string& referrer, |
| 51 int event_request_id); | 55 int event_request_id); |
| 52 | 56 |
| 53 ~AppBannerInfoBarDelegateAndroid() override; | 57 ~AppBannerInfoBarDelegateAndroid() override; |
| 54 | 58 |
| 55 // Called when the AppBannerInfoBar's button needs to be updated. | 59 // Called when the AppBannerInfoBar's button needs to be updated. |
| 56 void UpdateInstallState(JNIEnv* env, | 60 void UpdateInstallState(JNIEnv* env, |
| 57 const base::android::JavaParamRef<jobject>& obj); | 61 const base::android::JavaParamRef<jobject>& obj); |
| 58 | 62 |
| 59 // Called when the installation Intent has been handled and focus has been | 63 // Called when the installation Intent has been handled and focus has been |
| 60 // returned to Chrome. | 64 // returned to Chrome. |
| 61 void OnInstallIntentReturned(JNIEnv* env, | 65 void OnInstallIntentReturned(JNIEnv* env, |
| 62 const base::android::JavaParamRef<jobject>& obj, | 66 const base::android::JavaParamRef<jobject>& obj, |
| 63 jboolean jis_installing); | 67 jboolean jis_installing); |
| 64 | 68 |
| 65 // Called when the InstallerDelegate task has finished. | 69 // Called when the InstallerDelegate task has finished. |
| 66 void OnInstallFinished(JNIEnv* env, | 70 void OnInstallFinished(JNIEnv* env, |
| 67 const base::android::JavaParamRef<jobject>& obj, | 71 const base::android::JavaParamRef<jobject>& obj, |
| 68 jboolean success); | 72 jboolean success); |
| 69 | 73 |
| 74 // When user accepts to install a WebAPK, this function sends a request |
| 75 // to the WebAPK Server to create a WebAPK and install it. It returns |
| 76 // false to prevent infobar from disappearing when installation starts. |
| 77 // When user clicks the Open button after the intallation is compelete, this |
| 78 // function launches the installed WebAPK and returns true. |
| 79 bool AcceptWebApk(content::WebContents* web_contents); |
| 80 |
| 70 private: | 81 private: |
| 82 // Delegate for promoting a web app. |
| 83 AppBannerInfoBarDelegateAndroid( |
| 84 base::WeakPtr<AppBannerManager> weak_manager, |
| 85 const base::string16& app_title, |
| 86 std::unique_ptr<ShortcutInfo> info, |
| 87 std::unique_ptr<SkBitmap> icon, |
| 88 int event_request_id, |
| 89 bool is_webapk); |
| 90 |
| 91 // Delegate for promoting an Android app. |
| 92 AppBannerInfoBarDelegateAndroid( |
| 93 const base::string16& app_title, |
| 94 const base::android::ScopedJavaGlobalRef<jobject>& native_app_data, |
| 95 std::unique_ptr<SkBitmap> icon, |
| 96 const std::string& native_app_package, |
| 97 const std::string& referrer, |
| 98 int event_request_id); |
| 99 |
| 71 void CreateJavaDelegate(); | 100 void CreateJavaDelegate(); |
| 72 bool AcceptNativeApp(content::WebContents* web_contents); | 101 bool AcceptNativeApp(content::WebContents* web_contents); |
| 73 bool AcceptWebApp(content::WebContents* web_contents); | 102 bool AcceptWebApp(content::WebContents* web_contents); |
| 74 bool AcceptWebApk(content::WebContents* web_contents); | |
| 75 void SendBannerAccepted(content::WebContents* web_contents, | 103 void SendBannerAccepted(content::WebContents* web_contents, |
| 76 const std::string& platform); | 104 const std::string& platform); |
| 77 void OnWebApkInstallFinished(bool success, const std::string& webapk_package); | 105 void OnWebApkInstallFinished(bool success, const std::string& webapk_package); |
| 78 | 106 |
| 79 // ConfirmInfoBarDelegate: | 107 // ConfirmInfoBarDelegate: |
| 80 infobars::InfoBarDelegate::InfoBarIdentifier GetIdentifier() const override; | 108 infobars::InfoBarDelegate::InfoBarIdentifier GetIdentifier() const override; |
| 81 gfx::Image GetIcon() const override; | 109 gfx::Image GetIcon() const override; |
| 82 void InfoBarDismissed() override; | 110 void InfoBarDismissed() override; |
| 83 base::string16 GetMessageText() const override; | 111 base::string16 GetMessageText() const override; |
| 84 int GetButtons() const override; | 112 int GetButtons() const override; |
| 85 bool Accept() override; | 113 bool Accept() override; |
| 86 bool LinkClicked(WindowOpenDisposition disposition) override; | 114 bool LinkClicked(WindowOpenDisposition disposition) override; |
| 87 | 115 |
| 88 base::android::ScopedJavaGlobalRef<jobject> java_delegate_; | 116 base::android::ScopedJavaGlobalRef<jobject> java_delegate_; |
| 89 | 117 |
| 90 // Used to fetch the splash screen icon for webapps. | 118 // Used to fetch the splash screen icon for webapps. |
| 91 base::WeakPtr<AppBannerManager> weak_manager_; | 119 base::WeakPtr<AppBannerManager> weak_manager_; |
| 92 | 120 |
| 93 base::string16 app_title_; | 121 base::string16 app_title_; |
| 94 GURL manifest_url_; | 122 std::unique_ptr<ShortcutInfo> shortcut_info_; |
| 95 content::Manifest manifest_; | |
| 96 | 123 |
| 97 base::android::ScopedJavaGlobalRef<jobject> native_app_data_; | 124 base::android::ScopedJavaGlobalRef<jobject> native_app_data_; |
| 98 | 125 |
| 99 GURL icon_url_; | |
| 100 std::unique_ptr<SkBitmap> icon_; | 126 std::unique_ptr<SkBitmap> icon_; |
| 101 | 127 |
| 102 std::string native_app_package_; | 128 std::string native_app_package_; |
| 103 std::string referrer_; | 129 std::string referrer_; |
| 104 int event_request_id_; | 130 int event_request_id_; |
| 105 bool has_user_interaction_; | 131 bool has_user_interaction_; |
| 106 | 132 |
| 107 std::string webapk_package_name_; | 133 std::string webapk_package_name_; |
| 108 bool is_webapk_; | 134 bool is_webapk_; |
| 109 | 135 |
| 110 base::WeakPtrFactory<AppBannerInfoBarDelegateAndroid> weak_ptr_factory_; | 136 base::WeakPtrFactory<AppBannerInfoBarDelegateAndroid> weak_ptr_factory_; |
| 111 | 137 |
| 112 DISALLOW_COPY_AND_ASSIGN(AppBannerInfoBarDelegateAndroid); | 138 DISALLOW_COPY_AND_ASSIGN(AppBannerInfoBarDelegateAndroid); |
| 113 }; // AppBannerInfoBarDelegateAndroid | 139 }; |
| 114 | 140 |
| 115 // Register native methods. | 141 // Register native methods. |
| 116 bool RegisterAppBannerInfoBarDelegateAndroid(JNIEnv* env); | 142 bool RegisterAppBannerInfoBarDelegateAndroid(JNIEnv* env); |
| 117 | 143 |
| 118 } // namespace banners | 144 } // namespace banners |
| 119 | 145 |
| 120 #endif // CHROME_BROWSER_ANDROID_BANNERS_APP_BANNER_INFOBAR_DELEGATE_ANDROID_H_ | 146 #endif // CHROME_BROWSER_ANDROID_BANNERS_APP_BANNER_INFOBAR_DELEGATE_ANDROID_H_ |
| OLD | NEW |