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 #include "chrome/browser/banners/app_banner_infobar_delegate_desktop.h" |
| 6 |
| 7 #include "chrome/browser/banners/app_banner_data_fetcher_desktop.h" |
| 8 #include "chrome/browser/banners/app_banner_metrics.h" |
| 9 #include "chrome/browser/banners/app_banner_settings_helper.h" |
| 10 #include "chrome/browser/extensions/bookmark_app_helper.h" |
| 11 #include "chrome/browser/infobars/infobar_service.h" |
| 12 #include "chrome/common/render_messages.h" |
| 13 #include "chrome/grit/generated_resources.h" |
| 14 #include "components/infobars/core/infobar.h" |
| 15 #include "content/public/browser/render_frame_host.h" |
| 16 #include "content/public/browser/web_contents.h" |
| 17 #include "grit/theme_resources.h" |
| 18 #include "ui/base/l10n/l10n_util.h" |
| 19 |
| 20 namespace banners { |
| 21 |
| 22 AppBannerInfoBarDelegateDesktop::AppBannerInfoBarDelegateDesktop( |
| 23 scoped_refptr<AppBannerDataFetcherDesktop> fetcher, |
| 24 const content::Manifest& web_manifest, |
| 25 extensions::BookmarkAppHelper* bookmark_app_helper, |
| 26 int event_request_id) |
| 27 : ConfirmInfoBarDelegate(), |
| 28 fetcher_(fetcher), |
| 29 web_manifest_(web_manifest), |
| 30 bookmark_app_helper_(bookmark_app_helper), |
| 31 event_request_id_(event_request_id) { |
| 32 } |
| 33 |
| 34 AppBannerInfoBarDelegateDesktop::~AppBannerInfoBarDelegateDesktop() { |
| 35 } |
| 36 |
| 37 // static |
| 38 infobars::InfoBar* AppBannerInfoBarDelegateDesktop::Create( |
| 39 scoped_refptr<AppBannerDataFetcherDesktop> fetcher, |
| 40 content::WebContents* web_contents, |
| 41 const content::Manifest& web_manifest, |
| 42 extensions::BookmarkAppHelper* bookmark_app_helper, |
| 43 int event_request_id) { |
| 44 InfoBarService* infobar_service = |
| 45 InfoBarService::FromWebContents(web_contents); |
| 46 return infobar_service->AddInfoBar(infobar_service->CreateConfirmInfoBar( |
| 47 scoped_ptr<ConfirmInfoBarDelegate>(new AppBannerInfoBarDelegateDesktop( |
| 48 fetcher, web_manifest, bookmark_app_helper, event_request_id)))); |
| 49 } |
| 50 |
| 51 infobars::InfoBarDelegate::Type |
| 52 AppBannerInfoBarDelegateDesktop::GetInfoBarType() const { |
| 53 return PAGE_ACTION_TYPE; |
| 54 } |
| 55 |
| 56 int AppBannerInfoBarDelegateDesktop::GetIconID() const { |
| 57 return IDR_INFOBAR_APP_BANNER; |
| 58 } |
| 59 |
| 60 base::string16 AppBannerInfoBarDelegateDesktop::GetMessageText() const { |
| 61 return l10n_util::GetStringUTF16(IDS_ADD_TO_SHELF_INFOBAR_TITLE); |
| 62 } |
| 63 |
| 64 base::string16 AppBannerInfoBarDelegateDesktop::GetButtonLabel( |
| 65 InfoBarButton button) const { |
| 66 return l10n_util::GetStringUTF16((button == BUTTON_OK) |
| 67 ? IDS_ADD_TO_SHELF_INFOBAR_ADD_BUTTON |
| 68 : IDS_ADD_TO_SHELF_INFOBAR_NEVER_BUTTON); |
| 69 } |
| 70 |
| 71 bool AppBannerInfoBarDelegateDesktop::Accept() { |
| 72 bookmark_app_helper_->CreateFromAppBanner( |
| 73 base::Bind(&AppBannerDataFetcherDesktop::FinishCreateBookmarkApp, |
| 74 fetcher_), |
| 75 web_manifest_); |
| 76 return true; |
| 77 } |
| 78 |
| 79 bool AppBannerInfoBarDelegateDesktop::Cancel() { |
| 80 content::WebContents* web_contents = |
| 81 InfoBarService::WebContentsFromInfoBar(infobar()); |
| 82 if (web_contents) { |
| 83 fetcher_.get()->Cancel(); |
| 84 |
| 85 web_contents->GetMainFrame()->Send( |
| 86 new ChromeViewMsg_AppBannerDismissed( |
| 87 web_contents->GetMainFrame()->GetRoutingID(), |
| 88 event_request_id_)); |
| 89 |
| 90 AppBannerSettingsHelper::RecordBannerDismissEvent( |
| 91 web_contents, web_manifest_.start_url.spec(), |
| 92 AppBannerSettingsHelper::WEB); |
| 93 } |
| 94 return true; |
| 95 } |
| 96 |
| 97 void AppBannerInfoBarDelegateDesktop::InfoBarDismissed() { |
| 98 Cancel(); |
| 99 } |
| 100 |
| 101 } // namespace banners |
OLD | NEW |