Commit 8d72e7d4 authored by Becca Hughes's avatar Becca Hughes Committed by Chromium LUCI CQ

Add chrome://watch as an alias of chrome://kaleidoscope

This will be the user facing URL for Kaleidoscope when it
launches. We create an alias so existing users will not
be affected by this change.

Change-Id: I82a80c37374757a0e51b42a39f3bc918b35edf8b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2575389
Commit-Queue: Becca Hughes <beccahughes@chromium.org>
Reviewed-by: default avatarTommy Steimel <steimel@chromium.org>
Reviewed-by: default avatarEsmael Elmoslimany <aee@chromium.org>
Cr-Commit-Position: refs/heads/master@{#834514}
parent dd204543
...@@ -6,8 +6,12 @@ ...@@ -6,8 +6,12 @@
const char kKaleidoscopeUIHost[] = "kaleidoscope"; const char kKaleidoscopeUIHost[] = "kaleidoscope";
const char kKaleidoscopeUIWatchHost[] = "watch";
const char kKaleidoscopeUIURL[] = "chrome://kaleidoscope"; const char kKaleidoscopeUIURL[] = "chrome://kaleidoscope";
const char kKaleidoscopeWatchUIURL[] = "chrome://watch";
const char kKaleidoscopeUntrustedContentUIURL[] = const char kKaleidoscopeUntrustedContentUIURL[] =
"chrome-untrusted://kaleidoscope/"; "chrome-untrusted://kaleidoscope/";
......
...@@ -7,8 +7,12 @@ ...@@ -7,8 +7,12 @@
extern const char kKaleidoscopeUIHost[]; extern const char kKaleidoscopeUIHost[];
extern const char kKaleidoscopeUIWatchHost[];
extern const char kKaleidoscopeUIURL[]; extern const char kKaleidoscopeUIURL[];
extern const char kKaleidoscopeWatchUIURL[];
extern const char kKaleidoscopeUntrustedContentUIURL[]; extern const char kKaleidoscopeUntrustedContentUIURL[];
extern const char kKaleidoscopeUntrustedPALChildURL[]; extern const char kKaleidoscopeUntrustedPALChildURL[];
......
...@@ -207,7 +207,7 @@ void KaleidoscopeDataProviderImpl::GetContinueWatchingMediaFeedItems( ...@@ -207,7 +207,7 @@ void KaleidoscopeDataProviderImpl::GetContinueWatchingMediaFeedItems(
} }
void KaleidoscopeDataProviderImpl::SendFeedback() { void KaleidoscopeDataProviderImpl::SendFeedback() {
chrome::ShowFeedbackPage(GURL(kKaleidoscopeUIURL), profile_, chrome::ShowFeedbackPage(GURL(kKaleidoscopeWatchUIURL), profile_,
chrome::kFeedbackSourceKaleidoscope, chrome::kFeedbackSourceKaleidoscope,
std::string() /* description_template */, std::string() /* description_template */,
std::string() /* description_placeholder_text */, std::string() /* description_placeholder_text */,
......
...@@ -21,6 +21,12 @@ const url::Origin& KaleidoscopeOrigin() { ...@@ -21,6 +21,12 @@ const url::Origin& KaleidoscopeOrigin() {
return *origin; return *origin;
} }
const url::Origin& WatchOrigin() {
static base::NoDestructor<url::Origin> origin(
url::Origin::Create(GURL(kKaleidoscopeWatchUIURL)));
return *origin;
}
const url::Origin& KaleidoscopeUntrustedOrigin() { const url::Origin& KaleidoscopeUntrustedOrigin() {
static base::NoDestructor<url::Origin> origin( static base::NoDestructor<url::Origin> origin(
url::Origin::Create(GURL(kKaleidoscopeUntrustedContentUIURL))); url::Origin::Create(GURL(kKaleidoscopeUntrustedContentUIURL)));
...@@ -44,7 +50,8 @@ bool ShouldAllowAutoplay(content::NavigationHandle* handle) { ...@@ -44,7 +50,8 @@ bool ShouldAllowAutoplay(content::NavigationHandle* handle) {
// If the tab is Kaleidoscope then we should allow autoplay. // If the tab is Kaleidoscope then we should allow autoplay.
auto parent_origin = auto parent_origin =
url::Origin::Create(handle->GetWebContents()->GetLastCommittedURL()); url::Origin::Create(handle->GetWebContents()->GetLastCommittedURL());
if (parent_origin.IsSameOriginWith(KaleidoscopeOrigin())) { if (parent_origin.IsSameOriginWith(KaleidoscopeOrigin()) ||
parent_origin.IsSameOriginWith(WatchOrigin())) {
return true; return true;
} }
...@@ -91,13 +98,18 @@ void KaleidoscopeTabHelper::ReadyToCommitNavigation( ...@@ -91,13 +98,18 @@ void KaleidoscopeTabHelper::ReadyToCommitNavigation(
!new_origin.IsSameOriginWith(KaleidoscopeOrigin()) && !new_origin.IsSameOriginWith(KaleidoscopeOrigin()) &&
handle->IsInMainFrame()) { handle->IsInMainFrame()) {
OnKaleidoscopeSessionEnded(); OnKaleidoscopeSessionEnded();
} else if (current_origin.IsSameOriginWith(WatchOrigin()) &&
!new_origin.IsSameOriginWith(WatchOrigin()) &&
handle->IsInMainFrame()) {
OnKaleidoscopeSessionEnded();
} }
} }
void KaleidoscopeTabHelper::WebContentsDestroyed() { void KaleidoscopeTabHelper::WebContentsDestroyed() {
auto current_origin = auto current_origin =
url::Origin::Create(web_contents()->GetLastCommittedURL()); url::Origin::Create(web_contents()->GetLastCommittedURL());
if (current_origin.IsSameOriginWith(KaleidoscopeOrigin())) { if (current_origin.IsSameOriginWith(KaleidoscopeOrigin()) ||
current_origin.IsSameOriginWith(WatchOrigin())) {
OnKaleidoscopeSessionEnded(); OnKaleidoscopeSessionEnded();
} }
} }
......
...@@ -145,6 +145,32 @@ IN_PROC_BROWSER_TEST_F(KaleidoscopeTabHelperBrowserTest, ...@@ -145,6 +145,32 @@ IN_PROC_BROWSER_TEST_F(KaleidoscopeTabHelperBrowserTest,
true, 1); true, 1);
} }
IN_PROC_BROWSER_TEST_F(KaleidoscopeTabHelperBrowserTest,
SessionMetric_OpenedRecommendation_Watch) {
const GURL kTestPageUrl = embedded_test_server()->GetURL(kTestPagePath);
{
// Navigate to Kaleidoscope.
NavigateParams params(browser(), GURL(kKaleidoscopeWatchUIURL),
ui::PAGE_TRANSITION_LINK);
ui_test_utils::NavigateToURL(&params);
}
// Simulate a playback.
KaleidoscopeTabHelper::FromWebContents(GetWebContents())->MarkAsSuccessful();
{
// Navigate away from Kaleidoscope.
NavigateParams params(browser(), kTestPageUrl, ui::PAGE_TRANSITION_LINK);
ui_test_utils::NavigateToURL(&params);
}
histogram_tester_.ExpectBucketCount(
KaleidoscopeTabHelper::
kKaleidoscopeOpenedMediaRecommendationHistogramName,
true, 1);
}
IN_PROC_BROWSER_TEST_F(KaleidoscopeTabHelperBrowserTest, IN_PROC_BROWSER_TEST_F(KaleidoscopeTabHelperBrowserTest,
SessionMetric_DidNotOpenRecommendation) { SessionMetric_DidNotOpenRecommendation) {
const GURL kTestPageUrl = embedded_test_server()->GetURL(kTestPagePath); const GURL kTestPageUrl = embedded_test_server()->GetURL(kTestPagePath);
......
...@@ -204,58 +204,7 @@ void OnStringsRequest(const std::string& path, ...@@ -204,58 +204,7 @@ void OnStringsRequest(const std::string& path,
std::move(callback).Run(ref_contents); std::move(callback).Run(ref_contents);
} }
content::WebUIDataSource* CreateUntrustedPALChildWebUIDataSource() { void ConfigureMainFrameWebUIDataSource(content::WebUIDataSource* html_source) {
content::WebUIDataSource* untrusted_source =
content::WebUIDataSource::Create(kKaleidoscopeUntrustedPALChildURL);
untrusted_source->DisableDenyXFrameOptions();
// Allow scripts from Google.
untrusted_source->OverrideContentSecurityPolicy(
network::mojom::CSPDirectiveName::ScriptSrc,
"script-src https://imasdk.googleapis.com 'unsafe-inline' 'self';");
untrusted_source->DisableTrustedTypesCSP();
#if BUILDFLAG(ENABLE_KALEIDOSCOPE)
untrusted_source->AddResourcePath("pal-child.html",
IDR_KALEIDOSCOPE_PAL_CHILD_HTML);
untrusted_source->AddResourcePath("pal-child.js",
IDR_KALEIDOSCOPE_PAL_CHILD_JS);
#endif // BUILDFLAG(ENABLE_KALEIDOSCOPE)
return untrusted_source;
}
} // anonymous namespace
// We set |enable_chrome_send| to true since we need it for browser tests.
KaleidoscopeUI::KaleidoscopeUI(content::WebUI* web_ui)
: ui::MojoWebUIController(web_ui, /*enable_chrome_send=*/true) {
web_ui->AddRequestableScheme(content::kChromeUIUntrustedScheme);
auto* browser_context = web_ui->GetWebContents()->GetBrowserContext();
content::WebUIDataSource::Add(browser_context, CreateWebUIDataSource());
content::WebUIDataSource::Add(browser_context,
CreateUntrustedWebUIDataSource());
content::WebUIDataSource::Add(browser_context,
CreateUntrustedPALChildWebUIDataSource());
}
KaleidoscopeUI::~KaleidoscopeUI() {
if (metrics_recorder_)
metrics_recorder_->OnExitPage();
// Ensure that the provider is deleted before the metrics recorder, since the
// provider has a pointer to the metrics recorder.
provider_.reset();
metrics_recorder_.reset();
identity_manager_.reset();
}
// static
content::WebUIDataSource* KaleidoscopeUI::CreateWebUIDataSource() {
content::WebUIDataSource* html_source =
content::WebUIDataSource::Create(kKaleidoscopeUIHost);
// Allows us to put content in an IFrame. // Allows us to put content in an IFrame.
html_source->OverrideContentSecurityPolicy( html_source->OverrideContentSecurityPolicy(
network::mojom::CSPDirectiveName::ChildSrc, network::mojom::CSPDirectiveName::ChildSrc,
...@@ -307,7 +256,68 @@ content::WebUIDataSource* KaleidoscopeUI::CreateWebUIDataSource() { ...@@ -307,7 +256,68 @@ content::WebUIDataSource* KaleidoscopeUI::CreateWebUIDataSource() {
#endif // BUILDFLAG(ENABLE_KALEIDOSCOPE) #endif // BUILDFLAG(ENABLE_KALEIDOSCOPE)
html_source->AddResourcePath("module.js", IDR_KALEIDOSCOPE_NTP_MODULE_JS); html_source->AddResourcePath("module.js", IDR_KALEIDOSCOPE_NTP_MODULE_JS);
}
content::WebUIDataSource* CreateUntrustedPALChildWebUIDataSource() {
content::WebUIDataSource* untrusted_source =
content::WebUIDataSource::Create(kKaleidoscopeUntrustedPALChildURL);
untrusted_source->DisableDenyXFrameOptions();
// Allow scripts from Google.
untrusted_source->OverrideContentSecurityPolicy(
network::mojom::CSPDirectiveName::ScriptSrc,
"script-src https://imasdk.googleapis.com 'unsafe-inline' 'self';");
untrusted_source->DisableTrustedTypesCSP();
#if BUILDFLAG(ENABLE_KALEIDOSCOPE)
untrusted_source->AddResourcePath("pal-child.html",
IDR_KALEIDOSCOPE_PAL_CHILD_HTML);
untrusted_source->AddResourcePath("pal-child.js",
IDR_KALEIDOSCOPE_PAL_CHILD_JS);
#endif // BUILDFLAG(ENABLE_KALEIDOSCOPE)
return untrusted_source;
}
} // anonymous namespace
// We set |enable_chrome_send| to true since we need it for browser tests.
KaleidoscopeUI::KaleidoscopeUI(content::WebUI* web_ui)
: ui::MojoWebUIController(web_ui, /*enable_chrome_send=*/true) {
web_ui->AddRequestableScheme(content::kChromeUIUntrustedScheme);
auto* browser_context = web_ui->GetWebContents()->GetBrowserContext();
content::WebUIDataSource::Add(browser_context, CreateWebUIDataSource());
content::WebUIDataSource::Add(browser_context, CreateWatchDataSource());
content::WebUIDataSource::Add(browser_context,
CreateUntrustedWebUIDataSource());
content::WebUIDataSource::Add(browser_context,
CreateUntrustedPALChildWebUIDataSource());
}
KaleidoscopeUI::~KaleidoscopeUI() {
if (metrics_recorder_)
metrics_recorder_->OnExitPage();
// Ensure that the provider is deleted before the metrics recorder, since the
// provider has a pointer to the metrics recorder.
provider_.reset();
metrics_recorder_.reset();
identity_manager_.reset();
}
// static
content::WebUIDataSource* KaleidoscopeUI::CreateWebUIDataSource() {
auto* html_source = content::WebUIDataSource::Create(kKaleidoscopeUIHost);
ConfigureMainFrameWebUIDataSource(html_source);
return html_source;
}
// static
content::WebUIDataSource* KaleidoscopeUI::CreateWatchDataSource() {
auto* html_source =
content::WebUIDataSource::Create(kKaleidoscopeUIWatchHost);
ConfigureMainFrameWebUIDataSource(html_source);
return html_source; return html_source;
} }
......
...@@ -30,6 +30,8 @@ class KaleidoscopeUI : public ui::MojoWebUIController { ...@@ -30,6 +30,8 @@ class KaleidoscopeUI : public ui::MojoWebUIController {
static content::WebUIDataSource* CreateWebUIDataSource(); static content::WebUIDataSource* CreateWebUIDataSource();
static content::WebUIDataSource* CreateWatchDataSource();
static content::WebUIDataSource* CreateUntrustedWebUIDataSource(); static content::WebUIDataSource* CreateUntrustedWebUIDataSource();
private: private:
......
...@@ -886,9 +886,11 @@ WebUIFactoryFunction GetWebUIFactoryFunction(WebUI* web_ui, ...@@ -886,9 +886,11 @@ WebUIFactoryFunction GetWebUIFactoryFunction(WebUI* web_ui,
#if !defined(OS_ANDROID) #if !defined(OS_ANDROID)
if (base::FeatureList::IsEnabled(media::kKaleidoscope)) { if (base::FeatureList::IsEnabled(media::kKaleidoscope)) {
if (url.host_piece() == kKaleidoscopeUIHost) if (url.host_piece() == kKaleidoscopeUIHost ||
url.host_piece() == kKaleidoscopeUIWatchHost) {
return &NewWebUI<KaleidoscopeUI>; return &NewWebUI<KaleidoscopeUI>;
} }
}
#endif // !defined(OS_ANDROID) #endif // !defined(OS_ANDROID)
#if BUILDFLAG(ENABLE_NACL) #if BUILDFLAG(ENABLE_NACL)
if (url.host_piece() == chrome::kChromeUINaClHost) if (url.host_piece() == chrome::kChromeUINaClHost)
......
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