nsSystemPrincipal.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
  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. /* The privileged system principal. */
  6. #include "nscore.h"
  7. #include "nsSystemPrincipal.h"
  8. #include "nsIComponentManager.h"
  9. #include "nsIServiceManager.h"
  10. #include "nsIURL.h"
  11. #include "nsCOMPtr.h"
  12. #include "nsXPIDLString.h"
  13. #include "nsReadableUtils.h"
  14. #include "nsCRT.h"
  15. #include "nsString.h"
  16. #include "nsIClassInfoImpl.h"
  17. #include "nsIScriptSecurityManager.h"
  18. #include "pratom.h"
  19. NS_IMPL_CLASSINFO(nsSystemPrincipal, nullptr,
  20. nsIClassInfo::SINGLETON | nsIClassInfo::MAIN_THREAD_ONLY,
  21. NS_SYSTEMPRINCIPAL_CID)
  22. NS_IMPL_QUERY_INTERFACE_CI(nsSystemPrincipal,
  23. nsIPrincipal,
  24. nsISerializable)
  25. NS_IMPL_CI_INTERFACE_GETTER(nsSystemPrincipal,
  26. nsIPrincipal,
  27. nsISerializable)
  28. #define SYSTEM_PRINCIPAL_SPEC "[System Principal]"
  29. nsresult
  30. nsSystemPrincipal::GetScriptLocation(nsACString &aStr)
  31. {
  32. aStr.AssignLiteral(SYSTEM_PRINCIPAL_SPEC);
  33. return NS_OK;
  34. }
  35. ///////////////////////////////////////
  36. // Methods implementing nsIPrincipal //
  37. ///////////////////////////////////////
  38. NS_IMETHODIMP
  39. nsSystemPrincipal::GetHashValue(uint32_t *result)
  40. {
  41. *result = NS_PTR_TO_INT32(this);
  42. return NS_OK;
  43. }
  44. NS_IMETHODIMP
  45. nsSystemPrincipal::GetURI(nsIURI** aURI)
  46. {
  47. *aURI = nullptr;
  48. return NS_OK;
  49. }
  50. nsresult
  51. nsSystemPrincipal::GetOriginInternal(nsACString& aOrigin)
  52. {
  53. aOrigin.AssignLiteral(SYSTEM_PRINCIPAL_SPEC);
  54. return NS_OK;
  55. }
  56. NS_IMETHODIMP
  57. nsSystemPrincipal::GetCsp(nsIContentSecurityPolicy** aCsp)
  58. {
  59. *aCsp = nullptr;
  60. return NS_OK;
  61. }
  62. NS_IMETHODIMP
  63. nsSystemPrincipal::SetCsp(nsIContentSecurityPolicy* aCsp)
  64. {
  65. // Never destroy an existing CSP on the principal.
  66. // This method should only be called in rare cases.
  67. return NS_ERROR_FAILURE;
  68. }
  69. NS_IMETHODIMP
  70. nsSystemPrincipal::EnsureCSP(nsIDOMDocument* aDocument,
  71. nsIContentSecurityPolicy** aCSP)
  72. {
  73. // CSP on a system principal makes no sense
  74. return NS_ERROR_FAILURE;
  75. }
  76. NS_IMETHODIMP
  77. nsSystemPrincipal::GetPreloadCsp(nsIContentSecurityPolicy** aPreloadCSP)
  78. {
  79. *aPreloadCSP = nullptr;
  80. return NS_OK;
  81. }
  82. NS_IMETHODIMP
  83. nsSystemPrincipal::EnsurePreloadCSP(nsIDOMDocument* aDocument,
  84. nsIContentSecurityPolicy** aPreloadCSP)
  85. {
  86. // CSP on a system principal makes no sense
  87. return NS_OK;
  88. }
  89. NS_IMETHODIMP
  90. nsSystemPrincipal::GetDomain(nsIURI** aDomain)
  91. {
  92. *aDomain = nullptr;
  93. return NS_OK;
  94. }
  95. NS_IMETHODIMP
  96. nsSystemPrincipal::SetDomain(nsIURI* aDomain)
  97. {
  98. return NS_OK;
  99. }
  100. NS_IMETHODIMP
  101. nsSystemPrincipal::GetBaseDomain(nsACString& aBaseDomain)
  102. {
  103. // No base domain for chrome.
  104. return NS_OK;
  105. }
  106. //////////////////////////////////////////
  107. // Methods implementing nsISerializable //
  108. //////////////////////////////////////////
  109. NS_IMETHODIMP
  110. nsSystemPrincipal::Read(nsIObjectInputStream* aStream)
  111. {
  112. // no-op: CID is sufficient to identify the mSystemPrincipal singleton
  113. return NS_OK;
  114. }
  115. NS_IMETHODIMP
  116. nsSystemPrincipal::Write(nsIObjectOutputStream* aStream)
  117. {
  118. // no-op: CID is sufficient to identify the mSystemPrincipal singleton
  119. return NS_OK;
  120. }