Skip to content

Commit 03cae92

Browse files
authored
browser(webkit): remove BackendDispatcher::Mode (#2223)
1 parent e081ba7 commit 03cae92

File tree

2 files changed

+28
-128
lines changed

2 files changed

+28
-128
lines changed

browser_patches/webkit/BUILD_NUMBER

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1226
1+
1227

browser_patches/webkit/patches/bootstrap.diff

Lines changed: 27 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -148,113 +148,41 @@ index cd593a24af4fe24ba59577b73b26947765edcc32..1f7a04d72065dbd60761c1a72f3254f9
148148
return;
149149
}
150150
diff --git a/Source/JavaScriptCore/inspector/InspectorBackendDispatcher.cpp b/Source/JavaScriptCore/inspector/InspectorBackendDispatcher.cpp
151-
index 038cb646d31706905deff8935040d63c0afd00f9..2fca7b043f15a8cce3819cc827912fb719a345db 100644
151+
index 038cb646d31706905deff8935040d63c0afd00f9..54bf8bf6aba07039109f61369b5e441eee0ba184 100644
152152
--- a/Source/JavaScriptCore/inspector/InspectorBackendDispatcher.cpp
153153
+++ b/Source/JavaScriptCore/inspector/InspectorBackendDispatcher.cpp
154154
@@ -102,7 +102,7 @@ void BackendDispatcher::registerDispatcherForDomain(const String& domain, Supple
155155
m_dispatchers.set(domain, dispatcher);
156156
}
157157

158158
-void BackendDispatcher::dispatch(const String& message)
159-
+BackendDispatcher::DispatchResult BackendDispatcher::dispatch(const String& message, Mode mode, Interceptor&& interceptor)
159+
+void BackendDispatcher::dispatch(const String& message, Interceptor&& interceptor)
160160
{
161161
Ref<BackendDispatcher> protect(*this);
162162

163-
@@ -120,29 +120,32 @@ void BackendDispatcher::dispatch(const String& message)
164-
if (!JSON::Value::parseJSON(message, parsedMessage)) {
165-
reportProtocolError(ParseError, "Message must be in JSON format"_s);
166-
sendPendingErrors();
167-
- return;
168-
+ return DispatchResult::Finished;
169-
}
170-
171-
if (!parsedMessage->asObject(messageObject)) {
172-
reportProtocolError(InvalidRequest, "Message must be a JSONified object"_s);
173-
sendPendingErrors();
174-
- return;
175-
+ return DispatchResult::Finished;
176-
}
177-
178-
RefPtr<JSON::Value> requestIdValue;
179-
if (!messageObject->getValue("id"_s, requestIdValue)) {
180-
reportProtocolError(InvalidRequest, "'id' property was not found"_s);
181-
sendPendingErrors();
182-
- return;
183-
+ return DispatchResult::Finished;
184-
}
185-
186-
if (!requestIdValue->asInteger(requestId)) {
187-
reportProtocolError(InvalidRequest, "The type of 'id' property must be integer"_s);
188-
sendPendingErrors();
189-
- return;
190-
+ return DispatchResult::Finished;
163+
@@ -143,6 +143,9 @@ void BackendDispatcher::dispatch(const String& message)
191164
}
192165
}
193166

194-
+ if (interceptor && interceptor(messageObject) == DispatchResult::Finished)
195-
+ return DispatchResult::Finished;
167+
+ if (interceptor && interceptor(messageObject) == InterceptionResult::Intercepted)
168+
+ return;
196169
+
197170
{
198171
// We could be called re-entrantly from a nested run loop, so restore the previous id.
199172
SetForScope<Optional<long>> scopedRequestId(m_currentRequestId, requestId);
200-
@@ -151,29 +154,31 @@ void BackendDispatcher::dispatch(const String& message)
201-
if (!messageObject->getValue("method"_s, methodValue)) {
202-
reportProtocolError(InvalidRequest, "'method' property wasn't found"_s);
203-
sendPendingErrors();
204-
- return;
205-
+ return DispatchResult::Finished;
206-
}
207-
208-
String methodString;
209-
if (!methodValue->asString(methodString)) {
210-
reportProtocolError(InvalidRequest, "The type of 'method' property must be string"_s);
211-
sendPendingErrors();
212-
- return;
213-
+ return DispatchResult::Finished;
214-
}
215-
216-
Vector<String> domainAndMethod = methodString.splitAllowingEmptyEntries('.');
217-
if (domainAndMethod.size() != 2 || !domainAndMethod[0].length() || !domainAndMethod[1].length()) {
218-
reportProtocolError(InvalidRequest, "The 'method' property was formatted incorrectly. It should be 'Domain.method'"_s);
219-
sendPendingErrors();
220-
- return;
221-
+ return DispatchResult::Finished;
222-
}
223-
224-
String domain = domainAndMethod[0];
225-
SupplementalBackendDispatcher* domainDispatcher = m_dispatchers.get(domain);
226-
if (!domainDispatcher) {
227-
+ if (mode == Mode::ContinueIfDomainIsMissing)
228-
+ return DispatchResult::Continue;
229-
reportProtocolError(MethodNotFound, "'" + domain + "' domain was not found");
230-
sendPendingErrors();
231-
- return;
232-
+ return DispatchResult::Finished;
233-
}
234-
235-
String method = domainAndMethod[1];
236-
@@ -182,6 +187,7 @@ void BackendDispatcher::dispatch(const String& message)
237-
if (m_protocolErrors.size())
238-
sendPendingErrors();
239-
}
240-
+ return DispatchResult::Finished;
241-
}
242-
243-
// FIXME: remove this function when legacy InspectorObject symbols are no longer needed <http://webkit.org/b/179847>.
244173
diff --git a/Source/JavaScriptCore/inspector/InspectorBackendDispatcher.h b/Source/JavaScriptCore/inspector/InspectorBackendDispatcher.h
245-
index 95d9d81188e735e8f1b70cc0deee2682cb6714f0..4c67ce34302f74e0d07f64ae53a4eaf18df6669a 100644
174+
index 95d9d81188e735e8f1b70cc0deee2682cb6714f0..fbab25a07bf35c49faf026a3dfaccd50f50d1ab8 100644
246175
--- a/Source/JavaScriptCore/inspector/InspectorBackendDispatcher.h
247176
+++ b/Source/JavaScriptCore/inspector/InspectorBackendDispatcher.h
248-
@@ -82,7 +82,11 @@ public:
177+
@@ -82,7 +82,10 @@ public:
249178
};
250179

251180
void registerDispatcherForDomain(const String& domain, SupplementalBackendDispatcher*);
252181
- void dispatch(const String& message);
253182
+
254-
+ enum class DispatchResult { Finished, Continue };
255-
+ enum class Mode { FailIfDomainIsMissing, ContinueIfDomainIsMissing };
256-
+ using Interceptor = WTF::Function<DispatchResult(const RefPtr<JSON::Object>&)>;
257-
+ DispatchResult dispatch(const String& message, Mode mode = Mode::FailIfDomainIsMissing, Interceptor&& interceptor = Interceptor());
183+
+ enum class InterceptionResult { Intercepted, Continue };
184+
+ using Interceptor = WTF::Function<InterceptionResult(const RefPtr<JSON::Object>&)>;
185+
+ void dispatch(const String& message, Interceptor&& interceptor = Interceptor());
258186

259187
// Note that 'unused' is a workaround so the compiler can pick the right sendResponse based on arity.
260188
// When <http://webkit.org/b/179847> is fixed or this class is renamed for the JSON::Object case,
@@ -7657,7 +7585,7 @@ index 23b992f3ce45f82f0dcdede6007a2e3a46b7b0b6..7e711e8f5132931e01eac66db6ea60c3
76577585
// This reuses the basename of the remote file path so that the filename exposed to DOM API remains the same.
76587586
diff --git a/Source/WebKit/UIProcess/BrowserInspectorController.cpp b/Source/WebKit/UIProcess/BrowserInspectorController.cpp
76597587
new file mode 100644
7660-
index 0000000000000000000000000000000000000000..300be76e7926ac5eb435ab62df1a973f04520327
7588+
index 0000000000000000000000000000000000000000..df23f11858e6e60ca238793fe3f37cf19036fbee
76617589
--- /dev/null
76627590
+++ b/Source/WebKit/UIProcess/BrowserInspectorController.cpp
76637591
@@ -0,0 +1,244 @@
@@ -7818,27 +7746,27 @@ index 0000000000000000000000000000000000000000..300be76e7926ac5eb435ab62df1a973f
78187746
+
78197747
+void BrowserInspectorController::dispatchMessageFromFrontend(const String& message)
78207748
+{
7821-
+ m_backendDispatcher->dispatch(message, BackendDispatcher::Mode::FailIfDomainIsMissing, [&](const RefPtr<JSON::Object>& messageObject) {
7749+
+ m_backendDispatcher->dispatch(message, [&](const RefPtr<JSON::Object>& messageObject) {
78227750
+ RefPtr<JSON::Value> pageProxyIDValue;
78237751
+ if (!messageObject->getValue("pageProxyId"_s, pageProxyIDValue))
7824-
+ return BackendDispatcher::DispatchResult::Continue;
7752+
+ return BackendDispatcher::InterceptionResult::Continue;
78257753
+
78267754
+ String pageProxyID;
78277755
+ if (!pageProxyIDValue->asString(pageProxyID)) {
78287756
+ m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidRequest, "The type of 'pageProxyId' must be string"_s);
78297757
+ m_backendDispatcher->sendPendingErrors();
7830-
+ return BackendDispatcher::DispatchResult::Finished;
7758+
+ return BackendDispatcher::InterceptionResult::Intercepted;
78317759
+ }
78327760
+
78337761
+
78347762
+ if (auto pageProxyChannel = m_pageProxyChannels.get(pageProxyID)) {
78357763
+ pageProxyChannel->dispatchMessageFromFrontend(message);
7836-
+ return BackendDispatcher::DispatchResult::Finished;
7764+
+ return BackendDispatcher::InterceptionResult::Intercepted;
78377765
+ }
78387766
+
78397767
+ m_backendDispatcher->reportProtocolError(BackendDispatcher::InvalidRequest, "Cannot find page proxy with provided 'pageProxyId'"_s);
78407768
+ m_backendDispatcher->sendPendingErrors();
7841-
+ return BackendDispatcher::DispatchResult::Finished;
7769+
+ return BackendDispatcher::InterceptionResult::Intercepted;
78427770
+ });
78437771
+}
78447772
+
@@ -8716,7 +8644,7 @@ index 0000000000000000000000000000000000000000..b5eeeca0f6b8c5c31e3786c0a675e322
87168644
+
87178645
+} // namespace WebKit
87188646
diff --git a/Source/WebKit/UIProcess/Inspector/InspectorTargetProxy.cpp b/Source/WebKit/UIProcess/Inspector/InspectorTargetProxy.cpp
8719-
index 6928ca2fbfb6939062e3cd14bb7ba6f2fdc87f5f..c4645302296540a408aa88dabb64fd5e9a04f3f7 100644
8647+
index 6928ca2fbfb6939062e3cd14bb7ba6f2fdc87f5f..621b99e233ed5cf504fedbd3ca3209c03bcd611f 100644
87208648
--- a/Source/WebKit/UIProcess/Inspector/InspectorTargetProxy.cpp
87218649
+++ b/Source/WebKit/UIProcess/Inspector/InspectorTargetProxy.cpp
87228650
@@ -27,11 +27,10 @@
@@ -8756,17 +8684,7 @@ index 6928ca2fbfb6939062e3cd14bb7ba6f2fdc87f5f..c4645302296540a408aa88dabb64fd5e
87568684
, m_identifier(targetId)
87578685
, m_type(type)
87588686
{
8759-
@@ -83,6 +81,9 @@ void InspectorTargetProxy::disconnect()
8760-
8761-
void InspectorTargetProxy::sendMessageToTargetBackend(const String& message)
8762-
{
8763-
+ if (m_page.inspectorController().dispatchMessageToTargetBackend(message))
8764-
+ return;
8765-
+
8766-
if (m_provisionalPage) {
8767-
m_provisionalPage->send(Messages::WebPage::SendMessageToTargetBackend(identifier(), message));
8768-
return;
8769-
@@ -97,6 +98,31 @@ void InspectorTargetProxy::didCommitProvisionalTarget()
8687+
@@ -97,6 +95,31 @@ void InspectorTargetProxy::didCommitProvisionalTarget()
87708688
m_provisionalPage = nullptr;
87718689
}
87728690

@@ -8839,7 +8757,7 @@ index a2239cec8e18850f35f7f88a9c4ebadc62bf4023..79f3ff84327dc075ec96983e04db4b10
88398757

88408758
} // namespace WebKit
88418759
diff --git a/Source/WebKit/UIProcess/Inspector/WebPageInspectorController.cpp b/Source/WebKit/UIProcess/Inspector/WebPageInspectorController.cpp
8842-
index 1861cff806131196ea49b4f8aca6665beebbf6e8..7287fd4bbc06a5791190454bedf02190fe98d2ae 100644
8760+
index 1861cff806131196ea49b4f8aca6665beebbf6e8..521ef88239d5db7274cd19cd4258581464081f92 100644
88438761
--- a/Source/WebKit/UIProcess/Inspector/WebPageInspectorController.cpp
88448762
+++ b/Source/WebKit/UIProcess/Inspector/WebPageInspectorController.cpp
88458763
@@ -26,12 +26,20 @@
@@ -9009,19 +8927,7 @@ index 1861cff806131196ea49b4f8aca6665beebbf6e8..7287fd4bbc06a5791190454bedf02190
90098927
m_page.didChangeInspectorFrontendCount(m_frontendRouter->frontendCount());
90108928

90118929
#if ENABLE(REMOTE_INSPECTOR)
9012-
@@ -136,6 +235,11 @@ void WebPageInspectorController::dispatchMessageFromFrontend(const String& messa
9013-
m_backendDispatcher->dispatch(message);
9014-
}
9015-
9016-
+bool WebPageInspectorController::dispatchMessageToTargetBackend(const String& message)
9017-
+{
9018-
+ return m_backendDispatcher->dispatch(message, BackendDispatcher::Mode::ContinueIfDomainIsMissing) == BackendDispatcher::DispatchResult::Finished;
9019-
+}
9020-
+
9021-
#if ENABLE(REMOTE_INSPECTOR)
9022-
void WebPageInspectorController::setIndicating(bool indicating)
9023-
{
9024-
@@ -150,6 +254,55 @@ void WebPageInspectorController::setIndicating(bool indicating)
8930+
@@ -150,6 +249,55 @@ void WebPageInspectorController::setIndicating(bool indicating)
90258931
}
90268932
#endif
90278933

@@ -9077,7 +8983,7 @@ index 1861cff806131196ea49b4f8aca6665beebbf6e8..7287fd4bbc06a5791190454bedf02190
90778983
void WebPageInspectorController::createInspectorTarget(const String& targetId, Inspector::InspectorTargetType type)
90788984
{
90798985
addTarget(InspectorTargetProxy::create(m_page, targetId, type));
9080-
@@ -169,6 +322,33 @@ void WebPageInspectorController::sendMessageToInspectorFrontend(const String& ta
8986+
@@ -169,6 +317,33 @@ void WebPageInspectorController::sendMessageToInspectorFrontend(const String& ta
90818987
m_targetAgent->sendMessageFromTargetToFrontend(targetId, message);
90828988
}
90838989

@@ -9111,7 +9017,7 @@ index 1861cff806131196ea49b4f8aca6665beebbf6e8..7287fd4bbc06a5791190454bedf02190
91119017
bool WebPageInspectorController::shouldPauseLoading(const ProvisionalPageProxy& provisionalPage) const
91129018
{
91139019
if (!m_frontendRouter->hasFrontends())
9114-
@@ -188,7 +368,7 @@ void WebPageInspectorController::setContinueLoadingCallback(const ProvisionalPag
9020+
@@ -188,7 +363,7 @@ void WebPageInspectorController::setContinueLoadingCallback(const ProvisionalPag
91159021

91169022
void WebPageInspectorController::didCreateProvisionalPage(ProvisionalPageProxy& provisionalPage)
91179023
{
@@ -9120,7 +9026,7 @@ index 1861cff806131196ea49b4f8aca6665beebbf6e8..7287fd4bbc06a5791190454bedf02190
91209026
}
91219027

91229028
void WebPageInspectorController::willDestroyProvisionalPage(const ProvisionalPageProxy& provisionalPage)
9123-
@@ -241,4 +421,20 @@ void WebPageInspectorController::addTarget(std::unique_ptr<InspectorTargetProxy>
9029+
@@ -241,4 +416,20 @@ void WebPageInspectorController::addTarget(std::unique_ptr<InspectorTargetProxy>
91249030
m_targets.set(target->identifier(), WTFMove(target));
91259031
}
91269032

@@ -9142,7 +9048,7 @@ index 1861cff806131196ea49b4f8aca6665beebbf6e8..7287fd4bbc06a5791190454bedf02190
91429048
+
91439049
} // namespace WebKit
91449050
diff --git a/Source/WebKit/UIProcess/Inspector/WebPageInspectorController.h b/Source/WebKit/UIProcess/Inspector/WebPageInspectorController.h
9145-
index 9ce5ef36b652fd56a843c1d12a4c3c3cf639282c..9b6a239b6db52a55f693654ed65d89dff8dd0ffb 100644
9051+
index 9ce5ef36b652fd56a843c1d12a4c3c3cf639282c..bb4d6b26bf245aebc2bd0f435a7bb83151331961 100644
91469052
--- a/Source/WebKit/UIProcess/Inspector/WebPageInspectorController.h
91479053
+++ b/Source/WebKit/UIProcess/Inspector/WebPageInspectorController.h
91489054
@@ -26,17 +26,27 @@
@@ -9215,13 +9121,7 @@ index 9ce5ef36b652fd56a843c1d12a4c3c3cf639282c..9b6a239b6db52a55f693654ed65d89df
92159121

92169122
bool hasLocalFrontend() const;
92179123

9218-
@@ -60,15 +97,28 @@ public:
9219-
void disconnectAllFrontends();
9220-
9221-
void dispatchMessageFromFrontend(const String& message);
9222-
+ bool dispatchMessageToTargetBackend(const String&);
9223-
9224-
#if ENABLE(REMOTE_INSPECTOR)
9124+
@@ -65,10 +102,22 @@ public:
92259125
void setIndicating(bool);
92269126
#endif
92279127

@@ -9244,15 +9144,15 @@ index 9ce5ef36b652fd56a843c1d12a4c3c3cf639282c..9b6a239b6db52a55f693654ed65d89df
92449144
bool shouldPauseLoading(const ProvisionalPageProxy&) const;
92459145
void setContinueLoadingCallback(const ProvisionalPageProxy&, WTF::Function<void()>&&);
92469146

9247-
@@ -84,6 +134,7 @@ private:
9147+
@@ -84,6 +133,7 @@ private:
92489148
void createLazyAgents();
92499149

92509150
void addTarget(std::unique_ptr<InspectorTargetProxy>&&);
92519151
+ void adjustPageSettings();
92529152

92539153
Ref<Inspector::FrontendRouter> m_frontendRouter;
92549154
Ref<Inspector::BackendDispatcher> m_backendDispatcher;
9255-
@@ -92,11 +143,16 @@ private:
9155+
@@ -92,11 +142,16 @@ private:
92569156
WebPageProxy& m_page;
92579157

92589158
Inspector::InspectorTargetAgent* m_targetAgent;

0 commit comments

Comments
 (0)