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

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

Issue 576153002: Use 'display' when creating a shortcut on Android. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@manifest_parser_stuff
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"
(...skipping 29 matching lines...) Expand all
40 40
41 return reinterpret_cast<intptr_t>(shortcut_helper); 41 return reinterpret_cast<intptr_t>(shortcut_helper);
42 } 42 }
43 43
44 ShortcutHelper::ShortcutHelper(JNIEnv* env, 44 ShortcutHelper::ShortcutHelper(JNIEnv* env,
45 jobject obj, 45 jobject obj,
46 content::WebContents* web_contents) 46 content::WebContents* web_contents)
47 : WebContentsObserver(web_contents), 47 : WebContentsObserver(web_contents),
48 java_ref_(env, obj), 48 java_ref_(env, obj),
49 url_(web_contents->GetURL()), 49 url_(web_contents->GetURL()),
50 web_app_capable_(WebApplicationInfo::MOBILE_CAPABLE_UNSPECIFIED), 50 display_(content::Manifest::DISPLAY_MODE_BROWSER),
51 weak_ptr_factory_(this) { 51 weak_ptr_factory_(this) {
52 } 52 }
53 53
54 void ShortcutHelper::Initialize() { 54 void ShortcutHelper::Initialize() {
55 // Send a message to the renderer to retrieve information about the page. 55 // Send a message to the renderer to retrieve information about the page.
56 Send(new ChromeViewMsg_GetWebApplicationInfo(routing_id())); 56 Send(new ChromeViewMsg_GetWebApplicationInfo(routing_id()));
57 } 57 }
58 58
59 ShortcutHelper::~ShortcutHelper() { 59 ShortcutHelper::~ShortcutHelper() {
60 } 60 }
61 61
62 void ShortcutHelper::OnDidGetWebApplicationInfo( 62 void ShortcutHelper::OnDidGetWebApplicationInfo(
63 const WebApplicationInfo& received_web_app_info) { 63 const WebApplicationInfo& received_web_app_info) {
64 // Sanitize received_web_app_info. 64 // Sanitize received_web_app_info.
65 WebApplicationInfo web_app_info = received_web_app_info; 65 WebApplicationInfo web_app_info = received_web_app_info;
66 web_app_info.title = 66 web_app_info.title =
67 web_app_info.title.substr(0, chrome::kMaxMetaTagAttributeLength); 67 web_app_info.title.substr(0, chrome::kMaxMetaTagAttributeLength);
68 web_app_info.description = 68 web_app_info.description =
69 web_app_info.description.substr(0, chrome::kMaxMetaTagAttributeLength); 69 web_app_info.description.substr(0, chrome::kMaxMetaTagAttributeLength);
70 70
71 web_app_capable_ = web_app_info.mobile_capable;
72
73 title_ = web_app_info.title.empty() ? web_contents()->GetTitle() 71 title_ = web_app_info.title.empty() ? web_contents()->GetTitle()
74 : web_app_info.title; 72 : web_app_info.title;
75 73
74 if (web_app_info.mobile_capable == WebApplicationInfo::MOBILE_CAPABLE ||
gone 2014/09/17 17:11:24 didn't this field get renamed to web_app_capable?
mlamouri (slow - plz ping) 2014/09/17 17:16:40 When you asked me to rename, I assumed that you me
75 web_app_info.mobile_capable == WebApplicationInfo::MOBILE_CAPABLE_APPLE) {
76 display_ = content::Manifest::DISPLAY_MODE_STANDALONE;
77 }
78
79 // Record what type of shortcut was added by the user.
80 switch (web_app_info.mobile_capable) {
81 case WebApplicationInfo::MOBILE_CAPABLE:
82 content::RecordAction(
83 base::UserMetricsAction("webapps.AddShortcut.AppShortcut"));
84 break;
85 case WebApplicationInfo::MOBILE_CAPABLE_APPLE:
86 content::RecordAction(
87 base::UserMetricsAction("webapps.AddShortcut.AppShortcutApple"));
88 break;
89 case WebApplicationInfo::MOBILE_CAPABLE_UNSPECIFIED:
90 content::RecordAction(
91 base::UserMetricsAction("webapps.AddShortcut.Bookmark"));
92 break;
93 default:
Bernhard Bauer 2014/09/17 17:51:09 You can leave out the default statement; the compi
94 NOTREACHED();
95 }
96
76 web_contents()->GetManifest(base::Bind(&ShortcutHelper::OnDidGetManifest, 97 web_contents()->GetManifest(base::Bind(&ShortcutHelper::OnDidGetManifest,
77 weak_ptr_factory_.GetWeakPtr())); 98 weak_ptr_factory_.GetWeakPtr()));
78 } 99 }
79 100
80 void ShortcutHelper::OnDidGetManifest(const content::Manifest& manifest) { 101 void ShortcutHelper::OnDidGetManifest(const content::Manifest& manifest) {
81 // Set the title based on the manifest value, if any. 102 // Set the title based on the manifest value, if any.
82 if (!manifest.short_name.is_null()) 103 if (!manifest.short_name.is_null())
83 title_ = manifest.short_name.string(); 104 title_ = manifest.short_name.string();
84 else if (!manifest.name.is_null()) 105 else if (!manifest.name.is_null())
85 title_ = manifest.name.string(); 106 title_ = manifest.name.string();
86 107
87 // Set the url based on the manifest value, if any. 108 // Set the url based on the manifest value, if any.
88 if (manifest.start_url.is_valid()) 109 if (manifest.start_url.is_valid())
89 url_ = manifest.start_url; 110 url_ = manifest.start_url;
90 111
112 // Set the display based on the manifest value, if any.
113 if (manifest.display != content::Manifest::DISPLAY_MODE_UNSPECIFIED)
114 display_ = manifest.display;
115
116 // 'fullscreen' and 'minimal-ui' are not yet supported, fallback to the right
117 // mode in those cases.
118 if (manifest.display == content::Manifest::DISPLAY_MODE_FULLSCREEN)
119 display_ = content::Manifest::DISPLAY_MODE_STANDALONE;
120 if (manifest.display == content::Manifest::DISPLAY_MODE_MINIMAL_UI)
121 display_ = content::Manifest::DISPLAY_MODE_BROWSER;
122
91 // The ShortcutHelper is now able to notify its Java counterpart that it is 123 // The ShortcutHelper is now able to notify its Java counterpart that it is
92 // initialized. OnInitialized method is not conceptually part of getting the 124 // initialized. OnInitialized method is not conceptually part of getting the
93 // manifest data but it happens that the initialization is finalized when 125 // manifest data but it happens that the initialization is finalized when
94 // these data are available. 126 // these data are available.
95 JNIEnv* env = base::android::AttachCurrentThread(); 127 JNIEnv* env = base::android::AttachCurrentThread();
96 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); 128 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env);
97 ScopedJavaLocalRef<jstring> j_title = 129 ScopedJavaLocalRef<jstring> j_title =
98 base::android::ConvertUTF16ToJavaString(env, title_); 130 base::android::ConvertUTF16ToJavaString(env, title_);
99 131
100 Java_ShortcutHelper_onInitialized(env, j_obj.obj(), j_title.obj()); 132 Java_ShortcutHelper_onInitialized(env, j_obj.obj(), j_title.obj());
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 icon_ = bitmap_result; 177 icon_ = bitmap_result;
146 178
147 // Stop observing so we don't get destroyed while doing the last steps. 179 // Stop observing so we don't get destroyed while doing the last steps.
148 Observe(NULL); 180 Observe(NULL);
149 181
150 base::WorkerPool::PostTask( 182 base::WorkerPool::PostTask(
151 FROM_HERE, 183 FROM_HERE,
152 base::Bind(&ShortcutHelper::AddShortcutInBackground, 184 base::Bind(&ShortcutHelper::AddShortcutInBackground,
153 url_, 185 url_,
154 title_, 186 title_,
155 web_app_capable_, 187 display_,
156 icon_), 188 icon_),
157 true); 189 true);
158 190
159 Destroy(); 191 Destroy();
160 } 192 }
161 193
162 bool ShortcutHelper::OnMessageReceived(const IPC::Message& message) { 194 bool ShortcutHelper::OnMessageReceived(const IPC::Message& message) {
163 bool handled = true; 195 bool handled = true;
164 196
165 IPC_BEGIN_MESSAGE_MAP(ShortcutHelper, message) 197 IPC_BEGIN_MESSAGE_MAP(ShortcutHelper, message)
166 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_DidGetWebApplicationInfo, 198 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_DidGetWebApplicationInfo,
167 OnDidGetWebApplicationInfo) 199 OnDidGetWebApplicationInfo)
168 IPC_MESSAGE_UNHANDLED(handled = false) 200 IPC_MESSAGE_UNHANDLED(handled = false)
169 IPC_END_MESSAGE_MAP() 201 IPC_END_MESSAGE_MAP()
170 202
171 return handled; 203 return handled;
172 } 204 }
173 205
174 void ShortcutHelper::WebContentsDestroyed() { 206 void ShortcutHelper::WebContentsDestroyed() {
175 Destroy(); 207 Destroy();
176 } 208 }
177 209
178 bool ShortcutHelper::RegisterShortcutHelper(JNIEnv* env) { 210 bool ShortcutHelper::RegisterShortcutHelper(JNIEnv* env) {
179 return RegisterNativesImpl(env); 211 return RegisterNativesImpl(env);
180 } 212 }
181 213
182 void ShortcutHelper::AddShortcutInBackground( 214 void ShortcutHelper::AddShortcutInBackground(
183 const GURL& url, 215 const GURL& url,
184 const base::string16& title, 216 const base::string16& title,
185 WebApplicationInfo::MobileCapable web_app_capable, 217 content::Manifest::DisplayMode display,
186 const favicon_base::FaviconRawBitmapResult& bitmap_result) { 218 const favicon_base::FaviconRawBitmapResult& bitmap_result) {
187 DCHECK(base::WorkerPool::RunsTasksOnCurrentThread()); 219 DCHECK(base::WorkerPool::RunsTasksOnCurrentThread());
188 220
189 // Grab the average color from the bitmap. 221 // Grab the average color from the bitmap.
190 SkColor color = SK_ColorWHITE; 222 SkColor color = SK_ColorWHITE;
191 SkBitmap favicon_bitmap; 223 SkBitmap favicon_bitmap;
192 if (bitmap_result.is_valid()) { 224 if (bitmap_result.is_valid()) {
193 if (gfx::PNGCodec::Decode(bitmap_result.bitmap_data->front(), 225 if (gfx::PNGCodec::Decode(bitmap_result.bitmap_data->front(),
194 bitmap_result.bitmap_data->size(), 226 bitmap_result.bitmap_data->size(),
195 &favicon_bitmap)) 227 &favicon_bitmap))
(...skipping 16 matching lines...) Expand all
212 244
213 Java_ShortcutHelper_addShortcut( 245 Java_ShortcutHelper_addShortcut(
214 env, 246 env,
215 base::android::GetApplicationContext(), 247 base::android::GetApplicationContext(),
216 java_url.obj(), 248 java_url.obj(),
217 java_title.obj(), 249 java_title.obj(),
218 java_bitmap.obj(), 250 java_bitmap.obj(),
219 r_value, 251 r_value,
220 g_value, 252 g_value,
221 b_value, 253 b_value,
222 web_app_capable != WebApplicationInfo::MOBILE_CAPABLE_UNSPECIFIED); 254 display == content::Manifest::DISPLAY_MODE_STANDALONE);
223
224 // Record what type of shortcut was added by the user.
225 switch (web_app_capable) {
226 case WebApplicationInfo::MOBILE_CAPABLE:
227 content::RecordAction(
228 base::UserMetricsAction("webapps.AddShortcut.AppShortcut"));
229 break;
230 case WebApplicationInfo::MOBILE_CAPABLE_APPLE:
231 content::RecordAction(
232 base::UserMetricsAction("webapps.AddShortcut.AppShortcutApple"));
233 break;
234 case WebApplicationInfo::MOBILE_CAPABLE_UNSPECIFIED:
235 content::RecordAction(
236 base::UserMetricsAction("webapps.AddShortcut.Bookmark"));
237 break;
238 default:
239 NOTREACHED();
240 }
241 } 255 }
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