blob: f43c9bdc782e2d0a6cdc65f36df8dbc687f5f1eb [file] [log] [blame]
The Android Open Source Project63586082009-03-05 14:34:32 -08001/*
Steve Blockdcc8cf22010-04-27 16:31:00 +01002 * Copyright (C) 2010 Google Inc. All rights reserved.
Feng Qian8f72e702009-04-10 18:11:29 -07003 *
The Android Open Source Project63586082009-03-05 14:34:32 -08004 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
Feng Qian8f72e702009-04-10 18:11:29 -07007 *
The Android Open Source Project63586082009-03-05 14:34:32 -08008 * * 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.
Feng Qian8f72e702009-04-10 18:11:29 -070017 *
The Android Open Source Project63586082009-03-05 14:34:32 -080018 * 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
Steve Block643ca782009-12-15 10:12:09 +000031#include "config.h"
32#include "DatabaseObserver.h"
The Android Open Source Project63586082009-03-05 14:34:32 -080033
Kristian Monsen06171452010-07-30 10:46:49 +010034#if ENABLE(DATABASE)
35
Kristian Monsen06ea8e82010-06-28 16:42:48 +010036#include "AbstractDatabase.h"
Steve Blockdcc8cf22010-04-27 16:31:00 +010037#include "Document.h"
38#include "ScriptExecutionContext.h"
Steve Block643ca782009-12-15 10:12:09 +000039#include "WebDatabase.h"
40#include "WebDatabaseObserver.h"
Steve Blockdcc8cf22010-04-27 16:31:00 +010041#include "WebFrameClient.h"
42#include "WebFrameImpl.h"
43#include "WebSecurityOrigin.h"
44#include "WebWorkerImpl.h"
45#include "WorkerContext.h"
46#include "WorkerThread.h"
Steve Block643ca782009-12-15 10:12:09 +000047
48using namespace WebKit;
The Android Open Source Project63586082009-03-05 14:34:32 -080049
50namespace WebCore {
51
Steve Blockdcc8cf22010-04-27 16:31:00 +010052bool DatabaseObserver::canEstablishDatabase(ScriptExecutionContext* scriptExecutionContext, const String& name, const String& displayName, unsigned long estimatedSize)
53{
54 ASSERT(scriptExecutionContext->isContextThread());
Kristian Monsen6c2af942010-05-21 16:53:46 +010055 ASSERT(scriptExecutionContext->isDocument() || scriptExecutionContext->isWorkerContext());
Steve Blockdcc8cf22010-04-27 16:31:00 +010056 if (scriptExecutionContext->isDocument()) {
57 Document* document = static_cast<Document*>(scriptExecutionContext);
58 WebFrameImpl* webFrame = WebFrameImpl::fromFrame(document->frame());
59 return webFrame->client()->allowDatabase(webFrame, name, displayName, estimatedSize);
Kristian Monsen6c2af942010-05-21 16:53:46 +010060 } else {
61 WorkerContext* workerContext = static_cast<WorkerContext*>(scriptExecutionContext);
62 WorkerLoaderProxy* workerLoaderProxy = &workerContext->thread()->workerLoaderProxy();
63 WebWorkerBase* webWorker = static_cast<WebWorkerBase*>(workerLoaderProxy);
64 return webWorker->allowDatabase(0, name, displayName, estimatedSize);
Steve Blockdcc8cf22010-04-27 16:31:00 +010065 }
66
67 return true;
68}
69
Kristian Monsen06ea8e82010-06-28 16:42:48 +010070void DatabaseObserver::databaseOpened(AbstractDatabase* database)
Steve Block643ca782009-12-15 10:12:09 +000071{
Leon Clarke5af96e22010-06-03 14:33:32 +010072 ASSERT(database->scriptExecutionContext()->isContextThread());
Steve Block643ca782009-12-15 10:12:09 +000073 WebDatabase::observer()->databaseOpened(WebDatabase(database));
The Android Open Source Project63586082009-03-05 14:34:32 -080074}
75
Kristian Monsen06ea8e82010-06-28 16:42:48 +010076void DatabaseObserver::databaseModified(AbstractDatabase* database)
Steve Block643ca782009-12-15 10:12:09 +000077{
Leon Clarke5af96e22010-06-03 14:33:32 +010078 ASSERT(database->scriptExecutionContext()->isContextThread());
Steve Block643ca782009-12-15 10:12:09 +000079 WebDatabase::observer()->databaseModified(WebDatabase(database));
80}
81
Kristian Monsen06ea8e82010-06-28 16:42:48 +010082void DatabaseObserver::databaseClosed(AbstractDatabase* database)
Steve Block643ca782009-12-15 10:12:09 +000083{
Leon Clarke5af96e22010-06-03 14:33:32 +010084 ASSERT(database->scriptExecutionContext()->isContextThread());
Steve Block643ca782009-12-15 10:12:09 +000085 WebDatabase::observer()->databaseClosed(WebDatabase(database));
86}
87
88} // namespace WebCore
Kristian Monsen06171452010-07-30 10:46:49 +010089
90#endif // ENABLE(DATABASE)