| 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_H_ | 5 #ifndef CHROME_BROWSER_ANDROID_BANNERS_APP_BANNER_INFOBAR_DELEGATE_H_ |
| 6 #define CHROME_BROWSER_ANDROID_BANNERS_APP_BANNER_INFOBAR_DELEGATE_H_ | 6 #define CHROME_BROWSER_ANDROID_BANNERS_APP_BANNER_INFOBAR_DELEGATE_H_ |
| 7 | 7 |
| 8 #include "base/android/scoped_java_ref.h" | 8 #include "base/android/scoped_java_ref.h" |
| 9 #include "base/strings/string16.h" | 9 #include "base/strings/string16.h" |
| 10 #include "components/infobars/core/confirm_infobar_delegate.h" | 10 #include "components/infobars/core/confirm_infobar_delegate.h" |
| 11 #include "content/public/common/manifest.h" |
| 11 #include "ui/gfx/image/image.h" | 12 #include "ui/gfx/image/image.h" |
| 12 #include "url/gurl.h" | 13 #include "url/gurl.h" |
| 13 | 14 |
| 14 namespace infobars { | 15 namespace infobars { |
| 15 class InfoBarManager; | 16 class InfoBarManager; |
| 16 } // namespace infobars | 17 } // namespace infobars |
| 17 | 18 |
| 18 class AppBannerInfoBar; | 19 class AppBannerInfoBar; |
| 19 | 20 |
| 20 namespace banners { | 21 namespace banners { |
| 21 | 22 |
| 22 // Displays information about an app being promoted by a webpage. | 23 // Manages installation of an app being promoted by a webpage. |
| 23 class AppBannerInfoBarDelegate : public ConfirmInfoBarDelegate { | 24 class AppBannerInfoBarDelegate : public ConfirmInfoBarDelegate { |
| 24 public: | 25 public: |
| 25 // Handles calls dealing with blocking, promoting, or grabbing info about an | |
| 26 // app. | |
| 27 class AppDelegate { | |
| 28 public: | |
| 29 // User has elected to block the banner from being displayed. | |
| 30 virtual void Block() const = 0; | |
| 31 | |
| 32 // User has clicked the button. | |
| 33 // Returns true if the infobar should be dismissed. | |
| 34 virtual bool OnButtonClicked() const = 0; | |
| 35 | |
| 36 // User has clicked the link. | |
| 37 // Returns true if the infobar should be dismissed. | |
| 38 virtual bool OnLinkClicked() const = 0; | |
| 39 | |
| 40 // Called when the infobar has been destroyed. | |
| 41 virtual void OnInfoBarDestroyed() = 0; | |
| 42 | |
| 43 // Returns the title of the app. | |
| 44 virtual base::string16 GetTitle() const = 0; | |
| 45 | |
| 46 // Returns the icon to display for the app. | |
| 47 virtual gfx::Image GetIcon() const = 0; | |
| 48 }; | |
| 49 | |
| 50 // Creates a banner for the current page that promotes a native app. | 26 // Creates a banner for the current page that promotes a native app. |
| 51 // May return nullptr if the the infobar couldn't be created. | 27 // May return nullptr if the the infobar couldn't be created. |
| 52 static AppBannerInfoBar* CreateForNativeApp( | 28 static AppBannerInfoBar* CreateForNativeApp( |
| 53 infobars::InfoBarManager* infobar_manager, | 29 infobars::InfoBarManager* infobar_manager, |
| 54 AppDelegate* delegate, | 30 const base::string16& app_title, |
| 55 const base::android::ScopedJavaGlobalRef<jobject>& japp_data); | 31 SkBitmap* app_icon, |
| 32 const base::android::ScopedJavaGlobalRef<jobject>& app_data, |
| 33 const std::string& app_package); |
| 56 | 34 |
| 57 // Creates a banner for the current page that promotes a web app. | 35 // Creates a banner for the current page that promotes a web app. |
| 58 // May return nullptr if the the infobar couldn't be created. | 36 // May return nullptr if the the infobar couldn't be created. |
| 59 static AppBannerInfoBar* CreateForWebApp( | 37 static AppBannerInfoBar* CreateForWebApp( |
| 60 infobars::InfoBarManager* infobar_manager, | 38 infobars::InfoBarManager* infobar_manager, |
| 61 AppDelegate* delegate, | 39 const base::string16& app_title, |
| 62 const GURL& url); | 40 SkBitmap* app_icon, |
| 41 const content::Manifest& web_app_data); |
| 63 | 42 |
| 64 ~AppBannerInfoBarDelegate() override; | 43 ~AppBannerInfoBarDelegate() override; |
| 65 | 44 |
| 45 // Called when the AppBannerInfoBar's button needs to be updated. |
| 46 void UpdateInstallState(JNIEnv* env, jobject obj); |
| 47 |
| 48 // Called when the installation Intent has been handled and focus has been |
| 49 // returned to Chrome. |
| 50 void OnInstallIntentReturned(JNIEnv* env, |
| 51 jobject obj, |
| 52 jboolean jis_installing); |
| 53 |
| 54 // Called when the InstallerDelegate task has finished. |
| 55 void OnInstallFinished(JNIEnv* env, |
| 56 jobject obj, |
| 57 jboolean success); |
| 58 |
| 66 // InfoBarDelegate overrides. | 59 // InfoBarDelegate overrides. |
| 67 gfx::Image GetIcon() const override; | 60 gfx::Image GetIcon() const override; |
| 68 void InfoBarDismissed() override; | 61 void InfoBarDismissed() override; |
| 69 | 62 |
| 70 // ConfirmInfoBarDelegate overrides. | 63 // ConfirmInfoBarDelegate overrides. |
| 71 base::string16 GetMessageText() const override; | 64 base::string16 GetMessageText() const override; |
| 72 int GetButtons() const override; | 65 int GetButtons() const override; |
| 73 bool Accept() override; | 66 bool Accept() override; |
| 74 bool LinkClicked(WindowOpenDisposition disposition) override; | 67 bool LinkClicked(WindowOpenDisposition disposition) override; |
| 75 | 68 |
| 76 private: | 69 private: |
| 77 explicit AppBannerInfoBarDelegate(AppDelegate* delegate); | 70 AppBannerInfoBarDelegate( |
| 71 const base::string16& app_title, |
| 72 SkBitmap* app_icon, |
| 73 const content::Manifest& web_app_data, |
| 74 const base::android::ScopedJavaGlobalRef<jobject>& native_app_data, |
| 75 const std::string& native_app_package); |
| 78 | 76 |
| 79 AppDelegate* delegate_; | 77 base::android::ScopedJavaGlobalRef<jobject> java_delegate_; |
| 78 |
| 79 base::string16 app_title_; |
| 80 scoped_ptr<SkBitmap> app_icon_; |
| 81 |
| 82 content::Manifest web_app_data_; |
| 83 |
| 84 base::android::ScopedJavaGlobalRef<jobject> native_app_data_; |
| 85 std::string native_app_package_; |
| 80 | 86 |
| 81 DISALLOW_COPY_AND_ASSIGN(AppBannerInfoBarDelegate); | 87 DISALLOW_COPY_AND_ASSIGN(AppBannerInfoBarDelegate); |
| 82 }; // AppBannerInfoBarDelegate | 88 }; // AppBannerInfoBarDelegate |
| 83 | 89 |
| 90 // Register native methods. |
| 91 bool RegisterAppBannerInfoBarDelegate(JNIEnv* env); |
| 92 |
| 84 } // namespace banners | 93 } // namespace banners |
| 85 | 94 |
| 86 bool RegisterAppBannerInfoBarDelegate(JNIEnv* env); | |
| 87 | |
| 88 #endif // CHROME_BROWSER_ANDROID_BANNERS_APP_BANNER_INFOBAR_DELEGATE_H_ | 95 #endif // CHROME_BROWSER_ANDROID_BANNERS_APP_BANNER_INFOBAR_DELEGATE_H_ |
| OLD | NEW |