Skip to content

Commit c721c5c

Browse files
authored
browser(webkit): set input file paths (#12868)
1 parent f3ffd32 commit c721c5c

File tree

2 files changed

+44
-28
lines changed

2 files changed

+44
-28
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
1618
2-
Changed: dpino@igalia.com Thu Mar 17 23:36:05 HKT 2022
1+
1619
2+
Changed: yurys@chromium.org Fri 18 Mar 2022 08:33:43 AM PDT

browser_patches/webkit/patches/bootstrap.diff

Lines changed: 42 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ index e81573fd0fffaaf6fd2af36635c78fcdf8608c69..4169e227b5fb5a3a7fb51396c4679100
502502
// FrontendChannel
503503
FrontendChannel::ConnectionType connectionType() const;
504504
diff --git a/Source/JavaScriptCore/inspector/protocol/DOM.json b/Source/JavaScriptCore/inspector/protocol/DOM.json
505-
index b8447e3420fd09df651a6f1e9131473b07bc38ab..36def64e91c93729e13781d137e65d3fb3203faa 100644
505+
index b8447e3420fd09df651a6f1e9131473b07bc38ab..717101483796e3cb019f76c5f0560238766b5e33 100644
506506
--- a/Source/JavaScriptCore/inspector/protocol/DOM.json
507507
+++ b/Source/JavaScriptCore/inspector/protocol/DOM.json
508508
@@ -80,6 +80,16 @@
@@ -550,7 +550,7 @@ index b8447e3420fd09df651a6f1e9131473b07bc38ab..36def64e91c93729e13781d137e65d3f
550550
{ "name": "objectGroup", "type": "string", "optional": true, "description": "Symbolic group name that can be used to release multiple objects." }
551551
],
552552
"returns": [
553-
@@ -626,6 +648,45 @@
553+
@@ -626,6 +648,46 @@
554554
"parameters": [
555555
{ "name": "allow", "type": "boolean" }
556556
]
@@ -591,7 +591,8 @@ index b8447e3420fd09df651a6f1e9131473b07bc38ab..36def64e91c93729e13781d137e65d3f
591591
+ "description": "Sets input files for given <input type=file>",
592592
+ "parameters": [
593593
+ { "name": "objectId", "$ref": "Runtime.RemoteObjectId", "description": "Input element handle." },
594-
+ { "name": "files", "type": "array", "items": { "$ref": "FilePayload" }, "description": "Files to set" }
594+
+ { "name": "files", "type": "array", "items": { "$ref": "FilePayload" }, "optional": true, "description": "Files to set" },
595+
+ { "name": "paths", "type": "array", "items": { "type": "string" }, "optional": true, "description": "File paths to set" }
595596
+ ]
596597
}
597598
],
@@ -3314,7 +3315,7 @@ index 51badf49a6ce08975d655efa01cca9cd877e8f6b..ea4240cf72670cedfbd8b38d4d013676
33143315
{
33153316
return context ? instrumentingAgents(*context) : nullptr;
33163317
diff --git a/Source/WebCore/inspector/agents/InspectorDOMAgent.cpp b/Source/WebCore/inspector/agents/InspectorDOMAgent.cpp
3317-
index 0e186bcea701c6631985df40bc9a9b1e8784f0af..69a5fe6821b1fe7cfc502bbc93059df9f74b7463 100644
3318+
index 0e186bcea701c6631985df40bc9a9b1e8784f0af..5e4b051b882433075148723e6a1258d18c559b73 100644
33183319
--- a/Source/WebCore/inspector/agents/InspectorDOMAgent.cpp
33193320
+++ b/Source/WebCore/inspector/agents/InspectorDOMAgent.cpp
33203321
@@ -62,12 +62,16 @@
@@ -3579,11 +3580,11 @@ index 0e186bcea701c6631985df40bc9a9b1e8784f0af..69a5fe6821b1fe7cfc502bbc93059df9
35793580
}
35803581

35813582
Node* InspectorDOMAgent::scriptValueAsNode(JSC::JSValue value)
3582-
@@ -2984,4 +3123,42 @@ Protocol::ErrorStringOr<void> InspectorDOMAgent::setAllowEditingUserAgentShadowT
3583+
@@ -2984,4 +3123,57 @@ Protocol::ErrorStringOr<void> InspectorDOMAgent::setAllowEditingUserAgentShadowT
35833584
return { };
35843585
}
35853586

3586-
+Protocol::ErrorStringOr<void> InspectorDOMAgent::setInputFiles(const String& objectId, Ref<JSON::Array>&& files) {
3587+
+Protocol::ErrorStringOr<void> InspectorDOMAgent::setInputFiles(const String& objectId, RefPtr<JSON::Array>&& files, RefPtr<JSON::Array>&& paths) {
35873588
+ InjectedScript injectedScript = m_injectedScriptManager.injectedScriptForObjectId(objectId);
35883589
+ if (injectedScript.hasNoValue())
35893590
+ return makeUnexpected("Can not find element's context for given id"_s);
@@ -3595,26 +3596,41 @@ index 0e186bcea701c6631985df40bc9a9b1e8784f0af..69a5fe6821b1fe7cfc502bbc93059df9
35953596
+ if (node->nodeType() != Node::ELEMENT_NODE || node->nodeName() != "INPUT")
35963597
+ return makeUnexpected("Not an input node"_s);
35973598
+
3599+
+ if (!(bool(files) ^ bool(paths)))
3600+
+ return makeUnexpected("Exactly one of files and paths should be specified"_s);
3601+
+
35983602
+ HTMLInputElement* element = static_cast<HTMLInputElement*>(node);
35993603
+ Vector<Ref<File>> fileObjects;
3600-
+ for (unsigned i = 0; i < files->length(); ++i) {
3601-
+ RefPtr<JSON::Value> item = files->get(i);
3602-
+ RefPtr<JSON::Object> obj = item->asObject();
3603-
+ if (!obj)
3604-
+ return makeUnexpected("Invalid file payload format"_s);
3605-
+
3606-
+ String name;
3607-
+ String type;
3608-
+ String data;
3609-
+ if (!obj->getString("name", name) || !obj->getString("type", type) || !obj->getString("data", data))
3610-
+ return makeUnexpected("Invalid file payload format"_s);
3611-
+
3612-
+ std::optional<Vector<uint8_t>> buffer = base64Decode(data);
3613-
+ if (!buffer)
3614-
+ return makeUnexpected("Unable to decode given content"_s);
3615-
+
3616-
+ ScriptExecutionContext* context = element->scriptExecutionContext();
3617-
+ fileObjects.append(File::create(context, Blob::create(context, WTFMove(*buffer), type), name));
3604+
+ if (files) {
3605+
+ for (unsigned i = 0; i < files->length(); ++i) {
3606+
+ RefPtr<JSON::Value> item = files->get(i);
3607+
+ RefPtr<JSON::Object> obj = item->asObject();
3608+
+ if (!obj)
3609+
+ return makeUnexpected("Invalid file payload format"_s);
3610+
+
3611+
+ String name;
3612+
+ String type;
3613+
+ String data;
3614+
+ if (!obj->getString("name", name) || !obj->getString("type", type) || !obj->getString("data", data))
3615+
+ return makeUnexpected("Invalid file payload format"_s);
3616+
+
3617+
+ std::optional<Vector<uint8_t>> buffer = base64Decode(data);
3618+
+ if (!buffer)
3619+
+ return makeUnexpected("Unable to decode given content"_s);
3620+
+
3621+
+ ScriptExecutionContext* context = element->scriptExecutionContext();
3622+
+ fileObjects.append(File::create(context, Blob::create(context, WTFMove(*buffer), type), name));
3623+
+ }
3624+
+ } else {
3625+
+ for (unsigned i = 0; i < paths->length(); ++i) {
3626+
+ RefPtr<JSON::Value> item = paths->get(i);
3627+
+ String path = item->asString();
3628+
+ if (path.isEmpty())
3629+
+ return makeUnexpected("Invalid file path"_s);
3630+
+
3631+
+ ScriptExecutionContext* context = element->scriptExecutionContext();
3632+
+ fileObjects.append(File::create(context, path));
3633+
+ }
36183634
+ }
36193635
+ RefPtr<FileList> fileList = FileList::create(WTFMove(fileObjects));
36203636
+ element->setFiles(WTFMove(fileList));
@@ -3623,7 +3639,7 @@ index 0e186bcea701c6631985df40bc9a9b1e8784f0af..69a5fe6821b1fe7cfc502bbc93059df9
36233639
+
36243640
} // namespace WebCore
36253641
diff --git a/Source/WebCore/inspector/agents/InspectorDOMAgent.h b/Source/WebCore/inspector/agents/InspectorDOMAgent.h
3626-
index 2d073147ff54937b4ea0ce3f8ea3af61ad9761c4..e1f6eaf09510e6b1876fd1173d62b387675e147e 100644
3642+
index 2d073147ff54937b4ea0ce3f8ea3af61ad9761c4..373ea5f0205a7bb7ec2cac6c1aca8e663226f2e3 100644
36273643
--- a/Source/WebCore/inspector/agents/InspectorDOMAgent.h
36283644
+++ b/Source/WebCore/inspector/agents/InspectorDOMAgent.h
36293645
@@ -57,6 +57,7 @@ namespace WebCore {
@@ -3658,7 +3674,7 @@ index 2d073147ff54937b4ea0ce3f8ea3af61ad9761c4..e1f6eaf09510e6b1876fd1173d62b387
36583674
+ Inspector::Protocol::ErrorStringOr<std::tuple<String /* contentFrameId */, String /* ownerFrameId */>> describeNode(const String& objectId);
36593675
+ Inspector::Protocol::ErrorStringOr<void> scrollIntoViewIfNeeded(const String& objectId, RefPtr<JSON::Object>&& rect);
36603676
+ Inspector::Protocol::ErrorStringOr<Ref<JSON::ArrayOf<Inspector::Protocol::DOM::Quad>>> getContentQuads(const String& objectId);
3661-
+ Inspector::Protocol::ErrorStringOr<void> setInputFiles(const String& objectId, Ref<JSON::Array>&& files);
3677+
+ Inspector::Protocol::ErrorStringOr<void> setInputFiles(const String& objectId, RefPtr<JSON::Array>&& files, RefPtr<JSON::Array>&& paths);
36623678

36633679
// InspectorInstrumentation
36643680
Inspector::Protocol::DOM::NodeId identifierForNode(Node&);

0 commit comments

Comments
 (0)