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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 std::string package_name = ConvertJavaStringToUTF8(env, jpackage); | 71 std::string package_name = ConvertJavaStringToUTF8(env, jpackage); |
72 AppBannerSettingsHelper::RecordBannerEvent( | 72 AppBannerSettingsHelper::RecordBannerEvent( |
73 web_contents(), url, package_name, | 73 web_contents(), url, package_name, |
74 AppBannerSettingsHelper::APP_BANNER_EVENT_DID_BLOCK, base::Time::Now()); | 74 AppBannerSettingsHelper::APP_BANNER_EVENT_DID_BLOCK, base::Time::Now()); |
75 } | 75 } |
76 | 76 |
77 void AppBannerManager::Block() const { | 77 void AppBannerManager::Block() const { |
78 if (!web_contents()) | 78 if (!web_contents()) |
79 return; | 79 return; |
80 | 80 |
81 if (!web_app_data_.IsEmpty()) { | 81 if (!native_app_data_.is_null()) { |
| 82 AppBannerSettingsHelper::RecordBannerEvent( |
| 83 web_contents(), web_contents()->GetURL(), |
| 84 native_app_package_, |
| 85 AppBannerSettingsHelper::APP_BANNER_EVENT_DID_BLOCK, base::Time::Now()); |
| 86 } else if (!web_app_data_.IsEmpty()) { |
82 AppBannerSettingsHelper::RecordBannerEvent( | 87 AppBannerSettingsHelper::RecordBannerEvent( |
83 web_contents(), web_contents()->GetURL(), | 88 web_contents(), web_contents()->GetURL(), |
84 web_app_data_.start_url.spec(), | 89 web_app_data_.start_url.spec(), |
85 AppBannerSettingsHelper::APP_BANNER_EVENT_DID_BLOCK, base::Time::Now()); | 90 AppBannerSettingsHelper::APP_BANNER_EVENT_DID_BLOCK, base::Time::Now()); |
86 } | 91 } |
87 } | 92 } |
88 | 93 |
89 void AppBannerManager::OnInfoBarDestroyed() { | 94 void AppBannerManager::OnInfoBarDestroyed() { |
90 weak_infobar_ptr_ = nullptr; | 95 weak_infobar_ptr_ = nullptr; |
91 } | 96 } |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 } | 130 } |
126 | 131 |
127 void AppBannerManager::DidNavigateMainFrame( | 132 void AppBannerManager::DidNavigateMainFrame( |
128 const content::LoadCommittedDetails& details, | 133 const content::LoadCommittedDetails& details, |
129 const content::FrameNavigateParams& params) { | 134 const content::FrameNavigateParams& params) { |
130 // Clear current state. | 135 // Clear current state. |
131 fetcher_.reset(); | 136 fetcher_.reset(); |
132 app_title_ = base::string16(); | 137 app_title_ = base::string16(); |
133 app_icon_.reset(); | 138 app_icon_.reset(); |
134 web_app_data_ = content::Manifest(); | 139 web_app_data_ = content::Manifest(); |
| 140 native_app_data_.Reset(); |
| 141 native_app_package_ = std::string(); |
135 } | 142 } |
136 | 143 |
137 void AppBannerManager::DidFinishLoad( | 144 void AppBannerManager::DidFinishLoad( |
138 content::RenderFrameHost* render_frame_host, | 145 content::RenderFrameHost* render_frame_host, |
139 const GURL& validated_url) { | 146 const GURL& validated_url) { |
140 if (render_frame_host->GetParent()) | 147 if (render_frame_host->GetParent()) |
141 return; | 148 return; |
142 validated_url_ = validated_url; | 149 validated_url_ = validated_url; |
143 | 150 |
144 // See if the page has a manifest. Using Unretained(this) here is safe as the | 151 // See if the page has a manifest. Using Unretained(this) here is safe as the |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 | 247 |
241 JNIEnv* env = base::android::AttachCurrentThread(); | 248 JNIEnv* env = base::android::AttachCurrentThread(); |
242 ScopedJavaLocalRef<jobject> jobj = weak_java_banner_view_manager_.get(env); | 249 ScopedJavaLocalRef<jobject> jobj = weak_java_banner_view_manager_.get(env); |
243 if (jobj.is_null()) | 250 if (jobj.is_null()) |
244 return; | 251 return; |
245 | 252 |
246 app_icon_.reset(new SkBitmap(*bitmap)); | 253 app_icon_.reset(new SkBitmap(*bitmap)); |
247 InfoBarService* service = InfoBarService::FromWebContents(web_contents()); | 254 InfoBarService* service = InfoBarService::FromWebContents(web_contents()); |
248 | 255 |
249 weak_infobar_ptr_ = nullptr; | 256 weak_infobar_ptr_ = nullptr; |
250 if (!web_app_data_.IsEmpty()){ | 257 if (!native_app_data_.is_null()) { |
| 258 weak_infobar_ptr_ = AppBannerInfoBarDelegate::CreateForNativeApp( |
| 259 service, |
| 260 this, |
| 261 native_app_data_); |
| 262 } else if (!web_app_data_.IsEmpty()){ |
251 weak_infobar_ptr_ = AppBannerInfoBarDelegate::CreateForWebApp( | 263 weak_infobar_ptr_ = AppBannerInfoBarDelegate::CreateForWebApp( |
252 service, | 264 service, |
253 this, | 265 this, |
254 web_app_data_.start_url); | 266 web_app_data_.start_url); |
255 } | 267 } |
256 | 268 |
257 if (weak_infobar_ptr_ != nullptr) | 269 if (weak_infobar_ptr_ != nullptr) |
258 banners::TrackDisplayEvent(DISPLAY_CREATED); | 270 banners::TrackDisplayEvent(DISPLAY_CREATED); |
259 } | 271 } |
260 | 272 |
(...skipping 17 matching lines...) Expand all Loading... |
278 // 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. |
279 JNIEnv* env = base::android::AttachCurrentThread(); | 291 JNIEnv* env = base::android::AttachCurrentThread(); |
280 ScopedJavaLocalRef<jobject> jobj = weak_java_banner_view_manager_.get(env); | 292 ScopedJavaLocalRef<jobject> jobj = weak_java_banner_view_manager_.get(env); |
281 if (jobj.is_null()) | 293 if (jobj.is_null()) |
282 return; | 294 return; |
283 | 295 |
284 ScopedJavaLocalRef<jstring> jurl( | 296 ScopedJavaLocalRef<jstring> jurl( |
285 ConvertUTF8ToJavaString(env, expected_url.spec())); | 297 ConvertUTF8ToJavaString(env, expected_url.spec())); |
286 ScopedJavaLocalRef<jstring> jpackage( | 298 ScopedJavaLocalRef<jstring> jpackage( |
287 ConvertUTF8ToJavaString(env, tag_content)); | 299 ConvertUTF8ToJavaString(env, tag_content)); |
288 Java_AppBannerManager_prepareBanner(env, | 300 Java_AppBannerManager_fetchAppDetails(env, |
289 jobj.obj(), | 301 jobj.obj(), |
290 jurl.obj(), | 302 jurl.obj(), |
291 jpackage.obj()); | 303 jpackage.obj()); |
292 } | 304 } |
293 | 305 |
294 bool AppBannerManager::FetchIcon(JNIEnv* env, | 306 bool AppBannerManager::OnAppDetailsRetrieved(JNIEnv* env, |
295 jobject obj, | 307 jobject obj, |
296 jstring jimage_url) { | 308 jobject japp_data, |
297 std::string image_url = ConvertJavaStringToUTF8(env, jimage_url); | 309 jstring japp_title, |
| 310 jstring japp_package, |
| 311 jstring jicon_url) { |
| 312 if (validated_url_ != web_contents()->GetURL()) |
| 313 return false; |
| 314 |
| 315 std::string image_url = ConvertJavaStringToUTF8(env, jicon_url); |
| 316 app_title_ = ConvertJavaStringToUTF16(env, japp_title); |
| 317 native_app_package_ = ConvertJavaStringToUTF8(env, japp_package); |
| 318 native_app_data_.Reset(env, japp_data); |
298 return FetchIcon(GURL(image_url)); | 319 return FetchIcon(GURL(image_url)); |
299 } | 320 } |
300 | 321 |
301 bool AppBannerManager::FetchIcon(const GURL& image_url) { | 322 bool AppBannerManager::FetchIcon(const GURL& image_url) { |
302 if (!web_contents()) | 323 if (!web_contents()) |
303 return false; | 324 return false; |
304 | 325 |
305 // Begin asynchronously fetching the app icon. | 326 // Begin asynchronously fetching the app icon. |
306 Profile* profile = | 327 Profile* profile = |
307 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); | 328 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 return base::CommandLine::ForCurrentProcess()->HasSwitch( | 376 return base::CommandLine::ForCurrentProcess()->HasSwitch( |
356 switches::kEnableAppInstallAlerts); | 377 switches::kEnableAppInstallAlerts); |
357 } | 378 } |
358 | 379 |
359 // Register native methods | 380 // Register native methods |
360 bool RegisterAppBannerManager(JNIEnv* env) { | 381 bool RegisterAppBannerManager(JNIEnv* env) { |
361 return RegisterNativesImpl(env); | 382 return RegisterNativesImpl(env); |
362 } | 383 } |
363 | 384 |
364 } // namespace banners | 385 } // namespace banners |
OLD | NEW |