Clean up around content settings proxies for shared workers and service workers.

1. Remove origin parameter from mojo args
Both of SharedWorkerHost and EmbeddedWorkerInstance already have origin,
so WorkerContentSettingsProxy does not have to pass this parametor via mojo.

2. Let workers' host have content settings proxy on browser side
Make worker host have content settings proxy as member in order to
strongly associate the life time of content settings proxies to worker host.

Bug: 754182
Change-Id: I01c5ce967d5bfffa48f0c8a88fb2f56509f3cbcd
Reviewed-on: https://chromium-review.googlesource.com/615282
Commit-Queue: Yuki Yamada <yukiy@google.com>
Reviewed-by: Matt Falkenhagen <falken@chromium.org>
Reviewed-by: Makoto Shimazu <shimazu@chromium.org>
Reviewed-by: Kinuko Yasuda <kinuko@chromium.org>
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Reviewed-by: Hiroki Nakagawa <nhiroki@chromium.org>
Cr-Original-Commit-Position: refs/heads/master@{#495151}
Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src
Cr-Mirrored-Commit: bc1f43afe311480426fe8b98e8534fe79fe3db00
diff --git a/WebKit/Source/core/exported/WebSharedWorkerImpl.cpp b/WebKit/Source/core/exported/WebSharedWorkerImpl.cpp
index eb007a9..396a43d 100644
--- a/WebKit/Source/core/exported/WebSharedWorkerImpl.cpp
+++ b/WebKit/Source/core/exported/WebSharedWorkerImpl.cpp
@@ -279,7 +279,7 @@
 
   ProvideContentSettingsClientToWorker(
       worker_clients, WTF::MakeUnique<SharedWorkerContentSettingsProxy>(
-                          starter_origin, std::move(content_settings_info_)));
+                          std::move(content_settings_info_)));
 
   if (RuntimeEnabledFeatures::OffMainThreadFetchEnabled()) {
     std::unique_ptr<WebWorkerFetchContext> web_worker_fetch_context =
diff --git a/WebKit/Source/core/workers/SharedWorkerContentSettingsProxy.cpp b/WebKit/Source/core/workers/SharedWorkerContentSettingsProxy.cpp
index edfa80b..f55b58b 100644
--- a/WebKit/Source/core/workers/SharedWorkerContentSettingsProxy.cpp
+++ b/WebKit/Source/core/workers/SharedWorkerContentSettingsProxy.cpp
@@ -10,39 +10,37 @@
 namespace blink {
 
 SharedWorkerContentSettingsProxy::SharedWorkerContentSettingsProxy(
-    SecurityOrigin* security_origin,
     mojom::blink::WorkerContentSettingsProxyPtrInfo host_info)
-    : security_origin_(security_origin->IsolatedCopy()),
-      host_info_(std::move(host_info)) {}
+    : host_info_(std::move(host_info)) {}
 SharedWorkerContentSettingsProxy::~SharedWorkerContentSettingsProxy() = default;
 
 bool SharedWorkerContentSettingsProxy::AllowIndexedDB(
     const WebString& name,
     const WebSecurityOrigin& origin) {
   bool result = false;
-  GetService()->AllowIndexedDB(security_origin_, name, &result);
+  GetService()->AllowIndexedDB(name, &result);
   return result;
 }
 
 bool SharedWorkerContentSettingsProxy::RequestFileSystemAccessSync() {
   bool result = false;
-  GetService()->RequestFileSystemAccessSync(security_origin_, &result);
+  GetService()->RequestFileSystemAccessSync(&result);
   return result;
 }
 
-// Use ThreadSpecific to ensure that |content_setting_instance_host| is
+// Use ThreadSpecific to ensure that |content_settings_instance_host| is
 // destructed on worker thread.
 // Each worker has a dedicated thread so this is safe.
 mojom::blink::WorkerContentSettingsProxyPtr&
 SharedWorkerContentSettingsProxy::GetService() {
   DEFINE_THREAD_SAFE_STATIC_LOCAL(
       ThreadSpecific<mojom::blink::WorkerContentSettingsProxyPtr>,
-      content_setting_instance_host, ());
-  if (!content_setting_instance_host.IsSet()) {
+      content_settings_instance_host, ());
+  if (!content_settings_instance_host.IsSet()) {
     DCHECK(host_info_.is_valid());
-    content_setting_instance_host->Bind(std::move(host_info_));
+    content_settings_instance_host->Bind(std::move(host_info_));
   }
-  return *content_setting_instance_host;
+  return *content_settings_instance_host;
 }
 
 }  // namespace blink
diff --git a/WebKit/Source/core/workers/SharedWorkerContentSettingsProxy.h b/WebKit/Source/core/workers/SharedWorkerContentSettingsProxy.h
index 8f2b7e1..e92eedb 100644
--- a/WebKit/Source/core/workers/SharedWorkerContentSettingsProxy.h
+++ b/WebKit/Source/core/workers/SharedWorkerContentSettingsProxy.h
@@ -14,11 +14,10 @@
 
 // SharedWorkerContentSettingsProxy provides content settings information.
 // This is created on the main thread and then called on the worker thread.
-// Each information is requested via a Mojo connection to the browser process.
+// Information is requested via a Mojo connection to the browser process.
 class SharedWorkerContentSettingsProxy : public WebContentSettingsClient {
  public:
   SharedWorkerContentSettingsProxy(
-      SecurityOrigin*,
       mojom::blink::WorkerContentSettingsProxyPtrInfo host_info);
   ~SharedWorkerContentSettingsProxy() override;
 
@@ -31,10 +30,8 @@
   // that it was constructed on, this uses ThreadSpecific.
   mojom::blink::WorkerContentSettingsProxyPtr& GetService();
 
-  const RefPtr<blink::SecurityOrigin> security_origin_;
-
   // This is set on the main thread at the ctor,
-  // and moved to a thread localstorage on the worker thread
+  // and moved to thread local storage on the worker thread
   // when GetService() is called for the first time.
   mojom::blink::WorkerContentSettingsProxyPtrInfo host_info_;
 };
diff --git a/WebKit/Source/modules/exported/WebEmbeddedWorkerImpl.cpp b/WebKit/Source/modules/exported/WebEmbeddedWorkerImpl.cpp
index 50bc156..c1223a4 100644
--- a/WebKit/Source/modules/exported/WebEmbeddedWorkerImpl.cpp
+++ b/WebKit/Source/modules/exported/WebEmbeddedWorkerImpl.cpp
@@ -139,9 +139,6 @@
   WebSettings* settings = shadow_page_->GetSettings();
   settings->SetDataSaverEnabled(worker_start_data_.data_saver_enabled);
 
-  content_settings_client_->SetSecurityOrigin(
-      SecurityOrigin::Create(script_url));
-
   // Currently we block all mixed-content requests from a ServiceWorker.
   settings->SetStrictMixedContentChecking(true);
   settings->SetAllowRunningOfInsecureContent(false);
diff --git a/WebKit/Source/modules/serviceworkers/ServiceWorkerContentSettingsProxy.cpp b/WebKit/Source/modules/serviceworkers/ServiceWorkerContentSettingsProxy.cpp
index d9a7edf..1da5ff8 100644
--- a/WebKit/Source/modules/serviceworkers/ServiceWorkerContentSettingsProxy.cpp
+++ b/WebKit/Source/modules/serviceworkers/ServiceWorkerContentSettingsProxy.cpp
@@ -16,12 +16,6 @@
 ServiceWorkerContentSettingsProxy::~ServiceWorkerContentSettingsProxy() =
     default;
 
-void ServiceWorkerContentSettingsProxy::SetSecurityOrigin(
-    RefPtr<blink::SecurityOrigin> security_origin) {
-  DCHECK(!security_origin_);
-  security_origin_ = security_origin->IsolatedCopy();
-}
-
 bool ServiceWorkerContentSettingsProxy::RequestFileSystemAccessSync() {
   NOTREACHED();
   return false;
@@ -31,23 +25,23 @@
     const blink::WebString& name,
     const blink::WebSecurityOrigin&) {
   bool result = false;
-  GetService()->AllowIndexedDB(security_origin_, name, &result);
+  GetService()->AllowIndexedDB(name, &result);
   return result;
 }
 
-// Use ThreadSpecific to ensure that |content_setting_instance_host| is
+// Use ThreadSpecific to ensure that |content_settings_instance_host| is
 // destructed on worker thread.
 // Each worker has a dedicated thread so this is safe.
 mojom::blink::WorkerContentSettingsProxyPtr&
 ServiceWorkerContentSettingsProxy::GetService() {
   DEFINE_THREAD_SAFE_STATIC_LOCAL(
       ThreadSpecific<mojom::blink::WorkerContentSettingsProxyPtr>,
-      content_setting_instance_host, ());
-  if (!content_setting_instance_host.IsSet()) {
+      content_settings_instance_host, ());
+  if (!content_settings_instance_host.IsSet()) {
     DCHECK(host_info_.is_valid());
-    content_setting_instance_host->Bind(std::move(host_info_));
+    content_settings_instance_host->Bind(std::move(host_info_));
   }
-  return *content_setting_instance_host;
+  return *content_settings_instance_host;
 }
 
 }  // namespace blink
diff --git a/WebKit/Source/modules/serviceworkers/ServiceWorkerContentSettingsProxy.h b/WebKit/Source/modules/serviceworkers/ServiceWorkerContentSettingsProxy.h
index 021875d..27fe646 100644
--- a/WebKit/Source/modules/serviceworkers/ServiceWorkerContentSettingsProxy.h
+++ b/WebKit/Source/modules/serviceworkers/ServiceWorkerContentSettingsProxy.h
@@ -36,12 +36,10 @@
   mojom::blink::WorkerContentSettingsProxyPtr& GetService();
 
   // This is set on the main thread at the ctor,
-  // and moved to a thread local storage on the worker thread
+  // and moved to thread local storage on the worker thread
   // when GetService() is called for the first time.
   mojom::blink::WorkerContentSettingsProxyPtrInfo host_info_;
 
-  RefPtr<blink::SecurityOrigin> security_origin_;
-
   DISALLOW_COPY_AND_ASSIGN(ServiceWorkerContentSettingsProxy);
 };
 
diff --git a/WebKit/public/web/worker_content_settings_proxy.mojom b/WebKit/public/web/worker_content_settings_proxy.mojom
index 6ed005e..69c9b32e 100644
--- a/WebKit/public/web/worker_content_settings_proxy.mojom
+++ b/WebKit/public/web/worker_content_settings_proxy.mojom
@@ -15,14 +15,10 @@
 interface WorkerContentSettingsProxy {
 
   // Returns whether the worker is allowed access to IndexedDB.
-  // TODO(yukiy): remove |origin| from AllowIndexedDB() and
-  // RequestFileSystemAccessSync(), and instead, keep it on the browser process.
   [Sync]
-  AllowIndexedDB(url.mojom.Origin origin, mojo.common.mojom.String16 name)
-    => (bool result);
+  AllowIndexedDB(mojo.common.mojom.String16 name) => (bool result);
 
   // Returns whether the worker is allowed access to the file system.
   [Sync]
-  RequestFileSystemAccessSync(url.mojom.Origin origin)
-    => (bool result);
+  RequestFileSystemAccessSync() => (bool result);
 };