nsSaveAsCharset.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #include "nsSaveAsCharset.h"
  6. #include "mozilla/dom/EncodingUtils.h"
  7. //
  8. // nsISupports methods
  9. //
  10. NS_IMPL_ISUPPORTS(nsSaveAsCharset, nsISaveAsCharset)
  11. //
  12. // nsSaveAsCharset
  13. //
  14. nsSaveAsCharset::nsSaveAsCharset()
  15. {
  16. }
  17. nsSaveAsCharset::~nsSaveAsCharset()
  18. {
  19. }
  20. NS_IMETHODIMP
  21. nsSaveAsCharset::Init(const nsACString& aCharset, uint32_t aIgnored, uint32_t aAlsoIgnored)
  22. {
  23. nsAutoCString encoding;
  24. if (!mozilla::dom::EncodingUtils::FindEncodingForLabelNoReplacement(aCharset, encoding)) {
  25. return NS_ERROR_DOM_ENCODING_NOT_SUPPORTED_ERR;
  26. }
  27. mEncoder = new nsNCRFallbackEncoderWrapper(encoding);
  28. mCharset.Assign(encoding);
  29. return NS_OK;
  30. }
  31. NS_IMETHODIMP
  32. nsSaveAsCharset::Convert(const nsAString& aIn, nsACString& aOut)
  33. {
  34. if (!mEncoder) {
  35. return NS_ERROR_DOM_ENCODING_NOT_SUPPORTED_ERR;
  36. }
  37. if (!mEncoder->Encode(aIn, aOut)) {
  38. return NS_ERROR_OUT_OF_MEMORY;
  39. }
  40. return NS_OK;
  41. }
  42. NS_IMETHODIMP
  43. nsSaveAsCharset::GetCharset(nsACString& aCharset)
  44. {
  45. aCharset.Assign(mCharset);
  46. return NS_OK;
  47. }