| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/banners/app_banner_manager_desktop.h" | 5 #include "chrome/browser/banners/app_banner_manager_desktop.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/strings/string_number_conversions.h" |
| 8 #include "build/build_config.h" | 9 #include "build/build_config.h" |
| 9 #include "chrome/browser/banners/app_banner_data_fetcher_desktop.h" | 10 #include "chrome/browser/banners/app_banner_infobar_delegate_desktop.h" |
| 11 #include "chrome/browser/banners/app_banner_metrics.h" |
| 12 #include "chrome/browser/banners/app_banner_settings_helper.h" |
| 13 #include "chrome/browser/extensions/bookmark_app_helper.h" |
| 14 #include "chrome/browser/installable/installable_checker.h" |
| 15 #include "chrome/browser/installable/installable_logging.h" |
| 16 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/common/chrome_switches.h" | 17 #include "chrome/common/chrome_switches.h" |
| 18 #include "chrome/common/render_messages.h" |
| 19 #include "chrome/common/web_application_info.h" |
| 20 #include "content/public/browser/render_frame_host.h" |
| 11 #include "extensions/common/constants.h" | 21 #include "extensions/common/constants.h" |
| 12 | 22 |
| 13 namespace { | |
| 14 // TODO(dominickn) Identify the best minimum icon size to guarantee the best | |
| 15 // user experience. | |
| 16 int kMinimumIconSize = extension_misc::EXTENSION_ICON_LARGE; | |
| 17 } // anonymous namespace | |
| 18 | |
| 19 DEFINE_WEB_CONTENTS_USER_DATA_KEY(banners::AppBannerManagerDesktop); | 23 DEFINE_WEB_CONTENTS_USER_DATA_KEY(banners::AppBannerManagerDesktop); |
| 20 | 24 |
| 21 namespace banners { | 25 namespace banners { |
| 22 | 26 |
| 23 bool AppBannerManagerDesktop::IsEnabled() { | 27 bool AppBannerManagerDesktop::IsEnabled() { |
| 24 #if defined(OS_CHROMEOS) | 28 #if defined(OS_CHROMEOS) |
| 25 return !base::CommandLine::ForCurrentProcess()->HasSwitch( | 29 return !base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 26 switches::kDisableAddToShelf); | 30 switches::kDisableAddToShelf); |
| 27 #else | 31 #else |
| 28 return base::CommandLine::ForCurrentProcess()->HasSwitch( | 32 return base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 29 switches::kEnableAddToShelf); | 33 switches::kEnableAddToShelf); |
| 30 #endif | 34 #endif |
| 31 } | 35 } |
| 32 | 36 |
| 33 AppBannerDataFetcher* AppBannerManagerDesktop::CreateAppBannerDataFetcher( | |
| 34 base::WeakPtr<AppBannerDataFetcher::Delegate> weak_delegate, | |
| 35 bool is_debug_mode) { | |
| 36 return new AppBannerDataFetcherDesktop(web_contents(), weak_delegate, | |
| 37 kMinimumIconSize, kMinimumIconSize, | |
| 38 is_debug_mode); | |
| 39 } | |
| 40 | |
| 41 AppBannerManagerDesktop::AppBannerManagerDesktop( | 37 AppBannerManagerDesktop::AppBannerManagerDesktop( |
| 42 content::WebContents* web_contents) | 38 content::WebContents* web_contents) |
| 43 : AppBannerManager(web_contents) { | 39 : AppBannerManager(web_contents) { } |
| 40 |
| 41 AppBannerManagerDesktop::~AppBannerManagerDesktop() { } |
| 42 |
| 43 void AppBannerManagerDesktop::DidFinishCreatingBookmarkApp( |
| 44 const extensions::Extension* extension, |
| 45 const WebApplicationInfo& web_app_info) { |
| 46 content::WebContents* contents = web_contents(); |
| 47 if (contents) { |
| 48 // A null extension pointer indicates that the bookmark app install was |
| 49 // not successful. |
| 50 if (extension == nullptr) { |
| 51 contents->GetMainFrame()->Send(new ChromeViewMsg_AppBannerDismissed( |
| 52 contents->GetMainFrame()->GetRoutingID(), event_request_id())); |
| 53 |
| 54 AppBannerSettingsHelper::RecordBannerDismissEvent( |
| 55 contents, GetAppIdentifier(), AppBannerSettingsHelper::WEB); |
| 56 } else { |
| 57 contents->GetMainFrame()->Send(new ChromeViewMsg_AppBannerAccepted( |
| 58 contents->GetMainFrame()->GetRoutingID(), event_request_id(), |
| 59 GetBannerType())); |
| 60 |
| 61 AppBannerSettingsHelper::RecordBannerInstallEvent( |
| 62 contents, GetAppIdentifier(), AppBannerSettingsHelper::WEB); |
| 63 } |
| 64 } |
| 65 } |
| 66 |
| 67 bool AppBannerManagerDesktop::IsWebAppInstalled( |
| 68 content::BrowserContext* browser_context, |
| 69 const GURL& start_url) { |
| 70 return extensions::BookmarkAppHelper::BookmarkOrHostedAppInstalled( |
| 71 browser_context, start_url); |
| 72 } |
| 73 |
| 74 void AppBannerManagerDesktop::ShowBanner() { |
| 75 content::WebContents* contents = web_contents(); |
| 76 DCHECK(contents && !manifest_.IsEmpty()); |
| 77 |
| 78 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext()); |
| 79 WebApplicationInfo web_app_info; |
| 80 |
| 81 bookmark_app_helper_.reset( |
| 82 new extensions::BookmarkAppHelper(profile, web_app_info, contents)); |
| 83 |
| 84 // This differs from Android, where there is a concrete |
| 85 // AppBannerInfoBarAndroid class to interface with Java, and the manager calls |
| 86 // the InfoBarService to show the banner. On desktop, an InfoBar class |
| 87 // is not required, and the delegate calls the InfoBarService. |
| 88 infobars::InfoBar* infobar = AppBannerInfoBarDelegateDesktop::Create( |
| 89 contents, GetWeakPtr(), bookmark_app_helper_.get(), manifest_, |
| 90 event_request_id()); |
| 91 if (infobar) { |
| 92 RecordDidShowBanner("AppBanner.WebApp.Shown"); |
| 93 TrackDisplayEvent(DISPLAY_EVENT_WEB_APP_BANNER_CREATED); |
| 94 } |
| 95 } |
| 96 |
| 97 void AppBannerManagerDesktop::DidFinishLoad( |
| 98 content::RenderFrameHost* render_frame_host, |
| 99 const GURL& validated_url) { |
| 100 // Explicitly forbid banners from triggering on navigation unless this is |
| 101 // enabled. |
| 102 if (!IsEnabled()) |
| 103 return; |
| 104 |
| 105 AppBannerManager::DidFinishLoad(render_frame_host, validated_url); |
| 106 } |
| 107 |
| 108 void AppBannerManagerDesktop::OnEngagementIncreased( |
| 109 content::WebContents* web_contents, |
| 110 const GURL& url, |
| 111 double score) { |
| 112 // Explicitly forbid banners from triggering on navigation unless this is |
| 113 // enabled. |
| 114 if (!IsEnabled()) |
| 115 return; |
| 116 |
| 117 AppBannerManager::OnEngagementIncreased(web_contents, url, score); |
| 44 } | 118 } |
| 45 | 119 |
| 46 } // namespace banners | 120 } // namespace banners |
| OLD | NEW |