Tue, 06 Jan 2015 21:39:09 +0100
Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
1 /* vim: set shiftwidth=2 tabstop=8 autoindent cindent expandtab: */
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/. */
6 /* implements DOM interface for querying and observing media queries */
8 #ifndef mozilla_dom_MediaQueryList_h
9 #define mozilla_dom_MediaQueryList_h
11 #include "nsISupports.h"
12 #include "nsCycleCollectionParticipant.h"
13 #include "nsAutoPtr.h"
14 #include "nsTArray.h"
15 #include "prclist.h"
16 #include "mozilla/Attributes.h"
17 #include "nsWrapperCache.h"
18 #include "mozilla/dom/MediaQueryListBinding.h"
20 class nsPresContext;
21 class nsMediaList;
23 namespace mozilla {
24 namespace dom {
26 class MediaQueryList MOZ_FINAL : public nsISupports,
27 public nsWrapperCache,
28 public PRCList
29 {
30 public:
31 // The caller who constructs is responsible for calling Evaluate
32 // before calling any other methods.
33 MediaQueryList(nsPresContext *aPresContext,
34 const nsAString &aMediaQueryList);
35 private:
36 ~MediaQueryList();
38 public:
39 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
40 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(MediaQueryList)
42 nsISupports* GetParentObject() const;
44 struct HandleChangeData {
45 nsRefPtr<MediaQueryList> mql;
46 nsRefPtr<mozilla::dom::MediaQueryListListener> callback;
47 };
49 typedef FallibleTArray< nsRefPtr<mozilla::dom::MediaQueryListListener> > CallbackList;
50 typedef FallibleTArray<HandleChangeData> NotifyList;
52 // Appends listeners that need notification to aListenersToNotify
53 void MediumFeaturesChanged(NotifyList &aListenersToNotify);
55 bool HasListeners() const { return !mCallbacks.IsEmpty(); }
57 void RemoveAllListeners();
59 JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE;
61 // WebIDL methods
62 void GetMedia(nsAString& aMedia);
63 bool Matches();
64 void AddListener(mozilla::dom::MediaQueryListListener& aListener);
65 void RemoveListener(mozilla::dom::MediaQueryListListener& aListener);
67 private:
68 void RecomputeMatches();
70 // We only need a pointer to the pres context to support lazy
71 // reevaluation following dynamic changes. However, this lazy
72 // reevaluation is perhaps somewhat important, since some usage
73 // patterns may involve the creation of large numbers of
74 // MediaQueryList objects which almost immediately become garbage
75 // (after a single call to the .matches getter).
76 //
77 // This pointer does make us a little more dependent on cycle
78 // collection.
79 //
80 // We have a non-null mPresContext for our entire lifetime except
81 // after cycle collection unlinking. Having a non-null mPresContext
82 // is equivalent to being in that pres context's mDOMMediaQueryLists
83 // linked list.
84 nsRefPtr<nsPresContext> mPresContext;
86 nsRefPtr<nsMediaList> mMediaList;
87 bool mMatches;
88 bool mMatchesValid;
89 CallbackList mCallbacks;
90 };
92 } // namespace dom
93 } // namespace mozilla
95 #endif /* !defined(mozilla_dom_MediaQueryList_h) */