Commit 51005538 authored by Colin Blundell's avatar Colin Blundell Committed by Commit Bot

[WebLayer] Change shell to retain Fragment instance

This CL changes WebLayer Shell to retain the Fragment instance in order
to more accurately model the behavior of WebLayer consumers. As part of
this change, WebLayer Shell no longer handles rotation/resize internally
in its manifest and loads the startup url on weblayer creation only if
there is not already a navigation entry in the current Tab.

Note that to test rotation in an emulator it is necessary to turn on
autorotation, which is off by default in crow.

Change-Id: I8a575e477d1242486f9fbbe72151392b597b86b9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2007413Reviewed-by: default avatarBo <boliu@chromium.org>
Commit-Queue: Colin Blundell <blundell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#734505}
parent 6a96919e
...@@ -13,8 +13,7 @@ ...@@ -13,8 +13,7 @@
<activity android:name="WebLayerShellActivity" <activity android:name="WebLayerShellActivity"
android:launchMode="singleTask" android:launchMode="singleTask"
android:theme="@android:style/Theme.Holo.Light.NoActionBar" android:theme="@android:style/Theme.Holo.Light.NoActionBar"
android:windowSoftInputMode="adjustResize" android:windowSoftInputMode="adjustResize">
android:configChanges="orientation|screenSize">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.LAUNCHER" />
......
...@@ -62,6 +62,7 @@ public class WebLayerShellActivity extends FragmentActivity { ...@@ -62,6 +62,7 @@ public class WebLayerShellActivity extends FragmentActivity {
private View mMainView; private View mMainView;
private int mMainViewId; private int mMainViewId;
private ViewGroup mTopContentsContainer; private ViewGroup mTopContentsContainer;
private TabListCallback mTabListCallback;
private List<Tab> mPreviousTabList = new ArrayList<>(); private List<Tab> mPreviousTabList = new ArrayList<>();
private Runnable mExitFullscreenRunnable; private Runnable mExitFullscreenRunnable;
...@@ -140,36 +141,72 @@ public class WebLayerShellActivity extends FragmentActivity { ...@@ -140,36 +141,72 @@ public class WebLayerShellActivity extends FragmentActivity {
} }
} }
@Override
protected void onDestroy() {
super.onDestroy();
if (mTabListCallback != null) {
mBrowser.unregisterTabListCallback(mTabListCallback);
mTabListCallback = null;
}
}
private void onWebLayerReady(WebLayer webLayer, Bundle savedInstanceState) { private void onWebLayerReady(WebLayer webLayer, Bundle savedInstanceState) {
if (isFinishing() || isDestroyed()) return; if (isFinishing() || isDestroyed()) return;
webLayer.setRemoteDebuggingEnabled(true); webLayer.setRemoteDebuggingEnabled(true);
Fragment fragment = getOrCreateBrowserFragment(savedInstanceState); Fragment fragment = getOrCreateBrowserFragment(savedInstanceState);
// Have WebLayer Shell retain the fragment instance to simulate the behavior of
// external embedders (note that if this is changed, then WebLayer Shell should handle
// rotations and resizes itself via its manifest, as otherwise the user loses all state
// when the shell is rotated in the foreground).
fragment.setRetainInstance(true);
mBrowser = Browser.fromFragment(fragment); mBrowser = Browser.fromFragment(fragment);
mBrowser.registerTabListCallback(new TabListCallback() { mTabListCallback = new TabListCallback() {
@Override @Override
public void onActiveTabChanged(Tab activeTab) { public void onActiveTabChanged(Tab activeTab) {
NavigationController navigationController = activeTab.getNavigationController(); String currentDisplayUrl = getCurrentDisplayUrl();
if (navigationController.getNavigationListSize() > 0) { if (currentDisplayUrl != null) {
mUrlView.setText( mUrlView.setText(currentDisplayUrl);
navigationController
.getNavigationEntryDisplayUri(
navigationController.getNavigationListCurrentIndex())
.toString());
} }
} }
}); };
mBrowser.registerTabListCallback(mTabListCallback);
setTabCallbacks(mBrowser.getActiveTab(), fragment); setTabCallbacks(mBrowser.getActiveTab(), fragment);
mProfile = mBrowser.getProfile(); mProfile = mBrowser.getProfile();
mBrowser.setTopView(mTopContentsContainer); mBrowser.setTopView(mTopContentsContainer);
String startupUrl = getUrlFromIntent(getIntent()); // If there is already a url loaded in the current tab just display it in the top bar;
if (TextUtils.isEmpty(startupUrl)) { // otherwise load the startup url.
startupUrl = "https://google.com"; String currentDisplayUrl = getCurrentDisplayUrl();
if (currentDisplayUrl != null) {
mUrlView.setText(currentDisplayUrl);
} else {
String startupUrl = getUrlFromIntent(getIntent());
if (TextUtils.isEmpty(startupUrl)) {
startupUrl = "https://google.com";
}
loadUrl(startupUrl);
} }
loadUrl(startupUrl); }
/* Returns the Url for the current tab as a String, or null if there is no
* current tab. */
private String getCurrentDisplayUrl() {
NavigationController navigationController =
mBrowser.getActiveTab().getNavigationController();
if (navigationController.getNavigationListSize() == 0) {
return null;
}
return navigationController
.getNavigationEntryDisplayUri(navigationController.getNavigationListCurrentIndex())
.toString();
} }
private void setTabCallbacks(Tab tab, Fragment fragment) { private void setTabCallbacks(Tab tab, Fragment fragment) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment