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

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

Issue 579883002: Use Manifest's orientation when creating a shortcut and as default orientation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@use_display_in_shortcuthelper
Patch Set: review comments 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
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 30 matching lines...) Expand all
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 display_(content::Manifest::DISPLAY_MODE_BROWSER), 50 display_(content::Manifest::DISPLAY_MODE_BROWSER),
51 orientation_(blink::WebScreenOrientationLockDefault),
51 weak_ptr_factory_(this) { 52 weak_ptr_factory_(this) {
52 } 53 }
53 54
54 void ShortcutHelper::Initialize() { 55 void ShortcutHelper::Initialize() {
55 // Send a message to the renderer to retrieve information about the page. 56 // Send a message to the renderer to retrieve information about the page.
56 Send(new ChromeViewMsg_GetWebApplicationInfo(routing_id())); 57 Send(new ChromeViewMsg_GetWebApplicationInfo(routing_id()));
57 } 58 }
58 59
59 ShortcutHelper::~ShortcutHelper() { 60 ShortcutHelper::~ShortcutHelper() {
60 } 61 }
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 if (manifest.display != content::Manifest::DISPLAY_MODE_UNSPECIFIED) 112 if (manifest.display != content::Manifest::DISPLAY_MODE_UNSPECIFIED)
112 display_ = manifest.display; 113 display_ = manifest.display;
113 114
114 // 'fullscreen' and 'minimal-ui' are not yet supported, fallback to the right 115 // 'fullscreen' and 'minimal-ui' are not yet supported, fallback to the right
115 // mode in those cases. 116 // mode in those cases.
116 if (manifest.display == content::Manifest::DISPLAY_MODE_FULLSCREEN) 117 if (manifest.display == content::Manifest::DISPLAY_MODE_FULLSCREEN)
117 display_ = content::Manifest::DISPLAY_MODE_STANDALONE; 118 display_ = content::Manifest::DISPLAY_MODE_STANDALONE;
118 if (manifest.display == content::Manifest::DISPLAY_MODE_MINIMAL_UI) 119 if (manifest.display == content::Manifest::DISPLAY_MODE_MINIMAL_UI)
119 display_ = content::Manifest::DISPLAY_MODE_BROWSER; 120 display_ = content::Manifest::DISPLAY_MODE_BROWSER;
120 121
122 // Set the orientation based on the manifest value, if any.
123 if (manifest.orientation != blink::WebScreenOrientationLockDefault) {
124 // Ignore the orientation if the display mode is different from
125 // 'standalone'.
126 // TODO(mlamouri): send a message to the developer console about this.
127 if (display_ == content::Manifest::DISPLAY_MODE_STANDALONE)
128 orientation_ = manifest.orientation;
129 }
130
121 // The ShortcutHelper is now able to notify its Java counterpart that it is 131 // The ShortcutHelper is now able to notify its Java counterpart that it is
122 // initialized. OnInitialized method is not conceptually part of getting the 132 // initialized. OnInitialized method is not conceptually part of getting the
123 // manifest data but it happens that the initialization is finalized when 133 // manifest data but it happens that the initialization is finalized when
124 // these data are available. 134 // these data are available.
125 JNIEnv* env = base::android::AttachCurrentThread(); 135 JNIEnv* env = base::android::AttachCurrentThread();
126 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); 136 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env);
127 ScopedJavaLocalRef<jstring> j_title = 137 ScopedJavaLocalRef<jstring> j_title =
128 base::android::ConvertUTF16ToJavaString(env, title_); 138 base::android::ConvertUTF16ToJavaString(env, title_);
129 139
130 Java_ShortcutHelper_onInitialized(env, j_obj.obj(), j_title.obj()); 140 Java_ShortcutHelper_onInitialized(env, j_obj.obj(), j_title.obj());
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 186
177 // Stop observing so we don't get destroyed while doing the last steps. 187 // Stop observing so we don't get destroyed while doing the last steps.
178 Observe(NULL); 188 Observe(NULL);
179 189
180 base::WorkerPool::PostTask( 190 base::WorkerPool::PostTask(
181 FROM_HERE, 191 FROM_HERE,
182 base::Bind(&ShortcutHelper::AddShortcutInBackground, 192 base::Bind(&ShortcutHelper::AddShortcutInBackground,
183 url_, 193 url_,
184 title_, 194 title_,
185 display_, 195 display_,
186 icon_), 196 icon_,
197 orientation_),
187 true); 198 true);
188 199
189 Destroy(); 200 Destroy();
190 } 201 }
191 202
192 bool ShortcutHelper::OnMessageReceived(const IPC::Message& message) { 203 bool ShortcutHelper::OnMessageReceived(const IPC::Message& message) {
193 bool handled = true; 204 bool handled = true;
194 205
195 IPC_BEGIN_MESSAGE_MAP(ShortcutHelper, message) 206 IPC_BEGIN_MESSAGE_MAP(ShortcutHelper, message)
196 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_DidGetWebApplicationInfo, 207 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_DidGetWebApplicationInfo,
197 OnDidGetWebApplicationInfo) 208 OnDidGetWebApplicationInfo)
198 IPC_MESSAGE_UNHANDLED(handled = false) 209 IPC_MESSAGE_UNHANDLED(handled = false)
199 IPC_END_MESSAGE_MAP() 210 IPC_END_MESSAGE_MAP()
200 211
201 return handled; 212 return handled;
202 } 213 }
203 214
204 void ShortcutHelper::WebContentsDestroyed() { 215 void ShortcutHelper::WebContentsDestroyed() {
205 Destroy(); 216 Destroy();
206 } 217 }
207 218
208 bool ShortcutHelper::RegisterShortcutHelper(JNIEnv* env) { 219 bool ShortcutHelper::RegisterShortcutHelper(JNIEnv* env) {
209 return RegisterNativesImpl(env); 220 return RegisterNativesImpl(env);
210 } 221 }
211 222
212 void ShortcutHelper::AddShortcutInBackground( 223 void ShortcutHelper::AddShortcutInBackground(
213 const GURL& url, 224 const GURL& url,
214 const base::string16& title, 225 const base::string16& title,
215 content::Manifest::DisplayMode display, 226 content::Manifest::DisplayMode display,
216 const favicon_base::FaviconRawBitmapResult& bitmap_result) { 227 const favicon_base::FaviconRawBitmapResult& bitmap_result,
228 blink::WebScreenOrientationLockType orientation) {
217 DCHECK(base::WorkerPool::RunsTasksOnCurrentThread()); 229 DCHECK(base::WorkerPool::RunsTasksOnCurrentThread());
218 230
219 // Grab the average color from the bitmap. 231 // Grab the average color from the bitmap.
220 SkColor color = SK_ColorWHITE; 232 SkColor color = SK_ColorWHITE;
221 SkBitmap favicon_bitmap; 233 SkBitmap favicon_bitmap;
222 if (bitmap_result.is_valid()) { 234 if (bitmap_result.is_valid()) {
223 if (gfx::PNGCodec::Decode(bitmap_result.bitmap_data->front(), 235 if (gfx::PNGCodec::Decode(bitmap_result.bitmap_data->front(),
224 bitmap_result.bitmap_data->size(), 236 bitmap_result.bitmap_data->size(),
225 &favicon_bitmap)) 237 &favicon_bitmap))
226 color = color_utils::CalculateKMeanColorOfBitmap(favicon_bitmap); 238 color = color_utils::CalculateKMeanColorOfBitmap(favicon_bitmap);
(...skipping 15 matching lines...) Expand all
242 254
243 Java_ShortcutHelper_addShortcut( 255 Java_ShortcutHelper_addShortcut(
244 env, 256 env,
245 base::android::GetApplicationContext(), 257 base::android::GetApplicationContext(),
246 java_url.obj(), 258 java_url.obj(),
247 java_title.obj(), 259 java_title.obj(),
248 java_bitmap.obj(), 260 java_bitmap.obj(),
249 r_value, 261 r_value,
250 g_value, 262 g_value,
251 b_value, 263 b_value,
252 display == content::Manifest::DISPLAY_MODE_STANDALONE); 264 display == content::Manifest::DISPLAY_MODE_STANDALONE,
265 orientation);
253 } 266 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698