Commit ca3a0bee authored by Hiroki Nakagawa's avatar Hiroki Nakagawa Committed by Commit Bot

WebSocket: Clean up WebSocket creation

This is just a cleanup and doesn't change behavior.

Bug: 825740
Change-Id: I36c4002ca29bd3ad5af1a8f63ef2b33e6b977981
Reviewed-on: https://chromium-review.googlesource.com/1027370Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Reviewed-by: default avatarYutaka Hirano <yhirano@chromium.org>
Commit-Queue: Hiroki Nakagawa <nhiroki@chromium.org>
Cr-Commit-Position: refs/heads/master@{#553485}
parent e035dc12
...@@ -4581,21 +4581,11 @@ void RenderFrameHostImpl::BindMediaInterfaceFactoryRequest( ...@@ -4581,21 +4581,11 @@ void RenderFrameHostImpl::BindMediaInterfaceFactoryRequest(
void RenderFrameHostImpl::CreateWebSocket( void RenderFrameHostImpl::CreateWebSocket(
network::mojom::WebSocketRequest request) { network::mojom::WebSocketRequest request) {
if (base::FeatureList::IsEnabled(network::features::kNetworkService)) { // This is to support usage of WebSockets in cases in which there is an
auto* context = GetSiteInstance()->GetBrowserContext(); // associated RenderFrame. This is important for showing the correct security
auto* storage_partition = static_cast<StoragePartitionImpl*>( // state of the page and also honoring user override of bad certificates.
BrowserContext::GetStoragePartition(context, GetSiteInstance())); WebSocketManager::CreateWebSocket(process_->GetID(), routing_id_,
storage_partition->GetNetworkContext()->CreateWebSocket( last_committed_origin_, std::move(request));
std::move(request), process_->GetID(), routing_id_,
last_committed_origin_);
} else {
// This is to support usage of WebSockets in cases in which there is an
// associated RenderFrame. This is important for showing the correct
// security state of the page and also honoring user override of bad
// certificates.
WebSocketManager::CreateWebSocketForFrame(process_->GetID(), routing_id_,
std::move(request));
}
} }
void RenderFrameHostImpl::OnMediaInterfaceFactoryConnectionError() { void RenderFrameHostImpl::OnMediaInterfaceFactoryConnectionError() {
......
...@@ -1195,7 +1195,7 @@ class CONTENT_EXPORT RenderFrameHostImpl ...@@ -1195,7 +1195,7 @@ class CONTENT_EXPORT RenderFrameHostImpl
// RenderFrameHost owns its RenderViewHost. // RenderFrameHost owns its RenderViewHost.
RenderWidgetHostImpl* render_widget_host_; RenderWidgetHostImpl* render_widget_host_;
int routing_id_; const int routing_id_;
// Boolean indicating whether this RenderFrameHost is being actively used or // Boolean indicating whether this RenderFrameHost is being actively used or
// is waiting for FrameHostMsg_SwapOut_ACK and thus pending deletion. // is waiting for FrameHostMsg_SwapOut_ACK and thus pending deletion.
......
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
#include <utility> #include <utility>
#include "base/bind.h" #include "base/bind.h"
#include "base/feature_list.h"
#include "content/browser/background_fetch/background_fetch_service_impl.h" #include "content/browser/background_fetch/background_fetch_service_impl.h"
#include "content/browser/dedicated_worker/dedicated_worker_host.h" #include "content/browser/dedicated_worker/dedicated_worker_host.h"
#include "content/browser/locks/lock_manager.h" #include "content/browser/locks/lock_manager.h"
...@@ -26,7 +25,6 @@ ...@@ -26,7 +25,6 @@
#include "content/public/common/content_switches.h" #include "content/public/common/content_switches.h"
#include "services/device/public/mojom/constants.mojom.h" #include "services/device/public/mojom/constants.mojom.h"
#include "services/device/public/mojom/vibration_manager.mojom.h" #include "services/device/public/mojom/vibration_manager.mojom.h"
#include "services/network/public/cpp/features.h"
#include "services/network/restricted_cookie_manager.h" #include "services/network/restricted_cookie_manager.h"
#include "services/service_manager/public/cpp/binder_registry.h" #include "services/service_manager/public/cpp/binder_registry.h"
#include "services/service_manager/public/cpp/connector.h" #include "services/service_manager/public/cpp/connector.h"
...@@ -187,16 +185,8 @@ void RendererInterfaceBinders::CreateWebSocket( ...@@ -187,16 +185,8 @@ void RendererInterfaceBinders::CreateWebSocket(
network::mojom::WebSocketRequest request, network::mojom::WebSocketRequest request,
RenderProcessHost* host, RenderProcessHost* host,
const url::Origin& origin) { const url::Origin& origin) {
if (base::FeatureList::IsEnabled(network::features::kNetworkService)) { WebSocketManager::CreateWebSocket(host->GetID(), MSG_ROUTING_NONE, origin,
StoragePartition* storage_partition = host->GetStoragePartition(); std::move(request));
network::mojom::NetworkContext* network_context =
storage_partition->GetNetworkContext();
network_context->CreateWebSocket(std::move(request), host->GetID(),
MSG_ROUTING_NONE, origin);
} else {
WebSocketManager::CreateWebSocketWithOrigin(
host->GetID(), origin, std::move(request), MSG_ROUTING_NONE);
}
} }
} // namespace } // namespace
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include <vector> #include <vector>
#include "base/callback.h" #include "base/callback.h"
#include "base/feature_list.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
...@@ -23,6 +24,8 @@ ...@@ -23,6 +24,8 @@
#include "content/public/browser/render_process_host.h" #include "content/public/browser/render_process_host.h"
#include "content/public/browser/render_process_host_observer.h" #include "content/public/browser/render_process_host_observer.h"
#include "content/public/browser/storage_partition.h" #include "content/public/browser/storage_partition.h"
#include "services/network/network_context.h"
#include "services/network/public/cpp/features.h"
namespace content { namespace content {
...@@ -157,31 +160,25 @@ class WebSocketManager::Handle : public base::SupportsUserData::Data, ...@@ -157,31 +160,25 @@ class WebSocketManager::Handle : public base::SupportsUserData::Data,
}; };
// static // static
void WebSocketManager::CreateWebSocketForFrame( void WebSocketManager::CreateWebSocket(
int process_id, int process_id,
int frame_id, int frame_id,
network::mojom::WebSocketRequest request) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
// ForFrame() implies a frame: DCHECK this pre-condition.
RenderFrameHost* frame = RenderFrameHost::FromID(process_id, frame_id);
DCHECK(frame);
CreateWebSocketWithOrigin(process_id, frame->GetLastCommittedOrigin(),
std::move(request), frame_id);
}
// static
void WebSocketManager::CreateWebSocketWithOrigin(
int process_id,
url::Origin origin, url::Origin origin,
network::mojom::WebSocketRequest request, network::mojom::WebSocketRequest request) {
int frame_id) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
RenderProcessHost* host = RenderProcessHost::FromID(process_id); RenderProcessHost* host = RenderProcessHost::FromID(process_id);
DCHECK(host); DCHECK(host);
if (base::FeatureList::IsEnabled(network::features::kNetworkService)) {
StoragePartition* storage_partition = host->GetStoragePartition();
network::mojom::NetworkContext* network_context =
storage_partition->GetNetworkContext();
network_context->CreateWebSocket(std::move(request), process_id, frame_id,
origin);
return;
}
// Maintain a WebSocketManager per RenderProcessHost. While the instance of // Maintain a WebSocketManager per RenderProcessHost. While the instance of
// WebSocketManager is allocated on the UI thread, it must only be used and // WebSocketManager is allocated on the UI thread, it must only be used and
// deleted from the IO thread. // deleted from the IO thread.
......
...@@ -29,18 +29,15 @@ class StoragePartition; ...@@ -29,18 +29,15 @@ class StoragePartition;
class CONTENT_EXPORT WebSocketManager class CONTENT_EXPORT WebSocketManager
: public net::URLRequestContextGetterObserver { : public net::URLRequestContextGetterObserver {
public: public:
// Called on the UI thread: create a websocket for a frame. // Called on the UI thread: create a websocket.
static void CreateWebSocketForFrame(int process_id, // - For frames, |frame_id| should be their own id.
int frame_id, // - For dedicated workers, |frame_id| should be its parent frame's id.
network::mojom::WebSocketRequest request); // - For shared workers and service workers, |frame_id| should be
// MSG_ROUTING_NONE because they do not have a frame.
// Called on the UI thread: create a websocket for a worker. Web workers of static void CreateWebSocket(int process_id,
// any type (dedicated, shared, service worker) do not have a frame. int frame_id,
static void CreateWebSocketWithOrigin( url::Origin origin,
int process_id, network::mojom::WebSocketRequest request);
url::Origin origin,
network::mojom::WebSocketRequest request,
int frame_id = MSG_ROUTING_NONE);
// net::URLRequestContextGetterObserver implementation. // net::URLRequestContextGetterObserver implementation.
void OnContextShuttingDown() override; void OnContextShuttingDown() override;
......
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