[M85 Migration] Implement SharedURLLoaderFactoryEfl 17/246217/2
authorGajendra N <gajendra.n@samsung.com>
Thu, 15 Oct 2020 10:58:13 +0000 (16:28 +0530)
committerBot Blink <blinkbot@samsung.com>
Mon, 2 Nov 2020 11:57:21 +0000 (11:57 +0000)
On upstream Chromium, geolocation is refactored to use URLLoaderFactory.
GeolocationProviderImpl now dependant on SharedURLLoaderFactory, this
patch ports the same to EFL.

Added files :
shared_url_loader_factory_efl.cc
shared_url_loader_factory_efl.h

Reference:
https://review.tizen.org/gerrit/219507

Change-Id: Ic447a551bf857044627bdfff30976684241ee421
Signed-off-by: Gajendra N <gajendra.n@samsung.com>
(cherry picked from commit 1117d88a3afebe21fa6b830d7b668895ef31b440)

tizen_src/ewk/efl_integration/BUILD.gn
tizen_src/ewk/efl_integration/content_browser_client_efl.cc
tizen_src/ewk/efl_integration/content_browser_client_efl.h
tizen_src/ewk/efl_integration/shared_url_loader_factory_efl.cc [new file with mode: 0644]
tizen_src/ewk/efl_integration/shared_url_loader_factory_efl.h [new file with mode: 0644]

index 669b529..ee7a55d 100644 (file)
@@ -258,6 +258,8 @@ shared_library("chromium-ewk") {
     "popup_controller_efl.h",
     "scroll_detector.cc",
     "scroll_detector.h",
+    "shared_url_loader_factory_efl.cc",
+    "shared_url_loader_factory_efl.h",
     "text_encoding_map_efl.cc",
     "text_encoding_map_efl.h",
     "url_request_context_getter_efl.cc",
index 13b1975..7ba928f 100644 (file)
@@ -26,6 +26,7 @@
 #include "content/public/common/content_switches.h"
 #include "common/version_info.h"
 #include "common/web_contents_utils.h"
+#include "shared_url_loader_factory_efl.h"
 
 #if defined(OS_TIZEN)
 #if !defined(EWK_BRINGUP)
@@ -110,6 +111,15 @@ void ContentBrowserClientEfl::AppendExtraCommandLineSwitches(
   CommandLineEfl::AppendProcessSpecificArgs(*command_line);
 }
 
+scoped_refptr<network::SharedURLLoaderFactory>
+ContentBrowserClientEfl::GetSystemSharedURLLoaderFactory() {
+  DCHECK_CURRENTLY_ON(BrowserThread::UI);
+  if (!shared_url_loader_factory_)
+    shared_url_loader_factory_ = new SharedURLLoaderFactoryEfl();
+
+  return shared_url_loader_factory_;
+}
+
 bool ContentBrowserClientEfl::CanCreateWindow(
     RenderFrameHost* opener,
     const GURL& opener_url,
index e683da1..13823a6 100644 (file)
@@ -22,6 +22,7 @@ class BrowserMainPartsEfl;
 #if defined(ENABLE_NOTIFICATIONS)
 class NotificationControllerEfl;
 #endif
+class SharedURLLoaderFactoryEfl;
 class WebContents;
 class WebContentsView;
 
@@ -111,6 +112,9 @@ class ContentBrowserClientEfl : public ContentBrowserClient {
   std::string GetUserAgent() override;
 
  private:
+  scoped_refptr<network::SharedURLLoaderFactory>
+  GetSystemSharedURLLoaderFactory() override;
+
   static void SetCertificatePemOnUIThread(int render_process_id,
                                           int render_view_id,
                                           std::string certificate);
@@ -125,6 +129,10 @@ class ContentBrowserClientEfl : public ContentBrowserClient {
 
   BrowserContextEfl* browser_context_efl_;
 
+  // URLLoaderFactory backed by the NetworkContext returned by GetContext(), so
+  // consumers don't all need to create their own factory.
+  scoped_refptr<SharedURLLoaderFactoryEfl> shared_url_loader_factory_;
+
   DISALLOW_COPY_AND_ASSIGN(ContentBrowserClientEfl);
 };
 }
diff --git a/tizen_src/ewk/efl_integration/shared_url_loader_factory_efl.cc b/tizen_src/ewk/efl_integration/shared_url_loader_factory_efl.cc
new file mode 100644 (file)
index 0000000..dcadbbe
--- /dev/null
@@ -0,0 +1,78 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Copyright 2019 Samsung Electronics. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "shared_url_loader_factory_efl.h"
+
+#include "content/public/browser/browser_thread.h"
+#include "content/public/browser/network_service_instance.h"
+#include "services/network/public/cpp/cross_thread_pending_shared_url_loader_factory.h"
+
+namespace content {
+
+/* LCOV_EXCL_START */
+network::mojom::NetworkContextParamsPtr CreateNetworkContextParams() {
+  return network::mojom::NetworkContextParams::New();
+}
+
+void SharedURLLoaderFactoryEfl::CreateLoaderAndStart(
+    mojo::PendingReceiver<network::mojom::URLLoader> receiver,
+    int32_t routing_id,
+    int32_t request_id,
+    uint32_t options,
+    const network::ResourceRequest& url_request,
+    mojo::PendingRemote<network::mojom::URLLoaderClient> client,
+    const net::MutableNetworkTrafficAnnotationTag& traffic_annotation) {
+  DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
+  GetURLLoaderFactory()->CreateLoaderAndStart(
+      std::move(receiver), routing_id, request_id, options, url_request,
+      std::move(client), traffic_annotation);
+}
+
+void SharedURLLoaderFactoryEfl::Clone(
+    mojo::PendingReceiver<network::mojom::URLLoaderFactory> receiver) {
+  GetURLLoaderFactory()->Clone(std::move(receiver));
+}
+
+std::unique_ptr<network::PendingSharedURLLoaderFactory>
+SharedURLLoaderFactoryEfl::Clone() {
+  DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
+  return std::make_unique<network::CrossThreadPendingSharedURLLoaderFactory>(
+     this);
+}
+
+network::mojom::NetworkContext* SharedURLLoaderFactoryEfl::GetContext() {
+  if (!network_service_network_context_ ||
+      !network_service_network_context_.is_connected()) {
+    // This should call into OnNetworkServiceCreated(), which will re-create
+    // the network service, if needed. There's a chance that it won't be
+    // invoked, if the NetworkContext has encountered an error but the
+    // NetworkService has not yet noticed its pipe was closed. In that case,
+    // trying to create a new NetworkContext would fail, anyways, and hopefully
+    // a new NetworkContext will be created on the next GetContext() call.
+    content::GetNetworkService();
+    DCHECK(network_service_network_context_);
+  }
+  return network_service_network_context_.get();
+}
+
+network::mojom::URLLoaderFactory*
+SharedURLLoaderFactoryEfl::GetURLLoaderFactory() {
+  if (url_loader_factory_ && url_loader_factory_.is_connected())
+    return url_loader_factory_.get();
+
+  network::mojom::URLLoaderFactoryParamsPtr params =
+      network::mojom::URLLoaderFactoryParams::New();
+  params->process_id = network::mojom::kBrowserProcessId;
+  params->is_corb_enabled = false;
+  params->is_trusted = true;
+
+  url_loader_factory_.reset();
+  GetContext()->CreateURLLoaderFactory(
+      url_loader_factory_.BindNewPipeAndPassReceiver(), std::move(params));
+  return url_loader_factory_.get();
+}
+/* LCOV_EXCL_STOP */
+
+}  // namespace content
diff --git a/tizen_src/ewk/efl_integration/shared_url_loader_factory_efl.h b/tizen_src/ewk/efl_integration/shared_url_loader_factory_efl.h
new file mode 100644 (file)
index 0000000..49db052
--- /dev/null
@@ -0,0 +1,67 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Copyright 2019 Samsung Electronics. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef SHARED_URL_LOADER_FACTORY_EFL_H_
+#define SHARED_URL_LOADER_FACTORY_EFL_H_
+
+#include "base/memory/ref_counted.h"
+#include "services/network/network_context.h"
+#include "services/network/public/cpp/shared_url_loader_factory.h"
+
+namespace network {
+class PendingSharedURLLoaderFactory;
+}
+
+namespace content {
+
+/* LCOV_EXCL_START */
+// SharedURLLoaderFactory its network context. Transparently handles crashes.
+class SharedURLLoaderFactoryEfl : public network::SharedURLLoaderFactory {
+ public:
+  SharedURLLoaderFactoryEfl() {}
+
+  // mojom::URLLoaderFactory implementation:
+  void CreateLoaderAndStart(mojo::PendingReceiver<network::mojom::URLLoader> receiver,
+                            int32_t routing_id,
+                            int32_t request_id,
+                            uint32_t options,
+                            const network::ResourceRequest& url_request,
+                            mojo::PendingRemote<network::mojom::URLLoaderClient> client,
+                            const net::MutableNetworkTrafficAnnotationTag&
+                                traffic_annotation) override;
+
+  // SharedURLLoaderFactory implementation:
+  void Clone(mojo::PendingReceiver<network::mojom::URLLoaderFactory> receiver) override;
+
+  std::unique_ptr<network::PendingSharedURLLoaderFactory> Clone() override;
+
+  // Returns the System NetworkContext. May only be called after SetUp(). Does
+  // any initialization of the NetworkService that may be needed when first
+  // called.
+  network::mojom::NetworkContext* GetContext();
+
+  // Returns a URLLoaderFactory that is backed by the SystemNetworkContext.
+  // Allows sharing of the URLLoaderFactory. Prefer this to creating a new one.
+  // Call Clone() on the value returned by this method to get a URLLoaderFactory
+  // that can be used on other threads.
+  network::mojom::URLLoaderFactory* GetURLLoaderFactory();
+
+ private:
+  friend class base::RefCounted<SharedURLLoaderFactoryEfl>;
+  ~SharedURLLoaderFactoryEfl() override = default;
+
+  // NetworkContext using the network service, if the network service is
+  // enabled. mojo::NullRemote(), otherwise.
+  mojo::Remote<network::mojom::NetworkContext> network_service_network_context_;
+
+  mojo::Remote<network::mojom::URLLoaderFactory> url_loader_factory_;
+
+  DISALLOW_COPY_AND_ASSIGN(SharedURLLoaderFactoryEfl);
+};
+/* LCOV_EXCL_STOP */
+
+}  // namespace content
+
+#endif