Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(157)

Side by Side Diff: chrome/browser/android/banners/app_banner_infobar_delegate_android.cc

Issue 2393513004: Convert app banners to use Mojo. (Closed)
Patch Set: Add TODO Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
13 #include "base/strings/utf_string_conversions.h"
14 #include "chrome/browser/android/shortcut_helper.h" 12 #include "chrome/browser/android/shortcut_helper.h"
15 #include "chrome/browser/android/shortcut_info.h" 13 #include "chrome/browser/android/shortcut_info.h"
16 #include "chrome/browser/android/tab_android.h" 14 #include "chrome/browser/android/tab_android.h"
17 #include "chrome/browser/android/webapk/chrome_webapk_host.h" 15 #include "chrome/browser/android/webapk/chrome_webapk_host.h"
18 #include "chrome/browser/android/webapk/webapk_installer.h" 16 #include "chrome/browser/android/webapk/webapk_installer.h"
19 #include "chrome/browser/banners/app_banner_manager.h" 17 #include "chrome/browser/banners/app_banner_manager.h"
20 #include "chrome/browser/banners/app_banner_metrics.h" 18 #include "chrome/browser/banners/app_banner_metrics.h"
21 #include "chrome/browser/banners/app_banner_settings_helper.h" 19 #include "chrome/browser/banners/app_banner_settings_helper.h"
22 #include "chrome/browser/browser_process.h" 20 #include "chrome/browser/browser_process.h"
23 #include "chrome/browser/infobars/infobar_service.h" 21 #include "chrome/browser/infobars/infobar_service.h"
24 #include "chrome/browser/ui/android/infobars/app_banner_infobar_android.h" 22 #include "chrome/browser/ui/android/infobars/app_banner_infobar_android.h"
25 #include "chrome/common/render_messages.h"
26 #include "components/rappor/rappor_utils.h" 23 #include "components/rappor/rappor_utils.h"
27 #include "content/public/browser/render_frame_host.h"
28 #include "content/public/browser/web_contents.h" 24 #include "content/public/browser/web_contents.h"
29 #include "content/public/common/manifest.h" 25 #include "content/public/common/manifest.h"
30 #include "jni/AppBannerInfoBarDelegateAndroid_jni.h" 26 #include "jni/AppBannerInfoBarDelegateAndroid_jni.h"
31 #include "ui/gfx/android/java_bitmap.h" 27 #include "ui/gfx/android/java_bitmap.h"
32 #include "url/gurl.h" 28 #include "url/gurl.h"
33 29
34 using base::android::ConvertJavaStringToUTF8; 30 using base::android::ConvertJavaStringToUTF8;
35 using base::android::ConvertJavaStringToUTF16; 31 using base::android::ConvertJavaStringToUTF16;
36 using base::android::ConvertUTF8ToJavaString; 32 using base::android::ConvertUTF8ToJavaString;
37 using base::android::ConvertUTF16ToJavaString; 33 using base::android::ConvertUTF16ToJavaString;
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 bool was_opened = 272 bool was_opened =
277 Java_AppBannerInfoBarDelegateAndroid_installOrOpenNativeApp( 273 Java_AppBannerInfoBarDelegateAndroid_installOrOpenNativeApp(
278 env, java_delegate_, tab->GetJavaObject(), 274 env, java_delegate_, tab->GetJavaObject(),
279 native_app_data_, jreferrer); 275 native_app_data_, jreferrer);
280 276
281 if (was_opened) 277 if (was_opened)
282 TrackDismissEvent(DISMISS_EVENT_APP_OPEN); 278 TrackDismissEvent(DISMISS_EVENT_APP_OPEN);
283 else 279 else
284 TrackInstallEvent(INSTALL_EVENT_NATIVE_APP_INSTALL_TRIGGERED); 280 TrackInstallEvent(INSTALL_EVENT_NATIVE_APP_INSTALL_TRIGGERED);
285 281
286 SendBannerAccepted(web_contents, "play"); 282 SendBannerAccepted();
287 return was_opened; 283 return was_opened;
288 } 284 }
289 285
290 bool AppBannerInfoBarDelegateAndroid::AcceptWebApp( 286 bool AppBannerInfoBarDelegateAndroid::AcceptWebApp(
291 content::WebContents* web_contents) { 287 content::WebContents* web_contents) {
292 if (IsInfoEmpty(shortcut_info_)) 288 if (IsInfoEmpty(shortcut_info_))
293 return true; 289 return true;
294 TrackUserResponse(USER_RESPONSE_WEB_APP_ACCEPTED); 290 TrackUserResponse(USER_RESPONSE_WEB_APP_ACCEPTED);
295 291
296 AppBannerSettingsHelper::RecordBannerInstallEvent( 292 AppBannerSettingsHelper::RecordBannerInstallEvent(
297 web_contents, shortcut_info_->url.spec(), AppBannerSettingsHelper::WEB); 293 web_contents, shortcut_info_->url.spec(), AppBannerSettingsHelper::WEB);
298 294
299 if (weak_manager_) { 295 if (weak_manager_) {
300 const std::string& uid = base::GenerateGUID(); 296 const std::string& uid = base::GenerateGUID();
301 ShortcutHelper::AddToLauncherWithSkBitmap( 297 ShortcutHelper::AddToLauncherWithSkBitmap(
302 web_contents->GetBrowserContext(), *shortcut_info_, uid, 298 web_contents->GetBrowserContext(), *shortcut_info_, uid,
303 *icon_.get(), weak_manager_->FetchWebappSplashScreenImageCallback(uid)); 299 *icon_.get(), weak_manager_->FetchWebappSplashScreenImageCallback(uid));
304 } 300 }
305 301
306 SendBannerAccepted(web_contents, "web"); 302 SendBannerAccepted();
307 return true; 303 return true;
308 } 304 }
309 305
310 bool AppBannerInfoBarDelegateAndroid::AcceptWebApk( 306 bool AppBannerInfoBarDelegateAndroid::AcceptWebApk(
311 content::WebContents* web_contents) { 307 content::WebContents* web_contents) {
312 if (IsInfoEmpty(shortcut_info_)) 308 if (IsInfoEmpty(shortcut_info_))
313 return true; 309 return true;
314 310
315 JNIEnv* env = base::android::AttachCurrentThread(); 311 JNIEnv* env = base::android::AttachCurrentThread();
316 312
317 // If the WebAPK is installed and the "Open" button is clicked, open the 313 // If the WebAPK is installed and the "Open" button is clicked, open the
318 // WebAPK. 314 // WebAPK.
319 if (install_state_ == INSTALLED) { 315 if (install_state_ == INSTALLED) {
320 Java_AppBannerInfoBarDelegateAndroid_openWebApk(env, java_delegate_); 316 Java_AppBannerInfoBarDelegateAndroid_openWebApk(env, java_delegate_);
321 if (is_webapk_already_installed_) 317 if (is_webapk_already_installed_)
322 webapk::TrackUserAction(webapk::USER_ACTION_OPEN); 318 webapk::TrackUserAction(webapk::USER_ACTION_OPEN);
323 else 319 else
324 webapk::TrackUserAction(webapk::USER_ACTION_INSTALLED_OPEN); 320 webapk::TrackUserAction(webapk::USER_ACTION_INSTALLED_OPEN);
325 SendBannerAccepted(web_contents, "web"); 321 SendBannerAccepted();
326 return true; 322 return true;
327 } 323 }
328 324
329 // If the WebAPK is not installed and the "Add to Home Screen" button is 325 // If the WebAPK is not installed and the "Add to Home Screen" button is
330 // clicked, install the WebAPK. 326 // clicked, install the WebAPK.
331 install_state_ = INSTALLING; 327 install_state_ = INSTALLING;
332 TrackUserResponse(USER_RESPONSE_WEB_APP_ACCEPTED); 328 TrackUserResponse(USER_RESPONSE_WEB_APP_ACCEPTED);
333 webapk::TrackInstallSource(webapk_install_source_); 329 webapk::TrackInstallSource(webapk_install_source_);
334 AppBannerSettingsHelper::RecordBannerInstallEvent( 330 AppBannerSettingsHelper::RecordBannerInstallEvent(
335 web_contents, shortcut_info_->url.spec(), AppBannerSettingsHelper::WEB); 331 web_contents, shortcut_info_->url.spec(), AppBannerSettingsHelper::WEB);
336 332
337 Java_AppBannerInfoBarDelegateAndroid_setWebApkInstallingState( 333 Java_AppBannerInfoBarDelegateAndroid_setWebApkInstallingState(
338 env, java_delegate_, true); 334 env, java_delegate_, true);
339 UpdateInstallState(env, nullptr); 335 UpdateInstallState(env, nullptr);
340 WebApkInstaller::FinishCallback callback = 336 WebApkInstaller::FinishCallback callback =
341 base::Bind(&AppBannerInfoBarDelegateAndroid::OnWebApkInstallFinished, 337 base::Bind(&AppBannerInfoBarDelegateAndroid::OnWebApkInstallFinished,
342 weak_ptr_factory_.GetWeakPtr()); 338 weak_ptr_factory_.GetWeakPtr());
343 ShortcutHelper::InstallWebApkWithSkBitmap(web_contents->GetBrowserContext(), 339 ShortcutHelper::InstallWebApkWithSkBitmap(web_contents->GetBrowserContext(),
344 *shortcut_info_, 340 *shortcut_info_,
345 *icon_.get(), callback); 341 *icon_.get(), callback);
346 SendBannerAccepted(web_contents, "web"); 342 SendBannerAccepted();
347 343
348 // Prevent the infobar from disappearing, because the infobar will show 344 // Prevent the infobar from disappearing, because the infobar will show
349 // "Adding" during the installation process. 345 // "Adding" during the installation process.
350 return false; 346 return false;
351 } 347 }
352 348
353 void AppBannerInfoBarDelegateAndroid::SendBannerAccepted( 349 void AppBannerInfoBarDelegateAndroid::SendBannerAccepted() {
354 content::WebContents* web_contents, 350 if (weak_manager_)
355 const std::string& platform) { 351 weak_manager_->SendBannerAccepted(event_request_id_);
356 web_contents->GetMainFrame()->Send(
357 new ChromeViewMsg_AppBannerAccepted(
358 web_contents->GetMainFrame()->GetRoutingID(),
359 event_request_id_,
360 platform));
361 } 352 }
362 353
363 void AppBannerInfoBarDelegateAndroid::OnWebApkInstallFinished( 354 void AppBannerInfoBarDelegateAndroid::OnWebApkInstallFinished(
364 bool success, 355 bool success,
365 const std::string& webapk_package_name) { 356 const std::string& webapk_package_name) {
366 JNIEnv* env = base::android::AttachCurrentThread(); 357 JNIEnv* env = base::android::AttachCurrentThread();
367 if (!success) { 358 if (!success) {
368 DVLOG(1) << "The WebAPK installation failed."; 359 DVLOG(1) << "The WebAPK installation failed.";
369 Java_AppBannerInfoBarDelegateAndroid_showWebApkInstallFailureToast(env); 360 Java_AppBannerInfoBarDelegateAndroid_showWebApkInstallFailureToast(env);
370 webapk::TrackInstallEvent(webapk::INSTALL_FAILED); 361 webapk::TrackInstallEvent(webapk::INSTALL_FAILED);
(...skipping 30 matching lines...) Expand all
401 gfx::Image AppBannerInfoBarDelegateAndroid::GetIcon() const { 392 gfx::Image AppBannerInfoBarDelegateAndroid::GetIcon() const {
402 return gfx::Image::CreateFrom1xBitmap(*icon_.get()); 393 return gfx::Image::CreateFrom1xBitmap(*icon_.get());
403 } 394 }
404 395
405 void AppBannerInfoBarDelegateAndroid::InfoBarDismissed() { 396 void AppBannerInfoBarDelegateAndroid::InfoBarDismissed() {
406 has_user_interaction_ = true; 397 has_user_interaction_ = true;
407 398
408 content::WebContents* web_contents = 399 content::WebContents* web_contents =
409 InfoBarService::WebContentsFromInfoBar(infobar()); 400 InfoBarService::WebContentsFromInfoBar(infobar());
410 401
411 web_contents->GetMainFrame()->Send( 402 if (weak_manager_)
412 new ChromeViewMsg_AppBannerDismissed( 403 weak_manager_->SendBannerDismissed(event_request_id_);
413 web_contents->GetMainFrame()->GetRoutingID(),
414 event_request_id_));
415 404
416 if (native_app_data_.is_null()) { 405 if (native_app_data_.is_null()) {
417 if (is_webapk_) 406 if (is_webapk_)
418 TrackWebApkInstallationDismissEvents(install_state_); 407 TrackWebApkInstallationDismissEvents(install_state_);
419 TrackUserResponse(USER_RESPONSE_WEB_APP_DISMISSED); 408 TrackUserResponse(USER_RESPONSE_WEB_APP_DISMISSED);
420 AppBannerSettingsHelper::RecordBannerDismissEvent( 409 AppBannerSettingsHelper::RecordBannerDismissEvent(
421 web_contents, shortcut_info_->url.spec(), AppBannerSettingsHelper::WEB); 410 web_contents, shortcut_info_->url.spec(), AppBannerSettingsHelper::WEB);
422 } else { 411 } else {
423 TrackUserResponse(USER_RESPONSE_NATIVE_APP_DISMISSED); 412 TrackUserResponse(USER_RESPONSE_NATIVE_APP_DISMISSED);
424 AppBannerSettingsHelper::RecordBannerDismissEvent( 413 AppBannerSettingsHelper::RecordBannerDismissEvent(
(...skipping 23 matching lines...) Expand all
448 DCHECK(tab); 437 DCHECK(tab);
449 438
450 Java_AppBannerInfoBarDelegateAndroid_showAppDetails( 439 Java_AppBannerInfoBarDelegateAndroid_showAppDetails(
451 env, java_delegate_, tab->GetJavaObject(), native_app_data_); 440 env, java_delegate_, tab->GetJavaObject(), native_app_data_);
452 441
453 TrackDismissEvent(DISMISS_EVENT_BANNER_CLICK); 442 TrackDismissEvent(DISMISS_EVENT_BANNER_CLICK);
454 return true; 443 return true;
455 } 444 }
456 445
457 bool RegisterAppBannerInfoBarDelegateAndroid(JNIEnv* env) { 446 bool RegisterAppBannerInfoBarDelegateAndroid(JNIEnv* env) {
458 return RegisterNativesImpl(env); 447 return RegisterNativesImpl(env);
459 } 448 }
460 449
461 } // namespace banners 450 } // namespace banners
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698