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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 | 62 |
63 void AppBannerManager::BlockBanner(JNIEnv* env, | 63 void AppBannerManager::BlockBanner(JNIEnv* env, |
64 jobject obj, | 64 jobject obj, |
65 jstring jurl, | 65 jstring jurl, |
66 jstring jpackage) { | 66 jstring jpackage) { |
67 if (!web_contents()) | 67 if (!web_contents()) |
68 return; | 68 return; |
69 | 69 |
70 GURL url(ConvertJavaStringToUTF8(env, jurl)); | 70 GURL url(ConvertJavaStringToUTF8(env, jurl)); |
71 std::string package_name = ConvertJavaStringToUTF8(env, jpackage); | 71 std::string package_name = ConvertJavaStringToUTF8(env, jpackage); |
72 AppBannerSettingsHelper::Block(web_contents(), url, package_name); | 72 AppBannerSettingsHelper::RecordBannerEvent( |
| 73 web_contents(), url, package_name, |
| 74 AppBannerSettingsHelper::APP_BANNER_EVENT_DID_BLOCK, base::Time::Now()); |
73 } | 75 } |
74 | 76 |
75 void AppBannerManager::Block() const { | 77 void AppBannerManager::Block() const { |
76 if (!web_contents()) | 78 if (!web_contents()) |
77 return; | 79 return; |
78 | 80 |
79 if (!web_app_data_.IsEmpty()) { | 81 if (!web_app_data_.IsEmpty()) { |
80 AppBannerSettingsHelper::Block(web_contents(), | 82 AppBannerSettingsHelper::RecordBannerEvent( |
81 web_contents()->GetURL(), | 83 web_contents(), web_contents()->GetURL(), |
82 web_app_data_.start_url.spec()); | 84 web_app_data_.start_url.spec(), |
| 85 AppBannerSettingsHelper::APP_BANNER_EVENT_DID_BLOCK, base::Time::Now()); |
83 } | 86 } |
84 } | 87 } |
85 | 88 |
86 void AppBannerManager::OnInfoBarDestroyed() { | 89 void AppBannerManager::OnInfoBarDestroyed() { |
87 weak_infobar_ptr_ = nullptr; | 90 weak_infobar_ptr_ = nullptr; |
88 } | 91 } |
89 | 92 |
90 bool AppBannerManager::OnButtonClicked() const { | 93 bool AppBannerManager::OnButtonClicked() const { |
91 if (!web_contents()) | 94 if (!web_contents()) |
92 return true; | 95 return true; |
93 | 96 |
94 if (!web_app_data_.IsEmpty()) { | 97 if (!web_app_data_.IsEmpty()) { |
| 98 AppBannerSettingsHelper::RecordBannerEvent( |
| 99 web_contents(), web_contents()->GetURL(), |
| 100 web_app_data_.start_url.spec(), |
| 101 AppBannerSettingsHelper::APP_BANNER_EVENT_DID_ADD_TO_HOMESCREEN, |
| 102 base::Time::Now()); |
| 103 |
95 InstallManifestApp(web_app_data_, *app_icon_.get()); | 104 InstallManifestApp(web_app_data_, *app_icon_.get()); |
96 return true; | 105 return true; |
97 } | 106 } |
98 | 107 |
99 return true; | 108 return true; |
100 } | 109 } |
101 | 110 |
102 base::string16 AppBannerManager::GetTitle() const { | 111 base::string16 AppBannerManager::GetTitle() const { |
103 return app_title_; | 112 return app_title_; |
104 } | 113 } |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 // TODO(benwells): Check triggering parameters. | 185 // TODO(benwells): Check triggering parameters. |
177 // Create an infobar to promote the manifest's app. | 186 // Create an infobar to promote the manifest's app. |
178 GURL icon_url = | 187 GURL icon_url = |
179 ManifestIconSelector::FindBestMatchingIcon( | 188 ManifestIconSelector::FindBestMatchingIcon( |
180 web_app_data_.icons, | 189 web_app_data_.icons, |
181 GetPreferredIconSize(), | 190 GetPreferredIconSize(), |
182 gfx::Screen::GetScreenFor(web_contents()->GetNativeView())); | 191 gfx::Screen::GetScreenFor(web_contents()->GetNativeView())); |
183 if (icon_url.is_empty()) | 192 if (icon_url.is_empty()) |
184 return; | 193 return; |
185 | 194 |
| 195 RecordCouldShowBanner(web_app_data_.start_url.spec()); |
| 196 if (!CheckIfShouldShow(web_app_data_.start_url.spec())) |
| 197 return; |
| 198 |
186 FetchIcon(icon_url); | 199 FetchIcon(icon_url); |
187 } | 200 } |
188 } | 201 } |
189 | 202 |
| 203 void AppBannerManager::RecordCouldShowBanner( |
| 204 const std::string& package_or_start_url) { |
| 205 AppBannerSettingsHelper::RecordBannerEvent( |
| 206 web_contents(), validated_url_, package_or_start_url, |
| 207 AppBannerSettingsHelper::APP_BANNER_EVENT_COULD_SHOW, base::Time::Now()); |
| 208 } |
| 209 |
| 210 bool AppBannerManager::CheckIfShouldShow( |
| 211 const std::string& package_or_start_url) { |
| 212 if (!AppBannerSettingsHelper::ShouldShowBanner(web_contents(), validated_url_, |
| 213 package_or_start_url, |
| 214 base::Time::Now())) { |
| 215 return false; |
| 216 } |
| 217 |
| 218 AppBannerSettingsHelper::RecordBannerEvent( |
| 219 web_contents(), validated_url_, package_or_start_url, |
| 220 AppBannerSettingsHelper::APP_BANNER_EVENT_DID_SHOW, base::Time::Now()); |
| 221 return true; |
| 222 } |
| 223 |
190 bool AppBannerManager::OnMessageReceived(const IPC::Message& message) { | 224 bool AppBannerManager::OnMessageReceived(const IPC::Message& message) { |
191 bool handled = true; | 225 bool handled = true; |
192 IPC_BEGIN_MESSAGE_MAP(AppBannerManager, message) | 226 IPC_BEGIN_MESSAGE_MAP(AppBannerManager, message) |
193 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_DidRetrieveMetaTagContent, | 227 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_DidRetrieveMetaTagContent, |
194 OnDidRetrieveMetaTagContent) | 228 OnDidRetrieveMetaTagContent) |
195 IPC_MESSAGE_UNHANDLED(handled = false) | 229 IPC_MESSAGE_UNHANDLED(handled = false) |
196 IPC_END_MESSAGE_MAP() | 230 IPC_END_MESSAGE_MAP() |
197 return handled; | 231 return handled; |
198 } | 232 } |
199 | 233 |
(...skipping 30 matching lines...) Expand all Loading... |
230 const std::string& tag_content, | 264 const std::string& tag_content, |
231 const GURL& expected_url) { | 265 const GURL& expected_url) { |
232 DCHECK(web_contents()); | 266 DCHECK(web_contents()); |
233 if (!success || tag_name != kBannerTag || validated_url_ != expected_url || | 267 if (!success || tag_name != kBannerTag || validated_url_ != expected_url || |
234 tag_content.size() >= chrome::kMaxMetaTagAttributeLength) { | 268 tag_content.size() >= chrome::kMaxMetaTagAttributeLength) { |
235 return; | 269 return; |
236 } | 270 } |
237 | 271 |
238 banners::TrackDisplayEvent(DISPLAY_BANNER_REQUESTED); | 272 banners::TrackDisplayEvent(DISPLAY_BANNER_REQUESTED); |
239 | 273 |
240 if (!AppBannerSettingsHelper::IsAllowed(web_contents(), | 274 RecordCouldShowBanner(tag_content); |
241 expected_url, | 275 if (!CheckIfShouldShow(tag_content)) |
242 tag_content)) { | |
243 return; | 276 return; |
244 } | |
245 | 277 |
246 // Send the info to the Java side to get info about the app. | 278 // Send the info to the Java side to get info about the app. |
247 JNIEnv* env = base::android::AttachCurrentThread(); | 279 JNIEnv* env = base::android::AttachCurrentThread(); |
248 ScopedJavaLocalRef<jobject> jobj = weak_java_banner_view_manager_.get(env); | 280 ScopedJavaLocalRef<jobject> jobj = weak_java_banner_view_manager_.get(env); |
249 if (jobj.is_null()) | 281 if (jobj.is_null()) |
250 return; | 282 return; |
251 | 283 |
252 ScopedJavaLocalRef<jstring> jurl( | 284 ScopedJavaLocalRef<jstring> jurl( |
253 ConvertUTF8ToJavaString(env, expected_url.spec())); | 285 ConvertUTF8ToJavaString(env, expected_url.spec())); |
254 ScopedJavaLocalRef<jstring> jpackage( | 286 ScopedJavaLocalRef<jstring> jpackage( |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 return base::CommandLine::ForCurrentProcess()->HasSwitch( | 355 return base::CommandLine::ForCurrentProcess()->HasSwitch( |
324 switches::kEnableAppInstallAlerts); | 356 switches::kEnableAppInstallAlerts); |
325 } | 357 } |
326 | 358 |
327 // Register native methods | 359 // Register native methods |
328 bool RegisterAppBannerManager(JNIEnv* env) { | 360 bool RegisterAppBannerManager(JNIEnv* env) { |
329 return RegisterNativesImpl(env); | 361 return RegisterNativesImpl(env); |
330 } | 362 } |
331 | 363 |
332 } // namespace banners | 364 } // namespace banners |
OLD | NEW |