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/threading/worker_pool.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/banners/app_banner_metrics_ids.h" | 14 #include "chrome/browser/android/banners/app_banner_metrics_ids.h" |
14 #include "chrome/browser/android/banners/app_banner_utilities.h" | 15 #include "chrome/browser/android/banners/app_banner_utilities.h" |
16 #include "chrome/browser/android/shortcut_helper.h" | |
17 #include "chrome/browser/android/shortcut_info.h" | |
15 #include "chrome/browser/banners/app_banner_settings_helper.h" | 18 #include "chrome/browser/banners/app_banner_settings_helper.h" |
16 #include "chrome/browser/bitmap_fetcher/bitmap_fetcher.h" | 19 #include "chrome/browser/bitmap_fetcher/bitmap_fetcher.h" |
17 #include "chrome/browser/infobars/infobar_service.h" | 20 #include "chrome/browser/infobars/infobar_service.h" |
18 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
19 #include "chrome/common/chrome_constants.h" | 22 #include "chrome/common/chrome_constants.h" |
20 #include "chrome/common/chrome_switches.h" | 23 #include "chrome/common/chrome_switches.h" |
21 #include "chrome/common/render_messages.h" | 24 #include "chrome/common/render_messages.h" |
22 #include "content/public/browser/android/content_view_core.h" | 25 #include "content/public/browser/android/content_view_core.h" |
23 #include "content/public/browser/navigation_details.h" | 26 #include "content/public/browser/navigation_details.h" |
24 #include "content/public/browser/render_frame_host.h" | 27 #include "content/public/browser/render_frame_host.h" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
68 AppBannerSettingsHelper::Block(web_contents(), | 71 AppBannerSettingsHelper::Block(web_contents(), |
69 web_contents()->GetURL(), | 72 web_contents()->GetURL(), |
70 manifest_.start_url.spec()); | 73 manifest_.start_url.spec()); |
71 } | 74 } |
72 | 75 |
73 void AppBannerManager::Install() const { | 76 void AppBannerManager::Install() const { |
74 if (!web_contents()) | 77 if (!web_contents()) |
75 return; | 78 return; |
76 | 79 |
77 if (!manifest_.IsEmpty()) { | 80 if (!manifest_.IsEmpty()) { |
78 // TODO(dfalcantara): Trigger shortcut creation. | 81 InstallManifestApp(manifest_, *app_icon_.get()); |
79 } | 82 } |
80 } | 83 } |
81 | 84 |
82 gfx::Image AppBannerManager::GetIcon() const { | 85 gfx::Image AppBannerManager::GetIcon() const { |
83 return gfx::Image::CreateFrom1xBitmap(*app_icon_.get()); | 86 return gfx::Image::CreateFrom1xBitmap(*app_icon_.get()); |
84 } | 87 } |
85 | 88 |
86 void AppBannerManager::ReplaceWebContents(JNIEnv* env, | 89 void AppBannerManager::ReplaceWebContents(JNIEnv* env, |
87 jobject obj, | 90 jobject obj, |
88 jobject jweb_contents) { | 91 jobject jweb_contents) { |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
261 | 264 |
262 int AppBannerManager::GetPreferredIconSize() { | 265 int AppBannerManager::GetPreferredIconSize() { |
263 JNIEnv* env = base::android::AttachCurrentThread(); | 266 JNIEnv* env = base::android::AttachCurrentThread(); |
264 ScopedJavaLocalRef<jobject> jobj = weak_java_banner_view_manager_.get(env); | 267 ScopedJavaLocalRef<jobject> jobj = weak_java_banner_view_manager_.get(env); |
265 if (jobj.is_null()) | 268 if (jobj.is_null()) |
266 return 0; | 269 return 0; |
267 | 270 |
268 return Java_AppBannerManager_getPreferredIconSize(env, jobj.obj()); | 271 return Java_AppBannerManager_getPreferredIconSize(env, jobj.obj()); |
269 } | 272 } |
270 | 273 |
274 // static | |
275 void AppBannerManager::InstallManifestApp(const content::Manifest& manifest, | |
276 const SkBitmap& icon) { | |
277 ShortcutInfo info; | |
278 info.UpdateFromManifest(manifest); | |
mlamouri (slow - plz ping)
2015/02/03 17:40:24
You might want to set some default values like Sho
gone
2015/02/03 19:48:23
Changed a bit of the logic to prevent the infobar
| |
279 | |
280 base::WorkerPool::PostTask( | |
281 FROM_HERE, | |
282 base::Bind(&ShortcutHelper::AddShortcutInBackgroundWithSkBitmap, | |
283 info, | |
284 icon), | |
285 true); | |
286 } | |
287 | |
271 void RecordDismissEvent(JNIEnv* env, jclass clazz, jint metric) { | 288 void RecordDismissEvent(JNIEnv* env, jclass clazz, jint metric) { |
272 banners::TrackDismissEvent(metric); | 289 banners::TrackDismissEvent(metric); |
273 } | 290 } |
274 | 291 |
275 void RecordInstallEvent(JNIEnv* env, jclass clazz, jint metric) { | 292 void RecordInstallEvent(JNIEnv* env, jclass clazz, jint metric) { |
276 banners::TrackInstallEvent(metric); | 293 banners::TrackInstallEvent(metric); |
277 } | 294 } |
278 | 295 |
279 jlong Init(JNIEnv* env, jobject obj) { | 296 jlong Init(JNIEnv* env, jobject obj) { |
280 AppBannerManager* manager = new AppBannerManager(env, obj); | 297 AppBannerManager* manager = new AppBannerManager(env, obj); |
281 return reinterpret_cast<intptr_t>(manager); | 298 return reinterpret_cast<intptr_t>(manager); |
282 } | 299 } |
283 | 300 |
284 jboolean IsEnabled(JNIEnv* env, jclass clazz) { | 301 jboolean IsEnabled(JNIEnv* env, jclass clazz) { |
285 return base::CommandLine::ForCurrentProcess()->HasSwitch( | 302 return base::CommandLine::ForCurrentProcess()->HasSwitch( |
286 switches::kEnableAppInstallAlerts); | 303 switches::kEnableAppInstallAlerts); |
287 } | 304 } |
288 | 305 |
289 // Register native methods | 306 // Register native methods |
290 bool RegisterAppBannerManager(JNIEnv* env) { | 307 bool RegisterAppBannerManager(JNIEnv* env) { |
291 return RegisterNativesImpl(env); | 308 return RegisterNativesImpl(env); |
292 } | 309 } |
293 | 310 |
294 } // namespace banners | 311 } // namespace banners |
OLD | NEW |