Commit 54bc028e authored by Sam McNally's avatar Sam McNally Committed by Commit Bot

Remove origins from the BackgroundFetchService interface messages.

Move registration of the BackgroundFetchService interface from
RenderProcessHost to RendererInterfaceBinders so its implementation can
receive a browser-tracked origin for its renderer-process client.

Add support for move-only types to base::AutoReset. Use it in the
BackgroundFetchServiceImpl test to swap in a service instance with a
different origin for the part of the test that previously passed a
different origin to the mojo interface.

Bug: 779444
Change-Id: I68737625cb5cd0a2843eeb46643aad3b4f852d8c
Reviewed-on: https://chromium-review.googlesource.com/788641Reviewed-by: default avatarPeter Beverloo <peter@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Commit-Queue: Sam McNally <sammc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#523661}
parent 2b77b931
......@@ -5,6 +5,8 @@
#ifndef BASE_AUTO_RESET_H_
#define BASE_AUTO_RESET_H_
#include <utility>
#include "base/macros.h"
// base::AutoReset<> is useful for setting a variable to a new value only within
......@@ -23,11 +25,11 @@ class AutoReset {
public:
AutoReset(T* scoped_variable, T new_value)
: scoped_variable_(scoped_variable),
original_value_(*scoped_variable) {
*scoped_variable_ = new_value;
original_value_(std::move(*scoped_variable)) {
*scoped_variable_ = std::move(new_value);
}
~AutoReset() { *scoped_variable_ = original_value_; }
~AutoReset() { *scoped_variable_ = std::move(original_value_); }
private:
T* scoped_variable_;
......
......@@ -10,10 +10,11 @@
#include "content/browser/background_fetch/background_fetch_context.h"
#include "content/browser/background_fetch/background_fetch_registration_id.h"
#include "content/browser/bad_message.h"
#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_process_host.h"
#include "mojo/public/cpp/bindings/strong_binding.h"
#include "url/origin.h"
namespace content {
......@@ -29,21 +30,37 @@ constexpr size_t kMaxTitleLength = 1024 * 1024;
// static
void BackgroundFetchServiceImpl::Create(
int render_process_id,
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, std::move(request)));
}
// static
void BackgroundFetchServiceImpl::CreateOnIoThread(
scoped_refptr<BackgroundFetchContext> background_fetch_context,
url::Origin origin,
blink::mojom::BackgroundFetchServiceRequest request) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
mojo::MakeStrongBinding(
std::make_unique<BackgroundFetchServiceImpl>(
render_process_id, std::move(background_fetch_context)),
std::move(background_fetch_context), std::move(origin)),
std::move(request));
}
BackgroundFetchServiceImpl::BackgroundFetchServiceImpl(
int render_process_id,
scoped_refptr<BackgroundFetchContext> background_fetch_context)
: render_process_id_(render_process_id),
background_fetch_context_(std::move(background_fetch_context)) {
scoped_refptr<BackgroundFetchContext> background_fetch_context,
url::Origin origin)
: background_fetch_context_(std::move(background_fetch_context)),
origin_(std::move(origin)) {
DCHECK(background_fetch_context_);
}
......@@ -53,7 +70,6 @@ BackgroundFetchServiceImpl::~BackgroundFetchServiceImpl() {
void BackgroundFetchServiceImpl::Fetch(
int64_t service_worker_registration_id,
const url::Origin& origin,
const std::string& developer_id,
const std::vector<ServiceWorkerFetchRequest>& requests,
const BackgroundFetchOptions& options,
......@@ -76,7 +92,7 @@ void BackgroundFetchServiceImpl::Fetch(
// New |unique_id|, since this is a new Background Fetch registration. This is
// the only place new |unique_id|s should be created outside of tests.
BackgroundFetchRegistrationId registration_id(service_worker_registration_id,
origin, developer_id,
origin_, developer_id,
base::GenerateGUID());
background_fetch_context_->StartFetch(registration_id, requests, options,
......@@ -97,7 +113,6 @@ void BackgroundFetchServiceImpl::UpdateUI(const std::string& unique_id,
}
void BackgroundFetchServiceImpl::Abort(int64_t service_worker_registration_id,
const url::Origin& origin,
const std::string& developer_id,
const std::string& unique_id,
AbortCallback callback) {
......@@ -109,14 +124,13 @@ void BackgroundFetchServiceImpl::Abort(int64_t service_worker_registration_id,
}
background_fetch_context_->Abort(
BackgroundFetchRegistrationId(service_worker_registration_id, origin,
BackgroundFetchRegistrationId(service_worker_registration_id, origin_,
developer_id, unique_id),
std::move(callback));
}
void BackgroundFetchServiceImpl::GetRegistration(
int64_t service_worker_registration_id,
const url::Origin& origin,
const std::string& developer_id,
GetRegistrationCallback callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
......@@ -128,17 +142,16 @@ void BackgroundFetchServiceImpl::GetRegistration(
}
background_fetch_context_->GetRegistration(service_worker_registration_id,
origin, developer_id,
origin_, developer_id,
std::move(callback));
}
void BackgroundFetchServiceImpl::GetDeveloperIds(
int64_t service_worker_registration_id,
const url::Origin& origin,
GetDeveloperIdsCallback callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
background_fetch_context_->GetDeveloperIdsForServiceWorker(
service_worker_registration_id, origin, std::move(callback));
service_worker_registration_id, origin_, std::move(callback));
}
void BackgroundFetchServiceImpl::AddRegistrationObserver(
......@@ -155,8 +168,7 @@ void BackgroundFetchServiceImpl::AddRegistrationObserver(
bool BackgroundFetchServiceImpl::ValidateDeveloperId(
const std::string& developer_id) {
if (developer_id.empty() || developer_id.size() > kMaxDeveloperIdLength) {
bad_message::ReceivedBadMessage(render_process_id_,
bad_message::BFSI_INVALID_DEVELOPER_ID);
mojo::ReportBadMessage("Invalid developer_id");
return false;
}
......@@ -166,8 +178,7 @@ bool BackgroundFetchServiceImpl::ValidateDeveloperId(
bool BackgroundFetchServiceImpl::ValidateUniqueId(
const std::string& unique_id) {
if (!base::IsValidGUIDOutputString(unique_id)) {
bad_message::ReceivedBadMessage(render_process_id_,
bad_message::BFSI_INVALID_UNIQUE_ID);
mojo::ReportBadMessage("Invalid unique_id");
return false;
}
......@@ -177,8 +188,7 @@ bool BackgroundFetchServiceImpl::ValidateUniqueId(
bool BackgroundFetchServiceImpl::ValidateRequests(
const std::vector<ServiceWorkerFetchRequest>& requests) {
if (requests.empty()) {
bad_message::ReceivedBadMessage(render_process_id_,
bad_message::BFSI_INVALID_REQUESTS);
mojo::ReportBadMessage("Invalid requests");
return false;
}
......@@ -187,8 +197,7 @@ bool BackgroundFetchServiceImpl::ValidateRequests(
bool BackgroundFetchServiceImpl::ValidateTitle(const std::string& title) {
if (title.empty() || title.size() > kMaxTitleLength) {
bad_message::ReceivedBadMessage(render_process_id_,
bad_message::BFSI_INVALID_TITLE);
mojo::ReportBadMessage("Invalid title");
return false;
}
......
......@@ -14,14 +14,12 @@
#include "base/memory/ref_counted.h"
#include "content/common/content_export.h"
#include "third_party/WebKit/public/platform/modules/background_fetch/background_fetch.mojom.h"
namespace url {
class Origin;
}
#include "url/origin.h"
namespace content {
class BackgroundFetchContext;
class RenderProcessHost;
struct BackgroundFetchOptions;
struct ServiceWorkerFetchRequest;
......@@ -29,18 +27,16 @@ class CONTENT_EXPORT BackgroundFetchServiceImpl
: public blink::mojom::BackgroundFetchService {
public:
BackgroundFetchServiceImpl(
int render_process_id,
scoped_refptr<BackgroundFetchContext> background_fetch_context);
scoped_refptr<BackgroundFetchContext> background_fetch_context,
url::Origin origin);
~BackgroundFetchServiceImpl() override;
static void Create(
int render_process_id,
scoped_refptr<BackgroundFetchContext> background_fetch_context,
blink::mojom::BackgroundFetchServiceRequest request);
static void Create(blink::mojom::BackgroundFetchServiceRequest request,
RenderProcessHost* render_process_host,
const url::Origin& origin);
// blink::mojom::BackgroundFetchService implementation.
void Fetch(int64_t service_worker_registration_id,
const url::Origin& origin,
const std::string& developer_id,
const std::vector<ServiceWorkerFetchRequest>& requests,
const BackgroundFetchOptions& options,
......@@ -49,22 +45,24 @@ class CONTENT_EXPORT BackgroundFetchServiceImpl
const std::string& title,
UpdateUICallback callback) override;
void Abort(int64_t service_worker_registration_id,
const url::Origin& origin,
const std::string& developer_id,
const std::string& unique_id,
AbortCallback callback) override;
void GetRegistration(int64_t service_worker_registration_id,
const url::Origin& origin,
const std::string& developer_id,
GetRegistrationCallback callback) override;
void GetDeveloperIds(int64_t service_worker_registration_id,
const url::Origin& origin,
GetDeveloperIdsCallback callback) override;
void AddRegistrationObserver(
const std::string& unique_id,
blink::mojom::BackgroundFetchRegistrationObserverPtr observer) override;
private:
static void CreateOnIoThread(
scoped_refptr<BackgroundFetchContext> background_fetch_context,
url::Origin origin,
blink::mojom::BackgroundFetchServiceRequest request);
// Validates and returns whether the |developer_id|, |unique_id|, |requests|
// and |title| respectively have valid values. The renderer will be flagged
// for having sent a bad message if the values are invalid.
......@@ -74,12 +72,11 @@ class CONTENT_EXPORT BackgroundFetchServiceImpl
WARN_UNUSED_RESULT;
bool ValidateTitle(const std::string& title) WARN_UNUSED_RESULT;
// Id of the renderer process that this service has been created for.
int render_process_id_;
// The Background Fetch context on which operations will be dispatched.
scoped_refptr<BackgroundFetchContext> background_fetch_context_;
const url::Origin origin_;
DISALLOW_COPY_AND_ASSIGN(BackgroundFetchServiceImpl);
};
......
......@@ -6,6 +6,7 @@
#include <memory>
#include <utility>
#include "base/auto_reset.h"
#include "base/macros.h"
#include "base/memory/ptr_util.h"
#include "base/run_loop.h"
......@@ -18,6 +19,8 @@
#include "content/browser/service_worker/service_worker_context_wrapper.h"
#include "content/browser/storage_partition_impl.h"
#include "content/common/service_worker/service_worker_types.h"
#include "mojo/edk/embedder/embedder.h"
#include "mojo/public/cpp/bindings/message.h"
#include "services/network/public/interfaces/fetch_api.mojom.h"
namespace content {
......@@ -38,11 +41,52 @@ IconDefinition CreateIcon(std::string src,
return icon;
}
class BadMessageObserver {
public:
BadMessageObserver()
: dummy_message_(0, 0, 0, 0, nullptr), context_(&dummy_message_) {
mojo::edk::SetDefaultProcessErrorCallback(base::BindRepeating(
&BadMessageObserver::ReportBadMessage, base::Unretained(this)));
}
~BadMessageObserver() {
mojo::edk::SetDefaultProcessErrorCallback(
mojo::edk::ProcessErrorCallback());
}
const std::string& last_error() const { return last_error_; }
private:
void ReportBadMessage(const std::string& error) { last_error_ = error; }
mojo::Message dummy_message_;
mojo::internal::MessageDispatchContext context_;
std::string last_error_;
DISALLOW_COPY_AND_ASSIGN(BadMessageObserver);
};
class BackgroundFetchServiceTest : public BackgroundFetchTestBase {
public:
BackgroundFetchServiceTest() = default;
~BackgroundFetchServiceTest() override = default;
class ScopedCustomBackgroundFetchService {
public:
ScopedCustomBackgroundFetchService(BackgroundFetchServiceTest* test,
const url::Origin& origin)
: scoped_service_(
&test->service_,
std::make_unique<BackgroundFetchServiceImpl>(test->context_,
origin)) {}
private:
base::AutoReset<std::unique_ptr<BackgroundFetchServiceImpl>>
scoped_service_;
DISALLOW_COPY_AND_ASSIGN(ScopedCustomBackgroundFetchService);
};
// Synchronous wrapper for BackgroundFetchServiceImpl::Fetch().
BackgroundFetchRegistrationId Fetch(
int64_t service_worker_registration_id,
......@@ -56,8 +100,7 @@ class BackgroundFetchServiceTest : public BackgroundFetchTestBase {
base::RunLoop run_loop;
service_->Fetch(
service_worker_registration_id, origin(), developer_id, requests,
options,
service_worker_registration_id, developer_id, requests, options,
base::BindOnce(&BackgroundFetchServiceTest::DidGetRegistration,
base::Unretained(this), run_loop.QuitClosure(),
out_error, out_registration));
......@@ -94,8 +137,7 @@ class BackgroundFetchServiceTest : public BackgroundFetchTestBase {
DCHECK(out_error);
base::RunLoop run_loop;
service_->Abort(service_worker_registration_id, origin(), developer_id,
unique_id,
service_->Abort(service_worker_registration_id, developer_id, unique_id,
base::BindOnce(&BackgroundFetchServiceTest::DidGetError,
base::Unretained(this),
run_loop.QuitClosure(), out_error));
......@@ -113,7 +155,7 @@ class BackgroundFetchServiceTest : public BackgroundFetchTestBase {
base::RunLoop run_loop;
service_->GetRegistration(
service_worker_registration_id, origin(), developer_id,
service_worker_registration_id, developer_id,
base::BindOnce(&BackgroundFetchServiceTest::DidGetRegistration,
base::Unretained(this), run_loop.QuitClosure(),
out_error, out_registration));
......@@ -123,7 +165,6 @@ class BackgroundFetchServiceTest : public BackgroundFetchTestBase {
// Synchronous wrapper for BackgroundFetchServiceImpl::GetDeveloperIds().
void GetDeveloperIds(int64_t service_worker_registration_id,
const url::Origin& origin,
blink::mojom::BackgroundFetchError* out_error,
std::vector<std::string>* out_developer_ids) {
DCHECK(out_error);
......@@ -131,7 +172,7 @@ class BackgroundFetchServiceTest : public BackgroundFetchTestBase {
base::RunLoop run_loop;
service_->GetDeveloperIds(
service_worker_registration_id, origin,
service_worker_registration_id,
base::BindOnce(&BackgroundFetchServiceTest::DidGetDeveloperIds,
base::Unretained(this), run_loop.QuitClosure(),
out_error, out_developer_ids));
......@@ -147,8 +188,7 @@ class BackgroundFetchServiceTest : public BackgroundFetchTestBase {
browser_context(),
base::WrapRefCounted(embedded_worker_test_helper()->context_wrapper()));
service_ = std::make_unique<BackgroundFetchServiceImpl>(
0 /* render_process_id */, context_);
service_ = std::make_unique<BackgroundFetchServiceImpl>(context_, origin());
}
void TearDown() override {
......@@ -210,6 +250,7 @@ TEST_F(BackgroundFetchServiceTest, FetchInvalidArguments) {
// The |developer_id| must be a non-empty string.
{
BadMessageObserver bad_message_observer;
std::vector<ServiceWorkerFetchRequest> requests;
requests.emplace_back(); // empty, but valid
......@@ -219,10 +260,12 @@ TEST_F(BackgroundFetchServiceTest, FetchInvalidArguments) {
Fetch(42 /* service_worker_registration_id */, "" /* developer_id */,
requests, options, &error, &registration);
ASSERT_EQ(error, blink::mojom::BackgroundFetchError::INVALID_ARGUMENT);
EXPECT_EQ("Invalid developer_id", bad_message_observer.last_error());
}
// At least a single ServiceWorkerFetchRequest must be given.
{
BadMessageObserver bad_message_observer;
std::vector<ServiceWorkerFetchRequest> requests;
// |requests| has deliberately been left empty.
......@@ -232,6 +275,7 @@ TEST_F(BackgroundFetchServiceTest, FetchInvalidArguments) {
Fetch(42 /* service_worker_registration_id */, kExampleDeveloperId,
requests, options, &error, &registration);
ASSERT_EQ(error, blink::mojom::BackgroundFetchError::INVALID_ARGUMENT);
EXPECT_EQ("Invalid requests", bad_message_observer.last_error());
}
}
......@@ -598,10 +642,12 @@ TEST_F(BackgroundFetchServiceTest, AbortInvalidDeveloperIdArgument) {
// return INVALID_ARGUMENT when an invalid |developer_id| is sent over the
// Mojo channel.
BadMessageObserver bad_message_observer;
blink::mojom::BackgroundFetchError error;
Abort(42 /* service_worker_registration_id */, "" /* developer_id */,
kExampleUniqueId, &error);
ASSERT_EQ(error, blink::mojom::BackgroundFetchError::INVALID_ARGUMENT);
EXPECT_EQ("Invalid developer_id", bad_message_observer.last_error());
}
TEST_F(BackgroundFetchServiceTest, AbortInvalidUniqueIdArgument) {
......@@ -609,10 +655,12 @@ TEST_F(BackgroundFetchServiceTest, AbortInvalidUniqueIdArgument) {
// return INVALID_ARGUMENT when an invalid |unique_id| is sent over the Mojo
// channel.
BadMessageObserver bad_message_observer;
blink::mojom::BackgroundFetchError error;
Abort(42 /* service_worker_registration_id */, kExampleDeveloperId,
"not a GUID" /* unique_id */, &error);
ASSERT_EQ(error, blink::mojom::BackgroundFetchError::INVALID_ARGUMENT);
EXPECT_EQ("Invalid unique_id", bad_message_observer.last_error());
}
TEST_F(BackgroundFetchServiceTest, AbortUnknownUniqueId) {
......@@ -805,8 +853,7 @@ TEST_F(BackgroundFetchServiceTest, GetDeveloperIds) {
blink::mojom::BackgroundFetchError error;
std::vector<std::string> developer_ids;
GetDeveloperIds(service_worker_registration_id, origin(), &error,
&developer_ids);
GetDeveloperIds(service_worker_registration_id, &error, &developer_ids);
ASSERT_EQ(error, blink::mojom::BackgroundFetchError::NONE);
ASSERT_EQ(developer_ids.size(), 0u);
......@@ -827,8 +874,7 @@ TEST_F(BackgroundFetchServiceTest, GetDeveloperIds) {
blink::mojom::BackgroundFetchError error;
std::vector<std::string> developer_ids;
GetDeveloperIds(service_worker_registration_id, origin(), &error,
&developer_ids);
GetDeveloperIds(service_worker_registration_id, &error, &developer_ids);
ASSERT_EQ(error, blink::mojom::BackgroundFetchError::NONE);
ASSERT_EQ(developer_ids.size(), 1u);
......@@ -850,8 +896,7 @@ TEST_F(BackgroundFetchServiceTest, GetDeveloperIds) {
blink::mojom::BackgroundFetchError error;
std::vector<std::string> developer_ids;
GetDeveloperIds(service_worker_registration_id, origin(), &error,
&developer_ids);
GetDeveloperIds(service_worker_registration_id, &error, &developer_ids);
ASSERT_EQ(error, blink::mojom::BackgroundFetchError::NONE);
ASSERT_EQ(developer_ids.size(), 2u);
......@@ -866,12 +911,12 @@ TEST_F(BackgroundFetchServiceTest, GetDeveloperIds) {
// Verify that using the wrong origin does not return developer ids even if
// the service worker registration is correct.
{
ScopedCustomBackgroundFetchService scoped_bogus_url_service(
this, url::Origin::Create(GURL("https://www.bogus-origin.com")));
blink::mojom::BackgroundFetchError error;
std::vector<std::string> developer_ids;
GetDeveloperIds(service_worker_registration_id,
url::Origin::Create(GURL("https://www.bogus-origin.com")),
&error, &developer_ids);
GetDeveloperIds(service_worker_registration_id, &error, &developer_ids);
ASSERT_EQ(error, blink::mojom::BackgroundFetchError::NONE);
ASSERT_EQ(developer_ids.size(), 0u);
......@@ -886,7 +931,7 @@ TEST_F(BackgroundFetchServiceTest, GetDeveloperIds) {
int64_t bogus_service_worker_registration_id =
service_worker_registration_id + 1;
GetDeveloperIds(bogus_service_worker_registration_id, origin(), &error,
GetDeveloperIds(bogus_service_worker_registration_id, &error,
&developer_ids);
ASSERT_EQ(error, blink::mojom::BackgroundFetchError::NONE);
......
......@@ -1888,11 +1888,6 @@ void RenderProcessHostImpl::RegisterMojoInterfaces() {
base::Bind(&PushMessagingManager::BindRequest,
base::Unretained(push_messaging_manager_.get())));
registry->AddInterface(
base::Bind(&BackgroundFetchServiceImpl::Create, GetID(),
base::WrapRefCounted(
storage_partition_impl_->GetBackgroundFetchContext())));
if (gpu_client_) {
// |gpu_client_| outlives the registry, because its destruction is posted to
// IO thread from the destructor of |this|.
......
......@@ -140,6 +140,8 @@ void RendererInterfaceBinders::InitializeParameterizedBinderRegistry() {
->GetPlatformNotificationContext()
->CreateService(host->GetID(), origin, std::move(request));
}));
parameterized_binder_registry_.AddInterface(
base::BindRepeating(&BackgroundFetchServiceImpl::Create));
}
RendererInterfaceBinders& GetRendererInterfaceBinders() {
......
......@@ -18,7 +18,6 @@
"ui::mojom::Gpu"
],
"renderer": [
"blink::mojom::BackgroundFetchService",
"blink::mojom::BackgroundSyncService",
"blink::mojom::BlobRegistry",
"blink::mojom::BroadcastChannelProvider",
......@@ -124,6 +123,7 @@
// impossible this week. Remove once sky/ken fix this.
"autofill::mojom::AutofillDriver",
"autofill::mojom::PasswordManagerDriver",
"blink::mojom::BackgroundFetchService",
"blink::mojom::DedicatedWorkerFactory",
"blink::mojom::LockManager",
"blink::mojom::GeolocationService",
......@@ -194,6 +194,7 @@
"navigation:service_worker": {
"provides": {
"renderer": [
"blink::mojom::BackgroundFetchService",
"blink::mojom::LockManager",
"blink::mojom::NotificationService",
"blink::mojom::PermissionService",
......
......@@ -9,10 +9,9 @@
#include "modules/background_fetch/BackgroundFetchRegistration.h"
#include "modules/background_fetch/BackgroundFetchTypeConverters.h"
#include "modules/background_fetch/IconDefinition.h"
#include "public/platform/InterfaceProvider.h"
#include "public/platform/Platform.h"
#include "public/platform/modules/serviceworker/WebServiceWorkerRegistration.h"
#include "public/platform/modules/serviceworker/WebServiceWorkerRequest.h"
#include "services/service_manager/public/cpp/interface_provider.h"
namespace blink {
......@@ -50,9 +49,8 @@ void BackgroundFetchBridge::Fetch(const String& developer_id,
const BackgroundFetchOptions& options,
RegistrationCallback callback) {
GetService()->Fetch(
GetSupplementable()->WebRegistration()->RegistrationId(),
GetSecurityOrigin(), developer_id, std::move(requests),
mojom::blink::BackgroundFetchOptions::From(options),
GetSupplementable()->WebRegistration()->RegistrationId(), developer_id,
std::move(requests), mojom::blink::BackgroundFetchOptions::From(options),
WTF::Bind(&BackgroundFetchBridge::DidGetRegistration,
WrapPersistent(this), WTF::Passed(std::move(callback))));
}
......@@ -61,8 +59,7 @@ void BackgroundFetchBridge::Abort(const String& developer_id,
const String& unique_id,
AbortCallback callback) {
GetService()->Abort(GetSupplementable()->WebRegistration()->RegistrationId(),
GetSecurityOrigin(), developer_id, unique_id,
std::move(callback));
developer_id, unique_id, std::move(callback));
}
void BackgroundFetchBridge::UpdateUI(const String& developer_id,
......@@ -75,8 +72,7 @@ void BackgroundFetchBridge::UpdateUI(const String& developer_id,
void BackgroundFetchBridge::GetRegistration(const String& developer_id,
RegistrationCallback callback) {
GetService()->GetRegistration(
GetSupplementable()->WebRegistration()->RegistrationId(),
GetSecurityOrigin(), developer_id,
GetSupplementable()->WebRegistration()->RegistrationId(), developer_id,
WTF::Bind(&BackgroundFetchBridge::DidGetRegistration,
WrapPersistent(this), WTF::Passed(std::move(callback))));
}
......@@ -99,7 +95,7 @@ void BackgroundFetchBridge::DidGetRegistration(
void BackgroundFetchBridge::GetDeveloperIds(GetDeveloperIdsCallback callback) {
GetService()->GetDeveloperIds(
GetSupplementable()->WebRegistration()->RegistrationId(),
GetSecurityOrigin(), std::move(callback));
std::move(callback));
}
void BackgroundFetchBridge::AddRegistrationObserver(
......@@ -108,16 +104,16 @@ void BackgroundFetchBridge::AddRegistrationObserver(
GetService()->AddRegistrationObserver(unique_id, std::move(observer));
}
const SecurityOrigin* BackgroundFetchBridge::GetSecurityOrigin() {
return GetSupplementable()->GetExecutionContext()->GetSecurityOrigin();
}
mojom::blink::BackgroundFetchServicePtr& BackgroundFetchBridge::GetService() {
mojom::blink::BackgroundFetchService* BackgroundFetchBridge::GetService() {
if (!background_fetch_service_) {
Platform::Current()->GetInterfaceProvider()->GetInterface(
mojo::MakeRequest(&background_fetch_service_));
auto request = mojo::MakeRequest(&background_fetch_service_);
if (auto* interface_provider = GetSupplementable()
->GetExecutionContext()
->GetInterfaceProvider()) {
interface_provider->GetInterface(std::move(request));
}
}
return background_fetch_service_;
return background_fetch_service_.get();
}
} // namespace blink
......@@ -89,13 +89,9 @@ class BackgroundFetchBridge final
private:
explicit BackgroundFetchBridge(ServiceWorkerRegistration&);
// Returns the security origin for the Service Worker registration this bridge
// is servicing, which is to be included in the Mojo calls.
const SecurityOrigin* GetSecurityOrigin();
// Returns an initialized BackgroundFetchServicePtr. A connection will be
// Returns an initialized BackgroundFetchService*. A connection will be
// established after the first call to this method.
mojom::blink::BackgroundFetchServicePtr& GetService();
mojom::blink::BackgroundFetchService* GetService();
void DidGetRegistration(RegistrationCallback,
mojom::blink::BackgroundFetchError,
......
......@@ -5,7 +5,6 @@
module blink.mojom;
import "third_party/WebKit/public/platform/modules/fetch/fetch_api_request.mojom";
import "url/mojo/origin.mojom";
enum BackgroundFetchError {
NONE,
......@@ -64,7 +63,6 @@ interface BackgroundFetchService {
// Creates a new Background Fetch registration identified to the developer by
// |developer_id|, with the given |options| for the sequence of |requests|.
Fetch(int64 service_worker_registration_id,
url.mojom.Origin origin,
string developer_id,
array<FetchAPIRequest> requests,
BackgroundFetchOptions options)
......@@ -80,21 +78,19 @@ interface BackgroundFetchService {
// the developer's |developer_id|. Fails if the registration had already
// completed/failed/aborted.
Abort(int64 service_worker_registration_id,
url.mojom.Origin origin,
string developer_id,
string unique_id)
=> (BackgroundFetchError error);
// Gets the active Background Fetch registration identified by |developer_id|.
GetRegistration(int64 service_worker_registration_id,
url.mojom.Origin origin,
string developer_id)
=> (BackgroundFetchError error,
BackgroundFetchRegistration? registration);
// Gets the sequence of |developer_id|s for active Background Fetch
// registrations given the |service_worker_registration_id|.
GetDeveloperIds(int64 service_worker_registration_id, url.mojom.Origin origin)
GetDeveloperIds(int64 service_worker_registration_id)
=> (BackgroundFetchError error,
array<string> developer_ids);
......
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