docshell/base/nsDownloadHistory.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/docshell/base/nsDownloadHistory.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,56 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
     1.5 + * vim: sw=2 ts=2 sts=2
     1.6 + * This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +#include "nsDownloadHistory.h"
    1.11 +#include "nsCOMPtr.h"
    1.12 +#include "nsServiceManagerUtils.h"
    1.13 +#include "nsIGlobalHistory2.h"
    1.14 +#include "nsIObserverService.h"
    1.15 +#include "nsIURI.h"
    1.16 +
    1.17 +////////////////////////////////////////////////////////////////////////////////
    1.18 +//// nsDownloadHistory
    1.19 +
    1.20 +NS_IMPL_ISUPPORTS(nsDownloadHistory, nsIDownloadHistory)
    1.21 +
    1.22 +////////////////////////////////////////////////////////////////////////////////
    1.23 +//// nsIDownloadHistory
    1.24 +
    1.25 +NS_IMETHODIMP
    1.26 +nsDownloadHistory::AddDownload(nsIURI *aSource,
    1.27 +                               nsIURI *aReferrer,
    1.28 +                               PRTime aStartTime,
    1.29 +                               nsIURI *aDestination)
    1.30 +{
    1.31 +  NS_ENSURE_ARG_POINTER(aSource);
    1.32 +
    1.33 +  nsCOMPtr<nsIGlobalHistory2> history =
    1.34 +    do_GetService("@mozilla.org/browser/global-history;2");
    1.35 +  if (!history)
    1.36 +    return NS_ERROR_NOT_AVAILABLE;
    1.37 +
    1.38 +  bool visited;
    1.39 +  nsresult rv = history->IsVisited(aSource, &visited);
    1.40 +  NS_ENSURE_SUCCESS(rv, rv);
    1.41 +
    1.42 +  rv = history->AddURI(aSource, false, true, aReferrer);
    1.43 +  NS_ENSURE_SUCCESS(rv, rv);
    1.44 +  
    1.45 +  if (!visited) {
    1.46 +    nsCOMPtr<nsIObserverService> os =
    1.47 +      do_GetService("@mozilla.org/observer-service;1");
    1.48 +    if (os)
    1.49 +      os->NotifyObservers(aSource, NS_LINK_VISITED_EVENT_TOPIC, nullptr);
    1.50 +  }
    1.51 +
    1.52 +  return NS_OK;
    1.53 +}
    1.54 +
    1.55 +NS_IMETHODIMP
    1.56 +nsDownloadHistory::RemoveAllDownloads()
    1.57 +{
    1.58 +  return NS_ERROR_NOT_IMPLEMENTED;
    1.59 +}

mercurial