Closed
Bug 1333953
Opened 8 years ago
Closed 7 years ago
Theming API - validate colors in the schema
Categories
(WebExtensions :: Themes, defect, P2)
WebExtensions
Themes
Tracking
(Not tracked)
RESOLVED
FIXED
mozilla61
People
(Reporter: mattw, Assigned: ntim, Mentored)
References
Details
(Whiteboard: user-story, triaged, [ntim-intern-project])
Attachments
(1 obsolete file)
The engineering plan mentions supporting a wide range of color values that we'll eventually support. The way we currently handle this is by accepting arbitrary strings and then validating them in the script. However, it would be more efficient and somewhat less prone to bugs if we could catch these errors during schema validation.
Based on the engineering document, at least the following values should be supported:
- 3-digit and 6-digit hex values
- rgb and rgba values
- hsl and hsla values
Comment 1•8 years ago
|
||
Right now we don't have any special validation for the colors, but if they're not of the 3- or 4-length array type that Chrome uses, then they will get validated as a CSS color when they're applied. If they aren't a valid CSS color, then no value will get applied for that property. There isn't any explicit error presented to the theme author.
This doesn't seem like something that we should block enabling on Nightly for. I'll remove this from blocking that bug.
No longer blocks: 1341722
Reporter | ||
Updated•8 years ago
|
Updated•8 years ago
|
Updated•7 years ago
|
Priority: -- → P5
Comment 2•7 years ago
|
||
mass move of existing themes bugs to new WebExtensions: Themes component
Component: WebExtensions: Frontend → WebExtensions: Themes
Assignee | ||
Comment 3•7 years ago
|
||
P2, because right now we expose internal CSS variables to themes.
Priority: P5 → P2
Updated•7 years ago
|
Assignee: nobody → anejaalisha
Status: NEW → ASSIGNED
Updated•7 years ago
|
Mentor: jaws, ntim.bugs
Comment 4•7 years ago
|
||
The schema for themes is located at /toolkit/components/extensions/schemas/theme.json and the code to validate it would be embedded in the schema. We already have some validation that you can see there for the ThemeColor, but we also allow a String as a choice which is what this bug is concerned about.
For string names we should probably only support the color names listed in https://searchfox.org/mozilla-central/source/gfx/src/nsColorNameList.h. Unfortunately I don't see a good way for us to include that list during build time so we may need to duplicate it. It would be nice to have a test that tries all of the values we support, this way the test would fail if a new color name gets introduced. I don't know of an API to get those color names though.
In addition, we should make sure that we support each of these values:
- 3-digit, 6-digit, and 8-digit (new since this bug was filed) hex values
- rgb and rgba values
- hsl and hsla values
Comment 5•7 years ago
|
||
I largely understood what needs to be done, but where do you want me to place the duplicated file for the color names?
Flags: needinfo?(jaws)
Assignee | ||
Comment 6•7 years ago
|
||
It's probably not a new file, just a list of colors in a regex pattern.
Comment 7•7 years ago
|
||
Yeah, I agree with comment 6. It would just be located inside of theme.json.
Flags: needinfo?(jaws)
Comment 8•7 years ago
|
||
Sorry for the back and forth here, but I talked more with Tim and we've decided to simplify this a bit.
Instead of adding one long regex pattern to theme.json, we can allow all string values to pass through the schema, and then use _sanitizeCSSColor to convert color names to their proper RGBA values. We'll want to change the function so it doesn't strip the alpha component, possibly adding a boolean argument that can be passed in to remove the alpha component and updating the one callsite to use that argument.
Then we can use regex for the other types of validation.
Comment 9•7 years ago
|
||
Okay, that makes sense. Thanks!
Comment 10•7 years ago
|
||
If we are verifying the names of colors in _sanitizeCSSColor, how should I get the color names? Should it be hardcoded in /toolkit/modules/LightweightThemeConsumer.jsm or dynamically load from https://searchfox.org/mozilla-central/source/gfx/src/nsColorNameList.h?
Flags: needinfo?(jaws)
Assignee | ||
Comment 11•7 years ago
|
||
(In reply to anejaalisha from comment #10)
> If we are verifying the names of colors in _sanitizeCSSColor, how should I
> get the color names? Should it be hardcoded in
> /toolkit/modules/LightweightThemeConsumer.jsm or dynamically load from
> https://searchfox.org/mozilla-central/source/gfx/src/nsColorNameList.h?
getComputedStyle should convert the colors to rgba automatically, getting rid of the names.
Comment 12•7 years ago
|
||
I probably just want to make sure if my understanding is correct. In the function call, I have hardcoded 'true' for now to take your feedback. I'll change it later.
Am I on the right track?
Flags: needinfo?(ntim.bugs)
Attachment #8950079 -
Flags: feedback?(ntim.bugs)
Attachment #8950079 -
Flags: feedback?(jaws)
Comment 13•7 years ago
|
||
Comment on attachment 8950079 [details] [diff] [review]
Bug1333953.patch
Review of attachment 8950079 [details] [diff] [review]:
-----------------------------------------------------------------
Yeah, that's the right idea.
Attachment #8950079 -
Flags: feedback?(jaws) → feedback+
Updated•7 years ago
|
Flags: needinfo?(jaws)
Assignee | ||
Updated•7 years ago
|
Flags: needinfo?(ntim.bugs)
Assignee | ||
Comment 14•7 years ago
|
||
Comment on attachment 8950079 [details] [diff] [review]
Bug1333953.patch
Review of attachment 8950079 [details] [diff] [review]:
-----------------------------------------------------------------
You'll also need to use _sanitizeCSSColor in other calls of _setProperty as well, with alpha set to true.
::: toolkit/modules/LightweightThemeConsumer.jsm
@@ +133,5 @@
> root.style.removeProperty("--lwt-text-color");
> root.style.removeProperty("--lwt-accent-color");
> let textcolor = aData.textcolor || "black";
> _setProperty(root, active, "--lwt-text-color", textcolor);
> + _setProperty(root, active, "--lwt-accent-color", this._sanitizeCSSColor(aData.accentcolor, true) || "white");
This should probably have the alpha parameter set to false.
Attachment #8950079 -
Flags: feedback?(ntim.bugs)
Comment 15•7 years ago
|
||
anejaalisha, have you been able to make any progress on this?
Flags: needinfo?(anejaalisha)
Assignee | ||
Comment 16•7 years ago
|
||
I might actually be tackling this in bug 1417883 (the second patch)
Flags: needinfo?(anejaalisha)
Assignee | ||
Comment 17•7 years ago
|
||
Fixed by the refactor in bug 1417883. Bug 1449327 is adding tests for sanitization.
Assignee: anejaalisha → ntim.bugs
Status: ASSIGNED → RESOLVED
Closed: 7 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla61
Updated•7 years ago
|
Product: Toolkit → WebExtensions
Updated•7 years ago
|
Attachment #8950079 -
Attachment is obsolete: true
Updated•7 years ago
|
Whiteboard: user-story, triaged → user-story, triaged, [ntim-intern-project]
You need to log in
before you can comment on or make changes to this bug.
Description
•