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

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/ShortcutHelper.java

Issue 1286973003: webapps: introduce helper class to store extended set of data (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix compile Created 5 years, 4 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 package org.chromium.chrome.browser; 5 package org.chromium.chrome.browser;
6 6
7 import android.content.Context; 7 import android.content.Context;
8 import android.content.Intent; 8 import android.content.Intent;
9 import android.graphics.Bitmap; 9 import android.graphics.Bitmap;
10 import android.os.Handler; 10 import android.os.Handler;
11 import android.os.Looper; 11 import android.os.Looper;
12 import android.util.Base64; 12 import android.util.Base64;
13 import android.widget.Toast; 13 import android.widget.Toast;
14 14
15 import org.chromium.base.ApplicationStatus; 15 import org.chromium.base.ApplicationStatus;
16 import org.chromium.base.VisibleForTesting; 16 import org.chromium.base.VisibleForTesting;
17 import org.chromium.base.annotations.CalledByNative; 17 import org.chromium.base.annotations.CalledByNative;
18 import org.chromium.chrome.R; 18 import org.chromium.chrome.R;
19 import org.chromium.chrome.browser.tab.Tab; 19 import org.chromium.chrome.browser.tab.Tab;
20 import org.chromium.chrome.browser.webapps.WebappDataStorage;
20 import org.chromium.chrome.browser.webapps.WebappLauncherActivity; 21 import org.chromium.chrome.browser.webapps.WebappLauncherActivity;
21 import org.chromium.content_public.browser.WebContents; 22 import org.chromium.content_public.browser.WebContents;
22 import org.chromium.content_public.common.ScreenOrientationConstants; 23 import org.chromium.content_public.common.ScreenOrientationConstants;
23 24
24 import java.io.ByteArrayOutputStream; 25 import java.io.ByteArrayOutputStream;
25 import java.util.UUID; 26 import java.util.UUID;
26 27
27 /** 28 /**
28 * This is a helper class to create shortcuts on the Android home screen. 29 * This is a helper class to create shortcuts on the Android home screen.
29 */ 30 */
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 if (isWebappCapable) { 167 if (isWebappCapable) {
167 // Encode the icon as a base64 string (Launcher drops Bitmaps in the Intent). 168 // Encode the icon as a base64 string (Launcher drops Bitmaps in the Intent).
168 String encodedIcon = ""; 169 String encodedIcon = "";
169 if (icon != null) { 170 if (icon != null) {
170 ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutpu tStream(); 171 ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutpu tStream();
171 icon.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStr eam); 172 icon.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStr eam);
172 byte[] byteArray = byteArrayOutputStream.toByteArray(); 173 byte[] byteArray = byteArrayOutputStream.toByteArray();
173 encodedIcon = Base64.encodeToString(byteArray, Base64.DEFAULT); 174 encodedIcon = Base64.encodeToString(byteArray, Base64.DEFAULT);
174 } 175 }
175 176
177 String uuid = UUID.randomUUID().toString();
178
176 // Add the shortcut as a launcher icon for a full-screen Activity. 179 // Add the shortcut as a launcher icon for a full-screen Activity.
177 shortcutIntent = new Intent(); 180 shortcutIntent = new Intent();
178 shortcutIntent.setAction(sDelegate.getFullscreenAction()); 181 shortcutIntent.setAction(sDelegate.getFullscreenAction());
179 shortcutIntent.putExtra(EXTRA_ICON, encodedIcon); 182 shortcutIntent.putExtra(EXTRA_ICON, encodedIcon);
180 shortcutIntent.putExtra(EXTRA_ID, UUID.randomUUID().toString()); 183 shortcutIntent.putExtra(EXTRA_ID, uuid);
181 shortcutIntent.putExtra(EXTRA_NAME, name); 184 shortcutIntent.putExtra(EXTRA_NAME, name);
182 shortcutIntent.putExtra(EXTRA_SHORT_NAME, shortName); 185 shortcutIntent.putExtra(EXTRA_SHORT_NAME, shortName);
183 shortcutIntent.putExtra(EXTRA_URL, url); 186 shortcutIntent.putExtra(EXTRA_URL, url);
184 shortcutIntent.putExtra(EXTRA_ORIENTATION, orientation); 187 shortcutIntent.putExtra(EXTRA_ORIENTATION, orientation);
185 shortcutIntent.putExtra(EXTRA_MAC, getEncodedMac(context, url)); 188 shortcutIntent.putExtra(EXTRA_MAC, getEncodedMac(context, url));
186 shortcutIntent.putExtra(EXTRA_THEME_COLOR, themeColor); 189 shortcutIntent.putExtra(EXTRA_THEME_COLOR, themeColor);
190
191 WebappDataStorage.open(context, uuid).putSplashIcon(icon);
187 } else { 192 } else {
188 // Add the shortcut as a launcher icon to open in the browser Activi ty. 193 // Add the shortcut as a launcher icon to open in the browser Activi ty.
189 shortcutIntent = BookmarkUtils.createShortcutIntent(url); 194 shortcutIntent = BookmarkUtils.createShortcutIntent(url);
190 } 195 }
191 196
192 // Always attach a source (one of add to homescreen menu item, app banne r, or unknown) to 197 // Always attach a source (one of add to homescreen menu item, app banne r, or unknown) to
193 // the intent. This allows us to distinguish where a shortcut was added from in metrics. 198 // the intent. This allows us to distinguish where a shortcut was added from in metrics.
194 shortcutIntent.putExtra(EXTRA_SOURCE, source); 199 shortcutIntent.putExtra(EXTRA_SOURCE, source);
195 shortcutIntent.setPackage(context.getPackageName()); 200 shortcutIntent.setPackage(context.getPackageName());
196 sDelegate.sendBroadcast( 201 sDelegate.sendBroadcast(
(...skipping 22 matching lines...) Expand all
219 // byte[] when adding the shortcut -- the Bundle received by the launche d Activity even 224 // byte[] when adding the shortcut -- the Bundle received by the launche d Activity even
220 // lacks the key for the extra. 225 // lacks the key for the extra.
221 byte[] mac = WebappAuthenticator.getMacForUrl(context, url); 226 byte[] mac = WebappAuthenticator.getMacForUrl(context, url);
222 return Base64.encodeToString(mac, Base64.DEFAULT); 227 return Base64.encodeToString(mac, Base64.DEFAULT);
223 } 228 }
224 229
225 private native long nativeInitialize(WebContents webContents); 230 private native long nativeInitialize(WebContents webContents);
226 private native void nativeAddShortcut(long nativeShortcutHelper, String user RequestedTitle); 231 private native void nativeAddShortcut(long nativeShortcutHelper, String user RequestedTitle);
227 private native void nativeDestroy(long nativeShortcutHelper); 232 private native void nativeDestroy(long nativeShortcutHelper);
228 } 233 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698