1 | /*
|
---|
2 | * Copyright (C) 2009 Google Inc. All rights reserved.
|
---|
3 | *
|
---|
4 | * Redistribution and use in source and binary forms, with or without
|
---|
5 | * modification, are permitted provided that the following conditions are
|
---|
6 | * met:
|
---|
7 | *
|
---|
8 | * * Redistributions of source code must retain the above copyright
|
---|
9 | * notice, this list of conditions and the following disclaimer.
|
---|
10 | * * Redistributions in binary form must reproduce the above
|
---|
11 | * copyright notice, this list of conditions and the following disclaimer
|
---|
12 | * in the documentation and/or other materials provided with the
|
---|
13 | * distribution.
|
---|
14 | * * Neither the name of Google Inc. nor the names of its
|
---|
15 | * contributors may be used to endorse or promote products derived from
|
---|
16 | * this software without specific prior written permission.
|
---|
17 | *
|
---|
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
---|
19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
---|
20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
---|
21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
---|
22 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
---|
23 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
---|
24 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
---|
28 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
29 | */
|
---|
30 |
|
---|
31 | #pragma once
|
---|
32 |
|
---|
33 | #include "ThreadableLoaderClient.h"
|
---|
34 | #include <wtf/Ref.h>
|
---|
35 | #include <wtf/ThreadSafeRefCounted.h>
|
---|
36 |
|
---|
37 | namespace WebCore {
|
---|
38 |
|
---|
39 | class ThreadableLoaderClientWrapper : public ThreadSafeRefCounted<ThreadableLoaderClientWrapper> {
|
---|
40 | public:
|
---|
41 | static Ref<ThreadableLoaderClientWrapper> create(ThreadableLoaderClient& client, const String& initiator)
|
---|
42 | {
|
---|
43 | return adoptRef(*new ThreadableLoaderClientWrapper(client, initiator));
|
---|
44 | }
|
---|
45 |
|
---|
46 | void clearClient()
|
---|
47 | {
|
---|
48 | m_done = true;
|
---|
49 | m_client = nullptr;
|
---|
50 | }
|
---|
51 |
|
---|
52 | bool done() const
|
---|
53 | {
|
---|
54 | return m_done;
|
---|
55 | }
|
---|
56 |
|
---|
57 | void redirectReceived(const URL& redirectURL)
|
---|
58 | {
|
---|
59 | if (m_client)
|
---|
60 | m_client->redirectReceived(redirectURL);
|
---|
61 | }
|
---|
62 |
|
---|
63 | void didSendData(unsigned long long bytesSent, unsigned long long totalBytesToBeSent)
|
---|
64 | {
|
---|
65 | if (m_client)
|
---|
66 | m_client->didSendData(bytesSent, totalBytesToBeSent);
|
---|
67 | }
|
---|
68 |
|
---|
69 | void didReceiveResponse(ResourceLoaderIdentifier identifier, const ResourceResponse& response)
|
---|
70 | {
|
---|
71 | if (m_client)
|
---|
72 | m_client->didReceiveResponse(identifier, response);
|
---|
73 | }
|
---|
74 |
|
---|
75 | void didReceiveData(const SharedBuffer& buffer)
|
---|
76 | {
|
---|
77 | if (m_client)
|
---|
78 | m_client->didReceiveData(buffer);
|
---|
79 | }
|
---|
80 |
|
---|
81 | void didFinishLoading(ResourceLoaderIdentifier identifier, const NetworkLoadMetrics& metrics)
|
---|
82 | {
|
---|
83 | m_done = true;
|
---|
84 | if (m_client)
|
---|
85 | m_client->didFinishLoading(identifier, metrics);
|
---|
86 | }
|
---|
87 |
|
---|
88 | void notifyIsDone(bool isDone)
|
---|
89 | {
|
---|
90 | if (m_client)
|
---|
91 | m_client->notifyIsDone(isDone);
|
---|
92 | }
|
---|
93 |
|
---|
94 | void didFail(const ResourceError& error)
|
---|
95 | {
|
---|
96 | m_done = true;
|
---|
97 | if (m_client)
|
---|
98 | m_client->didFail(error);
|
---|
99 | }
|
---|
100 |
|
---|
101 | void didReceiveAuthenticationCancellation(ResourceLoaderIdentifier identifier, const ResourceResponse& response)
|
---|
102 | {
|
---|
103 | if (m_client)
|
---|
104 | m_client->didReceiveResponse(identifier, response);
|
---|
105 | }
|
---|
106 |
|
---|
107 | const String& initiator() const { return m_initiator; }
|
---|
108 |
|
---|
109 | protected:
|
---|
110 | explicit ThreadableLoaderClientWrapper(ThreadableLoaderClient&, const String&);
|
---|
111 |
|
---|
112 | ThreadableLoaderClient* m_client;
|
---|
113 | String m_initiator;
|
---|
114 | bool m_done { false };
|
---|
115 | };
|
---|
116 |
|
---|
117 | inline ThreadableLoaderClientWrapper::ThreadableLoaderClientWrapper(ThreadableLoaderClient& client, const String& initiator)
|
---|
118 | : m_client(&client)
|
---|
119 | , m_initiator(initiator.isolatedCopy())
|
---|
120 | {
|
---|
121 | }
|
---|
122 |
|
---|
123 | } // namespace WebCore
|
---|