Commit Graph
3469 Commits
Author SHA1 Message Date
GarboMuffin 40394f0c43 Revert "Move allAsyncExtensionsLoaded call from installTargets to _loadExtensions"
The async extensions loading counter is not the most reliable thing,
so let's not break block sharing if something went wrong.

This reverts commit 042f979d59.
2022-11-05 21:47:37 -05:00
GarboMuffin cd40f38f76 Make global.Scratch actually unique per extension
and add some tests for unsandboxed extensions
2022-11-05 20:28:53 -05:00
GarboMuffin badf74d28d Remove unnecessary duplicate ArgumentType set 2022-11-05 20:25:27 -05:00
GarboMuffin bffa0ac77c Allow loading custom extensions from file:
Regression from the unsandboxed extension changes. This matters in eg. the packager.
2022-11-05 19:12:05 -05:00
GarboMuffin 042f979d59 Move allAsyncExtensionsLoaded call from installTargets to _loadExtensions 2022-11-05 19:10:57 -05:00
GarboMuffin 6845e17bb9 Update a comment 2022-11-05 19:10:35 -05:00
GarboMuffin d67898291e Reject allAsyncExtensionsLoaded if an async extension fails to load 2022-10-29 23:02:41 -05:00
GarboMuffin d2dbf86035 Improve error messages for extension script errors
Browsers won't tell us any specifics, but the console will let the user find out what happened.
2022-10-29 22:58:15 -05:00
GarboMuffin ae7526f156 Merge branch 'extensions-update' into develop
This adds a new mode of custom extension that runs outside of any
sandbox -- they're just <script> tags. This is disabled by default and
needs explicit opt-in. Documentation will be written later.

This also will save the URLs of the loaded custom extensions to
project.json when serializing a project. When deserializing a project,
this list can be read to automatically load the extensions. This, again,
is disabled by default and requires explicit opt-in.

A new mechanism called the SecurityManager was added to the extension
manager to facilitate these new features. This replaces workerMode and
is a breaking change.

Various other custom extension related changes were also added:
 - Reject invalid URLs in loadExtensionURL
 - Various cleanup and refactoring
2022-10-29 22:55:08 -05:00
GarboMuffin abdae22a19 Disable future calls to register() when extension has finished loading 2022-10-29 22:49:10 -05:00
GarboMuffin 1549d40868 Add Scratch.extensions.unsandboxed boolean 2022-10-29 22:34:46 -05:00
GarboMuffin 96d76031bb Add Scratch.vm and Scratch.renderer to unsandboxed extension API 2022-10-29 22:34:30 -05:00
GarboMuffin dcc0d961d7 Automatically load custom extensions saved in project
Requires disabled-by-default security manager configuration
2022-10-22 22:02:30 -05:00
GarboMuffin 1e35432db0 Update format for saving custom extensions
Use a dictionary instead. Lets the VM that loads it possibly do some clever things.
Also added a test case.
2022-10-22 21:38:06 -05:00
GarboMuffin bede390599 Refactor extension manager's builtin extension check 2022-10-22 21:30:08 -05:00
GarboMuffin 977470a37d Replace "worker mode" with "sandbox mode" 2022-10-22 20:37:54 -05:00
GarboMuffin e09bdf37cb Replace workerMode with fine-grained per-extension control
A new object called the "security manager" has been added. It is supposed to be overwritten by users.
2022-10-22 20:35:42 -05:00
GarboMuffin ebe486b3dc Refactor loadExtensionURL to use async/await 2022-10-22 20:29:09 -05:00
GarboMuffin e965e33ea8 Allow monitors for mouse down, mouse x, mouse y, days since 2000
scratch-vm part. Not strictly necessary, but is more consistent with existing monitors.
https://github.com/TurboWarp/scratch-gui/issues/634
2022-10-22 19:36:34 -05:00
GarboMuffin 6be1b8003d Re-enable last key pressed monitor
Was disabled because hidden monitors are not actually removed from the JSON,
which cause issues when loading the project in vanilla Scratch. We have fixed
that issue in the previous commit.
2022-10-22 18:52:59 -05:00
GarboMuffin b31ca10082 Don't serialize hidden monitors from extensions
Replace our specific tw_getLastKeyPressed hack with a general solution
https://github.com/LLK/scratch-vm/issues/2331
2022-10-22 18:51:16 -05:00
GarboMuffin a4291cef17 Save extension URLs in project.json 2022-10-22 16:12:08 -05:00
GarboMuffin 333a6601ce Allow determining the URL of the loaded extensions 2022-10-22 16:03:30 -05:00
GarboMuffin 326af1930f Clean up unsandboxed extension loader
Remove a bit of global state hackery and prevent concurrent loads
2022-10-22 16:03:05 -05:00
GarboMuffin 1b226fc515 Reject invalid custom extension URLs 2022-10-22 11:05:33 -05:00
GarboMuffin 8fa75e2a3d Remove code duplication in loadExtensionURL 2022-10-22 11:02:42 -05:00
GarboMuffin e78b9b9dc3 Add disabled-by-default unsandboxed extension mode 2022-10-22 00:38:37 -05:00
GarboMuffin 3d75f4759a Fix incorrect mouse position when clientX or clientY is 0
https://github.com/TurboWarp/packager/issues/494
2022-10-21 22:10:22 -05:00
GarboMuffin ab6d10f929 Remove tw-experimental-audio-optimizations
This now lives in TurboWarp/scratch-audio
2022-09-17 18:53:19 -05:00
GarboMuffin d8984c80a2 Ignore error in performance.measure() if browser garbage collects a mark 2022-08-27 22:20:42 -05:00
GarboMuffin 135fa04259 Fix tangent of perfect multiplies of 90
Previously they would return very large or very small numbers when they should instead be returning Infinity or -Infinity
2022-08-27 17:49:42 -05:00
GarboMuffin eb600cfcf8 Replace local extended JSON parser with @turbowarp/json 2022-08-14 19:45:30 -05:00
GarboMuffin 106a1daa1f Remove loadProject ExtendedJSON hack
We now do this in scratch-parser instead.
Moving it to scratch-parser allows the alternative parser to run on
projects loaded from compressed files in addition to JSON projects
2022-08-14 19:39:57 -05:00
GarboMuffin dc9b3f6055 Fix error in uint8ArrayToBase64 when input is too large 2022-08-13 14:45:33 -05:00
GarboMuffin 6db9599f2e Do not use md5 to generate asset IDs in packaged runtime mode
md5 unnecessary in this mode and slows project load by ~10%.
2022-08-05 00:18:09 -05:00
GarboMuffin 9815a27470 Remove references to original asset in packaged runtime mode 2022-08-05 00:17:53 -05:00
GarboMuffin b78dc53c8e Set runtime.isPackaged=true when convertToPackagedRuntime is called 2022-08-05 00:17:47 -05:00
GarboMuffin 9045311a98 Revert "Fix custom extension inputs with default value "" being converted to undefined"
This reverts commit 3afb16c831.
2022-08-02 13:05:17 -05:00
GarboMuffin 458b9b7aad Allow rotation center preservation in exported SVGs
Requires additional changes in scratch-gui
2022-08-01 23:50:50 -05:00
GarboMuffin 45a4ca767a Handle weird edge case when createImageBitmap returns undefined
This should already be prevented, but in case it happens anyways, handle the error.
2022-07-31 15:59:20 -05:00
GarboMuffin 20258b5a7d Limit number of concurrent createImageBitmap calls
Browsers, especially Chrome, crumble when we try to create too many
image bitmaps at once. So we'll queue them up when too many are
happening. Projects will load slightly slower but this is still much
faster than <img> with data: URIs
2022-07-31 14:06:51 -05:00
GarboMuffin 125f20b9ce Revert "Don't use createImageBitmap to load bitmap costumes"
Reverts 7abbcdbb10

I am unable to reproduce the claim that ImageBitmap uses more memory
than <img>. Instead I've observed the following:

<img> uses a base64 data: URI which is slower than creating a Blob
directly from the binary data. I also experimented using a blob: URI
with <img> and did find it to perform better. A future commit may use
this when createImageBitmap() is not available.

<img> can't be reliably decoded in parallel. Chrome in particular will
very often wait until texImage2d() to actually decode the image, which
turns image decoding into a single-threaded process. Calling decode()
does not affect this. createImageBitmap is reliably parallelized.

<img>'s only benefit is that projects with a lot of copies of the same
exact costume will usually have their image decoding happen only once
whereas createImageBitmap() will decode each one individually (does not
apply when using blob: URIs).

Chrome:
<img> with data:    48.5MB  4160ms
<img> with blob:    48.4MB  2162ms
createImageBitmap() 48.4MB  1261ms
Equivalent SVGs     60.8MB  3857ms

Firefox:
<img> with data:    88.3MB  3704ms
<img> with blob:    88.9MB  2459ms
createImageBitmap() 92.5MB  2380ms
Equivalent SVGs     483.3MB 5429ms

Using a test project with 100 480x360 unique costumes.
Equivalent SVGs is the same project with each costume converted to SVG,
just for curiosity. Note that SVGs may not actually be rendered or
decoded until the project starts.
2022-07-31 01:51:23 -05:00
GarboMuffin 21eff9a311 Remove autoplay restriction from iframe extension worker feature policy
Regardless of this, the browser is not guaranteed to actually let the page play audio
We just won't add our own restriction on top of the browser's
2022-07-27 16:10:52 -05:00
GarboMuffin 3afb16c831 Fix custom extension inputs with default value "" being converted to undefined 2022-07-27 16:09:39 -05:00
GarboMuffin 7ea25cbbe8 Fix turbo mode stored in project not appearing in GUI state 2022-07-18 16:34:35 -05:00
Thomas Weber bbd9631a41 Only call renderer.markSkinAsPrivate if it exists 2022-07-13 23:47:03 -05:00
Thomas Weber 2257f975f8 Remove explicit allow from iframe worker feature policy
Feature policy is allow by default.
2022-07-12 01:22:19 -05:00
Thomas Weber 91afd10407 scratchx: Use block color like ScratchX 2022-07-09 19:19:55 -05:00
Thomas Weber 40a9ae057d scratchx: Force upgrade all $.ajax URLs to HTTPS 2022-07-09 19:07:05 -05:00
Thomas Weber c4fa4a84a8 Set Runtime.currentStepTime to a number by default instead of null 2022-07-09 16:28:28 -05:00