| 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/strings/string16.h" | 9 #include "base/strings/string16.h" |
| 9 #include "components/infobars/core/confirm_infobar_delegate.h" | 10 #include "components/infobars/core/confirm_infobar_delegate.h" |
| 10 #include "ui/gfx/image/image.h" | 11 #include "ui/gfx/image/image.h" |
| 11 #include "url/gurl.h" | 12 #include "url/gurl.h" |
| 12 | 13 |
| 13 namespace infobars { | 14 namespace infobars { |
| 14 class InfoBarManager; | 15 class InfoBarManager; |
| 15 } // namespace infobars | 16 } // namespace infobars |
| 16 | 17 |
| 18 class AppBannerInfoBar; |
| 19 |
| 17 namespace banners { | 20 namespace banners { |
| 18 | 21 |
| 19 // Displays information about an app being promoted by a webpage. | 22 // Displays information about an app being promoted by a webpage. |
| 20 class AppBannerInfoBarDelegate : public ConfirmInfoBarDelegate { | 23 class AppBannerInfoBarDelegate : public ConfirmInfoBarDelegate { |
| 21 public: | 24 public: |
| 22 // Handles calls dealing with blocking, promoting, or grabbing info about an | 25 // Handles calls dealing with blocking, promoting, or grabbing info about an |
| 23 // app. | 26 // app. |
| 24 class AppDelegate { | 27 class AppDelegate { |
| 25 public: | 28 public: |
| 26 // User has elected to block the banner from being displayed. | 29 // User has elected to block the banner from being displayed. |
| 27 virtual void Block() const = 0; | 30 virtual void Block() const = 0; |
| 28 | 31 |
| 29 // User has requested that the app be installed. | 32 // User has clicked the button. |
| 30 virtual void Install() const = 0; | 33 // Returns true if the infobar should be dismissed. |
| 34 virtual bool OnButtonClicked() const = 0; |
| 31 | 35 |
| 32 // Icon to display for the app. | 36 // Called when the infobar has been destroyed. |
| 37 virtual void OnInfoBarDestroyed() = 0; |
| 38 |
| 39 // Returns the title of the app. |
| 40 virtual base::string16 GetTitle() const = 0; |
| 41 |
| 42 // Returns the icon to display for the app. |
| 33 virtual gfx::Image GetIcon() const = 0; | 43 virtual gfx::Image GetIcon() const = 0; |
| 34 }; | 44 }; |
| 35 | 45 |
| 36 // Creates a banner for the current page. | 46 // Creates a banner for the current page that promotes a web app. |
| 37 // May return nullptr if the the infobar couldn't be created. | 47 // May return nullptr if the the infobar couldn't be created. |
| 38 static infobars::InfoBar* CreateForWebApp( | 48 static AppBannerInfoBar* CreateForWebApp( |
| 39 infobars::InfoBarManager* infobar_manager, | 49 infobars::InfoBarManager* infobar_manager, |
| 40 const AppDelegate* delegate, | 50 AppDelegate* delegate, |
| 41 const base::string16& app_title, | |
| 42 const GURL& url); | 51 const GURL& url); |
| 43 | 52 |
| 44 ~AppBannerInfoBarDelegate() override; | 53 ~AppBannerInfoBarDelegate() override; |
| 45 | 54 |
| 46 // Changes the label of the button. | |
| 47 void SetButtonLabel(const std::string& button_text); | |
| 48 | |
| 49 // InfoBarDelegate overrides. | 55 // InfoBarDelegate overrides. |
| 50 gfx::Image GetIcon() const override; | 56 gfx::Image GetIcon() const override; |
| 51 void InfoBarDismissed() override; | 57 void InfoBarDismissed() override; |
| 52 | 58 |
| 53 // ConfirmInfoBarDelegate overrides. | 59 // ConfirmInfoBarDelegate overrides. |
| 54 base::string16 GetMessageText() const override; | 60 base::string16 GetMessageText() const override; |
| 55 int GetButtons() const override; | 61 int GetButtons() const override; |
| 56 base::string16 GetButtonLabel(InfoBarButton button) const override; | |
| 57 bool Accept() override; | 62 bool Accept() override; |
| 58 | 63 |
| 59 private: | 64 private: |
| 60 // Constructor for a banner for web apps. | 65 explicit AppBannerInfoBarDelegate(AppDelegate* delegate); |
| 61 AppBannerInfoBarDelegate(const AppDelegate* helper, | |
| 62 const base::string16& app_title, | |
| 63 const GURL& url); | |
| 64 | 66 |
| 65 const AppDelegate* delegate_; | 67 AppDelegate* delegate_; |
| 66 base::string16 app_title_; | |
| 67 GURL url_; | |
| 68 base::string16 button_text_; | |
| 69 | 68 |
| 70 DISALLOW_COPY_AND_ASSIGN(AppBannerInfoBarDelegate); | 69 DISALLOW_COPY_AND_ASSIGN(AppBannerInfoBarDelegate); |
| 71 }; // AppBannerInfoBarDelegate | 70 }; // AppBannerInfoBarDelegate |
| 72 | 71 |
| 73 } // namespace banners | 72 } // namespace banners |
| 74 | 73 |
| 75 bool RegisterAppBannerInfoBarDelegate(JNIEnv* env); | 74 bool RegisterAppBannerInfoBarDelegate(JNIEnv* env); |
| 76 | 75 |
| 77 #endif // CHROME_BROWSER_ANDROID_BANNERS_APP_BANNER_INFOBAR_DELEGATE_H_ | 76 #endif // CHROME_BROWSER_ANDROID_BANNERS_APP_BANNER_INFOBAR_DELEGATE_H_ |
| OLD | NEW |