Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_manager.h" | 5 #include "chrome/browser/android/banners/app_banner_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/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 92 } | 92 } |
| 93 | 93 |
| 94 void AppBannerManager::OnInfoBarDestroyed() { | 94 void AppBannerManager::OnInfoBarDestroyed() { |
| 95 weak_infobar_ptr_ = nullptr; | 95 weak_infobar_ptr_ = nullptr; |
| 96 } | 96 } |
| 97 | 97 |
| 98 bool AppBannerManager::OnButtonClicked() const { | 98 bool AppBannerManager::OnButtonClicked() const { |
| 99 if (!web_contents()) | 99 if (!web_contents()) |
| 100 return true; | 100 return true; |
| 101 | 101 |
| 102 if (!web_app_data_.IsEmpty()) { | 102 if (!native_app_data_.is_null()) { |
| 103 JNIEnv* env = base::android::AttachCurrentThread(); | |
| 104 ScopedJavaLocalRef<jobject> jobj = weak_java_banner_view_manager_.get(env); | |
| 105 if (jobj.is_null()) | |
| 106 return true; | |
| 107 | |
| 108 return Java_AppBannerManager_installOrOpenNativeApp(env, | |
| 109 jobj.obj(), | |
| 110 native_app_data_.obj()); | |
| 111 } else if (!web_app_data_.IsEmpty()) { | |
| 103 AppBannerSettingsHelper::RecordBannerEvent( | 112 AppBannerSettingsHelper::RecordBannerEvent( |
| 104 web_contents(), web_contents()->GetURL(), | 113 web_contents(), web_contents()->GetURL(), |
| 105 web_app_data_.start_url.spec(), | 114 web_app_data_.start_url.spec(), |
| 106 AppBannerSettingsHelper::APP_BANNER_EVENT_DID_ADD_TO_HOMESCREEN, | 115 AppBannerSettingsHelper::APP_BANNER_EVENT_DID_ADD_TO_HOMESCREEN, |
| 107 base::Time::Now()); | 116 base::Time::Now()); |
| 108 | 117 |
| 109 InstallManifestApp(web_app_data_, *app_icon_.get()); | 118 InstallManifestApp(web_app_data_, *app_icon_.get()); |
| 110 return true; | 119 return true; |
| 111 } | 120 } |
| 112 | 121 |
| 113 return true; | 122 return true; |
| 114 } | 123 } |
| 115 | 124 |
| 125 bool AppBannerManager::OnLinkClicked() const { | |
| 126 if (!web_contents()) | |
| 127 return true; | |
| 128 | |
| 129 if (!native_app_data_.is_null()) { | |
| 130 // Try to show the details for the native app. | |
| 131 JNIEnv* env = base::android::AttachCurrentThread(); | |
| 132 ScopedJavaLocalRef<jobject> jobj = weak_java_banner_view_manager_.get(env); | |
| 133 if (jobj.is_null()) | |
| 134 return true; | |
| 135 | |
| 136 Java_AppBannerManager_showAppDetails(env, | |
| 137 jobj.obj(), | |
| 138 native_app_data_.obj()); | |
| 139 return true; | |
| 140 } else { | |
| 141 // Nothing should happen if the user is installing a web app. | |
| 142 return false; | |
| 143 } | |
| 144 } | |
| 145 | |
| 116 base::string16 AppBannerManager::GetTitle() const { | 146 base::string16 AppBannerManager::GetTitle() const { |
| 117 return app_title_; | 147 return app_title_; |
| 118 } | 148 } |
| 119 | 149 |
| 120 gfx::Image AppBannerManager::GetIcon() const { | 150 gfx::Image AppBannerManager::GetIcon() const { |
| 121 return gfx::Image::CreateFrom1xBitmap(*app_icon_.get()); | 151 return gfx::Image::CreateFrom1xBitmap(*app_icon_.get()); |
| 122 } | 152 } |
| 123 | 153 |
| 124 void AppBannerManager::ReplaceWebContents(JNIEnv* env, | 154 void AppBannerManager::ReplaceWebContents(JNIEnv* env, |
| 125 jobject obj, | 155 jobject obj, |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 312 if (validated_url_ != web_contents()->GetURL()) | 342 if (validated_url_ != web_contents()->GetURL()) |
| 313 return false; | 343 return false; |
| 314 | 344 |
| 315 std::string image_url = ConvertJavaStringToUTF8(env, jicon_url); | 345 std::string image_url = ConvertJavaStringToUTF8(env, jicon_url); |
| 316 app_title_ = ConvertJavaStringToUTF16(env, japp_title); | 346 app_title_ = ConvertJavaStringToUTF16(env, japp_title); |
| 317 native_app_package_ = ConvertJavaStringToUTF8(env, japp_package); | 347 native_app_package_ = ConvertJavaStringToUTF8(env, japp_package); |
| 318 native_app_data_.Reset(env, japp_data); | 348 native_app_data_.Reset(env, japp_data); |
| 319 return FetchIcon(GURL(image_url)); | 349 return FetchIcon(GURL(image_url)); |
| 320 } | 350 } |
| 321 | 351 |
| 352 void AppBannerManager::OnIntentCompleted(JNIEnv* env, | |
| 353 jobject obj, | |
| 354 jboolean jis_installing) { | |
| 355 if (!weak_infobar_ptr_) | |
| 356 return; | |
| 357 | |
| 358 if (jis_installing) { | |
| 359 AppBannerSettingsHelper::RecordBannerEvent( | |
| 360 web_contents(), | |
| 361 web_contents()->GetURL(), | |
| 362 native_app_package_, | |
| 363 AppBannerSettingsHelper::APP_BANNER_EVENT_DID_ADD_TO_HOMESCREEN, | |
| 364 base::Time::Now()); | |
| 365 | |
| 366 ScopedJavaLocalRef<jobject> jobj = weak_java_banner_view_manager_.get(env); | |
|
newt (away)
2015/02/06 22:46:27
what if jobj is null? Same issue below.
gone
2015/02/06 23:32:08
Null checking now.
| |
| 367 Java_AppBannerManager_monitorInstall(env, | |
|
newt (away)
2015/02/06 22:46:27
Why not call monitorInstall() from Java?
gone
2015/02/06 22:55:01
AppData isn't available from there; it doesn't sto
| |
| 368 jobj.obj(), | |
| 369 native_app_data_.obj()); | |
| 370 } | |
| 371 | |
| 372 UpdateInstallState(env, obj); | |
| 373 } | |
| 374 | |
| 375 void AppBannerManager::OnInstallFinished(JNIEnv* env, | |
| 376 jobject obj, | |
| 377 jboolean success) { | |
| 378 if (!weak_infobar_ptr_) | |
| 379 return; | |
| 380 | |
| 381 if (success) { | |
| 382 UpdateInstallState(env, obj); | |
| 383 } else { | |
| 384 InfoBarService* service = InfoBarService::FromWebContents(web_contents()); | |
| 385 service->RemoveInfoBar(weak_infobar_ptr_); | |
| 386 } | |
| 387 } | |
| 388 | |
| 389 void AppBannerManager::UpdateInstallState(JNIEnv *env, jobject obj) { | |
| 390 if (!weak_infobar_ptr_ || native_app_data_.is_null()) | |
| 391 return; | |
| 392 | |
| 393 ScopedJavaLocalRef<jobject> jobj = weak_java_banner_view_manager_.get(env); | |
| 394 int newState = Java_AppBannerManager_determineInstallState( | |
| 395 env, | |
| 396 jobj.obj(), | |
| 397 native_app_data_.obj()); | |
| 398 weak_infobar_ptr_->OnInstallStateChanged(newState); | |
| 399 } | |
| 400 | |
| 322 bool AppBannerManager::FetchIcon(const GURL& image_url) { | 401 bool AppBannerManager::FetchIcon(const GURL& image_url) { |
| 323 if (!web_contents()) | 402 if (!web_contents()) |
| 324 return false; | 403 return false; |
| 325 | 404 |
| 326 // Begin asynchronously fetching the app icon. | 405 // Begin asynchronously fetching the app icon. |
| 327 Profile* profile = | 406 Profile* profile = |
| 328 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); | 407 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
| 329 fetcher_.reset(new chrome::BitmapFetcher(image_url, this)); | 408 fetcher_.reset(new chrome::BitmapFetcher(image_url, this)); |
| 330 fetcher_.get()->Start( | 409 fetcher_.get()->Start( |
| 331 profile->GetRequestContext(), | 410 profile->GetRequestContext(), |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 376 return base::CommandLine::ForCurrentProcess()->HasSwitch( | 455 return base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 377 switches::kEnableAppInstallAlerts); | 456 switches::kEnableAppInstallAlerts); |
| 378 } | 457 } |
| 379 | 458 |
| 380 // Register native methods | 459 // Register native methods |
| 381 bool RegisterAppBannerManager(JNIEnv* env) { | 460 bool RegisterAppBannerManager(JNIEnv* env) { |
| 382 return RegisterNativesImpl(env); | 461 return RegisterNativesImpl(env); |
| 383 } | 462 } |
| 384 | 463 |
| 385 } // namespace banners | 464 } // namespace banners |
| OLD | NEW |