Index: chrome/android/java/src/org/chromium/chrome/browser/webapps/WebappActivity.java |
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/webapps/WebappActivity.java b/chrome/android/java/src/org/chromium/chrome/browser/webapps/WebappActivity.java |
index 6e7f57cd7dcf0ee80e5f835631165c77c086c353..df633af920209582cf8eb0f8e5e31851d48068bd 100644 |
--- a/chrome/android/java/src/org/chromium/chrome/browser/webapps/WebappActivity.java |
+++ b/chrome/android/java/src/org/chromium/chrome/browser/webapps/WebappActivity.java |
@@ -29,6 +29,7 @@ import org.chromium.base.VisibleForTesting; |
import org.chromium.base.metrics.RecordHistogram; |
import org.chromium.blink_public.platform.WebDisplayMode; |
import org.chromium.chrome.R; |
+import org.chromium.chrome.browser.ShortcutHelper; |
import org.chromium.chrome.browser.TabState; |
import org.chromium.chrome.browser.document.DocumentUtils; |
import org.chromium.chrome.browser.fullscreen.ChromeFullscreenManager; |
@@ -65,6 +66,7 @@ public class WebappActivity extends FullScreenActivity { |
private final WebappDirectoryManager mDirectoryManager; |
private WebappInfo mWebappInfo; |
+ 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
|
private boolean mOldWebappCleanupStarted; |
@@ -98,13 +100,30 @@ public class WebappActivity extends FullScreenActivity { |
if (newWebappInfo == null) { |
Log.e(TAG, "Failed to parse new Intent: " + intent); |
finish(); |
+ return; |
} else if (!TextUtils.equals(mWebappInfo.id(), newWebappInfo.id())) { |
mWebappInfo = newWebappInfo; |
+ mIsWebApk = isWebApk(mWebappInfo); |
resetSavedInstanceState(); |
if (mIsInitialized) initializeUI(null); |
// TODO(dominickn): send the web app into fullscreen if mDisplayMode is |
// WebDisplayMode.Fullscreen. See crbug.com/581522 |
} |
+ if (mIsWebApk) { |
+ // We could bring a WebAPK hosted WebappActivity to foreground and navigate it to a |
+ // different URL. For example, WebAPK "foo" is launched and navigates to |
+ // "www.foo.com/foo". In Chrome, user clicks a link "www.foo.com/bar" in Google search |
+ // results. After clicking the link, WebAPK "foo" is brought to foreground, and |
+ // loads the page of "www.foo.com/bar" at the same time. |
+ // The extra {@link ShortcutHelper.EXTRA_URL} provides the URL that the WebAPK will |
+ // navigate to. |
+ String overrideUrl = intent.getStringExtra(ShortcutHelper.EXTRA_URL); |
+ if (overrideUrl != null && mIsInitialized |
+ && !overrideUrl.equals(getActivityTab().getUrl())) { |
+ getActivityTab().loadUrl( |
+ new LoadUrlParams(overrideUrl, PageTransition.AUTO_TOPLEVEL)); |
+ } |
+ } |
} |
private void initializeUI(Bundle savedInstanceState) { |
@@ -128,7 +147,10 @@ public class WebappActivity extends FullScreenActivity { |
@Override |
public void preInflationStartup() { |
WebappInfo info = WebappInfo.create(getIntent()); |
- if (info != null) mWebappInfo = info; |
+ if (info != null) { |
+ mWebappInfo = info; |
+ mIsWebApk = isWebApk(info); |
+ } |
ScreenOrientationProvider.lockOrientation((byte) mWebappInfo.orientation(), this); |
super.preInflationStartup(); |
@@ -259,6 +281,12 @@ public class WebappActivity extends FullScreenActivity { |
? WebappUma.SPLASHSCREEN_COLOR_STATUS_CUSTOM |
: WebappUma.SPLASHSCREEN_COLOR_STATUS_DEFAULT); |
+ if (mIsWebApk) { |
+ // TODO(hanxi): Removes this check when WebAPKs are registered in WebappRegistry. |
+ initializeSplashScreenWidgets(backgroundColor, null); |
+ return; |
+ } |
+ |
final Intent intent = getIntent(); |
WebappRegistry.getWebappDataStorage(this, mWebappInfo.id(), |
new WebappRegistry.FetchWebappDataStorageCallback() { |
@@ -607,4 +635,14 @@ public class WebappActivity extends FullScreenActivity { |
protected boolean isContextualSearchAllowed() { |
return false; |
} |
+ |
+ /** |
+ * Returns whether {@link info} refers to a WebAPK. |
+ * Assumes that WebappLauncherActivity does not create WebappActivities for APKs whose package |
+ * starts with WEBAPK_PACKAGE_PREFIX but which are not WebAPKs (due to an incorrect signature). |
+ * @param info |
+ */ |
+ private static boolean isWebApk(WebappInfo info) { |
+ return info.webApkPackageName() != null; |
+ } |
} |