| OLD | NEW |
| 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 <utility> | 5 #include <utility> |
| 6 | 6 |
| 7 #include "chrome/browser/android/banners/app_banner_manager_android.h" | 7 #include "chrome/browser/android/banners/app_banner_manager_android.h" |
| 8 | 8 |
| 9 #include "base/android/jni_android.h" | 9 #include "base/android/jni_android.h" |
| 10 #include "base/android/jni_string.h" | 10 #include "base/android/jni_string.h" |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 // Check if the manifest prefers that we show a native app banner. If so, call | 144 // Check if the manifest prefers that we show a native app banner. If so, call |
| 145 // to Java to verify the details. | 145 // to Java to verify the details. |
| 146 if (manifest_.prefer_related_applications && | 146 if (manifest_.prefer_related_applications && |
| 147 manifest_.related_applications.size()) { | 147 manifest_.related_applications.size()) { |
| 148 for (const auto& application : manifest_.related_applications) { | 148 for (const auto& application : manifest_.related_applications) { |
| 149 std::string platform = base::UTF16ToUTF8(application.platform.string()); | 149 std::string platform = base::UTF16ToUTF8(application.platform.string()); |
| 150 std::string id = base::UTF16ToUTF8(application.id.string()); | 150 std::string id = base::UTF16ToUTF8(application.id.string()); |
| 151 if (CanHandleNonWebApp(platform, application.url, id)) | 151 if (CanHandleNonWebApp(platform, application.url, id)) |
| 152 return; | 152 return; |
| 153 } | 153 } |
| 154 Stop(); |
| 154 } | 155 } |
| 155 | 156 |
| 156 // No native app banner was requested. Continue checking for a web app banner. | 157 // No native app banner was requested. Continue checking for a web app banner. |
| 157 AppBannerManager::PerformInstallableCheck(); | 158 AppBannerManager::PerformInstallableCheck(); |
| 158 } | 159 } |
| 159 | 160 |
| 160 void AppBannerManagerAndroid::OnAppIconFetched(const SkBitmap& bitmap) { | 161 void AppBannerManagerAndroid::OnAppIconFetched(const SkBitmap& bitmap) { |
| 161 if (bitmap.drawsNothing()) { | 162 if (bitmap.drawsNothing()) { |
| 162 ReportError(web_contents(), NO_ICON_AVAILABLE); | 163 ReportStatus(web_contents(), NO_ICON_AVAILABLE); |
| 163 Stop(); | 164 Stop(); |
| 164 } | 165 } |
| 165 | 166 |
| 166 if (!is_active()) | 167 if (!is_active()) |
| 167 return; | 168 return; |
| 168 | 169 |
| 169 icon_.reset(new SkBitmap(bitmap)); | 170 icon_.reset(new SkBitmap(bitmap)); |
| 170 SendBannerPromptRequest(); | 171 SendBannerPromptRequest(); |
| 171 } | 172 } |
| 172 | 173 |
| 173 void AppBannerManagerAndroid::ShowBanner() { | 174 void AppBannerManagerAndroid::ShowBanner() { |
| 174 content::WebContents* contents = web_contents(); | 175 content::WebContents* contents = web_contents(); |
| 175 DCHECK(contents); | 176 DCHECK(contents); |
| 176 | 177 |
| 177 infobars::InfoBar* infobar = nullptr; | 178 infobars::InfoBar* infobar = nullptr; |
| 178 if (native_app_data_.is_null()) { | 179 if (native_app_data_.is_null()) { |
| 179 std::unique_ptr<AppBannerInfoBarDelegateAndroid> delegate( | 180 std::unique_ptr<AppBannerInfoBarDelegateAndroid> delegate( |
| 180 new AppBannerInfoBarDelegateAndroid( | 181 new AppBannerInfoBarDelegateAndroid( |
| 181 GetWeakPtr(), app_title_, manifest_url_, manifest_, icon_url_, | 182 GetWeakPtr(), app_title_, manifest_url_, manifest_, icon_url_, |
| 182 std::move(icon_), event_request_id())); | 183 std::move(icon_), event_request_id())); |
| 183 | 184 |
| 184 infobar = new AppBannerInfoBarAndroid(std::move(delegate), | 185 infobar = new AppBannerInfoBarAndroid(std::move(delegate), |
| 185 manifest_.start_url); | 186 manifest_.start_url); |
| 186 if (infobar) { | 187 if (infobar) { |
| 187 RecordDidShowBanner("AppBanner.WebApp.Shown"); | 188 RecordDidShowBanner("AppBanner.WebApp.Shown"); |
| 188 TrackDisplayEvent(DISPLAY_EVENT_WEB_APP_BANNER_CREATED); | 189 TrackDisplayEvent(DISPLAY_EVENT_WEB_APP_BANNER_CREATED); |
| 190 ReportStatus(contents, SHOWING_WEB_APP_BANNER); |
| 191 } else { |
| 192 ReportStatus(contents, FAILED_TO_CREATE_BANNER); |
| 189 } | 193 } |
| 190 } else { | 194 } else { |
| 191 std::unique_ptr<AppBannerInfoBarDelegateAndroid> delegate( | 195 std::unique_ptr<AppBannerInfoBarDelegateAndroid> delegate( |
| 192 new AppBannerInfoBarDelegateAndroid( | 196 new AppBannerInfoBarDelegateAndroid( |
| 193 app_title_, native_app_data_, std::move(icon_), native_app_package_, | 197 app_title_, native_app_data_, std::move(icon_), native_app_package_, |
| 194 referrer_, event_request_id())); | 198 referrer_, event_request_id())); |
| 195 infobar = | 199 infobar = |
| 196 new AppBannerInfoBarAndroid(std::move(delegate), native_app_data_); | 200 new AppBannerInfoBarAndroid(std::move(delegate), native_app_data_); |
| 197 if (infobar) { | 201 if (infobar) { |
| 198 RecordDidShowBanner("AppBanner.NativeApp.Shown"); | 202 RecordDidShowBanner("AppBanner.NativeApp.Shown"); |
| 199 TrackDisplayEvent(DISPLAY_EVENT_NATIVE_APP_BANNER_CREATED); | 203 TrackDisplayEvent(DISPLAY_EVENT_NATIVE_APP_BANNER_CREATED); |
| 204 ReportStatus(contents, SHOWING_NATIVE_APP_BANNER); |
| 205 } else { |
| 206 ReportStatus(contents, FAILED_TO_CREATE_BANNER); |
| 200 } | 207 } |
| 201 } | 208 } |
| 202 | 209 |
| 203 if (infobar) { | 210 if (infobar) { |
| 204 InfoBarService::FromWebContents(contents)->AddInfoBar( | 211 InfoBarService::FromWebContents(contents)->AddInfoBar( |
| 205 base::WrapUnique(infobar)); | 212 base::WrapUnique(infobar)); |
| 206 } | 213 } |
| 207 } | 214 } |
| 208 | 215 |
| 209 bool AppBannerManagerAndroid::CanHandleNonWebApp(const std::string& platform, | 216 bool AppBannerManagerAndroid::CanHandleNonWebApp(const std::string& platform, |
| 210 const GURL& url, | 217 const GURL& url, |
| 211 const std::string& id) { | 218 const std::string& id) { |
| 212 if (!CheckPlatformAndId(platform, id)) | 219 if (!CheckPlatformAndId(platform, id)) |
| 213 return false; | 220 return false; |
| 214 | 221 |
| 215 banners::TrackDisplayEvent(DISPLAY_EVENT_NATIVE_APP_BANNER_REQUESTED); | 222 banners::TrackDisplayEvent(DISPLAY_EVENT_NATIVE_APP_BANNER_REQUESTED); |
| 216 | 223 |
| 217 // Send the info to the Java side to get info about the app. | 224 // Send the info to the Java side to get info about the app. |
| 218 JNIEnv* env = base::android::AttachCurrentThread(); | 225 JNIEnv* env = base::android::AttachCurrentThread(); |
| 219 if (java_banner_manager_.is_null()) | 226 if (java_banner_manager_.is_null()) |
| 220 return false; | 227 return false; |
| 221 | 228 |
| 222 std::string id_from_app_url = ExtractQueryValueForName(url, kIdName); | 229 std::string id_from_app_url = ExtractQueryValueForName(url, kIdName); |
| 223 if (id_from_app_url.size() && id != id_from_app_url) { | 230 if (id_from_app_url.size() && id != id_from_app_url) { |
| 224 ReportError(web_contents(), IDS_DO_NOT_MATCH); | 231 ReportStatus(web_contents(), IDS_DO_NOT_MATCH); |
| 225 return false; | 232 return false; |
| 226 } | 233 } |
| 227 | 234 |
| 228 std::string referrer = ExtractQueryValueForName(url, kReferrerName); | 235 std::string referrer = ExtractQueryValueForName(url, kReferrerName); |
| 229 | 236 |
| 230 // Attach the chrome_inline referrer value, prefixed with "&" if the referrer | 237 // Attach the chrome_inline referrer value, prefixed with "&" if the referrer |
| 231 // is non empty. | 238 // is non empty. |
| 232 if (referrer.empty()) | 239 if (referrer.empty()) |
| 233 referrer = kPlayInlineReferrer; | 240 referrer = kPlayInlineReferrer; |
| 234 else | 241 else |
| (...skipping 11 matching lines...) Expand all Loading... |
| 246 | 253 |
| 247 void AppBannerManagerAndroid::CreateJavaBannerManager() { | 254 void AppBannerManagerAndroid::CreateJavaBannerManager() { |
| 248 JNIEnv* env = base::android::AttachCurrentThread(); | 255 JNIEnv* env = base::android::AttachCurrentThread(); |
| 249 java_banner_manager_.Reset( | 256 java_banner_manager_.Reset( |
| 250 Java_AppBannerManager_create(env, reinterpret_cast<intptr_t>(this))); | 257 Java_AppBannerManager_create(env, reinterpret_cast<intptr_t>(this))); |
| 251 } | 258 } |
| 252 | 259 |
| 253 bool AppBannerManagerAndroid::CheckPlatformAndId(const std::string& platform, | 260 bool AppBannerManagerAndroid::CheckPlatformAndId(const std::string& platform, |
| 254 const std::string& id) { | 261 const std::string& id) { |
| 255 if (platform != kPlayPlatform) { | 262 if (platform != kPlayPlatform) { |
| 256 ReportError(web_contents(), PLATFORM_NOT_SUPPORTED_ON_ANDROID); | 263 ReportStatus(web_contents(), PLATFORM_NOT_SUPPORTED_ON_ANDROID); |
| 257 return false; | 264 return false; |
| 258 } | 265 } |
| 259 if (id.empty()) { | 266 if (id.empty()) { |
| 260 ReportError(web_contents(), NO_ID_SPECIFIED); | 267 ReportStatus(web_contents(), NO_ID_SPECIFIED); |
| 261 return false; | 268 return false; |
| 262 } | 269 } |
| 263 return true; | 270 return true; |
| 264 } | 271 } |
| 265 | 272 |
| 266 std::string AppBannerManagerAndroid::ExtractQueryValueForName( | 273 std::string AppBannerManagerAndroid::ExtractQueryValueForName( |
| 267 const GURL& url, | 274 const GURL& url, |
| 268 const std::string& name) { | 275 const std::string& name) { |
| 269 url::Component query = url.parsed_for_possibly_invalid_spec().query; | 276 url::Component query = url.parsed_for_possibly_invalid_spec().query; |
| 270 url::Component key, value; | 277 url::Component key, value; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 } | 320 } |
| 314 | 321 |
| 315 // static | 322 // static |
| 316 void SetTimeDeltaForTesting(JNIEnv* env, | 323 void SetTimeDeltaForTesting(JNIEnv* env, |
| 317 const JavaParamRef<jclass>& clazz, | 324 const JavaParamRef<jclass>& clazz, |
| 318 jint days) { | 325 jint days) { |
| 319 AppBannerManager::SetTimeDeltaForTesting(days); | 326 AppBannerManager::SetTimeDeltaForTesting(days); |
| 320 } | 327 } |
| 321 | 328 |
| 322 } // namespace banners | 329 } // namespace banners |
| OLD | NEW |