-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use the origin/name of the main frame in chooser dialogs
Permissions dialogs (for WebUSB, WebHID, and Web Serial) should request permission for the main origin (the origin embedding the iframe) and not the site hosting the iframe as per crbug.com/802945. Update the UI code to accurately display the main origin (or extension name) and add tests. Bug: 1280233 Change-Id: Ia3bf9274eb49c1d842e204a518635cc1187f3d3d Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3353956 Reviewed-by: Scott Violet <sky@chromium.org> Reviewed-by: Andy Paicu <andypaicu@chromium.org> Commit-Queue: Reilly Grant <reillyg@chromium.org> Cr-Commit-Position: refs/heads/main@{#963184}
- Loading branch information
Showing
8 changed files
with
130 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// Copyright 2022 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/chooser_controller/title_util.h" | ||
|
||
#include "chrome/grit/generated_resources.h" | ||
#include "chrome/test/base/chrome_render_view_host_test_harness.h" | ||
#include "components/strings/grit/components_strings.h" | ||
|
||
#if BUILDFLAG(ENABLE_EXTENSIONS) | ||
#include "chrome/browser/extensions/extension_service.h" | ||
#include "chrome/browser/extensions/test_extension_system.h" | ||
#include "content/public/test/navigation_simulator.h" | ||
#include "extensions/browser/extension_registry.h" | ||
#include "extensions/common/extension.h" | ||
#include "extensions/common/extension_builder.h" | ||
#include "extensions/common/value_builder.h" | ||
#include "url/gurl.h" | ||
#include "url/origin.h" | ||
#endif // BUILDFLAG(ENABLE_EXTENSIONS) | ||
|
||
namespace { | ||
|
||
constexpr int kNonExtensionTitleResourceId = | ||
IDS_USB_DEVICE_CHOOSER_PROMPT_ORIGIN; | ||
constexpr int kExtensionTitleResourceId = | ||
IDS_USB_DEVICE_CHOOSER_PROMPT_EXTENSION_NAME; | ||
|
||
using ExtensionsAwareChooserTitleTest = ChromeRenderViewHostTestHarness; | ||
|
||
TEST_F(ExtensionsAwareChooserTitleTest, NoFrame) { | ||
EXPECT_EQ(u"", CreateExtensionAwareChooserTitle(nullptr, | ||
kNonExtensionTitleResourceId, | ||
kExtensionTitleResourceId)); | ||
} | ||
|
||
#if BUILDFLAG(ENABLE_EXTENSIONS) | ||
TEST_F(ExtensionsAwareChooserTitleTest, FrameTree) { | ||
extensions::DictionaryBuilder manifest; | ||
manifest.Set("name", "Chooser Title Subframe Test") | ||
.Set("version", "0.1") | ||
.Set("manifest_version", 2) | ||
.Set("web_accessible_resources", | ||
extensions::ListBuilder().Append("index.html").Build()); | ||
scoped_refptr<const extensions::Extension> extension = | ||
extensions::ExtensionBuilder().SetManifest(manifest.Build()).Build(); | ||
ASSERT_TRUE(extension); | ||
|
||
extensions::TestExtensionSystem* extension_system = | ||
static_cast<extensions::TestExtensionSystem*>( | ||
extensions::ExtensionSystem::Get(profile())); | ||
extensions::ExtensionService* extension_service = | ||
extension_system->CreateExtensionService( | ||
base::CommandLine::ForCurrentProcess(), base::FilePath(), false); | ||
extension_service->AddExtension(extension.get()); | ||
|
||
NavigateAndCommit(extension->GetResourceURL("index.html")); | ||
content::RenderFrameHost* subframe = | ||
content::NavigationSimulator::NavigateAndCommitFromDocument( | ||
GURL("data:text/html,"), | ||
content::RenderFrameHostTester::For(main_rfh()) | ||
->AppendChild("subframe")); | ||
|
||
EXPECT_EQ(extension->id(), main_rfh()->GetLastCommittedOrigin().host()); | ||
EXPECT_EQ( | ||
u"\"Chooser Title Subframe Test\" wants to connect", | ||
CreateExtensionAwareChooserTitle(main_rfh(), kNonExtensionTitleResourceId, | ||
kExtensionTitleResourceId)); | ||
EXPECT_NE(extension->id(), subframe->GetLastCommittedOrigin().host()); | ||
EXPECT_EQ( | ||
u"\"Chooser Title Subframe Test\" wants to connect", | ||
CreateExtensionAwareChooserTitle(subframe, kNonExtensionTitleResourceId, | ||
kExtensionTitleResourceId)); | ||
} | ||
#endif // BUILDFLAG(ENABLE_EXTENSIONS) | ||
|
||
} // namespace |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Copyright 2022 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 "components/permissions/chooser_title_util.h" | ||
|
||
#include "components/strings/grit/components_strings.h" | ||
#include "content/public/test/navigation_simulator.h" | ||
#include "content/public/test/test_renderer_host.h" | ||
#include "url/gurl.h" | ||
#include "url/origin.h" | ||
|
||
namespace permissions { | ||
namespace { | ||
|
||
constexpr int kTitleResourceId = IDS_USB_DEVICE_CHOOSER_PROMPT_ORIGIN; | ||
|
||
using ChooserTitleTest = content::RenderViewHostTestHarness; | ||
|
||
TEST_F(ChooserTitleTest, NoFrame) { | ||
EXPECT_EQ(u"", CreateChooserTitle(nullptr, kTitleResourceId)); | ||
} | ||
|
||
TEST_F(ChooserTitleTest, FrameTree) { | ||
NavigateAndCommit(GURL("https://main-frame.com")); | ||
content::RenderFrameHost* subframe = | ||
content::NavigationSimulator::NavigateAndCommitFromDocument( | ||
GURL("https://sub-frame.com"), | ||
content::RenderFrameHostTester::For(main_rfh()) | ||
->AppendChild("subframe")); | ||
|
||
EXPECT_EQ("main-frame.com", main_rfh()->GetLastCommittedOrigin().host()); | ||
EXPECT_EQ(u"main-frame.com wants to connect", | ||
CreateChooserTitle(main_rfh(), kTitleResourceId)); | ||
EXPECT_EQ("sub-frame.com", subframe->GetLastCommittedOrigin().host()); | ||
EXPECT_EQ(u"main-frame.com wants to connect", | ||
CreateChooserTitle(subframe, kTitleResourceId)); | ||
} | ||
|
||
} // namespace | ||
} // namespace permissions |