Commit 02dbf55c authored by Jian Li's avatar Jian Li Committed by Commit Bot

Initial implementation of FeedActionHandler

Bug: 1044139
Change-Id: I477580eeaad92239b624fbe78dc3c8d8fc005d4e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2130870Reviewed-by: default avatarDan H <harringtond@chromium.org>
Commit-Queue: Jian Li <jianli@chromium.org>
Cr-Commit-Position: refs/heads/master@{#755171}
parent bc70ea1c
// 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.feed.v2;
/**
* Interface to handle the actions user can trigger on the feed.
*/
public interface FeedActionHandler {
String KEY = "FeedActions";
/**
* Navigates the current tab to a particular URL.
*/
void navigate(String url);
/**
* Navigates a new tab to a particular URL.
*/
void navigateInNewTab(String url);
/**
* Requests additional content to be loaded. Once the load is completed, onStreamUpdated will be
* called.
*/
void loadMore();
/**
* Requests to dismiss a card. A change ID will be returned and it can be used to commit or
* discard the change.
*/
int requestDismissal();
/**
* Commits a previous requested dismissal denoted by change ID.
*/
void commitDismissal(int changeId);
/**
* Discards a previous requested dismissal denoted by change ID.
*/
void discardDismissal(int changeId);
}
......@@ -7,8 +7,15 @@ package org.chromium.chrome.browser.feed.v2;
import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace;
import org.chromium.base.annotations.NativeMethods;
import org.chromium.chrome.browser.ChromeActivity;
import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.tab.TabLaunchType;
import org.chromium.chrome.browser.tabmodel.TabModelSelector;
import org.chromium.components.feed.proto.FeedUiProto.StreamUpdate;
import org.chromium.content_public.browser.LoadUrlParams;
import org.chromium.ui.base.PageTransition;
import java.util.ArrayList;
import java.util.List;
/**
......@@ -17,15 +24,17 @@ import java.util.List;
* Created once for each StreamSurfaceMediator corresponding to each NTP/start surface.
*/
@JNINamespace("feed")
public class FeedStreamSurface {
public class FeedStreamSurface implements FeedActionHandler {
private final long mNativeFeedStreamSurface;
private final ChromeActivity mActivity;
/**
* Creates a {@link FeedStreamSurface} for creating native side bridge to access native feed
* client implementation.
*/
public FeedStreamSurface() {
public FeedStreamSurface(ChromeActivity activity) {
mNativeFeedStreamSurface = FeedStreamSurfaceJni.get().init(FeedStreamSurface.this);
mActivity = activity;
}
/**
......@@ -40,56 +49,59 @@ public class FeedStreamSurface {
}
}
/**
* Informs that a particular URL is being navigated to.
*/
public void navigationDone(String url, boolean inNewTab) {
FeedStreamSurfaceJni.get().navigationDone(
mNativeFeedStreamSurface, FeedStreamSurface.this, url, inNewTab);
@Override
public void navigate(String url) {
LoadUrlParams loadUrlParams = new LoadUrlParams(url);
loadUrlParams.setTransitionType(PageTransition.AUTO_BOOKMARK);
mActivity.getActivityTabProvider().get().loadUrl(loadUrlParams);
FeedStreamSurfaceJni.get().navigationStarted(
mNativeFeedStreamSurface, FeedStreamSurface.this, url, false /*inNewTab*/);
}
/**
* Requests additional content to be loaded. Once the load is completed, onStreamUpdated will be
* called.
*/
public void loadMore() {
FeedStreamSurfaceJni.get().loadMore(mNativeFeedStreamSurface, FeedStreamSurface.this);
@Override
public void navigateInNewTab(String url) {
TabModelSelector tabModelSelector = mActivity.getTabModelSelector();
Tab tab = mActivity.getActivityTabProvider().get();
tabModelSelector.openNewTab(
new LoadUrlParams(url), TabLaunchType.FROM_CHROME_UI, tab, tab.isIncognito());
FeedStreamSurfaceJni.get().navigationStarted(
mNativeFeedStreamSurface, FeedStreamSurface.this, url, true /*inNewTab*/);
}
/**
* Handles uploading data for ThereAndBackAgain.
*/
public void processThereAndBackAgain(byte[] data) {
FeedStreamSurfaceJni.get().processThereAndBackAgain(
mNativeFeedStreamSurface, FeedStreamSurface.this, data);
@Override
public void loadMore() {
FeedStreamSurfaceJni.get().loadMore(mNativeFeedStreamSurface, FeedStreamSurface.this);
}
/**
* Executes an ephemeral change, i.e. dismissals, that is described by a list of data operations
* serialized as bytes. A change ID will be returned and it can be used to commit or discard the
* change. If the change ID is 0, it means failure.
*/
public int executeEphemeralChange(List<byte[]> serializedDataOperations) {
@Override
public int requestDismissal() {
// TODO(jianli): may need to pass parameters from UI.
List<byte[]> serializedDataOperations = new ArrayList<byte[]>();
// TODO(jianli): append data to serializedDataOperations.
return FeedStreamSurfaceJni.get().executeEphemeralChange(
mNativeFeedStreamSurface, FeedStreamSurface.this, serializedDataOperations);
}
/**
* Commits a previously executed ephemeral change.
*/
public void commitEphemeralChange(int changeId) {
@Override
public void commitDismissal(int changeId) {
FeedStreamSurfaceJni.get().commitEphemeralChange(
mNativeFeedStreamSurface, FeedStreamSurface.this, changeId);
}
/**
* Discards a previously executed ephemeral change.
*/
public void discardEphemeralChange(int changeId) {
@Override
public void discardDismissal(int changeId) {
FeedStreamSurfaceJni.get().discardEphemeralChange(
mNativeFeedStreamSurface, FeedStreamSurface.this, changeId);
}
/**
* Handles uploading data for ThereAndBackAgain.
*/
public void processThereAndBackAgain(byte[] data) {
FeedStreamSurfaceJni.get().processThereAndBackAgain(
mNativeFeedStreamSurface, FeedStreamSurface.this, data);
}
/**
* Informs that the surface is opened. We can request the initial set of content now. Once
* the content is available, onStreamUpdated will be called.
......@@ -108,6 +120,8 @@ public class FeedStreamSurface {
@NativeMethods
interface Natives {
long init(FeedStreamSurface caller);
void navigationStarted(long nativeFeedStreamSurface, FeedStreamSurface caller, String url,
boolean inNewTab);
void navigationDone(long nativeFeedStreamSurface, FeedStreamSurface caller, String url,
boolean inNewTab);
void loadMore(long nativeFeedStreamSurface, FeedStreamSurface caller);
......
......@@ -378,6 +378,7 @@ if (enable_feed_in_chrome) {
"//chrome/android/feed/core/java/src/org/chromium/chrome/browser/feed/tooltip/BasicTooltipApi.java",
"//chrome/android/feed/core/java/src/org/chromium/chrome/browser/feed/tooltip/BasicTooltipSupportedApi.java",
"//chrome/android/feed/core/java/src/org/chromium/chrome/browser/feed/tooltip/FeedTooltipUtils.java",
"//chrome/android/feed/core/java/src/org/chromium/chrome/browser/feed/v2/FeedActionHandler.java",
"//chrome/android/feed/core/java/src/org/chromium/chrome/browser/feed/v2/FeedServiceBridge.java",
"//chrome/android/feed/core/java/src/org/chromium/chrome/browser/feed/v2/FeedStreamSurface.java",
]
......
......@@ -39,6 +39,11 @@ void FeedStreamSurface::OnStreamUpdated(
Java_FeedStreamSurface_onStreamUpdated(env, java_ref_, j_data);
}
void FeedStreamSurface::NavigationStarted(JNIEnv* env,
const JavaParamRef<jobject>& obj,
const JavaParamRef<jstring>& url,
jboolean in_new_tab) {}
void FeedStreamSurface::NavigationDone(JNIEnv* env,
const JavaParamRef<jobject>& obj,
const JavaParamRef<jstring>& url,
......
......@@ -24,6 +24,11 @@ class FeedStreamSurface {
void OnStreamUpdated(const feedui::StreamUpdate& stream_update);
void NavigationStarted(JNIEnv* env,
const base::android::JavaParamRef<jobject>& caller,
const base::android::JavaParamRef<jstring>& url,
jboolean in_new_tab);
void NavigationDone(JNIEnv* env,
const base::android::JavaParamRef<jobject>& caller,
const base::android::JavaParamRef<jstring>& url,
......
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