Commit 3d6d790e authored by Cathy Li's avatar Cathy Li Committed by Commit Bot

Reland "[xsurface]: Update SurfaceAdapter to SurfaceRenderer and spec"

This is a reland of 21245a70

TBR=twellington@chromium.org

Original change's description:
> [xsurface]: Update SurfaceAdapter to SurfaceRenderer and spec
>
> Change-Id: Ib77234174ece4facb35596808fd964a18db04311
> Bug: 1054944
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2048409
> Commit-Queue: Cathy Li <chili@chromium.org>
> Reviewed-by: Justin DeWitt <dewittj@chromium.org>
> Reviewed-by: Theresa  <twellington@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#744352}

Bug: 1054944
Change-Id: I5f6c81e1740e418307c3365bd13969769d99472a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2078794
Commit-Queue: Cathy Li <chili@chromium.org>
Reviewed-by: default avatarCathy Li <chili@chromium.org>
Reviewed-by: default avatarSky Malice <skym@chromium.org>
Reviewed-by: default avatarJustin DeWitt <dewittj@chromium.org>
Cr-Commit-Position: refs/heads/master@{#745237}
parent 4904d511
......@@ -53,7 +53,8 @@ import org.chromium.chrome.browser.ui.ImmersiveModeManager;
import org.chromium.chrome.browser.usage_stats.DigitalWellbeingClient;
import org.chromium.chrome.browser.webapps.GooglePlayWebApkInstallDelegate;
import org.chromium.chrome.browser.webauth.Fido2ApiHandler;
import org.chromium.chrome.browser.xsurface.SurfaceAdapterFactory;
import org.chromium.chrome.browser.xsurface.SurfaceDependencyProvider;
import org.chromium.chrome.browser.xsurface.SurfaceRenderer;
import org.chromium.components.browser_ui.widget.FeatureHighlightProvider;
import org.chromium.components.download.DownloadCollectionBridge;
import org.chromium.components.signin.AccountManagerDelegate;
......@@ -380,10 +381,11 @@ public abstract class AppHooks {
}
/**
* Returns a new {@link SurfaceAdapterFactory} if the xsurface implementation is included in the
* Returns a new {@link SurfaceRenderer} if the xsurface implementation is included in the
* apk. Otherwise null is returned.
*/
public @Nullable SurfaceAdapterFactory createExternalSurfaceAdapterFactory() {
public @Nullable SurfaceRenderer createExternalSurfaceRenderer(
SurfaceDependencyProvider dependencies) {
return null;
}
}
......@@ -6,7 +6,13 @@ import("//build/config/android/rules.gni")
android_library("java") {
sources = [
"android/java/src/org/chromium/chrome/browser/xsurface/SurfaceAdapter.java",
"android/java/src/org/chromium/chrome/browser/xsurface/SurfaceAdapterFactory.java",
"android/java/src/org/chromium/chrome/browser/xsurface/HybridListRenderer.java",
"android/java/src/org/chromium/chrome/browser/xsurface/ListContentManager.java",
"android/java/src/org/chromium/chrome/browser/xsurface/ListContentManagerObserver.java",
"android/java/src/org/chromium/chrome/browser/xsurface/SurfaceActionsHandler.java",
"android/java/src/org/chromium/chrome/browser/xsurface/SurfaceDependencyProvider.java",
"android/java/src/org/chromium/chrome/browser/xsurface/SurfaceRenderer.java",
]
deps =
[ "//third_party/android_deps:androidx_recyclerview_recyclerview_java" ]
}
// 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.xsurface;
import androidx.recyclerview.widget.RecyclerView;
/**
* A renderer that can handle mixing externally-provided views with native Android views
* in a RecyclerView.
*/
public interface HybridListRenderer {
/** Binds a RecyclerView and contentmanager with this renderer. */
void bind(RecyclerView view, ListContentManager manager);
/**
* Unbinds a previously attached recyclerview and contentmanager.
*
* Does nothing if nothing was previously bound.
*/
void unbind();
}
// 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.xsurface;
import android.view.View;
import android.view.ViewGroup;
import java.util.Map;
/**
* Interface to provide native views to incorporate in an external surface-controlled
* RecyclerView.
*
* Models after a RecyclerView.Adapter.
*/
public interface ListContentManager {
/** Returns whether the item at index is a native view or not. */
boolean isNativeView(int index);
/** Gets the bytes needed to render an external view. */
byte[] getExternalViewBytes(int index);
/** Returns map of values which should go in the context of an external view. */
Map<String, Object> getContextValues(int index);
/**
* Returns the inflated native view.
*
* View should not be attached to parent. {@link bindNativeView} will
* be called later to attach more information to the view.
*/
View getNativeView(int index, ViewGroup parent);
/**
* Binds the data at the specified location.
*/
void bindNativeView(int index, View v);
/** Returns number of items to show. */
int getItemCount();
/** Adds an observer to be notified when the list content changes. */
void addObserver(ListContentManagerObserver o);
/** Removes the observer so it's no longer notified of content changes. */
void removeObserver(ListContentManagerObserver o);
}
// 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.xsurface;
/** Interface to observe a list. */
public interface ListContentManagerObserver {
/** Called when range from startIndex to startIndex+count has been inserted. */
default void onItemRangeInserted(int startIndex, int count) {}
/** Called when range from startIndex to startIndex+count has been removed. */
default void onItemRangeRemoved(int startIndex, int count) {}
/** Called when range from startIndex to startIndex+count has been changed/updated. */
default void onItemRangeChanged(int startIndex, int count) {}
/** Called when item at curIndex has been moved to newIndex. */
default void onItemMoved(int curIndex, int newIndex) {}
}
......@@ -4,21 +4,19 @@
package org.chromium.chrome.browser.xsurface;
import android.view.View;
/**
* Creates, owns, and manages an exposed view. Can be rebound to a given implementation specific
* payload.
* Interface to provide chromium calling points for an external surface.
*/
public interface SurfaceAdapter {
public interface SurfaceActionsHandler {
String KEY = "GeneralActions";
/**
* Rebinds the associated view to the given payload.
* @param protoPayload The payload that should describe what the view should do.
* Navigates the current tab to a particular URL.
*/
void bind(byte[] protoPayload);
void navigateTab(String url);
/**
* Returns the single associated view.
* Navigates a new tab to a particular URL.
*/
View getView();
void navigateNewTab(String url);
}
......@@ -7,13 +7,15 @@ package org.chromium.chrome.browser.xsurface;
import android.content.Context;
/**
* Creates SurfaceAdapters on demand.
* Provides logging and context for an external surface.
*/
public interface SurfaceAdapterFactory {
/**
* Creates a new adapter backed by a shared set of dependencies with other adapters.
* @param context The context that any new Android UI objects should be created within.
* @return A new wrapper capable of making view objects.
*/
SurfaceAdapter createSurfaceAdapter(Context context);
public interface SurfaceDependencyProvider {
/** @return the context associated with the application. */
Context getContext();
/** @see {Log.e} */
void logError(String tag, String messageTemplate, Object... args);
/** @see {Log.w} */
void logWarning(String tag, String messageTemplate, Object... args);
}
// 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.xsurface;
import android.view.View;
import java.util.Map;
/**
* Interface to call a rendering service to render a View sent by a server.
*/
public interface SurfaceRenderer {
/** Update the card renderer with shared data bytes. */
void update(byte[] data);
/**
* Turns a stream of externally-provided bytes into an Android View.
*
* @param renderData externally-provided bytes to be rendered.
* @param contextValues additional context to be incorporated into the view.
*/
View render(byte[] renderData, Map<String, Object> contextValues);
}
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