Commit f998fee2 authored by Michael van Ouwerkerk's avatar Michael van Ouwerkerk Committed by Commit Bot

Call IActivityDelegate.onBackPressedAsync.

Bug: 843161
Change-Id: I433cad8d86b34d64de99e13281d84c953d9bf3b1
Reviewed-on: https://chromium-review.googlesource.com/1150225Reviewed-by: default avatarChris Palmer <palmer@chromium.org>
Reviewed-by: default avatarBernhard Bauer <bauerb@chromium.org>
Commit-Queue: Michael van Ouwerkerk <mvanouwerkerk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#580490}
parent 109eda25
...@@ -171,6 +171,8 @@ public class CustomTabActivity extends ChromeActivity { ...@@ -171,6 +171,8 @@ public class CustomTabActivity extends ChromeActivity {
private WebappCustomTabTimeSpentLogger mWebappTimeSpentLogger; private WebappCustomTabTimeSpentLogger mWebappTimeSpentLogger;
@Nullable
private ModuleEntryPoint mModuleEntryPoint;
@Nullable @Nullable
private ActivityDelegate mModuleActivityDelegate; private ActivityDelegate mModuleActivityDelegate;
@Nullable @Nullable
...@@ -322,6 +324,8 @@ public class CustomTabActivity extends ChromeActivity { ...@@ -322,6 +324,8 @@ public class CustomTabActivity extends ChromeActivity {
mLoadModuleCancelRunnable = null; mLoadModuleCancelRunnable = null;
if (entryPoint == null) return; if (entryPoint == null) return;
mModuleEntryPoint = entryPoint;
long createActivityDelegateStartTime = ModuleMetrics.now(); long createActivityDelegateStartTime = ModuleMetrics.now();
mModuleActivityDelegate = entryPoint.createActivityDelegate(new ActivityHostImpl(this)); mModuleActivityDelegate = entryPoint.createActivityDelegate(new ActivityHostImpl(this));
ModuleMetrics.recordCreateActivityDelegateTime(createActivityDelegateStartTime); ModuleMetrics.recordCreateActivityDelegateTime(createActivityDelegateStartTime);
...@@ -825,6 +829,7 @@ public class CustomTabActivity extends ChromeActivity { ...@@ -825,6 +829,7 @@ public class CustomTabActivity extends ChromeActivity {
mModuleActivityDelegate.onDestroy(); mModuleActivityDelegate.onDestroy();
mModuleActivityDelegate = null; mModuleActivityDelegate = null;
} }
mModuleEntryPoint = null;
ComponentName moduleComponentName = mIntentDataProvider.getModuleComponentName(); ComponentName moduleComponentName = mIntentDataProvider.getModuleComponentName();
if (moduleComponentName != null) { if (moduleComponentName != null) {
mConnection.getModuleLoader(moduleComponentName).maybeUnloadModule(); mConnection.getModuleLoader(moduleComponentName).maybeUnloadModule();
...@@ -1010,8 +1015,16 @@ public class CustomTabActivity extends ChromeActivity { ...@@ -1010,8 +1015,16 @@ public class CustomTabActivity extends ChromeActivity {
if (exitFullscreenIfShowing()) return true; if (exitFullscreenIfShowing()) return true;
if (mModuleActivityDelegate != null && mModuleActivityDelegate.onBackPressed()) return true; if (mModuleActivityDelegate != null && mModuleEntryPoint.getModuleVersion() >= 2) {
mModuleActivityDelegate.onBackPressedAsync(this::handleTabBackNavigation);
return true;
}
handleTabBackNavigation();
return true;
}
private void handleTabBackNavigation() {
if (!getToolbarManager().back()) { if (!getToolbarManager().back()) {
if (getCurrentTabModel().getCount() > 1) { if (getCurrentTabModel().getCount() > 1) {
getCurrentTabModel().closeTab(getActivityTab(), false, false, false); getCurrentTabModel().closeTab(getActivityTab(), false, false, false);
...@@ -1020,7 +1033,6 @@ public class CustomTabActivity extends ChromeActivity { ...@@ -1020,7 +1033,6 @@ public class CustomTabActivity extends ChromeActivity {
finishAndClose(false); finishAndClose(false);
} }
} }
return true;
} }
@Override @Override
......
...@@ -107,4 +107,12 @@ public class ActivityDelegate { ...@@ -107,4 +107,12 @@ public class ActivityDelegate {
} }
return false; return false;
} }
public void onBackPressedAsync(Runnable notHandledRunnable) {
try {
mActivityDelegate.onBackPressedAsync(ObjectWrapper.wrap(notHandledRunnable));
} catch (RemoteException e) {
assert false;
}
}
} }
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
package org.chromium.chrome.browser.customtabs.dynamicmodule; package org.chromium.chrome.browser.customtabs.dynamicmodule;
import org.chromium.chrome.browser.customtabs.dynamicmodule.IObjectWrapper;
interface IActivityDelegate { interface IActivityDelegate {
void onCreate(in Bundle savedInstanceState) = 0; void onCreate(in Bundle savedInstanceState) = 0;
...@@ -26,4 +28,12 @@ interface IActivityDelegate { ...@@ -26,4 +28,12 @@ interface IActivityDelegate {
void onDestroy() = 9; void onDestroy() = 9;
boolean onBackPressed() = 10; boolean onBackPressed() = 10;
/**
* Offers an opportunity to handle the back press event. If it is not handled,
* the Runnable must be run.
*
* Introduced in API version 2.
*/
void onBackPressedAsync(in IObjectWrapper /* Runnable */ notHandledRunnable) = 11;
} }
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