Chromium Code Reviews| 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 e4f5fe67dccc7fe10498d3c10e6b0f4cfe865c5e..5353603b65ce77573fe85724c35e6b09cb6c456d 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; |
| @@ -46,6 +47,7 @@ import org.chromium.content.browser.ScreenOrientationProvider; |
| import org.chromium.content_public.browser.LoadUrlParams; |
| import org.chromium.net.NetworkChangeNotifier; |
| import org.chromium.ui.base.PageTransition; |
| +import org.chromium.webapk.lib.common.WebApkConstants; |
| import java.io.File; |
| import java.io.FileNotFoundException; |
| @@ -62,9 +64,11 @@ public class WebappActivity extends FullScreenActivity { |
| private static final String TAG = "WebappActivity"; |
| private static final long MS_BEFORE_NAVIGATING_BACK_FROM_INTERSTITIAL = 1000; |
| - private final WebappInfo mWebappInfo; |
| private final WebappDirectoryManager mDirectoryManager; |
| + private WebappInfo mWebappInfo; |
| + private boolean mIsWebApk; |
| + |
| private boolean mOldWebappCleanupStarted; |
| private ViewGroup mSplashScreen; |
| @@ -98,7 +102,8 @@ public class WebappActivity extends FullScreenActivity { |
| Log.e(TAG, "Failed to parse new Intent: " + intent); |
| finish(); |
| } else if (!TextUtils.equals(mWebappInfo.id(), newWebappInfo.id())) { |
| - mWebappInfo.copy(newWebappInfo); |
| + mWebappInfo = newWebappInfo; |
| + mIsWebApk = isWebApk(mWebappInfo); |
| resetSavedInstanceState(); |
| if (mIsInitialized) initializeUI(null); |
| } |
| @@ -123,7 +128,10 @@ public class WebappActivity extends FullScreenActivity { |
| @Override |
| public void preInflationStartup() { |
| WebappInfo info = WebappInfo.create(getIntent()); |
| - if (info != null) mWebappInfo.copy(info); |
| + if (info != null) { |
| + mWebappInfo = info; |
| + mIsWebApk = isWebApk(info); |
| + } |
| ScreenOrientationProvider.lockOrientation((byte) mWebappInfo.orientation(), this); |
| super.preInflationStartup(); |
| @@ -208,8 +216,32 @@ public class WebappActivity extends FullScreenActivity { |
| } |
| @Override |
| + public void onPause() { |
| + super.onPause(); |
| + // TODO(hanxi): Change onResumeWithNative behaviour so this isn't necessary. |
| + if (mIsWebApk) { |
| + getIntent().removeExtra(ShortcutHelper.EXTRA_URL); |
| + } |
| + } |
| + |
| + @Override |
| public void onResumeWithNative() { |
| super.onResumeWithNative(); |
| + if (getIntent() != null && mIsWebApk) { |
|
pkotwicz
2016/05/18 23:00:17
- Is this change alone sufficient or does there al
Xi Han
2016/05/19 18:31:49
This makes WebAPK can load different URL in the In
|
| + // 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". A notification comes in with a link "www.foo.com/bar" with falls |
| + // in the scope of WebAPK "foo". After clicking the notification, WebAPK "foo" will be |
| + // brought to foreground and navigates to "www.foo.com/bar". |
| + // The extra {@link ShortcutHelper.EXTRA_URL} provides the URL that the WebAPK will |
| + // navigate to. |
| + String overrideUrl = getIntent().getStringExtra(ShortcutHelper.EXTRA_URL); |
| + if (overrideUrl != null && getActivityTab() != null |
| + && !overrideUrl.equals(getActivityTab().getUrl())) { |
| + getActivityTab().loadUrl( |
| + new LoadUrlParams(overrideUrl, PageTransition.AUTO_TOPLEVEL)); |
| + } |
| + } |
| mWebappUma.commitMetrics(); |
| } |
| @@ -253,6 +285,12 @@ public class WebappActivity extends FullScreenActivity { |
| ? WebappUma.SPLASHSCREEN_COLOR_STATUS_CUSTOM |
| : WebappUma.SPLASHSCREEN_COLOR_STATUS_DEFAULT); |
| + if (mIsWebApk) { |
|
pkotwicz
2016/05/18 23:00:17
Can we introduce this change in a followup CL?
Xi Han
2016/05/19 18:31:49
I intent to add this here, since it is a bug fix.
|
| + // 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() { |
| @@ -601,4 +639,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 singature). |
| + * @param info |
| + */ |
| + private static boolean isWebApk(WebappInfo info) { |
| + return info.packageName().startsWith(WebApkConstants.WEBAPK_PACKAGE_PREFIX); |
|
pkotwicz
2016/05/18 23:00:17
Can we fully trust WebappLauncherActivity? So chan
Xi Han
2016/05/19 18:31:49
Yes, it is better to have this check first.
pkotwicz
2016/05/19 21:36:35
I was actually suggesting removing the prefix chec
Xi Han
2016/05/20 14:45:41
Done.
|
| + } |
| } |