Commit 6ab64ce0 authored by Clark DuVall's avatar Clark DuVall Committed by Commit Bot

Convert CustomTabsConnectionService to split compat

Also removes unused onBind() from SplitCompatIntentService.

Review from Patchset 1 to get the right diffs on the changes in
CustomTabsConnectionServiceImpl.

Bug: 1126301
Change-Id: I21fa9e948030ace8377dc1fac24bc6ddcca16cd3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2462176
Commit-Queue: Clark DuVall <cduvall@chromium.org>
Reviewed-by: default avatarAndrew Grieve <agrieve@chromium.org>
Cr-Commit-Position: refs/heads/master@{#815320}
parent d8c3f0c1
...@@ -2071,6 +2071,7 @@ android_library("base_module_java") { ...@@ -2071,6 +2071,7 @@ android_library("base_module_java") {
"java/src/org/chromium/chrome/browser/ChromeBackgroundService.java", "java/src/org/chromium/chrome/browser/ChromeBackgroundService.java",
"java/src/org/chromium/chrome/browser/base/SplitChromeApplication.java", "java/src/org/chromium/chrome/browser/base/SplitChromeApplication.java",
"java/src/org/chromium/chrome/browser/base/SplitCompatApplication.java", "java/src/org/chromium/chrome/browser/base/SplitCompatApplication.java",
"java/src/org/chromium/chrome/browser/base/SplitCompatCustomTabsService.java",
"java/src/org/chromium/chrome/browser/base/SplitCompatGcmListenerService.java", "java/src/org/chromium/chrome/browser/base/SplitCompatGcmListenerService.java",
"java/src/org/chromium/chrome/browser/base/SplitCompatGcmTaskService.java", "java/src/org/chromium/chrome/browser/base/SplitCompatGcmTaskService.java",
"java/src/org/chromium/chrome/browser/base/SplitCompatIntentService.java", "java/src/org/chromium/chrome/browser/base/SplitCompatIntentService.java",
...@@ -2082,6 +2083,7 @@ android_library("base_module_java") { ...@@ -2082,6 +2083,7 @@ android_library("base_module_java") {
"java/src/org/chromium/chrome/browser/bookmarkswidget/BookmarkWidgetService.java", "java/src/org/chromium/chrome/browser/bookmarkswidget/BookmarkWidgetService.java",
"java/src/org/chromium/chrome/browser/crash/ChromeMinidumpUploadJobService.java", "java/src/org/chromium/chrome/browser/crash/ChromeMinidumpUploadJobService.java",
"java/src/org/chromium/chrome/browser/crash/MinidumpUploadService.java", "java/src/org/chromium/chrome/browser/crash/MinidumpUploadService.java",
"java/src/org/chromium/chrome/browser/customtabs/CustomTabsConnectionService.java",
"java/src/org/chromium/chrome/browser/download/DownloadBroadcastManager.java", "java/src/org/chromium/chrome/browser/download/DownloadBroadcastManager.java",
"java/src/org/chromium/chrome/browser/download/DownloadForegroundService.java", "java/src/org/chromium/chrome/browser/download/DownloadForegroundService.java",
"java/src/org/chromium/chrome/browser/incognito/IncognitoNotificationService.java", "java/src/org/chromium/chrome/browser/incognito/IncognitoNotificationService.java",
......
...@@ -451,7 +451,7 @@ chrome_java_sources = [ ...@@ -451,7 +451,7 @@ chrome_java_sources = [
"java/src/org/chromium/chrome/browser/customtabs/CustomTabTopBarDelegate.java", "java/src/org/chromium/chrome/browser/customtabs/CustomTabTopBarDelegate.java",
"java/src/org/chromium/chrome/browser/customtabs/CustomTabsClientFileProcessor.java", "java/src/org/chromium/chrome/browser/customtabs/CustomTabsClientFileProcessor.java",
"java/src/org/chromium/chrome/browser/customtabs/CustomTabsConnection.java", "java/src/org/chromium/chrome/browser/customtabs/CustomTabsConnection.java",
"java/src/org/chromium/chrome/browser/customtabs/CustomTabsConnectionService.java", "java/src/org/chromium/chrome/browser/customtabs/CustomTabsConnectionServiceImpl.java",
"java/src/org/chromium/chrome/browser/customtabs/FirstMeaningfulPaintObserver.java", "java/src/org/chromium/chrome/browser/customtabs/FirstMeaningfulPaintObserver.java",
"java/src/org/chromium/chrome/browser/customtabs/HiddenTabHolder.java", "java/src/org/chromium/chrome/browser/customtabs/HiddenTabHolder.java",
"java/src/org/chromium/chrome/browser/customtabs/IncognitoCustomTabIntentDataProvider.java", "java/src/org/chromium/chrome/browser/customtabs/IncognitoCustomTabIntentDataProvider.java",
......
...@@ -513,7 +513,7 @@ ...@@ -513,7 +513,7 @@
errorLine1=" mConnection.cleanUpSession(sessionToken);" errorLine1=" mConnection.cleanUpSession(sessionToken);"
errorLine2=" ~~~~~~~~~~~~~~"> errorLine2=" ~~~~~~~~~~~~~~">
<location <location
file="../../chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabsConnectionService.java" file="../../chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabsConnectionServiceImpl.java"
line="107" line="107"
column="21"/> column="21"/>
</issue> </issue>
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.chrome.browser.base;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.IBinder;
import androidx.browser.customtabs.CustomTabsService;
import androidx.browser.customtabs.CustomTabsSessionToken;
import java.util.List;
/**
* CustomTabsService base class which will call through to the given {@link Impl}. This class must
* be present in the base module, while the Impl can be in the chrome module.
*/
public class SplitCompatCustomTabsService extends CustomTabsService {
private String mServiceClassName;
private Impl mImpl;
public SplitCompatCustomTabsService(String serviceClassName) {
mServiceClassName = serviceClassName;
}
@Override
protected void attachBaseContext(Context context) {
context = SplitCompatUtils.createChromeContext(context);
mImpl = (Impl) SplitCompatUtils.newInstance(context, mServiceClassName);
mImpl.setService(this);
super.attachBaseContext(context);
}
@Override
public void onCreate() {
super.onCreate();
mImpl.onCreate();
}
@Override
public IBinder onBind(Intent intent) {
mImpl.onBind(intent);
return super.onBind(intent);
}
@Override
public boolean onUnbind(Intent intent) {
return mImpl.onUnbind(intent);
}
@Override
protected boolean warmup(long flags) {
return mImpl.warmup(flags);
}
@Override
protected boolean newSession(CustomTabsSessionToken sessionToken) {
return mImpl.newSession(sessionToken);
}
@Override
protected boolean mayLaunchUrl(CustomTabsSessionToken sessionToken, Uri url, Bundle extras,
List<Bundle> otherLikelyBundles) {
return mImpl.mayLaunchUrl(sessionToken, url, extras, otherLikelyBundles);
}
@Override
protected Bundle extraCommand(String commandName, Bundle args) {
return mImpl.extraCommand(commandName, args);
}
@Override
protected boolean updateVisuals(CustomTabsSessionToken sessionToken, Bundle bundle) {
return mImpl.updateVisuals(sessionToken, bundle);
}
@Override
protected boolean requestPostMessageChannel(
CustomTabsSessionToken sessionToken, Uri postMessageOrigin) {
return mImpl.requestPostMessageChannel(sessionToken, postMessageOrigin);
}
@Override
protected int postMessage(CustomTabsSessionToken sessionToken, String message, Bundle extras) {
return mImpl.postMessage(sessionToken, message, extras);
}
@Override
protected boolean validateRelationship(
CustomTabsSessionToken sessionToken, int relation, Uri originAsUri, Bundle extras) {
return mImpl.validateRelationship(sessionToken, relation, originAsUri, extras);
}
@Override
protected boolean cleanUpSession(CustomTabsSessionToken sessionToken) {
mImpl.cleanUpSession(sessionToken);
return super.cleanUpSession(sessionToken);
}
@Override
protected boolean receiveFile(
CustomTabsSessionToken sessionToken, Uri uri, int purpose, Bundle extras) {
return mImpl.receiveFile(sessionToken, uri, purpose, extras);
}
/**
* Holds the implementation of service logic. Will be called by {@link
* SplitCompatCustomTabsService}.
*/
public abstract static class Impl {
private SplitCompatCustomTabsService mService;
protected final void setService(SplitCompatCustomTabsService service) {
mService = service;
}
protected final SplitCompatCustomTabsService getService() {
return mService;
}
public void onCreate() {}
public void onBind(Intent intent) {}
public boolean onUnbind(Intent intent) {
return false;
}
protected abstract void cleanUpSession(CustomTabsSessionToken sessionToken);
protected abstract boolean warmup(long flags);
protected abstract boolean newSession(CustomTabsSessionToken sessionToken);
protected abstract boolean mayLaunchUrl(CustomTabsSessionToken sessionToken, Uri url,
Bundle extras, List<Bundle> otherLikelyBundles);
protected abstract Bundle extraCommand(String commandName, Bundle args);
protected abstract boolean updateVisuals(
CustomTabsSessionToken sessionToken, Bundle bundle);
protected abstract boolean requestPostMessageChannel(
CustomTabsSessionToken sessionToken, Uri postMessageOrigin);
protected abstract int postMessage(
CustomTabsSessionToken sessionToken, String message, Bundle extras);
protected abstract boolean validateRelationship(
CustomTabsSessionToken sessionToken, int relation, Uri originAsUri, Bundle extras);
protected abstract boolean receiveFile(
CustomTabsSessionToken sessionToken, Uri uri, int purpose, Bundle extras);
}
}
...@@ -7,7 +7,6 @@ package org.chromium.chrome.browser.base; ...@@ -7,7 +7,6 @@ package org.chromium.chrome.browser.base;
import android.app.IntentService; import android.app.IntentService;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.os.IBinder;
import androidx.annotation.VisibleForTesting; import androidx.annotation.VisibleForTesting;
...@@ -32,10 +31,6 @@ public class SplitCompatIntentService extends IntentService { ...@@ -32,10 +31,6 @@ public class SplitCompatIntentService extends IntentService {
super.attachBaseContext(context); super.attachBaseContext(context);
} }
private IBinder superOnBind(Intent intent) {
return super.onBind(intent);
}
@Override @Override
protected void onHandleIntent(Intent intent) { protected void onHandleIntent(Intent intent) {
mImpl.onHandleIntent(intent); mImpl.onHandleIntent(intent);
...@@ -65,10 +60,6 @@ public class SplitCompatIntentService extends IntentService { ...@@ -65,10 +60,6 @@ public class SplitCompatIntentService extends IntentService {
protected void onServiceSet() {} protected void onServiceSet() {}
public IBinder onBind(Intent intent) {
return mService.superOnBind(intent);
}
protected abstract void onHandleIntent(Intent intent); protected abstract void onHandleIntent(Intent intent);
} }
} }
// Copyright 2015 The Chromium Authors. All rights reserved. // Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
package org.chromium.chrome.browser.customtabs; package org.chromium.chrome.browser.customtabs;
import android.content.Intent; import org.chromium.chrome.browser.base.SplitCompatCustomTabsService;
import android.net.Uri; import org.chromium.chrome.browser.base.SplitCompatUtils;
import android.os.Bundle;
import android.os.IBinder;
import androidx.annotation.NonNull; /** See {@link CustomTabsConnectionServiceImpl}. */
import androidx.annotation.Nullable; public class CustomTabsConnectionService extends SplitCompatCustomTabsService {
import androidx.browser.customtabs.CustomTabsService; public CustomTabsConnectionService() {
import androidx.browser.customtabs.CustomTabsSessionToken; super(SplitCompatUtils.getIdentifierName(
"org.chromium.chrome.browser.customtabs.CustomTabsConnectionServiceImpl"));
import org.chromium.chrome.browser.firstrun.FirstRunFlowSequencer;
import org.chromium.chrome.browser.init.ProcessInitializationHandler;
import org.chromium.components.embedder_support.util.Origin;
import java.util.List;
/**
* Custom tabs connection service, used by the embedded Chrome activities.
*/
public class CustomTabsConnectionService extends CustomTabsService {
private CustomTabsConnection mConnection;
private Intent mBindIntent;
@Override
public void onCreate() {
ProcessInitializationHandler.getInstance().initializePreNative();
// Kick off the first access to avoid random StrictMode violations in clients.
RequestThrottler.loadInBackground();
super.onCreate();
}
@Override
public IBinder onBind(Intent intent) {
mBindIntent = intent;
mConnection = CustomTabsConnection.getInstance();
mConnection.logCall("Service#onBind()", true);
return super.onBind(intent);
}
@Override
public boolean onUnbind(Intent intent) {
super.onUnbind(intent);
if (mConnection != null) mConnection.logCall("Service#onUnbind()", true);
return false; // No support for onRebind().
}
@Override
protected boolean warmup(long flags) {
if (!isFirstRunDone()) return false;
return mConnection.warmup(flags);
}
@Override
protected boolean newSession(CustomTabsSessionToken sessionToken) {
return mConnection.newSession(sessionToken);
}
@Override
protected boolean mayLaunchUrl(CustomTabsSessionToken sessionToken, Uri url, Bundle extras,
List<Bundle> otherLikelyBundles) {
if (!isFirstRunDone()) return false;
return mConnection.mayLaunchUrl(sessionToken, url, extras, otherLikelyBundles);
}
@Override
protected Bundle extraCommand(String commandName, Bundle args) {
return mConnection.extraCommand(commandName, args);
}
@Override
protected boolean updateVisuals(CustomTabsSessionToken sessionToken, Bundle bundle) {
if (!isFirstRunDone()) return false;
return mConnection.updateVisuals(sessionToken, bundle);
}
@Override
protected boolean requestPostMessageChannel(CustomTabsSessionToken sessionToken,
Uri postMessageOrigin) {
Origin origin = Origin.create(postMessageOrigin);
if (origin == null) return false;
return mConnection.requestPostMessageChannel(sessionToken, origin);
}
@Override
protected int postMessage(CustomTabsSessionToken sessionToken, String message,
Bundle extras) {
if (!isFirstRunDone()) return CustomTabsService.RESULT_FAILURE_DISALLOWED;
return mConnection.postMessage(sessionToken, message, extras);
}
@Override
protected boolean validateRelationship(
CustomTabsSessionToken sessionToken, int relation, Uri originAsUri, Bundle extras) {
Origin origin = Origin.create(originAsUri);
if (origin == null) return false;
return mConnection.validateRelationship(sessionToken, relation, origin, extras);
}
@Override
protected boolean cleanUpSession(CustomTabsSessionToken sessionToken) {
mConnection.cleanUpSession(sessionToken);
return super.cleanUpSession(sessionToken);
}
@Override
protected boolean receiveFile(@NonNull CustomTabsSessionToken sessionToken, @NonNull Uri uri,
int purpose, @Nullable Bundle extras) {
return mConnection.receiveFile(sessionToken, uri, purpose, extras);
}
private boolean isFirstRunDone() {
if (mBindIntent == null) return true;
boolean firstRunNecessary = FirstRunFlowSequencer.checkIfFirstRunIsNecessary(false, true);
if (!firstRunNecessary) {
mBindIntent = null;
return true;
}
return false;
} }
} }
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.chrome.browser.customtabs;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.browser.customtabs.CustomTabsService;
import androidx.browser.customtabs.CustomTabsSessionToken;
import org.chromium.chrome.browser.firstrun.FirstRunFlowSequencer;
import org.chromium.chrome.browser.init.ProcessInitializationHandler;
import org.chromium.components.embedder_support.util.Origin;
import java.util.List;
/**
* Custom tabs connection service, used by the embedded Chrome activities.
*/
public class CustomTabsConnectionServiceImpl extends CustomTabsConnectionService.Impl {
private CustomTabsConnection mConnection;
private Intent mBindIntent;
@Override
public void onCreate() {
ProcessInitializationHandler.getInstance().initializePreNative();
// Kick off the first access to avoid random StrictMode violations in clients.
RequestThrottler.loadInBackground();
super.onCreate();
}
@Override
public void onBind(Intent intent) {
mBindIntent = intent;
mConnection = CustomTabsConnection.getInstance();
mConnection.logCall("Service#onBind()", true);
}
@Override
public boolean onUnbind(Intent intent) {
super.onUnbind(intent);
if (mConnection != null) mConnection.logCall("Service#onUnbind()", true);
return false; // No support for onRebind().
}
@Override
protected boolean warmup(long flags) {
if (!isFirstRunDone()) return false;
return mConnection.warmup(flags);
}
@Override
protected boolean newSession(CustomTabsSessionToken sessionToken) {
return mConnection.newSession(sessionToken);
}
@Override
protected boolean mayLaunchUrl(CustomTabsSessionToken sessionToken, Uri url, Bundle extras,
List<Bundle> otherLikelyBundles) {
if (!isFirstRunDone()) return false;
return mConnection.mayLaunchUrl(sessionToken, url, extras, otherLikelyBundles);
}
@Override
protected Bundle extraCommand(String commandName, Bundle args) {
return mConnection.extraCommand(commandName, args);
}
@Override
protected boolean updateVisuals(CustomTabsSessionToken sessionToken, Bundle bundle) {
if (!isFirstRunDone()) return false;
return mConnection.updateVisuals(sessionToken, bundle);
}
@Override
protected boolean requestPostMessageChannel(
CustomTabsSessionToken sessionToken, Uri postMessageOrigin) {
Origin origin = Origin.create(postMessageOrigin);
if (origin == null) return false;
return mConnection.requestPostMessageChannel(sessionToken, origin);
}
@Override
protected int postMessage(CustomTabsSessionToken sessionToken, String message, Bundle extras) {
if (!isFirstRunDone()) return CustomTabsService.RESULT_FAILURE_DISALLOWED;
return mConnection.postMessage(sessionToken, message, extras);
}
@Override
protected boolean validateRelationship(
CustomTabsSessionToken sessionToken, int relation, Uri originAsUri, Bundle extras) {
Origin origin = Origin.create(originAsUri);
if (origin == null) return false;
return mConnection.validateRelationship(sessionToken, relation, origin, extras);
}
@Override
protected void cleanUpSession(CustomTabsSessionToken sessionToken) {
mConnection.cleanUpSession(sessionToken);
}
@Override
protected boolean receiveFile(@NonNull CustomTabsSessionToken sessionToken, @NonNull Uri uri,
int purpose, @Nullable Bundle extras) {
return mConnection.receiveFile(sessionToken, uri, purpose, extras);
}
private boolean isFirstRunDone() {
if (mBindIntent == null) return true;
boolean firstRunNecessary = FirstRunFlowSequencer.checkIfFirstRunIsNecessary(false, true);
if (!firstRunNecessary) {
mBindIntent = null;
return true;
}
return false;
}
}
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