SerializedLoadContext.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 "SerializedLoadContext.h"
  6. #include "nsNetUtil.h"
  7. #include "nsIChannel.h"
  8. #include "nsILoadContext.h"
  9. #include "nsIPrivateBrowsingChannel.h"
  10. #include "nsIWebSocketChannel.h"
  11. namespace IPC {
  12. SerializedLoadContext::SerializedLoadContext(nsILoadContext* aLoadContext)
  13. {
  14. Init(aLoadContext);
  15. }
  16. SerializedLoadContext::SerializedLoadContext(nsIChannel* aChannel)
  17. {
  18. if (!aChannel) {
  19. Init(nullptr);
  20. return;
  21. }
  22. nsCOMPtr<nsILoadContext> loadContext;
  23. NS_QueryNotificationCallbacks(aChannel, loadContext);
  24. Init(loadContext);
  25. if (!loadContext) {
  26. // Attempt to retrieve the private bit from the channel if it has been
  27. // overriden.
  28. bool isPrivate = false;
  29. bool isOverriden = false;
  30. nsCOMPtr<nsIPrivateBrowsingChannel> pbChannel = do_QueryInterface(aChannel);
  31. if (pbChannel &&
  32. NS_SUCCEEDED(pbChannel->IsPrivateModeOverriden(&isPrivate,
  33. &isOverriden)) &&
  34. isOverriden) {
  35. mIsPrivateBitValid = true;
  36. }
  37. mOriginAttributes.SyncAttributesWithPrivateBrowsing(isPrivate);
  38. }
  39. }
  40. SerializedLoadContext::SerializedLoadContext(nsIWebSocketChannel* aChannel)
  41. {
  42. nsCOMPtr<nsILoadContext> loadContext;
  43. if (aChannel) {
  44. NS_QueryNotificationCallbacks(aChannel, loadContext);
  45. }
  46. Init(loadContext);
  47. }
  48. void
  49. SerializedLoadContext::Init(nsILoadContext* aLoadContext)
  50. {
  51. if (aLoadContext) {
  52. mIsNotNull = true;
  53. mIsPrivateBitValid = true;
  54. aLoadContext->GetIsContent(&mIsContent);
  55. aLoadContext->GetUseRemoteTabs(&mUseRemoteTabs);
  56. if (!aLoadContext->GetOriginAttributes(mOriginAttributes)) {
  57. NS_WARNING("GetOriginAttributes failed");
  58. }
  59. } else {
  60. mIsNotNull = false;
  61. mIsPrivateBitValid = false;
  62. // none of below values really matter when mIsNotNull == false:
  63. // we won't be GetInterfaced to nsILoadContext
  64. mIsContent = true;
  65. mUseRemoteTabs = false;
  66. }
  67. }
  68. } // namespace IPC