| OLD | NEW |
| (Empty) | |
| 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 #include "config.h" |
| 32 #include "core/workers/UIWorkerGlobalScope.h" |
| 33 |
| 34 #include "bindings/core/v8/ExceptionState.h" |
| 35 #include "bindings/core/v8/SerializedScriptValue.h" |
| 36 #include "core/frame/LocalDOMWindow.h" |
| 37 #include "core/workers/UIWorkerThread.h" |
| 38 #include "core/workers/WorkerClients.h" |
| 39 #include "core/workers/WorkerObjectProxy.h" |
| 40 #include "core/workers/WorkerThreadStartupData.h" |
| 41 #include "platform/TraceEvent.h" |
| 42 #include "public/platform/WebTeleportCallback.h" |
| 43 #include "public/platform/WebTeleporter.h" |
| 44 |
| 45 namespace blink { |
| 46 |
| 47 namespace { |
| 48 |
| 49 class WebTeleportCallbackWrapper : public WebTeleportCallback { |
| 50 public: |
| 51 WebTeleportCallbackWrapper( |
| 52 TeleportCallback* callback, |
| 53 PassRefPtrWillBeRawPtr<TeleportContext> context, |
| 54 Vector<OwnPtr<WebTeleportCallback> >* callbacks, |
| 55 WebTeleporter* teleporter) |
| 56 : m_callback(callback) |
| 57 , m_context(context) |
| 58 , m_callbacks(callbacks) |
| 59 , m_teleporter(teleporter) |
| 60 { |
| 61 if (m_context) |
| 62 m_values = m_context->getWebTeleportValues(); |
| 63 } |
| 64 |
| 65 virtual void Run(const WebVector<WebTeleportValue>& values) override |
| 66 { |
| 67 TRACE_EVENT0("teleport", "WebTeleportCallback::Run"); |
| 68 m_context->setWebTeleportValues(values); |
| 69 m_callback->handleEvent(m_context.get()); |
| 70 ASSERT(m_callbacks->contains(this)); |
| 71 m_teleporter->teleportMessage(WebVector<WebTeleportValue>(), 0); |
| 72 m_callbacks->remove(m_callbacks->find(this)); |
| 73 } |
| 74 |
| 75 WebTeleportValues* values() { return m_values.get(); } |
| 76 |
| 77 private: |
| 78 TeleportCallback* m_callback; |
| 79 RefPtr<TeleportContext> m_context; |
| 80 OwnPtr<WebTeleportValues> m_values; |
| 81 // FIXME: perhaps it would be better to pass a pointer to a |
| 82 // WorkerCallbackRegistry or something and invoke onCallbackComplete on the |
| 83 // registry when Run happens? This is expedient for now, but feel free to |
| 84 // hate on this in review :) |
| 85 Vector<OwnPtr<WebTeleportCallback> >* m_callbacks; |
| 86 WebTeleporter* m_teleporter; |
| 87 }; |
| 88 |
| 89 } // namespace |
| 90 |
| 91 PassRefPtrWillBeRawPtr<UIWorkerGlobalScope> UIWorkerGlobalScope::create(UIWorker
Thread* thread, PassOwnPtrWillBeRawPtr<WorkerThreadStartupData> startupData, dou
ble timeOrigin) |
| 92 { |
| 93 RefPtrWillBeRawPtr<UIWorkerGlobalScope> context = adoptRefWillBeNoop(new UIW
orkerGlobalScope(startupData->m_scriptURL, startupData->m_userAgent, thread, tim
eOrigin, NULL/*TODO?*/, startupData->m_workerClients.release())); |
| 94 context->applyContentSecurityPolicyFromString(startupData->m_contentSecurity
Policy, startupData->m_contentSecurityPolicyType); |
| 95 return context.release(); |
| 96 } |
| 97 |
| 98 UIWorkerGlobalScope::UIWorkerGlobalScope(const KURL& url, const String& userAgen
t, UIWorkerThread* thread, double timeOrigin, const SecurityOrigin* starterOrigi
n, PassOwnPtrWillBeRawPtr<WorkerClients> workerClients) |
| 99 : WorkerGlobalScope(url, userAgent, thread, timeOrigin, starterOrigin, worke
rClients) |
| 100 { |
| 101 TRACE_EVENT0("teleport,uiworker", "UIWorkerGlobalScope::UIWorkerGlobalScope"
); |
| 102 } |
| 103 |
| 104 UIWorkerGlobalScope::~UIWorkerGlobalScope() |
| 105 { |
| 106 } |
| 107 |
| 108 const AtomicString& UIWorkerGlobalScope::interfaceName() const |
| 109 { |
| 110 return EventTargetNames::UIWorkerGlobalScope; |
| 111 } |
| 112 |
| 113 void UIWorkerGlobalScope::postMessage(ExecutionContext*, PassRefPtr<SerializedSc
riptValue> message, const MessagePortArray* ports, ExceptionState& exceptionStat
e) |
| 114 { |
| 115 // Disentangle the port in preparation for sending it to the remote context. |
| 116 OwnPtr<MessagePortChannelArray> channels = MessagePort::disentanglePorts(por
ts, exceptionState); |
| 117 if (exceptionState.hadException()) |
| 118 return; |
| 119 thread()->workerObjectProxy().postMessageToWorkerObject(message, channels.re
lease()); |
| 120 } |
| 121 |
| 122 void UIWorkerGlobalScope::importScripts(const Vector<String>& urls, ExceptionSta
te& exceptionState) |
| 123 { |
| 124 Base::importScripts(urls, exceptionState); |
| 125 thread()->workerObjectProxy().reportPendingActivity(hasPendingActivity()); |
| 126 } |
| 127 |
| 128 |
| 129 UIWorkerThread* UIWorkerGlobalScope::thread() const |
| 130 { |
| 131 return static_cast<UIWorkerThread*>(Base::thread()); |
| 132 } |
| 133 |
| 134 class UseCounterTask : public ExecutionContextTask { |
| 135 public: |
| 136 static PassOwnPtr<UseCounterTask> createCount(UseCounter::Feature feature) {
return adoptPtr(new UseCounterTask(feature, false)); } |
| 137 static PassOwnPtr<UseCounterTask> createDeprecation(UseCounter::Feature feat
ure) { return adoptPtr(new UseCounterTask(feature, true)); } |
| 138 |
| 139 private: |
| 140 UseCounterTask(UseCounter::Feature feature, bool isDeprecation) |
| 141 : m_feature(feature) |
| 142 , m_isDeprecation(isDeprecation) |
| 143 { |
| 144 } |
| 145 |
| 146 virtual void performTask(ExecutionContext* context) override |
| 147 { |
| 148 ASSERT(context->isDocument()); |
| 149 if (m_isDeprecation) |
| 150 UseCounter::countDeprecation(context, m_feature); |
| 151 else |
| 152 UseCounter::count(context, m_feature); |
| 153 } |
| 154 |
| 155 UseCounter::Feature m_feature; |
| 156 bool m_isDeprecation; |
| 157 }; |
| 158 |
| 159 void UIWorkerGlobalScope::countFeature(UseCounter::Feature feature) const |
| 160 { |
| 161 thread()->workerObjectProxy().postTaskToMainExecutionContext(UseCounterTask:
:createCount(feature)); |
| 162 } |
| 163 |
| 164 void UIWorkerGlobalScope::countDeprecation(UseCounter::Feature feature) const |
| 165 { |
| 166 thread()->workerObjectProxy().postTaskToMainExecutionContext(UseCounterTask:
:createDeprecation(feature)); |
| 167 } |
| 168 |
| 169 void UIWorkerGlobalScope::teleportMessage(PassRefPtrWillBeRawPtr<TeleportContext
> context, TeleportCallback* callback, ExceptionState& exceptionState) |
| 170 { |
| 171 TRACE_EVENT0("teleport", "UIWorkerGlobalScope::teleportMessage"); |
| 172 //OwnPtr<WebTeleportCallbackWrapper> webCallback(adoptPtr(new WebTeleportCal
lbackWrapper(callback, context, &m_callbacks, thread()->teleporter()))); |
| 173 OwnPtr<WebTeleportCallbackWrapper> webCallback(adoptPtr(new WebTeleportCallb
ackWrapper(callback, context, &m_callbacks, thread()->teleporter()))); |
| 174 if (webCallback->values()) { |
| 175 thread()->teleporter()->teleportMessage(*webCallback->values(), webCallb
ack.get()); |
| 176 m_callbacks.append(webCallback.release()); |
| 177 } else { |
| 178 exceptionState.throwTypeError("Teleport failed."); |
| 179 } |
| 180 } |
| 181 |
| 182 void UIWorkerGlobalScope::trace(Visitor* visitor) |
| 183 { |
| 184 WorkerGlobalScope::trace(visitor); |
| 185 } |
| 186 |
| 187 } // namespace blink |
| OLD | NEW |