summaryrefslogtreecommitdiff
path: root/netwerk/protocol/about/nsAboutCacheEntry.h
blob: 8bfa0aa72314c5d92f2493ef338e4788af05d1aa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* 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 http://mozilla.org/MPL/2.0/. */

#ifndef nsAboutCacheEntry_h__
#define nsAboutCacheEntry_h__

#include "nsIAboutModule.h"
#include "nsICacheEntryOpenCallback.h"
#include "nsICacheEntry.h"
#include "nsIChannel.h"
#include "nsIStreamListener.h"
#include "nsString.h"
#include "nsCOMPtr.h"

class nsIAsyncOutputStream;
class nsIInputStream;
class nsILoadContextInfo;
class nsIURI;
class nsCString;

class nsAboutCacheEntry final : public nsIAboutModule
{
public:
    NS_DECL_ISUPPORTS
    NS_DECL_NSIABOUTMODULE

private:
    virtual ~nsAboutCacheEntry() {}

    class Channel final : public nsICacheEntryOpenCallback
                        , public nsICacheEntryMetaDataVisitor
                        , public nsIStreamListener
                        , public nsIChannel
    {
    public:
        NS_DECL_ISUPPORTS
        NS_DECL_NSICACHEENTRYOPENCALLBACK
        NS_DECL_NSICACHEENTRYMETADATAVISITOR
        NS_DECL_NSIREQUESTOBSERVER
        NS_DECL_NSISTREAMLISTENER
        NS_FORWARD_SAFE_NSICHANNEL(mChannel)
        NS_FORWARD_SAFE_NSIREQUEST(mChannel)

        Channel()
            : mBuffer(nullptr)
            , mWaitingForData(false)
            , mHexDumpState(0)
        {}

    private:
        virtual ~Channel() {}

    public:
        MOZ_MUST_USE nsresult Init(nsIURI* uri, nsILoadInfo* aLoadInfo);

        MOZ_MUST_USE nsresult GetContentStream(nsIURI *, nsIInputStream **);
        MOZ_MUST_USE nsresult OpenCacheEntry(nsIURI *);
        MOZ_MUST_USE nsresult OpenCacheEntry();
        MOZ_MUST_USE nsresult WriteCacheEntryDescription(nsICacheEntry *);
        MOZ_MUST_USE nsresult WriteCacheEntryUnavailable();
        MOZ_MUST_USE nsresult ParseURI(nsIURI *uri, nsACString &storageName,
                                       nsILoadContextInfo **loadInfo,
                                       nsCString &enahnceID,
                                       nsIURI **cacheUri);
        void CloseContent();

        static MOZ_MUST_USE nsresult
        PrintCacheData(nsIInputStream *aInStream,
                       void *aClosure,
                       const char *aFromSegment,
                       uint32_t aToOffset,
                       uint32_t aCount,
                       uint32_t *aWriteCount);

    private:
        nsCString mStorageName, mEnhanceId;
        nsCOMPtr<nsILoadContextInfo> mLoadInfo;
        nsCOMPtr<nsIURI> mCacheURI;

        nsCString *mBuffer;
        nsCOMPtr<nsIAsyncOutputStream> mOutputStream;
        bool mWaitingForData;
        uint32_t mHexDumpState;

        nsCOMPtr<nsIChannel> mChannel;
    };
};

#define NS_ABOUT_CACHE_ENTRY_MODULE_CID              \
{ /* 7fa5237d-b0eb-438f-9e50-ca0166e63788 */         \
    0x7fa5237d,                                      \
    0xb0eb,                                          \
    0x438f,                                          \
    {0x9e, 0x50, 0xca, 0x01, 0x66, 0xe6, 0x37, 0x88} \
}

#endif // nsAboutCacheEntry_h__