OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #include "chrome/browser/banners/app_banner_data_fetcher_desktop.h" |
| 6 |
| 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" |
| 14 |
| 15 namespace infobars { |
| 16 class InfoBar; |
| 17 } // namespace infobars |
| 18 |
| 19 namespace banners { |
| 20 |
| 21 AppBannerDataFetcherDesktop::AppBannerDataFetcherDesktop( |
| 22 content::WebContents* web_contents, |
| 23 base::WeakPtr<Delegate> weak_delegate, |
| 24 int ideal_icon_size) |
| 25 : AppBannerDataFetcher(web_contents, weak_delegate, ideal_icon_size) { |
| 26 } |
| 27 |
| 28 AppBannerDataFetcherDesktop::~AppBannerDataFetcherDesktop() { |
| 29 } |
| 30 |
| 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()); |
| 35 |
| 36 Profile* profile = |
| 37 Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
| 38 WebApplicationInfo web_app_info; |
| 39 |
| 40 bookmark_app_helper_.reset( |
| 41 new extensions::BookmarkAppHelper(profile, web_app_info, web_contents)); |
| 42 |
| 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()); |
| 50 if (infobar) { |
| 51 RecordDidShowBanner("AppBanner.WebApp.Shown"); |
| 52 } |
| 53 } |
| 54 |
| 55 void AppBannerDataFetcherDesktop::FinishCreateBookmarkApp( |
| 56 const extensions::Extension* extension, |
| 57 const WebApplicationInfo& web_app_info) { |
| 58 content::WebContents* web_contents = GetWebContents(); |
| 59 if (web_contents) { |
| 60 // A null extension pointer indicates that the bookmark app install was |
| 61 // not successful. |
| 62 if (extension == nullptr) { |
| 63 web_contents->GetMainFrame()->Send( |
| 64 new ChromeViewMsg_AppBannerDismissed( |
| 65 web_contents->GetMainFrame()->GetRoutingID(), |
| 66 event_request_id())); |
| 67 |
| 68 AppBannerSettingsHelper::RecordBannerDismissEvent( |
| 69 web_contents, web_app_data().start_url.spec(), |
| 70 AppBannerSettingsHelper::WEB); |
| 71 } else { |
| 72 web_contents->GetMainFrame()->Send( |
| 73 new ChromeViewMsg_AppBannerAccepted( |
| 74 web_contents->GetMainFrame()->GetRoutingID(), |
| 75 event_request_id(), "web")); |
| 76 |
| 77 AppBannerSettingsHelper::RecordBannerInstallEvent( |
| 78 web_contents, web_app_data().start_url.spec(), |
| 79 AppBannerSettingsHelper::WEB); |
| 80 } |
| 81 } |
| 82 } |
| 83 |
| 84 } // namespace banners |
OLD | NEW |