author Timothy Nikkel <>
Thu, 16 Mar 2017 03:06:06 -0500
changeset 348004 d4cafcc44babd82e009801f6d453b6002fb280d7
parent 288776 7f8a1c681597d1f1cfcc33fe47dcf59aff04b924
child 412013 caa5bef6848122d106ad47fc7b2bf104d2d8ce3d
permissions -rw-r--r--
Bug 1343341. Only set the animation state as discarded if we discarded the animated frames (and not a static frame from a first-frame-only decode). r=aosmond The SurfaceCache can hold the first frame of a "static" decode as well as the animated frames in two seperate entries. We only care about what happens to the animated frames, so ignore OnSurfaceDiscarded for anything else. To accomplish this we must pass the SurfaceKey to OnSurfaceDiscarded.

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at */

#ifndef nsDOMOfflineResourceList_h___
#define nsDOMOfflineResourceList_h___

#include "nscore.h"
#include "nsIDOMOfflineResourceList.h"
#include "nsIApplicationCache.h"
#include "nsIApplicationCacheContainer.h"
#include "nsIApplicationCacheService.h"
#include "nsIOfflineCacheUpdate.h"
#include "nsTArray.h"
#include "nsString.h"
#include "nsIURI.h"
#include "nsCOMPtr.h"
#include "nsWeakReference.h"
#include "nsCOMArray.h"
#include "nsIDOMEventListener.h"
#include "nsIObserver.h"
#include "nsIScriptContext.h"
#include "nsCycleCollectionParticipant.h"
#include "nsPIDOMWindow.h"
#include "mozilla/DOMEventTargetHelper.h"
#include "mozilla/ErrorResult.h"

namespace mozilla {
namespace dom {
class DOMStringList;
} // namespace dom
} // namespace mozilla

class nsDOMOfflineResourceList final : public mozilla::DOMEventTargetHelper,
                                       public nsIDOMOfflineResourceList,
                                       public nsIObserver,
                                       public nsIOfflineCacheUpdateObserver,
                                       public nsSupportsWeakReference
  typedef mozilla::ErrorResult ErrorResult;



  nsDOMOfflineResourceList(nsIURI* aManifestURI,
                           nsIURI* aDocumentURI,
                           nsIPrincipal* aLoadingPrincipal,
                           nsPIDOMWindowInner* aWindow);

  void FirePendingEvents();
  void Disconnect();

  nsresult Init();

  nsPIDOMWindowInner* GetParentObject() const
    return GetOwner();
  virtual JSObject*
  WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;

  uint16_t GetStatus(ErrorResult& aRv)
    uint16_t status = 0;
    aRv = GetStatus(&status);
    return status;
  void Update(ErrorResult& aRv)
    aRv = Update();
  void SwapCache(ErrorResult& aRv)
    aRv = SwapCache();


  already_AddRefed<mozilla::dom::DOMStringList> GetMozItems(ErrorResult& aRv);
  bool MozHasItem(const nsAString& aURI, ErrorResult& aRv)
    bool hasItem = false;
    aRv = MozHasItem(aURI, &hasItem);
    return hasItem;
  uint32_t GetMozLength(ErrorResult& aRv)
    uint32_t length = 0;
    aRv = GetMozLength(&length);
    return length;
  void MozItem(uint32_t aIndex, nsAString& aURI, ErrorResult& aRv)
    aRv = MozItem(aIndex, aURI);
  void IndexedGetter(uint32_t aIndex, bool& aFound, nsAString& aURI,
                     ErrorResult& aRv)
    MozItem(aIndex, aURI, aRv);
    aFound = !aURI.IsVoid();
  uint32_t Length()
    mozilla::IgnoredErrorResult rv;
    uint32_t length = GetMozLength(rv);
    return rv.Failed() ? 0 : length;
  void MozAdd(const nsAString& aURI, ErrorResult& aRv)
    aRv = MozAdd(aURI);
  void MozRemove(const nsAString& aURI, ErrorResult& aRv)
    aRv = MozRemove(aURI);

  virtual ~nsDOMOfflineResourceList();

  nsresult SendEvent(const nsAString &aEventName);

  nsresult UpdateAdded(nsIOfflineCacheUpdate *aUpdate);
  nsresult UpdateCompleted(nsIOfflineCacheUpdate *aUpdate);

  already_AddRefed<nsIApplicationCacheContainer> GetDocumentAppCacheContainer();
  already_AddRefed<nsIApplicationCache> GetDocumentAppCache();

  nsresult GetCacheKey(const nsAString &aURI, nsCString &aKey);
  nsresult GetCacheKey(nsIURI *aURI, nsCString &aKey);

  nsresult CacheKeys();
  void ClearCachedKeys();

  bool mInitialized;

  nsCOMPtr<nsIURI> mManifestURI;
  // AsciiSpec of mManifestURI
  nsCString mManifestSpec;

  nsCOMPtr<nsIURI> mDocumentURI;
  nsCOMPtr<nsIPrincipal> mLoadingPrincipal;
  nsCOMPtr<nsIApplicationCacheService> mApplicationCacheService;
  nsCOMPtr<nsIApplicationCache> mAvailableApplicationCache;
  nsCOMPtr<nsIOfflineCacheUpdate> mCacheUpdate;
  bool mExposeCacheUpdateStatus;
  uint16_t mStatus;

  // The set of dynamic keys for this application cache object.
  char **mCachedKeys;
  uint32_t mCachedKeysCount;

  nsCOMArray<nsIDOMEvent> mPendingEvents;