Auto merge of #11544 - jdm:privatebrowsing, r=asajeffrey

Implement private browsing for mozbrowser

<!-- Please describe your changes on the following line: -->
Support the `mozprivatebrowsing` attribute on mozbrowser iframes. This separates the non-private and private sessions in terms of cookies, HSTS lists, cached HTTP credentials, HTTP connection pools, and web storage. The private session is shared between all private mozbrowsers, and lasts until shutdown.

---
<!-- 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] 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="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/11544)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2016-06-20 14:32:17 -05:00 committed by GitHub
commit 6166d8e74f
14 changed files with 294 additions and 138 deletions

View file

@ -40,7 +40,7 @@ impl LoadOrigin for ResourceTest {
fn test_exit() {
let (tx, _rx) = ipc::channel().unwrap();
let (sender, receiver) = ipc::channel().unwrap();
let resource_thread = new_core_resource_thread("".to_owned(), None, ProfilerChan(tx));
let (resource_thread, _) = new_core_resource_thread("".to_owned(), None, ProfilerChan(tx));
resource_thread.send(CoreResourceMsg::Exit(sender)).unwrap();
receiver.recv().unwrap();
}
@ -49,7 +49,7 @@ fn test_exit() {
fn test_bad_scheme() {
let (tx, _rx) = ipc::channel().unwrap();
let (sender, receiver) = ipc::channel().unwrap();
let resource_thread = new_core_resource_thread("".to_owned(), None, ProfilerChan(tx));
let (resource_thread, _) = new_core_resource_thread("".to_owned(), None, ProfilerChan(tx));
let (start_chan, start) = ipc::channel().unwrap();
let url = Url::parse("bogus://whatever").unwrap();
resource_thread.send(CoreResourceMsg::Load(LoadData::new(LoadContext::Browsing, url, &ResourceTest),
@ -228,7 +228,7 @@ fn test_cancelled_listener() {
let (tx, _rx) = ipc::channel().unwrap();
let (exit_sender, exit_receiver) = ipc::channel().unwrap();
let resource_thread = new_core_resource_thread("".to_owned(), None, ProfilerChan(tx));
let (resource_thread, _) = new_core_resource_thread("".to_owned(), None, ProfilerChan(tx));
let (sender, receiver) = ipc::channel().unwrap();
let (id_sender, id_receiver) = ipc::channel().unwrap();
let (sync_sender, sync_receiver) = ipc::channel().unwrap();

View file

@ -6616,6 +6616,12 @@
"url": "/_mozilla/mozilla/mozbrowser/mozbrowsertitlechangedeagerly_event.html"
}
],
"mozilla/mozbrowser/private_browsing.html": [
{
"path": "mozilla/mozbrowser/private_browsing.html",
"url": "/_mozilla/mozilla/mozbrowser/private_browsing.html"
}
],
"mozilla/mozbrowser/redirect.html": [
{
"path": "mozilla/mozbrowser/redirect.html",

View file

@ -0,0 +1,3 @@
<html><body><div id="test">Normal iFrame</div></body>
<script>alert(document.cookie)</script>
</html>

View file

@ -0,0 +1,4 @@
<span id="cookie"></span>
<script>
document.querySelector('#cookie').innerHTML = document.cookie;
</script>

View file

@ -0,0 +1,13 @@
<html>
<body>
<div id="test">Private iFrame</div>
</body>
<script>document.cookie = "private=active;path=/";</script>
<iframe src="iframe_privateContent_grandchild.html"></iframe>
<script>
var iframe = document.querySelector('iframe');
iframe.onload = function() {
alert(document.cookie + ' ' + iframe.contentDocument.querySelector('#cookie').textContent);
};
</script>
</html>

View file

@ -0,0 +1,44 @@
<head>
<meta charset="utf8" />
<title>Private browsing</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<script>
async_test(function(t) {
var privateFrame = document.createElement("iframe");
privateFrame.mozbrowser = true;
privateFrame.mozprivatebrowsing = true;
var gotGrandchildResult = false;
privateFrame.addEventListener("mozbrowsershowmodalprompt", t.step_func(e => {
assert_equals(e.detail.message, 'private=active private=active');
gotGrandchildResult = true;
}));
privateFrame.onload = t.step_func(function() {
assert_true(gotGrandchildResult);
var parent = privateFrame.parentNode;
parent.removeChild(privateFrame);
var iframe = document.createElement("iframe");
var promptDisplay = false;
iframe.mozbrowser = true;
iframe.onload = t.step_func(function() {
assert_true(promptDisplay);
t.done();
});
iframe.addEventListener("mozbrowsershowmodalprompt", t.step_func(e => {
promptDisplay = true;
assert_equals(e.detail.message, "");
}));
iframe.src = "iframe_contentDocument_inner.html";
parent.appendChild(iframe);
});
privateFrame.src = "iframe_privateContent_inner.html";
document.body.appendChild(privateFrame);
});
</script>
</body>