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 const std::string
& referrer
) {
42 content::WebContents
* web_contents
= GetWebContents();
43 DCHECK(web_contents
&& !web_app_data().IsEmpty());
46 Profile::FromBrowserContext(web_contents
->GetBrowserContext());
47 WebApplicationInfo web_app_info
;
49 bookmark_app_helper_
.reset(
50 new extensions::BookmarkAppHelper(profile
, web_app_info
, web_contents
));
52 // This differs from the Android infobar creation, which has an explicit
53 // InfoBarAndroid class interfacing with Java. On Android, the data fetcher
54 // calls the InfoBarService to show the banner. On desktop, an InfoBar class
55 // is not required, so the InfoBarService call is made within the delegate.
56 infobars::InfoBar
* infobar
= AppBannerInfoBarDelegateDesktop::Create(
57 make_scoped_refptr(this), web_contents
, web_app_data(),
58 bookmark_app_helper_
.get(), event_request_id());
60 RecordDidShowBanner("AppBanner.WebApp.Shown");
61 TrackDisplayEvent(DISPLAY_EVENT_WEB_APP_BANNER_CREATED
);
65 void AppBannerDataFetcherDesktop::FinishCreateBookmarkApp(
66 const extensions::Extension
* extension
,
67 const WebApplicationInfo
& web_app_info
) {
68 content::WebContents
* web_contents
= GetWebContents();
70 // A null extension pointer indicates that the bookmark app install was
72 if (extension
== nullptr) {
73 web_contents
->GetMainFrame()->Send(
74 new ChromeViewMsg_AppBannerDismissed(
75 web_contents
->GetMainFrame()->GetRoutingID(),
78 AppBannerSettingsHelper::RecordBannerDismissEvent(
79 web_contents
, web_app_data().start_url
.spec(),
80 AppBannerSettingsHelper::WEB
);
82 web_contents
->GetMainFrame()->Send(
83 new ChromeViewMsg_AppBannerAccepted(
84 web_contents
->GetMainFrame()->GetRoutingID(),
85 event_request_id(), "web"));
87 AppBannerSettingsHelper::RecordBannerInstallEvent(
88 web_contents
, web_app_data().start_url
.spec(),
89 AppBannerSettingsHelper::WEB
);
94 } // namespace banners