SharedSSLState.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /* -*- Mode: C++; tab-width: 2; 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. #ifndef SharedSSLState_h
  6. #define SharedSSLState_h
  7. #include "mozilla/RefPtr.h"
  8. #include "nsNSSIOLayer.h"
  9. class nsClientAuthRememberService;
  10. class nsIObserver;
  11. namespace mozilla {
  12. namespace psm {
  13. class SharedSSLState {
  14. public:
  15. NS_INLINE_DECL_THREADSAFE_REFCOUNTING(SharedSSLState)
  16. SharedSSLState();
  17. static void GlobalInit();
  18. static void GlobalCleanup();
  19. nsClientAuthRememberService* GetClientAuthRememberService() {
  20. return mClientAuthRemember;
  21. }
  22. nsSSLIOLayerHelpers& IOLayerHelpers() {
  23. return mIOLayerHelpers;
  24. }
  25. // Main-thread only
  26. void ResetStoredData();
  27. void NotePrivateBrowsingStatus();
  28. void SetOCSPStaplingEnabled(bool staplingEnabled)
  29. {
  30. mOCSPStaplingEnabled = staplingEnabled;
  31. }
  32. void SetOCSPMustStapleEnabled(bool mustStapleEnabled)
  33. {
  34. mOCSPMustStapleEnabled = mustStapleEnabled;
  35. }
  36. void SetSignedCertTimestampsEnabled(bool signedCertTimestampsEnabled)
  37. {
  38. mSignedCertTimestampsEnabled = signedCertTimestampsEnabled;
  39. }
  40. // The following methods may be called from any thread
  41. bool SocketCreated();
  42. void NoteSocketCreated();
  43. static void NoteCertOverrideServiceInstantiated();
  44. bool IsOCSPStaplingEnabled() const { return mOCSPStaplingEnabled; }
  45. bool IsOCSPMustStapleEnabled() const { return mOCSPMustStapleEnabled; }
  46. bool IsSignedCertTimestampsEnabled() const
  47. {
  48. return mSignedCertTimestampsEnabled;
  49. }
  50. private:
  51. ~SharedSSLState();
  52. void Cleanup();
  53. nsCOMPtr<nsIObserver> mObserver;
  54. RefPtr<nsClientAuthRememberService> mClientAuthRemember;
  55. nsSSLIOLayerHelpers mIOLayerHelpers;
  56. // True if any sockets have been created that use this shared data.
  57. // Requires synchronization between the socket and main threads for
  58. // reading/writing.
  59. Mutex mMutex;
  60. bool mSocketCreated;
  61. bool mOCSPStaplingEnabled;
  62. bool mOCSPMustStapleEnabled;
  63. bool mSignedCertTimestampsEnabled;
  64. };
  65. SharedSSLState* PublicSSLState();
  66. SharedSSLState* PrivateSSLState();
  67. } // namespace psm
  68. } // namespace mozilla
  69. #endif