| 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 "base/strings/string_util.h" |
| 12 #include "chrome/browser/android/banners/app_banner_infobar_delegate.h" | 13 #include "chrome/browser/android/banners/app_banner_infobar_delegate.h" |
| 13 #include "chrome/browser/android/manifest_icon_selector.h" | 14 #include "chrome/browser/android/manifest_icon_selector.h" |
| 14 #include "chrome/browser/android/shortcut_helper.h" | 15 #include "chrome/browser/android/shortcut_helper.h" |
| 15 #include "chrome/browser/android/shortcut_info.h" | 16 #include "chrome/browser/android/shortcut_info.h" |
| 16 #include "chrome/browser/banners/app_banner_metrics.h" | 17 #include "chrome/browser/banners/app_banner_metrics.h" |
| 17 #include "chrome/browser/banners/app_banner_settings_helper.h" | 18 #include "chrome/browser/banners/app_banner_settings_helper.h" |
| 18 #include "chrome/browser/bitmap_fetcher/bitmap_fetcher.h" | 19 #include "chrome/browser/bitmap_fetcher/bitmap_fetcher.h" |
| 19 #include "chrome/browser/infobars/infobar_service.h" | 20 #include "chrome/browser/infobars/infobar_service.h" |
| 20 #include "chrome/browser/metrics/rappor/sampling.h" | 21 #include "chrome/browser/metrics/rappor/sampling.h" |
| 21 #include "chrome/browser/profiles/profile.h" | 22 #include "chrome/browser/profiles/profile.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 36 #include "net/base/load_flags.h" | 37 #include "net/base/load_flags.h" |
| 37 #include "ui/gfx/android/java_bitmap.h" | 38 #include "ui/gfx/android/java_bitmap.h" |
| 38 #include "ui/gfx/screen.h" | 39 #include "ui/gfx/screen.h" |
| 39 | 40 |
| 40 using base::android::ConvertJavaStringToUTF8; | 41 using base::android::ConvertJavaStringToUTF8; |
| 41 using base::android::ConvertJavaStringToUTF16; | 42 using base::android::ConvertJavaStringToUTF16; |
| 42 using base::android::ConvertUTF8ToJavaString; | 43 using base::android::ConvertUTF8ToJavaString; |
| 43 using base::android::ConvertUTF16ToJavaString; | 44 using base::android::ConvertUTF16ToJavaString; |
| 44 | 45 |
| 45 namespace { | 46 namespace { |
| 47 |
| 46 const char kBannerTag[] = "google-play-id"; | 48 const char kBannerTag[] = "google-play-id"; |
| 47 base::TimeDelta gTimeDeltaForTesting; | 49 base::TimeDelta gTimeDeltaForTesting; |
| 48 bool gDisableSecureCheckForTesting = false; | 50 bool gDisableSecureCheckForTesting = false; |
| 49 } // namespace | 51 const int kIconMinimumSize = 144; |
| 52 |
| 53 // The requirement for now is an image/png that is at least 144x144. |
| 54 bool DoesManifestContainRequiredIcon(const content::Manifest& manifest) { |
| 55 for (const auto& icon : manifest.icons) { |
| 56 if (EqualsASCII(icon.type.string(), "image/png")) |
| 57 continue; |
| 58 |
| 59 for (const auto& size : icon.sizes) { |
| 60 if (size.IsEmpty()) // "any" |
| 61 return true; |
| 62 if (size.width() >= kIconMinimumSize && size.height() >= kIconMinimumSize) |
| 63 return true; |
| 64 } |
| 65 } |
| 66 |
| 67 return false; |
| 68 } |
| 69 |
| 70 } // anonymous namespace |
| 50 | 71 |
| 51 namespace banners { | 72 namespace banners { |
| 52 | 73 |
| 53 // Fetches a bitmap and deletes itself when completed. | 74 // Fetches a bitmap and deletes itself when completed. |
| 54 class AppBannerManager::BannerBitmapFetcher | 75 class AppBannerManager::BannerBitmapFetcher |
| 55 : public chrome::BitmapFetcher, | 76 : public chrome::BitmapFetcher, |
| 56 public chrome::BitmapFetcherDelegate { | 77 public chrome::BitmapFetcherDelegate { |
| 57 public: | 78 public: |
| 58 BannerBitmapFetcher(const GURL& image_url, | 79 BannerBitmapFetcher(const GURL& image_url, |
| 59 banners::AppBannerManager* manager); | 80 banners::AppBannerManager* manager); |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 web_contents()->GetManifest(base::Bind(&AppBannerManager::OnDidGetManifest, | 164 web_contents()->GetManifest(base::Bind(&AppBannerManager::OnDidGetManifest, |
| 144 weak_factory_.GetWeakPtr())); | 165 weak_factory_.GetWeakPtr())); |
| 145 } | 166 } |
| 146 | 167 |
| 147 void AppBannerManager::OnDidGetManifest(const content::Manifest& manifest) { | 168 void AppBannerManager::OnDidGetManifest(const content::Manifest& manifest) { |
| 148 if (web_contents()->IsBeingDestroyed()) | 169 if (web_contents()->IsBeingDestroyed()) |
| 149 return; | 170 return; |
| 150 | 171 |
| 151 if (manifest.IsEmpty() | 172 if (manifest.IsEmpty() |
| 152 || !manifest.start_url.is_valid() | 173 || !manifest.start_url.is_valid() |
| 153 || (manifest.name.is_null() && manifest.short_name.is_null())) { | 174 || (manifest.name.is_null() && manifest.short_name.is_null()) |
| 175 || !DoesManifestContainRequiredIcon(manifest)) { |
| 154 // No usable manifest, see if there is a play store meta tag. | 176 // No usable manifest, see if there is a play store meta tag. |
| 155 Send(new ChromeViewMsg_RetrieveMetaTagContent(routing_id(), | 177 Send(new ChromeViewMsg_RetrieveMetaTagContent(routing_id(), |
| 156 validated_url_, | 178 validated_url_, |
| 157 kBannerTag)); | 179 kBannerTag)); |
| 158 return; | 180 return; |
| 159 } | 181 } |
| 160 | 182 |
| 161 banners::TrackDisplayEvent(DISPLAY_EVENT_BANNER_REQUESTED); | 183 banners::TrackDisplayEvent(DISPLAY_EVENT_BANNER_REQUESTED); |
| 162 | 184 |
| 163 web_app_data_ = manifest; | 185 web_app_data_ = manifest; |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 382 void DisableSecureSchemeCheckForTesting(JNIEnv* env, jclass clazz) { | 404 void DisableSecureSchemeCheckForTesting(JNIEnv* env, jclass clazz) { |
| 383 gDisableSecureCheckForTesting = true; | 405 gDisableSecureCheckForTesting = true; |
| 384 } | 406 } |
| 385 | 407 |
| 386 // Register native methods | 408 // Register native methods |
| 387 bool RegisterAppBannerManager(JNIEnv* env) { | 409 bool RegisterAppBannerManager(JNIEnv* env) { |
| 388 return RegisterNativesImpl(env); | 410 return RegisterNativesImpl(env); |
| 389 } | 411 } |
| 390 | 412 |
| 391 } // namespace banners | 413 } // namespace banners |
| OLD | NEW |