nsIconProtocolHandler.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  2. *
  3. * This Source Code Form is subject to the terms of the Mozilla Public
  4. * License, v. 2.0. If a copy of the MPL was not distributed with this
  5. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  6. #include "nsIconProtocolHandler.h"
  7. #include "nsIconChannel.h"
  8. #include "nsIconURI.h"
  9. #include "nsIURL.h"
  10. #include "nsCRT.h"
  11. #include "nsCOMPtr.h"
  12. #include "nsIComponentManager.h"
  13. #include "nsIServiceManager.h"
  14. #include "nsNetCID.h"
  15. ///////////////////////////////////////////////////////////////////////////////
  16. nsIconProtocolHandler::nsIconProtocolHandler()
  17. { }
  18. nsIconProtocolHandler::~nsIconProtocolHandler()
  19. { }
  20. NS_IMPL_ISUPPORTS(nsIconProtocolHandler, nsIProtocolHandler,
  21. nsISupportsWeakReference)
  22. ///////////////////////////////////////////////////////////////////////////////
  23. // nsIProtocolHandler methods:
  24. NS_IMETHODIMP
  25. nsIconProtocolHandler::GetScheme(nsACString& result)
  26. {
  27. result = "moz-icon";
  28. return NS_OK;
  29. }
  30. NS_IMETHODIMP
  31. nsIconProtocolHandler::GetDefaultPort(int32_t* result)
  32. {
  33. *result = 0;
  34. return NS_OK;
  35. }
  36. NS_IMETHODIMP
  37. nsIconProtocolHandler::AllowPort(int32_t port,
  38. const char* scheme,
  39. bool* _retval)
  40. {
  41. // don't override anything.
  42. *_retval = false;
  43. return NS_OK;
  44. }
  45. NS_IMETHODIMP
  46. nsIconProtocolHandler::GetProtocolFlags(uint32_t* result)
  47. {
  48. *result = URI_NORELATIVE | URI_NOAUTH | URI_IS_UI_RESOURCE |
  49. URI_IS_LOCAL_RESOURCE;
  50. return NS_OK;
  51. }
  52. NS_IMETHODIMP
  53. nsIconProtocolHandler::NewURI(const nsACString& aSpec,
  54. const char* aOriginCharset, // ignored
  55. nsIURI* aBaseURI,
  56. nsIURI** result)
  57. {
  58. nsCOMPtr<nsIMozIconURI> uri = new nsMozIconURI();
  59. if (!uri) return NS_ERROR_OUT_OF_MEMORY;
  60. nsresult rv = uri->SetSpec(aSpec);
  61. if (NS_FAILED(rv)) return rv;
  62. nsCOMPtr<nsIURL> iconURL;
  63. uri->GetIconURL(getter_AddRefs(iconURL));
  64. if (iconURL) {
  65. uri = new nsNestedMozIconURI();
  66. rv = uri->SetSpec(aSpec);
  67. if (NS_FAILED(rv)) {
  68. return rv;
  69. }
  70. }
  71. NS_ADDREF(*result = uri);
  72. return NS_OK;
  73. }
  74. NS_IMETHODIMP
  75. nsIconProtocolHandler::NewChannel2(nsIURI* url,
  76. nsILoadInfo* aLoadInfo,
  77. nsIChannel** result)
  78. {
  79. NS_ENSURE_ARG_POINTER(url);
  80. nsIconChannel* channel = new nsIconChannel;
  81. if (!channel) {
  82. return NS_ERROR_OUT_OF_MEMORY;
  83. }
  84. NS_ADDREF(channel);
  85. nsresult rv = channel->Init(url);
  86. if (NS_FAILED(rv)) {
  87. NS_RELEASE(channel);
  88. return rv;
  89. }
  90. // set the loadInfo on the new channel
  91. rv = channel->SetLoadInfo(aLoadInfo);
  92. if (NS_FAILED(rv)) {
  93. NS_RELEASE(channel);
  94. return rv;
  95. }
  96. *result = channel;
  97. return NS_OK;
  98. }
  99. NS_IMETHODIMP
  100. nsIconProtocolHandler::NewChannel(nsIURI* url, nsIChannel** result)
  101. {
  102. return NewChannel2(url, nullptr, result);
  103. }
  104. ////////////////////////////////////////////////////////////////////////////////