Skip to content

Add file backend support for Blob and related - #11221

Merged
bors-servo merged 1 commit into
servo:masterfrom
izgzhen:blob-file-backend
Jun 1, 2016
Merged

bors-servo merged 1 commit into
servo:masterfrom
izgzhen:blob-file-backend

Conversation

@izgzhen

@izgzhen izgzhen commented May 17, 2016 •

Copy link
Copy Markdown
Contributor

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
Copy Markdown

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
Copy Markdown

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

izgzhen commented May 17, 2016

Copy link
Copy Markdown
Contributor Author

@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
Comment thread components/script/dom/blob.rs Outdated

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

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown

New code was committed to pull request.

@izgzhen

izgzhen commented May 20, 2016

Copy link
Copy Markdown
Contributor Author

@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

jdm commented May 20, 2016

Copy link
Copy Markdown
Member

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
Copy Markdown
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
Copy Markdown
Member

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

@izgzhen

izgzhen commented May 20, 2016

Copy link
Copy Markdown
Contributor Author

@Manishearth

Copy link
Copy Markdown
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.

Comment thread components/script/dom/blob.rs Outdated
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Member

Almost done!

@highfive

Copy link
Copy Markdown

New code was committed to pull request.

@bors-servo

Copy link
Copy Markdown
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
DispositionParam::Filename(Charset::Ext(String::from(charset.clone())),
None,
f.name().clone().into()));
/// XXX: unwrap

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Member

Choose a reason for hiding this comment

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

@bors-servo

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

highfive commented Jun 1, 2016

Copy link
Copy Markdown
  ▶ 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
Copy Markdown
Member

@bors-servo try

@Manishearth

Manishearth commented Jun 1, 2016 •

Copy link
Copy Markdown
Member

@bors-servo

Copy link
Copy Markdown
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
Copy Markdown
Contributor

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

@bors-servo

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Member

@bors retry try-

  • interrupt

@Manishearth

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

6 participants