OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2009 Apple Inc. All Rights Reserved. | 2 * Copyright (C) 2009 Apple Inc. All Rights Reserved. |
3 * Copyright (C) 2009, 2011 Google Inc. All Rights Reserved. | 3 * Copyright (C) 2009, 2011 Google Inc. All Rights Reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
7 * are met: | 7 * are met: |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 19 matching lines...) Expand all Loading... |
30 | 30 |
31 #include "core/CoreExport.h" | 31 #include "core/CoreExport.h" |
32 #include "core/loader/ThreadableLoader.h" | 32 #include "core/loader/ThreadableLoader.h" |
33 #include "core/loader/ThreadableLoaderClient.h" | 33 #include "core/loader/ThreadableLoaderClient.h" |
34 #include "platform/network/ResourceRequest.h" | 34 #include "platform/network/ResourceRequest.h" |
35 #include "platform/weborigin/KURL.h" | 35 #include "platform/weborigin/KURL.h" |
36 #include "public/platform/WebURLRequest.h" | 36 #include "public/platform/WebURLRequest.h" |
37 #include "wtf/FastAllocBase.h" | 37 #include "wtf/FastAllocBase.h" |
38 #include "wtf/Functional.h" | 38 #include "wtf/Functional.h" |
39 #include "wtf/PassRefPtr.h" | 39 #include "wtf/PassRefPtr.h" |
| 40 #include "wtf/RefCounted.h" |
40 #include "wtf/text/StringBuilder.h" | 41 #include "wtf/text/StringBuilder.h" |
41 | 42 |
42 namespace blink { | 43 namespace blink { |
43 | 44 |
44 class ContentSecurityPolicy; | 45 class ContentSecurityPolicy; |
45 class ResourceRequest; | 46 class ResourceRequest; |
46 class ResourceResponse; | 47 class ResourceResponse; |
47 class ExecutionContext; | 48 class ExecutionContext; |
48 class TextResourceDecoder; | 49 class TextResourceDecoder; |
49 | 50 |
50 class CORE_EXPORT WorkerScriptLoader final : public ThreadableLoaderClient { | 51 class CORE_EXPORT WorkerScriptLoader final : public RefCounted<WorkerScriptLoade
r>, public ThreadableLoaderClient { |
51 WTF_MAKE_FAST_ALLOCATED(WorkerScriptLoader); | 52 WTF_MAKE_FAST_ALLOCATED(WorkerScriptLoader); |
52 public: | 53 public: |
53 WorkerScriptLoader(); | 54 static PassRefPtr<WorkerScriptLoader> create() |
54 ~WorkerScriptLoader() override; | 55 { |
| 56 return adoptRef(new WorkerScriptLoader()); |
| 57 } |
55 | 58 |
56 void loadSynchronously(ExecutionContext&, const KURL&, CrossOriginRequestPol
icy); | 59 void loadSynchronously(ExecutionContext&, const KURL&, CrossOriginRequestPol
icy); |
57 // TODO: |finishedCallback| is not currently guaranteed to be invoked if | 60 // TODO: |finishedCallback| is not currently guaranteed to be invoked if |
58 // used from worker context and the worker shuts down in the middle of an | 61 // used from worker context and the worker shuts down in the middle of an |
59 // operation. This will cause leaks when we support nested workers. | 62 // operation. This will cause leaks when we support nested workers. |
60 // Note that callbacks could be invoked before loadAsynchronously() returns. | 63 // Note that callbacks could be invoked before loadAsynchronously() returns. |
61 void loadAsynchronously(ExecutionContext&, const KURL&, CrossOriginRequestPo
licy, PassOwnPtr<Closure> responseCallback, PassOwnPtr<Closure> finishedCallback
); | 64 void loadAsynchronously(ExecutionContext&, const KURL&, CrossOriginRequestPo
licy, PassOwnPtr<Closure> responseCallback, PassOwnPtr<Closure> finishedCallback
); |
62 | 65 |
63 // This will immediately invoke |finishedCallback| if loadAsynchronously() | 66 // This will immediately invoke |finishedCallback| if loadAsynchronously() |
64 // is in progress. | 67 // is in progress. |
(...skipping 16 matching lines...) Expand all Loading... |
81 void didReceiveResponse(unsigned long /*identifier*/, const ResourceResponse
&, PassOwnPtr<WebDataConsumerHandle>) override; | 84 void didReceiveResponse(unsigned long /*identifier*/, const ResourceResponse
&, PassOwnPtr<WebDataConsumerHandle>) override; |
82 void didReceiveData(const char* data, unsigned dataLength) override; | 85 void didReceiveData(const char* data, unsigned dataLength) override; |
83 void didReceiveCachedMetadata(const char*, int /*dataLength*/) override; | 86 void didReceiveCachedMetadata(const char*, int /*dataLength*/) override; |
84 void didFinishLoading(unsigned long identifier, double) override; | 87 void didFinishLoading(unsigned long identifier, double) override; |
85 void didFail(const ResourceError&) override; | 88 void didFail(const ResourceError&) override; |
86 void didFailRedirectCheck() override; | 89 void didFailRedirectCheck() override; |
87 | 90 |
88 void setRequestContext(WebURLRequest::RequestContext requestContext) { m_req
uestContext = requestContext; } | 91 void setRequestContext(WebURLRequest::RequestContext requestContext) { m_req
uestContext = requestContext; } |
89 | 92 |
90 private: | 93 private: |
| 94 friend class WTF::RefCounted<WorkerScriptLoader>; |
| 95 |
| 96 WorkerScriptLoader(); |
| 97 ~WorkerScriptLoader() override; |
| 98 |
91 PassOwnPtr<ResourceRequest> createResourceRequest(); | 99 PassOwnPtr<ResourceRequest> createResourceRequest(); |
92 void notifyError(); | 100 void notifyError(); |
93 void notifyFinished(); | 101 void notifyFinished(); |
94 | 102 |
95 void processContentSecurityPolicy(const ResourceResponse&); | 103 void processContentSecurityPolicy(const ResourceResponse&); |
96 | 104 |
97 // Callbacks for loadAsynchronously(). | 105 // Callbacks for loadAsynchronously(). |
98 OwnPtr<Closure> m_responseCallback; | 106 OwnPtr<Closure> m_responseCallback; |
99 OwnPtr<Closure> m_finishedCallback; | 107 OwnPtr<Closure> m_finishedCallback; |
100 | 108 |
101 RefPtr<ThreadableLoader> m_threadableLoader; | 109 RefPtr<ThreadableLoader> m_threadableLoader; |
102 String m_responseEncoding; | 110 String m_responseEncoding; |
103 OwnPtr<TextResourceDecoder> m_decoder; | 111 OwnPtr<TextResourceDecoder> m_decoder; |
104 StringBuilder m_script; | 112 StringBuilder m_script; |
105 KURL m_url; | 113 KURL m_url; |
106 KURL m_responseURL; | 114 KURL m_responseURL; |
107 bool m_failed; | 115 bool m_failed; |
108 bool m_needToCancel; | 116 bool m_needToCancel; |
109 unsigned long m_identifier; | 117 unsigned long m_identifier; |
110 long long m_appCacheID; | 118 long long m_appCacheID; |
111 OwnPtr<Vector<char>> m_cachedMetadata; | 119 OwnPtr<Vector<char>> m_cachedMetadata; |
112 WebURLRequest::RequestContext m_requestContext; | 120 WebURLRequest::RequestContext m_requestContext; |
113 RefPtrWillBePersistent<ContentSecurityPolicy> m_contentSecurityPolicy; | 121 RefPtrWillBePersistent<ContentSecurityPolicy> m_contentSecurityPolicy; |
114 }; | 122 }; |
115 | 123 |
116 } // namespace blink | 124 } // namespace blink |
117 | 125 |
118 #endif // WorkerScriptLoader_h | 126 #endif // WorkerScriptLoader_h |
OLD | NEW |