Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(160)

Side by Side Diff: third_party/WebKit/Source/modules/indexeddb/IDBFactory.cpp

Issue 1865213006: Replace setIndexedDBClientCreateFunction madness with Supplements (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Simplify per review feedback Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 #include "platform/Histogram.h" 43 #include "platform/Histogram.h"
44 #include "platform/weborigin/SecurityOrigin.h" 44 #include "platform/weborigin/SecurityOrigin.h"
45 #include "public/platform/Platform.h" 45 #include "public/platform/Platform.h"
46 #include "public/platform/WebSecurityOrigin.h" 46 #include "public/platform/WebSecurityOrigin.h"
47 #include "public/platform/modules/indexeddb/WebIDBFactory.h" 47 #include "public/platform/modules/indexeddb/WebIDBFactory.h"
48 48
49 namespace blink { 49 namespace blink {
50 50
51 static const char permissionDeniedErrorMessage[] = "The user denied permission t o access the database."; 51 static const char permissionDeniedErrorMessage[] = "The user denied permission t o access the database.";
52 52
53 IDBFactory::IDBFactory(IndexedDBClient* permissionClient) 53 IDBFactory::IDBFactory()
54 : m_permissionClient(permissionClient)
55 { 54 {
56 } 55 }
57 56
58 DEFINE_TRACE(IDBFactory)
59 {
60 visitor->trace(m_permissionClient);
61 }
62
63 static bool isContextValid(ExecutionContext* context) 57 static bool isContextValid(ExecutionContext* context)
64 { 58 {
65 ASSERT(context->isDocument() || context->isWorkerGlobalScope()); 59 ASSERT(context->isDocument() || context->isWorkerGlobalScope());
66 if (context->isDocument()) { 60 if (context->isDocument()) {
67 Document* document = toDocument(context); 61 Document* document = toDocument(context);
68 return document->frame() && document->page(); 62 return document->frame() && document->page();
69 } 63 }
70 return true; 64 return true;
71 } 65 }
72 66
73 IDBRequest* IDBFactory::getDatabaseNames(ScriptState* scriptState, ExceptionStat e& exceptionState) 67 IDBRequest* IDBFactory::getDatabaseNames(ScriptState* scriptState, ExceptionStat e& exceptionState)
74 { 68 {
75 IDB_TRACE("IDBFactory::getDatabaseNames"); 69 IDB_TRACE("IDBFactory::getDatabaseNames");
76 if (!isContextValid(scriptState->getExecutionContext())) 70 if (!isContextValid(scriptState->getExecutionContext()))
77 return nullptr; 71 return nullptr;
78 if (!scriptState->getExecutionContext()->getSecurityOrigin()->canAccessDatab ase()) { 72 if (!scriptState->getExecutionContext()->getSecurityOrigin()->canAccessDatab ase()) {
79 exceptionState.throwSecurityError("access to the Indexed Database API is denied in this context."); 73 exceptionState.throwSecurityError("access to the Indexed Database API is denied in this context.");
80 return nullptr; 74 return nullptr;
81 } 75 }
82 76
83 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::createNull(), nullptr); 77 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::createNull(), nullptr);
84 78
85 if (!m_permissionClient->allowIndexedDB(scriptState->getExecutionContext(), "Database Listing")) { 79 if (!IndexedDBClient::from(scriptState->getExecutionContext())->allowIndexed DB(scriptState->getExecutionContext(), "Database Listing")) {
86 request->onError(DOMException::create(UnknownError, permissionDeniedErro rMessage)); 80 request->onError(DOMException::create(UnknownError, permissionDeniedErro rMessage));
87 return request; 81 return request;
88 } 82 }
89 83
90 Platform::current()->idbFactory()->getDatabaseNames(WebIDBCallbacksImpl::cre ate(request).leakPtr(), WebSecurityOrigin(scriptState->getExecutionContext()->ge tSecurityOrigin())); 84 Platform::current()->idbFactory()->getDatabaseNames(WebIDBCallbacksImpl::cre ate(request).leakPtr(), WebSecurityOrigin(scriptState->getExecutionContext()->ge tSecurityOrigin()));
91 return request; 85 return request;
92 } 86 }
93 87
94 IDBOpenDBRequest* IDBFactory::open(ScriptState* scriptState, const String& name, unsigned long long version, ExceptionState& exceptionState) 88 IDBOpenDBRequest* IDBFactory::open(ScriptState* scriptState, const String& name, unsigned long long version, ExceptionState& exceptionState)
95 { 89 {
(...skipping 13 matching lines...) Expand all
109 return nullptr; 103 return nullptr;
110 if (!scriptState->getExecutionContext()->getSecurityOrigin()->canAccessDatab ase()) { 104 if (!scriptState->getExecutionContext()->getSecurityOrigin()->canAccessDatab ase()) {
111 exceptionState.throwSecurityError("access to the Indexed Database API is denied in this context."); 105 exceptionState.throwSecurityError("access to the Indexed Database API is denied in this context.");
112 return nullptr; 106 return nullptr;
113 } 107 }
114 108
115 IDBDatabaseCallbacks* databaseCallbacks = IDBDatabaseCallbacks::create(); 109 IDBDatabaseCallbacks* databaseCallbacks = IDBDatabaseCallbacks::create();
116 int64_t transactionId = IDBDatabase::nextTransactionId(); 110 int64_t transactionId = IDBDatabase::nextTransactionId();
117 IDBOpenDBRequest* request = IDBOpenDBRequest::create(scriptState, databaseCa llbacks, transactionId, version); 111 IDBOpenDBRequest* request = IDBOpenDBRequest::create(scriptState, databaseCa llbacks, transactionId, version);
118 112
119 if (!m_permissionClient->allowIndexedDB(scriptState->getExecutionContext(), name)) { 113 if (!IndexedDBClient::from(scriptState->getExecutionContext())->allowIndexed DB(scriptState->getExecutionContext(), name)) {
120 request->onError(DOMException::create(UnknownError, permissionDeniedErro rMessage)); 114 request->onError(DOMException::create(UnknownError, permissionDeniedErro rMessage));
121 return request; 115 return request;
122 } 116 }
123 117
124 Platform::current()->idbFactory()->open(name, version, transactionId, WebIDB CallbacksImpl::create(request).leakPtr(), WebIDBDatabaseCallbacksImpl::create(da tabaseCallbacks).leakPtr(), WebSecurityOrigin(scriptState->getExecutionContext() ->getSecurityOrigin())); 118 Platform::current()->idbFactory()->open(name, version, transactionId, WebIDB CallbacksImpl::create(request).leakPtr(), WebIDBDatabaseCallbacksImpl::create(da tabaseCallbacks).leakPtr(), WebSecurityOrigin(scriptState->getExecutionContext() ->getSecurityOrigin()));
125 return request; 119 return request;
126 } 120 }
127 121
128 IDBOpenDBRequest* IDBFactory::open(ScriptState* scriptState, const String& name, ExceptionState& exceptionState) 122 IDBOpenDBRequest* IDBFactory::open(ScriptState* scriptState, const String& name, ExceptionState& exceptionState)
129 { 123 {
130 IDB_TRACE("IDBFactory::open"); 124 IDB_TRACE("IDBFactory::open");
131 return openInternal(scriptState, name, IDBDatabaseMetadata::NoVersion, excep tionState); 125 return openInternal(scriptState, name, IDBDatabaseMetadata::NoVersion, excep tionState);
132 } 126 }
133 127
134 IDBOpenDBRequest* IDBFactory::deleteDatabase(ScriptState* scriptState, const Str ing& name, ExceptionState& exceptionState) 128 IDBOpenDBRequest* IDBFactory::deleteDatabase(ScriptState* scriptState, const Str ing& name, ExceptionState& exceptionState)
135 { 129 {
136 IDB_TRACE("IDBFactory::deleteDatabase"); 130 IDB_TRACE("IDBFactory::deleteDatabase");
137 IDBDatabase::recordApiCallsHistogram(IDBDeleteDatabaseCall); 131 IDBDatabase::recordApiCallsHistogram(IDBDeleteDatabaseCall);
138 if (!isContextValid(scriptState->getExecutionContext())) 132 if (!isContextValid(scriptState->getExecutionContext()))
139 return nullptr; 133 return nullptr;
140 if (!scriptState->getExecutionContext()->getSecurityOrigin()->canAccessDatab ase()) { 134 if (!scriptState->getExecutionContext()->getSecurityOrigin()->canAccessDatab ase()) {
141 exceptionState.throwSecurityError("access to the Indexed Database API is denied in this context."); 135 exceptionState.throwSecurityError("access to the Indexed Database API is denied in this context.");
142 return nullptr; 136 return nullptr;
143 } 137 }
144 138
145 IDBOpenDBRequest* request = IDBOpenDBRequest::create(scriptState, nullptr, 0 , IDBDatabaseMetadata::DefaultVersion); 139 IDBOpenDBRequest* request = IDBOpenDBRequest::create(scriptState, nullptr, 0 , IDBDatabaseMetadata::DefaultVersion);
146 140
147 if (!m_permissionClient->allowIndexedDB(scriptState->getExecutionContext(), name)) { 141 if (!IndexedDBClient::from(scriptState->getExecutionContext())->allowIndexed DB(scriptState->getExecutionContext(), name)) {
148 request->onError(DOMException::create(UnknownError, permissionDeniedErro rMessage)); 142 request->onError(DOMException::create(UnknownError, permissionDeniedErro rMessage));
149 return request; 143 return request;
150 } 144 }
151 145
152 Platform::current()->idbFactory()->deleteDatabase(name, WebIDBCallbacksImpl: :create(request).leakPtr(), WebSecurityOrigin(scriptState->getExecutionContext() ->getSecurityOrigin())); 146 Platform::current()->idbFactory()->deleteDatabase(name, WebIDBCallbacksImpl: :create(request).leakPtr(), WebSecurityOrigin(scriptState->getExecutionContext() ->getSecurityOrigin()));
153 return request; 147 return request;
154 } 148 }
155 149
156 short IDBFactory::cmp(ScriptState* scriptState, const ScriptValue& firstValue, c onst ScriptValue& secondValue, ExceptionState& exceptionState) 150 short IDBFactory::cmp(ScriptState* scriptState, const ScriptValue& firstValue, c onst ScriptValue& secondValue, ExceptionState& exceptionState)
157 { 151 {
(...skipping 12 matching lines...) Expand all
170 ASSERT(second); 164 ASSERT(second);
171 if (!second->isValid()) { 165 if (!second->isValid()) {
172 exceptionState.throwDOMException(DataError, IDBDatabase::notValidKeyErro rMessage); 166 exceptionState.throwDOMException(DataError, IDBDatabase::notValidKeyErro rMessage);
173 return 0; 167 return 0;
174 } 168 }
175 169
176 return static_cast<short>(first->compare(second)); 170 return static_cast<short>(first->compare(second));
177 } 171 }
178 172
179 } // namespace blink 173 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698