Commit 9d4aa096 authored by Scott Violet's avatar Scott Violet Committed by Commit Bot

weblayer: adds versioning

This patch separates out creation of WebLayer to a WebLayerFactory and
has the client supply the version of chrome the client was compiled with.
WebLayerFactory also offers functions to return the version of the
implementation. This does not change the existing versioning checks, rather
adds the real chrome version. The goal is we will eventually use the real
chrome version and not the one of version we added.

BUG=1025615
TEST=all tests implicitly trigger the new code paths

Change-Id: Ie6330a57fd9f205504758c9cde9707537cb643f3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1935037
Commit-Queue: Scott Violet <sky@chromium.org>
Reviewed-by: default avatarClark DuVall <cduvall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#720825}
parent ff9eac7c
......@@ -51,6 +51,7 @@ android_library("java") {
"org/chromium/weblayer_private/TabImpl.java",
"org/chromium/weblayer_private/TopControlsContainerView.java",
"org/chromium/weblayer_private/WebContentsGestureStateTracker.java",
"org/chromium/weblayer_private/WebLayerFactoryImpl.java",
"org/chromium/weblayer_private/WebLayerImpl.java",
"org/chromium/weblayer_private/metrics/UmaUtils.java",
]
......@@ -172,5 +173,6 @@ android_aidl("aidl") {
"org/chromium/weblayer_private/interfaces/ITab.aidl",
"org/chromium/weblayer_private/interfaces/ITabClient.aidl",
"org/chromium/weblayer_private/interfaces/IWebLayer.aidl",
"org/chromium/weblayer_private/interfaces/IWebLayerFactory.aidl",
]
}
// Copyright 2019 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.weblayer_private;
import android.os.IBinder;
import org.chromium.base.annotations.UsedByReflection;
import org.chromium.components.version_info.VersionConstants;
import org.chromium.weblayer_private.interfaces.IWebLayer;
import org.chromium.weblayer_private.interfaces.IWebLayerFactory;
import org.chromium.weblayer_private.interfaces.WebLayerVersion;
/**
* Factory used to create WebLayer as well as verify compatibility.
* This is constructed by the client library using reflection.
*/
@UsedByReflection("WebLayer")
public final class WebLayerFactoryImpl extends IWebLayerFactory.Stub {
private final int mClientMajorVersion;
private final String mClientVersion;
private final int mClientWeblayerVersion;
/**
* This function is called by the client using reflection.
*
* @param clientVersion The full version string the client was compiled from.
* @param clientMajorVersion The major version number the client was compiled from. This is also
* contained in clientVersion.
* @param clientWebLayerVersion The version from interfaces.WebLayerVersion the client was
* compiled with.
*/
@UsedByReflection("WebLayer")
public static IBinder create(
String clientVersion, int clientMajorVersion, int clientWebLayerVersion) {
return new WebLayerFactoryImpl(clientVersion, clientMajorVersion, clientWebLayerVersion);
}
private WebLayerFactoryImpl(
String clientVersion, int clientMajorVersion, int clientWeblayerVersion) {
mClientMajorVersion = clientMajorVersion;
mClientVersion = clientVersion;
mClientWeblayerVersion = clientWeblayerVersion;
}
/**
* Returns true if the client compiled with the specific version is compatible with this
* implementation. The client library calls this exactly once.
*/
@Override
public boolean isClientSupported() {
return mClientWeblayerVersion == WebLayerVersion.sVersionNumber;
}
/**
* Returns the major version of the implementation.
*/
@Override
public int getImplementationMajorVersion() {
return VersionConstants.PRODUCT_MAJOR_VERSION;
}
/**
* Returns the full version string of the implementation.
*/
@Override
public String getImplementationVersion() {
return VersionConstants.PRODUCT_VERSION;
}
@Override
public IWebLayer createWebLayer() {
assert isClientSupported();
return new WebLayerImpl();
}
}
......@@ -12,7 +12,6 @@ import android.content.res.AssetManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.IBinder;
import android.support.v4.content.FileProvider;
import android.util.SparseArray;
import android.webkit.ValueCallback;
......@@ -28,7 +27,6 @@ import org.chromium.base.PathUtils;
import org.chromium.base.StrictModeContext;
import org.chromium.base.annotations.JNINamespace;
import org.chromium.base.annotations.NativeMethods;
import org.chromium.base.annotations.UsedByReflection;
import org.chromium.base.library_loader.LibraryLoader;
import org.chromium.base.library_loader.LibraryProcessType;
import org.chromium.components.embedder_support.application.ClassLoaderContextWrapperFactory;
......@@ -43,7 +41,6 @@ import org.chromium.weblayer_private.interfaces.IRemoteFragmentClient;
import org.chromium.weblayer_private.interfaces.IWebLayer;
import org.chromium.weblayer_private.interfaces.ObjectWrapper;
import org.chromium.weblayer_private.interfaces.StrictModeWorkaround;
import org.chromium.weblayer_private.interfaces.WebLayerVersion;
import org.chromium.weblayer_private.metrics.UmaUtils;
import java.io.File;
......@@ -52,10 +49,8 @@ import java.lang.reflect.Method;
/**
* Root implementation class for WebLayer.
* This is constructed by the client library using reflection.
*/
@JNINamespace("weblayer")
@UsedByReflection("WebLayer")
public final class WebLayerImpl extends IWebLayer.Stub {
// TODO: should there be one tag for all this code?
private static final String TAG = "WebLayer";
......@@ -80,20 +75,7 @@ public final class WebLayerImpl extends IWebLayer.Stub {
}
}
@UsedByReflection("WebLayer")
public static IBinder create() {
return new WebLayerImpl();
}
private WebLayerImpl() {}
/**
* Returns true if the client and implementation versions are compatible.
*/
@UsedByReflection("WebLayer")
public static boolean checkVersion(int clientVersion) {
return clientVersion == WebLayerVersion.sVersionNumber;
}
WebLayerImpl() {}
@Override
public void loadAsync(IObjectWrapper appContextWrapper, IObjectWrapper loadedCallbackWrapper) {
......
// Copyright 2019 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.weblayer_private.interfaces;
import android.os.Bundle;
import org.chromium.weblayer_private.interfaces.IWebLayer;
// Factory for creating IWebLayer as well as determining if a particular version
// of a client is supported.
interface IWebLayerFactory {
// Returns true if a client with the specified version is supported.
boolean isClientSupported() = 0;
// Creates a new IWebLayer. It is expected that a client has a single
// IWebLayer. Further, at this time, only a single client is supported.
IWebLayer createWebLayer() = 1;
// Returns the full version string of the implementation.
String getImplementationVersion() = 2;
// Returns the major version of the implementation.
int getImplementationMajorVersion() = 3;
}
......@@ -4,6 +4,10 @@
import("//build/config/android/config.gni")
import("//build/config/android/rules.gni")
import("//build/util/process_version.gni")
_version_constants_java_file =
"$target_gen_dir/org/chromium/weblayer/WebLayerClientVersionConstants.java"
weblayer_client_manifest =
"$target_gen_dir/weblayer_client_manifest/AndroidManifest.xml"
......@@ -47,10 +51,12 @@ android_library("java") {
"org/chromium/weblayer/UnsupportedVersionException.java",
"org/chromium/weblayer/WebLayer.java",
"org/chromium/weblayer/WebLayerFileProvider.java",
_version_constants_java_file,
]
deps = [
":client_resources",
":client_version",
":weblayer_client_manifest",
"//third_party/android_deps:androidx_annotation_annotation_java",
"//third_party/android_deps:com_android_support_support_compat_java",
......@@ -87,3 +93,13 @@ dist_aar("client_aar") {
android_manifest = weblayer_client_manifest
output = "$root_build_dir/WebLayerClient.aar"
}
process_version("client_version") {
process_only = true
template_file =
"org/chromium/weblayer/WebLayerClientVersionConstants.java.version"
output = _version_constants_java_file
sources = [
"//chrome/VERSION",
]
}
......@@ -7,12 +7,13 @@ package org.chromium.weblayer;
/**
* Error thrown if client and implementation versions are not compatible.
*/
public class UnsupportedVersionException extends Exception {
public class UnsupportedVersionException extends RuntimeException {
/**
* Constructs a new exception with the specified version.
*/
public UnsupportedVersionException(int clientVersion) {
super("Unsupported WebLayer version, client version " + clientVersion
+ " is not supported by the implementation.");
public UnsupportedVersionException(String implementationVersion) {
super("Unsupported WebLayer version, client version "
+ WebLayerClientVersionConstants.PRODUCT_VERSION
+ " is not supported by implementation version " + implementationVersion);
}
}
// Copyright 2019 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.weblayer;
final class WebLayerClientVersionConstants {
public static final String PRODUCT_VERSION = "@MAJOR@.@MINOR@.@BUILD@.@PATCH@";
public static final int PRODUCT_MAJOR_VERSION = @MAJOR@;
}
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