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 @@ ...@@ -14,6 +14,7 @@
#include "content/browser/storage_partition_impl.h" #include "content/browser/storage_partition_impl.h"
#include "content/common/service_worker/service_worker_types.h" #include "content/common/service_worker/service_worker_types.h"
#include "content/public/browser/browser_thread.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 "content/public/browser/render_process_host.h"
#include "mojo/public/cpp/bindings/strong_binding.h" #include "mojo/public/cpp/bindings/strong_binding.h"
...@@ -30,11 +31,34 @@ constexpr size_t kMaxTitleLength = 1024 * 1024; ...@@ -30,11 +31,34 @@ constexpr size_t kMaxTitleLength = 1024 * 1024;
} // namespace } // namespace
// static // static
void BackgroundFetchServiceImpl::Create( void BackgroundFetchServiceImpl::CreateForWorker(
blink::mojom::BackgroundFetchServiceRequest request, blink::mojom::BackgroundFetchServiceRequest request,
RenderProcessHost* render_process_host, RenderProcessHost* render_process_host,
const url::Origin& origin) { const url::Origin& origin) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); 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::PostTask(
BrowserThread::IO, FROM_HERE, BrowserThread::IO, FROM_HERE,
base::BindOnce( base::BindOnce(
...@@ -42,24 +66,28 @@ void BackgroundFetchServiceImpl::Create( ...@@ -42,24 +66,28 @@ void BackgroundFetchServiceImpl::Create(
WrapRefCounted(static_cast<StoragePartitionImpl*>( WrapRefCounted(static_cast<StoragePartitionImpl*>(
render_process_host->GetStoragePartition()) render_process_host->GetStoragePartition())
->GetBackgroundFetchContext()), ->GetBackgroundFetchContext()),
origin, std::move(request))); render_frame_host->GetLastCommittedOrigin(), render_frame_host,
std::move(request)));
} }
// static // static
void BackgroundFetchServiceImpl::CreateOnIoThread( void BackgroundFetchServiceImpl::CreateOnIoThread(
scoped_refptr<BackgroundFetchContext> background_fetch_context, scoped_refptr<BackgroundFetchContext> background_fetch_context,
url::Origin origin, url::Origin origin,
RenderFrameHost* render_frame_host,
blink::mojom::BackgroundFetchServiceRequest request) { blink::mojom::BackgroundFetchServiceRequest request) {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK_CURRENTLY_ON(BrowserThread::IO);
mojo::MakeStrongBinding(
std::make_unique<BackgroundFetchServiceImpl>( mojo::MakeStrongBinding(std::make_unique<BackgroundFetchServiceImpl>(
std::move(background_fetch_context), std::move(origin)), std::move(background_fetch_context),
std::move(request)); std::move(origin), render_frame_host),
std::move(request));
} }
BackgroundFetchServiceImpl::BackgroundFetchServiceImpl( BackgroundFetchServiceImpl::BackgroundFetchServiceImpl(
scoped_refptr<BackgroundFetchContext> background_fetch_context, scoped_refptr<BackgroundFetchContext> background_fetch_context,
url::Origin origin) url::Origin origin,
RenderFrameHost* render_frame_host)
: background_fetch_context_(std::move(background_fetch_context)), : background_fetch_context_(std::move(background_fetch_context)),
origin_(std::move(origin)) { origin_(std::move(origin)) {
DCHECK(background_fetch_context_); DCHECK(background_fetch_context_);
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
namespace content { namespace content {
class BackgroundFetchContext; class BackgroundFetchContext;
class RenderFrameHost;
class RenderProcessHost; class RenderProcessHost;
struct BackgroundFetchOptions; struct BackgroundFetchOptions;
struct ServiceWorkerFetchRequest; struct ServiceWorkerFetchRequest;
...@@ -29,12 +30,19 @@ class CONTENT_EXPORT BackgroundFetchServiceImpl ...@@ -29,12 +30,19 @@ class CONTENT_EXPORT BackgroundFetchServiceImpl
public: public:
BackgroundFetchServiceImpl( BackgroundFetchServiceImpl(
scoped_refptr<BackgroundFetchContext> background_fetch_context, scoped_refptr<BackgroundFetchContext> background_fetch_context,
url::Origin origin); url::Origin origin,
RenderFrameHost* render_frame_host);
~BackgroundFetchServiceImpl() override; ~BackgroundFetchServiceImpl() override;
static void Create(blink::mojom::BackgroundFetchServiceRequest request, static void CreateForWorker(
RenderProcessHost* render_process_host, blink::mojom::BackgroundFetchServiceRequest request,
const url::Origin& origin); 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. // blink::mojom::BackgroundFetchService implementation.
void Fetch(int64_t service_worker_registration_id, void Fetch(int64_t service_worker_registration_id,
...@@ -67,6 +75,7 @@ class CONTENT_EXPORT BackgroundFetchServiceImpl ...@@ -67,6 +75,7 @@ class CONTENT_EXPORT BackgroundFetchServiceImpl
static void CreateOnIoThread( static void CreateOnIoThread(
scoped_refptr<BackgroundFetchContext> background_fetch_context, scoped_refptr<BackgroundFetchContext> background_fetch_context,
url::Origin origin, url::Origin origin,
RenderFrameHost* render_frame_host,
blink::mojom::BackgroundFetchServiceRequest request); blink::mojom::BackgroundFetchServiceRequest request);
// Validates and returns whether the |developer_id|, |unique_id|, |requests| // Validates and returns whether the |developer_id|, |unique_id|, |requests|
......
...@@ -95,10 +95,11 @@ class BackgroundFetchServiceTest : public BackgroundFetchTestBase { ...@@ -95,10 +95,11 @@ class BackgroundFetchServiceTest : public BackgroundFetchTestBase {
public: public:
ScopedCustomBackgroundFetchService(BackgroundFetchServiceTest* test, ScopedCustomBackgroundFetchService(BackgroundFetchServiceTest* test,
const url::Origin& origin) const url::Origin& origin)
: scoped_service_( : scoped_service_(&test->service_,
&test->service_, std::make_unique<BackgroundFetchServiceImpl>(
std::make_unique<BackgroundFetchServiceImpl>(test->context_, test->context_,
origin)) {} origin,
nullptr /* render_frame_host */)) {}
private: private:
base::AutoReset<std::unique_ptr<BackgroundFetchServiceImpl>> base::AutoReset<std::unique_ptr<BackgroundFetchServiceImpl>>
...@@ -288,7 +289,8 @@ class BackgroundFetchServiceTest : public BackgroundFetchTestBase { ...@@ -288,7 +289,8 @@ class BackgroundFetchServiceTest : public BackgroundFetchTestBase {
embedded_worker_test_helper()->context_wrapper())); embedded_worker_test_helper()->context_wrapper()));
context_->InitializeOnIOThread(); context_->InitializeOnIOThread();
service_ = std::make_unique<BackgroundFetchServiceImpl>(context_, origin()); service_ = std::make_unique<BackgroundFetchServiceImpl>(
context_, origin(), nullptr /* render_frame_host */);
} }
void TearDown() override { void TearDown() override {
......
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
#include "cc/base/switches.h" #include "cc/base/switches.h"
#include "content/browser/accessibility/browser_accessibility_manager.h" #include "content/browser/accessibility/browser_accessibility_manager.h"
#include "content/browser/accessibility/browser_accessibility_state_impl.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/bluetooth/web_bluetooth_service_impl.h"
#include "content/browser/browser_main_loop.h" #include "content/browser/browser_main_loop.h"
#include "content/browser/child_process_security_policy_impl.h" #include "content/browser/child_process_security_policy_impl.h"
...@@ -3620,6 +3621,9 @@ void RenderFrameHostImpl::RegisterMojoInterfaces() { ...@@ -3620,6 +3621,9 @@ void RenderFrameHostImpl::RegisterMojoInterfaces() {
registry_->AddInterface(base::BindRepeating(IgnoreResult(&Portal::Create), registry_->AddInterface(base::BindRepeating(IgnoreResult(&Portal::Create),
base::Unretained(this))); base::Unretained(this)));
} }
registry_->AddInterface(base::BindRepeating(
&BackgroundFetchServiceImpl::CreateForFrame, GetProcess(), routing_id_));
} }
void RenderFrameHostImpl::ResetWaitingState() { void RenderFrameHostImpl::ResetWaitingState() {
......
...@@ -171,7 +171,7 @@ void RendererInterfaceBinders::InitializeParameterizedBinderRegistry() { ...@@ -171,7 +171,7 @@ void RendererInterfaceBinders::InitializeParameterizedBinderRegistry() {
->CreateService(origin, std::move(request)); ->CreateService(origin, std::move(request));
})); }));
parameterized_binder_registry_.AddInterface( parameterized_binder_registry_.AddInterface(
base::BindRepeating(&BackgroundFetchServiceImpl::Create)); base::BindRepeating(&BackgroundFetchServiceImpl::CreateForWorker));
parameterized_binder_registry_.AddInterface( parameterized_binder_registry_.AddInterface(
base::BindRepeating(GetRestrictedCookieManager)); base::BindRepeating(GetRestrictedCookieManager));
parameterized_binder_registry_.AddInterface( 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