Commit 1b36f1a7 authored by John Abd-El-Malek's avatar John Abd-El-Malek Committed by Commit Bot

Add autoplay parameter to navigations.

Bug: 1131881
Change-Id: Ia152dc0a76d1f9ad6eff87f74fef2ad17b327b91
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2432755Reviewed-by: default avatarScott Violet <sky@chromium.org>
Commit-Queue: John Abd-El-Malek <jam@chromium.org>
Cr-Commit-Position: refs/heads/master@{#810932}
parent 0f290a02
......@@ -36,16 +36,18 @@ public final class NavigationControllerImpl extends INavigationController.Stub {
if (WebLayerFactoryImpl.getClientMajorVersion() < 83) {
assert params == null;
}
navigate2(uri, params == null ? false : params.mShouldReplaceCurrentEntry, false, false);
navigate2(uri, params == null ? false : params.mShouldReplaceCurrentEntry, false, false,
false);
}
@Override
public void navigate2(String uri, boolean shouldReplaceCurrentEntry,
boolean disableIntentProcessing, boolean disableNetworkErrorAutoReload)
throws RemoteException {
boolean disableIntentProcessing, boolean disableNetworkErrorAutoReload,
boolean enableAutoPlay) throws RemoteException {
StrictModeWorkaround.apply();
NavigationControllerImplJni.get().navigate(mNativeNavigationController, uri,
shouldReplaceCurrentEntry, disableIntentProcessing, disableNetworkErrorAutoReload);
shouldReplaceCurrentEntry, disableIntentProcessing, disableNetworkErrorAutoReload,
enableAutoPlay);
}
@Override
......@@ -183,7 +185,7 @@ public final class NavigationControllerImpl extends INavigationController.Stub {
long getNavigationController(long tab);
void navigate(long nativeNavigationControllerImpl, String uri,
boolean shouldReplaceCurrentEntry, boolean disableIntentProcessing,
boolean disableNetworkErrorAutoReload);
boolean disableNetworkErrorAutoReload, boolean enableAutoPlay);
void goBack(long nativeNavigationControllerImpl);
void goForward(long nativeNavigationControllerImpl);
boolean canGoBack(long nativeNavigationControllerImpl);
......
......@@ -41,5 +41,6 @@ interface INavigationController {
void navigate2(in String uri,
in boolean shouldReplaceEntry,
in boolean disableIntentProcessing,
in boolean disableNetworkErrorAutoReload) = 14;
in boolean disableNetworkErrorAutoReload,
in boolean enableAutoPlay) = 14;
}
......@@ -9,18 +9,21 @@
#include "base/test/bind_test_util.h"
#include "components/variations/net/variations_http_headers.h"
#include "components/variations/variations_ids_provider.h"
#include "content/public/browser/web_contents_observer.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/url_loader_interceptor.h"
#include "net/dns/mock_host_resolver.h"
#include "net/test/embedded_test_server/controllable_http_response.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "net/test/embedded_test_server/http_response.h"
#include "weblayer/browser/tab_impl.h"
#include "weblayer/public/browser.h"
#include "weblayer/public/navigation.h"
#include "weblayer/public/navigation_controller.h"
#include "weblayer/public/navigation_observer.h"
#include "weblayer/public/tab.h"
#include "weblayer/shell/browser/shell.h"
#include "weblayer/test/interstitial_utils.h"
#include "weblayer/test/test_navigation_observer.h"
#include "weblayer/test/weblayer_browser_test_utils.h"
namespace weblayer {
......@@ -588,6 +591,63 @@ IN_PROC_BROWSER_TEST_F(NavigationBrowserTest,
EXPECT_EQ(custom_ua, new_ua);
}
IN_PROC_BROWSER_TEST_F(NavigationBrowserTest, AutoPlayDefault) {
ASSERT_TRUE(embedded_test_server()->Start());
GURL url(embedded_test_server()->GetURL("/autoplay.html"));
auto* tab = static_cast<TabImpl*>(shell()->tab());
NavigateAndWaitForCompletion(url, tab);
auto* web_contents = tab->web_contents();
bool playing = false;
// There's no notification to watch that would signal video wasn't autoplayed,
// so instead check once through javascript.
EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
web_contents,
"window.domAutomationController.send(!document.getElementById('vid')."
"paused)",
&playing));
ASSERT_FALSE(playing);
}
namespace {
class WaitForMediaPlaying : public content::WebContentsObserver {
public:
explicit WaitForMediaPlaying(content::WebContents* web_contents)
: WebContentsObserver(web_contents) {}
// WebContentsObserver override.
void MediaStartedPlaying(const MediaPlayerInfo& info,
const content::MediaPlayerId&) final {
run_loop_.Quit();
CHECK(info.has_audio);
CHECK(info.has_video);
}
void Wait() { run_loop_.Run(); }
private:
base::RunLoop run_loop_;
DISALLOW_COPY_AND_ASSIGN(WaitForMediaPlaying);
};
} // namespace
IN_PROC_BROWSER_TEST_F(NavigationBrowserTest, AutoPlayEnabled) {
ASSERT_TRUE(embedded_test_server()->Start());
GURL url(embedded_test_server()->GetURL("/autoplay.html"));
NavigationController::NavigateParams params;
params.enable_auto_play = true;
GetNavigationController()->Navigate(url, params);
auto* tab = static_cast<TabImpl*>(shell()->tab());
WaitForMediaPlaying wait_for_media(tab->web_contents());
wait_for_media.Wait();
}
class NavigationBrowserTest2 : public NavigationBrowserTest {
public:
void SetUp() override {
......
......@@ -153,7 +153,8 @@ void NavigationControllerImpl::Navigate(
const JavaParamRef<jstring>& url,
jboolean should_replace_current_entry,
jboolean disable_intent_processing,
jboolean disable_network_error_auto_reload) {
jboolean disable_network_error_auto_reload,
jboolean enable_auto_play) {
auto params = std::make_unique<content::NavigationController::LoadURLParams>(
GURL(base::android::ConvertJavaStringToUTF8(env, url)));
params->should_replace_current_entry = should_replace_current_entry;
......@@ -166,6 +167,8 @@ void NavigationControllerImpl::Navigate(
: ui::PAGE_TRANSITION_LINK;
if (disable_network_error_auto_reload)
params->navigation_ui_data = std::make_unique<NavigationUIDataImpl>(true);
if (enable_auto_play)
params->was_activated = content::mojom::WasActivatedOption::kYes;
DoNavigate(std::move(params));
}
......@@ -238,6 +241,9 @@ void NavigationControllerImpl::Navigate(
load_params->navigation_ui_data =
std::make_unique<NavigationUIDataImpl>(true);
}
if (params.enable_auto_play)
load_params->was_activated = content::mojom::WasActivatedOption::kYes;
DoNavigate(std::move(load_params));
}
......
......@@ -53,7 +53,8 @@ class NavigationControllerImpl : public NavigationController,
const base::android::JavaParamRef<jstring>& url,
jboolean should_replace_current_entry,
jboolean disable_intent_processing,
jboolean disable_network_error_auto_reload);
jboolean disable_network_error_auto_reload,
jboolean enable_auto_play);
void GoBack(JNIEnv* env) { GoBack(); }
void GoForward(JNIEnv* env) { GoForward(); }
bool CanGoBack(JNIEnv* env) { return CanGoBack(); }
......
......@@ -16,6 +16,7 @@ public class NavigateParams {
new org.chromium.weblayer_private.interfaces.NavigateParams();
private boolean mIntentProcessingDisabled;
private boolean mNetworkErrorAutoReloadDisabled;
private boolean mAutoPlayEnabled;
/**
* A Builder class to help create NavigateParams.
......@@ -82,6 +83,21 @@ public class NavigateParams {
mParams.mNetworkErrorAutoReloadDisabled = true;
return this;
}
/**
* Enable auto-play for videos in this navigation. Auto-play is disabled by default.
*
* @since 86
*/
@NonNull
public Builder enableAutoPlay() {
if (WebLayer.shouldPerformVersionChecks()
&& WebLayer.getSupportedMajorVersionInternal() < 86) {
throw new UnsupportedOperationException();
}
mParams.mAutoPlayEnabled = true;
return this;
}
}
org.chromium.weblayer_private.interfaces.NavigateParams toInterfaceParams() {
......@@ -126,4 +142,19 @@ public class NavigateParams {
}
return mNetworkErrorAutoReloadDisabled;
}
/**
* Returns true if auto play for videos is enabled.
*
* @return Whether auto play for videos is enabled.
*
* @since 86
*/
public boolean isAutoPlayEnabled() {
if (WebLayer.shouldPerformVersionChecks()
&& WebLayer.getSupportedMajorVersionInternal() < 86) {
throw new UnsupportedOperationException();
}
return mAutoPlayEnabled;
}
}
......@@ -63,7 +63,8 @@ public class NavigationController {
mNavigationController.navigate2(uri.toString(),
params == null ? false : params.getShouldReplaceCurrentEntry(),
params == null ? false : params.isIntentProcessingDisabled(),
params == null ? false : params.isNetworkErrorAutoReloadDisabled());
params == null ? false : params.isNetworkErrorAutoReloadDisabled(),
params == null ? false : params.isAutoPlayEnabled());
}
} catch (RemoteException e) {
throw new APICallException(e);
......
......@@ -20,6 +20,7 @@ class NavigationController {
struct NavigateParams {
bool should_replace_current_entry = false;
bool disable_network_error_auto_reload = false;
bool enable_auto_play = false;
};
virtual ~NavigationController() = default;
......
<html>
<body>
<video id="vid" controls autoplay>
<source src="bear.mp4" type="video/mp4">
</video>
</body>
</html>
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