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
,
26 : AppBannerDataFetcher(web_contents
, weak_delegate
, ideal_icon_size
) {
29 AppBannerDataFetcherDesktop::~AppBannerDataFetcherDesktop() {
32 bool AppBannerDataFetcherDesktop::IsWebAppInstalled(
33 content::BrowserContext
* browser_context
,
34 const GURL
& start_url
) {
35 return extensions::BookmarkAppHelper::BookmarkOrHostedAppInstalled(
36 browser_context
, start_url
);
39 void AppBannerDataFetcherDesktop::ShowBanner(const SkBitmap
* icon
,
40 const base::string16
& title
) {
41 content::WebContents
* web_contents
= GetWebContents();
42 DCHECK(web_contents
&& !web_app_data().IsEmpty());
45 Profile::FromBrowserContext(web_contents
->GetBrowserContext());
46 WebApplicationInfo web_app_info
;
48 bookmark_app_helper_
.reset(
49 new extensions::BookmarkAppHelper(profile
, web_app_info
, web_contents
));
51 // This differs from the Android infobar creation, which has an explicit
52 // InfoBarAndroid class interfacing with Java. On Android, the data fetcher
53 // calls the InfoBarService to show the banner. On desktop, an InfoBar class
54 // is not required, so the InfoBarService call is made within the delegate.
55 infobars::InfoBar
* infobar
= AppBannerInfoBarDelegateDesktop::Create(
56 make_scoped_refptr(this), web_contents
, web_app_data(),
57 bookmark_app_helper_
.get(), event_request_id());
59 RecordDidShowBanner("AppBanner.WebApp.Shown");
60 TrackDisplayEvent(DISPLAY_EVENT_WEB_APP_BANNER_CREATED
);
64 void AppBannerDataFetcherDesktop::FinishCreateBookmarkApp(
65 const extensions::Extension
* extension
,
66 const WebApplicationInfo
& web_app_info
) {
67 content::WebContents
* web_contents
= GetWebContents();
69 // A null extension pointer indicates that the bookmark app install was
71 if (extension
== nullptr) {
72 web_contents
->GetMainFrame()->Send(
73 new ChromeViewMsg_AppBannerDismissed(
74 web_contents
->GetMainFrame()->GetRoutingID(),
77 AppBannerSettingsHelper::RecordBannerDismissEvent(
78 web_contents
, web_app_data().start_url
.spec(),
79 AppBannerSettingsHelper::WEB
);
81 web_contents
->GetMainFrame()->Send(
82 new ChromeViewMsg_AppBannerAccepted(
83 web_contents
->GetMainFrame()->GetRoutingID(),
84 event_request_id(), "web"));
86 AppBannerSettingsHelper::RecordBannerInstallEvent(
87 web_contents
, web_app_data().start_url
.spec(),
88 AppBannerSettingsHelper::WEB
);
93 } // namespace banners