зеркало из https://github.com/mozilla/gecko-dev.git
Bug 804395 - Allow app:// protocol and XHR. r=sicking
This commit is contained in:
Родитель
171fb05cba
Коммит
27653df94c
|
@ -1232,12 +1232,36 @@ nsXMLHttpRequest::Status()
|
|||
|
||||
uint16_t readyState;
|
||||
GetReadyState(&readyState);
|
||||
if (readyState == UNSENT || readyState == OPENED || mErrorLoad) {
|
||||
if (readyState == UNSENT || readyState == OPENED) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (mErrorLoad) {
|
||||
// Let's simulate the http protocol for jar/app requests:
|
||||
nsCOMPtr<nsIJARChannel> jarChannel = GetCurrentJARChannel();
|
||||
if (jarChannel) {
|
||||
nsresult status;
|
||||
mChannel->GetStatus(&status);
|
||||
|
||||
if (status == NS_ERROR_FILE_NOT_FOUND) {
|
||||
return 404; // Not Found
|
||||
} else {
|
||||
return 500; // Internal Error
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIHttpChannel> httpChannel = GetCurrentHttpChannel();
|
||||
if (!httpChannel) {
|
||||
|
||||
// Let's simulate the http protocol for jar/app requests:
|
||||
nsCOMPtr<nsIJARChannel> jarChannel = GetCurrentJARChannel();
|
||||
if (jarChannel) {
|
||||
return 200; // Ok
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -1627,17 +1651,21 @@ nsXMLHttpRequest::DispatchProgressEvent(nsDOMEventTargetHelper* aTarget,
|
|||
already_AddRefed<nsIHttpChannel>
|
||||
nsXMLHttpRequest::GetCurrentHttpChannel()
|
||||
{
|
||||
nsIHttpChannel *httpChannel = nullptr;
|
||||
|
||||
if (mReadRequest) {
|
||||
CallQueryInterface(mReadRequest, &httpChannel);
|
||||
nsCOMPtr<nsIHttpChannel> httpChannel = do_QueryInterface(mReadRequest);
|
||||
if (!httpChannel) {
|
||||
httpChannel = do_QueryInterface(mChannel);
|
||||
}
|
||||
return httpChannel.forget();
|
||||
}
|
||||
|
||||
if (!httpChannel && mChannel) {
|
||||
CallQueryInterface(mChannel, &httpChannel);
|
||||
already_AddRefed<nsIJARChannel>
|
||||
nsXMLHttpRequest::GetCurrentJARChannel()
|
||||
{
|
||||
nsCOMPtr<nsIJARChannel> appChannel = do_QueryInterface(mReadRequest);
|
||||
if (!appChannel) {
|
||||
appChannel = do_QueryInterface(mChannel);
|
||||
}
|
||||
|
||||
return httpChannel;
|
||||
return appChannel.forget();
|
||||
}
|
||||
|
||||
bool
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include "nsString.h"
|
||||
#include "nsIURI.h"
|
||||
#include "nsIHttpChannel.h"
|
||||
#include "nsIJARChannel.h"
|
||||
#include "nsIDocument.h"
|
||||
#include "nsIStreamListener.h"
|
||||
#include "nsWeakReference.h"
|
||||
|
@ -514,6 +515,7 @@ protected:
|
|||
nsIURI *GetBaseURI();
|
||||
|
||||
already_AddRefed<nsIHttpChannel> GetCurrentHttpChannel();
|
||||
already_AddRefed<nsIJARChannel> GetCurrentJARChannel();
|
||||
|
||||
bool IsSystemXHR();
|
||||
|
||||
|
|
|
@ -584,6 +584,8 @@ MOCHITEST_FILES_B = \
|
|||
file_mixed_content_main.html \
|
||||
file_mixed_content_server.sjs \
|
||||
test_bug789856.html \
|
||||
file_bug804395.jar \
|
||||
test_bug804395.html \
|
||||
$(NULL)
|
||||
|
||||
# OOP tests don't work on Windows (bug 763081) or native-fennec
|
||||
|
|
Двоичный файл не отображается.
|
@ -0,0 +1,70 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<!--
|
||||
https://bugzilla.mozilla.org/show_bug.cgi?id=804395
|
||||
-->
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Test for Bug 804395</title>
|
||||
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
</head>
|
||||
<body>
|
||||
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=804395">Mozilla Bug 804395</a>
|
||||
<p id="display"></p>
|
||||
<div id="content" style="display: none">
|
||||
|
||||
</div>
|
||||
<pre id="test">
|
||||
<script type="application/javascript">
|
||||
|
||||
function test200() {
|
||||
var xhr = SpecialPowers.createSystemXHR();
|
||||
xhr.open('GET', 'jar:http://example.org/tests/content/base/test/file_bug804395.jar!/foo.bar', true);
|
||||
xhr.onreadystatechange = function() {
|
||||
if (xhr.readyState == 4) {
|
||||
ok(xhr.status == 200, "Existing file must have Status 200!");
|
||||
runTests();
|
||||
}
|
||||
}
|
||||
xhr.send(null);
|
||||
}
|
||||
|
||||
function test404() {
|
||||
var xhr = SpecialPowers.createSystemXHR();
|
||||
xhr.open('GET', 'jar:http://example.org/tests/content/base/test/file_bug804395.jar!/foo.do_not_exist', true);
|
||||
xhr.onreadystatechange = function() {
|
||||
if (xhr.readyState == 4) {
|
||||
ok(xhr.status == 404, "Non existing file must have Status 404!");
|
||||
runTests();
|
||||
}
|
||||
}
|
||||
xhr.send(null);
|
||||
}
|
||||
|
||||
function test0() {
|
||||
var xhr = SpecialPowers.createSystemXHR();
|
||||
xhr.open('GET', 'jar:http://example.org/tests/content/base/test/file_bug804395.jar!/foo.bar', true);
|
||||
ok(xhr.status == 0, "Not Sent request must have status 0");
|
||||
runTests();
|
||||
}
|
||||
|
||||
var tests = [ test200, test404, test0 ];
|
||||
function runTests() {
|
||||
if (!tests.length) {
|
||||
SimpleTest.finish();
|
||||
return;
|
||||
}
|
||||
|
||||
var test = tests.shift();
|
||||
test();
|
||||
}
|
||||
|
||||
/** Test for Bug 804395 **/
|
||||
runTests();
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
</script>
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
Загрузка…
Ссылка в новой задаче