Commit 24b721cd authored by Becca Hughes's avatar Becca Hughes Committed by Commit Bot

[Autoplay] Fix assistant activation bug

Adds a NewTabWithUserActivation method to open a new tab
with a user activation. This means that the page will
behave as if the user has interacted with it and autoplay
will always be allowed.

This CL also tweaks assistant to use it so that it can
open tabs without the autoplay restriction.

BUG=884777

Change-Id: I7c9327b438ac51003442f0e97bd6e63086fb48cd
Reviewed-on: https://chromium-review.googlesource.com/1239543Reviewed-by: default avatarKen Buchanan <kenrb@chromium.org>
Reviewed-by: default avatarJames Cook <jamescook@chromium.org>
Commit-Queue: Becca Hughes <beccahughes@chromium.org>
Cr-Commit-Position: refs/heads/master@{#595202}
parent 2bca53a6
......@@ -303,7 +303,10 @@ void AssistantController::OpenUrl(const GURL& url) {
return;
}
Shell::Get()->new_window_controller()->NewTabWithUrl(url);
// The new tab should be opened with a user activation since the user
// interacted with the assistant to open the url.
Shell::Get()->new_window_controller()->NewTabWithUrl(
url, true /* from_user_interaction */);
NotifyUrlOpened(url);
}
......
......@@ -69,7 +69,8 @@ void UrlHandlerServiceProvider::OpenUrl(
return;
}
ash::Shell::Get()->new_window_controller()->NewTabWithUrl(gurl);
ash::Shell::Get()->new_window_controller()->NewTabWithUrl(
gurl, false /* from_user_interaction */);
response_sender.Run(dbus::Response::FromMethodCall(method_call));
}
......
......@@ -29,9 +29,10 @@ void NewWindowController::ShowKeyboardOverlay() {
client_->ShowKeyboardOverlay();
}
void NewWindowController::NewTabWithUrl(const GURL& url) {
void NewWindowController::NewTabWithUrl(const GURL& url,
bool from_user_interaction) {
if (client_)
client_->NewTabWithUrl(url);
client_->NewTabWithUrl(url, from_user_interaction);
}
void NewWindowController::NewTab() {
......
......@@ -29,7 +29,7 @@ class ASH_EXPORT NewWindowController : public mojom::NewWindowController {
void ShowKeyboardOverlay() override;
// Pass throughs for methods of the same name on |client_|.
void NewTabWithUrl(const GURL& url);
void NewTabWithUrl(const GURL& url, bool from_user_interaction);
void NewTab();
void NewWindow(bool incognito);
void OpenFileManager();
......
......@@ -24,8 +24,10 @@ interface NewWindowClient {
// Invoked when the user uses Ctrl+T to open a new tab.
NewTab();
// Opens a new tab with the specified URL.
NewTabWithUrl(url.mojom.Url url);
// Opens a new tab with the specified URL. If the |from_user_interaction|
// is true then the page will load with a user activation. This means the
// page will be able to autoplay media without restriction.
NewTabWithUrl(url.mojom.Url url, bool from_user_interaction);
// Invoked when the user uses Ctrl-N or Ctrl-Shift-N to open a new window.
NewWindow(bool incognito);
......
......@@ -37,6 +37,7 @@
#include "components/url_formatter/url_fixer.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/service_manager_connection.h"
#include "content/public/common/was_activated_option.h"
#include "extensions/browser/extension_system.h"
#include "extensions/common/constants.h"
#include "services/service_manager/public/cpp/connector.h"
......@@ -151,8 +152,9 @@ void ChromeNewWindowClient::NewTab() {
browser->SetFocusToLocationBar(false);
}
void ChromeNewWindowClient::NewTabWithUrl(const GURL& url) {
OpenUrlImpl(url);
void ChromeNewWindowClient::NewTabWithUrl(const GURL& url,
bool from_user_interaction) {
OpenUrlImpl(url, from_user_interaction);
}
void ChromeNewWindowClient::NewWindow(bool is_incognito) {
......@@ -269,7 +271,8 @@ void ChromeNewWindowClient::OpenUrlFromArc(const GURL& url) {
url_to_open = arc::ArcUrlToExternalFileUrl(url_to_open);
}
content::WebContents* tab = OpenUrlImpl(url_to_open);
content::WebContents* tab =
OpenUrlImpl(url_to_open, false /* from_user_interaction */);
if (!tab)
return;
......@@ -278,7 +281,9 @@ void ChromeNewWindowClient::OpenUrlFromArc(const GURL& url) {
std::make_unique<arc::ArcWebContentsData>());
}
content::WebContents* ChromeNewWindowClient::OpenUrlImpl(const GURL& url) {
content::WebContents* ChromeNewWindowClient::OpenUrlImpl(
const GURL& url,
bool from_user_interaction) {
// If the url is for system settings, show the settings in a window instead of
// a browser tab.
if (url.GetContent() == "settings" &&
......@@ -293,6 +298,10 @@ content::WebContents* ChromeNewWindowClient::OpenUrlImpl(const GURL& url) {
ProfileManager::GetActiveUserProfile(), url,
ui::PageTransitionFromInt(ui::PAGE_TRANSITION_LINK |
ui::PAGE_TRANSITION_FROM_API));
if (from_user_interaction)
navigate_params.was_activated = content::WasActivatedOption::kYes;
Navigate(&navigate_params);
if (navigate_params.browser) {
......
......@@ -29,7 +29,7 @@ class ChromeNewWindowClient : public ash::mojom::NewWindowClient,
// Overridden from ash::mojom::NewWindowClient:
void NewTab() override;
void NewTabWithUrl(const GURL& url) override;
void NewTabWithUrl(const GURL& url, bool from_user_interaction) override;
void NewWindow(bool incognito) override;
void OpenFileManager() override;
void OpenCrosh() override;
......@@ -48,8 +48,11 @@ class ChromeNewWindowClient : public ash::mojom::NewWindowClient,
// Opens a URL in a new tab. Returns the WebContents for the tab that
// opened the URL. If the URL is for a chrome://settings page, opens settings
// in a new window and returns null.
content::WebContents* OpenUrlImpl(const GURL& url);
// in a new window and returns null. If the |from_user_interaction| is true
// then the page will load with a user activation. This means it will be able
// to autoplay media without restriction.
content::WebContents* OpenUrlImpl(const GURL& url,
bool from_user_interaction);
std::unique_ptr<TabRestoreHelper> tab_restore_helper_;
......
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