| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 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 28 matching lines...) Expand all Loading... |
| 39 #include "WebPermissionClient.h" | 39 #include "WebPermissionClient.h" |
| 40 #include "WebSecurityOrigin.h" | 40 #include "WebSecurityOrigin.h" |
| 41 #include "WebViewImpl.h" | 41 #include "WebViewImpl.h" |
| 42 #include "WebWorkerBase.h" | 42 #include "WebWorkerBase.h" |
| 43 #include "WorkerAllowMainThreadBridgeBase.h" | 43 #include "WorkerAllowMainThreadBridgeBase.h" |
| 44 #include "bindings/v8/WorkerScriptController.h" | 44 #include "bindings/v8/WorkerScriptController.h" |
| 45 #include "core/dom/CrossThreadTask.h" | 45 #include "core/dom/CrossThreadTask.h" |
| 46 #include "core/dom/Document.h" | 46 #include "core/dom/Document.h" |
| 47 #include "core/dom/ScriptExecutionContext.h" | 47 #include "core/dom/ScriptExecutionContext.h" |
| 48 #include "core/platform/CrossThreadCopier.h" | 48 #include "core/platform/CrossThreadCopier.h" |
| 49 #include "core/workers/WorkerContext.h" | 49 #include "core/workers/WorkerGlobalScope.h" |
| 50 #include "core/workers/WorkerLoaderProxy.h" | 50 #include "core/workers/WorkerLoaderProxy.h" |
| 51 #include "core/workers/WorkerThread.h" | 51 #include "core/workers/WorkerThread.h" |
| 52 #include "modules/webdatabase/DatabaseBackendBase.h" | 52 #include "modules/webdatabase/DatabaseBackendBase.h" |
| 53 #include "modules/webdatabase/DatabaseBackendContext.h" | 53 #include "modules/webdatabase/DatabaseBackendContext.h" |
| 54 | 54 |
| 55 using namespace WebKit; | 55 using namespace WebKit; |
| 56 | 56 |
| 57 namespace { | 57 namespace { |
| 58 | 58 |
| 59 static const char allowDatabaseMode[] = "allowDatabaseMode"; | 59 static const char allowDatabaseMode[] = "allowDatabaseMode"; |
| 60 | 60 |
| 61 // This class is used to route the result of the WebWorkerBase::allowDatabase | 61 // This class is used to route the result of the WebWorkerBase::allowDatabase |
| 62 // call back to the worker context. | 62 // call back to the worker context. |
| 63 class AllowDatabaseMainThreadBridge : public WorkerAllowMainThreadBridgeBase { | 63 class AllowDatabaseMainThreadBridge : public WorkerAllowMainThreadBridgeBase { |
| 64 public: | 64 public: |
| 65 static PassRefPtr<AllowDatabaseMainThreadBridge> create(WebCore::WorkerConte
xt* workerContext, WebWorkerBase* webWorkerBase, const String& mode, WebFrame* f
rame, const String& name, const String& displayName, unsigned long estimatedSize
) | 65 static PassRefPtr<AllowDatabaseMainThreadBridge> create(WebCore::WorkerGloba
lScope* workerGlobalScope, WebWorkerBase* webWorkerBase, const String& mode, Web
Frame* frame, const String& name, const String& displayName, unsigned long estim
atedSize) |
| 66 { | 66 { |
| 67 return adoptRef(new AllowDatabaseMainThreadBridge(workerContext, webWork
erBase, mode, frame, name, displayName, estimatedSize)); | 67 return adoptRef(new AllowDatabaseMainThreadBridge(workerGlobalScope, web
WorkerBase, mode, frame, name, displayName, estimatedSize)); |
| 68 } | 68 } |
| 69 | 69 |
| 70 private: | 70 private: |
| 71 class AllowDatabaseParams : public AllowParams | 71 class AllowDatabaseParams : public AllowParams |
| 72 { | 72 { |
| 73 public: | 73 public: |
| 74 AllowDatabaseParams(const String& mode, WebFrame* frame, const String& n
ame, const String& displayName, unsigned long estimatedSize) | 74 AllowDatabaseParams(const String& mode, WebFrame* frame, const String& n
ame, const String& displayName, unsigned long estimatedSize) |
| 75 : AllowParams(mode) | 75 : AllowParams(mode) |
| 76 , m_frame(WebCore::AllowCrossThreadAccess(frame)) | 76 , m_frame(WebCore::AllowCrossThreadAccess(frame)) |
| 77 , m_name(name.isolatedCopy()) | 77 , m_name(name.isolatedCopy()) |
| 78 , m_displayName(displayName.isolatedCopy()) | 78 , m_displayName(displayName.isolatedCopy()) |
| 79 , m_estimatedSize(estimatedSize) | 79 , m_estimatedSize(estimatedSize) |
| 80 { | 80 { |
| 81 } | 81 } |
| 82 WebCore::AllowCrossThreadAccessWrapper<WebFrame> m_frame; | 82 WebCore::AllowCrossThreadAccessWrapper<WebFrame> m_frame; |
| 83 String m_name; | 83 String m_name; |
| 84 String m_displayName; | 84 String m_displayName; |
| 85 unsigned long m_estimatedSize; | 85 unsigned long m_estimatedSize; |
| 86 }; | 86 }; |
| 87 | 87 |
| 88 AllowDatabaseMainThreadBridge(WebCore::WorkerContext* workerContext, WebWork
erBase* webWorkerBase, const String& mode, WebFrame* frame, const String& name,
const String& displayName, unsigned long estimatedSize) | 88 AllowDatabaseMainThreadBridge(WebCore::WorkerGlobalScope* workerGlobalScope,
WebWorkerBase* webWorkerBase, const String& mode, WebFrame* frame, const String
& name, const String& displayName, unsigned long estimatedSize) |
| 89 : WorkerAllowMainThreadBridgeBase(workerContext, webWorkerBase) | 89 : WorkerAllowMainThreadBridgeBase(workerGlobalScope, webWorkerBase) |
| 90 { | 90 { |
| 91 postTaskToMainThread( | 91 postTaskToMainThread( |
| 92 adoptPtr(new AllowDatabaseParams(mode, frame, name, displayName, est
imatedSize))); | 92 adoptPtr(new AllowDatabaseParams(mode, frame, name, displayName, est
imatedSize))); |
| 93 } | 93 } |
| 94 | 94 |
| 95 virtual bool allowOnMainThread(WebCommonWorkerClient* commonClient, AllowPar
ams* params) | 95 virtual bool allowOnMainThread(WebCommonWorkerClient* commonClient, AllowPar
ams* params) |
| 96 { | 96 { |
| 97 ASSERT(isMainThread()); | 97 ASSERT(isMainThread()); |
| 98 AllowDatabaseParams* allowDBParams = static_cast<AllowDatabaseParams*>(p
arams); | 98 AllowDatabaseParams* allowDBParams = static_cast<AllowDatabaseParams*>(p
arams); |
| 99 return commonClient->allowDatabase( | 99 return commonClient->allowDatabase( |
| 100 allowDBParams->m_frame.value(), allowDBParams->m_name, allowDBParams
->m_displayName, allowDBParams->m_estimatedSize); | 100 allowDBParams->m_frame.value(), allowDBParams->m_name, allowDBParams
->m_displayName, allowDBParams->m_estimatedSize); |
| 101 } | 101 } |
| 102 }; | 102 }; |
| 103 | 103 |
| 104 bool allowDatabaseForWorker(WebFrame* frame, const WebString& name, const WebStr
ing& displayName, unsigned long estimatedSize) | 104 bool allowDatabaseForWorker(WebFrame* frame, const WebString& name, const WebStr
ing& displayName, unsigned long estimatedSize) |
| 105 { | 105 { |
| 106 WebCore::WorkerScriptController* controller = WebCore::WorkerScriptControlle
r::controllerForContext(); | 106 WebCore::WorkerScriptController* controller = WebCore::WorkerScriptControlle
r::controllerForContext(); |
| 107 WebCore::WorkerContext* workerContext = controller->workerContext(); | 107 WebCore::WorkerGlobalScope* workerGlobalScope = controller->workerGlobalScop
e(); |
| 108 WebCore::WorkerThread* workerThread = workerContext->thread(); | 108 WebCore::WorkerThread* workerThread = workerGlobalScope->thread(); |
| 109 WebCore::WorkerRunLoop& runLoop = workerThread->runLoop(); | 109 WebCore::WorkerRunLoop& runLoop = workerThread->runLoop(); |
| 110 WebCore::WorkerLoaderProxy* workerLoaderProxy = &workerThread->workerLoaderP
roxy(); | 110 WebCore::WorkerLoaderProxy* workerLoaderProxy = &workerThread->workerLoaderP
roxy(); |
| 111 | 111 |
| 112 // Create a unique mode just for this synchronous call. | 112 // Create a unique mode just for this synchronous call. |
| 113 String mode = allowDatabaseMode; | 113 String mode = allowDatabaseMode; |
| 114 mode.append(String::number(runLoop.createUniqueId())); | 114 mode.append(String::number(runLoop.createUniqueId())); |
| 115 | 115 |
| 116 RefPtr<AllowDatabaseMainThreadBridge> bridge = AllowDatabaseMainThreadBridge
::create(workerContext, workerLoaderProxy->toWebWorkerBase(), mode, frame, name,
displayName, estimatedSize); | 116 RefPtr<AllowDatabaseMainThreadBridge> bridge = AllowDatabaseMainThreadBridge
::create(workerGlobalScope, workerLoaderProxy->toWebWorkerBase(), mode, frame, n
ame, displayName, estimatedSize); |
| 117 | 117 |
| 118 // Either the bridge returns, or the queue gets terminated. | 118 // Either the bridge returns, or the queue gets terminated. |
| 119 if (runLoop.runInMode(workerContext, mode) == MessageQueueTerminated) { | 119 if (runLoop.runInMode(workerGlobalScope, mode) == MessageQueueTerminated) { |
| 120 bridge->cancel(); | 120 bridge->cancel(); |
| 121 return false; | 121 return false; |
| 122 } | 122 } |
| 123 | 123 |
| 124 return bridge->result(); | 124 return bridge->result(); |
| 125 } | 125 } |
| 126 | 126 |
| 127 } | 127 } |
| 128 | 128 |
| 129 namespace WebCore { | 129 namespace WebCore { |
| 130 | 130 |
| 131 bool DatabaseObserver::canEstablishDatabase(ScriptExecutionContext* scriptExecut
ionContext, const String& name, const String& displayName, unsigned long estimat
edSize) | 131 bool DatabaseObserver::canEstablishDatabase(ScriptExecutionContext* scriptExecut
ionContext, const String& name, const String& displayName, unsigned long estimat
edSize) |
| 132 { | 132 { |
| 133 ASSERT(scriptExecutionContext->isContextThread()); | 133 ASSERT(scriptExecutionContext->isContextThread()); |
| 134 ASSERT(scriptExecutionContext->isDocument() || scriptExecutionContext->isWor
kerContext()); | 134 ASSERT(scriptExecutionContext->isDocument() || scriptExecutionContext->isWor
kerGlobalScope()); |
| 135 if (scriptExecutionContext->isDocument()) { | 135 if (scriptExecutionContext->isDocument()) { |
| 136 Document* document = static_cast<Document*>(scriptExecutionContext); | 136 Document* document = static_cast<Document*>(scriptExecutionContext); |
| 137 WebFrameImpl* webFrame = WebFrameImpl::fromFrame(document->frame()); | 137 WebFrameImpl* webFrame = WebFrameImpl::fromFrame(document->frame()); |
| 138 if (!webFrame) | 138 if (!webFrame) |
| 139 return false; | 139 return false; |
| 140 WebViewImpl* webView = webFrame->viewImpl(); | 140 WebViewImpl* webView = webFrame->viewImpl(); |
| 141 if (!webView) | 141 if (!webView) |
| 142 return false; | 142 return false; |
| 143 if (webView->permissionClient()) | 143 if (webView->permissionClient()) |
| 144 return webView->permissionClient()->allowDatabase(webFrame, name, di
splayName, estimatedSize); | 144 return webView->permissionClient()->allowDatabase(webFrame, name, di
splayName, estimatedSize); |
| 145 } else { | 145 } else { |
| 146 WorkerContext* workerContext = static_cast<WorkerContext*>(scriptExecuti
onContext); | 146 WorkerGlobalScope* workerGlobalScope = static_cast<WorkerGlobalScope*>(s
criptExecutionContext); |
| 147 WebWorkerBase* webWorker = static_cast<WebWorkerBase*>(workerContext->th
read()->workerLoaderProxy().toWebWorkerBase()); | 147 WebWorkerBase* webWorker = static_cast<WebWorkerBase*>(workerGlobalScope
->thread()->workerLoaderProxy().toWebWorkerBase()); |
| 148 WebView* view = webWorker->view(); | 148 WebView* view = webWorker->view(); |
| 149 if (!view) | 149 if (!view) |
| 150 return false; | 150 return false; |
| 151 return allowDatabaseForWorker(view->mainFrame(), name, displayName, esti
matedSize); | 151 return allowDatabaseForWorker(view->mainFrame(), name, displayName, esti
matedSize); |
| 152 } | 152 } |
| 153 | 153 |
| 154 return true; | 154 return true; |
| 155 } | 155 } |
| 156 | 156 |
| 157 void DatabaseObserver::databaseOpened(DatabaseBackendBase* database) | 157 void DatabaseObserver::databaseOpened(DatabaseBackendBase* database) |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 { | 196 { |
| 197 WebDatabase::observer()->reportExecuteStatementResult(WebDatabase(database),
errorSite, webSqlErrorCode, sqliteErrorCode); | 197 WebDatabase::observer()->reportExecuteStatementResult(WebDatabase(database),
errorSite, webSqlErrorCode, sqliteErrorCode); |
| 198 } | 198 } |
| 199 | 199 |
| 200 void DatabaseObserver::reportVacuumDatabaseResult(DatabaseBackendBase* database,
int sqliteErrorCode) | 200 void DatabaseObserver::reportVacuumDatabaseResult(DatabaseBackendBase* database,
int sqliteErrorCode) |
| 201 { | 201 { |
| 202 WebDatabase::observer()->reportVacuumDatabaseResult(WebDatabase(database), s
qliteErrorCode); | 202 WebDatabase::observer()->reportVacuumDatabaseResult(WebDatabase(database), s
qliteErrorCode); |
| 203 } | 203 } |
| 204 | 204 |
| 205 } // namespace WebCore | 205 } // namespace WebCore |
| OLD | NEW |