зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1347515 - Get rid of dom/json, r=qdot
This commit is contained in:
Родитель
207b8d909e
Коммит
a4ddff0ca6
|
@ -206,7 +206,6 @@
|
|||
@RESPATH@/components/dom_notification.xpt
|
||||
@RESPATH@/components/dom_html.xpt
|
||||
@RESPATH@/components/dom_offline.xpt
|
||||
@RESPATH@/components/dom_json.xpt
|
||||
@RESPATH@/components/dom_payments.xpt
|
||||
@RESPATH@/components/dom_power.xpt
|
||||
@RESPATH@/components/dom_push.xpt
|
||||
|
|
|
@ -91,7 +91,6 @@
|
|||
#include "nsContentCID.h"
|
||||
#include "nsError.h"
|
||||
#include "nsPresContext.h"
|
||||
#include "nsIJSON.h"
|
||||
#include "nsThreadUtils.h"
|
||||
#include "nsNodeInfoManager.h"
|
||||
#include "nsIFileChannel.h"
|
||||
|
|
|
@ -1,15 +0,0 @@
|
|||
# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
|
||||
# vim: set filetype=python:
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
with Files("**"):
|
||||
BUG_COMPONENT = ("Core", "JavaScript Engine")
|
||||
|
||||
XPIDL_SOURCES += [
|
||||
'nsIJSON.idl',
|
||||
]
|
||||
|
||||
XPIDL_MODULE = 'dom_json'
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "domstubs.idl"
|
||||
|
||||
interface nsIInputStream;
|
||||
interface nsIScriptGlobalObject;
|
||||
|
||||
[ptr] native JSValPtr(JS::Value);
|
||||
[ptr] native JSContext(JSContext);
|
||||
|
||||
%{C++
|
||||
#include "js/TypeDecls.h"
|
||||
%}
|
||||
|
||||
/**
|
||||
* Don't use this! Use JSON.parse and JSON.stringify directly.
|
||||
*/
|
||||
[scriptable, uuid(083aebb0-7790-43b2-ae81-9e404e626236)]
|
||||
interface nsIJSON : nsISupports
|
||||
{
|
||||
};
|
|
@ -1,22 +0,0 @@
|
|||
# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
|
||||
# vim: set filetype=python:
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
with Files("**"):
|
||||
BUG_COMPONENT = ("Core", "JavaScript Engine")
|
||||
|
||||
EXPORTS += [
|
||||
'nsJSON.h',
|
||||
]
|
||||
|
||||
UNIFIED_SOURCES += [
|
||||
'nsJSON.cpp',
|
||||
]
|
||||
|
||||
LOCAL_INCLUDES += [
|
||||
'/dom/base',
|
||||
]
|
||||
|
||||
FINAL_LIBRARY = 'xul'
|
|
@ -1,274 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "nsJSON.h"
|
||||
|
||||
#include "jsapi.h"
|
||||
#include "js/CharacterEncoding.h"
|
||||
#include "nsIXPConnect.h"
|
||||
#include "nsIXPCScriptable.h"
|
||||
#include "nsStreamUtils.h"
|
||||
#include "nsIInputStream.h"
|
||||
#include "nsStringStream.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "nsIURI.h"
|
||||
#include "nsComponentManagerUtils.h"
|
||||
#include "nsContentUtils.h"
|
||||
#include "nsIScriptError.h"
|
||||
#include "nsCRTGlue.h"
|
||||
#include "nsIScriptSecurityManager.h"
|
||||
#include "NullPrincipal.h"
|
||||
#include "mozilla/Maybe.h"
|
||||
#include <algorithm>
|
||||
|
||||
using namespace mozilla;
|
||||
|
||||
#define JSON_STREAM_BUFSIZE 4096
|
||||
|
||||
NS_INTERFACE_MAP_BEGIN(nsJSON)
|
||||
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIJSON)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIJSON)
|
||||
NS_INTERFACE_MAP_END
|
||||
|
||||
NS_IMPL_ADDREF(nsJSON)
|
||||
NS_IMPL_RELEASE(nsJSON)
|
||||
|
||||
nsJSON::nsJSON()
|
||||
{
|
||||
}
|
||||
|
||||
nsJSON::~nsJSON()
|
||||
{
|
||||
}
|
||||
|
||||
// TODO This is going to be removed in the next patches!
|
||||
nsresult
|
||||
nsJSON::DecodeInternal(JSContext* cx,
|
||||
nsIInputStream *aStream,
|
||||
int32_t aContentLength,
|
||||
bool aNeedsConverter,
|
||||
JS::MutableHandle<JS::Value> aRetval)
|
||||
{
|
||||
// Consume the stream
|
||||
nsCOMPtr<nsIChannel> jsonChannel;
|
||||
if (!mURI) {
|
||||
NS_NewURI(getter_AddRefs(mURI), NS_LITERAL_CSTRING("about:blank"), 0, 0 );
|
||||
if (!mURI)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIPrincipal> nullPrincipal = NullPrincipal::Create();
|
||||
|
||||
// The ::Decode function is deprecated [Bug 675797] and the following
|
||||
// channel is never openend, so it does not matter what securityFlags
|
||||
// we pass to NS_NewInputStreamChannel here.
|
||||
rv = NS_NewInputStreamChannel(getter_AddRefs(jsonChannel),
|
||||
mURI,
|
||||
aStream,
|
||||
nullPrincipal,
|
||||
nsILoadInfo::SEC_REQUIRE_SAME_ORIGIN_DATA_IS_BLOCKED,
|
||||
nsIContentPolicy::TYPE_OTHER,
|
||||
NS_LITERAL_CSTRING("application/json"));
|
||||
|
||||
if (!jsonChannel || NS_FAILED(rv))
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
RefPtr<nsJSONListener> jsonListener =
|
||||
new nsJSONListener(cx, aRetval.address(), aNeedsConverter);
|
||||
|
||||
//XXX this stream pattern should be consolidated in netwerk
|
||||
rv = jsonListener->OnStartRequest(jsonChannel, nullptr);
|
||||
if (NS_FAILED(rv)) {
|
||||
jsonChannel->Cancel(rv);
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult status;
|
||||
jsonChannel->GetStatus(&status);
|
||||
uint64_t offset = 0;
|
||||
while (NS_SUCCEEDED(status)) {
|
||||
uint64_t available;
|
||||
rv = aStream->Available(&available);
|
||||
if (rv == NS_BASE_STREAM_CLOSED) {
|
||||
rv = NS_OK;
|
||||
break;
|
||||
}
|
||||
if (NS_FAILED(rv)) {
|
||||
jsonChannel->Cancel(rv);
|
||||
break;
|
||||
}
|
||||
if (!available)
|
||||
break; // blocking input stream has none available when done
|
||||
|
||||
if (available > UINT32_MAX)
|
||||
available = UINT32_MAX;
|
||||
|
||||
rv = jsonListener->OnDataAvailable(jsonChannel, nullptr,
|
||||
aStream,
|
||||
offset,
|
||||
(uint32_t)available);
|
||||
if (NS_FAILED(rv)) {
|
||||
jsonChannel->Cancel(rv);
|
||||
break;
|
||||
}
|
||||
|
||||
offset += available;
|
||||
jsonChannel->GetStatus(&status);
|
||||
}
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
rv = jsonListener->OnStopRequest(jsonChannel, nullptr, status);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
NS_NewJSON(nsISupports* aOuter, REFNSIID aIID, void** aResult)
|
||||
{
|
||||
nsJSON* json = new nsJSON();
|
||||
NS_ADDREF(json);
|
||||
*aResult = json;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsJSONListener::nsJSONListener(JSContext *cx, JS::Value *rootVal,
|
||||
bool needsConverter)
|
||||
: mNeedsConverter(needsConverter),
|
||||
mCx(cx),
|
||||
mRootVal(rootVal)
|
||||
{
|
||||
}
|
||||
|
||||
nsJSONListener::~nsJSONListener()
|
||||
{
|
||||
}
|
||||
|
||||
NS_INTERFACE_MAP_BEGIN(nsJSONListener)
|
||||
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsJSONListener)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIRequestObserver)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIStreamListener)
|
||||
NS_INTERFACE_MAP_END
|
||||
|
||||
NS_IMPL_ADDREF(nsJSONListener)
|
||||
NS_IMPL_RELEASE(nsJSONListener)
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJSONListener::OnStartRequest(nsIRequest *aRequest, nsISupports *aContext)
|
||||
{
|
||||
mDecoder = nullptr;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJSONListener::OnStopRequest(nsIRequest *aRequest, nsISupports *aContext,
|
||||
nsresult aStatusCode)
|
||||
{
|
||||
JS::Rooted<JS::Value> reviver(mCx, JS::NullValue()), value(mCx);
|
||||
|
||||
JS::ConstTwoByteChars chars(reinterpret_cast<const char16_t*>(mBufferedChars.Elements()),
|
||||
mBufferedChars.Length());
|
||||
bool ok = JS_ParseJSONWithReviver(mCx, chars.begin().get(),
|
||||
uint32_t(mBufferedChars.Length()),
|
||||
reviver, &value);
|
||||
|
||||
*mRootVal = value;
|
||||
mBufferedChars.TruncateLength(0);
|
||||
return ok ? NS_OK : NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJSONListener::OnDataAvailable(nsIRequest *aRequest, nsISupports *aContext,
|
||||
nsIInputStream *aStream,
|
||||
uint64_t aOffset, uint32_t aLength)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
char buffer[JSON_STREAM_BUFSIZE];
|
||||
unsigned long bytesRemaining = aLength;
|
||||
while (bytesRemaining) {
|
||||
unsigned int bytesRead;
|
||||
rv = aStream->Read(buffer,
|
||||
std::min((unsigned long)sizeof(buffer), bytesRemaining),
|
||||
&bytesRead);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = ProcessBytes(buffer, bytesRead);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
bytesRemaining -= bytesRead;
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsJSONListener::ProcessBytes(const char* aBuffer, uint32_t aByteLength)
|
||||
{
|
||||
if (mNeedsConverter && !mDecoder) {
|
||||
// BOM sniffing is built into the decoder.
|
||||
mDecoder = UTF_8_ENCODING->NewDecoder();
|
||||
}
|
||||
|
||||
if (!aBuffer)
|
||||
return NS_OK;
|
||||
|
||||
nsresult rv;
|
||||
if (mNeedsConverter) {
|
||||
rv = ConsumeConverted(aBuffer, aByteLength);
|
||||
} else {
|
||||
uint32_t unichars = aByteLength / sizeof(char16_t);
|
||||
rv = Consume((char16_t *) aBuffer, unichars);
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsJSONListener::ConsumeConverted(const char* aBuffer, uint32_t aByteLength)
|
||||
{
|
||||
CheckedInt<size_t> needed = mDecoder->MaxUTF16BufferLength(aByteLength);
|
||||
if (!needed.isValid()) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
CheckedInt<size_t> total(needed);
|
||||
total += mBufferedChars.Length();
|
||||
if (!total.isValid()) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
char16_t* endelems = mBufferedChars.AppendElements(needed.value(), fallible);
|
||||
if (!endelems) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
auto src = AsBytes(MakeSpan(aBuffer, aByteLength));
|
||||
auto dst = MakeSpan(endelems, needed.value());
|
||||
uint32_t result;
|
||||
size_t read;
|
||||
size_t written;
|
||||
bool hadErrors;
|
||||
// Ignoring EOF like the old code
|
||||
Tie(result, read, written, hadErrors) =
|
||||
mDecoder->DecodeToUTF16(src, dst, false);
|
||||
MOZ_ASSERT(result == kInputEmpty);
|
||||
MOZ_ASSERT(read == src.Length());
|
||||
MOZ_ASSERT(written <= needed.value());
|
||||
Unused << hadErrors;
|
||||
mBufferedChars.TruncateLength(total.value() - (needed.value() - written));
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsJSONListener::Consume(const char16_t* aBuffer, uint32_t aByteLength)
|
||||
{
|
||||
if (!mBufferedChars.AppendElements(aBuffer, aByteLength))
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
return NS_OK;
|
||||
}
|
|
@ -1,65 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#ifndef nsJSON_h__
|
||||
#define nsJSON_h__
|
||||
|
||||
#include "nsIJSON.h"
|
||||
#include "nsString.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIOutputStream.h"
|
||||
#include "mozilla/Encoding.h"
|
||||
#include "nsIRequestObserver.h"
|
||||
#include "nsIStreamListener.h"
|
||||
#include "nsTArray.h"
|
||||
|
||||
class nsIURI;
|
||||
|
||||
class nsJSON final : public nsIJSON
|
||||
{
|
||||
public:
|
||||
nsJSON();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIJSON
|
||||
|
||||
protected:
|
||||
virtual ~nsJSON();
|
||||
|
||||
nsresult DecodeInternal(JSContext* cx,
|
||||
nsIInputStream* aStream,
|
||||
int32_t aContentLength,
|
||||
bool aNeedsConverter,
|
||||
JS::MutableHandle<JS::Value> aRetVal);
|
||||
nsCOMPtr<nsIURI> mURI;
|
||||
};
|
||||
|
||||
nsresult
|
||||
NS_NewJSON(nsISupports* aOuter, REFNSIID aIID, void** aResult);
|
||||
|
||||
class nsJSONListener : public nsIStreamListener
|
||||
{
|
||||
public:
|
||||
nsJSONListener(JSContext *cx, JS::Value *rootVal, bool needsConverter);
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIREQUESTOBSERVER
|
||||
NS_DECL_NSISTREAMLISTENER
|
||||
|
||||
protected:
|
||||
virtual ~nsJSONListener();
|
||||
|
||||
bool mNeedsConverter;
|
||||
JSContext *mCx;
|
||||
JS::Value *mRootVal;
|
||||
mozilla::UniquePtr<mozilla::Decoder> mDecoder;
|
||||
nsTArray<char16_t> mBufferedChars;
|
||||
nsresult ProcessBytes(const char* aBuffer, uint32_t aByteLength);
|
||||
nsresult ConsumeConverted(const char* aBuffer, uint32_t aByteLength);
|
||||
nsresult Consume(const char16_t *data, uint32_t len);
|
||||
};
|
||||
|
||||
#endif
|
|
@ -29,7 +29,6 @@ interfaces = [
|
|||
'xul',
|
||||
'security',
|
||||
'storage',
|
||||
'json',
|
||||
'offline',
|
||||
'geolocation',
|
||||
'notification',
|
||||
|
@ -65,7 +64,6 @@ DIRS += [
|
|||
'geolocation',
|
||||
'grid',
|
||||
'html',
|
||||
'json',
|
||||
'jsurl',
|
||||
'asmjscache',
|
||||
'mathml',
|
||||
|
|
|
@ -37,7 +37,6 @@ LOCAL_INCLUDES += [
|
|||
'/dom/filesystem',
|
||||
'/dom/geolocation',
|
||||
'/dom/html',
|
||||
'/dom/json',
|
||||
'/dom/jsurl',
|
||||
'/dom/media',
|
||||
'/dom/offline',
|
||||
|
|
|
@ -75,7 +75,6 @@
|
|||
#include "nsJSProtocolHandler.h"
|
||||
#include "nsScriptNameSpaceManager.h"
|
||||
#include "nsIControllerContext.h"
|
||||
#include "nsJSON.h"
|
||||
#include "nsZipArchive.h"
|
||||
#include "mozilla/Attributes.h"
|
||||
#include "mozilla/dom/DOMException.h"
|
||||
|
@ -627,7 +626,6 @@ NS_DEFINE_NAMED_CID(NS_XMLHTTPREQUEST_CID);
|
|||
NS_DEFINE_NAMED_CID(NS_DOMPARSER_CID);
|
||||
NS_DEFINE_NAMED_CID(NS_DOMSESSIONSTORAGEMANAGER_CID);
|
||||
NS_DEFINE_NAMED_CID(NS_DOMLOCALSTORAGEMANAGER_CID);
|
||||
NS_DEFINE_NAMED_CID(NS_DOMJSON_CID);
|
||||
NS_DEFINE_NAMED_CID(NS_TEXTEDITOR_CID);
|
||||
NS_DEFINE_NAMED_CID(DOMREQUEST_SERVICE_CID);
|
||||
NS_DEFINE_NAMED_CID(QUOTAMANAGER_SERVICE_CID);
|
||||
|
@ -886,7 +884,6 @@ static const mozilla::Module::CIDEntry kLayoutCIDs[] = {
|
|||
{ &kNS_XPCEXCEPTION_CID, false, nullptr, ExceptionConstructor },
|
||||
{ &kNS_DOMSESSIONSTORAGEMANAGER_CID, false, nullptr, SessionStorageManagerConstructor },
|
||||
{ &kNS_DOMLOCALSTORAGEMANAGER_CID, false, nullptr, LocalStorageManagerConstructor },
|
||||
{ &kNS_DOMJSON_CID, false, nullptr, NS_NewJSON },
|
||||
{ &kNS_TEXTEDITOR_CID, false, nullptr, TextEditorConstructor },
|
||||
{ &kDOMREQUEST_SERVICE_CID, false, nullptr, DOMRequestServiceConstructor },
|
||||
{ &kQUOTAMANAGER_SERVICE_CID, false, nullptr, QuotaManagerServiceConstructor },
|
||||
|
@ -1013,7 +1010,6 @@ static const mozilla::Module::ContractIDEntry kLayoutContracts[] = {
|
|||
// Keeping the old ContractID for backward compatibility
|
||||
{ "@mozilla.org/dom/storagemanager;1", &kNS_DOMLOCALSTORAGEMANAGER_CID },
|
||||
{ "@mozilla.org/dom/sessionStorage-manager;1", &kNS_DOMSESSIONSTORAGEMANAGER_CID },
|
||||
{ "@mozilla.org/dom/json;1", &kNS_DOMJSON_CID },
|
||||
{ "@mozilla.org/editor/texteditor;1", &kNS_TEXTEDITOR_CID },
|
||||
{ DOMREQUEST_SERVICE_CONTRACTID, &kDOMREQUEST_SERVICE_CID },
|
||||
{ QUOTAMANAGER_SERVICE_CONTRACTID, &kQUOTAMANAGER_SERVICE_CID },
|
||||
|
|
|
@ -131,7 +131,6 @@
|
|||
@BINPATH@/components/dom_notification.xpt
|
||||
@BINPATH@/components/dom_html.xpt
|
||||
@BINPATH@/components/dom_offline.xpt
|
||||
@BINPATH@/components/dom_json.xpt
|
||||
@BINPATH@/components/dom_payments.xpt
|
||||
@BINPATH@/components/dom_power.xpt
|
||||
#ifdef MOZ_ANDROID_GCM
|
||||
|
|
Загрузка…
Ссылка в новой задаче