Commit 9d561ffc authored by Raymes Khoury's avatar Raymes Khoury Committed by Commit Bot

Ensure a permission prompt is shown for voice search on the old NTP

The old NTP should show a permission prompt when the first voice search
happens. However when permission delegation was enabled it caused the
wrong origin to be used for the request: chrome://newtab instead of the
search origin (e.g. google.com). This CL fixes the origin so that the
search origin is again used for the request.

This bug does not impact the new NTP.

Bug: 881742
Change-Id: Ic70c39d2adb2efafbea3f5c8b89d462c9f01352c
Reviewed-on: https://chromium-review.googlesource.com/1214976Reviewed-by: default avatarTimothy Loh <timloh@chromium.org>
Commit-Queue: Raymes Khoury <raymes@chromium.org>
Cr-Commit-Position: refs/heads/master@{#589852}
parent 137522b4
......@@ -34,6 +34,7 @@
#include "chrome/common/buildflags.h"
#include "chrome/common/chrome_features.h"
#include "chrome/common/url_constants.h"
#include "chrome/common/webui_url_constants.h"
#include "components/content_settings/core/browser/host_content_settings_map.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/permission_controller.h"
......@@ -323,10 +324,15 @@ void PermissionManager::Shutdown() {
GURL PermissionManager::GetCanonicalOrigin(const GURL& requesting_origin,
const GURL& embedding_origin) const {
if (requesting_origin.GetOrigin() ==
GURL(chrome::kChromeSearchLocalNtpUrl).GetOrigin()) {
return GURL(UIThreadSearchTermsData(profile_).GoogleBaseURLValue())
.GetOrigin();
if (embedding_origin.GetOrigin() ==
GURL(chrome::kChromeUINewTabURL).GetOrigin()) {
if (requesting_origin.GetOrigin() ==
GURL(chrome::kChromeSearchLocalNtpUrl).GetOrigin()) {
return GURL(UIThreadSearchTermsData(profile_).GoogleBaseURLValue())
.GetOrigin();
} else {
return requesting_origin;
}
}
if (base::FeatureList::IsEnabled(features::kPermissionDelegation)) {
......
......@@ -18,6 +18,7 @@
#include "chrome/browser/vr/vr_tab_helper.h"
#include "chrome/common/chrome_features.h"
#include "chrome/common/url_constants.h"
#include "chrome/common/webui_url_constants.h"
#include "chrome/test/base/chrome_render_view_host_test_harness.h"
#include "chrome/test/base/testing_profile.h"
#include "components/content_settings/core/browser/host_content_settings_map.h"
......@@ -612,6 +613,7 @@ TEST_F(PermissionManagerTest, GetCanonicalOriginSearch) {
const GURL remote_ntp = GURL(std::string("chrome-search://") +
chrome::kChromeSearchRemoteNtpHost);
const GURL other_chrome_search = GURL("chrome-search://not-local-ntp");
const GURL top_level_ntp(chrome::kChromeUINewTabURL);
// "Normal" URLs are not affected by GetCanonicalOrigin.
EXPECT_EQ(google_com, GetPermissionControllerDelegate()->GetCanonicalOrigin(
......@@ -625,14 +627,16 @@ TEST_F(PermissionManagerTest, GetCanonicalOriginSearch) {
// The local NTP URL gets mapped to the Google base URL.
EXPECT_EQ(google_base, GetPermissionControllerDelegate()->GetCanonicalOrigin(
local_ntp, local_ntp));
local_ntp, top_level_ntp));
// However, other chrome-search:// URLs, including the remote NTP URL, are
// not affected.
EXPECT_EQ(remote_ntp, GetPermissionControllerDelegate()->GetCanonicalOrigin(
remote_ntp, remote_ntp));
remote_ntp, top_level_ntp));
EXPECT_EQ(google_com, GetPermissionControllerDelegate()->GetCanonicalOrigin(
google_com, top_level_ntp));
EXPECT_EQ(other_chrome_search,
GetPermissionControllerDelegate()->GetCanonicalOrigin(
other_chrome_search, other_chrome_search));
other_chrome_search, top_level_ntp));
}
TEST_F(PermissionManagerTest, GetCanonicalOriginPermissionDelegation) {
......@@ -838,4 +842,4 @@ TEST_F(PermissionManagerTest, SubscribeWithPermissionDelegation) {
GetPermissionControllerDelegate()->UnsubscribePermissionStatusChange(
subscription_id);
}
\ No newline at end of file
}
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