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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 class ExecutionContext; | 47 class ExecutionContext; |
48 class TextResourceDecoder; | 48 class TextResourceDecoder; |
49 | 49 |
50 class CORE_EXPORT WorkerScriptLoader final : public ThreadableLoaderClient { | 50 class CORE_EXPORT WorkerScriptLoader final : public ThreadableLoaderClient { |
51 WTF_MAKE_FAST_ALLOCATED(WorkerScriptLoader); | 51 WTF_MAKE_FAST_ALLOCATED(WorkerScriptLoader); |
52 public: | 52 public: |
53 WorkerScriptLoader(); | 53 WorkerScriptLoader(); |
54 ~WorkerScriptLoader() override; | 54 ~WorkerScriptLoader() override; |
55 | 55 |
56 void loadSynchronously(ExecutionContext&, const KURL&, CrossOriginRequestPol
icy); | 56 void loadSynchronously(ExecutionContext&, const KURL&, CrossOriginRequestPol
icy); |
57 // TODO: finishedCallback is not currently guaranteed to be invoked if used | 57 // TODO: |finishedCallback| is not currently guaranteed to be invoked if |
58 // from worker context and the worker shuts down in the middle of an | 58 // 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. | 59 // operation. This will cause leaks when we support nested workers. |
| 60 // Note that callbacks could be invoked before loadAsynchronously() returns. |
60 void loadAsynchronously(ExecutionContext&, const KURL&, CrossOriginRequestPo
licy, PassOwnPtr<Closure> responseCallback, PassOwnPtr<Closure> finishedCallback
); | 61 void loadAsynchronously(ExecutionContext&, const KURL&, CrossOriginRequestPo
licy, PassOwnPtr<Closure> responseCallback, PassOwnPtr<Closure> finishedCallback
); |
61 | 62 |
62 void notifyError(); | 63 // This will immediately invoke |finishedCallback| if loadAsynchronously() |
63 | |
64 // This will immediately lead to notifyFinished() if loadAsynchronously | |
65 // is in progress. | 64 // is in progress. |
66 void cancel(); | 65 void cancel(); |
67 | 66 |
68 String script(); | 67 String script(); |
69 const KURL& url() const { return m_url; } | 68 const KURL& url() const { return m_url; } |
70 const KURL& responseURL() const; | 69 const KURL& responseURL() const; |
71 bool failed() const { return m_failed; } | 70 bool failed() const { return m_failed; } |
72 unsigned long identifier() const { return m_identifier; } | 71 unsigned long identifier() const { return m_identifier; } |
73 long long appCacheID() const { return m_appCacheID; } | 72 long long appCacheID() const { return m_appCacheID; } |
74 | 73 |
75 PassOwnPtr<Vector<char>> releaseCachedMetadata() { return m_cachedMetadata.r
elease(); } | 74 PassOwnPtr<Vector<char>> releaseCachedMetadata() { return m_cachedMetadata.r
elease(); } |
76 const Vector<char>* cachedMetadata() const { return m_cachedMetadata.get();
} | 75 const Vector<char>* cachedMetadata() const { return m_cachedMetadata.get();
} |
77 | 76 |
78 PassRefPtr<ContentSecurityPolicy> contentSecurityPolicy() { return m_content
SecurityPolicy; } | 77 PassRefPtr<ContentSecurityPolicy> contentSecurityPolicy() { return m_content
SecurityPolicy; } |
79 PassRefPtr<ContentSecurityPolicy> releaseContentSecurityPolicy() { return m_
contentSecurityPolicy.release(); } | 78 PassRefPtr<ContentSecurityPolicy> releaseContentSecurityPolicy() { return m_
contentSecurityPolicy.release(); } |
80 | 79 |
81 // ThreadableLoaderClient | 80 // ThreadableLoaderClient |
82 void didReceiveResponse(unsigned long /*identifier*/, const ResourceResponse
&, PassOwnPtr<WebDataConsumerHandle>) override; | 81 void didReceiveResponse(unsigned long /*identifier*/, const ResourceResponse
&, PassOwnPtr<WebDataConsumerHandle>) override; |
83 void didReceiveData(const char* data, unsigned dataLength) override; | 82 void didReceiveData(const char* data, unsigned dataLength) override; |
84 void didReceiveCachedMetadata(const char*, int /*dataLength*/) override; | 83 void didReceiveCachedMetadata(const char*, int /*dataLength*/) override; |
85 void didFinishLoading(unsigned long identifier, double) override; | 84 void didFinishLoading(unsigned long identifier, double) override; |
86 void didFail(const ResourceError&) override; | 85 void didFail(const ResourceError&) override; |
87 void didFailRedirectCheck() override; | 86 void didFailRedirectCheck() override; |
88 | 87 |
89 void setRequestContext(WebURLRequest::RequestContext requestContext) { m_req
uestContext = requestContext; } | 88 void setRequestContext(WebURLRequest::RequestContext requestContext) { m_req
uestContext = requestContext; } |
90 | 89 |
91 private: | 90 private: |
92 PassOwnPtr<ResourceRequest> createResourceRequest(); | 91 PassOwnPtr<ResourceRequest> createResourceRequest(); |
| 92 void notifyError(); |
93 void notifyFinished(); | 93 void notifyFinished(); |
94 | 94 |
95 void processContentSecurityPolicy(const ResourceResponse&); | 95 void processContentSecurityPolicy(const ResourceResponse&); |
96 | 96 |
97 // Callbacks for loadAsynchronously(). | 97 // Callbacks for loadAsynchronously(). |
98 OwnPtr<Closure> m_responseCallback; | 98 OwnPtr<Closure> m_responseCallback; |
99 OwnPtr<Closure> m_finishedCallback; | 99 OwnPtr<Closure> m_finishedCallback; |
100 | 100 |
101 RefPtr<ThreadableLoader> m_threadableLoader; | 101 RefPtr<ThreadableLoader> m_threadableLoader; |
102 String m_responseEncoding; | 102 String m_responseEncoding; |
103 OwnPtr<TextResourceDecoder> m_decoder; | 103 OwnPtr<TextResourceDecoder> m_decoder; |
104 StringBuilder m_script; | 104 StringBuilder m_script; |
105 KURL m_url; | 105 KURL m_url; |
106 KURL m_responseURL; | 106 KURL m_responseURL; |
107 bool m_failed; | 107 bool m_failed; |
108 unsigned long m_identifier; | 108 unsigned long m_identifier; |
109 long long m_appCacheID; | 109 long long m_appCacheID; |
110 bool m_finishing; | |
111 OwnPtr<Vector<char>> m_cachedMetadata; | 110 OwnPtr<Vector<char>> m_cachedMetadata; |
112 WebURLRequest::RequestContext m_requestContext; | 111 WebURLRequest::RequestContext m_requestContext; |
113 RefPtr<ContentSecurityPolicy> m_contentSecurityPolicy; | 112 RefPtr<ContentSecurityPolicy> m_contentSecurityPolicy; |
114 }; | 113 }; |
115 | 114 |
116 } // namespace blink | 115 } // namespace blink |
117 | 116 |
118 #endif // WorkerScriptLoader_h | 117 #endif // WorkerScriptLoader_h |
OLD | NEW |