summaryrefslogtreecommitdiff
path: root/chromium/content/browser/dedicated_worker/dedicated_worker_host.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/content/browser/dedicated_worker/dedicated_worker_host.cc')
-rw-r--r--chromium/content/browser/dedicated_worker/dedicated_worker_host.cc57
1 files changed, 44 insertions, 13 deletions
diff --git a/chromium/content/browser/dedicated_worker/dedicated_worker_host.cc b/chromium/content/browser/dedicated_worker/dedicated_worker_host.cc
index 86b2b534245..7eccbe6db70 100644
--- a/chromium/content/browser/dedicated_worker/dedicated_worker_host.cc
+++ b/chromium/content/browser/dedicated_worker/dedicated_worker_host.cc
@@ -11,6 +11,7 @@
#include "content/browser/interface_provider_filtering.h"
#include "content/browser/renderer_interface_binders.h"
#include "content/browser/websockets/websocket_manager.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"
#include "mojo/public/cpp/system/message_pipe.h"
@@ -27,10 +28,10 @@ namespace {
class DedicatedWorkerHost : public service_manager::mojom::InterfaceProvider {
public:
DedicatedWorkerHost(int process_id,
- int parent_render_frame_id,
+ int ancestor_render_frame_id,
const url::Origin& origin)
: process_id_(process_id),
- parent_render_frame_id_(parent_render_frame_id),
+ ancestor_render_frame_id_(ancestor_render_frame_id),
origin_(origin) {
RegisterMojoInterfaces();
}
@@ -53,22 +54,52 @@ class DedicatedWorkerHost : public service_manager::mojom::InterfaceProvider {
private:
void RegisterMojoInterfaces() {
- registry_.AddInterface(
- base::BindRepeating(&WebSocketManager::CreateWebSocket, process_id_,
- parent_render_frame_id_, origin_));
+ registry_.AddInterface(base::BindRepeating(
+ &DedicatedWorkerHost::CreateWebSocket, base::Unretained(this)));
registry_.AddInterface(base::BindRepeating(
&DedicatedWorkerHost::CreateUsbDeviceManager, base::Unretained(this)));
+ registry_.AddInterface(base::BindRepeating(
+ &DedicatedWorkerHost::CreateDedicatedWorker, base::Unretained(this)));
}
void CreateUsbDeviceManager(device::mojom::UsbDeviceManagerRequest request) {
auto* host =
- RenderFrameHostImpl::FromID(process_id_, parent_render_frame_id_);
+ RenderFrameHostImpl::FromID(process_id_, ancestor_render_frame_id_);
GetContentClient()->browser()->CreateUsbDeviceManager(host,
std::move(request));
}
+ void CreateWebSocket(network::mojom::WebSocketRequest request) {
+ network::mojom::AuthenticationHandlerPtr auth_handler;
+ auto* frame =
+ RenderFrameHost::FromID(process_id_, ancestor_render_frame_id_);
+ if (!frame) {
+ // In some cases |frame| can be null. In such cases the worker will
+ // soon be terminated too, so let's abort the connection.
+ request.ResetWithReason(network::mojom::WebSocket::kInsufficientResources,
+ "The parent frame has already been gone.");
+ return;
+ }
+
+ GetContentClient()->browser()->WillCreateWebSocket(frame, &request,
+ &auth_handler);
+
+ WebSocketManager::CreateWebSocket(process_id_, ancestor_render_frame_id_,
+ origin_, std::move(auth_handler),
+ std::move(request));
+ }
+
+ void CreateDedicatedWorker(
+ blink::mojom::DedicatedWorkerFactoryRequest request) {
+ CreateDedicatedWorkerHostFactory(process_id_, ancestor_render_frame_id_,
+ origin_, std::move(request));
+ }
+
const int process_id_;
- const int parent_render_frame_id_;
+ // ancestor_render_frame_id_ is the id of the frame that owns this worker,
+ // either directly, or (in the case of nested workers) indirectly via a tree
+ // of dedicated workers.
+ const int ancestor_render_frame_id_;
const url::Origin origin_;
service_manager::BinderRegistry registry_;
@@ -81,10 +112,10 @@ class DedicatedWorkerHost : public service_manager::mojom::InterfaceProvider {
class DedicatedWorkerFactoryImpl : public blink::mojom::DedicatedWorkerFactory {
public:
DedicatedWorkerFactoryImpl(int process_id,
- int parent_render_frame_id,
+ int ancestor_render_frame_id,
const url::Origin& parent_context_origin)
: process_id_(process_id),
- parent_render_frame_id_(parent_render_frame_id),
+ ancestor_render_frame_id_(ancestor_render_frame_id),
parent_context_origin_(parent_context_origin) {}
// blink::mojom::DedicatedWorkerFactory:
@@ -95,7 +126,7 @@ class DedicatedWorkerFactoryImpl : public blink::mojom::DedicatedWorkerFactory {
// with the request for |DedicatedWorkerFactory|, enforce that the worker's
// origin either matches the creating document's origin, or is unique.
mojo::MakeStrongBinding(std::make_unique<DedicatedWorkerHost>(
- process_id_, parent_render_frame_id_, origin),
+ process_id_, ancestor_render_frame_id_, origin),
FilterRendererExposedInterfaces(
blink::mojom::kNavigation_DedicatedWorkerSpec,
process_id_, std::move(request)));
@@ -103,7 +134,7 @@ class DedicatedWorkerFactoryImpl : public blink::mojom::DedicatedWorkerFactory {
private:
const int process_id_;
- const int parent_render_frame_id_;
+ const int ancestor_render_frame_id_;
const url::Origin parent_context_origin_;
DISALLOW_COPY_AND_ASSIGN(DedicatedWorkerFactoryImpl);
@@ -113,11 +144,11 @@ class DedicatedWorkerFactoryImpl : public blink::mojom::DedicatedWorkerFactory {
void CreateDedicatedWorkerHostFactory(
int process_id,
- int parent_render_frame_id,
+ int ancestor_render_frame_id,
const url::Origin& origin,
blink::mojom::DedicatedWorkerFactoryRequest request) {
mojo::MakeStrongBinding(std::make_unique<DedicatedWorkerFactoryImpl>(
- process_id, parent_render_frame_id, origin),
+ process_id, ancestor_render_frame_id, origin),
std::move(request));
}