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 upHandle crossorigin in Link #14940
Handle crossorigin in Link #14940
Conversation
highfive
commented
Jan 10, 2017
|
Heads up! This PR modifies the following files: |
|
I'm glad to see more tests passing. I've made a few suggestions for ways to avoid duplicating code. |
| @@ -377,6 +387,32 @@ impl HTMLLinkElementMethods for HTMLLinkElement { | |||
| // https://html.spec.whatwg.org/multipage/#dom-link-target | |||
| make_setter!(SetTarget, "target"); | |||
|
|
|||
| // https://html.spec.whatwg.org/multipage/#dom-link-crossorigin | |||
This comment has been minimized.
This comment has been minimized.
jdm
Jan 10, 2017
Member
This should be using an enumerated getter instead: https://dxr.mozilla.org/servo/rev/124301cf484818a87ab0b3e0c4ef34645be66174/components/script/dom/htmlimageelement.rs#296
This comment has been minimized.
This comment has been minimized.
nmvk
Jan 11, 2017
Author
Contributor
Using enumerated_getter always returns default crossorigin value as anonymous. This value is returned even if request is not a valid crossorigin request. This breaks many test case.
This comment has been minimized.
This comment has been minimized.
jdm
Jan 11, 2017
Member
You're right. Could we share this code with htmlscriptelement.rs instead of duplicating it, in that case?
This comment has been minimized.
This comment has been minimized.
| } | ||
|
|
||
| // https://html.spec.whatwg.org/multipage/#dom-link-crossorigin | ||
| fn SetCrossOrigin(&self, value: Option<DOMString>) { |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
jdm
Jan 11, 2017
Member
My mistake; it can't. Let's add another set_cross_origin_attribute helper we can call from both HTMLLinkElement and HTMLScriptElement.
| @@ -235,6 +237,14 @@ impl HTMLLinkElement { | |||
| } | |||
| }; | |||
|
|
|||
| // Step 3 | |||
| let cors_setting = match self.GetCrossOrigin() { | |||
This comment has been minimized.
This comment has been minimized.
jdm
Jan 10, 2017
Member
Let's make a helper function for this and share it with htmlscriptelement.rs.
This comment has been minimized.
This comment has been minimized.
nmvk
Jan 11, 2017
Author
Contributor
I have added a method in request.rs which given a &str returns CorsSettings. I am not sure if this is good refactoring. Other option could be return CorsSettings given DomString but I dont know what is the right location for such utility.
This comment has been minimized.
This comment has been minimized.
jdm
Jan 11, 2017
Member
I propose the following in element.rs:
fn reflect_cross_origin_attribute(element: &Element) -> Option<DOMString> {
// body of HTMLScriptElement::GetCrossOrigin
}
fn cors_setting_for_element(element: &Element) -> Option<CorsSetting> {
reflect_cross_origin_attribute(element).map(|attr| {
// body of CorsSetting::from_str_ref
})
}Then these can be called by both HTMLLinkElement and HTMLScriptElement as necessary.
| @@ -244,6 +255,6 @@ impl<'a> StylesheetLoader<'a> { | |||
|
|
|||
| impl<'a> StyleStylesheetLoader for StylesheetLoader<'a> { | |||
| fn request_stylesheet(&self, import: &Arc<RwLock<ImportRule>>) { | |||
| self.load(StylesheetContextSource::Import(import.clone()), "".to_owned()) | |||
| self.load(StylesheetContextSource::Import(import.clone()), None, "".to_owned()) | |||
This comment has been minimized.
This comment has been minimized.
jdm
Jan 10, 2017
Member
Let's add a TODO comment about whether we should use the original loader's CORS setting. I don't find any direction from the specification about it.
|
|
Implemented Step three and handled step four of obtain the resource part of 4.2.4 The link element. Link to spec : https://html.spec.whatwg.org/multipage/semantics.html#concept-link-obtain Refactored crossOrigin handling in HTMLScriptElement, HTMLImageElement
|
@jdm Thanks, I have addressed review comments. Additionally I refactored |
|
@bors-servo: r+ |
|
|
Handle crossorigin in Link Implemented Step three and handled step four of obtain the resource part of 4.2.4 The link element. Link to spec : https://html.spec.whatwg.org/multipage/semantics.html#concept-link-obtain <!-- Please describe your changes on the following line: --> --- <!-- 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 <!-- Either: --> - [X] There are tests for these changes OR <!-- 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/14940) <!-- Reviewable:end -->
|
|
nmvk commentedJan 10, 2017
•
edited
Implemented Step three and handled step four of obtain the resource part
of 4.2.4 The link element.
Link to spec : https://html.spec.whatwg.org/multipage/semantics.html#concept-link-obtain
./mach build -ddoes not report any errors./mach test-tidydoes not report any errorsThis change is