2013-01-20 16:40:09 +04: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/. */
|
1999-10-12 03:47:27 +04:00
|
|
|
|
|
|
|
#include "nsSaveAsCharset.h"
|
2014-05-08 13:32:00 +04:00
|
|
|
#include "mozilla/dom/EncodingUtils.h"
|
1999-10-12 03:47:27 +04:00
|
|
|
|
|
|
|
//
|
|
|
|
// nsISupports methods
|
|
|
|
//
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(nsSaveAsCharset, nsISaveAsCharset)
|
1999-10-12 03:47:27 +04:00
|
|
|
|
|
|
|
//
|
|
|
|
// nsSaveAsCharset
|
|
|
|
//
|
|
|
|
nsSaveAsCharset::nsSaveAsCharset()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsSaveAsCharset::~nsSaveAsCharset()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2015-10-22 11:18:45 +03:00
|
|
|
nsSaveAsCharset::Init(const nsACString& aCharset, uint32_t aIgnored, uint32_t aAlsoIgnored)
|
2002-04-26 02:49:19 +04:00
|
|
|
{
|
2015-10-22 11:18:45 +03:00
|
|
|
nsAutoCString encoding;
|
|
|
|
if (!mozilla::dom::EncodingUtils::FindEncodingForLabelNoReplacement(aCharset, encoding)) {
|
|
|
|
return NS_ERROR_DOM_ENCODING_NOT_SUPPORTED_ERR;
|
2002-04-26 02:49:19 +04:00
|
|
|
}
|
2015-10-22 11:18:45 +03:00
|
|
|
mEncoder = new nsNCRFallbackEncoderWrapper(encoding);
|
|
|
|
mCharset.Assign(encoding);
|
|
|
|
return NS_OK;
|
2002-04-26 02:49:19 +04:00
|
|
|
}
|
|
|
|
|
1999-10-12 03:47:27 +04:00
|
|
|
NS_IMETHODIMP
|
2015-10-22 11:18:45 +03:00
|
|
|
nsSaveAsCharset::Convert(const nsAString& aIn, nsACString& aOut)
|
1999-10-12 03:47:27 +04:00
|
|
|
{
|
2015-10-22 11:18:45 +03:00
|
|
|
if (!mEncoder) {
|
|
|
|
return NS_ERROR_DOM_ENCODING_NOT_SUPPORTED_ERR;
|
1999-10-12 03:47:27 +04:00
|
|
|
}
|
|
|
|
|
2015-10-22 11:18:45 +03:00
|
|
|
if (!mEncoder->Encode(aIn, aOut)) {
|
2013-01-20 16:40:09 +04:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
2014-05-08 13:32:00 +04:00
|
|
|
return NS_OK;
|
2002-04-26 02:49:19 +04:00
|
|
|
}
|
|
|
|
|
2015-10-22 11:18:45 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSaveAsCharset::GetCharset(nsACString& aCharset)
|
2002-04-26 02:49:19 +04:00
|
|
|
{
|
2015-10-22 11:18:45 +03:00
|
|
|
aCharset.Assign(mCharset);
|
2002-04-26 02:49:19 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|