Commit 8df8b249 authored by Gang Wu's avatar Gang Wu Committed by Commit Bot

Handle post data from start surface

Bug: 1085538
Change-Id: Iade4c1e85bb865d3dda9e6ab74107546df234de9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2213324
Commit-Queue: Gang Wu <gangwu@chromium.org>
Reviewed-by: default avatarTed Choc <tedchoc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#771355}
parent 9b4c78a3
...@@ -935,7 +935,9 @@ public class LocationBarLayout extends FrameLayout ...@@ -935,7 +935,9 @@ public class LocationBarLayout extends FrameLayout
// side is initialized // side is initialized
assert mNativeInitialized : "Loading URL before native side initialized"; assert mNativeInitialized : "Loading URL before native side initialized";
if (ReturnToChromeExperimentsUtil.willHandleLoadUrlFromStartSurface(url, transition)) { // TODO(crbug.com/1085812): Should be taking a fulll loaded LoadUrlParams.
if (ReturnToChromeExperimentsUtil.willHandleLoadUrlWithPostDataFromStartSurface(
url, transition, postDataType, postData)) {
return; return;
} }
......
...@@ -7,6 +7,7 @@ package org.chromium.chrome.browser.tasks; ...@@ -7,6 +7,7 @@ package org.chromium.chrome.browser.tasks;
import android.app.Activity; import android.app.Activity;
import android.text.TextUtils; import android.text.TextUtils;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting; import androidx.annotation.VisibleForTesting;
import org.chromium.base.ApplicationStatus; import org.chromium.base.ApplicationStatus;
...@@ -29,6 +30,7 @@ import org.chromium.chrome.browser.tasks.pseudotab.PseudoTab; ...@@ -29,6 +30,7 @@ import org.chromium.chrome.browser.tasks.pseudotab.PseudoTab;
import org.chromium.chrome.browser.util.AccessibilityUtil; import org.chromium.chrome.browser.util.AccessibilityUtil;
import org.chromium.chrome.features.start_surface.StartSurfaceConfiguration; import org.chromium.chrome.features.start_surface.StartSurfaceConfiguration;
import org.chromium.content_public.browser.LoadUrlParams; import org.chromium.content_public.browser.LoadUrlParams;
import org.chromium.content_public.common.ResourceRequestBody;
import org.chromium.ui.base.DeviceFormFactor; import org.chromium.ui.base.DeviceFormFactor;
import org.chromium.ui.base.PageTransition; import org.chromium.ui.base.PageTransition;
...@@ -142,6 +144,23 @@ public final class ReturnToChromeExperimentsUtil { ...@@ -142,6 +144,23 @@ public final class ReturnToChromeExperimentsUtil {
*/ */
public static boolean willHandleLoadUrlFromStartSurface( public static boolean willHandleLoadUrlFromStartSurface(
String url, @PageTransition int transition) { String url, @PageTransition int transition) {
return willHandleLoadUrlWithPostDataFromStartSurface(url, transition, null, null);
}
/**
* Check if we should handle the navigation. If so, create a new tab and load the URL with POST
* data.
*
* @param url The URL to load.
* @param transition The page transition type.
* @param postDataType postData type.
* @param postData POST data to include in the tab URL's request body, ex. bitmap when
* image search.
* @return true if we have handled the navigation, false otherwise.
*/
public static boolean willHandleLoadUrlWithPostDataFromStartSurface(String url,
@PageTransition int transition, @Nullable String postDataType,
@Nullable byte[] postData) {
ChromeActivity chromeActivity = getActivityPresentingOverviewWithOmnibox(); ChromeActivity chromeActivity = getActivityPresentingOverviewWithOmnibox();
if (chromeActivity == null) return false; if (chromeActivity == null) return false;
...@@ -149,6 +168,11 @@ public final class ReturnToChromeExperimentsUtil { ...@@ -149,6 +168,11 @@ public final class ReturnToChromeExperimentsUtil {
TabModel model = chromeActivity.getCurrentTabModel(); TabModel model = chromeActivity.getCurrentTabModel();
LoadUrlParams params = new LoadUrlParams(url); LoadUrlParams params = new LoadUrlParams(url);
params.setTransitionType(transition | PageTransition.FROM_ADDRESS_BAR); params.setTransitionType(transition | PageTransition.FROM_ADDRESS_BAR);
if (!TextUtils.isEmpty(postDataType) && postData != null && postData.length != 0) {
params.setVerbatimHeaders("Content-Type: " + postDataType);
params.setPostData(ResourceRequestBody.createFromBytes(postData));
}
chromeActivity.getTabCreator(model.isIncognito()) chromeActivity.getTabCreator(model.isIncognito())
.createNewTab(params, TabLaunchType.FROM_START_SURFACE, null); .createNewTab(params, TabLaunchType.FROM_START_SURFACE, null);
......
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