WebBrowserPersistResourcesChild.cpp 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /* -*- Mode: C++; tab-width: 4; 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 "WebBrowserPersistResourcesChild.h"
  7. #include "WebBrowserPersistDocumentChild.h"
  8. #include "mozilla/dom/ContentChild.h"
  9. namespace mozilla {
  10. NS_IMPL_ISUPPORTS(WebBrowserPersistResourcesChild,
  11. nsIWebBrowserPersistResourceVisitor)
  12. WebBrowserPersistResourcesChild::WebBrowserPersistResourcesChild()
  13. {
  14. }
  15. WebBrowserPersistResourcesChild::~WebBrowserPersistResourcesChild()
  16. {
  17. }
  18. NS_IMETHODIMP
  19. WebBrowserPersistResourcesChild::VisitResource(nsIWebBrowserPersistDocument *aDocument,
  20. const nsACString& aURI)
  21. {
  22. nsCString copiedURI(aURI); // Yay, XPIDL/IPDL mismatch.
  23. SendVisitResource(copiedURI);
  24. return NS_OK;
  25. }
  26. NS_IMETHODIMP
  27. WebBrowserPersistResourcesChild::VisitDocument(nsIWebBrowserPersistDocument* aDocument,
  28. nsIWebBrowserPersistDocument* aSubDocument)
  29. {
  30. auto* subActor = new WebBrowserPersistDocumentChild();
  31. // As a consequence of how PWebBrowserPersistDocumentConstructor
  32. // can be sent by both the parent and the child, we must pass the
  33. // aBrowser and outerWindowID arguments here, but the values are
  34. // ignored by the parent. In particular, the TabChild in which
  35. // persistence started does not necessarily exist at this point;
  36. // see bug 1203602.
  37. if (!Manager()->Manager()
  38. ->SendPWebBrowserPersistDocumentConstructor(subActor, nullptr, 0)) {
  39. // NOTE: subActor is freed at this point.
  40. return NS_ERROR_FAILURE;
  41. }
  42. // ...but here, IPC won't free subActor until after this returns
  43. // to the event loop.
  44. // The order of these two messages will be preserved, because
  45. // they're the same toplevel protocol and priority.
  46. //
  47. // With this ordering, it's always the transition out of START
  48. // state that causes a document's parent actor to be exposed to
  49. // XPCOM (for both parent->child and child->parent construction),
  50. // which simplifies the lifetime management.
  51. SendVisitDocument(subActor);
  52. subActor->Start(aSubDocument);
  53. return NS_OK;
  54. }
  55. NS_IMETHODIMP
  56. WebBrowserPersistResourcesChild::EndVisit(nsIWebBrowserPersistDocument *aDocument,
  57. nsresult aStatus)
  58. {
  59. Send__delete__(this, aStatus);
  60. return NS_OK;
  61. }
  62. } // namespace mozilla