OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 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 |
11 * copyright notice, this list of conditions and the following disclaimer | 11 * copyright notice, this list of conditions and the following disclaimer |
12 * in the documentation and/or other materials provided with the | 12 * in the documentation and/or other materials provided with the |
13 * distribution. | 13 * distribution. |
14 * * Neither the name of Google Inc. nor the names of its | 14 * * Neither the name of Google Inc. nor the names of its |
15 * contributors may be used to endorse or promote products derived from | 15 * contributors may be used to endorse or promote products derived from |
16 * this software without specific prior written permission. | 16 * this software without specific prior written permission. |
17 * | 17 * |
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #include "modules/webdatabase/SQLTransactionClient.h" | 31 #include "core/workers/ThreadedWorkletObjectProxy.h" |
32 | 32 |
| 33 #include "bindings/core/v8/SerializedScriptValue.h" |
| 34 #include "bindings/core/v8/SourceLocation.h" |
| 35 #include "core/dom/Document.h" |
33 #include "core/dom/ExecutionContext.h" | 36 #include "core/dom/ExecutionContext.h" |
34 #include "core/dom/ExecutionContextTask.h" | 37 #include "core/dom/ExecutionContextTask.h" |
35 #include "modules/webdatabase/Database.h" | 38 #include "core/inspector/ConsoleMessage.h" |
36 #include "modules/webdatabase/DatabaseContext.h" | 39 #include "core/workers/ThreadedWorkletMessagingProxy.h" |
37 #include "platform/weborigin/SecurityOrigin.h" | |
38 #include "public/platform/Platform.h" | |
39 #include "public/platform/WebDatabaseObserver.h" | |
40 #include "public/platform/WebSecurityOrigin.h" | |
41 #include "public/platform/WebTraceLocation.h" | |
42 #include "wtf/Functional.h" | 40 #include "wtf/Functional.h" |
| 41 #include "wtf/PtrUtil.h" |
| 42 #include <memory> |
43 | 43 |
44 namespace blink { | 44 namespace blink { |
45 | 45 |
46 namespace { | 46 std::unique_ptr<ThreadedWorkletObjectProxy> ThreadedWorkletObjectProxy::create(T
hreadedWorkletMessagingProxy* messagingProxy) |
47 | |
48 void databaseModified(const WebSecurityOrigin& origin, const String& databaseNam
e) | |
49 { | 47 { |
50 if (Platform::current()->databaseObserver()) | 48 DCHECK(messagingProxy); |
51 Platform::current()->databaseObserver()->databaseModified(origin, databa
seName); | 49 return wrapUnique(new ThreadedWorkletObjectProxy(messagingProxy)); |
52 } | 50 } |
53 | 51 |
54 void databaseModifiedCrossThread(const String& originString, const String& datab
aseName) | 52 void ThreadedWorkletObjectProxy::postTaskToMainExecutionContext(std::unique_ptr<
ExecutionContextTask> task) |
55 { | 53 { |
56 databaseModified(WebSecurityOrigin::createFromString(originString), database
Name); | 54 getExecutionContext()->postTask(BLINK_FROM_HERE, std::move(task)); |
57 } | 55 } |
58 | 56 |
59 } // namespace | 57 void ThreadedWorkletObjectProxy::reportPendingActivity(bool hasPendingActivity) |
60 | |
61 void SQLTransactionClient::didCommitWriteTransaction(Database* database) | |
62 { | 58 { |
63 String databaseName = database->stringIdentifier(); | 59 getExecutionContext()->postTask(BLINK_FROM_HERE, createCrossThreadTask(&Thre
adedWorkletMessagingProxy::reportPendingActivity, crossThreadUnretained(m_messag
ingProxy), hasPendingActivity)); |
64 ExecutionContext* executionContext = database->getDatabaseContext()->getExec
utionContext(); | |
65 if (!executionContext->isContextThread()) { | |
66 executionContext->postTask(BLINK_FROM_HERE, createCrossThreadTask(&datab
aseModifiedCrossThread, executionContext->getSecurityOrigin()->toRawString(), da
tabaseName)); | |
67 } else { | |
68 databaseModified(WebSecurityOrigin(executionContext->getSecurityOrigin()
), databaseName); | |
69 } | |
70 } | 60 } |
71 | 61 |
72 bool SQLTransactionClient::didExceedQuota(Database* database) | 62 void ThreadedWorkletObjectProxy::reportConsoleMessage(MessageSource source, Mess
ageLevel level, const String& message, SourceLocation* location) |
73 { | 63 { |
74 // Chromium does not allow users to manually change the quota for an origin
(for now, at least). | 64 getExecutionContext()->postTask(BLINK_FROM_HERE, createCrossThreadTask(&Thre
adedWorkletMessagingProxy::reportConsoleMessage, crossThreadUnretained(m_messagi
ngProxy), source, level, message, passed(location->clone()))); |
75 // Don't do anything. | 65 } |
76 ASSERT(database->getDatabaseContext()->getExecutionContext()->isContextThrea
d()); | 66 |
77 return false; | 67 void ThreadedWorkletObjectProxy::postMessageToPageInspector(const String& messag
e) |
| 68 { |
| 69 ExecutionContext* context = getExecutionContext(); |
| 70 if (context->isDocument()) |
| 71 toDocument(context)->postInspectorTask(BLINK_FROM_HERE, createCrossThrea
dTask(&ThreadedWorkletMessagingProxy::postMessageToPageInspector, crossThreadUnr
etained(m_messagingProxy), message)); |
| 72 } |
| 73 |
| 74 void ThreadedWorkletObjectProxy::workerGlobalScopeClosed() |
| 75 { |
| 76 getExecutionContext()->postTask(BLINK_FROM_HERE, createCrossThreadTask(&Thre
adedWorkletMessagingProxy::terminateWorkletGlobalScope, crossThreadUnretained(m_
messagingProxy))); |
| 77 } |
| 78 |
| 79 void ThreadedWorkletObjectProxy::workerThreadTerminated() |
| 80 { |
| 81 // This will terminate the MessagingProxy. |
| 82 getExecutionContext()->postTask(BLINK_FROM_HERE, createCrossThreadTask(&Thre
adedWorkletMessagingProxy::workerThreadTerminated, crossThreadUnretained(m_messa
gingProxy))); |
| 83 } |
| 84 |
| 85 ThreadedWorkletObjectProxy::ThreadedWorkletObjectProxy(ThreadedWorkletMessagingP
roxy* messagingProxy) |
| 86 : m_messagingProxy(messagingProxy) |
| 87 { |
| 88 } |
| 89 |
| 90 ExecutionContext* ThreadedWorkletObjectProxy::getExecutionContext() const |
| 91 { |
| 92 DCHECK(m_messagingProxy); |
| 93 return m_messagingProxy->getExecutionContext(); |
78 } | 94 } |
79 | 95 |
80 } // namespace blink | 96 } // namespace blink |
OLD | NEW |