Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
feat(webkit): implement file chooser interception (#97)
Pavel Feldmand70133b23229
diff --git a/browser_patches/webkit/BUILD_NUMBER b/browser_patches/webkit/BUILD_NUMBERindex dd11724042..7d802a3e71 100644--- a/browser_patches/webkit/BUILD_NUMBER+++ b/browser_patches/webkit/BUILD_NUMBER@@ -1 +1 @@-1001+1002diff --git a/browser_patches/webkit/patches/0001-chore-bootstrap.patch b/browser_patches/webkit/patches/0001-chore-bootstrap.patchindex 8d553aab0a..efc115005b 100644--- a/browser_patches/webkit/patches/0001-chore-bootstrap.patch+++ b/browser_patches/webkit/patches/0001-chore-bootstrap.patch@@ -1,7 +1,7 @@-From d4351da392a4cade240d990a2986f0fe73b84f4a Mon Sep 17 00:00:00 2001-From: Andrey Lushnikov <[email protected]>-Date: Tue, 26 Nov 2019 14:07:23 -0800-Subject: [PATCH] chore: bootstrap+From 121a2630d6d47db4f113d0d063e717329b69ae4f Mon Sep 17 00:00:00 2001+From: Pavel <[email protected]>+Date: Tue, 26 Nov 2019 18:43:46 -0800+Subject: [PATCH xserver] chore: bootstrap---Source/JavaScriptCore/CMakeLists.txt | 4 +@@ -12,18 +12,19 @@ Subject: [PATCH] chore: bootstrap.../inspector/agents/InspectorTargetAgent.cpp | 46 +-.../inspector/agents/InspectorTargetAgent.h | 6 +-.../inspector/protocol/Browser.json | 40 ++- .../inspector/protocol/DOM.json | 21 ++ .../inspector/protocol/DOM.json | 39 ++.../inspector/protocol/Dialog.json | 36 ++.../inspector/protocol/Emulation.json | 14 +.../inspector/protocol/Input.json | 160 ++++++- .../inspector/protocol/Page.json | 66 ++-+ .../inspector/protocol/Page.json | 82 ++-.../inspector/protocol/Target.json | 18 +-- .../inspector/InspectorInstrumentation.cpp | 6 +- .../inspector/InspectorInstrumentation.h | 9 +- .../inspector/agents/InspectorDOMAgent.cpp | 57 +++- .../inspector/agents/InspectorDOMAgent.h | 1 +- .../inspector/agents/InspectorPageAgent.cpp | 468 +++++++++++++++++-- .../inspector/agents/InspectorPageAgent.h | 7 +-+ Source/WebCore/html/FileInputType.cpp | 6 ++ .../inspector/InspectorInstrumentation.cpp | 12 ++ .../inspector/InspectorInstrumentation.h | 21 ++ .../inspector/agents/InspectorDOMAgent.cpp | 103 +++++ .../inspector/agents/InspectorDOMAgent.h | 2 ++ .../inspector/agents/InspectorPageAgent.cpp | 495 +++++++++++++++++-+ .../inspector/agents/InspectorPageAgent.h | 16 +-Source/WebCore/loader/FrameLoader.cpp | 1 +Source/WebCore/page/History.cpp | 1 +.../WebCore/platform/PlatformKeyboardEvent.h | 2 +@@ -43,11 +44,11 @@ Subject: [PATCH] chore: bootstrapSource/WebKit/UIProcess/API/C/WKPage.cpp | 2 +.../UIProcess/API/Cocoa/_WKBrowserInspector.h | 23 +.../API/Cocoa/_WKBrowserInspector.mm | 25 +- .../API/glib/WebKitBrowserInspector.cpp | 114 ++++++ .../API/glib/WebKitBrowserInspector.cpp | 114 ++++.../API/glib/WebKitBrowserInspectorPrivate.h | 9 +.../UIProcess/API/glib/WebKitWebContext.cpp | 5 +.../UIProcess/API/gtk/PageClientImpl.cpp | 2 +- .../API/gtk/WebKitBrowserInspector.h | 57 ++++ .../API/gtk/WebKitBrowserInspector.h | 57 ++Source/WebKit/UIProcess/API/gtk/webkit2.h | 1 +.../API/wpe/WebKitBrowserInspector.h | 54 ++Source/WebKit/UIProcess/API/wpe/webkit.h | 1 +@@ -55,7 +56,7 @@ Subject: [PATCH] chore: bootstrap.../UIProcess/BrowserInspectorController.h | 47 ++.../WebKit/UIProcess/BrowserInspectorPipe.cpp | 35 ++.../WebKit/UIProcess/BrowserInspectorPipe.h | 16 +- .../UIProcess/BrowserInspectorTargetAgent.cpp | 83 +++++ .../UIProcess/BrowserInspectorTargetAgent.cpp | 83 +++.../UIProcess/BrowserInspectorTargetAgent.h | 35 ++.../PopUpSOAuthorizationSession.h | 4 +.../PopUpSOAuthorizationSession.mm | 1 +@@ -69,7 +70,7 @@ Subject: [PATCH] chore: bootstrap.../WebKit/UIProcess/RemoteInspectorPipe.cpp | 132 +++++Source/WebKit/UIProcess/RemoteInspectorPipe.h | 43 ++.../AuthenticatorManager.cpp | 1 +- .../UIProcess/WebPageInspectorController.cpp | 56 ++-+ .../UIProcess/WebPageInspectorController.cpp | 56 +-.../UIProcess/WebPageInspectorController.h | 8 +.../WebPageInspectorEmulationAgent.cpp | 39 ++.../WebPageInspectorEmulationAgent.h | 41 ++@@ -83,10 +84,10 @@ Subject: [PATCH] chore: bootstrap.../glib/InspectorBrowserAgentClientGLib.h | 36 ++.../UIProcess/gtk/InspectorDialogAgentGtk.cpp | 23 +.../gtk/WebPageInspectorEmulationAgentGtk.cpp | 35 ++- .../gtk/WebPageInspectorInputAgentGtk.cpp | 85 +++++ .../gtk/WebPageInspectorInputAgentGtk.cpp | 85 +++.../gtk/WebPageInspectorTargetProxyGtk.cpp | 22 +.../WebKit/UIProcess/ios/PageClientImplIOS.mm | 2 +- .../mac/InspectorBrowserAgentClientMac.h | 29 +++ .../mac/InspectorBrowserAgentClientMac.h | 29 +.../mac/InspectorBrowserAgentClientMac.mm | 68 +++.../UIProcess/mac/InspectorDialogAgentMac.mm | 15 +.../WebKit/UIProcess/mac/PageClientImplMac.mm | 5 +@@ -100,13 +101,13 @@ Subject: [PATCH] chore: bootstrap.../WebPage/WebPageInspectorTarget.cpp | 7 +.../WebPage/WebPageInspectorTarget.h | 1 +Source/WebKit/WebProcess/WebProcess.cpp | 3 +-- Tools/MiniBrowser/gtk/main.c | 28 +++ Tools/MiniBrowser/gtk/main.c | 28 +Tools/MiniBrowser/mac/AppDelegate.h | 4 +-Tools/MiniBrowser/mac/AppDelegate.m | 25 +-.../mac/WK2BrowserWindowController.h | 3 +.../mac/WK2BrowserWindowController.m | 17 +-Tools/MiniBrowser/wpe/main.cpp | 37 ++- 102 files changed, 3966 insertions(+), 55 deletions(-)+ 103 files changed, 4107 insertions(+), 55 deletions(-)create mode 100644 Source/JavaScriptCore/inspector/protocol/Browser.jsoncreate mode 100644 Source/JavaScriptCore/inspector/protocol/Dialog.jsoncreate mode 100644 Source/JavaScriptCore/inspector/protocol/Emulation.json@@ -513,10 +514,27 @@ index 00000000000..bed4a3bfe6f+ ]+}diff --git a/Source/JavaScriptCore/inspector/protocol/DOM.json b/Source/JavaScriptCore/inspector/protocol/DOM.json-index 38cb48bedf2..285027ae5d7 100644+index 38cb48bedf2..c8da2a4f10f 100644--- a/Source/JavaScriptCore/inspector/protocol/DOM.json+++ b/Source/JavaScriptCore/inspector/protocol/DOM.json-@@ -542,6 +542,27 @@+@@ -167,6 +167,16 @@+ { "name": "borderColor", "$ref": "RGBAColor", "optional": true, "description": "The border highlight fill color (default: transparent)." },+ { "name": "marginColor", "$ref": "RGBAColor", "optional": true, "description": "The margin highlight fill color (default: transparent)." }+ ]++ },++ {++ "id": "FilePayload",++ "type": "object",++ "description": "Data to construct File object.",++ "properties": [++ { "name": "name", "type": "string", "description": "File name." },++ { "name": "type", "type": "string", "description": "File type." },++ { "name": "data", "type": "string", "description": "Base64-encoded file data." }++ ]+ }+ ],+ "commands": [+@@ -542,6 +552,35 @@"parameters": [{ "name": "allow", "type": "boolean" }]@@ -540,6 +558,14 @@ index 38cb48bedf2..285027ae5d7 100644+ "$ref": "Quad"+ }+ }++ ]++ },++ {++ "name": "setInputFiles",++ "description": "Sets input files for given <input type=file>",++ "parameters": [++ { "name": "objectId", "$ref": "Runtime.RemoteObjectId", "description": "Input element handle." },++ { "name": "files", "type": "array", "items": { "$ref": "FilePayload" }, "description": "Files to set" }+ ]}],@@ -773,7 +799,7 @@ index 00000000000..79bbe73b0df+ ]+}diff --git a/Source/JavaScriptCore/inspector/protocol/Page.json b/Source/JavaScriptCore/inspector/protocol/Page.json-index 367d1f235a8..9f455a19f22 100644+index 367d1f235a8..b01d36e5e86 100644--- a/Source/JavaScriptCore/inspector/protocol/Page.json+++ b/Source/JavaScriptCore/inspector/protocol/Page.json@@ -108,6 +108,40 @@@@ -827,7 +853,7 @@ index 367d1f235a8..9f455a19f22 100644]},{-@@ -288,6 +323,20 @@+@@ -288,6 +323,27 @@"returns": [{ "name": "data", "type": "string", "description": "Base64-encoded web archive." }]@@ -844,14 +870,22 @@ index 367d1f235a8..9f455a19f22 100644+ "description": "Serializes and returns all of the accessibility nodes of the page.",+ "returns": [+ { "name": "axNode", "$ref": "AXNode", "description": "The root AXNode."}++ ]++ },++ {++ "name": "setInterceptFileChooserDialog",++ "description": "Intercepts file chooser dialog",++ "parameters": [++ { "name": "enabled", "type": "boolean", "description": "True to enable." }+ ]}],"events": [-@@ -347,6 +396,21 @@+@@ -346,12 +402,36 @@+ { "name": "frameId", "$ref": "Network.FrameId", "description": "Id of the frame that has cleared its scheduled navigation." }]},- {++ {+ "name": "navigatedWithinDocument",+ "description": "Fired when same-document navigation happens, e.g. due to history API usage or anchor navigation.",+ "parameters": [@@ -866,10 +900,24 @@ index 367d1f235a8..9f455a19f22 100644+ "type": "string"+ }+ ]-+ }, {++ },+ {"name": "defaultAppearanceDidChange","description": "Fired when page's default appearance changes, even if there is a forced appearance.","parameters": [+ { "name": "appearance", "$ref": "Appearance", "description": "Name of the appearance that is active (not considering any forced appearance.)" }+ ]++ },++ {++ "name": "fileChooserOpened",++ "description": "Fired when the page shows file chooser for it's <input type=file>.",++ "parameters": [++ { "name": "frameId", "$ref": "Network.FrameId", "description": "Frame where file chooser is opened." },++ { "name": "element", "$ref": "Runtime.RemoteObject", "description": "Input element." }++ ]+ }+ ]+ }diff --git a/Source/JavaScriptCore/inspector/protocol/Target.json b/Source/JavaScriptCore/inspector/protocol/Target.jsonindex 240cd42e67e..f635c67ef3f 100644--- a/Source/JavaScriptCore/inspector/protocol/Target.json@@ -906,8 +954,32 @@ index 240cd42e67e..f635c67ef3f 100644}],"events": [+diff --git a/Source/WebCore/html/FileInputType.cpp b/Source/WebCore/html/FileInputType.cpp+index 4e41fd3f807..1f7be602cb2 100644+--- a/Source/WebCore/html/FileInputType.cpp++++ b/Source/WebCore/html/FileInputType.cpp+@@ -36,6 +36,7 @@+ #include "HTMLNames.h"+ #include "Icon.h"+ #include "InputTypeNames.h"++#include "InspectorInstrumentation.h"+ #include "LocalizedStrings.h"+ #include "RenderFileUploadControl.h"+ #include "RuntimeEnabledFeatures.h"+@@ -205,6 +206,11 @@ void FileInputType::handleDOMActivateEvent(Event& event)+ if (input.isDisabledFormControl())+ return;+++ bool intercept = false;++ InspectorInstrumentation::runOpenPanel(input.document().frame(), element(), &intercept);++ if (intercept)++ return;+++ if (!UserGestureIndicator::processingUserGesture())+ return;+diff --git a/Source/WebCore/inspector/InspectorInstrumentation.cpp b/Source/WebCore/inspector/InspectorInstrumentation.cpp-index cb6ed9f6c84..b5a560b7bb8 100644+index cb6ed9f6c84..95154bc9140 100644--- a/Source/WebCore/inspector/InspectorInstrumentation.cpp+++ b/Source/WebCore/inspector/InspectorInstrumentation.cpp@@ -783,6 +783,12 @@ void InspectorInstrumentation::frameClearedScheduledNavigationImpl(Instrumenting@@ -923,11 +995,32 @@ index cb6ed9f6c84..b5a560b7bb8 100644void InspectorInstrumentation::defaultAppearanceDidChangeImpl(InstrumentingAgents& instrumentingAgents, bool useDarkAppearance){if (InspectorPageAgent* inspectorPageAgent = instrumentingAgents.inspectorPageAgent())+@@ -1251,6 +1257,12 @@ void InspectorInstrumentation::renderLayerDestroyedImpl(InstrumentingAgents& ins+ layerTreeAgent->renderLayerDestroyed(renderLayer);+ }+++void InspectorInstrumentation::runOpenPanelImpl(InstrumentingAgents& instrumentingAgents, HTMLInputElement* element, bool* intercept)++{++ if (InspectorPageAgent* pageAgent = instrumentingAgents.inspectorPageAgent())++ pageAgent->runOpenPanel(element, intercept);++}+++ InstrumentingAgents& InspectorInstrumentation::instrumentingAgentsForWorkerGlobalScope(WorkerGlobalScope& workerGlobalScope)+ {+ return workerGlobalScope.inspectorController().m_instrumentingAgents;diff --git a/Source/WebCore/inspector/InspectorInstrumentation.h b/Source/WebCore/inspector/InspectorInstrumentation.h-index 6698431f316..40dd67f43e9 100644+index 6698431f316..486a6781d81 100644--- a/Source/WebCore/inspector/InspectorInstrumentation.h+++ b/Source/WebCore/inspector/InspectorInstrumentation.h-@@ -228,6 +228,7 @@ public:+@@ -77,6 +77,7 @@ class DOMWrapperWorld;+ class Document;+ class DocumentLoader;+ class EventListener;++class HTMLInputElement;+ class HTTPHeaderMap;+ class InspectorTimelineAgent;+ class InstrumentingAgents;+@@ -228,6 +229,7 @@ public:static void frameStoppedLoading(Frame&);static void frameScheduledNavigation(Frame&, Seconds delay);static void frameClearedScheduledNavigation(Frame&);@@ -935,7 +1028,16 @@ index 6698431f316..40dd67f43e9 100644static void defaultAppearanceDidChange(Page&, bool useDarkAppearance);static void willDestroyCachedResource(CachedResource&);-@@ -428,6 +429,7 @@ private:+@@ -313,6 +315,8 @@ public:+ static void layerTreeDidChange(Page*);+ static void renderLayerDestroyed(Page*, const RenderLayer&);+++ static void runOpenPanel(Frame*, HTMLInputElement*, bool*);+++ static void frontendCreated();+ static void frontendDeleted();+ static bool hasFrontends() { return InspectorInstrumentationPublic::hasFrontends(); }+@@ -428,6 +432,7 @@ private:static void frameStoppedLoadingImpl(InstrumentingAgents&, Frame&);static void frameScheduledNavigationImpl(InstrumentingAgents&, Frame&, Seconds delay);static void frameClearedScheduledNavigationImpl(InstrumentingAgents&, Frame&);@@ -943,7 +1045,16 @@ index 6698431f316..40dd67f43e9 100644static void defaultAppearanceDidChangeImpl(InstrumentingAgents&, bool useDarkAppearance);static void willDestroyCachedResourceImpl(CachedResource&);-@@ -1219,6 +1221,13 @@ inline void InspectorInstrumentation::frameClearedScheduledNavigation(Frame& fra+@@ -509,6 +514,8 @@ private:+ static void layerTreeDidChangeImpl(InstrumentingAgents&);+ static void renderLayerDestroyedImpl(InstrumentingAgents&, const RenderLayer&);+++ static void runOpenPanelImpl(InstrumentingAgents&, HTMLInputElement*, bool*);+++ static InstrumentingAgents& instrumentingAgentsForPage(Page&);+ static InstrumentingAgents& instrumentingAgentsForWorkerGlobalScope(WorkerGlobalScope&);++@@ -1219,6 +1226,13 @@ inline void InspectorInstrumentation::frameClearedScheduledNavigation(Frame& fraframeClearedScheduledNavigationImpl(*instrumentingAgents, frame);}@@ -957,19 +1068,42 @@ index 6698431f316..40dd67f43e9 100644inline void InspectorInstrumentation::defaultAppearanceDidChange(Page& page, bool useDarkAppearance){FAST_RETURN_IF_NO_FRONTENDS(void());+@@ -1643,6 +1657,13 @@ inline void InspectorInstrumentation::renderLayerDestroyed(Page* page, const Ren+ renderLayerDestroyedImpl(*instrumentingAgents, renderLayer);+ }+++inline void InspectorInstrumentation::runOpenPanel(Frame* frame, HTMLInputElement* element, bool* intercept)++{++ FAST_RETURN_IF_NO_FRONTENDS(void());++ if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForFrame(*frame))++ runOpenPanelImpl(*instrumentingAgents, element, intercept);++}+++ inline InstrumentingAgents* InspectorInstrumentation::instrumentingAgentsForContext(ScriptExecutionContext* context)+ {+ return context ? instrumentingAgentsForContext(*context) : nullptr;diff --git a/Source/WebCore/inspector/agents/InspectorDOMAgent.cpp b/Source/WebCore/inspector/agents/InspectorDOMAgent.cpp-index aecc79bc0ca..d9fa197eab6 100644+index aecc79bc0ca..57ce50c1f94 100644--- a/Source/WebCore/inspector/agents/InspectorDOMAgent.cpp+++ b/Source/WebCore/inspector/agents/InspectorDOMAgent.cpp-@@ -65,6 +65,7 @@+@@ -61,12 +61,16 @@+ #include "Event.h"+ #include "EventListener.h"+ #include "EventNames.h"++#include "File.h"++#include "FileList.h"+ #include "Frame.h"#include "FrameTree.h"#include "FrameView.h"#include "FullscreenManager.h"+#include "FloatQuad.h"#include "HTMLElement.h"#include "HTMLFrameOwnerElement.h"++#include "HTMLInputElement.h"#include "HTMLMediaElement.h"-@@ -93,6 +94,7 @@+ #include "HTMLNames.h"+ #include "HTMLParserIdioms.h"+@@ -93,11 +97,13 @@#include "Page.h"#include "Pasteboard.h"#include "PseudoElement.h"@@ -977,7 +1111,13 @@ index aecc79bc0ca..d9fa197eab6 100644#include "RenderStyle.h"#include "RenderStyleConstants.h"#include "ScriptState.h"-@@ -1475,6 +1477,61 @@ void InspectorDOMAgent::setInspectedNode(ErrorString& errorString, int nodeId)+ #include "SelectorChecker.h"+ #include "ShadowRoot.h"++#include "SharedBuffer.h"+ #include "StaticNodeList.h"+ #include "StyleProperties.h"+ #include "StyleResolver.h"+@@ -1475,6 +1481,61 @@ void InspectorDOMAgent::setInspectedNode(ErrorString& errorString, int nodeId)m_suppressEventListenerChangedEvent = false;}@@ -1039,20 +1179,68 @@ index aecc79bc0ca..d9fa197eab6 100644void InspectorDOMAgent::resolveNode(ErrorString& errorString, int nodeId, const String* objectGroup, RefPtr<Inspector::Protocol::Runtime::RemoteObject>& result){String objectGroupName = objectGroup ? *objectGroup : emptyString();+@@ -2686,4 +2747,46 @@ void InspectorDOMAgent::setAllowEditingUserAgentShadowTrees(ErrorString&, bool a+ m_allowEditingUserAgentShadowTrees = allow;+ }+++void InspectorDOMAgent::setInputFiles(ErrorString& errorString, const String& objectId, const JSON::Array& in_files) {++ InjectedScript injectedScript = m_injectedScriptManager.injectedScriptForObjectId(objectId);++ if (injectedScript.hasNoValue()) {++ errorString = "Can not find element's context for given id"_s;++ return;++ }++ Node* node = scriptValueAsNode(injectedScript.findObjectById(objectId));++ if (!node) {++ errorString = "Can not find element for given id"_s;++ return;++ }++ if (node->nodeType() != Node::ELEMENT_NODE || node->nodeName() != "INPUT") {++ errorString = "Not an input node"_s;++ return;++ }++ HTMLInputElement* element = static_cast<HTMLInputElement*>(node);++ Vector<Ref<File>> fileObjects;++ for (unsigned i = 0; i < in_files.length(); ++i) {++ RefPtr<JSON::Value> item = in_files.get(i);++ RefPtr<JSON::Object> obj;++ if (!item->asObject(obj)) {++ errorString = "Invalid file payload format"_s;++ return;++ }++ String name;++ String type;++ String data;++ if (!obj->getString("name", name) || !obj->getString("type", type) || !obj->getString("data", data)) {++ errorString = "Invalid file payload format"_s;++ return;++ }++ Vector<uint8_t> buffer;++ if (!base64Decode(data, buffer)) {++ errorString = "Unable to decode given content"_s;++ return;++ }++ fileObjects.append(File::create(Blob::create(SharedBuffer::create(WTFMove(buffer)), type), name));++ }++ RefPtr<FileList> fileList = FileList::create(WTFMove(fileObjects));++ element->setFiles(WTFMove(fileList));++}+++ } // namespace WebCorediff --git a/Source/WebCore/inspector/agents/InspectorDOMAgent.h b/Source/WebCore/inspector/agents/InspectorDOMAgent.h-index 51639abeb84..fbb7773978d 100644+index 51639abeb84..16080f2c017 100644--- a/Source/WebCore/inspector/agents/InspectorDOMAgent.h+++ b/Source/WebCore/inspector/agents/InspectorDOMAgent.h-@@ -148,6 +148,7 @@ public:+@@ -148,6 +148,8 @@ public:void focus(ErrorString&, int nodeId) override;void setInspectedNode(ErrorString&, int nodeId) override;void setAllowEditingUserAgentShadowTrees(ErrorString&, bool allow) final;+ void getContentQuads(ErrorString&, const String& objectId, RefPtr<JSON::ArrayOf<Inspector::Protocol::DOM::Quad>>& out_quads) override;++ void setInputFiles(ErrorString&, const String& objectId, const JSON::Array& in_files) override;// InspectorInstrumentationint identifierForNode(Node&);diff --git a/Source/WebCore/inspector/agents/InspectorPageAgent.cpp b/Source/WebCore/inspector/agents/InspectorPageAgent.cpp-index f2e228b7f74..a5eabfa65c4 100644+index f2e228b7f74..62236cbccd7 100644--- a/Source/WebCore/inspector/agents/InspectorPageAgent.cpp+++ b/Source/WebCore/inspector/agents/InspectorPageAgent.cpp@@ -32,6 +32,7 @@@@ -1063,7 +1251,7 @@ index f2e228b7f74..a5eabfa65c4 100644#include "CachedResource.h"#include "CachedResourceLoader.h"#include "Cookie.h"-@@ -39,6 +40,7 @@+@@ -39,12 +40,14 @@#include "CustomHeaderFields.h"#include "Document.h"#include "DocumentLoader.h"@@ -1071,7 +1259,19 @@ index f2e228b7f74..a5eabfa65c4 100644#include "Frame.h"#include "FrameLoadRequest.h"#include "FrameLoader.h"-@@ -63,6 +65,7 @@+ #include "FrameSnapshotting.h"+ #include "FrameView.h"+ #include "HTMLFrameOwnerElement.h"++#include "HTMLInputElement.h"+ #include "HTMLNames.h"+ #include "ImageBuffer.h"+ #include "InspectorClient.h"+@@ -59,13 +62,16 @@+ #include "RenderTheme.h"+ #include "ScriptController.h"+ #include "ScriptSourceCode.h"++#include "ScriptState.h"+ #include "SecurityOrigin.h"#include "Settings.h"#include "StyleScope.h"#include "TextEncoding.h"@@ -1079,7 +1279,19 @@ index f2e228b7f74..a5eabfa65c4 100644#include "UserGestureIndicator.h"#include <JavaScriptCore/ContentSearchUtilities.h>#include <JavaScriptCore/IdentifiersFactory.h>-@@ -412,14 +415,16 @@ void InspectorPageAgent::reload(ErrorString&, const bool* optionalReloadFromOrig++#include <JavaScriptCore/InjectedScriptManager.h>+ #include <JavaScriptCore/RegularExpression.h>+ #include <wtf/ListHashSet.h>+ #include <wtf/Stopwatch.h>+@@ -337,6 +343,7 @@ InspectorPageAgent::InspectorPageAgent(PageAgentContext& context, InspectorClien+ , m_frontendDispatcher(makeUnique<Inspector::PageFrontendDispatcher>(context.frontendRouter))+ , m_backendDispatcher(Inspector::PageBackendDispatcher::create(context.backendDispatcher, this))+ , m_inspectedPage(context.inspectedPage)++ , m_injectedScriptManager(context.injectedScriptManager)+ , m_client(client)+ , m_overlay(overlay)+ {+@@ -412,14 +419,16 @@ void InspectorPageAgent::reload(ErrorString&, const bool* optionalReloadFromOrigm_inspectedPage.mainFrame().loader().reload(reloadOptions);}@@ -1101,7 +1313,7 @@ index f2e228b7f74..a5eabfa65c4 100644}void InspectorPageAgent::overrideUserAgent(ErrorString&, const String* value)-@@ -761,6 +766,12 @@ void InspectorPageAgent::frameClearedScheduledNavigation(Frame& frame)+@@ -761,6 +770,12 @@ void InspectorPageAgent::frameClearedScheduledNavigation(Frame& frame)m_frontendDispatcher->frameClearedScheduledNavigation(frameId(&frame));}@@ -1114,7 +1326,33 @@ index f2e228b7f74..a5eabfa65c4 100644void InspectorPageAgent::defaultAppearanceDidChange(bool useDarkAppearance){m_frontendDispatcher->defaultAppearanceDidChange(useDarkAppearance ? Inspector::Protocol::Page::Appearance::Dark : Inspector::Protocol::Page::Appearance::Light);-@@ -986,4 +997,451 @@ void InspectorPageAgent::archive(ErrorString& errorString, String* data)+@@ -815,6 +830,25 @@ void InspectorPageAgent::didRecalculateStyle()+ m_overlay->update();+ }+++void InspectorPageAgent::runOpenPanel(HTMLInputElement* element, bool* intercept) {++ if (m_interceptFileChooserDialog) {++ *intercept = true;++ } else {++ return;++ }++ Document& document = element->document();++ auto* frame = document.frame();++ if (!frame)++ return;++++ auto& state = *mainWorldExecState(frame);++ auto injectedScript = m_injectedScriptManager.injectedScriptFor(&state);++ if (injectedScript.hasNoValue())++ return;++++ m_frontendDispatcher->fileChooserOpened(frameId(frame), injectedScript.wrapObject(InspectorDOMAgent::nodeAsScriptValue(state, element), WTF::String()));++}+++ Ref<Inspector::Protocol::Page::Frame> InspectorPageAgent::buildObjectForFrame(Frame* frame)+ {+ ASSERT_ARG(frame, frame);+@@ -986,4 +1020,455 @@ void InspectorPageAgent::archive(ErrorString& errorString, String* data)#endif}@@ -1564,13 +1802,33 @@ index f2e228b7f74..a5eabfa65c4 100644++ out_axNode = snapshotForAXObject(makeRefPtr(axObject));+}++++void InspectorPageAgent::setInterceptFileChooserDialog(ErrorString&, bool enabled) {++ m_interceptFileChooserDialog = enabled;++}+} // namespace WebCorediff --git a/Source/WebCore/inspector/agents/InspectorPageAgent.h b/Source/WebCore/inspector/agents/InspectorPageAgent.h-index 4fd8c0b1016..9f7cb087110 100644+index 4fd8c0b1016..50712625607 100644--- a/Source/WebCore/inspector/agents/InspectorPageAgent.h+++ b/Source/WebCore/inspector/agents/InspectorPageAgent.h-@@ -96,7 +96,7 @@ public:+@@ -40,10 +40,15 @@+ #include <wtf/Seconds.h>+ #include <wtf/text/WTFString.h>+++namespace Inspector {++class InjectedScriptManager;++}+++ namespace WebCore {++ class DocumentLoader;+ class Frame;++class HTMLInputElement;+ class InspectorClient;+ class InspectorOverlay;+ class Page;+@@ -96,7 +101,7 @@ public:void enable(ErrorString&) override;void disable(ErrorString&) override;void reload(ErrorString&, const bool* optionalReloadFromOrigin, const bool* optionalRevalidateAllResources) override;@@ -1579,7 +1837,7 @@ index 4fd8c0b1016..9f7cb087110 100644void overrideUserAgent(ErrorString&, const String* value) override;void overrideSetting(ErrorString&, const String& setting, const bool* value) override;void getCookies(ErrorString&, RefPtr<JSON::ArrayOf<Inspector::Protocol::Page::Cookie>>& cookies) override;-@@ -113,8 +113,10 @@ public:+@@ -113,8 +118,11 @@ public:void getCompositingBordersVisible(ErrorString&, bool* out_param) override;void setCompositingBordersVisible(ErrorString&, bool) override;void snapshotNode(ErrorString&, int nodeId, String* outDataURL) override;@@ -1588,10 +1846,11 @@ index 4fd8c0b1016..9f7cb087110 100644void archive(ErrorString&, String* data) override;+ void insertText(ErrorString&, const String& text) override;+ void accessibilitySnapshot(ErrorString&, RefPtr<Inspector::Protocol::Page::AXNode>& out_axNode) override;++ void setInterceptFileChooserDialog(ErrorString&, bool enabled) override;// InspectorInstrumentationvoid domContentEventFired();-@@ -126,6 +128,7 @@ public:+@@ -126,6 +134,7 @@ public:void frameStoppedLoading(Frame&);void frameScheduledNavigation(Frame&, Seconds delay);void frameClearedScheduledNavigation(Frame&);@@ -1599,6 +1858,30 @@ index 4fd8c0b1016..9f7cb087110 100644void defaultAppearanceDidChange(bool useDarkAppearance);void applyUserAgentOverride(String&);void applyEmulatedMedia(String&);+@@ -134,6 +143,7 @@ public:+ void didLayout();+ void didScroll();+ void didRecalculateStyle();++ void runOpenPanel(HTMLInputElement* element, bool* intercept);++ Frame* frameForId(const String& frameId);+ WEBCORE_EXPORT String frameId(Frame*);+@@ -153,6 +163,7 @@ private:+ RefPtr<Inspector::PageBackendDispatcher> m_backendDispatcher;++ Page& m_inspectedPage;++ Inspector::InjectedScriptManager& m_injectedScriptManager;+ InspectorClient* m_client { nullptr };+ InspectorOverlay* m_overlay { nullptr };++@@ -165,6 +176,7 @@ private:+ String m_bootstrapScript;+ bool m_isFirstLayoutAfterOnLoad { false };+ bool m_showPaintRects { false };++ bool m_interceptFileChooserDialog { false };+ };++ } // namespace WebCorediff --git a/Source/WebCore/loader/FrameLoader.cpp b/Source/WebCore/loader/FrameLoader.cppindex 9b4211b4212..5881bd624df 100644--- a/Source/WebCore/loader/FrameLoader.cpp@@ -5847,5 +6130,5 @@ index 2d183d39412..d94d4f06fc5 100644webkit_web_context_set_tls_errors_policy(webContext, WEBKIT_TLS_ERRORS_POLICY_IGNORE);---2.22.1+2.17.1