Skip to content

Commit a7d2464

Browse files
committed
fix(runtime/serviceworker): fix 'unregister'
1 parent 3126a28 commit a7d2464

File tree

4 files changed

+31
-13
lines changed

4 files changed

+31
-13
lines changed

src/runtime/ipc/routes.cc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2605,14 +2605,15 @@ static void mapIPCRoutes (Router *router) {
26052605
* @param scope
26062606
*/
26072607
router->map("serviceWorker.unregister", [=](auto message, auto router, auto reply) {
2608-
auto err = validateMessageParameters(message, {"scope"});
2608+
auto err = validateMessageParameters(message, {"id"});
26092609

26102610
if (err.type != JSON::Type::Null) {
26112611
return reply(Result { message.seq, message, err });
26122612
}
26132613

2614-
const auto scope = message.get("scope");
2615-
router->bridge.navigator.serviceWorkerServer->container.unregisterServiceWorker(scope);
2614+
uint64_t id;
2615+
REQUIRE_AND_GET_MESSAGE_VALUE(id, "id", std::stoull);
2616+
router->bridge.navigator.serviceWorkerServer->container.unregisterServiceWorker(id);
26162617

26172618
return reply(Result::Data { message, JSON::Object {} });
26182619
});
@@ -3562,6 +3563,7 @@ static void mapIPCRoutes (Router *router) {
35623563
options.index = targetWindowIndex;
35633564
options.RUNTIME_PRIMORDIAL_OVERRIDES = message.get("__runtime_primordial_overrides__");
35643565
options.userConfig = INI::parse(message.get("config"));
3566+
options.userScript = message.get("userScript");
35653567
options.resourcesDirectory = message.get("resourcesDirectory");
35663568
options.shouldPreferServiceWorker = message.get("shouldPreferServiceWorker", "false") == "true";
35673569

@@ -3580,9 +3582,7 @@ static void mapIPCRoutes (Router *router) {
35803582
createdWindow->navigate(message.get("url"));
35813583
}
35823584

3583-
if (!options.headless) {
3584-
createdWindow->show();
3585-
}
3585+
createdWindow->show();
35863586

35873587
reply(Result::Data { message, createdWindow->json() });
35883588
} else {

src/runtime/serviceworker/container.cc

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,17 @@ namespace ssc::runtime::serviceworker {
290290
return registration;
291291
}
292292

293+
for (const auto& entry : this->registrations) {
294+
const auto& registration = entry.second;
295+
if (registration.options.scriptURL == scriptURL) {
296+
if (this->bridge != nullptr) {
297+
this->bridge->emit("serviceWorker.register", registration.json(true).str());
298+
}
299+
300+
return registration;
301+
}
302+
}
303+
293304
const auto id = options.id > 0 ? options.id : rand64();
294305
this->registrations.insert_or_assign(key, Registration(
295306
id,
@@ -301,7 +312,7 @@ namespace ssc::runtime::serviceworker {
301312
scope,
302313
options.scheme,
303314
options.serializedWorkerArgs,
304-
Registration::Priority::Default,
315+
options.priority,
305316
id
306317
}
307318
));
@@ -323,7 +334,7 @@ namespace ssc::runtime::serviceworker {
323334
const auto key = Registration::key(scope, this->origin);
324335

325336
if (this->registrations.contains(key)) {
326-
const auto& registration = this->registrations.at(scope);
337+
const auto& registration = this->registrations.at(key);
327338
if (this->bridge != nullptr) {
328339
return this->bridge->emit("serviceWorker.unregister", registration.json());
329340
}
@@ -334,13 +345,14 @@ namespace ssc::runtime::serviceworker {
334345

335346
for (const auto& entry : this->registrations) {
336347
if (entry.second.options.scriptURL == scriptURL) {
337-
const auto& registration = this->registrations.at(entry.first);
348+
const auto& registration = entry.second;
338349

339350
if (this->bridge != nullptr) {
340351
return this->bridge->emit("serviceWorker.unregister", registration.json().str());
341352
}
342353

343354
this->registrations.erase(entry.first);
355+
return true;
344356
}
345357
}
346358

@@ -352,7 +364,14 @@ namespace ssc::runtime::serviceworker {
352364

353365
for (const auto& entry : this->registrations) {
354366
if (entry.second.id == id) {
355-
return this->unregisterServiceWorker(entry.first);
367+
const auto& registration = entry.second;
368+
369+
if (this->bridge != nullptr) {
370+
return this->bridge->emit("serviceWorker.unregister", registration.json().str());
371+
}
372+
373+
this->registrations.erase(entry.first);
374+
return true;
356375
}
357376
}
358377

src/runtime/webview/scheme_handlers.cc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,6 @@ namespace ssc::runtime::webview {
462462

463463
auto span = request->tracer.span("handler");
464464

465-
this->bridge.dispatch([this, id, span, handler, callback, request] () mutable {
466465
if (request != nullptr && request->isActive() && !request->isCancelled()) {
467466
handler(request, this->bridge, &request->callbacks, [this, id, span, callback](auto& response) mutable {
468467
// make sure the response was finished before
@@ -486,7 +485,6 @@ namespace ssc::runtime::webview {
486485
} while (0);
487486
});
488487
}
489-
});
490488

491489
return true;
492490
}

src/runtime/window/apple.mm

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -778,6 +778,7 @@ - (void) scrollViewDidScroll: (UIScrollView*) scrollView {
778778
[this->webview removeFromSuperview];
779779
this->webview.navigationDelegate = nullptr;
780780
this->webview.UIDelegate = nullptr;
781+
this->webview = nullptr;
781782
}
782783

783784
if (this->window != nullptr) {
@@ -794,7 +795,6 @@ - (void) scrollViewDidScroll: (UIScrollView*) scrollView {
794795
}
795796

796797
[this->window performClose: nullptr];
797-
this->window = nullptr;
798798
this->window.webview = nullptr;
799799
this->window.delegate = nullptr;
800800
this->window.contentView = nullptr;
@@ -807,6 +807,7 @@ - (void) scrollViewDidScroll: (UIScrollView*) scrollView {
807807
}
808808

809809
this->window.titleBarView = nullptr;
810+
this->window = nullptr;
810811
#endif
811812
}
812813
}

0 commit comments

Comments
 (0)