OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * 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 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 static PassOwnPtr<Loader> create() | 80 static PassOwnPtr<Loader> create() |
81 { | 81 { |
82 return adoptPtr(new Loader()); | 82 return adoptPtr(new Loader()); |
83 } | 83 } |
84 | 84 |
85 virtual ~Loader() | 85 virtual ~Loader() |
86 { | 86 { |
87 m_scriptLoader->setClient(0); | 87 m_scriptLoader->setClient(0); |
88 } | 88 } |
89 | 89 |
90 void load(ExecutionContext* loadingContext, const KURL& scriptURL, const Clo
sure& receiveResponseCallback, const Closure& finishCallback) | 90 void load(ExecutionContext* loadingContext, const KURL& scriptURL, PassOwnPt
r<Closure> receiveResponseCallback, PassOwnPtr<Closure> finishCallback) |
91 { | 91 { |
92 ASSERT(loadingContext); | 92 ASSERT(loadingContext); |
93 m_receiveResponseCallback = receiveResponseCallback; | 93 m_receiveResponseCallback = receiveResponseCallback; |
94 m_finishCallback = finishCallback; | 94 m_finishCallback = finishCallback; |
95 m_scriptLoader->setRequestContext(WebURLRequest::RequestContextSharedWor
ker); | 95 m_scriptLoader->setRequestContext(WebURLRequest::RequestContextSharedWor
ker); |
96 m_scriptLoader->loadAsynchronously( | 96 m_scriptLoader->loadAsynchronously( |
97 *loadingContext, scriptURL, DenyCrossOriginRequests, this); | 97 *loadingContext, scriptURL, DenyCrossOriginRequests, this); |
98 } | 98 } |
99 | 99 |
100 void didReceiveResponse(unsigned long identifier, const ResourceResponse& re
sponse) override | 100 void didReceiveResponse(unsigned long identifier, const ResourceResponse& re
sponse) override |
101 { | 101 { |
102 m_identifier = identifier; | 102 m_identifier = identifier; |
103 m_appCacheID = response.appCacheID(); | 103 m_appCacheID = response.appCacheID(); |
104 m_receiveResponseCallback(); | 104 (*m_receiveResponseCallback)(); |
105 } | 105 } |
106 | 106 |
107 virtual void notifyFinished() override | 107 virtual void notifyFinished() override |
108 { | 108 { |
109 m_finishCallback(); | 109 (*m_finishCallback)(); |
110 } | 110 } |
111 | 111 |
112 void cancel() | 112 void cancel() |
113 { | 113 { |
114 m_scriptLoader->cancel(); | 114 m_scriptLoader->cancel(); |
115 } | 115 } |
116 | 116 |
117 bool failed() const { return m_scriptLoader->failed(); } | 117 bool failed() const { return m_scriptLoader->failed(); } |
118 const KURL& url() const { return m_scriptLoader->responseURL(); } | 118 const KURL& url() const { return m_scriptLoader->responseURL(); } |
119 String script() const { return m_scriptLoader->script(); } | 119 String script() const { return m_scriptLoader->script(); } |
120 unsigned long identifier() const { return m_identifier; } | 120 unsigned long identifier() const { return m_identifier; } |
121 long long appCacheID() const { return m_appCacheID; } | 121 long long appCacheID() const { return m_appCacheID; } |
122 | 122 |
123 private: | 123 private: |
124 Loader() : m_scriptLoader(WorkerScriptLoader::create()), m_identifier(0), m_
appCacheID(0) | 124 Loader() : m_scriptLoader(WorkerScriptLoader::create()), m_identifier(0), m_
appCacheID(0) |
125 { | 125 { |
126 } | 126 } |
127 | 127 |
128 RefPtr<WorkerScriptLoader> m_scriptLoader; | 128 RefPtr<WorkerScriptLoader> m_scriptLoader; |
129 unsigned long m_identifier; | 129 unsigned long m_identifier; |
130 long long m_appCacheID; | 130 long long m_appCacheID; |
131 Closure m_receiveResponseCallback; | 131 OwnPtr<Closure> m_receiveResponseCallback; |
132 Closure m_finishCallback; | 132 OwnPtr<Closure> m_finishCallback; |
133 }; | 133 }; |
134 | 134 |
135 // This function is called on the main thread to force to initialize some static | 135 // This function is called on the main thread to force to initialize some static |
136 // values used in WebKit before any worker thread is started. This is because in | 136 // values used in WebKit before any worker thread is started. This is because in |
137 // our worker processs, we do not run any WebKit code in main thread and thus | 137 // our worker processs, we do not run any WebKit code in main thread and thus |
138 // when multiple workers try to start at the same time, we might hit crash due | 138 // when multiple workers try to start at the same time, we might hit crash due |
139 // to contention for initializing static values. | 139 // to contention for initializing static values. |
140 static void initializeWebKitStaticValues() | 140 static void initializeWebKitStaticValues() |
141 { | 141 { |
142 static bool initialized = false; | 142 static bool initialized = false; |
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
452 if (devtoolsAgent) | 452 if (devtoolsAgent) |
453 devtoolsAgent->dispatchOnInspectorBackend(message); | 453 devtoolsAgent->dispatchOnInspectorBackend(message); |
454 } | 454 } |
455 | 455 |
456 WebSharedWorker* WebSharedWorker::create(WebSharedWorkerClient* client) | 456 WebSharedWorker* WebSharedWorker::create(WebSharedWorkerClient* client) |
457 { | 457 { |
458 return new WebSharedWorkerImpl(client); | 458 return new WebSharedWorkerImpl(client); |
459 } | 459 } |
460 | 460 |
461 } // namespace blink | 461 } // namespace blink |
OLD | NEW |