Chromium Code Reviews| 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 61 | 61 |
| 62 void AppBannerManager::BlockBanner(JNIEnv* env, | 62 void AppBannerManager::BlockBanner(JNIEnv* env, |
| 63 jobject obj, | 63 jobject obj, |
| 64 jstring jurl, | 64 jstring jurl, |
| 65 jstring jpackage) { | 65 jstring jpackage) { |
| 66 if (!web_contents()) | 66 if (!web_contents()) |
| 67 return; | 67 return; |
| 68 | 68 |
| 69 GURL url(ConvertJavaStringToUTF8(env, jurl)); | 69 GURL url(ConvertJavaStringToUTF8(env, jurl)); |
| 70 std::string package_name = ConvertJavaStringToUTF8(env, jpackage); | 70 std::string package_name = ConvertJavaStringToUTF8(env, jpackage); |
| 71 AppBannerSettingsHelper::Block(web_contents(), url, package_name); | 71 AppBannerSettingsHelper::RecordBannerEvent( |
| 72 web_contents(), url, package_name, | |
| 73 AppBannerSettingsHelper::APP_BANNER_EVENT_DID_BLOCK, base::Time::Now()); | |
| 72 } | 74 } |
| 73 | 75 |
| 74 void AppBannerManager::Block() const { | 76 void AppBannerManager::Block() const { |
| 75 if (!web_contents() || manifest_.IsEmpty()) | 77 if (!web_contents() || manifest_.IsEmpty()) |
| 76 return; | 78 return; |
| 77 | 79 |
| 78 AppBannerSettingsHelper::Block(web_contents(), | 80 AppBannerSettingsHelper::RecordBannerEvent( |
| 79 web_contents()->GetURL(), | 81 web_contents(), web_contents()->GetURL(), manifest_.start_url.spec(), |
| 80 manifest_.start_url.spec()); | 82 AppBannerSettingsHelper::APP_BANNER_EVENT_DID_BLOCK, base::Time::Now()); |
| 81 } | 83 } |
| 82 | 84 |
| 83 void AppBannerManager::Install() const { | 85 void AppBannerManager::Install() const { |
| 84 if (!web_contents()) | 86 if (!web_contents()) |
| 85 return; | 87 return; |
| 86 | 88 |
| 87 if (!manifest_.IsEmpty()) { | 89 if (!manifest_.IsEmpty()) { |
| 90 AppBannerSettingsHelper::RecordBannerEvent( | |
| 91 web_contents(), web_contents()->GetURL(), manifest_.start_url.spec(), | |
| 92 AppBannerSettingsHelper::APP_BANNER_EVENT_DID_ADD_TO_HOMESCREEN, | |
| 93 base::Time::Now()); | |
| 94 | |
| 88 InstallManifestApp(manifest_, *app_icon_.get()); | 95 InstallManifestApp(manifest_, *app_icon_.get()); |
| 89 } | 96 } |
| 90 } | 97 } |
| 91 | 98 |
| 92 gfx::Image AppBannerManager::GetIcon() const { | 99 gfx::Image AppBannerManager::GetIcon() const { |
| 93 return gfx::Image::CreateFrom1xBitmap(*app_icon_.get()); | 100 return gfx::Image::CreateFrom1xBitmap(*app_icon_.get()); |
| 94 } | 101 } |
| 95 | 102 |
| 96 void AppBannerManager::ReplaceWebContents(JNIEnv* env, | 103 void AppBannerManager::ReplaceWebContents(JNIEnv* env, |
| 97 jobject obj, | 104 jobject obj, |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 164 | 171 |
| 165 void AppBannerManager::OnDidCheckHasServiceWorker(bool has_same) { | 172 void AppBannerManager::OnDidCheckHasServiceWorker(bool has_same) { |
| 166 if (has_same) { | 173 if (has_same) { |
| 167 // TODO(benwells): Check triggering parameters. | 174 // TODO(benwells): Check triggering parameters. |
| 168 GURL icon_url = ManifestIconSelector::FindBestMatchingIcon( | 175 GURL icon_url = ManifestIconSelector::FindBestMatchingIcon( |
| 169 manifest_.icons, GetPreferredIconSize(), | 176 manifest_.icons, GetPreferredIconSize(), |
| 170 gfx::Screen::GetScreenFor(web_contents()->GetNativeView())); | 177 gfx::Screen::GetScreenFor(web_contents()->GetNativeView())); |
| 171 if (icon_url.is_empty()) | 178 if (icon_url.is_empty()) |
| 172 return; | 179 return; |
| 173 | 180 |
| 181 if (!CheckIfShouldShow(manifest_.start_url.spec())) | |
| 182 return; | |
| 183 | |
| 174 FetchIcon(icon_url); | 184 FetchIcon(icon_url); |
| 175 } | 185 } |
| 176 } | 186 } |
| 177 | 187 |
| 188 bool AppBannerManager::CheckIfShouldShow( | |
| 189 const std::string& package_or_start_url) { | |
| 190 AppBannerSettingsHelper::RecordBannerEvent( | |
| 191 web_contents(), validated_url_, package_or_start_url, | |
| 192 AppBannerSettingsHelper::APP_BANNER_EVENT_COULD_SHOW, base::Time::Now()); | |
| 193 if (!AppBannerSettingsHelper::ShouldShowBanner(web_contents(), validated_url_, | |
| 194 package_or_start_url, | |
| 195 base::Time::Now())) { | |
| 196 return false; | |
| 197 } | |
| 198 | |
| 199 AppBannerSettingsHelper::RecordBannerEvent( | |
| 200 web_contents(), validated_url_, package_or_start_url, | |
| 201 AppBannerSettingsHelper::APP_BANNER_EVENT_DID_SHOW, base::Time::Now()); | |
|
gone
2015/02/05 22:21:10
Seems strange to record that we did show it in a f
benwells
2015/02/06 16:36:28
Good point. I've split this into two functions: Re
| |
| 202 return true; | |
| 203 } | |
| 204 | |
| 178 bool AppBannerManager::OnMessageReceived(const IPC::Message& message) { | 205 bool AppBannerManager::OnMessageReceived(const IPC::Message& message) { |
| 179 bool handled = true; | 206 bool handled = true; |
| 180 IPC_BEGIN_MESSAGE_MAP(AppBannerManager, message) | 207 IPC_BEGIN_MESSAGE_MAP(AppBannerManager, message) |
| 181 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_DidRetrieveMetaTagContent, | 208 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_DidRetrieveMetaTagContent, |
| 182 OnDidRetrieveMetaTagContent) | 209 OnDidRetrieveMetaTagContent) |
| 183 IPC_MESSAGE_UNHANDLED(handled = false) | 210 IPC_MESSAGE_UNHANDLED(handled = false) |
| 184 IPC_END_MESSAGE_MAP() | 211 IPC_END_MESSAGE_MAP() |
| 185 return handled; | 212 return handled; |
| 186 } | 213 } |
| 187 | 214 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 228 const std::string& tag_content, | 255 const std::string& tag_content, |
| 229 const GURL& expected_url) { | 256 const GURL& expected_url) { |
| 230 DCHECK(web_contents()); | 257 DCHECK(web_contents()); |
| 231 if (!success || tag_name != kBannerTag || validated_url_ != expected_url || | 258 if (!success || tag_name != kBannerTag || validated_url_ != expected_url || |
| 232 tag_content.size() >= chrome::kMaxMetaTagAttributeLength) { | 259 tag_content.size() >= chrome::kMaxMetaTagAttributeLength) { |
| 233 return; | 260 return; |
| 234 } | 261 } |
| 235 | 262 |
| 236 banners::TrackDisplayEvent(DISPLAY_BANNER_REQUESTED); | 263 banners::TrackDisplayEvent(DISPLAY_BANNER_REQUESTED); |
| 237 | 264 |
| 238 if (!AppBannerSettingsHelper::IsAllowed(web_contents(), | 265 if (!CheckIfShouldShow(tag_content)) |
| 239 expected_url, | |
| 240 tag_content)) { | |
| 241 return; | 266 return; |
| 242 } | |
| 243 | 267 |
| 244 // Send the info to the Java side to get info about the app. | 268 // Send the info to the Java side to get info about the app. |
| 245 JNIEnv* env = base::android::AttachCurrentThread(); | 269 JNIEnv* env = base::android::AttachCurrentThread(); |
| 246 ScopedJavaLocalRef<jobject> jobj = weak_java_banner_view_manager_.get(env); | 270 ScopedJavaLocalRef<jobject> jobj = weak_java_banner_view_manager_.get(env); |
| 247 if (jobj.is_null()) | 271 if (jobj.is_null()) |
| 248 return; | 272 return; |
| 249 | 273 |
| 250 ScopedJavaLocalRef<jstring> jurl( | 274 ScopedJavaLocalRef<jstring> jurl( |
| 251 ConvertUTF8ToJavaString(env, expected_url.spec())); | 275 ConvertUTF8ToJavaString(env, expected_url.spec())); |
| 252 ScopedJavaLocalRef<jstring> jpackage( | 276 ScopedJavaLocalRef<jstring> jpackage( |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 320 return base::CommandLine::ForCurrentProcess()->HasSwitch( | 344 return base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 321 switches::kEnableAppInstallAlerts); | 345 switches::kEnableAppInstallAlerts); |
| 322 } | 346 } |
| 323 | 347 |
| 324 // Register native methods | 348 // Register native methods |
| 325 bool RegisterAppBannerManager(JNIEnv* env) { | 349 bool RegisterAppBannerManager(JNIEnv* env) { |
| 326 return RegisterNativesImpl(env); | 350 return RegisterNativesImpl(env); |
| 327 } | 351 } |
| 328 | 352 |
| 329 } // namespace banners | 353 } // namespace banners |
| OLD | NEW |