| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 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 | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * | 7 * |
| 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 11 matching lines...) Expand all Loading... |
| 22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | 23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 */ | 27 */ |
| 28 | 28 |
| 29 #include "config.h" | 29 #include "config.h" |
| 30 #include "IDBFactoryBackendProxy.h" | 30 #include "IDBFactoryBackendProxy.h" |
| 31 | 31 |
| 32 #include "public/platform/WebIDBCallbacks.h" | |
| 33 #include "public/platform/WebIDBDatabase.h" | |
| 34 #include "public/platform/WebIDBDatabaseCallbacks.h" | |
| 35 #include "public/platform/WebIDBDatabaseError.h" | |
| 36 #include "public/platform/WebIDBFactory.h" | |
| 37 #include "public/platform/WebVector.h" | |
| 38 #include "WebFrameImpl.h" | 32 #include "WebFrameImpl.h" |
| 39 #include "WebKit.h" | 33 #include "WebKit.h" |
| 40 #include "WebPermissionClient.h" | 34 #include "WebPermissionClient.h" |
| 41 #include "WebSecurityOrigin.h" | 35 #include "WebSecurityOrigin.h" |
| 42 #include "WebViewImpl.h" | 36 #include "WebViewImpl.h" |
| 43 #include "WorkerPermissionClient.h" | 37 #include "WorkerPermissionClient.h" |
| 44 #include "bindings/v8/WorkerScriptController.h" | 38 #include "bindings/v8/WorkerScriptController.h" |
| 45 #include "core/dom/DOMError.h" | |
| 46 #include "core/dom/ExceptionCode.h" | |
| 47 #include "core/dom/ExecutionContext.h" | |
| 48 #include "core/workers/WorkerGlobalScope.h" | 39 #include "core/workers/WorkerGlobalScope.h" |
| 49 #include "platform/weborigin/SecurityOrigin.h" | 40 #include "platform/weborigin/SecurityOrigin.h" |
| 50 | 41 |
| 51 | 42 |
| 52 using namespace WebCore; | 43 using namespace WebCore; |
| 53 | 44 |
| 54 namespace blink { | 45 namespace blink { |
| 55 | 46 |
| 56 PassRefPtr<IDBFactoryBackendInterface> IDBFactoryBackendProxy::create() | 47 PassRefPtr<IDBFactoryBackendInterface> IDBFactoryBackendProxy::create() |
| 57 { | 48 { |
| 58 return adoptRef(new IDBFactoryBackendProxy()); | 49 return adoptRef(new IDBFactoryBackendProxy()); |
| 59 } | 50 } |
| 60 | 51 |
| 61 IDBFactoryBackendProxy::IDBFactoryBackendProxy() | 52 bool IDBFactoryBackendProxy::allowIndexedDB(ExecutionContext* context, const Str
ing& name) |
| 62 { | 53 { |
| 63 m_webIDBFactory = blink::Platform::current()->idbFactory(); | 54 ASSERT_WITH_SECURITY_IMPLICATION(context->isDocument() || context->isWorkerG
lobalScope()); |
| 64 } | |
| 65 | 55 |
| 66 IDBFactoryBackendProxy::~IDBFactoryBackendProxy() | |
| 67 { | |
| 68 } | |
| 69 | |
| 70 bool IDBFactoryBackendProxy::allowIndexedDB(ExecutionContext* context, const Str
ing& name, const WebSecurityOrigin& origin, PassRefPtr<IDBRequest> callbacks) | |
| 71 { | |
| 72 bool allowed; | |
| 73 ASSERT_WITH_SECURITY_IMPLICATION(context->isDocument() || context->isWorkerG
lobalScope()); | |
| 74 if (context->isDocument()) { | 56 if (context->isDocument()) { |
| 57 WebSecurityOrigin origin(context->securityOrigin()); |
| 75 Document* document = toDocument(context); | 58 Document* document = toDocument(context); |
| 76 WebFrameImpl* webFrame = WebFrameImpl::fromFrame(document->frame()); | 59 WebFrameImpl* webFrame = WebFrameImpl::fromFrame(document->frame()); |
| 77 WebViewImpl* webView = webFrame->viewImpl(); | 60 WebViewImpl* webView = webFrame->viewImpl(); |
| 78 // FIXME: webView->permissionClient() returns 0 in test_shell and conten
t_shell http://crbug.com/137269 | 61 // FIXME: webView->permissionClient() returns 0 in test_shell and conten
t_shell http://crbug.com/137269 |
| 79 allowed = !webView->permissionClient() || webView->permissionClient()->a
llowIndexedDB(webFrame, name, origin); | 62 return !webView->permissionClient() || webView->permissionClient()->allo
wIndexedDB(webFrame, name, origin); |
| 80 } else { | |
| 81 WorkerGlobalScope* workerGlobalScope = toWorkerGlobalScope(context); | |
| 82 allowed = WorkerPermissionClient::from(workerGlobalScope)->allowIndexedD
B(name); | |
| 83 } | 63 } |
| 84 | 64 |
| 85 if (!allowed) | 65 WorkerGlobalScope* workerGlobalScope = toWorkerGlobalScope(context); |
| 86 callbacks->onError(WebIDBDatabaseError(UnknownError, "The user denied pe
rmission to access the database.")); | 66 return WorkerPermissionClient::from(workerGlobalScope)->allowIndexedDB(name)
; |
| 87 | |
| 88 return allowed; | |
| 89 } | |
| 90 | |
| 91 void IDBFactoryBackendProxy::getDatabaseNames(PassRefPtr<IDBRequest> prpCallback
s, const String& databaseIdentifier, ExecutionContext* context) | |
| 92 { | |
| 93 RefPtr<IDBRequest> callbacks(prpCallbacks); | |
| 94 WebSecurityOrigin origin(context->securityOrigin()); | |
| 95 if (!allowIndexedDB(context, "Database Listing", origin, callbacks)) | |
| 96 return; | |
| 97 | |
| 98 m_webIDBFactory->getDatabaseNames(new WebIDBCallbacks(callbacks), databaseId
entifier); | |
| 99 } | |
| 100 | |
| 101 void IDBFactoryBackendProxy::open(const String& name, int64_t version, int64_t t
ransactionId, PassRefPtr<IDBRequest> prpCallbacks, PassOwnPtr<WebIDBDatabaseCal
lbacks> databaseCallbacks, const String& databaseIdentifier, ExecutionContext* c
ontext) | |
| 102 { | |
| 103 RefPtr<IDBRequest> callbacks(prpCallbacks); | |
| 104 WebSecurityOrigin origin(context->securityOrigin()); | |
| 105 if (!allowIndexedDB(context, name, origin, callbacks)) | |
| 106 return; | |
| 107 | |
| 108 m_webIDBFactory->open(name, version, transactionId, new WebIDBCallbacks(call
backs), databaseCallbacks.leakPtr(), databaseIdentifier); | |
| 109 } | |
| 110 | |
| 111 void IDBFactoryBackendProxy::deleteDatabase(const String& name, PassRefPtr<IDBRe
quest> prpCallbacks, const String& databaseIdentifier, ExecutionContext* context
) | |
| 112 { | |
| 113 RefPtr<IDBRequest> callbacks(prpCallbacks); | |
| 114 WebSecurityOrigin origin(context->securityOrigin()); | |
| 115 if (!allowIndexedDB(context, name, origin, callbacks)) | |
| 116 return; | |
| 117 | |
| 118 m_webIDBFactory->deleteDatabase(name, new WebIDBCallbacks(callbacks), databa
seIdentifier); | |
| 119 } | 67 } |
| 120 | 68 |
| 121 } // namespace blink | 69 } // namespace blink |
| OLD | NEW |