Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(157)

Side by Side Diff: chrome/browser/android/banners/app_banner_manager.cc

Issue 899543003: Break out more manifest parsing logic from ShortcutHelper (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebasing Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
15 #include "chrome/browser/android/manifest_icon_selector.h" 16 #include "chrome/browser/android/manifest_icon_selector.h"
17 #include "chrome/browser/android/shortcut_helper.h"
18 #include "chrome/browser/android/shortcut_info.h"
16 #include "chrome/browser/banners/app_banner_settings_helper.h" 19 #include "chrome/browser/banners/app_banner_settings_helper.h"
17 #include "chrome/browser/bitmap_fetcher/bitmap_fetcher.h" 20 #include "chrome/browser/bitmap_fetcher/bitmap_fetcher.h"
18 #include "chrome/browser/infobars/infobar_service.h" 21 #include "chrome/browser/infobars/infobar_service.h"
19 #include "chrome/browser/profiles/profile.h" 22 #include "chrome/browser/profiles/profile.h"
20 #include "chrome/common/chrome_constants.h" 23 #include "chrome/common/chrome_constants.h"
21 #include "chrome/common/chrome_switches.h" 24 #include "chrome/common/chrome_switches.h"
22 #include "chrome/common/render_messages.h" 25 #include "chrome/common/render_messages.h"
23 #include "content/public/browser/android/content_view_core.h" 26 #include "content/public/browser/android/content_view_core.h"
24 #include "content/public/browser/navigation_details.h" 27 #include "content/public/browser/navigation_details.h"
25 #include "content/public/browser/render_frame_host.h" 28 #include "content/public/browser/render_frame_host.h"
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 AppBannerSettingsHelper::Block(web_contents(), 73 AppBannerSettingsHelper::Block(web_contents(),
71 web_contents()->GetURL(), 74 web_contents()->GetURL(),
72 manifest_.start_url.spec()); 75 manifest_.start_url.spec());
73 } 76 }
74 77
75 void AppBannerManager::Install() const { 78 void AppBannerManager::Install() const {
76 if (!web_contents()) 79 if (!web_contents())
77 return; 80 return;
78 81
79 if (!manifest_.IsEmpty()) { 82 if (!manifest_.IsEmpty()) {
80 // TODO(dfalcantara): Trigger shortcut creation. 83 InstallManifestApp(manifest_, *app_icon_.get());
81 } 84 }
82 } 85 }
83 86
84 gfx::Image AppBannerManager::GetIcon() const { 87 gfx::Image AppBannerManager::GetIcon() const {
85 return gfx::Image::CreateFrom1xBitmap(*app_icon_.get()); 88 return gfx::Image::CreateFrom1xBitmap(*app_icon_.get());
86 } 89 }
87 90
88 void AppBannerManager::ReplaceWebContents(JNIEnv* env, 91 void AppBannerManager::ReplaceWebContents(JNIEnv* env,
89 jobject obj, 92 jobject obj,
90 jobject jweb_contents) { 93 jobject jweb_contents) {
(...skipping 29 matching lines...) Expand all
120 // lifetime of this object extends beyond the lifetime of the web_contents(), 123 // lifetime of this object extends beyond the lifetime of the web_contents(),
121 // and when web_contents() is destroyed it will call OnDidGetManifest. 124 // and when web_contents() is destroyed it will call OnDidGetManifest.
122 web_contents()->GetManifest(base::Bind(&AppBannerManager::OnDidGetManifest, 125 web_contents()->GetManifest(base::Bind(&AppBannerManager::OnDidGetManifest,
123 base::Unretained(this))); 126 base::Unretained(this)));
124 } 127 }
125 128
126 void AppBannerManager::OnDidGetManifest(const content::Manifest& manifest) { 129 void AppBannerManager::OnDidGetManifest(const content::Manifest& manifest) {
127 if (web_contents()->IsBeingDestroyed()) 130 if (web_contents()->IsBeingDestroyed())
128 return; 131 return;
129 132
130 if (manifest.IsEmpty()) { 133 if (manifest.IsEmpty()
131 // No manifest, see if there is a play store meta tag. 134 || !manifest.start_url.is_valid()
135 || (manifest.name.is_null() && manifest.short_name.is_null())) {
136 // No usable manifest, see if there is a play store meta tag.
132 Send(new ChromeViewMsg_RetrieveMetaTagContent(routing_id(), 137 Send(new ChromeViewMsg_RetrieveMetaTagContent(routing_id(),
133 validated_url_, 138 validated_url_,
134 kBannerTag)); 139 kBannerTag));
135 return; 140 return;
136 } 141 }
137 142
138 // TODO(benwells): Check triggering parameters here and if there is a meta 143 // TODO(benwells): Check triggering parameters here and if there is a meta
139 // tag. 144 // tag.
140 145
141 // Create an infobar to promote the manifest's app. 146 // Create an infobar to promote the manifest's app.
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 264
260 int AppBannerManager::GetPreferredIconSize() { 265 int AppBannerManager::GetPreferredIconSize() {
261 JNIEnv* env = base::android::AttachCurrentThread(); 266 JNIEnv* env = base::android::AttachCurrentThread();
262 ScopedJavaLocalRef<jobject> jobj = weak_java_banner_view_manager_.get(env); 267 ScopedJavaLocalRef<jobject> jobj = weak_java_banner_view_manager_.get(env);
263 if (jobj.is_null()) 268 if (jobj.is_null())
264 return 0; 269 return 0;
265 270
266 return Java_AppBannerManager_getPreferredIconSize(env, jobj.obj()); 271 return Java_AppBannerManager_getPreferredIconSize(env, jobj.obj());
267 } 272 }
268 273
274 // static
275 void AppBannerManager::InstallManifestApp(const content::Manifest& manifest,
276 const SkBitmap& icon) {
277 ShortcutInfo info;
278 info.UpdateFromManifest(manifest);
279
280 base::WorkerPool::PostTask(
281 FROM_HERE,
282 base::Bind(&ShortcutHelper::AddShortcutInBackgroundWithSkBitmap,
283 info,
284 icon),
285 true);
286 }
287
269 void RecordDismissEvent(JNIEnv* env, jclass clazz, jint metric) { 288 void RecordDismissEvent(JNIEnv* env, jclass clazz, jint metric) {
270 banners::TrackDismissEvent(metric); 289 banners::TrackDismissEvent(metric);
271 } 290 }
272 291
273 void RecordInstallEvent(JNIEnv* env, jclass clazz, jint metric) { 292 void RecordInstallEvent(JNIEnv* env, jclass clazz, jint metric) {
274 banners::TrackInstallEvent(metric); 293 banners::TrackInstallEvent(metric);
275 } 294 }
276 295
277 jlong Init(JNIEnv* env, jobject obj) { 296 jlong Init(JNIEnv* env, jobject obj) {
278 AppBannerManager* manager = new AppBannerManager(env, obj); 297 AppBannerManager* manager = new AppBannerManager(env, obj);
279 return reinterpret_cast<intptr_t>(manager); 298 return reinterpret_cast<intptr_t>(manager);
280 } 299 }
281 300
282 jboolean IsEnabled(JNIEnv* env, jclass clazz) { 301 jboolean IsEnabled(JNIEnv* env, jclass clazz) {
283 return base::CommandLine::ForCurrentProcess()->HasSwitch( 302 return base::CommandLine::ForCurrentProcess()->HasSwitch(
284 switches::kEnableAppInstallAlerts); 303 switches::kEnableAppInstallAlerts);
285 } 304 }
286 305
287 // Register native methods 306 // Register native methods
288 bool RegisterAppBannerManager(JNIEnv* env) { 307 bool RegisterAppBannerManager(JNIEnv* env) {
289 return RegisterNativesImpl(env); 308 return RegisterNativesImpl(env);
290 } 309 }
291 310
292 } // namespace banners 311 } // namespace banners
OLDNEW
« no previous file with comments | « chrome/browser/android/banners/app_banner_manager.h ('k') | chrome/browser/android/shortcut_helper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698