Line data Source code
1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : // vim:cindent:tabstop=2:expandtab:shiftwidth=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 :
7 : /* a CSS style sheet returned from nsIStyleSheetService.preloadSheet */
8 :
9 : #ifndef mozilla_PreloadedStyleSheet_h
10 : #define mozilla_PreloadedStyleSheet_h
11 :
12 : #include "mozilla/css/SheetParsingMode.h"
13 : #include "mozilla/NotNull.h"
14 : #include "mozilla/Result.h"
15 : #include "mozilla/StyleBackendType.h"
16 : #include "nsCOMPtr.h"
17 : #include "nsCycleCollectionParticipant.h"
18 : #include "nsICSSLoaderObserver.h"
19 : #include "nsIPreloadedStyleSheet.h"
20 :
21 : class nsIURI;
22 :
23 : namespace mozilla {
24 : namespace dom {
25 : class Promise;
26 : }
27 :
28 : class StyleSheet;
29 :
30 : class PreloadedStyleSheet : public nsIPreloadedStyleSheet
31 : {
32 : public:
33 : // *aResult is addrefed.
34 : static nsresult Create(nsIURI* aURI, css::SheetParsingMode aParsingMode,
35 : PreloadedStyleSheet** aResult);
36 :
37 : NS_DECL_CYCLE_COLLECTING_ISUPPORTS
38 9 : NS_DECL_CYCLE_COLLECTION_CLASS(PreloadedStyleSheet)
39 :
40 : // *aResult is not addrefed, since the PreloadedStyleSheet holds a strong
41 : // reference to the sheet.
42 : nsresult GetSheet(StyleBackendType aType, StyleSheet** aResult);
43 :
44 : nsresult Preload();
45 : nsresult PreloadAsync(NotNull<dom::Promise*> aPromise);
46 :
47 : protected:
48 0 : virtual ~PreloadedStyleSheet() {}
49 :
50 : private:
51 : PreloadedStyleSheet(nsIURI* aURI, css::SheetParsingMode aParsingMode);
52 :
53 : class StylesheetPreloadObserver final : public nsICSSLoaderObserver
54 : {
55 : public:
56 : NS_DECL_ISUPPORTS
57 :
58 0 : explicit StylesheetPreloadObserver(NotNull<dom::Promise*> aPromise,
59 : PreloadedStyleSheet* aSheet)
60 0 : : mPromise(aPromise)
61 0 : , mPreloadedSheet(aSheet)
62 0 : {}
63 :
64 : NS_IMETHOD StyleSheetLoaded(StyleSheet* aSheet,
65 : bool aWasAlternate,
66 : nsresult aStatus) override;
67 :
68 : protected:
69 0 : virtual ~StylesheetPreloadObserver() {}
70 :
71 : private:
72 : RefPtr<dom::Promise> mPromise;
73 : RefPtr<PreloadedStyleSheet> mPreloadedSheet;
74 : };
75 :
76 : RefPtr<StyleSheet> mGecko;
77 : RefPtr<StyleSheet> mServo;
78 :
79 : bool mLoaded;
80 : nsCOMPtr<nsIURI> mURI;
81 : css::SheetParsingMode mParsingMode;
82 : };
83 :
84 : } // namespace mozilla
85 :
86 : #endif // mozilla_PreloadedStyleSheet_h
|