Commit bcbbe28c authored by Shakti Sahu's avatar Shakti Sahu Committed by Commit Bot

Video Tutorials : Allowed autoplay for video player URL

Bug: 1132709
Change-Id: I51b0823e590b158a97061894ed0b8bc9bbb7d143
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2434554
Commit-Queue: Shakti Sahu <shaktisahu@chromium.org>
Reviewed-by: default avatarDavid Trainor <dtrainor@chromium.org>
Cr-Commit-Position: refs/heads/master@{#811975}
parent fd23cebd
...@@ -384,6 +384,7 @@ static_library("ui") { ...@@ -384,6 +384,7 @@ static_library("ui") {
"//chrome/browser/ui/webui/read_later:mojo_bindings", "//chrome/browser/ui/webui/read_later:mojo_bindings",
"//chrome/browser/ui/webui/tab_search:mojo_bindings", "//chrome/browser/ui/webui/tab_search:mojo_bindings",
"//chrome/browser/ui/webui/usb_internals:mojo_bindings", "//chrome/browser/ui/webui/usb_internals:mojo_bindings",
"//chrome/browser/video_tutorials",
"//chrome/common", "//chrome/common",
"//chrome/common/net", "//chrome/common/net",
"//chrome/common/search:mojo_bindings", "//chrome/common/search:mojo_bindings",
......
...@@ -123,6 +123,7 @@ ...@@ -123,6 +123,7 @@
#include "chrome/browser/flags/android/chrome_feature_list.h" #include "chrome/browser/flags/android/chrome_feature_list.h"
#include "chrome/browser/ui/android/context_menu_helper.h" #include "chrome/browser/ui/android/context_menu_helper.h"
#include "chrome/browser/ui/javascript_dialogs/javascript_tab_modal_dialog_manager_delegate_android.h" #include "chrome/browser/ui/javascript_dialogs/javascript_tab_modal_dialog_manager_delegate_android.h"
#include "chrome/browser/video_tutorials/video_tutorial_tab_helper.h"
#else #else
#include "chrome/browser/banners/app_banner_manager_desktop.h" #include "chrome/browser/banners/app_banner_manager_desktop.h"
#include "chrome/browser/safe_browsing/safe_browsing_tab_observer.h" #include "chrome/browser/safe_browsing/safe_browsing_tab_observer.h"
...@@ -356,6 +357,7 @@ void TabHelpers::AttachTabHelpers(WebContents* web_contents) { ...@@ -356,6 +357,7 @@ void TabHelpers::AttachTabHelpers(WebContents* web_contents) {
web_contents); web_contents);
} }
SearchGeolocationDisclosureTabHelper::CreateForWebContents(web_contents); SearchGeolocationDisclosureTabHelper::CreateForWebContents(web_contents);
video_tutorials::VideoTutorialTabHelper::CreateForWebContents(web_contents);
#else #else
banners::AppBannerManagerDesktop::CreateForWebContents(web_contents); banners::AppBannerManagerDesktop::CreateForWebContents(web_contents);
BookmarkTabHelper::CreateForWebContents(web_contents); BookmarkTabHelper::CreateForWebContents(web_contents);
......
...@@ -26,9 +26,14 @@ source_set("public") { ...@@ -26,9 +26,14 @@ source_set("public") {
"tutorial.cc", "tutorial.cc",
"tutorial.h", "tutorial.h",
"video_tutorial_service.h", "video_tutorial_service.h",
"video_tutorial_tab_helper.cc",
"video_tutorial_tab_helper.h",
] ]
deps = [] deps = [
"//chrome/common",
"//content/public/browser",
]
public_deps = [ public_deps = [
"//base", "//base",
......
// 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.
#include "chrome/browser/video_tutorials/video_tutorial_tab_helper.h"
#include "build/build_config.h"
#include "content/public/browser/navigation_handle.h"
#include "third_party/blink/public/common/associated_interfaces/associated_interface_provider.h"
#include "third_party/blink/public/mojom/autoplay/autoplay.mojom.h"
namespace video_tutorials {
namespace {
// Returns whether the URL of the navigation matches the video player URL.
bool IsVideoPlayerURL(GURL url) {
#if defined(OS_ANDROID)
std::string url_string = url.possibly_invalid_spec();
if (url_string.find(chrome::kChromeUIUntrustedVideoPlayerUrl) == 0)
return true;
#endif
return false;
}
} // namespace
VideoTutorialTabHelper::VideoTutorialTabHelper(
content::WebContents* web_contents)
: content::WebContentsObserver(web_contents) {}
VideoTutorialTabHelper::~VideoTutorialTabHelper() = default;
void VideoTutorialTabHelper::ReadyToCommitNavigation(
content::NavigationHandle* handle) {
std::string url = handle->GetURL().possibly_invalid_spec();
if (!IsVideoPlayerURL(handle->GetURL()))
return;
mojo::AssociatedRemote<blink::mojom::AutoplayConfigurationClient> client;
handle->GetRenderFrameHost()->GetRemoteAssociatedInterfaces()->GetInterface(
&client);
client->AddAutoplayFlags(url::Origin::Create(handle->GetURL()),
blink::mojom::kAutoplayFlagUserException);
}
WEB_CONTENTS_USER_DATA_KEY_IMPL(VideoTutorialTabHelper)
} // namespace video_tutorials
// 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.
#ifndef CHROME_BROWSER_VIDEO_TUTORIALS_VIDEO_TUTORIAL_TAB_HELPER_H_
#define CHROME_BROWSER_VIDEO_TUTORIALS_VIDEO_TUTORIAL_TAB_HELPER_H_
#include "chrome/common/webui_url_constants.h"
#include "content/public/browser/web_contents_observer.h"
#include "content/public/browser/web_contents_user_data.h"
namespace video_tutorials {
class VideoTutorialTabHelper
: public content::WebContentsObserver,
public content::WebContentsUserData<VideoTutorialTabHelper> {
public:
~VideoTutorialTabHelper() override;
VideoTutorialTabHelper(const VideoTutorialTabHelper&) = delete;
VideoTutorialTabHelper& operator=(const VideoTutorialTabHelper&) = delete;
// content::WebContentsObserver overrides.
void ReadyToCommitNavigation(content::NavigationHandle* handle) override;
private:
friend class content::WebContentsUserData<VideoTutorialTabHelper>;
explicit VideoTutorialTabHelper(content::WebContents* web_contents);
WEB_CONTENTS_USER_DATA_KEY_DECL();
};
} // namespace video_tutorials
#endif // CHROME_BROWSER_VIDEO_TUTORIALS_VIDEO_TUTORIAL_TAB_HELPER_H_
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