| 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" |
| 11 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
| 12 #include "chrome/browser/android/banners/app_banner_infobar_delegate.h" | 12 #include "chrome/browser/android/banners/app_banner_infobar_delegate.h" |
| 13 #include "chrome/browser/android/manifest_icon_selector.h" | 13 #include "chrome/browser/android/manifest_icon_selector.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/banners/app_banner_metrics.h" | 16 #include "chrome/browser/banners/app_banner_metrics.h" |
| 17 #include "chrome/browser/banners/app_banner_settings_helper.h" | 17 #include "chrome/browser/banners/app_banner_settings_helper.h" |
| 18 #include "chrome/browser/bitmap_fetcher/bitmap_fetcher.h" | 18 #include "chrome/browser/bitmap_fetcher/bitmap_fetcher.h" |
| 19 #include "chrome/browser/infobars/infobar_service.h" | 19 #include "chrome/browser/infobars/infobar_service.h" |
| 20 #include "chrome/browser/metrics/rappor/sampling.h" |
| 20 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
| 21 #include "chrome/common/chrome_constants.h" | 22 #include "chrome/common/chrome_constants.h" |
| 22 #include "chrome/common/chrome_switches.h" | 23 #include "chrome/common/chrome_switches.h" |
| 23 #include "chrome/common/render_messages.h" | 24 #include "chrome/common/render_messages.h" |
| 24 #include "content/public/browser/android/content_view_core.h" | 25 #include "content/public/browser/android/content_view_core.h" |
| 25 #include "content/public/browser/browser_context.h" | 26 #include "content/public/browser/browser_context.h" |
| 26 #include "content/public/browser/browser_thread.h" | 27 #include "content/public/browser/browser_thread.h" |
| 27 #include "content/public/browser/navigation_details.h" | 28 #include "content/public/browser/navigation_details.h" |
| 28 #include "content/public/browser/render_frame_host.h" | 29 #include "content/public/browser/render_frame_host.h" |
| 29 #include "content/public/browser/service_worker_context.h" | 30 #include "content/public/browser/service_worker_context.h" |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 return handled; | 231 return handled; |
| 231 } | 232 } |
| 232 | 233 |
| 233 void AppBannerManager::OnFetchComplete(BannerBitmapFetcher* fetcher, | 234 void AppBannerManager::OnFetchComplete(BannerBitmapFetcher* fetcher, |
| 234 const GURL url, | 235 const GURL url, |
| 235 const SkBitmap* bitmap) { | 236 const SkBitmap* bitmap) { |
| 236 if (fetcher_ != fetcher) | 237 if (fetcher_ != fetcher) |
| 237 return; | 238 return; |
| 238 fetcher_ = nullptr; | 239 fetcher_ = nullptr; |
| 239 | 240 |
| 240 if (!bitmap || url != app_icon_url_) | 241 if (!web_contents() |
| 242 || web_contents()->IsBeingDestroyed() |
| 243 || validated_url_ != web_contents()->GetURL() |
| 244 || !bitmap |
| 245 || url != app_icon_url_) { |
| 241 return; | 246 return; |
| 247 } |
| 242 | 248 |
| 243 JNIEnv* env = base::android::AttachCurrentThread(); | 249 JNIEnv* env = base::android::AttachCurrentThread(); |
| 244 ScopedJavaLocalRef<jobject> jobj = weak_java_banner_view_manager_.get(env); | 250 ScopedJavaLocalRef<jobject> jobj = weak_java_banner_view_manager_.get(env); |
| 245 if (jobj.is_null()) | 251 if (jobj.is_null()) |
| 246 return; | 252 return; |
| 247 | 253 |
| 248 InfoBarService* service = InfoBarService::FromWebContents(web_contents()); | 254 InfoBarService* service = InfoBarService::FromWebContents(web_contents()); |
| 249 | 255 |
| 250 AppBannerInfoBar* weak_infobar_ptr = nullptr; | 256 AppBannerInfoBar* weak_infobar_ptr = nullptr; |
| 251 if (!native_app_data_.is_null()) { | 257 if (!native_app_data_.is_null()) { |
| 252 RecordCouldShowBanner(native_app_package_); | 258 RecordCouldShowBanner(native_app_package_); |
| 253 if (!CheckIfShouldShow(native_app_package_)) | 259 if (!CheckIfShouldShow(native_app_package_)) |
| 254 return; | 260 return; |
| 255 | 261 |
| 256 weak_infobar_ptr = AppBannerInfoBarDelegate::CreateForNativeApp( | 262 weak_infobar_ptr = AppBannerInfoBarDelegate::CreateForNativeApp( |
| 257 service, | 263 service, |
| 258 app_title_, | 264 app_title_, |
| 259 new SkBitmap(*bitmap), | 265 new SkBitmap(*bitmap), |
| 260 native_app_data_, | 266 native_app_data_, |
| 261 native_app_package_); | 267 native_app_package_); |
| 268 |
| 269 rappor::SampleDomainAndRegistryFromGURL("AppBanner.NativeApp.Shown", |
| 270 web_contents()->GetURL()); |
| 262 } else if (!web_app_data_.IsEmpty()){ | 271 } else if (!web_app_data_.IsEmpty()){ |
| 263 RecordCouldShowBanner(web_app_data_.start_url.spec()); | 272 RecordCouldShowBanner(web_app_data_.start_url.spec()); |
| 264 if (!CheckIfShouldShow(web_app_data_.start_url.spec())) | 273 if (!CheckIfShouldShow(web_app_data_.start_url.spec())) |
| 265 return; | 274 return; |
| 266 | 275 |
| 267 weak_infobar_ptr = AppBannerInfoBarDelegate::CreateForWebApp( | 276 weak_infobar_ptr = AppBannerInfoBarDelegate::CreateForWebApp( |
| 268 service, | 277 service, |
| 269 app_title_, | 278 app_title_, |
| 270 new SkBitmap(*bitmap), | 279 new SkBitmap(*bitmap), |
| 271 web_app_data_); | 280 web_app_data_); |
| 281 |
| 282 rappor::SampleDomainAndRegistryFromGURL("AppBanner.WebApp.Shown", |
| 283 web_contents()->GetURL()); |
| 272 } | 284 } |
| 273 | 285 |
| 274 if (weak_infobar_ptr != nullptr) | 286 if (weak_infobar_ptr != nullptr) |
| 275 banners::TrackDisplayEvent(DISPLAY_EVENT_CREATED); | 287 banners::TrackDisplayEvent(DISPLAY_EVENT_CREATED); |
| 276 } | 288 } |
| 277 | 289 |
| 278 void AppBannerManager::OnDidRetrieveMetaTagContent( | 290 void AppBannerManager::OnDidRetrieveMetaTagContent( |
| 279 bool success, | 291 bool success, |
| 280 const std::string& tag_name, | 292 const std::string& tag_name, |
| 281 const std::string& tag_content, | 293 const std::string& tag_content, |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 362 void SetTimeDeltaForTesting(JNIEnv* env, jclass clazz, jint days) { | 374 void SetTimeDeltaForTesting(JNIEnv* env, jclass clazz, jint days) { |
| 363 gTimeDeltaForTesting = base::TimeDelta::FromDays(days); | 375 gTimeDeltaForTesting = base::TimeDelta::FromDays(days); |
| 364 } | 376 } |
| 365 | 377 |
| 366 // Register native methods | 378 // Register native methods |
| 367 bool RegisterAppBannerManager(JNIEnv* env) { | 379 bool RegisterAppBannerManager(JNIEnv* env) { |
| 368 return RegisterNativesImpl(env); | 380 return RegisterNativesImpl(env); |
| 369 } | 381 } |
| 370 | 382 |
| 371 } // namespace banners | 383 } // namespace banners |
| OLD | NEW |