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.
5 #include "chrome/browser/banners/app_banner_data_fetcher_desktop.h"
7 #include "chrome/browser/banners/app_banner_infobar_delegate_desktop.h"
8 #include "chrome/browser/banners/app_banner_settings_helper.h"
9 #include "chrome/browser/extensions/bookmark_app_helper.h"
10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/common/render_messages.h"
12 #include "chrome/common/web_application_info.h"
13 #include "content/public/browser/render_frame_host.h"
17 } // namespace infobars
21 AppBannerDataFetcherDesktop::AppBannerDataFetcherDesktop(
22 content::WebContents
* web_contents
,
23 base::WeakPtr
<Delegate
> weak_delegate
,
25 : AppBannerDataFetcher(web_contents
, weak_delegate
, ideal_icon_size
) {
28 AppBannerDataFetcherDesktop::~AppBannerDataFetcherDesktop() {
31 void AppBannerDataFetcherDesktop::ShowBanner(const SkBitmap
* icon
,
32 const base::string16
& title
) {
33 content::WebContents
* web_contents
= GetWebContents();
34 DCHECK(web_contents
&& !web_app_data().IsEmpty());
37 Profile::FromBrowserContext(web_contents
->GetBrowserContext());
38 WebApplicationInfo web_app_info
;
40 bookmark_app_helper_
.reset(
41 new extensions::BookmarkAppHelper(profile
, web_app_info
, web_contents
));
43 // This differs from the Android infobar creation, which has an explicit
44 // InfoBarAndroid class interfacing with Java. On Android, the data fetcher
45 // calls the InfoBarService to show the banner. On desktop, an InfoBar class
46 // is not required, so the InfoBarService call is made within the delegate.
47 infobars::InfoBar
* infobar
= AppBannerInfoBarDelegateDesktop::Create(
48 make_scoped_refptr(this), web_contents
, web_app_data(),
49 bookmark_app_helper_
.get(), event_request_id());
51 RecordDidShowBanner("AppBanner.WebApp.Shown");
55 void AppBannerDataFetcherDesktop::FinishCreateBookmarkApp(
56 const extensions::Extension
* extension
,
57 const WebApplicationInfo
& web_app_info
) {
58 content::WebContents
* web_contents
= GetWebContents();
60 // A null extension pointer indicates that the bookmark app install was
62 if (extension
== nullptr) {
63 web_contents
->GetMainFrame()->Send(
64 new ChromeViewMsg_AppBannerDismissed(
65 web_contents
->GetMainFrame()->GetRoutingID(),
68 AppBannerSettingsHelper::RecordBannerDismissEvent(
69 web_contents
, web_app_data().start_url
.spec(),
70 AppBannerSettingsHelper::WEB
);
72 web_contents
->GetMainFrame()->Send(
73 new ChromeViewMsg_AppBannerAccepted(
74 web_contents
->GetMainFrame()->GetRoutingID(),
75 event_request_id(), "web"));
77 AppBannerSettingsHelper::RecordBannerInstallEvent(
78 web_contents
, web_app_data().start_url
.spec(),
79 AppBannerSettingsHelper::WEB
);
84 } // namespace banners