| 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 26 matching lines...) Expand all Loading... |
| 37 #include "ui/gfx/screen.h" | 37 #include "ui/gfx/screen.h" |
| 38 | 38 |
| 39 using base::android::ConvertJavaStringToUTF8; | 39 using base::android::ConvertJavaStringToUTF8; |
| 40 using base::android::ConvertJavaStringToUTF16; | 40 using base::android::ConvertJavaStringToUTF16; |
| 41 using base::android::ConvertUTF8ToJavaString; | 41 using base::android::ConvertUTF8ToJavaString; |
| 42 using base::android::ConvertUTF16ToJavaString; | 42 using base::android::ConvertUTF16ToJavaString; |
| 43 | 43 |
| 44 namespace { | 44 namespace { |
| 45 const char kBannerTag[] = "google-play-id"; | 45 const char kBannerTag[] = "google-play-id"; |
| 46 base::TimeDelta gTimeDeltaForTesting; | 46 base::TimeDelta gTimeDeltaForTesting; |
| 47 bool gDisableSecureCheckForTesting = false; |
| 47 } // namespace | 48 } // namespace |
| 48 | 49 |
| 49 namespace banners { | 50 namespace banners { |
| 50 | 51 |
| 51 // Fetches a bitmap and deletes itself when completed. | 52 // Fetches a bitmap and deletes itself when completed. |
| 52 class AppBannerManager::BannerBitmapFetcher | 53 class AppBannerManager::BannerBitmapFetcher |
| 53 : public chrome::BitmapFetcher, | 54 : public chrome::BitmapFetcher, |
| 54 public chrome::BitmapFetcherDelegate { | 55 public chrome::BitmapFetcherDelegate { |
| 55 public: | 56 public: |
| 56 BannerBitmapFetcher(const GURL& image_url, | 57 BannerBitmapFetcher(const GURL& image_url, |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 native_app_package_ = std::string(); | 126 native_app_package_ = std::string(); |
| 126 } | 127 } |
| 127 | 128 |
| 128 void AppBannerManager::DidFinishLoad( | 129 void AppBannerManager::DidFinishLoad( |
| 129 content::RenderFrameHost* render_frame_host, | 130 content::RenderFrameHost* render_frame_host, |
| 130 const GURL& validated_url) { | 131 const GURL& validated_url) { |
| 131 if (render_frame_host->GetParent()) | 132 if (render_frame_host->GetParent()) |
| 132 return; | 133 return; |
| 133 validated_url_ = validated_url; | 134 validated_url_ = validated_url; |
| 134 | 135 |
| 136 // A secure scheme is required to show banners, so exit early if we see the |
| 137 // URL is invalid. |
| 138 if (!validated_url_.SchemeIsSecure() && !gDisableSecureCheckForTesting) |
| 139 return; |
| 140 |
| 135 // See if the page has a manifest. Using Unretained(this) here is safe as the | 141 // See if the page has a manifest. Using Unretained(this) here is safe as the |
| 136 // lifetime of this object extends beyond the lifetime of the web_contents(), | 142 // lifetime of this object extends beyond the lifetime of the web_contents(), |
| 137 // and when web_contents() is destroyed it will call OnDidGetManifest. | 143 // and when web_contents() is destroyed it will call OnDidGetManifest. |
| 138 web_contents()->GetManifest(base::Bind(&AppBannerManager::OnDidGetManifest, | 144 web_contents()->GetManifest(base::Bind(&AppBannerManager::OnDidGetManifest, |
| 139 base::Unretained(this))); | 145 base::Unretained(this))); |
| 140 } | 146 } |
| 141 | 147 |
| 142 void AppBannerManager::OnDidGetManifest(const content::Manifest& manifest) { | 148 void AppBannerManager::OnDidGetManifest(const content::Manifest& manifest) { |
| 143 if (web_contents()->IsBeingDestroyed()) | 149 if (web_contents()->IsBeingDestroyed()) |
| 144 return; | 150 return; |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 | 362 |
| 357 jboolean IsEnabled(JNIEnv* env, jclass clazz) { | 363 jboolean IsEnabled(JNIEnv* env, jclass clazz) { |
| 358 return base::CommandLine::ForCurrentProcess()->HasSwitch( | 364 return base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 359 switches::kEnableAppInstallAlerts); | 365 switches::kEnableAppInstallAlerts); |
| 360 } | 366 } |
| 361 | 367 |
| 362 void SetTimeDeltaForTesting(JNIEnv* env, jclass clazz, jint days) { | 368 void SetTimeDeltaForTesting(JNIEnv* env, jclass clazz, jint days) { |
| 363 gTimeDeltaForTesting = base::TimeDelta::FromDays(days); | 369 gTimeDeltaForTesting = base::TimeDelta::FromDays(days); |
| 364 } | 370 } |
| 365 | 371 |
| 372 void DisableSecureSchemeCheckForTesting(JNIEnv* env, jclass clazz) { |
| 373 gDisableSecureCheckForTesting = true; |
| 374 } |
| 375 |
| 366 // Register native methods | 376 // Register native methods |
| 367 bool RegisterAppBannerManager(JNIEnv* env) { | 377 bool RegisterAppBannerManager(JNIEnv* env) { |
| 368 return RegisterNativesImpl(env); | 378 return RegisterNativesImpl(env); |
| 369 } | 379 } |
| 370 | 380 |
| 371 } // namespace banners | 381 } // namespace banners |
| OLD | NEW |