| 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" | 14 #include "content/public/common/manifest.h" |
| 15 #include "ui/gfx/image/image.h" | 15 #include "ui/gfx/image/image.h" |
| 16 #include "url/gurl.h" | 16 #include "url/gurl.h" |
| 17 | 17 |
| 18 namespace content { | 18 namespace content { |
| 19 class WebContents; | 19 class WebContents; |
| 20 } | 20 } |
| 21 | 21 |
| 22 namespace infobars { | 22 namespace infobars { |
| 23 class InfoBarManager; | 23 class InfoBarManager; |
| 24 } | 24 } |
| 25 | 25 |
| 26 class AppBannerInfoBar; | 26 class AppBannerInfoBar; |
| 27 struct ShortcutInfo; |
| 27 | 28 |
| 28 namespace banners { | 29 namespace banners { |
| 29 | 30 |
| 30 // Manages installation of an app being promoted by a page. | 31 // Manages installation of an app being promoted by a page. |
| 31 class AppBannerInfoBarDelegateAndroid : public ConfirmInfoBarDelegate { | 32 class AppBannerInfoBarDelegateAndroid : public ConfirmInfoBarDelegate { |
| 32 public: | 33 public: |
| 33 // Delegate for promoting a web app. | 34 // Delegate for promoting a web app. |
| 34 AppBannerInfoBarDelegateAndroid( | 35 AppBannerInfoBarDelegateAndroid( |
| 35 base::WeakPtr<AppBannerManager> weak_manager, | 36 base::WeakPtr<AppBannerManager> weak_manager, |
| 36 const base::string16& app_title, | 37 const base::string16& app_title, |
| 37 const GURL& manifest_url, | 38 const GURL& manifest_url, |
| 39 std::unique_ptr<ShortcutInfo> info, |
| 40 const GURL& icon_url, |
| 41 std::unique_ptr<SkBitmap> icon, |
| 42 int event_request_id, |
| 43 bool is_webapk); |
| 44 |
| 45 // Delegate for promoting a web app. |
| 46 AppBannerInfoBarDelegateAndroid( |
| 47 base::WeakPtr<AppBannerManager> weak_manager, |
| 48 const base::string16& app_title, |
| 49 const GURL& manifest_url, |
| 38 const content::Manifest& manifest, | 50 const content::Manifest& manifest, |
| 39 const GURL& icon_url, | 51 const GURL& icon_url, |
| 40 std::unique_ptr<SkBitmap> icon, | 52 std::unique_ptr<SkBitmap> icon, |
| 41 int event_request_id, | 53 int event_request_id, |
| 42 bool is_webapk); | 54 bool is_webapk); |
| 43 | 55 |
| 44 // Delegate for promoting an Android app. | 56 // Delegate for promoting an Android app. |
| 45 AppBannerInfoBarDelegateAndroid( | 57 AppBannerInfoBarDelegateAndroid( |
| 46 const base::string16& app_title, | 58 const base::string16& app_title, |
| 47 const base::android::ScopedJavaGlobalRef<jobject>& native_app_data, | 59 const base::android::ScopedJavaGlobalRef<jobject>& native_app_data, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 60 // returned to Chrome. | 72 // returned to Chrome. |
| 61 void OnInstallIntentReturned(JNIEnv* env, | 73 void OnInstallIntentReturned(JNIEnv* env, |
| 62 const base::android::JavaParamRef<jobject>& obj, | 74 const base::android::JavaParamRef<jobject>& obj, |
| 63 jboolean jis_installing); | 75 jboolean jis_installing); |
| 64 | 76 |
| 65 // Called when the InstallerDelegate task has finished. | 77 // Called when the InstallerDelegate task has finished. |
| 66 void OnInstallFinished(JNIEnv* env, | 78 void OnInstallFinished(JNIEnv* env, |
| 67 const base::android::JavaParamRef<jobject>& obj, | 79 const base::android::JavaParamRef<jobject>& obj, |
| 68 jboolean success); | 80 jboolean success); |
| 69 | 81 |
| 82 // Called when user clicks the "Add To Homescreen" from the app menu to |
| 83 // install a WebAPK. This function sets the text on infobar to "Adding" and |
| 84 // disables the button to avoid user interaction. It also starts the WebAPK's |
| 85 // installation process automatically. |
| 86 void InstallWebApk(content::WebContents* web_contents); |
| 87 |
| 70 private: | 88 private: |
| 71 void CreateJavaDelegate(); | 89 void CreateJavaDelegate(); |
| 72 bool AcceptNativeApp(content::WebContents* web_contents); | 90 bool AcceptNativeApp(content::WebContents* web_contents); |
| 73 bool AcceptWebApp(content::WebContents* web_contents); | 91 bool AcceptWebApp(content::WebContents* web_contents); |
| 74 bool AcceptWebApk(content::WebContents* web_contents); | 92 bool AcceptWebApk(content::WebContents* web_contents); |
| 75 void SendBannerAccepted(content::WebContents* web_contents, | 93 void SendBannerAccepted(content::WebContents* web_contents, |
| 76 const std::string& platform); | 94 const std::string& platform); |
| 77 void OnWebApkInstallFinished(bool success, const std::string& webapk_package); | 95 void OnWebApkInstallFinished(bool success, const std::string& webapk_package); |
| 78 | 96 |
| 79 // ConfirmInfoBarDelegate: | 97 // ConfirmInfoBarDelegate: |
| 80 infobars::InfoBarDelegate::InfoBarIdentifier GetIdentifier() const override; | 98 infobars::InfoBarDelegate::InfoBarIdentifier GetIdentifier() const override; |
| 81 gfx::Image GetIcon() const override; | 99 gfx::Image GetIcon() const override; |
| 82 void InfoBarDismissed() override; | 100 void InfoBarDismissed() override; |
| 83 base::string16 GetMessageText() const override; | 101 base::string16 GetMessageText() const override; |
| 84 int GetButtons() const override; | 102 int GetButtons() const override; |
| 85 bool Accept() override; | 103 bool Accept() override; |
| 86 bool LinkClicked(WindowOpenDisposition disposition) override; | 104 bool LinkClicked(WindowOpenDisposition disposition) override; |
| 105 AppBannerInfoBarDelegateAndroid* AsAppBannerInfoBarDelegateAndroid() override; |
| 87 | 106 |
| 88 base::android::ScopedJavaGlobalRef<jobject> java_delegate_; | 107 base::android::ScopedJavaGlobalRef<jobject> java_delegate_; |
| 89 | 108 |
| 90 // Used to fetch the splash screen icon for webapps. | 109 // Used to fetch the splash screen icon for webapps. |
| 91 base::WeakPtr<AppBannerManager> weak_manager_; | 110 base::WeakPtr<AppBannerManager> weak_manager_; |
| 92 | 111 |
| 93 base::string16 app_title_; | 112 base::string16 app_title_; |
| 94 GURL manifest_url_; | 113 GURL manifest_url_; |
| 95 content::Manifest manifest_; | 114 std::unique_ptr<ShortcutInfo> shortcut_info_; |
| 96 | 115 |
| 97 base::android::ScopedJavaGlobalRef<jobject> native_app_data_; | 116 base::android::ScopedJavaGlobalRef<jobject> native_app_data_; |
| 98 | 117 |
| 99 GURL icon_url_; | 118 GURL icon_url_; |
| 100 std::unique_ptr<SkBitmap> icon_; | 119 std::unique_ptr<SkBitmap> icon_; |
| 101 | 120 |
| 102 std::string native_app_package_; | 121 std::string native_app_package_; |
| 103 std::string referrer_; | 122 std::string referrer_; |
| 104 int event_request_id_; | 123 int event_request_id_; |
| 105 bool has_user_interaction_; | 124 bool has_user_interaction_; |
| 106 | 125 |
| 107 std::string webapk_package_name_; | 126 std::string webapk_package_name_; |
| 108 bool is_webapk_; | 127 bool is_webapk_; |
| 109 | 128 |
| 110 base::WeakPtrFactory<AppBannerInfoBarDelegateAndroid> weak_ptr_factory_; | 129 base::WeakPtrFactory<AppBannerInfoBarDelegateAndroid> weak_ptr_factory_; |
| 111 | 130 |
| 112 DISALLOW_COPY_AND_ASSIGN(AppBannerInfoBarDelegateAndroid); | 131 DISALLOW_COPY_AND_ASSIGN(AppBannerInfoBarDelegateAndroid); |
| 113 }; // AppBannerInfoBarDelegateAndroid | 132 }; // AppBannerInfoBarDelegateAndroid |
| 114 | 133 |
| 115 // Register native methods. | 134 // Register native methods. |
| 116 bool RegisterAppBannerInfoBarDelegateAndroid(JNIEnv* env); | 135 bool RegisterAppBannerInfoBarDelegateAndroid(JNIEnv* env); |
| 117 | 136 |
| 118 } // namespace banners | 137 } // namespace banners |
| 119 | 138 |
| 120 #endif // CHROME_BROWSER_ANDROID_BANNERS_APP_BANNER_INFOBAR_DELEGATE_ANDROID_H_ | 139 #endif // CHROME_BROWSER_ANDROID_BANNERS_APP_BANNER_INFOBAR_DELEGATE_ANDROID_H_ |
| OLD | NEW |