nsDownloadHistory.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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 "nsDownloadHistory.h"
  6. #include "nsCOMPtr.h"
  7. #include "nsServiceManagerUtils.h"
  8. #include "nsIGlobalHistory2.h"
  9. #include "nsIObserverService.h"
  10. #include "nsIURI.h"
  11. #include "mozilla/Services.h"
  12. NS_IMPL_ISUPPORTS(nsDownloadHistory, nsIDownloadHistory)
  13. NS_IMETHODIMP
  14. nsDownloadHistory::AddDownload(nsIURI* aSource,
  15. nsIURI* aReferrer,
  16. PRTime aStartTime,
  17. nsIURI* aDestination)
  18. {
  19. NS_ENSURE_ARG_POINTER(aSource);
  20. nsCOMPtr<nsIGlobalHistory2> history =
  21. do_GetService("@mozilla.org/browser/global-history;2");
  22. if (!history) {
  23. return NS_ERROR_NOT_AVAILABLE;
  24. }
  25. bool visited;
  26. nsresult rv = history->IsVisited(aSource, &visited);
  27. NS_ENSURE_SUCCESS(rv, rv);
  28. rv = history->AddURI(aSource, false, true, aReferrer);
  29. NS_ENSURE_SUCCESS(rv, rv);
  30. if (!visited) {
  31. nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
  32. if (os) {
  33. os->NotifyObservers(aSource, NS_LINK_VISITED_EVENT_TOPIC, nullptr);
  34. }
  35. }
  36. return NS_OK;
  37. }
  38. NS_IMETHODIMP
  39. nsDownloadHistory::RemoveAllDownloads()
  40. {
  41. return NS_ERROR_NOT_IMPLEMENTED;
  42. }