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

Side by Side Diff: chrome/browser/android/shortcut_helper.cc

Issue 573073002: Use Web Manifest when creating a shortcut on Chrome Android. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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
« no previous file with comments | « chrome/browser/android/shortcut_helper.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/shortcut_helper.h" 5 #include "chrome/browser/android/shortcut_helper.h"
6 6
7 #include <jni.h> 7 #include <jni.h>
8 8
9 #include "base/android/jni_android.h" 9 #include "base/android/jni_android.h"
10 #include "base/android/jni_string.h" 10 #include "base/android/jni_string.h"
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/location.h" 12 #include "base/location.h"
13 #include "base/strings/string16.h" 13 #include "base/strings/string16.h"
14 #include "base/task/cancelable_task_tracker.h" 14 #include "base/task/cancelable_task_tracker.h"
15 #include "base/threading/worker_pool.h" 15 #include "base/threading/worker_pool.h"
16 #include "chrome/browser/android/tab_android.h" 16 #include "chrome/browser/android/tab_android.h"
17 #include "chrome/browser/favicon/favicon_service.h" 17 #include "chrome/browser/favicon/favicon_service.h"
18 #include "chrome/browser/favicon/favicon_service_factory.h" 18 #include "chrome/browser/favicon/favicon_service_factory.h"
19 #include "chrome/common/chrome_constants.h" 19 #include "chrome/common/chrome_constants.h"
20 #include "chrome/common/render_messages.h" 20 #include "chrome/common/render_messages.h"
21 #include "chrome/common/web_application_info.h" 21 #include "chrome/common/web_application_info.h"
22 #include "content/public/browser/user_metrics.h" 22 #include "content/public/browser/user_metrics.h"
23 #include "content/public/browser/web_contents.h" 23 #include "content/public/browser/web_contents.h"
24 #include "content/public/browser/web_contents_observer.h" 24 #include "content/public/browser/web_contents_observer.h"
25 #include "content/public/common/frame_navigate_params.h" 25 #include "content/public/common/frame_navigate_params.h"
26 #include "content/public/common/manifest.h"
26 #include "jni/ShortcutHelper_jni.h" 27 #include "jni/ShortcutHelper_jni.h"
27 #include "ui/gfx/android/java_bitmap.h" 28 #include "ui/gfx/android/java_bitmap.h"
28 #include "ui/gfx/codec/png_codec.h" 29 #include "ui/gfx/codec/png_codec.h"
29 #include "ui/gfx/color_analysis.h" 30 #include "ui/gfx/color_analysis.h"
30 #include "ui/gfx/favicon_size.h" 31 #include "ui/gfx/favicon_size.h"
31 #include "url/gurl.h" 32 #include "url/gurl.h"
32 33
33 jlong Initialize(JNIEnv* env, jobject obj, jlong tab_android_ptr) { 34 jlong Initialize(JNIEnv* env, jobject obj, jlong tab_android_ptr) {
34 TabAndroid* tab = reinterpret_cast<TabAndroid*>(tab_android_ptr); 35 TabAndroid* tab = reinterpret_cast<TabAndroid*>(tab_android_ptr);
35 36
(...skipping 28 matching lines...) Expand all
64 web_app_info.title = 65 web_app_info.title =
65 web_app_info.title.substr(0, chrome::kMaxMetaTagAttributeLength); 66 web_app_info.title.substr(0, chrome::kMaxMetaTagAttributeLength);
66 web_app_info.description = 67 web_app_info.description =
67 web_app_info.description.substr(0, chrome::kMaxMetaTagAttributeLength); 68 web_app_info.description.substr(0, chrome::kMaxMetaTagAttributeLength);
68 69
69 web_app_capable_ = web_app_info.mobile_capable; 70 web_app_capable_ = web_app_info.mobile_capable;
70 71
71 title_ = web_app_info.title.empty() ? web_contents()->GetTitle() 72 title_ = web_app_info.title.empty() ? web_contents()->GetTitle()
72 : web_app_info.title; 73 : web_app_info.title;
73 74
75 web_contents()->GetManifest(base::Bind(&ShortcutHelper::OnDidGetManifest,
76 base::Unretained(this)));
Miguel Garcia 2014/09/17 09:02:42 why base::unretained? wouldn't it be better to use
mlamouri (slow - plz ping) 2014/09/17 10:51:04 Very good point. I wonder if I should introduce a
77 }
78
79 void ShortcutHelper::OnDidGetManifest(const content::Manifest& manifest) {
80 // Set the title based on the manifest value, if any.
81 if (!manifest.short_name.is_null())
82 title_ = manifest.short_name.string();
83 else if (!manifest.name.is_null())
84 title_ = manifest.name.string();
85
86 // Set the url based on the manifest value, if any.
87 if (manifest.start_url.is_valid())
88 url_ = manifest.start_url;
89
90 // The ShortcutHelper is now able to notify its Java counterpart that it is
91 // initialized. OnInitialized method is not conceptually part of getting the
92 // manifest data but it happens that the initialization is finalized when
93 // these data are available.
74 JNIEnv* env = base::android::AttachCurrentThread(); 94 JNIEnv* env = base::android::AttachCurrentThread();
75 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); 95 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env);
76 ScopedJavaLocalRef<jstring> j_title = 96 ScopedJavaLocalRef<jstring> j_title =
77 base::android::ConvertUTF16ToJavaString(env, title_); 97 base::android::ConvertUTF16ToJavaString(env, title_);
78 98
79 Java_ShortcutHelper_onInitialized(env, j_obj.obj(), j_title.obj()); 99 Java_ShortcutHelper_onInitialized(env, j_obj.obj(), j_title.obj());
80 } 100 }
81 101
82 void ShortcutHelper::TearDown(JNIEnv*, jobject) { 102 void ShortcutHelper::TearDown(JNIEnv*, jobject) {
83 Destroy(); 103 Destroy();
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 base::UserMetricsAction("webapps.AddShortcut.AppShortcutApple")); 231 base::UserMetricsAction("webapps.AddShortcut.AppShortcutApple"));
212 break; 232 break;
213 case WebApplicationInfo::MOBILE_CAPABLE_UNSPECIFIED: 233 case WebApplicationInfo::MOBILE_CAPABLE_UNSPECIFIED:
214 content::RecordAction( 234 content::RecordAction(
215 base::UserMetricsAction("webapps.AddShortcut.Bookmark")); 235 base::UserMetricsAction("webapps.AddShortcut.Bookmark"));
216 break; 236 break;
217 default: 237 default:
218 NOTREACHED(); 238 NOTREACHED();
219 } 239 }
220 } 240 }
OLDNEW
« no previous file with comments | « chrome/browser/android/shortcut_helper.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698