Commit 4c5494ab authored by haraken's avatar haraken Committed by Commit bot

Use a new Supplement constructor for LocalFrame's supplements

This is one of the steps to deprecate the default constructor of Supplement.

BUG=610176

Review-Url: https://codereview.chromium.org/2614143002
Cr-Commit-Position: refs/heads/master@{#441943}
parent 8b6b77e8
......@@ -10,6 +10,9 @@
namespace blink {
AudioOutputDeviceClient::AudioOutputDeviceClient(LocalFrame& frame)
: Supplement<LocalFrame>(frame) {}
const char* AudioOutputDeviceClient::supplementName() {
return "AudioOutputDeviceClient";
}
......@@ -29,7 +32,8 @@ AudioOutputDeviceClient* AudioOutputDeviceClient::from(
void provideAudioOutputDeviceClientTo(LocalFrame& frame,
AudioOutputDeviceClient* client) {
frame.provideSupplement(AudioOutputDeviceClient::supplementName(), client);
Supplement<LocalFrame>::provideTo(
frame, AudioOutputDeviceClient::supplementName(), client);
}
DEFINE_TRACE(AudioOutputDeviceClient) {
......
......@@ -18,6 +18,7 @@ class WebString;
class MODULES_EXPORT AudioOutputDeviceClient : public Supplement<LocalFrame> {
public:
explicit AudioOutputDeviceClient(LocalFrame&);
virtual ~AudioOutputDeviceClient() {}
// Checks that a given sink exists and has permissions to be used from the
......
......@@ -72,11 +72,6 @@ class CallbackWrapper final
std::unique_ptr<AsyncFileSystemCallbacks> m_callbacks;
};
LocalFileSystem* LocalFileSystem::create(
std::unique_ptr<FileSystemClient> client) {
return new LocalFileSystem(std::move(client));
}
LocalFileSystem::~LocalFileSystem() {}
void LocalFileSystem::resolveURL(
......@@ -214,8 +209,13 @@ void LocalFileSystem::deleteFileSystemInternal(ExecutionContext* context,
callbacks->release());
}
LocalFileSystem::LocalFileSystem(std::unique_ptr<FileSystemClient> client)
: m_client(std::move(client)) {}
LocalFileSystem::LocalFileSystem(LocalFrame& frame,
std::unique_ptr<FileSystemClient> client)
: Supplement<LocalFrame>(frame), m_client(std::move(client)) {}
LocalFileSystem::LocalFileSystem(WorkerClients& workerClients,
std::unique_ptr<FileSystemClient> client)
: Supplement<WorkerClients>(workerClients), m_client(std::move(client)) {}
DEFINE_TRACE(LocalFileSystem) {
Supplement<LocalFrame>::trace(visitor);
......@@ -227,26 +227,33 @@ const char* LocalFileSystem::supplementName() {
}
LocalFileSystem* LocalFileSystem::from(ExecutionContext& context) {
if (context.isDocument())
return static_cast<LocalFileSystem*>(Supplement<LocalFrame>::from(
if (context.isDocument()) {
LocalFileSystem* fileSystem =
static_cast<LocalFileSystem*>(Supplement<LocalFrame>::from(
toDocument(context).frame(), supplementName()));
DCHECK(fileSystem);
return fileSystem;
}
WorkerClients* clients = toWorkerGlobalScope(context).clients();
ASSERT(clients);
return static_cast<LocalFileSystem*>(
LocalFileSystem* fileSystem = static_cast<LocalFileSystem*>(
Supplement<WorkerClients>::from(clients, supplementName()));
DCHECK(fileSystem);
return fileSystem;
}
void provideLocalFileSystemTo(LocalFrame& frame,
std::unique_ptr<FileSystemClient> client) {
frame.provideSupplement(LocalFileSystem::supplementName(),
LocalFileSystem::create(std::move(client)));
new LocalFileSystem(frame, std::move(client)));
}
void provideLocalFileSystemToWorker(WorkerClients* clients,
void provideLocalFileSystemToWorker(WorkerClients* workerClients,
std::unique_ptr<FileSystemClient> client) {
clients->provideSupplement(LocalFileSystem::supplementName(),
LocalFileSystem::create(std::move(client)));
Supplement<WorkerClients>::provideTo(
*workerClients, LocalFileSystem::supplementName(),
new LocalFileSystem(*workerClients, std::move(client)));
}
} // namespace blink
......@@ -56,7 +56,8 @@ class LocalFileSystem final : public GarbageCollectedFinalized<LocalFileSystem>,
WTF_MAKE_NONCOPYABLE(LocalFileSystem);
public:
static LocalFileSystem* create(std::unique_ptr<FileSystemClient>);
LocalFileSystem(LocalFrame&, std::unique_ptr<FileSystemClient>);
LocalFileSystem(WorkerClients&, std::unique_ptr<FileSystemClient>);
~LocalFileSystem();
void resolveURL(ExecutionContext*,
......@@ -78,8 +79,6 @@ class LocalFileSystem final : public GarbageCollectedFinalized<LocalFileSystem>,
DECLARE_VIRTUAL_TRACE();
private:
explicit LocalFileSystem(std::unique_ptr<FileSystemClient>);
WebFileSystem* getFileSystem() const;
void fileSystemNotAvailable(ExecutionContext*, CallbackWrapper*);
......
......@@ -12,7 +12,11 @@
namespace blink {
IndexedDBClient::IndexedDBClient() {}
IndexedDBClient::IndexedDBClient(LocalFrame& frame)
: Supplement<LocalFrame>(frame) {}
IndexedDBClient::IndexedDBClient(WorkerClients& clients)
: Supplement<WorkerClients>(clients) {}
IndexedDBClient* IndexedDBClient::from(ExecutionContext* context) {
if (context->isDocument())
......@@ -35,7 +39,8 @@ DEFINE_TRACE(IndexedDBClient) {
}
void provideIndexedDBClientTo(LocalFrame& frame, IndexedDBClient* client) {
frame.provideSupplement(IndexedDBClient::supplementName(), client);
Supplement<LocalFrame>::provideTo(frame, IndexedDBClient::supplementName(),
client);
}
void provideIndexedDBClientToWorker(WorkerClients* clients,
......
......@@ -49,7 +49,8 @@ class MODULES_EXPORT IndexedDBClient
WTF_MAKE_NONCOPYABLE(IndexedDBClient);
public:
IndexedDBClient();
explicit IndexedDBClient(LocalFrame&);
explicit IndexedDBClient(WorkerClients&);
virtual ~IndexedDBClient() {}
DECLARE_VIRTUAL_TRACE();
......
......@@ -33,7 +33,9 @@ InstalledAppController* InstalledAppController::from(LocalFrame& frame) {
InstalledAppController::InstalledAppController(LocalFrame& frame,
WebInstalledAppClient* client)
: ContextLifecycleObserver(frame.document()), m_client(client) {}
: Supplement<LocalFrame>(frame),
ContextLifecycleObserver(frame.document()),
m_client(client) {}
const char* InstalledAppController::supplementName() {
return "InstalledAppController";
......
......@@ -31,23 +31,19 @@ const char* UserMediaController::supplementName() {
}
UserMediaController::UserMediaController(
LocalFrame& frame,
std::unique_ptr<UserMediaClient> client)
: m_client(std::move(client)) {}
: Supplement<LocalFrame>(frame), m_client(std::move(client)) {}
DEFINE_TRACE(UserMediaController) {
Supplement<LocalFrame>::trace(visitor);
}
UserMediaController* UserMediaController::create(
std::unique_ptr<UserMediaClient> client) {
return new UserMediaController(std::move(client));
}
void provideUserMediaTo(LocalFrame& frame,
std::unique_ptr<UserMediaClient> client) {
UserMediaController::provideTo(
frame, UserMediaController::supplementName(),
UserMediaController::create(std::move(client)));
new UserMediaController(frame, std::move(client)));
}
} // namespace blink
......@@ -40,8 +40,7 @@ class UserMediaController final
USING_GARBAGE_COLLECTED_MIXIN(UserMediaController);
public:
static UserMediaController* create(std::unique_ptr<UserMediaClient>);
UserMediaController(LocalFrame&, std::unique_ptr<UserMediaClient>);
DECLARE_VIRTUAL_TRACE();
UserMediaClient* client() const { return m_client.get(); }
......@@ -58,8 +57,6 @@ class UserMediaController final
}
private:
explicit UserMediaController(std::unique_ptr<UserMediaClient>);
std::unique_ptr<UserMediaClient> m_client;
};
......
......@@ -15,7 +15,9 @@ namespace blink {
PresentationController::PresentationController(LocalFrame& frame,
WebPresentationClient* client)
: ContextLifecycleObserver(frame.document()), m_client(client) {
: Supplement<LocalFrame>(frame),
ContextLifecycleObserver(frame.document()),
m_client(client) {
if (m_client)
m_client->setController(this);
}
......
......@@ -9,11 +9,8 @@
namespace blink {
PushController::PushController(WebPushClient* client) : m_client(client) {}
PushController* PushController::create(WebPushClient* client) {
return new PushController(client);
}
PushController::PushController(LocalFrame& frame, WebPushClient* client)
: Supplement<LocalFrame>(frame), m_client(client) {}
WebPushClient& PushController::clientFrom(LocalFrame* frame) {
PushController* controller = PushController::from(frame);
......@@ -29,7 +26,7 @@ const char* PushController::supplementName() {
void providePushControllerTo(LocalFrame& frame, WebPushClient* client) {
PushController::provideTo(frame, PushController::supplementName(),
PushController::create(client));
new PushController(frame, client));
}
} // namespace blink
......@@ -21,7 +21,8 @@ class PushController final : public GarbageCollected<PushController>,
WTF_MAKE_NONCOPYABLE(PushController);
public:
static PushController* create(WebPushClient*);
PushController(LocalFrame&, WebPushClient*);
static const char* supplementName();
static PushController* from(LocalFrame* frame) {
return static_cast<PushController*>(
......@@ -32,8 +33,6 @@ class PushController final : public GarbageCollected<PushController>,
DEFINE_INLINE_VIRTUAL_TRACE() { Supplement<LocalFrame>::trace(visitor); }
private:
explicit PushController(WebPushClient*);
WebPushClient* client() const { return m_client; }
WebPushClient* m_client;
......
......@@ -13,12 +13,12 @@
namespace blink {
// SensorProviderProxy
SensorProviderProxy::SensorProviderProxy(LocalFrame* frame) {
initialize(frame);
}
SensorProviderProxy::SensorProviderProxy(LocalFrame& frame)
: Supplement<LocalFrame>(frame) {}
void SensorProviderProxy::initialize(LocalFrame* frame) {
DCHECK(!isInitialized());
void SensorProviderProxy::initializeIfNeeded(LocalFrame* frame) {
if (isInitialized())
return;
frame->interfaceProvider()->getInterface(
mojo::MakeRequest(&m_sensorProvider));
......@@ -37,13 +37,10 @@ SensorProviderProxy* SensorProviderProxy::from(LocalFrame* frame) {
SensorProviderProxy* providerProxy = static_cast<SensorProviderProxy*>(
Supplement<LocalFrame>::from(*frame, supplementName()));
if (!providerProxy) {
providerProxy = new SensorProviderProxy(frame);
providerProxy = new SensorProviderProxy(*frame);
Supplement<LocalFrame>::provideTo(*frame, supplementName(), providerProxy);
}
if (!providerProxy->isInitialized())
providerProxy->initialize(frame);
providerProxy->initializeIfNeeded(frame);
return providerProxy;
}
......
......@@ -41,9 +41,9 @@ class SensorProviderProxy final
private:
friend class SensorProxy; // To call getSensorProvider().
explicit SensorProviderProxy(LocalFrame*);
explicit SensorProviderProxy(LocalFrame&);
static const char* supplementName();
void initialize(LocalFrame*);
void initializeIfNeeded(LocalFrame*);
bool isInitialized() const { return m_sensorProvider; }
device::mojom::blink::SensorProvider* getSensorProvider() const {
......
......@@ -62,7 +62,8 @@ DEFINE_TRACE(ScreenWakeLock) {
}
ScreenWakeLock::ScreenWakeLock(LocalFrame& frame)
: ContextLifecycleObserver(frame.document()),
: Supplement<LocalFrame>(frame),
ContextLifecycleObserver(frame.document()),
PageVisibilityObserver(frame.page()),
m_keepAwake(false) {
DCHECK(!m_service.is_bound());
......
......@@ -12,11 +12,8 @@
namespace blink {
AudioOutputDeviceClientImpl* AudioOutputDeviceClientImpl::create() {
return new AudioOutputDeviceClientImpl();
}
AudioOutputDeviceClientImpl::AudioOutputDeviceClientImpl() {}
AudioOutputDeviceClientImpl::AudioOutputDeviceClientImpl(LocalFrame& frame)
: AudioOutputDeviceClient(frame) {}
AudioOutputDeviceClientImpl::~AudioOutputDeviceClientImpl() {}
......
......@@ -18,7 +18,7 @@ class AudioOutputDeviceClientImpl
WTF_MAKE_NONCOPYABLE(AudioOutputDeviceClientImpl);
public:
static AudioOutputDeviceClientImpl* create();
explicit AudioOutputDeviceClientImpl(LocalFrame&);
~AudioOutputDeviceClientImpl() override;
......
......@@ -1142,7 +1142,7 @@ void ChromeClientImpl::installSupplements(LocalFrame& frame) {
providePushControllerTo(frame, client->pushClient());
provideUserMediaTo(frame,
UserMediaClientImpl::create(client->userMediaClient()));
provideIndexedDBClientTo(frame, IndexedDBClientImpl::create());
provideIndexedDBClientTo(frame, IndexedDBClientImpl::create(frame));
provideLocalFileSystemTo(frame, LocalFileSystemClient::create());
provideNavigatorContentUtilsTo(
frame, NavigatorContentUtilsClientImpl::create(webFrame));
......@@ -1151,9 +1151,10 @@ void ChromeClientImpl::installSupplements(LocalFrame& frame) {
frame, client->webScreenOrientationClient());
if (RuntimeEnabledFeatures::presentationEnabled())
PresentationController::provideTo(frame, client->presentationClient());
if (RuntimeEnabledFeatures::audioOutputDevicesEnabled())
if (RuntimeEnabledFeatures::audioOutputDevicesEnabled()) {
provideAudioOutputDeviceClientTo(frame,
AudioOutputDeviceClientImpl::create());
new AudioOutputDeviceClientImpl(frame));
}
if (RuntimeEnabledFeatures::installedAppEnabled())
InstalledAppController::provideTo(frame, client->installedAppClient());
}
......
......@@ -56,7 +56,7 @@ DedicatedWorkerMessagingProxyProviderImpl::createWorkerMessagingProxy(
WebLocalFrameImpl::fromFrame(document->frame());
WorkerClients* workerClients = WorkerClients::create();
provideIndexedDBClientToWorker(workerClients,
IndexedDBClientImpl::create());
IndexedDBClientImpl::create(*workerClients));
provideLocalFileSystemToWorker(workerClients,
LocalFileSystemClient::create());
provideContentSettingsClientToWorker(
......
......@@ -41,10 +41,20 @@
namespace blink {
IndexedDBClient* IndexedDBClientImpl::create() {
return new IndexedDBClientImpl();
IndexedDBClient* IndexedDBClientImpl::create(LocalFrame& frame) {
return new IndexedDBClientImpl(frame);
}
IndexedDBClient* IndexedDBClientImpl::create(WorkerClients& workerClients) {
return new IndexedDBClientImpl(workerClients);
}
IndexedDBClientImpl::IndexedDBClientImpl(LocalFrame& frame)
: IndexedDBClient(frame) {}
IndexedDBClientImpl::IndexedDBClientImpl(WorkerClients& workerClients)
: IndexedDBClient(workerClients) {}
bool IndexedDBClientImpl::allowIndexedDB(ExecutionContext* context,
const String& name) {
DCHECK(context->isContextThread());
......
......@@ -42,12 +42,14 @@ class ExecutionContext;
// for the main thread.
class IndexedDBClientImpl final : public IndexedDBClient {
public:
static IndexedDBClient* create();
static IndexedDBClient* create(LocalFrame&);
static IndexedDBClient* create(WorkerClients&);
bool allowIndexedDB(ExecutionContext*, const String& name) override;
private:
IndexedDBClientImpl() {}
explicit IndexedDBClientImpl(LocalFrame&);
explicit IndexedDBClientImpl(WorkerClients&);
};
} // namespace blink
......
......@@ -425,7 +425,8 @@ void WebEmbeddedWorkerImpl::startWorkerThread() {
WorkerClients* workerClients = WorkerClients::create();
provideContentSettingsClientToWorker(workerClients,
std::move(m_contentSettingsClient));
provideIndexedDBClientToWorker(workerClients, IndexedDBClientImpl::create());
provideIndexedDBClientToWorker(workerClients,
IndexedDBClientImpl::create(*workerClients));
provideServiceWorkerGlobalScopeClientToWorker(
workerClients,
ServiceWorkerGlobalScopeClientImpl::create(*m_workerContextClient));
......
......@@ -386,7 +386,8 @@ void WebSharedWorkerImpl::onScriptLoaderFinished() {
workerClients,
WTF::wrapUnique(
m_client->createWorkerContentSettingsClientProxy(webSecurityOrigin)));
provideIndexedDBClientToWorker(workerClients, IndexedDBClientImpl::create());
provideIndexedDBClientToWorker(workerClients,
IndexedDBClientImpl::create(*workerClients));
ContentSecurityPolicy* contentSecurityPolicy =
m_mainScriptLoader->releaseContentSecurityPolicy();
WorkerThreadStartMode startMode =
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment