OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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.webapps; | 5 package org.chromium.chrome.browser.webapps; |
6 | 6 |
7 import android.content.Intent; | 7 import android.content.Intent; |
8 import android.graphics.Bitmap; | 8 import android.graphics.Bitmap; |
9 import android.graphics.Color; | 9 import android.graphics.Color; |
10 import android.graphics.drawable.Drawable; | 10 import android.graphics.drawable.Drawable; |
(...skipping 11 matching lines...) Expand all Loading... | |
22 | 22 |
23 import org.chromium.base.ActivityState; | 23 import org.chromium.base.ActivityState; |
24 import org.chromium.base.ApiCompatibilityUtils; | 24 import org.chromium.base.ApiCompatibilityUtils; |
25 import org.chromium.base.ApplicationStatus; | 25 import org.chromium.base.ApplicationStatus; |
26 import org.chromium.base.Log; | 26 import org.chromium.base.Log; |
27 import org.chromium.base.StreamUtil; | 27 import org.chromium.base.StreamUtil; |
28 import org.chromium.base.VisibleForTesting; | 28 import org.chromium.base.VisibleForTesting; |
29 import org.chromium.base.metrics.RecordHistogram; | 29 import org.chromium.base.metrics.RecordHistogram; |
30 import org.chromium.blink_public.platform.WebDisplayMode; | 30 import org.chromium.blink_public.platform.WebDisplayMode; |
31 import org.chromium.chrome.R; | 31 import org.chromium.chrome.R; |
32 import org.chromium.chrome.browser.ShortcutHelper; | |
32 import org.chromium.chrome.browser.TabState; | 33 import org.chromium.chrome.browser.TabState; |
33 import org.chromium.chrome.browser.document.DocumentUtils; | 34 import org.chromium.chrome.browser.document.DocumentUtils; |
34 import org.chromium.chrome.browser.fullscreen.ChromeFullscreenManager; | 35 import org.chromium.chrome.browser.fullscreen.ChromeFullscreenManager; |
35 import org.chromium.chrome.browser.metrics.WebappUma; | 36 import org.chromium.chrome.browser.metrics.WebappUma; |
36 import org.chromium.chrome.browser.tab.EmptyTabObserver; | 37 import org.chromium.chrome.browser.tab.EmptyTabObserver; |
37 import org.chromium.chrome.browser.tab.Tab; | 38 import org.chromium.chrome.browser.tab.Tab; |
38 import org.chromium.chrome.browser.tab.TabDelegateFactory; | 39 import org.chromium.chrome.browser.tab.TabDelegateFactory; |
39 import org.chromium.chrome.browser.tab.TabObserver; | 40 import org.chromium.chrome.browser.tab.TabObserver; |
40 import org.chromium.chrome.browser.tab.TopControlsVisibilityDelegate; | 41 import org.chromium.chrome.browser.tab.TopControlsVisibilityDelegate; |
41 import org.chromium.chrome.browser.util.ColorUtils; | 42 import org.chromium.chrome.browser.util.ColorUtils; |
(...skipping 16 matching lines...) Expand all Loading... | |
58 */ | 59 */ |
59 public class WebappActivity extends FullScreenActivity { | 60 public class WebappActivity extends FullScreenActivity { |
60 public static final String WEBAPP_SCHEME = "webapp"; | 61 public static final String WEBAPP_SCHEME = "webapp"; |
61 | 62 |
62 private static final String TAG = "WebappActivity"; | 63 private static final String TAG = "WebappActivity"; |
63 private static final long MS_BEFORE_NAVIGATING_BACK_FROM_INTERSTITIAL = 1000 ; | 64 private static final long MS_BEFORE_NAVIGATING_BACK_FROM_INTERSTITIAL = 1000 ; |
64 | 65 |
65 private final WebappDirectoryManager mDirectoryManager; | 66 private final WebappDirectoryManager mDirectoryManager; |
66 | 67 |
67 private WebappInfo mWebappInfo; | 68 private WebappInfo mWebappInfo; |
69 private boolean mIsWebApk; | |
gone
2016/05/21 00:07:28
Do you gain anything by caching this boolean? mWe
Xi Han
2016/05/25 14:37:58
We don't need this function after introducing WebA
| |
68 | 70 |
69 private boolean mOldWebappCleanupStarted; | 71 private boolean mOldWebappCleanupStarted; |
70 | 72 |
71 private ViewGroup mSplashScreen; | 73 private ViewGroup mSplashScreen; |
72 private WebappUrlBar mUrlBar; | 74 private WebappUrlBar mUrlBar; |
73 | 75 |
74 private boolean mIsInitialized; | 76 private boolean mIsInitialized; |
75 private Integer mBrandColor; | 77 private Integer mBrandColor; |
76 | 78 |
77 private WebappUma mWebappUma; | 79 private WebappUma mWebappUma; |
(...skipping 13 matching lines...) Expand all Loading... | |
91 | 93 |
92 @Override | 94 @Override |
93 protected void onNewIntent(Intent intent) { | 95 protected void onNewIntent(Intent intent) { |
94 if (intent == null) return; | 96 if (intent == null) return; |
95 super.onNewIntent(intent); | 97 super.onNewIntent(intent); |
96 | 98 |
97 WebappInfo newWebappInfo = WebappInfo.create(intent); | 99 WebappInfo newWebappInfo = WebappInfo.create(intent); |
98 if (newWebappInfo == null) { | 100 if (newWebappInfo == null) { |
99 Log.e(TAG, "Failed to parse new Intent: " + intent); | 101 Log.e(TAG, "Failed to parse new Intent: " + intent); |
100 finish(); | 102 finish(); |
103 return; | |
101 } else if (!TextUtils.equals(mWebappInfo.id(), newWebappInfo.id())) { | 104 } else if (!TextUtils.equals(mWebappInfo.id(), newWebappInfo.id())) { |
102 mWebappInfo = newWebappInfo; | 105 mWebappInfo = newWebappInfo; |
106 mIsWebApk = isWebApk(mWebappInfo); | |
103 resetSavedInstanceState(); | 107 resetSavedInstanceState(); |
104 if (mIsInitialized) initializeUI(null); | 108 if (mIsInitialized) initializeUI(null); |
105 // TODO(dominickn): send the web app into fullscreen if mDisplayMode is | 109 // TODO(dominickn): send the web app into fullscreen if mDisplayMode is |
106 // WebDisplayMode.Fullscreen. See crbug.com/581522 | 110 // WebDisplayMode.Fullscreen. See crbug.com/581522 |
107 } | 111 } |
112 if (mIsWebApk) { | |
113 // We could bring a WebAPK hosted WebappActivity to foreground and n avigate it to a | |
114 // different URL. For example, WebAPK "foo" is launched and navigate s to | |
115 // "www.foo.com/foo". In Chrome, user clicks a link "www.foo.com/bar " in Google search | |
116 // results. After clicking the link, WebAPK "foo" is brought to fore ground, and | |
117 // loads the page of "www.foo.com/bar" at the same time. | |
118 // The extra {@link ShortcutHelper.EXTRA_URL} provides the URL that the WebAPK will | |
119 // navigate to. | |
120 String overrideUrl = intent.getStringExtra(ShortcutHelper.EXTRA_URL) ; | |
121 if (overrideUrl != null && mIsInitialized | |
122 && !overrideUrl.equals(getActivityTab().getUrl())) { | |
123 getActivityTab().loadUrl( | |
124 new LoadUrlParams(overrideUrl, PageTransition.AUTO_TOPLE VEL)); | |
125 } | |
126 } | |
108 } | 127 } |
109 | 128 |
110 private void initializeUI(Bundle savedInstanceState) { | 129 private void initializeUI(Bundle savedInstanceState) { |
111 // We do not load URL when restoring from saved instance states. | 130 // We do not load URL when restoring from saved instance states. |
112 if (savedInstanceState == null && mWebappInfo.isInitialized()) { | 131 if (savedInstanceState == null && mWebappInfo.isInitialized()) { |
113 if (TextUtils.isEmpty(getActivityTab().getUrl())) { | 132 if (TextUtils.isEmpty(getActivityTab().getUrl())) { |
114 getActivityTab().loadUrl(new LoadUrlParams( | 133 getActivityTab().loadUrl(new LoadUrlParams( |
115 mWebappInfo.uri().toString(), PageTransition.AUTO_TOPLEV EL)); | 134 mWebappInfo.uri().toString(), PageTransition.AUTO_TOPLEV EL)); |
116 } | 135 } |
117 } else { | 136 } else { |
118 if (NetworkChangeNotifier.isOnline()) getActivityTab().reloadIgnorin gCache(); | 137 if (NetworkChangeNotifier.isOnline()) getActivityTab().reloadIgnorin gCache(); |
119 } | 138 } |
120 | 139 |
121 getActivityTab().addObserver(createTabObserver()); | 140 getActivityTab().addObserver(createTabObserver()); |
122 getActivityTab().getTabWebContentsDelegateAndroid().setDisplayMode( | 141 getActivityTab().getTabWebContentsDelegateAndroid().setDisplayMode( |
123 WebDisplayMode.Standalone); | 142 WebDisplayMode.Standalone); |
124 // TODO(dominickn): send the web app into fullscreen if mDisplayMode is | 143 // TODO(dominickn): send the web app into fullscreen if mDisplayMode is |
125 // WebDisplayMode.Fullscreen. See crbug.com/581522 | 144 // WebDisplayMode.Fullscreen. See crbug.com/581522 |
126 } | 145 } |
127 | 146 |
128 @Override | 147 @Override |
129 public void preInflationStartup() { | 148 public void preInflationStartup() { |
130 WebappInfo info = WebappInfo.create(getIntent()); | 149 WebappInfo info = WebappInfo.create(getIntent()); |
131 if (info != null) mWebappInfo = info; | 150 if (info != null) { |
151 mWebappInfo = info; | |
152 mIsWebApk = isWebApk(info); | |
153 } | |
132 | 154 |
133 ScreenOrientationProvider.lockOrientation((byte) mWebappInfo.orientation (), this); | 155 ScreenOrientationProvider.lockOrientation((byte) mWebappInfo.orientation (), this); |
134 super.preInflationStartup(); | 156 super.preInflationStartup(); |
135 } | 157 } |
136 | 158 |
137 @Override | 159 @Override |
138 public void finishNativeInitialization() { | 160 public void finishNativeInitialization() { |
139 if (!mWebappInfo.isInitialized()) finish(); | 161 if (!mWebappInfo.isInitialized()) finish(); |
140 super.finishNativeInitialization(); | 162 super.finishNativeInitialization(); |
141 initializeUI(getSavedInstanceState()); | 163 initializeUI(getSavedInstanceState()); |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
252 contentView.addView(mSplashScreen); | 274 contentView.addView(mSplashScreen); |
253 | 275 |
254 mWebappUma.splashscreenVisible(); | 276 mWebappUma.splashscreenVisible(); |
255 mWebappUma.recordSplashscreenBackgroundColor(mWebappInfo.hasValidBackgro undColor() | 277 mWebappUma.recordSplashscreenBackgroundColor(mWebappInfo.hasValidBackgro undColor() |
256 ? WebappUma.SPLASHSCREEN_COLOR_STATUS_CUSTOM | 278 ? WebappUma.SPLASHSCREEN_COLOR_STATUS_CUSTOM |
257 : WebappUma.SPLASHSCREEN_COLOR_STATUS_DEFAULT); | 279 : WebappUma.SPLASHSCREEN_COLOR_STATUS_DEFAULT); |
258 mWebappUma.recordSplashscreenThemeColor(mWebappInfo.hasValidThemeColor() | 280 mWebappUma.recordSplashscreenThemeColor(mWebappInfo.hasValidThemeColor() |
259 ? WebappUma.SPLASHSCREEN_COLOR_STATUS_CUSTOM | 281 ? WebappUma.SPLASHSCREEN_COLOR_STATUS_CUSTOM |
260 : WebappUma.SPLASHSCREEN_COLOR_STATUS_DEFAULT); | 282 : WebappUma.SPLASHSCREEN_COLOR_STATUS_DEFAULT); |
261 | 283 |
284 if (mIsWebApk) { | |
285 // TODO(hanxi): Removes this check when WebAPKs are registered in We bappRegistry. | |
286 initializeSplashScreenWidgets(backgroundColor, null); | |
287 return; | |
288 } | |
289 | |
262 final Intent intent = getIntent(); | 290 final Intent intent = getIntent(); |
263 WebappRegistry.getWebappDataStorage(this, mWebappInfo.id(), | 291 WebappRegistry.getWebappDataStorage(this, mWebappInfo.id(), |
264 new WebappRegistry.FetchWebappDataStorageCallback() { | 292 new WebappRegistry.FetchWebappDataStorageCallback() { |
265 @Override | 293 @Override |
266 public void onWebappDataStorageRetrieved(WebappDataStorage s torage) { | 294 public void onWebappDataStorageRetrieved(WebappDataStorage s torage) { |
267 if (storage == null) return; | 295 if (storage == null) return; |
268 | 296 |
269 // The information in the WebappDataStorage may have bee n purged by the | 297 // The information in the WebappDataStorage may have bee n purged by the |
270 // user clearing their history or not launching the web app recently. | 298 // user clearing their history or not launching the web app recently. |
271 // Restore the data if necessary from the intent. | 299 // Restore the data if necessary from the intent. |
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
600 || securityLevel == ConnectionSecurityLevel.SECURITY_WARNING; | 628 || securityLevel == ConnectionSecurityLevel.SECURITY_WARNING; |
601 return visible; | 629 return visible; |
602 } | 630 } |
603 | 631 |
604 // We're temporarily disable CS on webapp since there are some issues. (http ://crbug.com/471950) | 632 // We're temporarily disable CS on webapp since there are some issues. (http ://crbug.com/471950) |
605 // TODO(changwan): re-enable it once the issues are resolved. | 633 // TODO(changwan): re-enable it once the issues are resolved. |
606 @Override | 634 @Override |
607 protected boolean isContextualSearchAllowed() { | 635 protected boolean isContextualSearchAllowed() { |
608 return false; | 636 return false; |
609 } | 637 } |
638 | |
639 /** | |
640 * Returns whether {@link info} refers to a WebAPK. | |
641 * Assumes that WebappLauncherActivity does not create WebappActivities for APKs whose package | |
642 * starts with WEBAPK_PACKAGE_PREFIX but which are not WebAPKs (due to an in correct signature). | |
643 * @param info | |
644 */ | |
645 private static boolean isWebApk(WebappInfo info) { | |
646 return info.webApkPackageName() != null; | |
647 } | |
610 } | 648 } |
OLD | NEW |