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