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

Delegate resource reading to embedder #20533

Merged
merged 1 commit into from Apr 27, 2018
Merged

Delegate resource reading to embedder #20533

merged 1 commit into from Apr 27, 2018

Conversation

@paulrouget
Copy link
Contributor

paulrouget commented Apr 4, 2018

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

highfive commented Apr 4, 2018

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
@paulrouget paulrouget force-pushed the paulrouget:res branch 5 times, most recently from 1cc07ad to 48f2222 Apr 4, 2018
@paulrouget paulrouget changed the title [WIP] Delegate resource reading to embedder Delegate resource reading to embedder Apr 11, 2018
@paulrouget
Copy link
Contributor Author

paulrouget commented Apr 11, 2018

Note to self:

  • need to test if we broke sandboxing (most likely)
  • ml post about the change in arguments (--shaders and --userscripts)
@paulrouget
Copy link
Contributor Author

paulrouget commented Apr 16, 2018

eb91969 fixes the sandboxing issues.

@paulrouget paulrouget force-pushed the paulrouget:res branch from eb91969 to fca81e5 Apr 16, 2018
@paulrouget
Copy link
Contributor Author

paulrouget commented Apr 16, 2018

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

@paulrouget paulrouget force-pushed the paulrouget:res branch from fca81e5 to 9d15d6d Apr 16, 2018
@paulrouget
Copy link
Contributor Author

paulrouget commented Apr 16, 2018

@paulrouget paulrouget force-pushed the paulrouget:res branch from 9d15d6d to 481f5ba Apr 17, 2018
@paulrouget
Copy link
Contributor Author

paulrouget commented Apr 17, 2018

(fixed the Windows failure)

@paulrouget paulrouget requested a review from mbrubeck Apr 18, 2018
buffer
}
fn sandbox_access_files_rec(&self) -> Vec<PathBuf> {
vec![resources_dir_path().expect("Can't find resources directory")]

This comment has been minimized.

@mbrubeck

mbrubeck Apr 18, 2018

Contributor

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.

@@ -1740,11 +1741,11 @@ fn get_root_flow_background_color(flow: &mut Flow) -> webrender_api::ColorF {
fn get_ua_stylesheets() -> Result<UserAgentStylesheets, &'static str> {
fn parse_ua_stylesheet(
shared_lock: &SharedRwLock,
filename: &'static str,
filename: &str,
content: String,

This comment has been minimized.

@mbrubeck

mbrubeck Apr 18, 2018

Contributor

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.

Copy link
Contributor

mbrubeck left a comment

Looks good overall. Some minor suggestions/concerns below.

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");

This comment has been minimized.

@mbrubeck

mbrubeck Apr 18, 2018

Contributor

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

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");

This comment has been minimized.

@mbrubeck

mbrubeck Apr 18, 2018

Contributor

This can use fs::read_to_string.

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);

This comment has been minimized.

@mbrubeck

mbrubeck Apr 18, 2018

Contributor

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;

This comment has been minimized.

@mbrubeck

mbrubeck Apr 18, 2018

Contributor

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

This comment has been minimized.

@paulrouget

paulrouget Apr 20, 2018

Author Contributor

I use END CERTIFICATE now.

let mut ssl_connector_builder = SslConnectorBuilder::new(SslMethod::tls()).unwrap();
ssl_connector_builder.set_ca_file(ca_file).expect("could not set CA file");

This comment has been minimized.

@mbrubeck

mbrubeck Apr 18, 2018

Contributor

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.

This comment has been minimized.

@paulrouget

paulrouget Apr 20, 2018

Author Contributor

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 paulrouget force-pushed the paulrouget:res branch from 481f5ba to eced418 Apr 20, 2018
@paulrouget
Copy link
Contributor Author

paulrouget commented Apr 21, 2018

(comments addressed)

@mbrubeck
Copy link
Contributor

mbrubeck commented Apr 21, 2018

@bors-servo
Copy link
Contributor

bors-servo commented Apr 21, 2018

📌 Commit eced418 has been approved by mbrubeck

@bors-servo
Copy link
Contributor

bors-servo commented Apr 21, 2018

Testing commit eced418 with merge 7ced433...

bors-servo added 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
Contributor

bors-servo commented Apr 21, 2018

💔 Test failed - linux-dev

@bors-servo
Copy link
Contributor

bors-servo commented Apr 27, 2018

Testing commit 9fb5795 with merge c28d6f0...

bors-servo added 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
Contributor

bors-servo commented Apr 27, 2018

💔 Test failed - mac-rel-css1

@paulrouget
Copy link
Contributor Author

paulrouget commented Apr 27, 2018

@bors-servo retry

  • Infra: Servers failed to start.
@bors-servo
Copy link
Contributor

bors-servo commented Apr 27, 2018

@nox
Copy link
Member

nox commented Apr 27, 2018

@bors-servo retry force

@bors-servo
Copy link
Contributor

bors-servo commented Apr 27, 2018

@bors-servo
Copy link
Contributor

bors-servo commented Apr 27, 2018

The build was interrupted to prioritize another pull request.

@nox
Copy link
Member

nox commented Apr 27, 2018

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

@bors-servo p=1

@bors-servo
Copy link
Contributor

bors-servo commented Apr 27, 2018

@bors-servo
Copy link
Contributor

bors-servo commented Apr 27, 2018

💔 Test failed - mac-rel-wpt2

@nox
Copy link
Member

nox commented Apr 27, 2018

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

nox commented Apr 27, 2018

@bors-servo r=mbrubeck

@bors-servo
Copy link
Contributor

bors-servo commented Apr 27, 2018

💡 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
Contributor

bors-servo commented Apr 27, 2018

📌 Commit 9fb5795 has been approved by mbrubeck

@bors-servo
Copy link
Contributor

bors-servo commented Apr 27, 2018

Testing commit 9fb5795 with merge d1378d6...

bors-servo added 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
Contributor

bors-servo commented Apr 27, 2018

@bors-servo bors-servo merged commit 9fb5795 into servo:master Apr 27, 2018
3 checks passed
3 checks passed
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
homu Test successful
Details
@paulrouget paulrouget mentioned this pull request Sep 21, 2018
3 of 3 tasks complete
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.

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