OLD | NEW |
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.app.ActivityManager; | 7 import android.app.ActivityManager; |
8 import android.content.Context; | 8 import android.content.Context; |
9 import android.content.Intent; | 9 import android.content.Intent; |
10 import android.content.pm.PackageManager; | 10 import android.content.pm.PackageManager; |
(...skipping 17 matching lines...) Expand all Loading... |
28 import android.util.Base64; | 28 import android.util.Base64; |
29 | 29 |
30 import org.chromium.base.ApiCompatibilityUtils; | 30 import org.chromium.base.ApiCompatibilityUtils; |
31 import org.chromium.base.CommandLine; | 31 import org.chromium.base.CommandLine; |
32 import org.chromium.base.ContextUtils; | 32 import org.chromium.base.ContextUtils; |
33 import org.chromium.base.Log; | 33 import org.chromium.base.Log; |
34 import org.chromium.base.ThreadUtils; | 34 import org.chromium.base.ThreadUtils; |
35 import org.chromium.base.VisibleForTesting; | 35 import org.chromium.base.VisibleForTesting; |
36 import org.chromium.base.annotations.CalledByNative; | 36 import org.chromium.base.annotations.CalledByNative; |
37 import org.chromium.chrome.R; | 37 import org.chromium.chrome.R; |
38 import org.chromium.chrome.browser.webapps.WebApkBuilder; | |
39 import org.chromium.chrome.browser.webapps.WebappAuthenticator; | 38 import org.chromium.chrome.browser.webapps.WebappAuthenticator; |
40 import org.chromium.chrome.browser.webapps.WebappDataStorage; | 39 import org.chromium.chrome.browser.webapps.WebappDataStorage; |
41 import org.chromium.chrome.browser.webapps.WebappLauncherActivity; | 40 import org.chromium.chrome.browser.webapps.WebappLauncherActivity; |
42 import org.chromium.chrome.browser.webapps.WebappRegistry; | 41 import org.chromium.chrome.browser.webapps.WebappRegistry; |
43 import org.chromium.chrome.browser.widget.RoundedIconGenerator; | 42 import org.chromium.chrome.browser.widget.RoundedIconGenerator; |
44 import org.chromium.content_public.common.ScreenOrientationConstants; | 43 import org.chromium.content_public.common.ScreenOrientationConstants; |
45 import org.chromium.net.GURLUtils; | |
46 import org.chromium.ui.widget.Toast; | 44 import org.chromium.ui.widget.Toast; |
47 import org.chromium.webapk.lib.client.WebApkValidator; | 45 import org.chromium.webapk.lib.client.WebApkValidator; |
48 | 46 |
49 import java.io.ByteArrayOutputStream; | 47 import java.io.ByteArrayOutputStream; |
50 import java.util.List; | 48 import java.util.List; |
51 | 49 |
52 /** | 50 /** |
53 * This class contains functions related to adding shortcuts to the Android Home | 51 * This class contains functions related to adding shortcuts to the Android Home |
54 * screen. These shortcuts are used to either open a page in the main browser | 52 * screen. These shortcuts are used to either open a page in the main browser |
55 * or open a web app. | 53 * or open a web app. |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 | 122 |
125 /** | 123 /** |
126 * Sets the delegate to use. | 124 * Sets the delegate to use. |
127 */ | 125 */ |
128 @VisibleForTesting | 126 @VisibleForTesting |
129 public static void setDelegateForTests(Delegate delegate) { | 127 public static void setDelegateForTests(Delegate delegate) { |
130 sDelegate = delegate; | 128 sDelegate = delegate; |
131 } | 129 } |
132 | 130 |
133 /** | 131 /** |
134 * Installs a WebAPK. | |
135 */ | |
136 @SuppressWarnings("unused") | |
137 @CalledByNative | |
138 private static void installWebApk(String url, String scopeUrl, final String
name, | |
139 String shortName, String iconUrl, Bitmap icon, int displayMode, int
orientation, | |
140 long themeColor, long backgroundColor, String manifestUrl) { | |
141 assert !ThreadUtils.runningOnUiThread(); | |
142 Context context = ContextUtils.getApplicationContext(); | |
143 WebApkBuilder apkBuilder = ((ChromeApplication) context).createWebApkBui
lder(); | |
144 if (apkBuilder == null) { | |
145 // TODO(pkotwicz): Figure out what to do when building WebAPK fails.
(crbug.com/626950) | |
146 return; | |
147 } | |
148 | |
149 if (TextUtils.isEmpty(scopeUrl)) { | |
150 scopeUrl = GURLUtils.getOrigin(url); | |
151 } | |
152 apkBuilder.buildWebApkAsync(url, scopeUrl, name, shortName, iconUrl, ico
n, displayMode, | |
153 orientation, themeColor, backgroundColor, manifestUrl); | |
154 } | |
155 | |
156 /** | |
157 * Adds home screen shortcut which opens in a {@link WebappActivity}. | 132 * Adds home screen shortcut which opens in a {@link WebappActivity}. |
158 */ | 133 */ |
159 @SuppressWarnings("unused") | 134 @SuppressWarnings("unused") |
160 @CalledByNative | 135 @CalledByNative |
161 private static void addWebappShortcut(String id, String url, String scopeUrl
, | 136 private static void addWebappShortcut(String id, String url, String scopeUrl
, |
162 final String userTitle, String name, String shortName, String iconUr
l, Bitmap icon, | 137 final String userTitle, String name, String shortName, String iconUr
l, Bitmap icon, |
163 int displayMode, int orientation, int source, long themeColor, long
backgroundColor, | 138 int displayMode, int orientation, int source, long themeColor, long
backgroundColor, |
164 final long callbackPointer) { | 139 final long callbackPointer) { |
165 assert !ThreadUtils.runningOnUiThread(); | 140 assert !ThreadUtils.runningOnUiThread(); |
166 | 141 |
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
605 if (drawable instanceof BitmapDrawable) { | 580 if (drawable instanceof BitmapDrawable) { |
606 BitmapDrawable bd = (BitmapDrawable) drawable; | 581 BitmapDrawable bd = (BitmapDrawable) drawable; |
607 return bd.getBitmap(); | 582 return bd.getBitmap(); |
608 } | 583 } |
609 assert false : "The drawable was not a bitmap drawable as expected"; | 584 assert false : "The drawable was not a bitmap drawable as expected"; |
610 return null; | 585 return null; |
611 } | 586 } |
612 | 587 |
613 private static native void nativeOnWebappDataStored(long callbackPointer); | 588 private static native void nativeOnWebappDataStored(long callbackPointer); |
614 } | 589 } |
OLD | NEW |