Commit 62c286d1 authored by Andrey Kosyakov's avatar Andrey Kosyakov Committed by Commit Bot

Do not execute global commands on non-root targets

Bug: 1116444
Change-Id: Ic50dfc144f8024870131e7586b9dce2dff591e42
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2419712Reviewed-by: default avatarDmitry Gozman <dgozman@chromium.org>
Commit-Queue: Andrey Kosyakov <caseq@chromium.org>
Cr-Commit-Position: refs/heads/master@{#808635}
parent c50e3d40
...@@ -78,6 +78,8 @@ constexpr int kDefaultScreenshotQuality = 80; ...@@ -78,6 +78,8 @@ constexpr int kDefaultScreenshotQuality = 80;
constexpr int kFrameRetryDelayMs = 100; constexpr int kFrameRetryDelayMs = 100;
constexpr int kCaptureRetryLimit = 2; constexpr int kCaptureRetryLimit = 2;
constexpr int kMaxScreencastFramesInFlight = 2; constexpr int kMaxScreencastFramesInFlight = 2;
constexpr char kCommandIsOnlyAvailableAtTopTarget[] =
"Command can only be executed on top-level targets";
Binary EncodeImage(const gfx::Image& image, Binary EncodeImage(const gfx::Image& image,
const std::string& format, const std::string& format,
...@@ -168,6 +170,17 @@ void GetMetadataFromFrame(const media::VideoFrame& frame, ...@@ -168,6 +170,17 @@ void GetMetadataFromFrame(const media::VideoFrame& frame,
*top_controls_visible_height = *frame.metadata()->top_controls_visible_height; *top_controls_visible_height = *frame.metadata()->top_controls_visible_height;
} }
template <typename ProtocolCallback>
bool CanExecuteGlobalCommands(
RenderFrameHost* host,
const std::unique_ptr<ProtocolCallback>& callback) {
if (!host || !host->GetParent())
return true;
callback->sendFailure(
Response::ServerError(kCommandIsOnlyAvailableAtTopTarget));
return false;
}
} // namespace } // namespace
PageHandler::PageHandler(EmulationHandler* emulation_handler, PageHandler::PageHandler(EmulationHandler* emulation_handler,
...@@ -653,6 +666,8 @@ Response PageHandler::ResetNavigationHistory() { ...@@ -653,6 +666,8 @@ Response PageHandler::ResetNavigationHistory() {
void PageHandler::CaptureSnapshot( void PageHandler::CaptureSnapshot(
Maybe<std::string> format, Maybe<std::string> format,
std::unique_ptr<CaptureSnapshotCallback> callback) { std::unique_ptr<CaptureSnapshotCallback> callback) {
if (!CanExecuteGlobalCommands(host_, callback))
return;
std::string snapshot_format = format.fromMaybe(kMhtml); std::string snapshot_format = format.fromMaybe(kMhtml);
if (snapshot_format != kMhtml) { if (snapshot_format != kMhtml) {
callback->sendFailure(Response::ServerError("Unsupported snapshot format")); callback->sendFailure(Response::ServerError("Unsupported snapshot format"));
...@@ -672,6 +687,8 @@ void PageHandler::CaptureScreenshot( ...@@ -672,6 +687,8 @@ void PageHandler::CaptureScreenshot(
callback->sendFailure(Response::InternalError()); callback->sendFailure(Response::InternalError());
return; return;
} }
if (!CanExecuteGlobalCommands(host_, callback))
return;
if (clip.isJust()) { if (clip.isJust()) {
if (clip.fromJust()->GetWidth() == 0) { if (clip.fromJust()->GetWidth() == 0) {
callback->sendFailure( callback->sendFailure(
...@@ -928,6 +945,8 @@ Response PageHandler::SetDownloadBehavior(const std::string& behavior, ...@@ -928,6 +945,8 @@ Response PageHandler::SetDownloadBehavior(const std::string& behavior,
host_ ? host_->GetProcess()->GetBrowserContext() : nullptr; host_ ? host_->GetProcess()->GetBrowserContext() : nullptr;
if (!browser_context) if (!browser_context)
return Response::ServerError("Could not fetch browser context"); return Response::ServerError("Could not fetch browser context");
if (host_ && host_->GetParent())
return Response::ServerError(kCommandIsOnlyAvailableAtTopTarget);
return browser_handler_->DoSetDownloadBehavior(behavior, browser_context, return browser_handler_->DoSetDownloadBehavior(behavior, browser_context,
std::move(download_path)); std::move(download_path));
} }
...@@ -938,6 +957,8 @@ void PageHandler::GetAppManifest( ...@@ -938,6 +957,8 @@ void PageHandler::GetAppManifest(
callback->sendFailure(Response::ServerError("Cannot retrieve manifest")); callback->sendFailure(Response::ServerError("Cannot retrieve manifest"));
return; return;
} }
if (!CanExecuteGlobalCommands(host_, callback))
return;
ManifestManagerHost::GetOrCreateForCurrentDocument(host_->GetMainFrame()) ManifestManagerHost::GetOrCreateForCurrentDocument(host_->GetMainFrame())
->RequestManifestDebugInfo(base::BindOnce(&PageHandler::GotManifest, ->RequestManifestDebugInfo(base::BindOnce(&PageHandler::GotManifest,
weak_factory_.GetWeakPtr(), weak_factory_.GetWeakPtr(),
......
Tests for certain commands are only available at the top-level target
Page.captureSnapshot: Command can only be executed on top-level targets
Page.captureScreenshot: Command can only be executed on top-level targets
Page.startScreencast: Internal error
Page.setDownloadBehavior: Command can only be executed on top-level targets
(async function(testRunner) {
const {session, dp} = await testRunner.startBlank('Tests for certain commands are only available at the top-level target');
await dp.Page.enable();
await dp.Target.setAutoAttach({autoAttach: true, waitForDebuggerOnStart: true, flatten: true});
dp.Page.navigate({url: testRunner.url('./resources/site_per_process_main.html')});
const {params} = await dp.Target.onceAttachedToTarget();
const childSession = session.createChild(params.sessionId);
const dp2 = childSession.protocol;
dp2.Page.enable();
async function checkCommand(method, params) {
const result = await childSession.sendCommand(method, params);
testRunner.log(`${method}: ` + (result.error ? result.error.message : 'FAIL: no error'));
}
await checkCommand('Page.captureSnapshot', {});
await checkCommand('Page.captureScreenshot', {});
await checkCommand('Page.startScreencast', {});
await checkCommand('Page.setDownloadBehavior', { behavior: 'deny'});
testRunner.completeTest();
})
\ 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