2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* 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/. */
|
2007-12-28 00:34:03 +03:00
|
|
|
|
|
|
|
#ifndef nsJSON_h__
|
|
|
|
#define nsJSON_h__
|
|
|
|
|
|
|
|
#include "nsIJSON.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsIOutputStream.h"
|
2017-04-27 13:27:03 +03:00
|
|
|
#include "mozilla/Encoding.h"
|
2007-12-28 00:34:03 +03:00
|
|
|
#include "nsIRequestObserver.h"
|
|
|
|
#include "nsIStreamListener.h"
|
|
|
|
#include "nsTArray.h"
|
|
|
|
|
2008-02-07 10:19:26 +03:00
|
|
|
class nsIURI;
|
|
|
|
|
2013-04-12 07:20:18 +04:00
|
|
|
class MOZ_STACK_CLASS nsJSONWriter
|
2007-12-28 00:34:03 +03:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsJSONWriter();
|
2014-09-02 04:49:25 +04:00
|
|
|
explicit nsJSONWriter(nsIOutputStream* aStream);
|
2007-12-28 00:34:03 +03:00
|
|
|
virtual ~nsJSONWriter();
|
|
|
|
nsCOMPtr<nsIOutputStream> mStream;
|
2014-01-04 19:02:17 +04:00
|
|
|
nsresult Write(const char16_t *aBuffer, uint32_t aLength);
|
2008-02-07 10:19:26 +03:00
|
|
|
nsString mOutputString;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool DidWrite();
|
2008-02-07 10:19:26 +03:00
|
|
|
void FlushBuffer();
|
2007-12-28 00:34:03 +03:00
|
|
|
|
|
|
|
protected:
|
2014-01-04 19:02:17 +04:00
|
|
|
char16_t *mBuffer;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t mBufferCount;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mDidWrite;
|
2017-04-27 13:27:03 +03:00
|
|
|
nsresult WriteToStream(nsIOutputStream* aStream,
|
|
|
|
mozilla::Encoder* encoder,
|
|
|
|
const char16_t* aBuffer,
|
|
|
|
uint32_t aLength);
|
2007-12-28 00:34:03 +03:00
|
|
|
|
2017-04-27 13:27:03 +03:00
|
|
|
mozilla::UniquePtr<mozilla::Encoder> mEncoder;
|
2007-12-28 00:34:03 +03:00
|
|
|
};
|
|
|
|
|
2017-08-06 04:25:15 +03:00
|
|
|
class nsJSON final : public nsIJSON
|
2007-12-28 00:34:03 +03:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsJSON();
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIJSON
|
|
|
|
|
|
|
|
protected:
|
2014-06-23 23:56:07 +04:00
|
|
|
virtual ~nsJSON();
|
|
|
|
|
2011-11-26 14:21:29 +04:00
|
|
|
nsresult DecodeInternal(JSContext* cx,
|
|
|
|
nsIInputStream* aStream,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t aContentLength,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aNeedsConverter,
|
2014-01-09 21:39:36 +04:00
|
|
|
JS::MutableHandle<JS::Value> aRetVal);
|
2008-02-07 10:19:26 +03:00
|
|
|
nsCOMPtr<nsIURI> mURI;
|
2007-12-28 00:34:03 +03:00
|
|
|
};
|
|
|
|
|
2010-06-10 22:11:11 +04:00
|
|
|
nsresult
|
2007-12-28 00:34:03 +03:00
|
|
|
NS_NewJSON(nsISupports* aOuter, REFNSIID aIID, void** aResult);
|
|
|
|
|
|
|
|
class nsJSONListener : public nsIStreamListener
|
|
|
|
{
|
|
|
|
public:
|
2013-05-24 02:28:31 +04:00
|
|
|
nsJSONListener(JSContext *cx, JS::Value *rootVal, bool needsConverter);
|
2007-12-28 00:34:03 +03:00
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIREQUESTOBSERVER
|
|
|
|
NS_DECL_NSISTREAMLISTENER
|
|
|
|
|
|
|
|
protected:
|
2014-06-23 23:56:07 +04:00
|
|
|
virtual ~nsJSONListener();
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mNeedsConverter;
|
2007-12-28 00:34:03 +03:00
|
|
|
JSContext *mCx;
|
2013-04-03 03:05:37 +04:00
|
|
|
JS::Value *mRootVal;
|
2017-04-27 13:27:03 +03:00
|
|
|
mozilla::UniquePtr<mozilla::Decoder> mDecoder;
|
2014-01-04 19:02:17 +04:00
|
|
|
nsTArray<char16_t> mBufferedChars;
|
2012-08-22 19:56:38 +04:00
|
|
|
nsresult ProcessBytes(const char* aBuffer, uint32_t aByteLength);
|
|
|
|
nsresult ConsumeConverted(const char* aBuffer, uint32_t aByteLength);
|
2014-01-04 19:02:17 +04:00
|
|
|
nsresult Consume(const char16_t *data, uint32_t len);
|
2007-12-28 00:34:03 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|