Chromium Code Reviews| 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/android/webapps/add_to_homescreen_manager.h" | 5 #include "chrome/browser/android/webapps/add_to_homescreen_manager.h" |
| 6 | 6 |
| 7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
| 8 #include "base/android/jni_string.h" | 8 #include "base/android/jni_string.h" |
| 9 #include "base/location.h" | 9 #include "base/location.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| 11 #include "base/strings/string16.h" | 11 #include "base/strings/string16.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 13 #include "base/threading/sequenced_worker_pool.h" | 13 #include "base/threading/sequenced_worker_pool.h" |
| 14 #include "chrome/browser/android/banners/app_banner_infobar_delegate_android.h" | 14 #include "chrome/browser/android/banners/app_banner_infobar_delegate_android.h" |
| 15 #include "chrome/browser/android/banners/app_banner_manager_android.h" | |
| 15 #include "chrome/browser/android/shortcut_helper.h" | 16 #include "chrome/browser/android/shortcut_helper.h" |
| 16 #include "chrome/browser/android/webapk/chrome_webapk_host.h" | 17 #include "chrome/browser/android/webapk/chrome_webapk_host.h" |
| 17 #include "chrome/browser/android/webapk/webapk_install_service.h" | 18 #include "chrome/browser/android/webapk/webapk_install_service.h" |
| 18 #include "chrome/browser/android/webapk/webapk_metrics.h" | 19 #include "chrome/browser/android/webapk/webapk_metrics.h" |
| 19 #include "chrome/browser/banners/app_banner_settings_helper.h" | 20 #include "chrome/browser/banners/app_banner_settings_helper.h" |
| 20 #include "chrome/browser/installable/installable_manager.h" | 21 #include "chrome/browser/installable/installable_manager.h" |
| 21 #include "content/public/browser/browser_thread.h" | 22 #include "content/public/browser/browser_thread.h" |
| 22 #include "content/public/browser/render_frame_host.h" | 23 #include "content/public/browser/render_frame_host.h" |
| 23 #include "content/public/browser/web_contents.h" | 24 #include "content/public/browser/web_contents.h" |
| 24 #include "jni/AddToHomescreenManager_jni.h" | 25 #include "jni/AddToHomescreenManager_jni.h" |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 83 ShowDialog(); | 84 ShowDialog(); |
| 84 } | 85 } |
| 85 | 86 |
| 86 data_fetcher_ = new AddToHomescreenDataFetcher( | 87 data_fetcher_ = new AddToHomescreenDataFetcher( |
| 87 web_contents, ShortcutHelper::GetIdealHomescreenIconSizeInPx(), | 88 web_contents, ShortcutHelper::GetIdealHomescreenIconSizeInPx(), |
| 88 ShortcutHelper::GetMinimumHomescreenIconSizeInPx(), | 89 ShortcutHelper::GetMinimumHomescreenIconSizeInPx(), |
| 89 ShortcutHelper::GetIdealSplashImageSizeInPx(), | 90 ShortcutHelper::GetIdealSplashImageSizeInPx(), |
| 90 ShortcutHelper::GetMinimumSplashImageSizeInPx(), | 91 ShortcutHelper::GetMinimumSplashImageSizeInPx(), |
| 91 ShortcutHelper::GetIdealBadgeIconSizeInPx(), | 92 ShortcutHelper::GetIdealBadgeIconSizeInPx(), |
| 92 check_webapk_compatible, this); | 93 check_webapk_compatible, this); |
| 94 | |
| 95 app_banner_manager_ = | |
|
dominickn
2017/04/24 00:56:30
Having thought about this, I think it's better to
Matt Giuca
2017/04/24 01:42:13
Done.
| |
| 96 banners::AppBannerManagerAndroid::FromWebContents(web_contents); | |
| 97 DCHECK(app_banner_manager_); | |
| 93 } | 98 } |
| 94 | 99 |
| 95 AddToHomescreenManager::~AddToHomescreenManager() { | 100 AddToHomescreenManager::~AddToHomescreenManager() { |
| 96 if (data_fetcher_) { | 101 if (data_fetcher_) { |
| 97 data_fetcher_->set_weak_observer(nullptr); | 102 data_fetcher_->set_weak_observer(nullptr); |
| 98 data_fetcher_ = nullptr; | 103 data_fetcher_ = nullptr; |
| 99 } | 104 } |
| 100 } | 105 } |
| 101 | 106 |
| 102 void AddToHomescreenManager::ShowDialog() { | 107 void AddToHomescreenManager::ShowDialog() { |
| 103 JNIEnv* env = base::android::AttachCurrentThread(); | 108 JNIEnv* env = base::android::AttachCurrentThread(); |
| 104 Java_AddToHomescreenManager_showDialog(env, java_ref_); | 109 Java_AddToHomescreenManager_showDialog(env, java_ref_); |
| 105 } | 110 } |
| 106 | 111 |
| 107 void AddToHomescreenManager::AddShortcut(const ShortcutInfo& info, | 112 void AddToHomescreenManager::AddShortcut(const ShortcutInfo& info, |
| 108 const SkBitmap& icon) { | 113 const SkBitmap& icon) { |
| 109 DCHECK(add_shortcut_pending_); | 114 DCHECK(add_shortcut_pending_); |
| 110 if (!add_shortcut_pending_) | 115 if (!add_shortcut_pending_) |
| 111 return; | 116 return; |
| 112 add_shortcut_pending_ = false; | 117 add_shortcut_pending_ = false; |
| 113 | 118 |
| 114 content::WebContents* web_contents = data_fetcher_->web_contents(); | 119 content::WebContents* web_contents = data_fetcher_->web_contents(); |
| 115 if (!web_contents) | 120 if (!web_contents) |
| 116 return; | 121 return; |
| 117 | 122 |
| 118 RecordAddToHomescreen(); | 123 RecordAddToHomescreen(); |
| 119 ShortcutHelper::AddToLauncherWithSkBitmap(web_contents, info, icon); | 124 ShortcutHelper::AddToLauncherWithSkBitmap(web_contents, info, icon); |
| 120 | 125 |
| 121 // Fire the appinstalled event. | 126 // Fire the appinstalled event. |
| 122 blink::mojom::InstallationServicePtr installation_service; | 127 app_banner_manager_->OnInstall(); |
| 123 web_contents->GetMainFrame()->GetRemoteInterfaces()->GetInterface( | |
| 124 mojo::MakeRequest(&installation_service)); | |
| 125 DCHECK(installation_service); | |
| 126 installation_service->OnInstall(); | |
| 127 } | 128 } |
| 128 | 129 |
| 129 void AddToHomescreenManager::RecordAddToHomescreen() { | 130 void AddToHomescreenManager::RecordAddToHomescreen() { |
| 130 // Record that the shortcut has been added, so no banners will be shown | 131 // Record that the shortcut has been added, so no banners will be shown |
| 131 // for this app. | 132 // for this app. |
| 132 content::WebContents* web_contents = data_fetcher_->web_contents(); | 133 content::WebContents* web_contents = data_fetcher_->web_contents(); |
| 133 if (!web_contents) | 134 if (!web_contents) |
| 134 return; | 135 return; |
| 135 | 136 |
| 136 AppBannerSettingsHelper::RecordBannerEvent( | 137 AppBannerSettingsHelper::RecordBannerEvent( |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 185 | 186 |
| 186 if (add_shortcut_pending_) | 187 if (add_shortcut_pending_) |
| 187 AddShortcut(info, primary_icon); | 188 AddShortcut(info, primary_icon); |
| 188 } | 189 } |
| 189 | 190 |
| 190 void AddToHomescreenManager::CreateInfoBarForWebApk( | 191 void AddToHomescreenManager::CreateInfoBarForWebApk( |
| 191 const ShortcutInfo& info, | 192 const ShortcutInfo& info, |
| 192 const SkBitmap& primary_icon, | 193 const SkBitmap& primary_icon, |
| 193 const SkBitmap& badge_icon) { | 194 const SkBitmap& badge_icon) { |
| 194 banners::AppBannerInfoBarDelegateAndroid::Create( | 195 banners::AppBannerInfoBarDelegateAndroid::Create( |
| 195 data_fetcher_->web_contents(), nullptr, info.user_title, | 196 data_fetcher_->web_contents(), app_banner_manager_->GetWeakPtr(), |
| 196 base::MakeUnique<ShortcutInfo>(info), primary_icon, badge_icon, | 197 info.user_title, base::MakeUnique<ShortcutInfo>(info), primary_icon, |
| 197 -1 /* event_request_id */, webapk::INSTALL_SOURCE_MENU); | 198 badge_icon, -1 /* event_request_id */, webapk::INSTALL_SOURCE_MENU); |
| 198 } | 199 } |
| 199 | 200 |
| 200 SkBitmap AddToHomescreenManager::FinalizeLauncherIconInBackground( | 201 SkBitmap AddToHomescreenManager::FinalizeLauncherIconInBackground( |
| 201 const SkBitmap& bitmap, | 202 const SkBitmap& bitmap, |
| 202 const GURL& url, | 203 const GURL& url, |
| 203 bool* is_generated) { | 204 bool* is_generated) { |
| 204 DCHECK(content::BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); | 205 DCHECK(content::BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); |
| 205 | 206 |
| 206 return ShortcutHelper::FinalizeLauncherIconInBackground(bitmap, url, | 207 return ShortcutHelper::FinalizeLauncherIconInBackground(bitmap, url, |
| 207 is_generated); | 208 is_generated); |
| 208 } | 209 } |
| OLD | NEW |