From c721c5c3b140542a11fe1002329f676a2bf72d56 Mon Sep 17 00:00:00 2001 From: Yury Semikhatsky Date: Fri, 18 Mar 2022 08:37:51 -0700 Subject: [PATCH] browser(webkit): set input file paths (#12868) --- browser_patches/webkit/BUILD_NUMBER | 4 +- browser_patches/webkit/patches/bootstrap.diff | 62 ++++++++++++------- 2 files changed, 41 insertions(+), 25 deletions(-) diff --git a/browser_patches/webkit/BUILD_NUMBER b/browser_patches/webkit/BUILD_NUMBER index 950a842bf6..f52292bf33 100644 --- a/browser_patches/webkit/BUILD_NUMBER +++ b/browser_patches/webkit/BUILD_NUMBER @@ -1,2 +1,2 @@ -1618 -Changed: dpino@igalia.com Thu Mar 17 23:36:05 HKT 2022 +1619 +Changed: yurys@chromium.org Fri 18 Mar 2022 08:33:43 AM PDT diff --git a/browser_patches/webkit/patches/bootstrap.diff b/browser_patches/webkit/patches/bootstrap.diff index 09a08249ae..2828a59848 100644 --- a/browser_patches/webkit/patches/bootstrap.diff +++ b/browser_patches/webkit/patches/bootstrap.diff @@ -502,7 +502,7 @@ index e81573fd0fffaaf6fd2af36635c78fcdf8608c69..4169e227b5fb5a3a7fb51396c4679100 // FrontendChannel FrontendChannel::ConnectionType connectionType() const; diff --git a/Source/JavaScriptCore/inspector/protocol/DOM.json b/Source/JavaScriptCore/inspector/protocol/DOM.json -index b8447e3420fd09df651a6f1e9131473b07bc38ab..36def64e91c93729e13781d137e65d3fb3203faa 100644 +index b8447e3420fd09df651a6f1e9131473b07bc38ab..717101483796e3cb019f76c5f0560238766b5e33 100644 --- a/Source/JavaScriptCore/inspector/protocol/DOM.json +++ b/Source/JavaScriptCore/inspector/protocol/DOM.json @@ -80,6 +80,16 @@ @@ -550,7 +550,7 @@ index b8447e3420fd09df651a6f1e9131473b07bc38ab..36def64e91c93729e13781d137e65d3f { "name": "objectGroup", "type": "string", "optional": true, "description": "Symbolic group name that can be used to release multiple objects." } ], "returns": [ -@@ -626,6 +648,45 @@ +@@ -626,6 +648,46 @@ "parameters": [ { "name": "allow", "type": "boolean" } ] @@ -591,7 +591,8 @@ index b8447e3420fd09df651a6f1e9131473b07bc38ab..36def64e91c93729e13781d137e65d3f + "description": "Sets input files for given ", + "parameters": [ + { "name": "objectId", "$ref": "Runtime.RemoteObjectId", "description": "Input element handle." }, -+ { "name": "files", "type": "array", "items": { "$ref": "FilePayload" }, "description": "Files to set" } ++ { "name": "files", "type": "array", "items": { "$ref": "FilePayload" }, "optional": true, "description": "Files to set" }, ++ { "name": "paths", "type": "array", "items": { "type": "string" }, "optional": true, "description": "File paths to set" } + ] } ], @@ -3314,7 +3315,7 @@ index 51badf49a6ce08975d655efa01cca9cd877e8f6b..ea4240cf72670cedfbd8b38d4d013676 { return context ? instrumentingAgents(*context) : nullptr; diff --git a/Source/WebCore/inspector/agents/InspectorDOMAgent.cpp b/Source/WebCore/inspector/agents/InspectorDOMAgent.cpp -index 0e186bcea701c6631985df40bc9a9b1e8784f0af..69a5fe6821b1fe7cfc502bbc93059df9f74b7463 100644 +index 0e186bcea701c6631985df40bc9a9b1e8784f0af..5e4b051b882433075148723e6a1258d18c559b73 100644 --- a/Source/WebCore/inspector/agents/InspectorDOMAgent.cpp +++ b/Source/WebCore/inspector/agents/InspectorDOMAgent.cpp @@ -62,12 +62,16 @@ @@ -3579,11 +3580,11 @@ index 0e186bcea701c6631985df40bc9a9b1e8784f0af..69a5fe6821b1fe7cfc502bbc93059df9 } Node* InspectorDOMAgent::scriptValueAsNode(JSC::JSValue value) -@@ -2984,4 +3123,42 @@ Protocol::ErrorStringOr InspectorDOMAgent::setAllowEditingUserAgentShadowT +@@ -2984,4 +3123,57 @@ Protocol::ErrorStringOr InspectorDOMAgent::setAllowEditingUserAgentShadowT return { }; } -+Protocol::ErrorStringOr InspectorDOMAgent::setInputFiles(const String& objectId, Ref&& files) { ++Protocol::ErrorStringOr InspectorDOMAgent::setInputFiles(const String& objectId, RefPtr&& files, RefPtr&& paths) { + InjectedScript injectedScript = m_injectedScriptManager.injectedScriptForObjectId(objectId); + if (injectedScript.hasNoValue()) + return makeUnexpected("Can not find element's context for given id"_s); @@ -3595,26 +3596,41 @@ index 0e186bcea701c6631985df40bc9a9b1e8784f0af..69a5fe6821b1fe7cfc502bbc93059df9 + if (node->nodeType() != Node::ELEMENT_NODE || node->nodeName() != "INPUT") + return makeUnexpected("Not an input node"_s); + ++ if (!(bool(files) ^ bool(paths))) ++ return makeUnexpected("Exactly one of files and paths should be specified"_s); ++ + HTMLInputElement* element = static_cast(node); + Vector> fileObjects; -+ for (unsigned i = 0; i < files->length(); ++i) { -+ RefPtr item = files->get(i); -+ RefPtr obj = item->asObject(); -+ if (!obj) -+ return makeUnexpected("Invalid file payload format"_s); ++ if (files) { ++ for (unsigned i = 0; i < files->length(); ++i) { ++ RefPtr item = files->get(i); ++ RefPtr obj = item->asObject(); ++ if (!obj) ++ return makeUnexpected("Invalid file payload format"_s); + -+ String name; -+ String type; -+ String data; -+ if (!obj->getString("name", name) || !obj->getString("type", type) || !obj->getString("data", data)) -+ return makeUnexpected("Invalid file payload format"_s); ++ String name; ++ String type; ++ String data; ++ if (!obj->getString("name", name) || !obj->getString("type", type) || !obj->getString("data", data)) ++ return makeUnexpected("Invalid file payload format"_s); + -+ std::optional> buffer = base64Decode(data); -+ if (!buffer) -+ return makeUnexpected("Unable to decode given content"_s); ++ std::optional> buffer = base64Decode(data); ++ if (!buffer) ++ return makeUnexpected("Unable to decode given content"_s); + -+ ScriptExecutionContext* context = element->scriptExecutionContext(); -+ fileObjects.append(File::create(context, Blob::create(context, WTFMove(*buffer), type), name)); ++ ScriptExecutionContext* context = element->scriptExecutionContext(); ++ fileObjects.append(File::create(context, Blob::create(context, WTFMove(*buffer), type), name)); ++ } ++ } else { ++ for (unsigned i = 0; i < paths->length(); ++i) { ++ RefPtr item = paths->get(i); ++ String path = item->asString(); ++ if (path.isEmpty()) ++ return makeUnexpected("Invalid file path"_s); ++ ++ ScriptExecutionContext* context = element->scriptExecutionContext(); ++ fileObjects.append(File::create(context, path)); ++ } + } + RefPtr fileList = FileList::create(WTFMove(fileObjects)); + element->setFiles(WTFMove(fileList)); @@ -3623,7 +3639,7 @@ index 0e186bcea701c6631985df40bc9a9b1e8784f0af..69a5fe6821b1fe7cfc502bbc93059df9 + } // namespace WebCore diff --git a/Source/WebCore/inspector/agents/InspectorDOMAgent.h b/Source/WebCore/inspector/agents/InspectorDOMAgent.h -index 2d073147ff54937b4ea0ce3f8ea3af61ad9761c4..e1f6eaf09510e6b1876fd1173d62b387675e147e 100644 +index 2d073147ff54937b4ea0ce3f8ea3af61ad9761c4..373ea5f0205a7bb7ec2cac6c1aca8e663226f2e3 100644 --- a/Source/WebCore/inspector/agents/InspectorDOMAgent.h +++ b/Source/WebCore/inspector/agents/InspectorDOMAgent.h @@ -57,6 +57,7 @@ namespace WebCore { @@ -3658,7 +3674,7 @@ index 2d073147ff54937b4ea0ce3f8ea3af61ad9761c4..e1f6eaf09510e6b1876fd1173d62b387 + Inspector::Protocol::ErrorStringOr> describeNode(const String& objectId); + Inspector::Protocol::ErrorStringOr scrollIntoViewIfNeeded(const String& objectId, RefPtr&& rect); + Inspector::Protocol::ErrorStringOr>> getContentQuads(const String& objectId); -+ Inspector::Protocol::ErrorStringOr setInputFiles(const String& objectId, Ref&& files); ++ Inspector::Protocol::ErrorStringOr setInputFiles(const String& objectId, RefPtr&& files, RefPtr&& paths); // InspectorInstrumentation Inspector::Protocol::DOM::NodeId identifierForNode(Node&);