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

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
36 ShortcutHelper* shortcut_helper = 37 ShortcutHelper* shortcut_helper =
37 new ShortcutHelper(env, obj, tab->web_contents()); 38 new ShortcutHelper(env, obj, tab->web_contents());
38 shortcut_helper->Initialize(); 39 shortcut_helper->Initialize();
39 40
40 return reinterpret_cast<intptr_t>(shortcut_helper); 41 return reinterpret_cast<intptr_t>(shortcut_helper);
41 } 42 }
42 43
43 ShortcutHelper::ShortcutHelper(JNIEnv* env, 44 ShortcutHelper::ShortcutHelper(JNIEnv* env,
44 jobject obj, 45 jobject obj,
45 content::WebContents* web_contents) 46 content::WebContents* web_contents)
46 : WebContentsObserver(web_contents), 47 : WebContentsObserver(web_contents),
47 java_ref_(env, obj), 48 java_ref_(env, obj),
48 url_(web_contents->GetURL()), 49 url_(web_contents->GetURL()),
49 web_app_capable_(WebApplicationInfo::MOBILE_CAPABLE_UNSPECIFIED) { 50 web_app_capable_(WebApplicationInfo::MOBILE_CAPABLE_UNSPECIFIED) {
50 } 51 }
51 52
52 void ShortcutHelper::Initialize() { 53 void ShortcutHelper::Initialize() {
53 // Send a message to the renderer to retrieve information about the page. 54 // Send a message to the renderer to retrieve information about the page.
54 Send(new ChromeViewMsg_GetWebApplicationInfo(routing_id())); 55 Send(new ChromeViewMsg_GetWebApplicationInfo(routing_id()));
Mike West 2014/09/17 07:57:00 Does the application info need to be gathered befo
mlamouri (slow - plz ping) 2014/09/17 08:47:11 We probably could. We want to make sure the manife
55 } 56 }
56 57
57 ShortcutHelper::~ShortcutHelper() { 58 ShortcutHelper::~ShortcutHelper() {
58 } 59 }
59 60
60 void ShortcutHelper::OnDidGetWebApplicationInfo( 61 void ShortcutHelper::OnDidGetWebApplicationInfo(
61 const WebApplicationInfo& received_web_app_info) { 62 const WebApplicationInfo& received_web_app_info) {
62 // Sanitize received_web_app_info. 63 // Sanitize received_web_app_info.
63 WebApplicationInfo web_app_info = received_web_app_info; 64 WebApplicationInfo web_app_info = received_web_app_info;
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)));
77 }
78
79 void ShortcutHelper::OnDidGetManifest(const content::Manifest& manifest) {
80 if (!manifest.short_name.is_null())
81 title_ = manifest.short_name.string();
82 else if (!manifest.name.is_null())
83 title_ = manifest.name.string();
84
74 JNIEnv* env = base::android::AttachCurrentThread(); 85 JNIEnv* env = base::android::AttachCurrentThread();
Mike West 2014/09/17 07:57:00 Nit: For clarity, I'd suggest breaking this block
mlamouri (slow - plz ping) 2014/09/17 08:47:11 Done.
75 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); 86 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env);
76 ScopedJavaLocalRef<jstring> j_title = 87 ScopedJavaLocalRef<jstring> j_title =
77 base::android::ConvertUTF16ToJavaString(env, title_); 88 base::android::ConvertUTF16ToJavaString(env, title_);
78 89
79 Java_ShortcutHelper_onInitialized(env, j_obj.obj(), j_title.obj()); 90 Java_ShortcutHelper_onInitialized(env, j_obj.obj(), j_title.obj());
80 } 91 }
81 92
82 void ShortcutHelper::TearDown(JNIEnv*, jobject) { 93 void ShortcutHelper::TearDown(JNIEnv*, jobject) {
83 Destroy(); 94 Destroy();
84 } 95 }
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 base::UserMetricsAction("webapps.AddShortcut.AppShortcutApple")); 222 base::UserMetricsAction("webapps.AddShortcut.AppShortcutApple"));
212 break; 223 break;
213 case WebApplicationInfo::MOBILE_CAPABLE_UNSPECIFIED: 224 case WebApplicationInfo::MOBILE_CAPABLE_UNSPECIFIED:
214 content::RecordAction( 225 content::RecordAction(
215 base::UserMetricsAction("webapps.AddShortcut.Bookmark")); 226 base::UserMetricsAction("webapps.AddShortcut.Bookmark"));
216 break; 227 break;
217 default: 228 default:
218 NOTREACHED(); 229 NOTREACHED();
219 } 230 }
220 } 231 }
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