| 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 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 // TODO(benwells): Check triggering parameters. | 192 // TODO(benwells): Check triggering parameters. |
| 193 // Create an infobar to promote the manifest's app. | 193 // Create an infobar to promote the manifest's app. |
| 194 GURL icon_url = | 194 GURL icon_url = |
| 195 ManifestIconSelector::FindBestMatchingIcon( | 195 ManifestIconSelector::FindBestMatchingIcon( |
| 196 web_app_data_.icons, | 196 web_app_data_.icons, |
| 197 GetPreferredIconSize(), | 197 GetPreferredIconSize(), |
| 198 gfx::Screen::GetScreenFor(web_contents()->GetNativeView())); | 198 gfx::Screen::GetScreenFor(web_contents()->GetNativeView())); |
| 199 if (icon_url.is_empty()) | 199 if (icon_url.is_empty()) |
| 200 return; | 200 return; |
| 201 | 201 |
| 202 RecordCouldShowBanner(web_app_data_.start_url.spec()); | |
| 203 if (!CheckIfShouldShow(web_app_data_.start_url.spec())) | |
| 204 return; | |
| 205 | |
| 206 FetchIcon(icon_url); | 202 FetchIcon(icon_url); |
| 207 } | 203 } |
| 208 } | 204 } |
| 209 | 205 |
| 210 void AppBannerManager::RecordCouldShowBanner( | 206 void AppBannerManager::RecordCouldShowBanner( |
| 211 const std::string& package_or_start_url) { | 207 const std::string& package_or_start_url) { |
| 212 AppBannerSettingsHelper::RecordBannerEvent( | 208 AppBannerSettingsHelper::RecordBannerEvent( |
| 213 web_contents(), validated_url_, package_or_start_url, | 209 web_contents(), validated_url_, package_or_start_url, |
| 214 AppBannerSettingsHelper::APP_BANNER_EVENT_COULD_SHOW, base::Time::Now()); | 210 AppBannerSettingsHelper::APP_BANNER_EVENT_COULD_SHOW, base::Time::Now()); |
| 215 } | 211 } |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 JNIEnv* env = base::android::AttachCurrentThread(); | 244 JNIEnv* env = base::android::AttachCurrentThread(); |
| 249 ScopedJavaLocalRef<jobject> jobj = weak_java_banner_view_manager_.get(env); | 245 ScopedJavaLocalRef<jobject> jobj = weak_java_banner_view_manager_.get(env); |
| 250 if (jobj.is_null()) | 246 if (jobj.is_null()) |
| 251 return; | 247 return; |
| 252 | 248 |
| 253 app_icon_.reset(new SkBitmap(*bitmap)); | 249 app_icon_.reset(new SkBitmap(*bitmap)); |
| 254 InfoBarService* service = InfoBarService::FromWebContents(web_contents()); | 250 InfoBarService* service = InfoBarService::FromWebContents(web_contents()); |
| 255 | 251 |
| 256 weak_infobar_ptr_ = nullptr; | 252 weak_infobar_ptr_ = nullptr; |
| 257 if (!native_app_data_.is_null()) { | 253 if (!native_app_data_.is_null()) { |
| 254 RecordCouldShowBanner(native_app_package_); |
| 255 if (!CheckIfShouldShow(native_app_package_)) |
| 256 return; |
| 257 |
| 258 weak_infobar_ptr_ = AppBannerInfoBarDelegate::CreateForNativeApp( | 258 weak_infobar_ptr_ = AppBannerInfoBarDelegate::CreateForNativeApp( |
| 259 service, | 259 service, |
| 260 this, | 260 this, |
| 261 native_app_data_); | 261 native_app_data_); |
| 262 } else if (!web_app_data_.IsEmpty()){ | 262 } else if (!web_app_data_.IsEmpty()){ |
| 263 RecordCouldShowBanner(web_app_data_.start_url.spec()); |
| 264 if (!CheckIfShouldShow(web_app_data_.start_url.spec())) |
| 265 return; |
| 266 |
| 263 weak_infobar_ptr_ = AppBannerInfoBarDelegate::CreateForWebApp( | 267 weak_infobar_ptr_ = AppBannerInfoBarDelegate::CreateForWebApp( |
| 264 service, | 268 service, |
| 265 this, | 269 this, |
| 266 web_app_data_.start_url); | 270 web_app_data_.start_url); |
| 267 } | 271 } |
| 268 | 272 |
| 269 if (weak_infobar_ptr_ != nullptr) | 273 if (weak_infobar_ptr_ != nullptr) |
| 270 banners::TrackDisplayEvent(DISPLAY_CREATED); | 274 banners::TrackDisplayEvent(DISPLAY_CREATED); |
| 271 } | 275 } |
| 272 | 276 |
| 273 void AppBannerManager::OnDidRetrieveMetaTagContent( | 277 void AppBannerManager::OnDidRetrieveMetaTagContent( |
| 274 bool success, | 278 bool success, |
| 275 const std::string& tag_name, | 279 const std::string& tag_name, |
| 276 const std::string& tag_content, | 280 const std::string& tag_content, |
| 277 const GURL& expected_url) { | 281 const GURL& expected_url) { |
| 278 DCHECK(web_contents()); | 282 DCHECK(web_contents()); |
| 279 if (!success || tag_name != kBannerTag || validated_url_ != expected_url || | 283 if (!success || tag_name != kBannerTag || validated_url_ != expected_url || |
| 280 tag_content.size() >= chrome::kMaxMetaTagAttributeLength) { | 284 tag_content.size() >= chrome::kMaxMetaTagAttributeLength) { |
| 281 return; | 285 return; |
| 282 } | 286 } |
| 283 | 287 |
| 284 banners::TrackDisplayEvent(DISPLAY_BANNER_REQUESTED); | 288 banners::TrackDisplayEvent(DISPLAY_BANNER_REQUESTED); |
| 285 | 289 |
| 286 RecordCouldShowBanner(tag_content); | |
| 287 if (!CheckIfShouldShow(tag_content)) | |
| 288 return; | |
| 289 | |
| 290 // Send the info to the Java side to get info about the app. | 290 // Send the info to the Java side to get info about the app. |
| 291 JNIEnv* env = base::android::AttachCurrentThread(); | 291 JNIEnv* env = base::android::AttachCurrentThread(); |
| 292 ScopedJavaLocalRef<jobject> jobj = weak_java_banner_view_manager_.get(env); | 292 ScopedJavaLocalRef<jobject> jobj = weak_java_banner_view_manager_.get(env); |
| 293 if (jobj.is_null()) | 293 if (jobj.is_null()) |
| 294 return; | 294 return; |
| 295 | 295 |
| 296 ScopedJavaLocalRef<jstring> jurl( | 296 ScopedJavaLocalRef<jstring> jurl( |
| 297 ConvertUTF8ToJavaString(env, expected_url.spec())); | 297 ConvertUTF8ToJavaString(env, expected_url.spec())); |
| 298 ScopedJavaLocalRef<jstring> jpackage( | 298 ScopedJavaLocalRef<jstring> jpackage( |
| 299 ConvertUTF8ToJavaString(env, tag_content)); | 299 ConvertUTF8ToJavaString(env, tag_content)); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 return base::CommandLine::ForCurrentProcess()->HasSwitch( | 376 return base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 377 switches::kEnableAppInstallAlerts); | 377 switches::kEnableAppInstallAlerts); |
| 378 } | 378 } |
| 379 | 379 |
| 380 // Register native methods | 380 // Register native methods |
| 381 bool RegisterAppBannerManager(JNIEnv* env) { | 381 bool RegisterAppBannerManager(JNIEnv* env) { |
| 382 return RegisterNativesImpl(env); | 382 return RegisterNativesImpl(env); |
| 383 } | 383 } |
| 384 | 384 |
| 385 } // namespace banners | 385 } // namespace banners |
| OLD | NEW |