Skip to content

Commit

Permalink
Convert RestrictedCookieManager client to use BrowserInterfaceBroker
Browse files Browse the repository at this point in the history
This change converts RestrictedCookieManager mojom interface client
in blink to use BrowserInterfaceBroker.

Bug: 936482
Change-Id: I2d8a4cee3b7f039ea350cffedfa15d96447c9df5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1844754
Commit-Queue: Miyoung Shin <myid.shin@igalia.com>
Reviewed-by: Kinuko Yasuda <kinuko@chromium.org>
Reviewed-by: Dave Tapuska <dtapuska@chromium.org>
Reviewed-by: Oksana Zhuravlova <oksamyt@chromium.org>
Cr-Commit-Position: refs/heads/master@{#720870}
  • Loading branch information
MyidShin authored and Commit Bot committed Dec 3, 2019
1 parent 7109368 commit 58d0b6c
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 42 deletions.
9 changes: 9 additions & 0 deletions content/browser/browser_interface_binders.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
#include "services/device/public/mojom/constants.mojom.h"
#include "services/device/public/mojom/sensor_provider.mojom.h"
#include "services/device/public/mojom/vibration_manager.mojom.h"
#include "services/network/public/mojom/restricted_cookie_manager.mojom.h"
#include "services/service_manager/public/cpp/connector.h"
#include "services/shape_detection/public/mojom/barcodedetection_provider.mojom.h"
#include "services/shape_detection/public/mojom/facedetection_provider.mojom.h"
Expand Down Expand Up @@ -592,6 +593,10 @@ void PopulateFrameBinders(RenderFrameHostImpl* host,
base::BindRepeating(&RenderProcessHost::BindVideoDecodePerfHistory,
base::Unretained(host->GetProcess())));

map->Add<network::mojom::RestrictedCookieManager>(
base::BindRepeating(&RenderFrameHostImpl::BindRestrictedCookieManager,
base::Unretained(host)));

map->Add<shape_detection::mojom::BarcodeDetectionProvider>(
base::BindRepeating(&BindBarcodeDetectionProvider));

Expand Down Expand Up @@ -888,6 +893,10 @@ void PopulateBinderMapWithContext(
&RenderProcessHost::CreateNotificationService, host));
map->Add<blink::mojom::WebSocketConnector>(BindServiceWorkerReceiverForOrigin(
&RenderProcessHost::CreateWebSocketConnector, host));
map->Add<network::mojom::RestrictedCookieManager>(
BindServiceWorkerReceiverForOrigin(
&RenderProcessHost::BindRestrictedCookieManagerForServiceWorker,
host));

// render process host binders taking a frame id and an origin
map->Add<blink::mojom::IDBFactory>(
Expand Down
28 changes: 10 additions & 18 deletions content/browser/frame_host/render_frame_host_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -528,20 +528,6 @@ std::unique_ptr<blink::URLLoaderFactoryBundleInfo> CloneFactoryBundle(
bundle->Clone().release()));
}

void GetRestrictedCookieManager(
RenderFrameHostImpl* frame_host,
int process_id,
int frame_id,
StoragePartition* storage_partition,
mojo::PendingReceiver<network::mojom::RestrictedCookieManager> receiver) {
storage_partition->CreateRestrictedCookieManager(
network::mojom::RestrictedCookieManagerRole::SCRIPT,
frame_host->GetLastCommittedOrigin(), frame_host->ComputeSiteForCookies(),
frame_host->ComputeTopFrameOrigin(frame_host->GetLastCommittedOrigin()),
/* is_service_worker = */ false, process_id, frame_id,
std::move(receiver));
}

// Helper method to download a URL on UI thread.
void StartDownload(
std::unique_ptr<download::DownloadUrlParameters> parameters,
Expand Down Expand Up @@ -4683,10 +4669,6 @@ void RenderFrameHostImpl::RegisterMojoInterfaces() {
GetProcess()->GetID(),
GetProcess()->GetStoragePartition()->GetFileSystemContext(),
ChromeBlobStorageContext::GetFor(GetProcess()->GetBrowserContext())));

registry_->AddInterface(base::BindRepeating(
&GetRestrictedCookieManager, base::Unretained(this),
GetProcess()->GetID(), routing_id_, GetProcess()->GetStoragePartition()));
}

media::MediaMetricsProvider::RecordAggregateWatchTimeCallback
Expand Down Expand Up @@ -6634,6 +6616,16 @@ void RenderFrameHostImpl::BindSmsReceiverReceiver(
SmsService::Create(fetcher, this, std::move(receiver));
}

void RenderFrameHostImpl::BindRestrictedCookieManager(
mojo::PendingReceiver<network::mojom::RestrictedCookieManager> receiver) {
GetProcess()->GetStoragePartition()->CreateRestrictedCookieManager(
network::mojom::RestrictedCookieManagerRole::SCRIPT,
GetLastCommittedOrigin(), ComputeSiteForCookies(),
ComputeTopFrameOrigin(GetLastCommittedOrigin()),
/* is_service_worker = */ false, GetProcess()->GetID(), routing_id(),
std::move(receiver));
}

void RenderFrameHostImpl::GetInterface(
const std::string& interface_name,
mojo::ScopedMessagePipeHandle interface_pipe) {
Expand Down
3 changes: 3 additions & 0 deletions content/browser/frame_host/render_frame_host_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -1164,6 +1164,9 @@ class CONTENT_EXPORT RenderFrameHostImpl
void BindSmsReceiverReceiver(
mojo::PendingReceiver<blink::mojom::SmsReceiver> receiver);

void BindRestrictedCookieManager(
mojo::PendingReceiver<network::mojom::RestrictedCookieManager> receiver);

// Creates connections to WebUSB interfaces bound to this frame.
void CreateWebUsbService(
mojo::PendingReceiver<blink::mojom::WebUsbService> receiver);
Expand Down
10 changes: 10 additions & 0 deletions content/browser/renderer_host/render_process_host_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1937,6 +1937,16 @@ void RenderProcessHostImpl::BindNativeFileSystemManager(
std::move(receiver));
}

void RenderProcessHostImpl::BindRestrictedCookieManagerForServiceWorker(
const url::Origin& origin,
mojo::PendingReceiver<network::mojom::RestrictedCookieManager> receiver) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
GetStoragePartition()->CreateRestrictedCookieManager(
network::mojom::RestrictedCookieManagerRole::SCRIPT, origin,
origin.GetURL(), origin, true /* is_service_worker */, GetID(),
MSG_ROUTING_NONE, std::move(receiver));
}

void RenderProcessHostImpl::BindVideoDecodePerfHistory(
mojo::PendingReceiver<media::mojom::VideoDecodePerfHistory> receiver) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
Expand Down
9 changes: 9 additions & 0 deletions content/browser/renderer_host/render_process_host_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,15 @@ class CONTENT_EXPORT RenderProcessHostImpl
return file_system_manager_impl_.get();
}

// Binds |receiver| to the RestrictedCookieManager instance owned by
// |storage_partition_impl_|, and is used by a service worker via
// BrowserInterfaceBroker. |receiver| belongs to the service worker at
// |origin| hosted by this process,
void BindRestrictedCookieManagerForServiceWorker(
const url::Origin& origin,
mojo::PendingReceiver<network::mojom::RestrictedCookieManager> receiver)
override;

// Binds |receiver| to the VideoDecodePerfHistory instance owned by the render
// process host, and is used by workers via BrowserInterfaceBroker.
void BindVideoDecodePerfHistory(
Expand Down
12 changes: 0 additions & 12 deletions content/browser/service_worker/service_worker_provider_host.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,6 @@ void GetInterfaceImpl(const std::string& interface_name,
if (!process)
return;

// RestrictedCookieManager creation is different between frames and service
// workers, so it's handled here.
if (interface_name == network::mojom::RestrictedCookieManager::Name_) {
mojo::PendingReceiver<network::mojom::RestrictedCookieManager> receiver(
std::move(interface_pipe));
process->GetStoragePartition()->CreateRestrictedCookieManager(
network::mojom::RestrictedCookieManagerRole::SCRIPT, origin,
origin.GetURL(), origin, true /* is_service_worker */, process_id,
MSG_ROUTING_NONE, std::move(receiver));
return;
}

BindWorkerInterface(interface_name, std::move(interface_pipe), process,
origin);
}
Expand Down
4 changes: 1 addition & 3 deletions content/public/app/content_browser_manifest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,7 @@ const service_manager::Manifest& GetContentBrowserManifest() {
.ExposeInterfaceFilterCapability_Deprecated(
"navigation:service_worker", "renderer",
std::set<const char*>{
"blink.mojom.QuotaDispatcherHost",
"network.mojom.RestrictedCookieManager"})
"blink.mojom.QuotaDispatcherHost"})
.ExposeInterfaceFilterCapability_Deprecated(
"navigation:frame", "renderer",
std::set<const char*>{
Expand All @@ -188,7 +187,6 @@ const service_manager::Manifest& GetContentBrowserManifest() {
"content.mojom.RendererAudioInputStreamFactory",
"content.mojom.RendererAudioOutputStreamFactory",
"discardable_memory.mojom.DiscardableSharedMemoryManager",
"network.mojom.RestrictedCookieManager",
"viz.mojom.Gpu"})
.PackageService(content::GetManifest())
.Build()};
Expand Down
5 changes: 5 additions & 0 deletions content/public/browser/render_process_host.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "net/base/network_isolation_key.h"
#include "services/network/public/mojom/cross_origin_embedder_policy.mojom-forward.h"
#include "services/network/public/mojom/network_context.mojom-forward.h"
#include "services/network/public/mojom/restricted_cookie_manager.mojom-forward.h"
#include "services/network/public/mojom/url_loader_factory.mojom-forward.h"
#include "third_party/blink/public/mojom/appcache/appcache.mojom.h"
#include "third_party/blink/public/mojom/cache_storage/cache_storage.mojom-forward.h"
Expand Down Expand Up @@ -511,6 +512,10 @@ class CONTENT_EXPORT RenderProcessHost : public IPC::Sender,
int render_frame_id,
const url::Origin& origin,
mojo::PendingReceiver<blink::mojom::IDBFactory> receiver) = 0;
virtual void BindRestrictedCookieManagerForServiceWorker(
const url::Origin& origin,
mojo::PendingReceiver<network::mojom::RestrictedCookieManager>
receiver) = 0;
virtual void BindVideoDecodePerfHistory(
mojo::PendingReceiver<media::mojom::VideoDecodePerfHistory> receiver) = 0;
virtual void CreateLockManager(
Expand Down
4 changes: 4 additions & 0 deletions content/public/test/mock_render_process_host.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,10 @@ class MockRenderProcessHost : public RenderProcessHost {
int render_frame_id,
const url::Origin& origin,
mojo::PendingReceiver<blink::mojom::IDBFactory> receiver) override;
void BindRestrictedCookieManagerForServiceWorker(
const url::Origin& origin,
mojo::PendingReceiver<network::mojom::RestrictedCookieManager> receiver)
override {}
void BindVideoDecodePerfHistory(
mojo::PendingReceiver<media::mojom::VideoDecodePerfHistory> receiver)
override {}
Expand Down
4 changes: 2 additions & 2 deletions third_party/blink/renderer/core/loader/cookie_jar.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include "third_party/blink/renderer/core/loader/cookie_jar.h"

#include "services/service_manager/public/cpp/interface_provider.h"
#include "third_party/blink/public/common/browser_interface_broker_proxy.h"
#include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/platform/instrumentation/histogram.h"
#include "third_party/blink/renderer/platform/weborigin/kurl.h"
Expand Down Expand Up @@ -54,7 +54,7 @@ bool CookieJar::CookiesEnabled() {
void CookieJar::RequestRestrictedCookieManagerIfNeeded() {
if (!backend_.is_bound() || !backend_.is_connected()) {
backend_.reset();
document_->GetInterfaceProvider()->GetInterface(
document_->GetBrowserInterfaceBroker().GetInterface(
backend_.BindNewPipeAndPassReceiver());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <utility>

#include "services/network/public/mojom/restricted_cookie_manager.mojom-blink.h"
#include "services/service_manager/public/cpp/interface_provider.h"
#include "third_party/blink/public/common/browser_interface_broker_proxy.h"
#include "third_party/blink/renderer/core/execution_context/execution_context.h"
#include "third_party/blink/renderer/core/frame/local_dom_window.h"
#include "third_party/blink/renderer/core/frame/local_frame.h"
Expand Down Expand Up @@ -46,15 +46,13 @@ class GlobalCookieStoreImpl final
CookieStore* GetCookieStore(T& scope) {
if (!cookie_store_) {
ExecutionContext* execution_context = scope.GetExecutionContext();

service_manager::InterfaceProvider* interface_provider =
execution_context->GetInterfaceProvider();
if (!interface_provider)
if (!execution_context->GetInterfaceProvider())
return nullptr;

mojo::Remote<network::mojom::blink::RestrictedCookieManager> backend;
interface_provider->GetInterface(backend.BindNewPipeAndPassReceiver(
execution_context->GetTaskRunner(TaskType::kMiscPlatformAPI)));
execution_context->GetBrowserInterfaceBroker().GetInterface(
backend.BindNewPipeAndPassReceiver(
execution_context->GetTaskRunner(TaskType::kMiscPlatformAPI)));
cookie_store_ = MakeGarbageCollected<CookieStore>(execution_context,
std::move(backend));
}
Expand Down

0 comments on commit 58d0b6c

Please sign in to comment.