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_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/profiles/profile.h"
12 #include "chrome/common/render_messages.h"
13 #include "chrome/common/web_application_info.h"
14 #include "content/public/browser/render_frame_host.h"
18 } // namespace infobars
22 AppBannerDataFetcherDesktop::AppBannerDataFetcherDesktop(
23 content::WebContents
* web_contents
,
24 base::WeakPtr
<Delegate
> weak_delegate
,
25 int ideal_icon_size_in_dp
,
26 int minimum_icon_size_in_dp
)
27 : AppBannerDataFetcher(web_contents
,
29 ideal_icon_size_in_dp
,
30 minimum_icon_size_in_dp
) {
33 AppBannerDataFetcherDesktop::~AppBannerDataFetcherDesktop() {
36 bool AppBannerDataFetcherDesktop::IsWebAppInstalled(
37 content::BrowserContext
* browser_context
,
38 const GURL
& start_url
) {
39 return extensions::BookmarkAppHelper::BookmarkOrHostedAppInstalled(
40 browser_context
, start_url
);
43 void AppBannerDataFetcherDesktop::ShowBanner(const SkBitmap
* icon
,
44 const base::string16
& title
,
45 const std::string
& referrer
) {
46 content::WebContents
* web_contents
= GetWebContents();
47 DCHECK(web_contents
&& !web_app_data().IsEmpty());
50 Profile::FromBrowserContext(web_contents
->GetBrowserContext());
51 WebApplicationInfo web_app_info
;
53 bookmark_app_helper_
.reset(
54 new extensions::BookmarkAppHelper(profile
, web_app_info
, web_contents
));
56 // This differs from the Android infobar creation, which has an explicit
57 // InfoBarAndroid class interfacing with Java. On Android, the data fetcher
58 // calls the InfoBarService to show the banner. On desktop, an InfoBar class
59 // is not required, so the InfoBarService call is made within the delegate.
60 infobars::InfoBar
* infobar
= AppBannerInfoBarDelegateDesktop::Create(
61 make_scoped_refptr(this), web_contents
, web_app_data(),
62 bookmark_app_helper_
.get(), event_request_id());
64 RecordDidShowBanner("AppBanner.WebApp.Shown");
65 TrackDisplayEvent(DISPLAY_EVENT_WEB_APP_BANNER_CREATED
);
69 void AppBannerDataFetcherDesktop::FinishCreateBookmarkApp(
70 const extensions::Extension
* extension
,
71 const WebApplicationInfo
& web_app_info
) {
72 content::WebContents
* web_contents
= GetWebContents();
74 // A null extension pointer indicates that the bookmark app install was
76 if (extension
== nullptr) {
77 web_contents
->GetMainFrame()->Send(
78 new ChromeViewMsg_AppBannerDismissed(
79 web_contents
->GetMainFrame()->GetRoutingID(),
82 AppBannerSettingsHelper::RecordBannerDismissEvent(
83 web_contents
, web_app_data().start_url
.spec(),
84 AppBannerSettingsHelper::WEB
);
86 web_contents
->GetMainFrame()->Send(
87 new ChromeViewMsg_AppBannerAccepted(
88 web_contents
->GetMainFrame()->GetRoutingID(),
89 event_request_id(), "web"));
91 AppBannerSettingsHelper::RecordBannerInstallEvent(
92 web_contents
, web_app_data().start_url
.spec(),
93 AppBannerSettingsHelper::WEB
);
98 } // namespace banners