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/guid.h" | 9 #include "base/guid.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| 11 #include "base/memory/ptr_util.h" | |
| 11 #include "base/strings/string16.h" | 12 #include "base/strings/string16.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 14 #include "chrome/browser/android/banners/app_banner_infobar_delegate_android.h" | |
| 13 #include "chrome/browser/android/shortcut_helper.h" | 15 #include "chrome/browser/android/shortcut_helper.h" |
| 14 #include "chrome/browser/android/webapk/chrome_webapk_host.h" | 16 #include "chrome/browser/android/webapk/chrome_webapk_host.h" |
| 15 #include "chrome/browser/banners/app_banner_settings_helper.h" | 17 #include "chrome/browser/banners/app_banner_settings_helper.h" |
| 18 #include "chrome/browser/infobars/infobar_service.h" | |
| 16 #include "chrome/browser/installable/installable_manager.h" | 19 #include "chrome/browser/installable/installable_manager.h" |
| 20 #include "chrome/browser/ui/android/infobars/app_banner_infobar_android.h" | |
| 17 #include "content/public/browser/browser_thread.h" | 21 #include "content/public/browser/browser_thread.h" |
| 18 #include "content/public/browser/web_contents.h" | 22 #include "content/public/browser/web_contents.h" |
| 19 #include "content/public/common/origin_util.h" | 23 #include "content/public/common/origin_util.h" |
| 20 #include "jni/AddToHomescreenManager_jni.h" | 24 #include "jni/AddToHomescreenManager_jni.h" |
| 21 #include "third_party/skia/include/core/SkBitmap.h" | 25 #include "third_party/skia/include/core/SkBitmap.h" |
| 22 #include "ui/gfx/android/java_bitmap.h" | 26 #include "ui/gfx/android/java_bitmap.h" |
| 23 | 27 |
| 24 using base::android::JavaParamRef; | 28 using base::android::JavaParamRef; |
| 25 using base::android::ScopedJavaLocalRef; | 29 using base::android::ScopedJavaLocalRef; |
| 26 | 30 |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 142 | 146 |
| 143 AppBannerSettingsHelper::RecordBannerEvent( | 147 AppBannerSettingsHelper::RecordBannerEvent( |
| 144 web_contents, web_contents->GetURL(), | 148 web_contents, web_contents->GetURL(), |
| 145 data_fetcher_->shortcut_info().url.spec(), | 149 data_fetcher_->shortcut_info().url.spec(), |
| 146 AppBannerSettingsHelper::APP_BANNER_EVENT_DID_ADD_TO_HOMESCREEN, | 150 AppBannerSettingsHelper::APP_BANNER_EVENT_DID_ADD_TO_HOMESCREEN, |
| 147 base::Time::Now()); | 151 base::Time::Now()); |
| 148 } | 152 } |
| 149 | 153 |
| 150 void AddToHomescreenManager::OnDidDetermineWebApkCompatibility( | 154 void AddToHomescreenManager::OnDidDetermineWebApkCompatibility( |
| 151 bool is_webapk_compatible) { | 155 bool is_webapk_compatible) { |
| 152 // TODO(pkotwicz): Select whether to use dialog or not based on | 156 is_webapk_compatible_ = is_webapk_compatible; |
| 153 // |is_webapk_compatible|. | 157 if (!is_webapk_compatible) |
| 154 ShowDialog(); | 158 ShowDialog(); |
| 155 } | 159 } |
| 156 | 160 |
| 157 void AddToHomescreenManager::OnUserTitleAvailable( | 161 void AddToHomescreenManager::OnUserTitleAvailable( |
| 158 const base::string16& user_title) { | 162 const base::string16& user_title) { |
| 163 if (is_webapk_compatible_) | |
| 164 return; | |
| 159 JNIEnv* env = base::android::AttachCurrentThread(); | 165 JNIEnv* env = base::android::AttachCurrentThread(); |
| 160 ScopedJavaLocalRef<jstring> j_user_title = | 166 ScopedJavaLocalRef<jstring> j_user_title = |
| 161 base::android::ConvertUTF16ToJavaString(env, user_title); | 167 base::android::ConvertUTF16ToJavaString(env, user_title); |
| 162 Java_AddToHomescreenManager_onUserTitleAvailable(env, | 168 Java_AddToHomescreenManager_onUserTitleAvailable(env, |
| 163 java_ref_, | 169 java_ref_, |
| 164 j_user_title); | 170 j_user_title); |
| 165 } | 171 } |
| 166 | 172 |
| 167 void AddToHomescreenManager::OnDataAvailable(const ShortcutInfo& info, | 173 void AddToHomescreenManager::OnDataAvailable(const ShortcutInfo& info, |
| 168 const SkBitmap& icon) { | 174 const SkBitmap& icon) { |
| 175 if (is_webapk_compatible_) { | |
| 176 CreateInfoBarForWebAPK(info, icon); | |
| 177 return; | |
| 178 } | |
| 179 | |
| 169 JNIEnv* env = base::android::AttachCurrentThread(); | 180 JNIEnv* env = base::android::AttachCurrentThread(); |
| 170 ScopedJavaLocalRef<jobject> java_bitmap; | 181 ScopedJavaLocalRef<jobject> java_bitmap; |
| 171 if (icon.getSize()) | 182 if (icon.getSize()) |
| 172 java_bitmap = gfx::ConvertToJavaBitmap(&icon); | 183 java_bitmap = gfx::ConvertToJavaBitmap(&icon); |
| 173 | 184 |
| 174 Java_AddToHomescreenManager_onReadyToAdd(env, java_ref_, java_bitmap); | 185 Java_AddToHomescreenManager_onReadyToAdd(env, java_ref_, java_bitmap); |
| 175 | 186 |
| 176 if (add_shortcut_pending_) | 187 if (add_shortcut_pending_) |
| 177 AddShortcut(info, icon); | 188 AddShortcut(info, icon); |
| 178 } | 189 } |
| 179 | 190 |
| 191 void AddToHomescreenManager::CreateInfoBarForWebAPK(const ShortcutInfo& info, | |
| 192 const SkBitmap& icon) { | |
| 193 std::unique_ptr<banners::AppBannerInfoBarDelegateAndroid> delegate_ptr = | |
| 194 base::MakeUnique<banners::AppBannerInfoBarDelegateAndroid>( | |
| 195 nullptr, info.user_title, info.manifest_url, | |
| 196 base::MakeUnique<ShortcutInfo>(info), info.icon_url, | |
| 197 base::MakeUnique<SkBitmap>(icon), | |
| 198 -1 /* event_request_id */, true); | |
|
dominickn
2016/09/02 01:00:58
Minor nit: add /* is_webapk */ after true inside t
Xi Han
2016/09/02 13:58:23
Done.
| |
| 199 | |
| 200 std::unique_ptr<infobars::InfoBar> infobar_ptr = | |
| 201 base::MakeUnique<AppBannerInfoBarAndroid>( | |
| 202 std::move(delegate_ptr), data_fetcher_->shortcut_info().url, true); | |
| 203 if (!infobar_ptr.get()) { | |
| 204 LOG(ERROR) << "Failed to create infobar to install the WebAPK."; | |
| 205 return; | |
| 206 } | |
| 207 | |
| 208 content::WebContents* web_contents = data_fetcher_->web_contents(); | |
| 209 if (!web_contents) { | |
| 210 LOG(ERROR) << "Failed to create infobar to install the WebAPK: " | |
| 211 << "the associated WebContents is null."; | |
| 212 return; | |
| 213 } | |
| 214 | |
| 215 banners::AppBannerInfoBarDelegateAndroid* delegate = | |
|
dominickn
2016/09/02 01:00:58
Minor nit: move this line below 216 so you fetch t
Xi Han
2016/09/02 13:58:23
You can't get the delegate pointer once the std::m
dominickn
2016/09/02 14:30:48
Acknowledged - I'm blind and didn't see the std::m
| |
| 216 infobar_ptr.get()->delegate()->AsAppBannerInfoBarDelegateAndroid(); | |
| 217 | |
| 218 InfoBarService::FromWebContents(web_contents)->AddInfoBar( | |
| 219 std::move(infobar_ptr)); | |
| 220 delegate->InstallWebApk(web_contents); | |
| 221 } | |
| 222 | |
| 180 SkBitmap AddToHomescreenManager::FinalizeLauncherIconInBackground( | 223 SkBitmap AddToHomescreenManager::FinalizeLauncherIconInBackground( |
| 181 const SkBitmap& bitmap, | 224 const SkBitmap& bitmap, |
| 182 const GURL& url, | 225 const GURL& url, |
| 183 bool* is_generated) { | 226 bool* is_generated) { |
| 184 DCHECK(content::BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); | 227 DCHECK(content::BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); |
| 185 | 228 |
| 186 return ShortcutHelper::FinalizeLauncherIconInBackground(bitmap, url, | 229 return ShortcutHelper::FinalizeLauncherIconInBackground(bitmap, url, |
| 187 is_generated); | 230 is_generated); |
| 188 } | 231 } |
| OLD | NEW |