Replace WTF::move with WTFMove
[WebKit-https.git] / Source / WebCore / Modules / indexeddb / DOMWindowIndexedDatabase.cpp
1 /*
2  * Copyright (C) 2011, 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 met:
6  *
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY GOOGLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND
14  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16  * ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE
17  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
20  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
23  * DAMAGE.
24  */
25
26 #include "config.h"
27 #include "DOMWindowIndexedDatabase.h"
28
29 #if ENABLE(INDEXED_DATABASE)
30
31 #include "DOMWindow.h"
32 #include "DatabaseProvider.h"
33 #include "Document.h"
34 #include "IDBFactoryImpl.h"
35 #include "LegacyFactory.h"
36 #include "Page.h"
37 #include "SecurityOrigin.h"
38
39 namespace WebCore {
40
41 DOMWindowIndexedDatabase::DOMWindowIndexedDatabase(DOMWindow* window)
42     : DOMWindowProperty(window->frame())
43     , m_window(window)
44 {
45 }
46
47 DOMWindowIndexedDatabase::~DOMWindowIndexedDatabase()
48 {
49 }
50
51 const char* DOMWindowIndexedDatabase::supplementName()
52 {
53     return "DOMWindowIndexedDatabase";
54 }
55
56 DOMWindowIndexedDatabase* DOMWindowIndexedDatabase::from(DOMWindow* window)
57 {
58     DOMWindowIndexedDatabase* supplement = static_cast<DOMWindowIndexedDatabase*>(Supplement<DOMWindow>::from(window, supplementName()));
59     if (!supplement) {
60         auto newSupplement = std::make_unique<DOMWindowIndexedDatabase>(window);
61         supplement = newSupplement.get();
62         provideTo(window, supplementName(), WTFMove(newSupplement));
63     }
64     return supplement;
65 }
66
67 void DOMWindowIndexedDatabase::disconnectFrameForDocumentSuspension()
68 {
69     m_suspendedIDBFactory = m_idbFactory.release();
70     DOMWindowProperty::disconnectFrameForDocumentSuspension();
71 }
72
73 void DOMWindowIndexedDatabase::reconnectFrameFromDocumentSuspension(Frame* frame)
74 {
75     DOMWindowProperty::reconnectFrameFromDocumentSuspension(frame);
76     m_idbFactory = m_suspendedIDBFactory.release();
77 }
78
79 void DOMWindowIndexedDatabase::willDestroyGlobalObjectInCachedFrame()
80 {
81     m_suspendedIDBFactory = nullptr;
82     DOMWindowProperty::willDestroyGlobalObjectInCachedFrame();
83 }
84
85 void DOMWindowIndexedDatabase::willDestroyGlobalObjectInFrame()
86 {
87     m_idbFactory = nullptr;
88     DOMWindowProperty::willDestroyGlobalObjectInFrame();
89 }
90
91 void DOMWindowIndexedDatabase::willDetachGlobalObjectFromFrame()
92 {
93     m_idbFactory = nullptr;
94     DOMWindowProperty::willDetachGlobalObjectFromFrame();
95 }
96
97 IDBFactory* DOMWindowIndexedDatabase::indexedDB(DOMWindow* window)
98 {
99     return from(window)->indexedDB();
100 }
101
102 IDBFactory* DOMWindowIndexedDatabase::indexedDB()
103 {
104     Document* document = m_window->document();
105     if (!document)
106         return nullptr;
107
108     Page* page = document->page();
109     if (!page)
110         return nullptr;
111
112     if (!m_window->isCurrentlyDisplayedInFrame())
113         return nullptr;
114
115     if (!m_idbFactory) {
116         if (page->databaseProvider().supportsModernIDB())
117             m_idbFactory = IDBClient::IDBFactory::create(page->idbConnection());
118         else
119             m_idbFactory = LegacyFactory::create(page->databaseProvider().idbFactoryBackend());
120     }
121
122     return m_idbFactory.get();
123 }
124
125 } // namespace WebCore
126
127 #endif // ENABLE(INDEXED_DATABASE)