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/banners/app_banner_infobar_delegate_android.h" | 5 #include "chrome/browser/android/banners/app_banner_infobar_delegate_android.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/memory/ptr_util.h" |
| 12 #include "base/strings/string16.h" | 12 #include "base/strings/string16.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 14 #include "chrome/browser/android/shortcut_helper.h" | 14 #include "chrome/browser/android/shortcut_helper.h" |
| 15 #include "chrome/browser/android/shortcut_info.h" | 15 #include "chrome/browser/android/shortcut_info.h" |
| 16 #include "chrome/browser/android/tab_android.h" | 16 #include "chrome/browser/android/tab_android.h" |
| 17 #include "chrome/browser/android/webapk/webapk_installer.h" | |
| 17 #include "chrome/browser/banners/app_banner_manager.h" | 18 #include "chrome/browser/banners/app_banner_manager.h" |
| 18 #include "chrome/browser/banners/app_banner_metrics.h" | 19 #include "chrome/browser/banners/app_banner_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/browser_process.h" | 21 #include "chrome/browser/browser_process.h" |
| 21 #include "chrome/browser/infobars/infobar_service.h" | 22 #include "chrome/browser/infobars/infobar_service.h" |
| 22 #include "chrome/browser/ui/android/infobars/app_banner_infobar_android.h" | 23 #include "chrome/browser/ui/android/infobars/app_banner_infobar_android.h" |
| 23 #include "chrome/common/render_messages.h" | 24 #include "chrome/common/render_messages.h" |
| 24 #include "chrome/grit/generated_resources.h" | 25 #include "chrome/grit/generated_resources.h" |
| 25 #include "components/rappor/rappor_utils.h" | 26 #include "components/rappor/rappor_utils.h" |
| 27 #include "content/public/browser/browser_thread.h" | |
| 26 #include "content/public/browser/render_frame_host.h" | 28 #include "content/public/browser/render_frame_host.h" |
| 27 #include "content/public/browser/web_contents.h" | 29 #include "content/public/browser/web_contents.h" |
| 28 #include "content/public/common/manifest.h" | 30 #include "content/public/common/manifest.h" |
| 29 #include "jni/AppBannerInfoBarDelegateAndroid_jni.h" | 31 #include "jni/AppBannerInfoBarDelegateAndroid_jni.h" |
| 30 #include "ui/gfx/android/java_bitmap.h" | 32 #include "ui/gfx/android/java_bitmap.h" |
| 31 #include "url/gurl.h" | 33 #include "url/gurl.h" |
| 32 | 34 |
| 33 using base::android::ConvertJavaStringToUTF8; | 35 using base::android::ConvertJavaStringToUTF8; |
| 34 using base::android::ConvertJavaStringToUTF16; | 36 using base::android::ConvertJavaStringToUTF16; |
| 35 using base::android::ConvertUTF8ToJavaString; | 37 using base::android::ConvertUTF8ToJavaString; |
| 36 using base::android::ConvertUTF16ToJavaString; | 38 using base::android::ConvertUTF16ToJavaString; |
| 37 using base::android::JavaParamRef; | 39 using base::android::JavaParamRef; |
| 38 using base::android::ScopedJavaLocalRef; | 40 using base::android::ScopedJavaLocalRef; |
| 39 | 41 |
| 40 namespace banners { | 42 namespace banners { |
| 41 | 43 |
| 42 AppBannerInfoBarDelegateAndroid::AppBannerInfoBarDelegateAndroid( | 44 AppBannerInfoBarDelegateAndroid::AppBannerInfoBarDelegateAndroid( |
| 43 base::WeakPtr<AppBannerManager> weak_manager, | 45 base::WeakPtr<AppBannerManager> weak_manager, |
| 44 const base::string16& app_title, | 46 const base::string16& app_title, |
| 45 const GURL& manifest_url, | 47 const GURL& manifest_url, |
| 46 const content::Manifest& manifest, | 48 const content::Manifest& manifest, |
| 47 const GURL& icon_url, | 49 const GURL& icon_url, |
| 48 std::unique_ptr<SkBitmap> icon, | 50 std::unique_ptr<SkBitmap> icon, |
| 49 int event_request_id) | 51 int event_request_id, |
| 52 bool is_webapk) | |
| 50 : weak_manager_(weak_manager), | 53 : weak_manager_(weak_manager), |
| 51 app_title_(app_title), | 54 app_title_(app_title), |
| 52 manifest_url_(manifest_url), | 55 manifest_url_(manifest_url), |
| 53 manifest_(manifest), | 56 manifest_(manifest), |
| 54 icon_url_(icon_url), | 57 icon_url_(icon_url), |
| 55 icon_(std::move(icon)), | 58 icon_(std::move(icon)), |
| 56 event_request_id_(event_request_id), | 59 event_request_id_(event_request_id), |
| 57 has_user_interaction_(false) { | 60 has_user_interaction_(false), |
| 61 is_webapk_(is_webapk) { | |
| 58 DCHECK(!manifest.IsEmpty()); | 62 DCHECK(!manifest.IsEmpty()); |
| 59 CreateJavaDelegate(); | 63 CreateJavaDelegate(); |
| 60 } | 64 } |
| 61 | 65 |
| 62 AppBannerInfoBarDelegateAndroid::AppBannerInfoBarDelegateAndroid( | 66 AppBannerInfoBarDelegateAndroid::AppBannerInfoBarDelegateAndroid( |
| 63 const base::string16& app_title, | 67 const base::string16& app_title, |
| 64 const base::android::ScopedJavaGlobalRef<jobject>& native_app_data, | 68 const base::android::ScopedJavaGlobalRef<jobject>& native_app_data, |
| 65 std::unique_ptr<SkBitmap> icon, | 69 std::unique_ptr<SkBitmap> icon, |
| 66 const std::string& native_app_package, | 70 const std::string& native_app_package, |
| 67 const std::string& referrer, | 71 const std::string& referrer, |
| 68 int event_request_id) | 72 int event_request_id) |
| 69 : app_title_(app_title), | 73 : app_title_(app_title), |
| 70 native_app_data_(native_app_data), | 74 native_app_data_(native_app_data), |
| 71 icon_(std::move(icon)), | 75 icon_(std::move(icon)), |
| 72 native_app_package_(native_app_package), | 76 native_app_package_(native_app_package), |
| 73 referrer_(referrer), | 77 referrer_(referrer), |
| 74 event_request_id_(event_request_id), | 78 event_request_id_(event_request_id), |
| 75 has_user_interaction_(false) { | 79 has_user_interaction_(false) { |
| 76 DCHECK(!native_app_data_.is_null()); | 80 DCHECK(!native_app_data_.is_null()); |
| 77 CreateJavaDelegate(); | 81 CreateJavaDelegate(); |
| 78 } | 82 } |
| 79 | 83 |
| 80 AppBannerInfoBarDelegateAndroid::~AppBannerInfoBarDelegateAndroid() { | 84 AppBannerInfoBarDelegateAndroid::~AppBannerInfoBarDelegateAndroid() { |
| 81 if (!has_user_interaction_) { | 85 if (!has_user_interaction_) { |
| 82 if (!native_app_data_.is_null()) | 86 if (!native_app_data_.is_null()) |
| 83 TrackUserResponse(USER_RESPONSE_NATIVE_APP_IGNORED); | 87 TrackUserResponse(USER_RESPONSE_NATIVE_APP_IGNORED); |
| 88 else if (is_webapk_) | |
| 89 TrackUserResponse(USER_RESPONSE_WEBAPK_IGNORED); | |
| 84 else if (!manifest_.IsEmpty()) | 90 else if (!manifest_.IsEmpty()) |
| 85 TrackUserResponse(USER_RESPONSE_WEB_APP_IGNORED); | 91 TrackUserResponse(USER_RESPONSE_WEB_APP_IGNORED); |
| 86 } | 92 } |
| 87 | 93 |
| 88 TrackDismissEvent(DISMISS_EVENT_DISMISSED); | 94 TrackDismissEvent(DISMISS_EVENT_DISMISSED); |
| 89 JNIEnv* env = base::android::AttachCurrentThread(); | 95 JNIEnv* env = base::android::AttachCurrentThread(); |
| 90 Java_AppBannerInfoBarDelegateAndroid_destroy(env, java_delegate_); | 96 Java_AppBannerInfoBarDelegateAndroid_destroy(env, java_delegate_); |
| 91 java_delegate_.Reset(); | 97 java_delegate_.Reset(); |
| 92 } | 98 } |
| 93 | 99 |
| 94 void AppBannerInfoBarDelegateAndroid::UpdateInstallState( | 100 void AppBannerInfoBarDelegateAndroid::UpdateInstallState( |
| 95 JNIEnv* env, | 101 JNIEnv* env, |
| 96 const JavaParamRef<jobject>& obj) { | 102 const JavaParamRef<jobject>& obj) { |
| 97 if (native_app_data_.is_null()) | 103 if (native_app_data_.is_null() && !is_webapk_) |
| 98 return; | 104 return; |
| 99 | 105 |
| 100 int newState = Java_AppBannerInfoBarDelegateAndroid_determineInstallState( | 106 int newState = Java_AppBannerInfoBarDelegateAndroid_determineInstallState( |
| 101 env, java_delegate_, native_app_data_); | 107 env, java_delegate_, native_app_data_); |
| 102 static_cast<AppBannerInfoBarAndroid*>(infobar()) | 108 static_cast<AppBannerInfoBarAndroid*>(infobar()) |
| 103 ->OnInstallStateChanged(newState); | 109 ->OnInstallStateChanged(newState); |
| 104 } | 110 } |
| 105 | 111 |
| 106 void AppBannerInfoBarDelegateAndroid::OnInstallIntentReturned( | 112 void AppBannerInfoBarDelegateAndroid::OnInstallIntentReturned( |
| 107 JNIEnv* env, | 113 JNIEnv* env, |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 125 | 131 |
| 126 TrackInstallEvent(INSTALL_EVENT_NATIVE_APP_INSTALL_STARTED); | 132 TrackInstallEvent(INSTALL_EVENT_NATIVE_APP_INSTALL_STARTED); |
| 127 rappor::SampleDomainAndRegistryFromGURL(g_browser_process->rappor_service(), | 133 rappor::SampleDomainAndRegistryFromGURL(g_browser_process->rappor_service(), |
| 128 "AppBanner.NativeApp.Installed", | 134 "AppBanner.NativeApp.Installed", |
| 129 web_contents->GetURL()); | 135 web_contents->GetURL()); |
| 130 } | 136 } |
| 131 | 137 |
| 132 UpdateInstallState(env, obj); | 138 UpdateInstallState(env, obj); |
| 133 } | 139 } |
| 134 | 140 |
| 135 void AppBannerInfoBarDelegateAndroid::OnInstallFinished( | 141 void AppBannerInfoBarDelegateAndroid::OnInstallFinished( |
|
pkotwicz
2016/08/25 22:23:15
It looks like this function is no longer called in
Xi Han
2016/08/26 17:04:17
Removed.
| |
| 136 JNIEnv* env, | 142 JNIEnv* env, |
| 137 const JavaParamRef<jobject>& obj, | 143 const JavaParamRef<jobject>& obj, |
| 138 jboolean success) { | 144 jboolean success) { |
| 139 if (!infobar()) | 145 if (!infobar()) |
| 140 return; | 146 return; |
| 141 | 147 |
| 142 if (success) { | 148 if (success) { |
| 143 TrackInstallEvent(INSTALL_EVENT_NATIVE_APP_INSTALL_COMPLETED); | 149 if (!is_webapk_) { |
| 150 TrackInstallEvent(INSTALL_EVENT_NATIVE_APP_INSTALL_COMPLETED); | |
| 151 } else { | |
| 152 TrackInstallEvent(INSTALL_EVENT_WEBAPK_INSTALL_COMPLETED); | |
| 153 Java_AppBannerInfoBarDelegateAndroid_setWebApkInstallingState( | |
| 154 env, java_delegate_, false); | |
| 155 } | |
| 144 UpdateInstallState(env, obj); | 156 UpdateInstallState(env, obj); |
| 145 } else if (infobar()->owner()) { | 157 } else if (infobar()->owner()) { |
| 146 TrackDismissEvent(DISMISS_EVENT_INSTALL_TIMEOUT); | 158 TrackDismissEvent(DISMISS_EVENT_INSTALL_TIMEOUT); |
| 147 infobar()->owner()->RemoveInfoBar(infobar()); | 159 infobar()->owner()->RemoveInfoBar(infobar()); |
| 148 } | 160 } |
| 149 } | 161 } |
| 150 | 162 |
| 151 void AppBannerInfoBarDelegateAndroid::CreateJavaDelegate() { | 163 void AppBannerInfoBarDelegateAndroid::CreateJavaDelegate() { |
| 152 JNIEnv* env = base::android::AttachCurrentThread(); | 164 JNIEnv* env = base::android::AttachCurrentThread(); |
| 153 java_delegate_.Reset(Java_AppBannerInfoBarDelegateAndroid_create( | 165 java_delegate_.Reset(Java_AppBannerInfoBarDelegateAndroid_create( |
| 154 env, | 166 env, |
| 155 reinterpret_cast<intptr_t>(this))); | 167 reinterpret_cast<intptr_t>(this), |
| 168 is_webapk_)); | |
| 156 } | 169 } |
| 157 | 170 |
| 158 void AppBannerInfoBarDelegateAndroid::SendBannerAccepted( | 171 void AppBannerInfoBarDelegateAndroid::SendBannerAccepted( |
| 159 content::WebContents* web_contents, | 172 content::WebContents* web_contents, |
| 160 const std::string& platform) { | 173 const std::string& platform) { |
| 161 web_contents->GetMainFrame()->Send( | 174 web_contents->GetMainFrame()->Send( |
| 162 new ChromeViewMsg_AppBannerAccepted( | 175 new ChromeViewMsg_AppBannerAccepted( |
| 163 web_contents->GetMainFrame()->GetRoutingID(), | 176 web_contents->GetMainFrame()->GetRoutingID(), |
| 164 event_request_id_, | 177 event_request_id_, |
| 165 platform)); | 178 platform)); |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 185 web_contents->GetMainFrame()->Send( | 198 web_contents->GetMainFrame()->Send( |
| 186 new ChromeViewMsg_AppBannerDismissed( | 199 new ChromeViewMsg_AppBannerDismissed( |
| 187 web_contents->GetMainFrame()->GetRoutingID(), | 200 web_contents->GetMainFrame()->GetRoutingID(), |
| 188 event_request_id_)); | 201 event_request_id_)); |
| 189 | 202 |
| 190 if (!native_app_data_.is_null()) { | 203 if (!native_app_data_.is_null()) { |
| 191 TrackUserResponse(USER_RESPONSE_NATIVE_APP_DISMISSED); | 204 TrackUserResponse(USER_RESPONSE_NATIVE_APP_DISMISSED); |
| 192 AppBannerSettingsHelper::RecordBannerDismissEvent( | 205 AppBannerSettingsHelper::RecordBannerDismissEvent( |
| 193 web_contents, native_app_package_, AppBannerSettingsHelper::NATIVE); | 206 web_contents, native_app_package_, AppBannerSettingsHelper::NATIVE); |
| 194 } else if (!manifest_.IsEmpty()) { | 207 } else if (!manifest_.IsEmpty()) { |
| 195 TrackUserResponse(USER_RESPONSE_WEB_APP_DISMISSED); | 208 if (is_webapk_) { |
| 196 AppBannerSettingsHelper::RecordBannerDismissEvent( | 209 TrackUserResponse(USER_RESPONSE_WEBAPK_DISMISSED); |
| 197 web_contents, manifest_.start_url.spec(), | 210 AppBannerSettingsHelper::RecordBannerDismissEvent( |
| 198 AppBannerSettingsHelper::WEB); | 211 web_contents, manifest_.start_url.spec(), |
| 212 AppBannerSettingsHelper::WEBAPK); | |
| 213 } else { | |
| 214 TrackUserResponse(USER_RESPONSE_WEB_APP_DISMISSED); | |
| 215 AppBannerSettingsHelper::RecordBannerDismissEvent( | |
| 216 web_contents, manifest_.start_url.spec(), | |
| 217 AppBannerSettingsHelper::WEB); | |
| 218 } | |
| 199 } | 219 } |
| 200 } | 220 } |
| 201 | 221 |
| 202 base::string16 AppBannerInfoBarDelegateAndroid::GetMessageText() const { | 222 base::string16 AppBannerInfoBarDelegateAndroid::GetMessageText() const { |
| 203 return app_title_; | 223 return app_title_; |
| 204 } | 224 } |
| 205 | 225 |
| 206 int AppBannerInfoBarDelegateAndroid::GetButtons() const { | 226 int AppBannerInfoBarDelegateAndroid::GetButtons() const { |
| 207 return BUTTON_OK; | 227 return BUTTON_OK; |
| 208 } | 228 } |
| 209 | 229 |
| 210 bool AppBannerInfoBarDelegateAndroid::Accept() { | 230 bool AppBannerInfoBarDelegateAndroid::Accept() { |
| 211 has_user_interaction_ = true; | 231 has_user_interaction_ = true; |
| 212 | 232 |
| 213 content::WebContents* web_contents = | 233 content::WebContents* web_contents = |
| 214 InfoBarService::WebContentsFromInfoBar(infobar()); | 234 InfoBarService::WebContentsFromInfoBar(infobar()); |
| 215 if (!web_contents) { | 235 if (!web_contents) { |
| 216 TrackDismissEvent(DISMISS_EVENT_ERROR); | 236 TrackDismissEvent(DISMISS_EVENT_ERROR); |
| 217 return true; | 237 return true; |
| 218 } | 238 } |
| 219 | 239 |
| 220 if (!native_app_data_.is_null()) { | 240 if (!native_app_data_.is_null()) { |
| 221 TrackUserResponse(USER_RESPONSE_NATIVE_APP_ACCEPTED); | 241 return AcceptNativeApp(web_contents); |
| 222 JNIEnv* env = base::android::AttachCurrentThread(); | 242 } else if (is_webapk_) { |
| 243 return AcceptWebApk(web_contents); | |
| 244 } | |
| 245 return AcceptWebApp(web_contents); | |
| 246 } | |
| 223 | 247 |
| 224 TabAndroid* tab = TabAndroid::FromWebContents(web_contents); | 248 bool AppBannerInfoBarDelegateAndroid::AcceptNativeApp( |
| 225 if (tab == nullptr) { | 249 content::WebContents* web_contents) { |
| 226 TrackDismissEvent(DISMISS_EVENT_ERROR); | 250 TrackUserResponse(USER_RESPONSE_NATIVE_APP_ACCEPTED); |
| 227 return true; | 251 JNIEnv* env = base::android::AttachCurrentThread(); |
| 228 } | |
| 229 ScopedJavaLocalRef<jstring> jreferrer( | |
| 230 ConvertUTF8ToJavaString(env, referrer_)); | |
| 231 | 252 |
| 232 bool was_opened = | 253 TabAndroid* tab = TabAndroid::FromWebContents(web_contents); |
| 233 Java_AppBannerInfoBarDelegateAndroid_installOrOpenNativeApp( | 254 if (tab == nullptr) { |
| 234 env, java_delegate_, tab->GetJavaObject(), native_app_data_, | 255 TrackDismissEvent(DISMISS_EVENT_ERROR); |
| 235 jreferrer); | 256 return true; |
| 257 } | |
| 258 ScopedJavaLocalRef<jstring> jreferrer( | |
| 259 ConvertUTF8ToJavaString(env, referrer_)); | |
| 236 | 260 |
| 237 if (was_opened) { | 261 bool was_opened = |
| 238 TrackDismissEvent(DISMISS_EVENT_APP_OPEN); | 262 Java_AppBannerInfoBarDelegateAndroid_installOrOpenNativeApp( |
| 239 } else { | 263 env, java_delegate_, tab->GetJavaObject(), |
| 240 TrackInstallEvent(INSTALL_EVENT_NATIVE_APP_INSTALL_TRIGGERED); | 264 native_app_data_, jreferrer); |
| 241 } | 265 |
| 242 SendBannerAccepted(web_contents, "play"); | 266 if (was_opened) { |
| 243 return was_opened; | 267 TrackDismissEvent(DISMISS_EVENT_APP_OPEN); |
| 244 } else if (!manifest_.IsEmpty()) { | 268 } else { |
| 245 TrackUserResponse(USER_RESPONSE_WEB_APP_ACCEPTED); | 269 TrackInstallEvent(INSTALL_EVENT_NATIVE_APP_INSTALL_TRIGGERED); |
| 270 } | |
| 271 SendBannerAccepted(web_contents, "play"); | |
| 272 return was_opened; | |
| 273 } | |
| 274 | |
| 275 bool AppBannerInfoBarDelegateAndroid::AcceptWebApp( | |
| 276 content::WebContents* web_contents) { | |
| 277 if (manifest_.IsEmpty()) | |
| 278 return true; | |
| 279 TrackUserResponse(USER_RESPONSE_WEB_APP_ACCEPTED); | |
| 280 | |
| 281 AppBannerSettingsHelper::RecordBannerInstallEvent( | |
| 282 web_contents, manifest_.start_url.spec(), | |
| 283 AppBannerSettingsHelper::WEB); | |
| 284 | |
| 285 if (weak_manager_) { | |
| 286 ShortcutInfo info(GURL::EmptyGURL()); | |
| 287 info.UpdateFromManifest(manifest_); | |
| 288 info.manifest_url = manifest_url_; | |
| 289 info.icon_url = icon_url_; | |
| 290 info.UpdateSource(ShortcutInfo::SOURCE_APP_BANNER); | |
| 291 | |
| 292 const std::string& uid = base::GenerateGUID(); | |
| 293 ShortcutHelper::AddToLauncherWithSkBitmap( | |
| 294 web_contents->GetBrowserContext(), info, uid, *icon_.get(), | |
| 295 weak_manager_->FetchWebappSplashScreenImageCallback(uid)); | |
| 296 } | |
| 297 | |
| 298 SendBannerAccepted(web_contents, "web"); | |
| 299 return true; | |
| 300 } | |
| 301 | |
| 302 bool AppBannerInfoBarDelegateAndroid::AcceptWebApk( | |
| 303 content::WebContents* web_contents) { | |
| 304 if (manifest_.IsEmpty()) | |
| 305 return true; | |
| 306 | |
| 307 JNIEnv* env = base::android::AttachCurrentThread(); | |
| 308 if (webapk_package_name_.empty()) { | |
| 309 // Request install the WebAPK. | |
| 310 TrackUserResponse(USER_RESPONSE_WEBAPK_ACCEPTED); | |
| 246 | 311 |
| 247 AppBannerSettingsHelper::RecordBannerInstallEvent( | 312 AppBannerSettingsHelper::RecordBannerInstallEvent( |
| 248 web_contents, manifest_.start_url.spec(), | 313 web_contents, manifest_.start_url.spec(), |
| 249 AppBannerSettingsHelper::WEB); | 314 AppBannerSettingsHelper::WEBAPK); |
| 250 | 315 |
| 251 if (weak_manager_) { | 316 ShortcutInfo info(GURL::EmptyGURL()); |
| 252 ShortcutInfo info(GURL::EmptyGURL()); | 317 info.UpdateFromManifest(manifest_); |
| 253 info.UpdateFromManifest(manifest_); | 318 info.manifest_url = manifest_url_; |
| 254 info.manifest_url = manifest_url_; | 319 info.icon_url = icon_url_; |
| 255 info.icon_url = icon_url_; | 320 info.UpdateSource(ShortcutInfo::SOURCE_APP_BANNER); |
| 256 info.UpdateSource(ShortcutInfo::SOURCE_APP_BANNER); | |
| 257 | 321 |
| 258 const std::string& uid = base::GenerateGUID(); | 322 Java_AppBannerInfoBarDelegateAndroid_setWebApkInstallingState( |
| 259 ShortcutHelper::AddToLauncherWithSkBitmap( | 323 env, java_delegate_, true); |
| 260 web_contents->GetBrowserContext(), info, uid, *icon_.get(), | 324 UpdateInstallState(env, nullptr); |
|
pkotwicz
2016/08/25 22:23:15
I am not a fan of these calls. We know exactly whi
Xi Han
2016/08/26 17:04:17
The state INSTALL_STATE_INSTALLING is defined in A
pkotwicz
2016/08/26 22:31:24
I didn't realize that INSTALL_STATE_INSTALLING was
Xi Han
2016/08/29 14:44:52
I am not a fan of the way of how the state is upda
| |
| 261 weak_manager_->FetchWebappSplashScreenImageCallback(uid)); | 325 |
| 262 } | 326 WebApkInstaller::FinishCallback callback = base::Bind( |
| 327 &AppBannerInfoBarDelegateAndroid::OnWebApkInstallFinished, | |
| 328 base::Unretained(this)); | |
|
dominickn
2016/08/25 04:25:56
I'm a bit nervous about this unretained call, beca
Xi Han
2016/08/26 17:04:17
Use WeakPtrFactory instead.
| |
| 329 ShortcutHelper::InstallWebApkWithSkBitmap( | |
| 330 web_contents->GetBrowserContext(), info, *icon_.get(), callback); | |
| 331 TrackInstallEvent(INSTALL_EVENT_WEBAPK_INSTALL_TRIGGERED); | |
| 263 | 332 |
| 264 SendBannerAccepted(web_contents, "web"); | 333 SendBannerAccepted(web_contents, "web"); |
| 265 return true; | 334 return false; |
| 266 } | 335 } |
| 267 | 336 |
| 337 // Open the WebAPK. | |
| 338 ScopedJavaLocalRef<jstring> java_webapk_package_name = | |
| 339 base::android::ConvertUTF8ToJavaString(env, webapk_package_name_); | |
| 340 Java_AppBannerInfoBarDelegateAndroid_openWebApk( | |
| 341 env, java_delegate_, java_webapk_package_name); | |
| 342 | |
| 343 SendBannerAccepted(web_contents, "webapk"); | |
| 268 return true; | 344 return true; |
| 269 } | 345 } |
| 270 | 346 |
| 347 void AppBannerInfoBarDelegateAndroid::OnWebApkInstallFinished( | |
| 348 bool success, | |
| 349 const std::string& webapk_package_name) { | |
| 350 JNIEnv* env = base::android::AttachCurrentThread(); | |
| 351 if (!success) { | |
| 352 // The installation failed. | |
| 353 content::BrowserThread::PostTask( | |
| 354 content::BrowserThread::UI, FROM_HERE, | |
| 355 base::Bind(&AppBannerInfoBarDelegateAndroid::RemoveInfoBarOnUIThread, | |
| 356 base::Unretained(this))); | |
|
dominickn
2016/08/25 04:25:56
See the other comment about base::Unretained.
Xi Han
2016/08/26 17:04:17
Done.
| |
| 357 Java_AppBannerInfoBarDelegateAndroid_showWebApkInstallFailureToast(env); | |
| 358 TrackInstallEvent(INSTALL_EVENT_WEBAPK_INSTALL_FAILED); | |
| 359 return; | |
| 360 } | |
| 361 | |
| 362 webapk_package_name_ = webapk_package_name; | |
| 363 ScopedJavaLocalRef<jstring> java_webapk_package_name = | |
| 364 base::android::ConvertUTF8ToJavaString(env, webapk_package_name); | |
| 365 Java_AppBannerInfoBarDelegateAndroid_setWebApkInstallingState( | |
| 366 env, java_delegate_, false); | |
| 367 Java_AppBannerInfoBarDelegateAndroid_setWebApkPackageName( | |
| 368 env, java_delegate_, java_webapk_package_name); | |
| 369 UpdateInstallState(env, nullptr); | |
| 370 } | |
| 371 | |
| 372 void AppBannerInfoBarDelegateAndroid::RemoveInfoBarOnUIThread() { | |
| 373 static_cast<AppBannerInfoBarAndroid*>(infobar()) | |
|
dominickn
2016/08/25 04:25:56
Does this need the static cast at all? It's a meth
Xi Han
2016/08/26 17:04:17
Removed.
| |
| 374 ->RemoveSelf(); | |
| 375 } | |
| 376 | |
| 271 bool AppBannerInfoBarDelegateAndroid::LinkClicked( | 377 bool AppBannerInfoBarDelegateAndroid::LinkClicked( |
| 272 WindowOpenDisposition disposition) { | 378 WindowOpenDisposition disposition) { |
| 273 if (native_app_data_.is_null()) | 379 if (native_app_data_.is_null()) |
| 274 return false; | 380 return false; |
| 275 | 381 |
| 276 // Try to show the details for the native app. | 382 // Try to show the details for the native app. |
| 277 JNIEnv* env = base::android::AttachCurrentThread(); | 383 JNIEnv* env = base::android::AttachCurrentThread(); |
| 278 | 384 |
| 279 content::WebContents* web_contents = | 385 content::WebContents* web_contents = |
| 280 InfoBarService::WebContentsFromInfoBar(infobar()); | 386 InfoBarService::WebContentsFromInfoBar(infobar()); |
| 281 TabAndroid* tab = web_contents ? TabAndroid::FromWebContents(web_contents) | 387 TabAndroid* tab = web_contents ? TabAndroid::FromWebContents(web_contents) |
| 282 : nullptr; | 388 : nullptr; |
| 283 if (tab == nullptr) { | 389 if (tab == nullptr) { |
| 284 TrackDismissEvent(DISMISS_EVENT_ERROR); | 390 TrackDismissEvent(DISMISS_EVENT_ERROR); |
| 285 return true; | 391 return true; |
| 286 } | 392 } |
| 287 | 393 |
| 288 Java_AppBannerInfoBarDelegateAndroid_showAppDetails( | 394 Java_AppBannerInfoBarDelegateAndroid_showAppDetails( |
| 289 env, java_delegate_, tab->GetJavaObject(), native_app_data_); | 395 env, java_delegate_, tab->GetJavaObject(), native_app_data_); |
| 290 | 396 |
| 291 TrackDismissEvent(DISMISS_EVENT_BANNER_CLICK); | 397 TrackDismissEvent(DISMISS_EVENT_BANNER_CLICK); |
| 292 return true; | 398 return true; |
| 293 } | 399 } |
| 294 | 400 |
| 295 bool RegisterAppBannerInfoBarDelegateAndroid(JNIEnv* env) { | 401 bool RegisterAppBannerInfoBarDelegateAndroid(JNIEnv* env) { |
| 296 return RegisterNativesImpl(env); | 402 return RegisterNativesImpl(env); |
| 297 } | 403 } |
| 298 | 404 |
| 299 } // namespace banners | 405 } // namespace banners |
| OLD | NEW |