blob: dfcd97c763bc41b8ee723a76cc8b9e6881355e2a [file] [log] [blame]
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "content/browser/browser_interface_binders.h"
#include "content/browser/background_fetch/background_fetch_service_impl.h"
#include "content/browser/frame_host/render_frame_host_impl.h"
#include "content/browser/renderer_host/render_process_host_impl.h"
#include "content/browser/service_worker/service_worker_provider_host.h"
#include "content/browser/worker_host/dedicated_worker_host.h"
#include "content/browser/worker_host/shared_worker_host.h"
#include "content/browser/worker_host/shared_worker_instance.h"
#include "third_party/blink/public/mojom/webaudio/audio_context_manager.mojom.h"
namespace content {
namespace internal {
// Documents/frames
void PopulateFrameBinders(RenderFrameHostImpl* host,
service_manager::BinderMap* map) {
map->Add<blink::mojom::AudioContextManager>(base::BindRepeating(
&RenderFrameHostImpl::GetAudioContextManager, base::Unretained(host)));
map->Add<blink::mojom::FileSystemManager>(base::BindRepeating(
&RenderFrameHostImpl::GetFileSystemManager, base::Unretained(host)));
}
void PopulateBinderMapWithContext(
RenderFrameHostImpl* host,
service_manager::BinderMapWithContext<RenderFrameHost*>* map) {
map->Add<blink::mojom::BackgroundFetchService>(
base::BindRepeating(&BackgroundFetchServiceImpl::CreateForFrame));
}
void PopulateBinderMap(RenderFrameHostImpl* host,
service_manager::BinderMap* map) {
PopulateFrameBinders(host, map);
}
RenderFrameHost* GetContextForHost(RenderFrameHostImpl* host) {
return host;
}
// Dedicated workers
const url::Origin& GetContextForHost(DedicatedWorkerHost* host) {
return host->GetOrigin();
}
void PopulateDedicatedWorkerBinders(DedicatedWorkerHost* host,
service_manager::BinderMap* map) {}
void PopulateBinderMapWithContext(
DedicatedWorkerHost* host,
service_manager::BinderMapWithContext<const url::Origin&>* map) {
// TODO(https://crbug.com/873661): Pass origin to FileSystemManager.
map->Add<blink::mojom::FileSystemManager>(
base::BindRepeating(&RenderProcessHost::BindFileSystemManager,
base::Unretained(host->GetProcessHost())));
}
void PopulateBinderMap(DedicatedWorkerHost* host,
service_manager::BinderMap* map) {
PopulateDedicatedWorkerBinders(host, map);
}
// Shared workers
url::Origin GetContextForHost(SharedWorkerHost* host) {
return url::Origin::Create(host->instance()->url());
}
void PopulateSharedWorkerBinders(SharedWorkerHost* host,
service_manager::BinderMap* map) {}
void PopulateBinderMapWithContext(
SharedWorkerHost* host,
service_manager::BinderMapWithContext<const url::Origin&>* map) {
// TODO(https://crbug.com/873661): Pass origin to FileSystemManager.
map->Add<blink::mojom::FileSystemManager>(
base::BindRepeating(&RenderProcessHost::BindFileSystemManager,
base::Unretained(host->GetProcessHost())));
}
void PopulateBinderMap(SharedWorkerHost* host,
service_manager::BinderMap* map) {
PopulateSharedWorkerBinders(host, map);
}
// Service workers
ServiceWorkerRunningInfo GetContextForHost(ServiceWorkerProviderHost* host) {
// TODO(crbug.com/993409): pass Origin instead of GURL
return {host->running_hosted_version()->script_origin().GetURL(),
host->running_hosted_version()->version_id(), host->process_id()};
}
void PopulateServiceWorkerBinders(ServiceWorkerProviderHost* host,
service_manager::BinderMap* map) {}
void PopulateBinderMapWithContext(
ServiceWorkerProviderHost* host,
service_manager::BinderMapWithContext<const ServiceWorkerRunningInfo&>*
map) {
// Using a task runner since ServiceWorkerProviderHost lives on the IO thread,
// and CreateForWorker() needs to be called on the UI thread.
map->Add<blink::mojom::BackgroundFetchService>(
base::BindRepeating(&BackgroundFetchServiceImpl::CreateForWorker),
base::CreateSingleThreadTaskRunnerWithTraits(BrowserThread::UI));
}
void PopulateBinderMap(ServiceWorkerProviderHost* host,
service_manager::BinderMap* map) {
PopulateServiceWorkerBinders(host, map);
}
} // namespace internal
} // namespace content