Skip to content

Commit

Permalink
[shared storage] Record usage for when addModule() is called with cro…
Browse files Browse the repository at this point in the history
…ss-origin script

Why: We proposed a potentially breaking change to addModule() in
WICG/shared-storage#158. That is, currently,
a website can call addModule() everywhere and expect it to fail when
they're not in their own context; however, with cross-origin script
support, these calls could unexpectedly succeed.

Thus, we track potentially non-forward-compatible addModule() usages to
assess the potential impact and guide further decisions. We anticipate
this usage to be low.

Bug: 350764023
Change-Id: I5da4583ed583baa398bdb2cadf8955d341474050
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5665746
Reviewed-by: Josh Karlin <jkarlin@chromium.org>
Commit-Queue: Yao Xiao <yaoxia@chromium.org>
Reviewed-by: Sun Yueru <yrsun@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1322541}
  • Loading branch information
yaoxiachromium authored and Chromium LUCI CQ committed Jul 3, 2024
1 parent cdafd25 commit 259f6e5
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,7 @@ UseCounterMetricsRecorder::GetAllowedUkmFeatures() {
WebFeature::kV8GPUAdapter_RequestAdapterInfo_Method,
WebFeature::
kSharedStorageAPI_CreateWorklet_CrossOriginScriptDefaultDataOrigin,
WebFeature::kSharedStorageAPI_AddModule_CrossOriginScript,
}));
return *opt_in_features;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4394,6 +4394,7 @@ enum WebFeature {
kV8MLContext_Dispatch_Method = 5025,
kCSSMixins = 5026,
kDurationFormat = 5027,
kSharedStorageAPI_AddModule_CrossOriginScript = 5028,

// Add new features immediately above this line. Don't change assigned
// numbers of any item, and don't reuse removed slots. Also don't add extra
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,16 @@ void SharedStorageWorklet::AddModuleHelper(
scoped_refptr<SecurityOrigin> script_security_origin =
SecurityOrigin::Create(script_source_url);

if (!resolve_to_worklet &&
!execution_context->GetSecurityOrigin()->IsSameOriginWith(
script_security_origin.get())) {
// This `addModule()` call could be affected by the breaking change
// proposed in https://github.com/WICG/shared-storage/pull/158. Measure its
// usage.
execution_context->CountUse(
WebFeature::kSharedStorageAPI_AddModule_CrossOriginScript);
}

if (!cross_origin_script_allowed_ &&
!execution_context->GetSecurityOrigin()->IsSameOriginWith(
script_security_origin.get())) {
Expand Down
1 change: 1 addition & 0 deletions tools/metrics/histograms/enums.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11157,6 +11157,7 @@ Called by update_use_counter_feature_enum.py.-->
<int value="5025" label="V8MLContext_Dispatch_Method"/>
<int value="5026" label="CSSMixins"/>
<int value="5027" label="DurationFormat"/>
<int value="5028" label="SharedStorageAPI_AddModule_CrossOriginScript"/>
</enum>

<enum name="FeaturePolicyFeature">
Expand Down

0 comments on commit 259f6e5

Please sign in to comment.