Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 | 9 |
| 9 import org.chromium.base.ContextUtils; | 10 import org.chromium.base.ContextUtils; |
| 10 import org.chromium.base.library_loader.LibraryProcessType; | 11 import org.chromium.base.library_loader.LibraryProcessType; |
| 11 import org.chromium.chrome.browser.ChromeApplication; | 12 import org.chromium.chrome.browser.ChromeApplication; |
| 12 import org.chromium.chrome.browser.ShortcutHelper; | 13 import org.chromium.chrome.browser.ShortcutHelper; |
| 13 import org.chromium.chrome.browser.banners.AppBannerManager; | 14 import org.chromium.chrome.browser.banners.AppBannerManager; |
| 14 import org.chromium.chrome.browser.externalnav.ExternalNavigationParams; | 15 import org.chromium.chrome.browser.externalnav.ExternalNavigationParams; |
| 15 import org.chromium.chrome.browser.tab.InterceptNavigationDelegateImpl; | 16 import org.chromium.chrome.browser.tab.InterceptNavigationDelegateImpl; |
| 16 import org.chromium.chrome.browser.tab.Tab; | 17 import org.chromium.chrome.browser.tab.Tab; |
| 17 import org.chromium.chrome.browser.tab.TabDelegateFactory; | 18 import org.chromium.chrome.browser.tab.TabDelegateFactory; |
| 18 import org.chromium.chrome.browser.tab.TabRedirectHandler; | 19 import org.chromium.chrome.browser.tab.TabRedirectHandler; |
| 19 import org.chromium.components.navigation_interception.NavigationParams; | 20 import org.chromium.components.navigation_interception.NavigationParams; |
| 20 import org.chromium.content.browser.ChildProcessCreationParams; | 21 import org.chromium.content.browser.ChildProcessCreationParams; |
| 22 import org.chromium.content.browser.ScreenOrientationProvider; | |
| 21 import org.chromium.content_public.browser.LoadUrlParams; | 23 import org.chromium.content_public.browser.LoadUrlParams; |
| 22 import org.chromium.ui.base.PageTransition; | 24 import org.chromium.ui.base.PageTransition; |
| 23 import org.chromium.webapk.lib.client.WebApkServiceConnectionManager; | 25 import org.chromium.webapk.lib.client.WebApkServiceConnectionManager; |
| 24 import org.chromium.webapk.lib.common.WebApkSandboxedProcessService; | 26 import org.chromium.webapk.lib.common.WebApkSandboxedProcessService; |
| 25 | 27 |
| 26 /** | 28 /** |
| 27 * An Activity is designed for WebAPKs (native Android apps) and displays a weba pp in a nearly | 29 * An Activity is designed for WebAPKs (native Android apps) and displays a weba pp in a nearly |
| 28 * UI-less Chrome. | 30 * UI-less Chrome. |
| 29 */ | 31 */ |
| 30 public class WebApkActivity extends WebappActivity { | 32 public class WebApkActivity extends WebappActivity { |
| 31 @Override | 33 @Override |
| 32 protected void onNewIntent(Intent intent) { | 34 protected void onNewIntent(Intent intent) { |
| 33 super.onNewIntent(intent); | 35 super.onNewIntent(intent); |
| 34 // We could bring a WebAPK hosted WebappActivity to foreground and navig ate it to a | 36 // We could bring a WebAPK hosted WebappActivity to foreground and navig ate it to a |
| 35 // different URL. For example, WebAPK "foo" is launched and navigates to | 37 // different URL. For example, WebAPK "foo" is launched and navigates to |
| 36 // "www.foo.com/foo". In Chrome, user clicks a link "www.foo.com/bar" in Google search | 38 // "www.foo.com/foo". In Chrome, user clicks a link "www.foo.com/bar" in Google search |
| 37 // results. After clicking the link, WebAPK "foo" is brought to foregrou nd, and | 39 // results. After clicking the link, WebAPK "foo" is brought to foregrou nd, and |
| 38 // loads the page of "www.foo.com/bar" at the same time. | 40 // loads the page of "www.foo.com/bar" at the same time. |
| 39 // The extra {@link ShortcutHelper.EXTRA_URL} provides the URL that the WebAPK will | 41 // The extra {@link ShortcutHelper.EXTRA_URL} provides the URL that the WebAPK will |
| 40 // navigate to. | 42 // navigate to. |
| 41 String overrideUrl = intent.getStringExtra(ShortcutHelper.EXTRA_URL); | 43 String overrideUrl = intent.getStringExtra(ShortcutHelper.EXTRA_URL); |
| 42 if (overrideUrl != null && isInitialized() | 44 if (overrideUrl != null && isInitialized() |
| 43 && !overrideUrl.equals(getActivityTab().getUrl())) { | 45 && !overrideUrl.equals(getActivityTab().getUrl())) { |
| 44 getActivityTab().loadUrl( | 46 getActivityTab().loadUrl( |
| 45 new LoadUrlParams(overrideUrl, PageTransition.AUTO_TOPLEVEL) ); | 47 new LoadUrlParams(overrideUrl, PageTransition.AUTO_TOPLEVEL) ); |
| 46 } | 48 } |
| 47 } | 49 } |
| 48 | 50 |
| 49 @Override | 51 @Override |
| 50 protected void initializeSplashScreenWidgets(final int backgroundColor) { | 52 protected void initializeWebappData() { |
|
pkotwicz
2016/06/20 18:26:14
- Can this function be in WebappActivity instead o
Xi Han
2016/06/22 15:55:28
I am not sure whether this suits Webapps, because
pkotwicz
2016/06/23 01:16:37
I don't mind waiting till the "fetch updated Web M
| |
| 51 // TODO(hanxi): Removes this function and use {@link WebApkActivity}'s i mplementation | 53 WebappRegistry.getWebappDataStorage(this, getId(), |
| 52 // when WebAPKs are registered in WebappRegistry. | 54 new WebappRegistry.FetchWebappDataStorageCallback() { |
| 53 initializeSplashScreenWidgets(backgroundColor, null); | 55 @Override |
| 56 public void onWebappDataStorageRetrieved(WebappDataStorage s torage) { | |
| 57 if (storage == null) { | |
|
pkotwicz
2016/06/20 18:26:14
Currently, WebappRegistry#registerWebapp() is not
Xi Han
2016/06/22 15:55:28
Yes, we always go through the early return for now
pkotwicz
2016/06/23 01:16:37
I think that there will be multiple places which w
pkotwicz
2016/06/27 19:23:38
It looks like you missed this comment
Xi Han
2016/06/27 20:04:10
Sorry, just forgot to reply in here. I add the reg
pkotwicz
2016/06/28 19:00:11
I see the call to registerWebapp() now. Sorry that
| |
| 58 initializeSplashScreenWidgets(initializeWebappDataIn ternal(), null); | |
| 59 return; | |
| 60 } | |
| 61 // Update WebappInfo for the WebAPK. Changes in fields l ike backgroundColor, | |
| 62 // themeColor, orientation won't request re-minting a We bAPK, but will | |
| 63 // update the metadata in the SharedPreference. The upda ted values are | |
| 64 // used when launching a WebAPK. | |
| 65 // TODO(hanxi): Introduces data fetcher to detect web ma nifest changes and | |
| 66 // update SharedPreference for WebAPKs. | |
| 67 mWebappInfo.setBackgroundColor(storage.getBackgroundColo r()); | |
| 68 final int backgroundColor = initializeWebappDataInternal (); | |
| 69 | |
| 70 mWebappInfo.setThemeColor(storage.getThemeColor()); | |
| 71 | |
| 72 int orientation = storage.getOrientation(); | |
| 73 if (mWebappInfo.orientation() != orientation) { | |
| 74 mWebappInfo.setOrientation(orientation); | |
| 75 ScreenOrientationProvider.lockOrientation( | |
| 76 (byte) mWebappInfo.orientation(), WebApkActi vity.this); | |
| 77 } | |
| 78 | |
|
pkotwicz
2016/06/20 18:26:14
Shouldn't we also update WebappInfo#name()?
I am u
Xi Han
2016/06/22 15:55:28
Good point. Creating a new WebappInfo will have th
| |
| 79 storage.updateLastUsedTime(); | |
| 80 | |
| 81 // Retrieve the splash image if it exists. | |
| 82 storage.getSplashScreenImage(new WebappDataStorage.Fetch Callback<Bitmap>() { | |
| 83 @Override | |
| 84 public void onDataRetrieved(Bitmap splashImage) { | |
| 85 initializeSplashScreenWidgets(backgroundColor, s plashImage); | |
| 86 } | |
| 87 }); | |
| 88 } | |
| 89 } | |
| 90 ); | |
| 54 } | 91 } |
| 55 | 92 |
| 56 @Override | 93 @Override |
| 57 protected TabDelegateFactory createTabDelegateFactory() { | 94 protected TabDelegateFactory createTabDelegateFactory() { |
| 58 return new WebappDelegateFactory(this) { | 95 return new WebappDelegateFactory(this) { |
| 59 @Override | 96 @Override |
| 60 public InterceptNavigationDelegateImpl createInterceptNavigationDele gate(Tab tab) { | 97 public InterceptNavigationDelegateImpl createInterceptNavigationDele gate(Tab tab) { |
| 61 return new InterceptNavigationDelegateImpl(tab) { | 98 return new InterceptNavigationDelegateImpl(tab) { |
| 62 @Override | 99 @Override |
| 63 public ExternalNavigationParams.Builder buildExternalNavigat ionParams( | 100 public ExternalNavigationParams.Builder buildExternalNavigat ionParams( |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 130 ChildProcessCreationParams params = chrome.getChildProcessCreationParams (); | 167 ChildProcessCreationParams params = chrome.getChildProcessCreationParams (); |
| 131 if (isForWebApk) { | 168 if (isForWebApk) { |
| 132 int extraBindFlag = params == null ? 0 : params.getExtraBindFlags(); | 169 int extraBindFlag = params == null ? 0 : params.getExtraBindFlags(); |
| 133 params = new ChildProcessCreationParams(getWebappInfo().webApkPackag eName(), | 170 params = new ChildProcessCreationParams(getWebappInfo().webApkPackag eName(), |
| 134 extraBindFlag, LibraryProcessType.PROCESS_CHILD, | 171 extraBindFlag, LibraryProcessType.PROCESS_CHILD, |
| 135 WebApkSandboxedProcessService.class); | 172 WebApkSandboxedProcessService.class); |
| 136 } | 173 } |
| 137 ChildProcessCreationParams.set(params); | 174 ChildProcessCreationParams.set(params); |
| 138 } | 175 } |
| 139 } | 176 } |
| OLD | NEW |