Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Do not expose inner WebContents on scripting/getAllFrames.
Inner WebContents shouldn't be exposed for executeScript or getAllFrames APIs. This is consistent with the API before crrev.com/f894f106 and crrev.com/c8de3b0a. BUG=1301320,1261261 (cherry picked from commit 5c4e043) Change-Id: I86a5b09aa44c48319b7dd0a10e5442b8c803d4e5 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3497565 Reviewed-by: Devlin Cronin <rdevlin.cronin@chromium.org> Reviewed-by: Kevin McNee <mcnee@chromium.org> Commit-Queue: Dave Tapuska <dtapuska@chromium.org> Cr-Original-Commit-Position: refs/heads/main@{#977769} Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3507493 Auto-Submit: Dave Tapuska <dtapuska@chromium.org> Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com> Owners-Override: Prudhvikumar Bommana <pbommana@google.com> Cr-Commit-Position: refs/branch-heads/4896@{#382} Cr-Branched-From: 1f63ff4-refs/heads/main@{#972766}
- Loading branch information
Showing
5 changed files
with
91 additions
and
17 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
8 changes: 8 additions & 0 deletions
8
chrome/test/data/extensions/api_test/scripting/nested_web_contents/manifest.json
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,8 @@ | ||
{ | ||
"name": "Scripting API Test", | ||
"manifest_version": 3, | ||
"version": "0.1", | ||
"permissions": ["scripting", "tabs", "webNavigation"], | ||
"background": {"service_worker": "worker.js"}, | ||
"host_permissions": ["http://a.com/*", "http://b.com/*"] | ||
} |
41 changes: 41 additions & 0 deletions
41
chrome/test/data/extensions/api_test/scripting/nested_web_contents/worker.js
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. | ||
|
||
function injectedFunction() { | ||
return location.pathname; | ||
} | ||
|
||
// Returns the single tab matching the given `query`. | ||
async function getSingleTab(query) { | ||
const tabs = await chrome.tabs.query(query); | ||
chrome.test.assertEq(1, tabs.length); | ||
return tabs[0]; | ||
} | ||
|
||
chrome.test.runTests([ | ||
async function nestedWebContents() { | ||
const query = {url: 'http://a.com/*'}; | ||
let tab = await getSingleTab(query); | ||
// There should be exactly 2 frames. | ||
let frames = await chrome.webNavigation.getAllFrames({tabId: tab.id}); | ||
chrome.test.assertEq(2, frames.length); | ||
|
||
// There should be exactly 2 results from executeScript. | ||
let results = await chrome.scripting.executeScript({ | ||
target: { | ||
tabId: tab.id, | ||
allFrames: true, | ||
}, | ||
func: injectedFunction, | ||
}); | ||
|
||
// We see two frames here, the main frame and one for the embed. We should | ||
// *not* see the third "embed within the embed" created by the PDF | ||
// reader. | ||
chrome.test.assertEq(2, results.length); | ||
chrome.test.assertEq('/page_with_embedded_pdf.html', results[0].result); | ||
chrome.test.assertEq('/pdf/test.pdf', results[1].result); | ||
chrome.test.succeed(); | ||
}, | ||
]); |
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