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

Add file backend support for Blob and related #11221

Merged
merged 1 commit into from Jun 1, 2016
Merged

Add file backend support for Blob and related #11221

merged 1 commit into from Jun 1, 2016

Conversation

izgzhen
Copy link
Contributor

@izgzhen izgzhen commented May 17, 2016

Major changes

  1. Add new backend to Blob and a BlobImpl struct to abstract multiple backends
  2. Rewrite most interfaces of Blob to accommodate the change
  3. Change the read behaviour of FileReader, considering the case when blob is file-backed and not cached

The design is still immature, welcome comments!

Problems to resolve

  • I used DOMRefCell to cache the bytes in BlobImpl, is it sound?
  • The interfaces (like BlobImpl::get_bytes) handle requests in a default-to-empty way when the inner DataSlice is not cached. It might be possible to handle this condition better.

This change is Reviewable

@highfive
Copy link

Heads up! This PR modifies the following files:

  • @KiChjang: components/script/dom/testbinding.rs, components/script/dom/file.rs, components/script/dom/xmlhttprequest.rs, components/net_traits/filemanager_thread.rs, components/net_traits/filemanager_thread.rs, components/script/dom/htmlformelement.rs, components/script/dom/filereader.rs, components/script/dom/websocket.rs, components/script/dom/blob.rs, components/script/dom/formdata.rs

@highfive
Copy link

warning Warning warning

  • These commits modify script code, but no tests are modified. Please consider adding a test!

@highfive highfive added the S-awaiting-review There is new code that needs to be reviewed. label May 17, 2016
@izgzhen
Copy link
Contributor Author

izgzhen commented May 17, 2016

@Manishearth I refined the design a bit and I think we can push the progress of this thread in parallel with #11189

@mbrubeck mbrubeck assigned Manishearth and unassigned mbrubeck May 17, 2016
typeString: String,
isClosed_: Cell<bool>,
}

#[derive(Clone, JSTraceable)]
pub struct BlobImpl {
slice: DOMRefCell<Option<DataSlice>>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps this should be an enum?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am thinking about the possibility of caching here. If it is file-backed, we can put the cached content inside the other DataSlice field.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather have an enum here and within the FileId variant have an option for caching. As it stands slice = Some can mean cached or an in-memory slice, a clear boundary would be nicer and more Rusty.

@highfive
Copy link

New code was committed to pull request.

@izgzhen
Copy link
Contributor Author

izgzhen commented May 20, 2016

@Manishearth In order to get port to filemanger thread inside blob (by GlobalRef), I need to attach the filemanager_thread to worker (in workerglobalscope.rs). Currently the worker only has access to core_resource_thread (renamed from original resource_thread), rather than the combined ResourceThreads from which I can access the file manager. However I don't know if storage API (storage_thread I think) can be exposed to worker as well.

@jdm
Copy link
Member

jdm commented May 20, 2016

Exposing it won't hurt anything; the storage APIs aren't accessible from workers, so there hasn't been any need to make the storage thread available.

@Manishearth
Copy link
Member

Any particular reason for workers not being able to use storage? If there's a security reason we should not even give workers an unused storage chan (sandboxing).

@Manishearth
Copy link
Member

Seems like it used to be for security reasons but now it's just for "threading issues".

@izgzhen
Copy link
Contributor Author

izgzhen commented May 20, 2016

I didn't see any Exposed or similar in this spec http://www.w3.org/TR/2016/REC-webstorage-20160419/#the-storage-interface

@Manishearth
Copy link
Member

Oh, sure, the spec doesn't let you, the question is: If a sandboxed worker was compromised with an RCE vulnerability and got access to storage data, is that an escalation of access?

Assuming that we have checks in place in the resource/storage thread that ensure that no process gets data from a different origin (we don't, but we should eventually), I don't think this is an issue. Also, I don't see us putting workers in separate processes, so if a worker thread is compromised the script thread would be compromised too anyway.

let file_manager: IpcSender<FileManagerThreadMsg> = unimplemented!();
let (chan, recv) = ipc::channel().unwrap();
let _ = file_manager.send(FileManagerThreadMsg::ReadFile(chan, id));
let result = recv.recv().unwrap();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we be handling/propagating errors here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think read_file can be made Option<DataSlice> and we can throw a script-level exception or something at the dom API where it is used (like Slice)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Result<DataSlice,()> and use try! or the ? operator, but yeah

@Manishearth
Copy link
Member

Almost done!

@highfive
Copy link

New code was committed to pull request.

@bors-servo
Copy link
Contributor

☔ The latest upstream changes (presumably #10961) made this pull request unmergeable. Please resolve the merge conflicts.

@highfive highfive added the S-needs-rebase There are merge conflict errors. label May 21, 2016
@@ -308,12 +308,17 @@ impl HTMLFormElement {
DispositionParam::Filename(Charset::Ext(String::from(charset.clone())),
None,
f.name().clone().into()));
/// XXX: unwrap
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

replace it with an expect

though in this case unwrap_or(text/plain) might be better?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure, can't find related spec, maybe an empty ""?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Section 4.4, it defaults to text/plain

https://tools.ietf.org/html/rfc7578#section-4.4

@bors-servo
Copy link
Contributor

☔ The latest upstream changes (presumably #11225) made this pull request unmergeable. Please resolve the merge conflicts.

@highfive highfive added the S-needs-rebase There are merge conflict errors. label May 23, 2016
@bors-servo
Copy link
Contributor

☔ The latest upstream changes (presumably #11326) made this pull request unmergeable. Please resolve the merge conflicts.

@highfive highfive added the S-needs-rebase There are merge conflict errors. label May 24, 2016
@jdm jdm removed the S-needs-rebase There are merge conflict errors. label May 24, 2016
@bors-servo
Copy link
Contributor

☔ The latest upstream changes (presumably #11368) made this pull request unmergeable. Please resolve the merge conflicts.

@jdm jdm removed the S-blocked-on-external Something, somewhere else, needs to happen before this PR can be merged. label Jun 1, 2016
@bors-servo
Copy link
Contributor

⌛ Testing commit 43ad4ba with merge e83fb45...

bors-servo pushed a commit that referenced this pull request Jun 1, 2016
Add file backend support for Blob and related

- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy --faster` does not report any errors
- [x] These changes fix #10851, related to #11131
- [x] These changes do not require tests because the implementation is partial and can't work alone

1. Add new backend to `Blob` and a `BlobImpl` struct to abstract multiple backends
2. Rewrite most interfaces of `Blob` to accommodate the change
3. Change the `read` behaviour of `FileReader`, considering the case when blob is file-backed and not cached

The design is still immature, welcome comments!

- [x] I used `DOMRefCell` to cache the bytes in `BlobImpl`, is it sound?
- [x] The interfaces (like `BlobImpl::get_bytes`) handle requests in a default-to-empty way when the inner `DataSlice` is not cached. It might be possible to handle this condition better.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/11221)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

💔 Test failed - mac-rel-css

@highfive highfive removed the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label Jun 1, 2016
@highfive
Copy link

highfive commented Jun 1, 2016

  ▶ TIMEOUT [expected PASS] /css21_dev/html4/at-charset-074.htm

  ▶ TIMEOUT [expected PASS] /css21_dev/html4/at-charset-072.htm
  │ 
  └ Shutting down the Constellation after generating an output file or exit flag specified

  ▶ TIMEOUT [expected PASS] /css21_dev/html4/attribute-value-selector-001.htm

@highfive highfive added the S-tests-failed The changes caused existing tests to fail. label Jun 1, 2016
@Manishearth
Copy link
Member

@bors-servo try

@Manishearth
Copy link
Member

Manishearth commented Jun 1, 2016

@bors-servo
Copy link
Contributor

⌛ Trying commit 43ad4ba with merge decbabd...

bors-servo pushed a commit that referenced this pull request Jun 1, 2016
Add file backend support for Blob and related

- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy --faster` does not report any errors
- [x] These changes fix #10851, related to #11131
- [x] These changes do not require tests because the implementation is partial and can't work alone

1. Add new backend to `Blob` and a `BlobImpl` struct to abstract multiple backends
2. Rewrite most interfaces of `Blob` to accommodate the change
3. Change the `read` behaviour of `FileReader`, considering the case when blob is file-backed and not cached

The design is still immature, welcome comments!

- [x] I used `DOMRefCell` to cache the bytes in `BlobImpl`, is it sound?
- [x] The interfaces (like `BlobImpl::get_bytes`) handle requests in a default-to-empty way when the inner `DataSlice` is not cached. It might be possible to handle this condition better.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/11221)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

☀️ Test successful - android, arm32, arm64, linux-dev, linux-rel, mac-dev-unit, mac-rel-css, mac-rel-wpt, windows

@bors-servo
Copy link
Contributor

⌛ Testing commit 43ad4ba with merge 7293702...

bors-servo pushed a commit that referenced this pull request Jun 1, 2016
Add file backend support for Blob and related

- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy --faster` does not report any errors
- [x] These changes fix #10851, related to #11131
- [x] These changes do not require tests because the implementation is partial and can't work alone

1. Add new backend to `Blob` and a `BlobImpl` struct to abstract multiple backends
2. Rewrite most interfaces of `Blob` to accommodate the change
3. Change the `read` behaviour of `FileReader`, considering the case when blob is file-backed and not cached

The design is still immature, welcome comments!

- [x] I used `DOMRefCell` to cache the bytes in `BlobImpl`, is it sound?
- [x] The interfaces (like `BlobImpl::get_bytes`) handle requests in a default-to-empty way when the inner `DataSlice` is not cached. It might be possible to handle this condition better.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/11221)
<!-- Reviewable:end -->
@highfive highfive added S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. and removed S-tests-failed The changes caused existing tests to fail. labels Jun 1, 2016
@bors-servo
Copy link
Contributor

💔 Test failed - mac-rel-css

@highfive highfive added S-tests-failed The changes caused existing tests to fail. and removed S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. labels Jun 1, 2016
@Manishearth
Copy link
Member

@bors retry try-

  • interrupt

@Manishearth
Copy link
Member

@bors-servo retry try-

bors-servo pushed a commit that referenced this pull request Jun 1, 2016
Add file backend support for Blob and related

- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy --faster` does not report any errors
- [x] These changes fix #10851, related to #11131
- [x] These changes do not require tests because the implementation is partial and can't work alone

1. Add new backend to `Blob` and a `BlobImpl` struct to abstract multiple backends
2. Rewrite most interfaces of `Blob` to accommodate the change
3. Change the `read` behaviour of `FileReader`, considering the case when blob is file-backed and not cached

The design is still immature, welcome comments!

- [x] I used `DOMRefCell` to cache the bytes in `BlobImpl`, is it sound?
- [x] The interfaces (like `BlobImpl::get_bytes`) handle requests in a default-to-empty way when the inner `DataSlice` is not cached. It might be possible to handle this condition better.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/11221)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

⌛ Testing commit 43ad4ba with merge 3d7b176...

@highfive highfive added S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. and removed S-tests-failed The changes caused existing tests to fail. labels Jun 1, 2016
@bors-servo
Copy link
Contributor

☀️ Test successful - android, arm32, arm64, linux-dev, linux-rel, mac-dev-unit, mac-rel-css, mac-rel-wpt, windows

@bors-servo bors-servo merged commit 43ad4ba into servo:master Jun 1, 2016
@highfive highfive removed the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label Jun 1, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add file handling functionality to Blob object
7 participants