Commit c1fe3ed2 authored by Becca Hughes's avatar Becca Hughes Committed by Commit Bot

[CSS Env Vars] Add WebFeatures for env()

Add WebFeature UseCounters for when env() is used and for when
each safe area inset variable is used.

These should also be exposed to UKM so we can cross reference
with our UKM event.

BUG=855739

Change-Id: Ib5e4f26752a279c9696a050bd42dd5842fe28cb0
Reviewed-on: https://chromium-review.googlesource.com/1112698Reviewed-by: default avatarEmil A Eklund <eae@chromium.org>
Reviewed-by: default avatarRobert Kaplow <rkaplow@chromium.org>
Commit-Queue: Becca Hughes <beccahughes@chromium.org>
Cr-Commit-Position: refs/heads/master@{#571144}
parent 9ca72e1a
......@@ -41,6 +41,11 @@ bool IsAllowedUkmFeature(blink::mojom::WebFeature feature) {
WebFeature::kCustomElementRegistryDefine,
WebFeature::kTextToSpeech_Speak,
WebFeature::kTextToSpeech_SpeakDisallowedByAutoplay,
WebFeature::kCSSEnvironmentVariable,
WebFeature::kCSSEnvironmentVariable_SafeAreaInsetTop,
WebFeature::kCSSEnvironmentVariable_SafeAreaInsetLeft,
WebFeature::kCSSEnvironmentVariable_SafeAreaInsetRight,
WebFeature::kCSSEnvironmentVariable_SafeAreaInsetBottom,
}));
return opt_in_features.count(feature);
}
......@@ -1948,6 +1948,11 @@ enum WebFeature {
kLegacySymantecCertInSubresource = 2485,
kLegacySymantecCertInSubframeMainResource = 2486,
kEventTimingExplicitlyRequested = 2487,
kCSSEnvironmentVariable = 2488,
kCSSEnvironmentVariable_SafeAreaInsetTop = 2489,
kCSSEnvironmentVariable_SafeAreaInsetLeft = 2490,
kCSSEnvironmentVariable_SafeAreaInsetBottom = 2491,
kCSSEnvironmentVariable_SafeAreaInsetRight = 2492,
// Add new features immediately above this line. Don't change assigned
// numbers of any item, and don't reuse removed slots.
......
......@@ -6,9 +6,28 @@
#include "third_party/blink/renderer/core/css/style_engine.h"
#include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/frame/use_counter.h"
#include "third_party/blink/renderer/core/frame/web_feature.h"
#include "third_party/blink/renderer/platform/wtf/string_hasher.h"
namespace blink {
// static
unsigned DocumentStyleEnvironmentVariables::GenerateHashFromName(
const AtomicString& name) {
StringHasher hasher;
if (name.Is8Bit()) {
String name_str = String(name);
name_str.Ensure16Bit();
hasher.AddCharacters(name_str.Characters16(), name_str.length());
} else {
hasher.AddCharacters(name.Characters16(), name.length());
}
return hasher.GetHash();
}
// static
scoped_refptr<DocumentStyleEnvironmentVariables>
DocumentStyleEnvironmentVariables::Create(StyleEnvironmentVariables& parent,
......@@ -24,8 +43,11 @@ DocumentStyleEnvironmentVariables::Create(StyleEnvironmentVariables& parent,
CSSVariableData* DocumentStyleEnvironmentVariables::ResolveVariable(
const AtomicString& name) {
unsigned id = GenerateHashFromName(name);
RecordVariableUsage(id);
// Mark the variable as seen so we will invalidate the style if we change it.
seen_variables_.insert(name);
seen_variables_.insert(id);
return StyleEnvironmentVariables::ResolveVariable(name);
}
......@@ -34,7 +56,7 @@ void DocumentStyleEnvironmentVariables::InvalidateVariable(
DCHECK(document_);
// Invalidate the document if we have seen this variable on this document.
if (seen_variables_.Contains(name))
if (seen_variables_.Contains(GenerateHashFromName(name)))
document_->GetStyleEngine().EnvironmentVariableChanged();
StyleEnvironmentVariables::InvalidateVariable(name);
......@@ -44,4 +66,32 @@ DocumentStyleEnvironmentVariables::DocumentStyleEnvironmentVariables(
Document& document)
: document_(&document) {}
void DocumentStyleEnvironmentVariables::RecordVariableUsage(unsigned id) {
UseCounter::Count(document_, WebFeature::kCSSEnvironmentVariable);
// See the unittest DISABLED_PrintExpectedVariableNameHashes() for how these
// values are computed.
switch (id) {
case 0x3eb492df:
UseCounter::Count(document_,
WebFeature::kCSSEnvironmentVariable_SafeAreaInsetTop);
break;
case 0xe0994c83:
UseCounter::Count(document_,
WebFeature::kCSSEnvironmentVariable_SafeAreaInsetLeft);
break;
case 0x898873a2:
UseCounter::Count(
document_, WebFeature::kCSSEnvironmentVariable_SafeAreaInsetBottom);
break;
case 0xd99fe75b:
UseCounter::Count(document_,
WebFeature::kCSSEnvironmentVariable_SafeAreaInsetRight);
break;
default:
// Do nothing if this is an unknown variable.
break;
}
}
} // namespace blink
......@@ -17,6 +17,9 @@ class Document;
class CORE_EXPORT DocumentStyleEnvironmentVariables
: public StyleEnvironmentVariables {
public:
// Generate a hash from the provided name.
static unsigned GenerateHashFromName(const AtomicString&);
// Create an instance bound to |parent| that will invalidate |document|'s
// style when a variable is changed.
static scoped_refptr<DocumentStyleEnvironmentVariables> Create(
......@@ -36,7 +39,10 @@ class CORE_EXPORT DocumentStyleEnvironmentVariables
private:
DocumentStyleEnvironmentVariables(Document& document);
HashSet<AtomicString> seen_variables_;
// Record variable usage using |UseCounter|.
void RecordVariableUsage(unsigned id);
HashSet<unsigned> seen_variables_;
Persistent<Document> document_;
};
......
......@@ -19067,6 +19067,11 @@ Called by update_net_error_codes.py.-->
<int value="2485" label="LegacySymantecCertInSubresource"/>
<int value="2486" label="LegacySymantecCertInSubframeMainResource"/>
<int value="2487" label="EventTimingExplicitlyRequested"/>
<int value="2488" label="CSSEnvironmentVariable"/>
<int value="2489" label="CSSEnvironmentVariable_SafeAreaInsetTop"/>
<int value="2490" label="CSSEnvironmentVariable_SafeAreaInsetLeft"/>
<int value="2491" label="CSSEnvironmentVariable_SafeAreaInsetBottom"/>
<int value="2492" label="CSSEnvironmentVariable_SafeAreaInsetRight"/>
</enum>
<enum name="FeedbackSource">
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment