Skip to content

Delegate resource reading to embedder - #20533

Merged
bors-servo merged 1 commit into
servo:masterfrom
paulrouget:res
Apr 27, 2018
Merged

bors-servo merged 1 commit into
servo:masterfrom
paulrouget:res

Conversation

@paulrouget

@paulrouget paulrouget commented Apr 4, 2018 •

Copy link
Copy Markdown
Contributor

Now the embedder provides the content of the files itself. Now, on Android, we can use regular assets instead of unzipping all the resources on the scared at startup.


  • ./mach build -d does not report any errors
  • ./mach build-geckolib does not report any errors
  • ./mach test-tidy does not report any errors
  • These changes fix Dependency on /resources/ #15635 (github issue number if applicable).
  • There are tests for these changes OR
  • These changes do not require tests because _____

This change is Reviewable

@highfive

highfive commented Apr 4, 2018

Copy link
Copy Markdown

Heads up! This PR modifies the following files:

  • @asajeffrey: components/script/dom/userscripts.rs, components/script/dom/servoparser/mod.rs, components/script/lib.rs, components/constellation/sandboxing.rs, components/script/Cargo.toml
  • @cbrewster: components/constellation/sandboxing.rs
  • @fitzgen: components/script/dom/userscripts.rs, components/script/dom/servoparser/mod.rs, components/script/lib.rs, components/script/Cargo.toml
  • @KiChjang: components/net/lib.rs, components/net/image_cache.rs, components/script/dom/userscripts.rs, components/script/dom/servoparser/mod.rs, components/net/connector.rs and 10 more

@highfive highfive added the S-awaiting-review There is new code that needs to be reviewed. label Apr 4, 2018
@paulrouget
paulrouget force-pushed the res branch 5 times, most recently from 1cc07ad to 48f2222 Compare April 11, 2018 08:04
@paulrouget paulrouget changed the title [WIP] Delegate resource reading to embedder Delegate resource reading to embedder Apr 11, 2018
@paulrouget

Copy link
Copy Markdown
Contributor Author

Note to self:

  • need to test if we broke sandboxing (most likely)
  • ml post about the change in arguments (--shaders and --userscripts)

@paulrouget

paulrouget commented Apr 16, 2018 •

Copy link
Copy Markdown
Contributor Author

eb91969 fixes the sandboxing issues.

@paulrouget

Copy link
Copy Markdown
Contributor Author

Tested on Android and Mac. Sandboxing has been tested too.

@paulrouget

Copy link
Copy Markdown
Contributor Author

@mbrubeck r?

@paulrouget

Copy link
Copy Markdown
Contributor Author

(fixed the Windows failure)

@paulrouget
paulrouget requested a review from mbrubeck April 18, 2018 08:16
Comment thread ports/servo/resources.rs
buffer
}
fn sandbox_access_files_rec(&self) -> Vec<PathBuf> {
vec![resources_dir_path().expect("Can't find resources directory")]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If this just returns paths to top-level directories (rather than recursively iterating over the files inside those directories), maybe it should be renamed to sandox_access_files_dirs.

Comment thread components/layout_thread/lib.rs Outdated
shared_lock: &SharedRwLock,
filename: &'static str,
filename: &str,
content: String,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This could take Vec<u8> or &[u8] instead, and then the callers could use read_bytes instead of read_string to avoid needless UTF-8 validation.

@mbrubeck mbrubeck left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good overall. Some minor suggestions/concerns below.

Comment thread ports/servo/resources.rs Outdated
path.push(file);
let mut buffer = vec![];
File::open(path).expect(&format!("Can't find file: {}", file))
.read_to_end(&mut buffer).expect("Can't read file");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This could use the new std::fs::read which pre-allocates a buffer.

Comment thread components/net/resource_thread.rs Outdated
let mut txt = String::new();
let mut file = File::open(PathBuf::from(path))
.expect("Couldn't not find certificate file");
file.read_to_string(&mut txt).expect("Cant read certificate");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This can use fs::read_to_string.

Comment thread components/net/connector.rs Outdated
ssl_connector_builder.set_ca_file(ca_file).expect("could not set CA file");
loop {
if let Some(index) = certs.rfind("-----BEGIN CERTIFICATE-----") {
let cert = certs.split_off(index);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We could avoid allocating and copying here, by keeping cert as &str instead of String, and doing:

let (cert, rest) = certs.split_at(i);
certs = rest;

}
}).expect("could not set CA file");
} else {
break;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It looks like this might skip the last certificate in the file, because it's not followed by a BEGIN CERTIFICATE line.

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 use END CERTIFICATE now.

// but if any of them were already added, openssl would fail to insert all
// of them.
let mut ssl_connector_builder = SslConnectorBuilder::new(SslMethod::tls()).unwrap();
ssl_connector_builder.set_ca_file(ca_file).expect("could not set CA file");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe we should add a function to the openssl crate that takes the certificate file contents as a string. Then we could continue to let OpenSSL do the parsing 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.

It already has a method to parse the whole certs file, but it's a "all or non" operation (not like the previous method we were passing a file instead of a buffer). If it fails to load one of the certificate, they are all rejected. And in our case, it might fail because some certificates were already registered (so it's fine to ignore the error). So if we were to improve the Rust OpenSSL API, we should allow OpenSSL to ignore the duplicate error.

I can file a bug for that. Sounds to me that it's a OpenSSL issue, not a Rust OpenSSL problem though.

@paulrouget

Copy link
Copy Markdown
Contributor Author

(comments addressed)

@mbrubeck

Copy link
Copy Markdown
Contributor

@bors-servo r+

@bors-servo

Copy link
Copy Markdown
Contributor

📌 Commit eced418 has been approved by mbrubeck

@highfive highfive added S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. and removed S-awaiting-review There is new code that needs to be reviewed. labels Apr 21, 2018
@bors-servo

Copy link
Copy Markdown
Contributor

⌛ Testing commit eced418 with merge 7ced433...

bors-servo pushed a commit that referenced this pull request Apr 21, 2018
Delegate resource reading to embedder

Now the embedder provides the content of the files itself. Now, on Android, we can use regular assets instead of unzipping all the resources on the scared at startup.

---
<!-- 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
- [ ] `./mach build-geckolib` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #15635 (github issue number if applicable).

<!-- Either: -->
- [ ] There are tests for these changes OR
- [ ] These changes do not require tests because _____

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- 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/20533)
<!-- Reviewable:end -->
@bors-servo

Copy link
Copy Markdown
Contributor

💔 Test failed - linux-dev

@bors-servo

Copy link
Copy Markdown
Contributor

⌛ Testing commit 9fb5795 with merge c28d6f0...

bors-servo pushed a commit that referenced this pull request Apr 27, 2018
Delegate resource reading to embedder

Now the embedder provides the content of the files itself. Now, on Android, we can use regular assets instead of unzipping all the resources on the scared at startup.

---
<!-- 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
- [ ] `./mach build-geckolib` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #15635 (github issue number if applicable).

<!-- Either: -->
- [ ] There are tests for these changes OR
- [ ] These changes do not require tests because _____

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- 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/20533)
<!-- Reviewable:end -->
@bors-servo

Copy link
Copy Markdown
Contributor

💔 Test failed - mac-rel-css1

@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 Apr 27, 2018
@paulrouget

Copy link
Copy Markdown
Contributor Author

@bors-servo retry

  • Infra: Servers failed to start.

@bors-servo

Copy link
Copy Markdown
Contributor

⚡ Previous build results for android, arm32, arm64, linux-dev, linux-rel-wpt, mac-dev-unit, mac-rel-css2, mac-rel-wpt1, mac-rel-wpt3, windows-msvc-dev are reusable. Rebuilding only linux-rel-css, mac-rel-css1, mac-rel-wpt2, mac-rel-wpt4...

@nox

nox commented Apr 27, 2018

Copy link
Copy Markdown
Contributor

@bors-servo retry force

@bors-servo

Copy link
Copy Markdown
Contributor

⚡ Previous build results for android, arm32, arm64, linux-dev, linux-rel-css, linux-rel-wpt, mac-dev-unit, mac-rel-css1, mac-rel-css2, mac-rel-wpt1, mac-rel-wpt3, windows-msvc-dev are reusable. Rebuilding only mac-rel-wpt2, mac-rel-wpt4...

@bors-servo

Copy link
Copy Markdown
Contributor

⛄ The build was interrupted to prioritize another pull request.

@nox

nox commented Apr 27, 2018

Copy link
Copy Markdown
Contributor

Sorry again @paulrouget, Homu was sitting on its hands doing nothing.

@bors-servo p=1

@bors-servo

Copy link
Copy Markdown
Contributor

⚡ Previous build results for android, arm32, arm64, linux-dev, linux-rel-css, linux-rel-wpt, mac-dev-unit, mac-rel-css1, mac-rel-css2, mac-rel-wpt1, mac-rel-wpt3, windows-msvc-dev are reusable. Rebuilding only mac-rel-wpt2, mac-rel-wpt4...

@bors-servo

Copy link
Copy Markdown
Contributor

💔 Test failed - mac-rel-wpt2

@highfive highfive added the S-tests-failed The changes caused existing tests to fail. label Apr 27, 2018
@nox

nox commented Apr 27, 2018

Copy link
Copy Markdown
Contributor

@paulrouget CI is still a bit foobar'd. Please don't retry this, I'll do it myself once I know it can build without constant attention.

@nox

nox commented Apr 27, 2018

Copy link
Copy Markdown
Contributor

@bors-servo r=mbrubeck

@bors-servo

Copy link
Copy Markdown
Contributor

💡 This pull request was already approved, no need to approve it again.

  • This pull request previously failed. You should add more commits to fix the bug, or use retry to trigger a build again.

@bors-servo

Copy link
Copy Markdown
Contributor

📌 Commit 9fb5795 has been approved by mbrubeck

@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 Apr 27, 2018
@bors-servo

Copy link
Copy Markdown
Contributor

⌛ Testing commit 9fb5795 with merge d1378d6...

bors-servo pushed a commit that referenced this pull request Apr 27, 2018
Delegate resource reading to embedder

Now the embedder provides the content of the files itself. Now, on Android, we can use regular assets instead of unzipping all the resources on the scared at startup.

---
<!-- 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
- [ ] `./mach build-geckolib` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #15635 (github issue number if applicable).

<!-- Either: -->
- [ ] There are tests for these changes OR
- [ ] These changes do not require tests because _____

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- 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/20533)
<!-- Reviewable:end -->
@bors-servo

Copy link
Copy Markdown
Contributor

☀️ Test successful - android, arm32, arm64, linux-dev, linux-rel-css, linux-rel-wpt, mac-dev-unit, mac-rel-css1, mac-rel-css2, mac-rel-wpt1, mac-rel-wpt2, mac-rel-wpt3, mac-rel-wpt4, windows-msvc-dev
Approved by: mbrubeck
Pushing d1378d6 to master...

@bors-servo
bors-servo merged commit 9fb5795 into servo:master Apr 27, 2018
@highfive highfive removed the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label Apr 27, 2018
@paulrouget paulrouget mentioned this pull request Sep 21, 2018
3 tasks done
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.

Dependency on /resources/

6 participants