Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upProvide a Sender for ServiceWorker object to communicate to its ServiceWorkerGlobalScope #12773
Comments
|
It could be an IpcSender to the ServiceWorkerManager which could route the messages, I suppose. |
|
To work around the cyclic issues, one option might be to do something like the OpaqueScriptLayoutChannel we used to have: 49d244d#diff-ac20d4dfaff4522ec78bdd6f12f7445cL233 . There may also be a way to use traits in a similar fashion as the rest of that commit... |
|
Although |
|
Another idea: if we have a set of messages that can be sent to the ServiceWorkerGlobalScope from the ServiceWorker by routing them through the Constellation, what if those messages are defined in |
|
Using a seperate message in |
|
Sending |
|
So, do you mean something like below would work ? The vec is fn PostMessage(&self, cx: *mut JSContext, message: HandleValue) -> ErrorResult {
let data = try!(StructuredCloneData::write(cx, message));
let mut msg_vec : Vec<u64> = Vec::new();
let mut msg_ptr = msg_vec.as_mut_ptr();
data.move_to_arraybuffer(msg_ptr);
if let Some(ref sender) = *self.msg_sender.borrow() {
let _ = sender.send(msg_vec);
}
Ok(())
}where /// converts a StructuredCloneData to Vec<u64>
pub fn move_to_arraybuffer(&self, dst: *mut u64) {
unsafe {
ptr::copy_nonoverlapping(self.data, dst, self.nbytes);
}
}Correct me if i misunderstood the way of converting a StructuredClone to a |
|
You could extract the bytes with slice::from_raw_parts(self.data, self.nbytes).to_vec()but the idea was very much to send pub unsafe fn new(data: *mut u64, nbytes: size_t) -> StructuredCloneData {}
pub unsafe fn extract(self) -> (*mut u64, size_t) {} |
|
Pointers don't serialize over IPC channels, hence the Vec I propose. @creativcoder, that should work, but the Vec needs to reserve the right number of bytes and use u8 to ensure that nbytes is correct. |
Implement postMessage for ServiceWorkers <!-- Please describe your changes on the following line: --> Fixes #12773 r? @jdm Changes: * Implements `postMessage` on `ServiceWorker` object. * Removes unused channels from sw and their scopes. * Fixes a crash when calling `scope.script_chan()` in sw-scopes event handling. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix #12773 <!-- Either: --> - [X] There are tests for these changes at `tests/html/service-worker` <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/12910) <!-- Reviewable:end -->
Note: This is assigned to myself.
In order to implement the postMessage api for the
ServiceWorkerobject, we need to have a Sender to its correspondingServiceWorkerGlobalScope. From the current implementation of SW api's, we do not have a way to store aSender<ServiceWorkerScriptMsg>, inServiceWorkerobject as the creation of object and its global scope is decoupled with the global scope being created inside theServiceWorkerManagerat a later stage.The issue has been described here discussing approaches.
Need suggestions from @jdm