WebBrowserPersistResourcesParent.cpp 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 "WebBrowserPersistResourcesParent.h"
  7. #include "nsThreadUtils.h"
  8. namespace mozilla {
  9. NS_IMPL_ISUPPORTS(WebBrowserPersistResourcesParent,
  10. nsIWebBrowserPersistDocumentReceiver)
  11. WebBrowserPersistResourcesParent::WebBrowserPersistResourcesParent(
  12. nsIWebBrowserPersistDocument* aDocument,
  13. nsIWebBrowserPersistResourceVisitor* aVisitor)
  14. : mDocument(aDocument)
  15. , mVisitor(aVisitor)
  16. {
  17. MOZ_ASSERT(aDocument);
  18. MOZ_ASSERT(aVisitor);
  19. }
  20. WebBrowserPersistResourcesParent::~WebBrowserPersistResourcesParent()
  21. {
  22. }
  23. void
  24. WebBrowserPersistResourcesParent::ActorDestroy(ActorDestroyReason aWhy)
  25. {
  26. if (aWhy != Deletion && mVisitor) {
  27. // See comment in WebBrowserPersistDocumentParent::ActorDestroy
  28. // (or bug 1202887) for why this is deferred.
  29. nsCOMPtr<nsIRunnable> errorLater = NewRunnableMethod
  30. <nsCOMPtr<nsIWebBrowserPersistDocument>, nsresult>
  31. (mVisitor, &nsIWebBrowserPersistResourceVisitor::EndVisit,
  32. mDocument, NS_ERROR_FAILURE);
  33. NS_DispatchToCurrentThread(errorLater);
  34. }
  35. mVisitor = nullptr;
  36. }
  37. bool
  38. WebBrowserPersistResourcesParent::Recv__delete__(const nsresult& aStatus)
  39. {
  40. mVisitor->EndVisit(mDocument, aStatus);
  41. mVisitor = nullptr;
  42. return true;
  43. }
  44. bool
  45. WebBrowserPersistResourcesParent::RecvVisitResource(const nsCString& aURI)
  46. {
  47. mVisitor->VisitResource(mDocument, aURI);
  48. return true;
  49. }
  50. bool
  51. WebBrowserPersistResourcesParent::RecvVisitDocument(PWebBrowserPersistDocumentParent* aSubDocument)
  52. {
  53. // Don't expose the subdocument to the visitor until it's ready
  54. // (until the actor isn't in START state).
  55. static_cast<WebBrowserPersistDocumentParent*>(aSubDocument)
  56. ->SetOnReady(this);
  57. return true;
  58. }
  59. NS_IMETHODIMP
  60. WebBrowserPersistResourcesParent::OnDocumentReady(nsIWebBrowserPersistDocument* aSubDocument)
  61. {
  62. if (!mVisitor) {
  63. return NS_ERROR_FAILURE;
  64. }
  65. mVisitor->VisitDocument(mDocument, aSubDocument);
  66. return NS_OK;
  67. }
  68. NS_IMETHODIMP
  69. WebBrowserPersistResourcesParent::OnError(nsresult aFailure)
  70. {
  71. // Nothing useful to do but ignore the failed document.
  72. return NS_OK;
  73. }
  74. } // namespace mozilla