Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Put Blob URL online #12440

Merged
merged 1 commit into from Jul 15, 2016
Merged

Put Blob URL online #12440

merged 1 commit into from Jul 15, 2016

Conversation

@izgzhen
Copy link
Contributor

izgzhen commented Jul 14, 2016

This PR connects the resource requests with file manager thread, including:

  • script_thread load request
  • image_cache_thread load request
  • XHR load request (the responding part code yet not implemented due to unfamiliarity with fetch standard, but the infra is here)

One notable change is the introduction of "long-live validity", to handle the case specified in WPT test FileAPI/blob/Blob-XHR-revoke.html.

r? @Manishearth


  • ./mach build -d does not report any errors
  • ./mach test-tidy does not report any errors
  • These changes fix #10539
  • There are tests for these changes

This change is Reviewable

@highfive
Copy link

highfive commented Jul 14, 2016

Heads up! This PR modifies the following files:

  • @KiChjang: components/net/filemanager_thread.rs, components/net_traits/blob_url_store.rs, components/net_traits/blob_url_store.rs, components/script/dom/url.rs, components/script/dom/xmlhttprequest.rs, components/net/blob_loader.rs, components/net_traits/filemanager_thread.rs, components/net_traits/filemanager_thread.rs, components/script/script_thread.rs, components/script/dom/htmlinputelement.rs, components/script/dom/blob.rs, components/net/image_cache_thread.rs
@izgzhen
Copy link
Contributor Author

izgzhen commented Jul 14, 2016

Still WIP, welcome comments! (esp. about "long-live")

@izgzhen izgzhen force-pushed the izgzhen:blob-online branch from 6889bd0 to 56d43db Jul 14, 2016
let _ = sender.send(Err(BlobURLStoreError::InvalidOrigin));
}
// Check origin format correctness
if Url::parse(&origin).is_ok() || origin == "file://" {

This comment has been minimized.

@Manishearth

Manishearth Jul 14, 2016

Member

Why do we have a separate check for file://?

This comment has been minimized.

@izgzhen

izgzhen Jul 14, 2016

Author Contributor

Because Url::parse is not happy with an origin equal to file://. It is kinda a hack (related to get_blob_origin, parse_blob_url etc. as well)

This comment has been minimized.

@Manishearth

Manishearth Jul 14, 2016

Member

Oh, I see.

origin: origin.clone(),
file_impl: FileImpl::Memory(blob_buf),
refs: AtomicUsize::new(1),
// Valid here since PromoteMemory implies URL creation

This comment has been minimized.

@Manishearth

Manishearth Jul 14, 2016

Member

Not necessarily, yes? What if a child blob promotes the parent in-memory blob when it is converted to a URL?

We should have validity be a bool option on this function. Call it "valid_as_url" or something

if ref_url.scheme() == "blob" {
let msg = FileManagerThreadMsg::LoadBlob(load_data,
LoadConsumer::Listener(response_target));
self.resource_threads.send(msg).unwrap(); // XXX: unwrap?!

This comment has been minimized.

@Manishearth

Manishearth Jul 14, 2016

Member

No unwrap, just let _ = ..

pub fn get_blob_origin(url: &Url) -> FileOrigin {
if url.scheme() == "file" {
// NOTE: by default this is "null" (Opaque), which is not ideal
"file://".to_string()

This comment has been minimized.

@Manishearth

Manishearth Jul 14, 2016

Member

Aren't file URIs supposed to be considered opaque origin? What's wrong with using the opaque origin in the blob?

This comment has been minimized.

@izgzhen

izgzhen Jul 14, 2016

Author Contributor

Well, FileOrigin is still a unicode-serialization of url::Origin, which, when it is file://, turned into "null"

This comment has been minimized.

@izgzhen

izgzhen Jul 14, 2016

Author Contributor

A lot of things can be null, including file://, so I am trying to make this case more special here. (not a elegant solution though)

This comment has been minimized.

@Manishearth

Manishearth Jul 14, 2016

Member

works for me

core_resource_thread.send(Fetch(init, action_sender)).unwrap();

if init.url.scheme() == "blob" {
resource_threads.send(FileManagerThreadMsg::Fetch(init, action_sender)).unwrap(); // XXX: unwrap?

This comment has been minimized.

@Manishearth

Manishearth Jul 14, 2016

Member

.expect("Resource thread shut down")

@@ -368,6 +373,11 @@ impl XMLHttpRequestMethods for XMLHttpRequest {
// Step 11 - abort existing requests
self.terminate_ongoing_fetch();

// See WPT test: FileAPI/blob/Blob-XHR-revoke.html

This comment has been minimized.

@Manishearth

Manishearth Jul 14, 2016

Member

So this is wrong. I think you're aware of this since you've marked it as a hack 😄

The correct behavior is that XHR queries for validity during open(), and is allowed to access the blob even after the URL validity expires, provided that it was allowed to during open(). Firefox returns an error on invalid blob URIs in open() (for both existing-but-revoked URIs and nonexistant URIs)

We should have a second refcount, which counts the number of XHRs holding on to this. When xhr calls open(), it should send a special message that checks validity and bumps this refcount if still valid; and the message will respond with the validity state (which is now just a bool). When the XHR gets a response or error, it un-bumps the refcount. Deleting an entry from the store is done when the refcounts and validity state are null. HTTP fetches will not fetch URLs with a false validity. New XHR requests will also fail on open() for invalid URIs. Existing XHRs will work fine.

The spec says nothing about this, however 😄

for now, don't include this hack, have a simple validity state and let the test fail. We'll work on clearing up the spec and only then implement it.

This comment has been minimized.

@izgzhen

izgzhen Jul 14, 2016

Author Contributor

That would be good

This comment has been minimized.

@Manishearth

Manishearth Jul 14, 2016

Member

Feel free to make a PR to wpt to remove this test, too, since it's unspecced and inconsistent across browsers. If this gets specced and/or becomes consistent, we can add it again.

We should probably create an issue on a spec somewhere, but right now I'm discussing with baku and we'll figure out which spec we care about.

This comment has been minimized.

@izgzhen

izgzhen Jul 14, 2016

Author Contributor

So I will keep a comment in tree for now.

let msg = FileManagerThreadMsg::LoadBlob(net_load_data, LoadConsumer::Listener(response_target));
self.resource_threads.send(msg).unwrap();
} else {
let msg = CoreResourceMsg::Load(net_load_data, LoadConsumer::Listener(response_target), None);

This comment has been minimized.

@Manishearth

Manishearth Jul 14, 2016

Member

The CoreResource handler should be doing the delegation to the file manager thread, not script_task

This comment has been minimized.

@izgzhen

izgzhen Jul 14, 2016

Author Contributor

Yep, that is one way. But I remembered that we discussed this before and thought CoreResource thread handler might be too busy thus clogged?

This comment has been minimized.

@Manishearth

Manishearth Jul 14, 2016

Member

No, it shouldn't get clogged easily since it just spawns threads for each message.

It could get clogged in cases where we pool, but in that case we shouldn't be giving File fetches any priority over other fetches anyway.

This comment has been minimized.

@izgzhen

izgzhen Jul 14, 2016

Author Contributor

I see. But that will incur some broader restructuring over net process interface so I wonder if I should do it here (since we split filemanagermsg out from core one before)

<body>
<img src="test.jpg" id="image">
<input type="file" id="file-input"">
</body>

This comment has been minimized.

@Manishearth

Manishearth Jul 14, 2016

Member

newline at eof for both tests

@izgzhen izgzhen force-pushed the izgzhen:blob-online branch 3 times, most recently from 5a10e14 to fef71bd Jul 14, 2016
@@ -548,6 +554,7 @@ impl CoreResourceManager {
},
"data" => from_factory(data_loader::factory),
"about" => from_factory(about_loader::factory),
"blob" => blob_loader::factory(self.filemanager_chan.clone()),

This comment has been minimized.

@izgzhen

izgzhen Jul 15, 2016

Author Contributor

@Manishearth I think this might get it right now

@izgzhen izgzhen force-pushed the izgzhen:blob-online branch from fef71bd to 456e2d3 Jul 15, 2016
None, name.as_bytes().to_vec())
]
});
pub fn factory(filemanager_chan: IpcSender<FileManagerThreadMsg>)

This comment has been minimized.

@Manishearth

Manishearth Jul 15, 2016

Member

Perhaps we should take a reference (arc) to the file store instead?

Then again, we already have a filemanager thread, so meh.

This comment has been minimized.

@izgzhen

izgzhen Jul 15, 2016

Author Contributor

Maybe handle the msg to FileManager will make resource_thread.rs look less formidable 😄

@izgzhen izgzhen force-pushed the izgzhen:blob-online branch from 456e2d3 to 932a2a8 Jul 15, 2016
if let Ok(chan) =
start_sending_sniffed_opt(start_chan, metadata, classifier,
&blob_buf.bytes, load_data.context.clone()) {
let _ = chan.send(Payload(blob_buf.bytes));

This comment has been minimized.

@Manishearth

Manishearth Jul 15, 2016

Member

This sends the payload twice, start_sending_sniffed_opt already does this

This comment has been minimized.

@izgzhen

izgzhen Jul 15, 2016

Author Contributor

But partial_body is only used to classify the content as I can tell from the code :/

This comment has been minimized.

@Manishearth
Copy link
Member

Manishearth commented Jul 15, 2016

One small issue, then update test expectations, and should be good to go.

@Manishearth
Copy link
Member

Manishearth commented Jul 15, 2016

@bors-servo try

There should be some new tests passing

@bors-servo
Copy link
Contributor

bors-servo commented Jul 15, 2016

Trying commit 932a2a8 with merge a7ec87c...

bors-servo added a commit that referenced this pull request Jul 15, 2016
Put Blob URL online

This PR connects the resource requests with file manager thread, including:

+ `script_thread` load request
+ `image_cache_thread` load request
+ XHR load request (the responding part code yet not implemented due to unfamiliarity with fetch standard, but the infra is here)

One notable change is the introduction of "long-live validity", to handle the case specified in WPT test FileAPI/blob/Blob-XHR-revoke.html.

r? @Manishearth

<!-- 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
- [x] These changes fix #10539
- [x] There are tests for these changes

<!-- 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/12440)
<!-- Reviewable:end -->
@izgzhen
Copy link
Contributor Author

izgzhen commented Jul 15, 2016

@Manishearth Actually I first thought it will send the Payload for me and didn't write that line code. Should I file an issue on this potentially misleading naming?

@bors-servo
Copy link
Contributor

bors-servo commented Jul 15, 2016

💔 Test failed - linux-dev

@izgzhen izgzhen force-pushed the izgzhen:blob-online branch from 932a2a8 to a364a37 Jul 15, 2016
bors-servo added a commit that referenced this pull request Jul 15, 2016
Put Blob URL online

This PR connects the resource requests with file manager thread, including:

+ `script_thread` load request
+ `image_cache_thread` load request
+ XHR load request (the responding part code yet not implemented due to unfamiliarity with fetch standard, but the infra is here)

One notable change is the introduction of "long-live validity", to handle the case specified in WPT test FileAPI/blob/Blob-XHR-revoke.html.

r? @Manishearth

<!-- 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
- [x] These changes fix #10539
- [x] There are tests for these changes

<!-- 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/12440)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Jul 15, 2016

💔 Test failed - linux-dev

@izgzhen izgzhen force-pushed the izgzhen:blob-online branch from a364a37 to 60b116b Jul 15, 2016
@izgzhen
Copy link
Contributor Author

izgzhen commented Jul 15, 2016

@bors-servo try

Fixed tidy (Feeling like homu would come to GMT 0800 and bite me)

@bors-servo
Copy link
Contributor

bors-servo commented Jul 15, 2016

Trying commit 60b116b with merge 4cc4bc3...

bors-servo added a commit that referenced this pull request Jul 15, 2016
Put Blob URL online

This PR connects the resource requests with file manager thread, including:

+ `script_thread` load request
+ `image_cache_thread` load request
+ XHR load request (the responding part code yet not implemented due to unfamiliarity with fetch standard, but the infra is here)

One notable change is the introduction of "long-live validity", to handle the case specified in WPT test FileAPI/blob/Blob-XHR-revoke.html.

r? @Manishearth

<!-- 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
- [x] These changes fix #10539
- [x] There are tests for these changes

<!-- 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/12440)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Jul 15, 2016

💔 Test failed - linux-rel

@highfive
Copy link

highfive commented Jul 15, 2016

  ▶ PASS [expected FAIL] /FileAPI/url/url_xmlhttprequest_img.html

  ▶ OK [expected TIMEOUT] /workers/constructors/Worker/Blob-url.html

  ▶ Unexpected subtest result in /workers/constructors/Worker/Blob-url.html:
  └ PASS [expected TIMEOUT] Worker supports Blob url
@izgzhen izgzhen force-pushed the izgzhen:blob-online branch from 60b116b to fdc3a8e Jul 15, 2016
@izgzhen
Copy link
Contributor Author

izgzhen commented Jul 15, 2016

@bors-servo try

WPT tests updated

@bors-servo
Copy link
Contributor

bors-servo commented Jul 15, 2016

Trying commit fdc3a8e with merge db547d0...

bors-servo added a commit that referenced this pull request Jul 15, 2016
Put Blob URL online

This PR connects the resource requests with file manager thread, including:

+ `script_thread` load request
+ `image_cache_thread` load request
+ XHR load request (the responding part code yet not implemented due to unfamiliarity with fetch standard, but the infra is here)

One notable change is the introduction of "long-live validity", to handle the case specified in WPT test FileAPI/blob/Blob-XHR-revoke.html.

r? @Manishearth

<!-- 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
- [x] These changes fix #10539
- [x] There are tests for these changes

<!-- 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/12440)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Jul 15, 2016

@Manishearth
Copy link
Member

Manishearth commented Jul 15, 2016

@bors-servo r+

Now that most of the functionality exists, could you go through the list of tests that still fail and ensure that there aren't any tests there that shouldn't be (tests which should pass in Servo but fail)? I'm a bit concerned by the small number of fixed tests in each PR, but it looks like WPT has very few File tests to begin with 😄 so I don't think that's due to imperfections in your changes.

Perhaps we should add more.

@bors-servo
Copy link
Contributor

bors-servo commented Jul 15, 2016

📌 Commit fdc3a8e has been approved by Manishearth

@bors-servo
Copy link
Contributor

bors-servo commented Jul 15, 2016

Testing commit fdc3a8e with merge 0e5893d...

bors-servo added a commit that referenced this pull request Jul 15, 2016
Put Blob URL online

This PR connects the resource requests with file manager thread, including:

+ `script_thread` load request
+ `image_cache_thread` load request
+ XHR load request (the responding part code yet not implemented due to unfamiliarity with fetch standard, but the infra is here)

One notable change is the introduction of "long-live validity", to handle the case specified in WPT test FileAPI/blob/Blob-XHR-revoke.html.

r? @Manishearth

<!-- 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
- [x] These changes fix #10539
- [x] There are tests for these changes

<!-- 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/12440)
<!-- Reviewable:end -->
@izgzhen
Copy link
Contributor Author

izgzhen commented Jul 15, 2016

@Manishearth as I peeked a few days ago, most of the failed tests are due to ArrayBuffer. But yes, I should really consider adding more tests :)

@bors-servo
Copy link
Contributor

bors-servo commented Jul 15, 2016

@bors-servo bors-servo merged commit fdc3a8e into servo:master Jul 15, 2016
1 of 2 checks passed
1 of 2 checks passed
continuous-integration/travis-ci/pr The Travis CI build failed
Details
homu Test successful
Details
@nox
Copy link
Member

nox commented Jul 18, 2016

Would be great to explain why the file manager now needs to be passed to new_core_resource_thread, this isn't made clear in the corresponding commit.

@izgzhen
Copy link
Contributor Author

izgzhen commented Jul 18, 2016

@nox Because the ResourceManager will be responsible to forward the blob URL loading request to file manager as here. So we need to grab a reference to it in the initialisation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

5 participants
You can’t perform that action at this time.