Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / banners / app_banner_data_fetcher_desktop.cc
blob5cc7fa860070f8a7a551a973483014b573fde950
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"
16 namespace infobars {
17 class InfoBar;
18 } // namespace infobars
20 namespace banners {
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,
28 weak_delegate,
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());
49 Profile* profile =
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());
63 if (infobar) {
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();
73 if (web_contents) {
74 // A null extension pointer indicates that the bookmark app install was
75 // not successful.
76 if (extension == nullptr) {
77 web_contents->GetMainFrame()->Send(
78 new ChromeViewMsg_AppBannerDismissed(
79 web_contents->GetMainFrame()->GetRoutingID(),
80 event_request_id()));
82 AppBannerSettingsHelper::RecordBannerDismissEvent(
83 web_contents, web_app_data().start_url.spec(),
84 AppBannerSettingsHelper::WEB);
85 } else {
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