Commit e30a0e8e authored by Rayan Kanso's avatar Rayan Kanso Committed by Commit Bot

[Background Fetch] Register interface via RenderFrameHostImpl

In order to support permissions for Background Fetch, the
RenderFrameHost should be made available. The binding is done from
RenderFrameHostImpl now, with RendererInterfaceBinders left as
a fallback (to register from service worker contexts for example).

Bug: 692647
Change-Id: I3e12b60f410ba104601c68392a07fe24da1cc220
Reviewed-on: https://chromium-review.googlesource.com/1172785Reviewed-by: default avatarAvi Drissman <avi@chromium.org>
Reviewed-by: default avatarPeter Beverloo <peter@chromium.org>
Reviewed-by: default avatarMugdha Lakhani <nator@chromium.org>
Commit-Queue: Rayan Kanso <rayankans@chromium.org>
Cr-Commit-Position: refs/heads/master@{#582954}
parent cda89e62
......@@ -14,6 +14,7 @@
#include "content/browser/storage_partition_impl.h"
#include "content/common/service_worker/service_worker_types.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_process_host.h"
#include "mojo/public/cpp/bindings/strong_binding.h"
......@@ -30,11 +31,34 @@ constexpr size_t kMaxTitleLength = 1024 * 1024;
} // namespace
// static
void BackgroundFetchServiceImpl::Create(
void BackgroundFetchServiceImpl::CreateForWorker(
blink::mojom::BackgroundFetchServiceRequest request,
RenderProcessHost* render_process_host,
const url::Origin& origin) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
base::BindOnce(
BackgroundFetchServiceImpl::CreateOnIoThread,
WrapRefCounted(static_cast<StoragePartitionImpl*>(
render_process_host->GetStoragePartition())
->GetBackgroundFetchContext()),
origin, nullptr /* render_frame_host */, std::move(request)));
}
// static
void BackgroundFetchServiceImpl::CreateForFrame(
RenderProcessHost* render_process_host,
int render_frame_id,
blink::mojom::BackgroundFetchServiceRequest request) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
DCHECK(render_process_host);
auto* render_frame_host =
RenderFrameHost::FromID(render_process_host->GetID(), render_frame_id);
DCHECK(render_frame_host);
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
base::BindOnce(
......@@ -42,24 +66,28 @@ void BackgroundFetchServiceImpl::Create(
WrapRefCounted(static_cast<StoragePartitionImpl*>(
render_process_host->GetStoragePartition())
->GetBackgroundFetchContext()),
origin, std::move(request)));
render_frame_host->GetLastCommittedOrigin(), render_frame_host,
std::move(request)));
}
// static
void BackgroundFetchServiceImpl::CreateOnIoThread(
scoped_refptr<BackgroundFetchContext> background_fetch_context,
url::Origin origin,
RenderFrameHost* render_frame_host,
blink::mojom::BackgroundFetchServiceRequest request) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
mojo::MakeStrongBinding(
std::make_unique<BackgroundFetchServiceImpl>(
std::move(background_fetch_context), std::move(origin)),
std::move(request));
mojo::MakeStrongBinding(std::make_unique<BackgroundFetchServiceImpl>(
std::move(background_fetch_context),
std::move(origin), render_frame_host),
std::move(request));
}
BackgroundFetchServiceImpl::BackgroundFetchServiceImpl(
scoped_refptr<BackgroundFetchContext> background_fetch_context,
url::Origin origin)
url::Origin origin,
RenderFrameHost* render_frame_host)
: background_fetch_context_(std::move(background_fetch_context)),
origin_(std::move(origin)) {
DCHECK(background_fetch_context_);
......
......@@ -20,6 +20,7 @@
namespace content {
class BackgroundFetchContext;
class RenderFrameHost;
class RenderProcessHost;
struct BackgroundFetchOptions;
struct ServiceWorkerFetchRequest;
......@@ -29,12 +30,19 @@ class CONTENT_EXPORT BackgroundFetchServiceImpl
public:
BackgroundFetchServiceImpl(
scoped_refptr<BackgroundFetchContext> background_fetch_context,
url::Origin origin);
url::Origin origin,
RenderFrameHost* render_frame_host);
~BackgroundFetchServiceImpl() override;
static void Create(blink::mojom::BackgroundFetchServiceRequest request,
RenderProcessHost* render_process_host,
const url::Origin& origin);
static void CreateForWorker(
blink::mojom::BackgroundFetchServiceRequest request,
RenderProcessHost* render_process_host,
const url::Origin& origin);
static void CreateForFrame(
RenderProcessHost* render_process_host,
int render_frame_id,
blink::mojom::BackgroundFetchServiceRequest request);
// blink::mojom::BackgroundFetchService implementation.
void Fetch(int64_t service_worker_registration_id,
......@@ -67,6 +75,7 @@ class CONTENT_EXPORT BackgroundFetchServiceImpl
static void CreateOnIoThread(
scoped_refptr<BackgroundFetchContext> background_fetch_context,
url::Origin origin,
RenderFrameHost* render_frame_host,
blink::mojom::BackgroundFetchServiceRequest request);
// Validates and returns whether the |developer_id|, |unique_id|, |requests|
......
......@@ -95,10 +95,11 @@ class BackgroundFetchServiceTest : public BackgroundFetchTestBase {
public:
ScopedCustomBackgroundFetchService(BackgroundFetchServiceTest* test,
const url::Origin& origin)
: scoped_service_(
&test->service_,
std::make_unique<BackgroundFetchServiceImpl>(test->context_,
origin)) {}
: scoped_service_(&test->service_,
std::make_unique<BackgroundFetchServiceImpl>(
test->context_,
origin,
nullptr /* render_frame_host */)) {}
private:
base::AutoReset<std::unique_ptr<BackgroundFetchServiceImpl>>
......@@ -288,7 +289,8 @@ class BackgroundFetchServiceTest : public BackgroundFetchTestBase {
embedded_worker_test_helper()->context_wrapper()));
context_->InitializeOnIOThread();
service_ = std::make_unique<BackgroundFetchServiceImpl>(context_, origin());
service_ = std::make_unique<BackgroundFetchServiceImpl>(
context_, origin(), nullptr /* render_frame_host */);
}
void TearDown() override {
......
......@@ -30,6 +30,7 @@
#include "cc/base/switches.h"
#include "content/browser/accessibility/browser_accessibility_manager.h"
#include "content/browser/accessibility/browser_accessibility_state_impl.h"
#include "content/browser/background_fetch/background_fetch_service_impl.h"
#include "content/browser/bluetooth/web_bluetooth_service_impl.h"
#include "content/browser/browser_main_loop.h"
#include "content/browser/child_process_security_policy_impl.h"
......@@ -3620,6 +3621,9 @@ void RenderFrameHostImpl::RegisterMojoInterfaces() {
registry_->AddInterface(base::BindRepeating(IgnoreResult(&Portal::Create),
base::Unretained(this)));
}
registry_->AddInterface(base::BindRepeating(
&BackgroundFetchServiceImpl::CreateForFrame, GetProcess(), routing_id_));
}
void RenderFrameHostImpl::ResetWaitingState() {
......
......@@ -171,7 +171,7 @@ void RendererInterfaceBinders::InitializeParameterizedBinderRegistry() {
->CreateService(origin, std::move(request));
}));
parameterized_binder_registry_.AddInterface(
base::BindRepeating(&BackgroundFetchServiceImpl::Create));
base::BindRepeating(&BackgroundFetchServiceImpl::CreateForWorker));
parameterized_binder_registry_.AddInterface(
base::BindRepeating(GetRestrictedCookieManager));
parameterized_binder_registry_.AddInterface(
......
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