Refactor async window creation feature to avoid chromium modifications.
authorPiotr Tworek <p.tworek@samsung.com>
Fri, 24 Apr 2015 13:27:31 +0000 (15:27 +0200)
committerYoungsoo Choi <kenshin.choi@samsung.com>
Tue, 10 Jul 2018 06:57:09 +0000 (06:57 +0000)
The goal is to competely get rid of chromium src patch and contain the
feature entirely in tizen_src. To do this we need to create our own
custom WebContentsDelegate class only used by EFL implementation of
WebContentsImpl. Additionally we can no longer use WebContents::Create
call to instantiate the class. Instead, a direct call to
WebContentsImplEfl constructor followed by Init call has to be used.
This makes EWK usage of content API a bit non standard, but allows us to
get by without any modifications to the upstream code.

Change-Id: I2f1397842e7194afc331514986d12b13705af71c
Signed-off-by: Piotr Tworek <p.tworek@samsung.com>
14 files changed:
tizen_src/chromium_impl/content/browser/web_contents/web_contents_impl_efl.cc
tizen_src/chromium_impl/content/browser/web_contents/web_contents_impl_efl.h
tizen_src/chromium_impl/content/content_efl.gypi
tizen_src/chromium_impl/content/public/browser/web_contents_delegate_efl.cc [deleted file]
tizen_src/chromium_impl/content/public/browser/web_contents_efl_delegate.h [new file with mode: 0644]
tizen_src/ewk/efl_integration/efl_integration.gypi
tizen_src/ewk/efl_integration/eweb_view.cc
tizen_src/ewk/efl_integration/eweb_view.h
tizen_src/ewk/efl_integration/private/ewk_policy_decision_private.cc
tizen_src/ewk/efl_integration/private/ewk_policy_decision_private.h
tizen_src/ewk/efl_integration/web_contents_delegate_efl.cc
tizen_src/ewk/efl_integration/web_contents_delegate_efl.h
tizen_src/ewk/efl_integration/web_contents_efl_delegate_ewk.cc [new file with mode: 0644]
tizen_src/ewk/efl_integration/web_contents_efl_delegate_ewk.h [new file with mode: 0644]

index 9d1d6e2..a890ed2 100644 (file)
 #include "content/browser/dom_storage/session_storage_namespace_impl.h"
 #include "content/browser/renderer_host/render_view_host_impl.h"
 #include "content/browser/web_contents/web_contents_view.h"
+#include "content/public/browser/browser_context.h"
 #include "content/public/browser/browser_plugin_guest_manager.h"
 #include "content/public/browser/content_browser_client.h"
-#include "content/public/browser/browser_context.h"
-#include "content/public/browser/web_contents_delegate.h"
-#include "content/public/browser/user_metrics.h"
 #include "content/public/browser/storage_partition.h"
+#include "content/public/browser/user_metrics.h"
+#include "content/public/browser/web_contents_delegate.h"
+#include "content/public/browser/web_contents_efl_delegate.h"
 #include "content/public/common/result_codes.h"
 
 // Majority of the code in this file was taken directly from
 
 namespace content {
 
-WebContentsImpl* WebContentsImpl::CreateWithOpener(
-    const WebContents::CreateParams& params,
-    WebContentsImpl* opener) {
-  TRACE_EVENT0("browser", "WebContentsImpl::CreateWithOpener");
-  // XXX: Compared to original this one creates WebContentsImplEfl
-  WebContentsImpl* new_contents = new WebContentsImplEfl(
-      params.browser_context, opener, params.platform_data);
-
-  new_contents->Init(params);
-  return new_contents;
-}
-
-WebContents* WebContents::CreateWithSessionStorage(
-    const WebContents::CreateParams& params,
-    const SessionStorageNamespaceMap& session_storage_namespace_map) {
-  // XXX: Compared to original this one creates WebContentsImplEfl
-  WebContentsImpl* new_contents = new WebContentsImplEfl(
-      params.browser_context, NULL, params.platform_data);
-
-  for (SessionStorageNamespaceMap::const_iterator it =
-           session_storage_namespace_map.begin();
-       it != session_storage_namespace_map.end();
-       ++it) {
-    new_contents->GetController()
-        .SetSessionStorageNamespace(it->first, it->second.get());
-  }
-
-  new_contents->Init(params);
-  return new_contents;
-}
-
 WebContentsImplEfl::WebContentsImplEfl(BrowserContext* browser_context,
                                        WebContentsImpl* opener,
                                        void* platform_data)
@@ -102,6 +72,15 @@ WebContentsImplEfl::WebContentsImplEfl(BrowserContext* browser_context,
     , platform_data_(platform_data) {
 }
 
+void WebContentsImplEfl::SetEflDelegate(WebContentsEflDelegate* delegate) {
+  efl_delegate_.reset(delegate);
+}
+
+WebContents* WebContentsImplEfl::Clone() {
+  NOTREACHED() << "Cloning WebContents is not supported in EFL port";
+  return NULL;
+}
+
 void WebContentsImplEfl::CreateNewWindow(
     int render_process_id,
     int route_id,
@@ -159,7 +138,8 @@ void WebContentsImplEfl::CreateNewWindow(
       &WebContentsImplEfl::HandleNewWindowRequest,
       base::Unretained(this), render_process_id, route_id,
       main_frame_route_id, params, ssn);
-  if (delegate_ && delegate_->ShouldCreateWebContentsAsync(callback, params.target_url))
+  if (efl_delegate_ &&
+      efl_delegate_->ShouldCreateWebContentsAsync(callback, params.target_url))
     return;
   // End of EFL port specific code.
 
@@ -209,11 +189,11 @@ void WebContentsImplEfl::HandleNewWindowRequest(
 
   if (create) {
     scoped_refptr<SessionStorageNamespace> ssn = session_storage_namespace;
-    WebContentsDelegate::WebContentsCreateCallback callback = base::Bind(
+    WebContentsEflDelegate::WebContentsCreateCallback callback = base::Bind(
         &WebContentsImplEfl::HandleNewWebContentsCreate,
         base::Unretained(this), render_process_id, route_id,
         main_frame_route_id, params, ssn);
-    if (delegate_ && delegate_->WebContentsCreateAsync(callback))
+    if (efl_delegate_ && efl_delegate_->WebContentsCreateAsync(callback))
       return;
 
     callback.Run(NULL);
@@ -246,7 +226,6 @@ WebContents* WebContentsImplEfl::HandleNewWebContentsCreate(
   create_params.main_frame_routing_id = main_frame_route_id;
   create_params.opener = this;
   create_params.opener_suppressed = params.opener_suppressed;
-  create_params.platform_data = platform_data;
   if (params.disposition == NEW_BACKGROUND_TAB)
     create_params.initially_hidden = true;
 
@@ -266,7 +245,7 @@ WebContents* WebContentsImplEfl::HandleNewWebContentsCreate(
   new_contents->RenderViewCreated(new_contents->GetRenderViewHost());
 
   // Added for EFL port
-  new_contents->SetPlatformData(platform_data);
+  new_contents->platform_data_ = platform_data;
   // Added for EFL port
 
   // Save the window for later if we're not suppressing the opener (since it
index 97e97a2..091d703 100644 (file)
@@ -9,8 +9,15 @@
 
 namespace content {
 
+class WebContentsEflDelegate;
+
 class WebContentsImplEfl : public WebContentsImpl {
  public:
+  // See WebContents::Create for a description of these parameters.
+  WebContentsImplEfl(BrowserContext* browser_context,
+                     WebContentsImpl* opener,
+                     void* platform_data);
+
   void CreateNewWindow(
       int render_process_id,
       int route_id,
@@ -19,7 +26,11 @@ class WebContentsImplEfl : public WebContentsImpl {
       SessionStorageNamespace* session_storage_namespace) override;
 
   void* GetPlatformData() const { return platform_data_; };
-  void SetPlatformData(void* data) { platform_data_ = data; };
+
+  void SetEflDelegate(WebContentsEflDelegate*);
+
+  // Overrides for WebContents
+  WebContents* Clone() override;
 
  private:
   // Needed to access private WebContentsImplEfl constructor from
@@ -27,11 +38,6 @@ class WebContentsImplEfl : public WebContentsImpl {
   friend class WebContentsImpl;
   friend class WebContents;
 
-  // See WebContents::Create for a description of these parameters.
-  WebContentsImplEfl(BrowserContext* browser_context,
-                     WebContentsImpl* opener,
-                     void* ewk_view);
-
   void CancelWindowRequest(
       int render_process_id,
       int route_id,
@@ -51,10 +57,12 @@ class WebContentsImplEfl : public WebContentsImpl {
       int main_frame_route_id,
       const ViewHostMsg_CreateWindow_Params& params,
       SessionStorageNamespace* session_storage_namespace,
-      void* ewk_view);
+      void* platform_data);
 
   void* platform_data_;
 
+  scoped_ptr<WebContentsEflDelegate> efl_delegate_;
+
   DISALLOW_COPY_AND_ASSIGN(WebContentsImplEfl);
 };
 
index 832145c..a7622a9 100644 (file)
           'browser/renderer_host/render_widget_host_view_efl.cc',
           'browser/renderer_host/web_event_factory_efl.h',
           'browser/renderer_host/web_event_factory_efl.cc',
-          'public/browser/web_contents_delegate_efl.cc',
+          'public/browser/web_contents_efl_delegate.h',
           'public/browser/web_contents_view_efl_delegate.h',
         ],
         'sources/': [
diff --git a/tizen_src/chromium_impl/content/public/browser/web_contents_delegate_efl.cc b/tizen_src/chromium_impl/content/public/browser/web_contents_delegate_efl.cc
deleted file mode 100644 (file)
index 209be20..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-// Copyright 2015 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 "content/public/browser/web_contents_delegate.h"
-
-namespace content {
-
-bool WebContentsDelegate::ShouldCreateWebContentsAsync(
-    NewWindowDecideCallback, const GURL&) {
-  return false;
-};
-
-bool WebContentsDelegate::WebContentsCreateAsync(
-    WebContentsCreateCallback) {
-  return false;
-};
-
-} // namespace content
diff --git a/tizen_src/chromium_impl/content/public/browser/web_contents_efl_delegate.h b/tizen_src/chromium_impl/content/public/browser/web_contents_efl_delegate.h
new file mode 100644 (file)
index 0000000..5ded8c7
--- /dev/null
@@ -0,0 +1,49 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CONTENT_PUBLIC_BROWSER_WEB_CONTENTS_EFL_DELEGATE_H_
+#define CONTENT_PUBLIC_BROWSER_WEB_CONTENTS_EFL_DELEGATE_H_
+
+#include "base/callback.h"
+#include "content/common/content_export.h"
+
+class GURL;
+
+namespace content {
+
+class WebContents;
+
+class CONTENT_EXPORT WebContentsEflDelegate {
+ public:
+  // Callback function allowing the embedder to create new web contents object
+  // in an asynchronous manner. The callback takes one opaque parameter
+  // intended to pass platform specific data to WebContents constructor. It
+  // returns a pointer to new WebContents created by the function. The caller
+  // is expected to take ownership of the returned object.
+  typedef base::Callback<WebContents*(void*)> WebContentsCreateCallback;
+
+  // Callback allowing the embedder to resume or block new window request. The
+  // argument specifies if the request should be allowed (true) or blocked
+  // (false).
+  typedef base::Callback<void(bool)> NewWindowDecideCallback;
+
+  // Allows delegate to asynchronously control whether a WebContents should be
+  // created. The function should return true if the implementation intends to
+  // use this functionality. In such case the synchronous version of this
+  // function ShouldCreateWebContents will not be called. The embedder must
+  // call the callback function at some point.
+  virtual bool ShouldCreateWebContentsAsync(NewWindowDecideCallback,
+                                            const GURL&) = 0;
+
+  // Allows the delegate to control new web contents creation in an
+  // asynchronous manner. The function is called with a callback object the
+  // delegate may keep if it wants to delay creation of new web contents. In
+  // such case the function should return true. Returning false means new web
+  // contents creation should be handled in normal, synchronous manner.
+  virtual bool WebContentsCreateAsync(WebContentsCreateCallback) = 0;
+};
+
+} // namespace content
+
+#endif // CONTENT_PUBLIC_BROWSER_WEB_CONTENTS_EFL_DELEGATE_H_
index a15f929..192124e 100644 (file)
       'selection_magnifier_efl.h',
       'url_request_context_getter_efl.cc',
       'url_request_context_getter_efl.h',
+      'web_contents_efl_delegate_ewk.cc',
+      'web_contents_efl_delegate_ewk.h',
       'web_contents_delegate_efl.cc',
       'web_contents_delegate_efl.h',
       'web_contents_view_delegate_ewk.cc',
index ca5aeae..66d9b6d 100644 (file)
@@ -32,6 +32,7 @@
 #include "content/browser/renderer_host/web_event_factory_efl.h"
 #include "content/browser/renderer_host/ui_events_helper.h"
 #include "content/browser/renderer_host/render_view_host_impl.h"
+#include "content/browser/web_contents/web_contents_impl_efl.h"
 #include "content/browser/web_contents/web_contents_view.h"
 #include "content/browser/web_contents/web_contents_view_efl.h"
 #include "content/public/browser/browser_message_filter.h"
@@ -45,6 +46,7 @@
 #include "skia/ext/platform_canvas.h"
 #include "third_party/WebKit/public/web/WebFindOptions.h"
 #include "ui/events/event_switches.h"
+#include "web_contents_efl_delegate_ewk.h"
 #include "web_contents_view_efl_delegate_ewk.h"
 #if defined(OS_TIZEN_MOBILE)
 #include "browser/motion/wkext_motion.h"
@@ -267,7 +269,7 @@ class WebViewUnfocusAllowCallback {
 };
 
 int EWebView::find_request_id_counter_ = 0;
-content::WebContentsDelegate::WebContentsCreateCallback
+content::WebContentsEflDelegate::WebContentsCreateCallback
     EWebView::create_new_window_web_contents_cb_ =
         base::Bind(&NullCreateWebContents);
 
@@ -429,7 +431,7 @@ void EWebView::SetFocus(Eina_Bool focus)
 }
 
 void EWebView::CreateNewWindow(
-    content::WebContentsDelegate::WebContentsCreateCallback cb) {
+    content::WebContentsEflDelegate::WebContentsCreateCallback cb) {
   create_new_window_web_contents_cb_ = cb;
   Evas_Object* new_object = NULL;
   SmartCallback<EWebViewCallbacks::CreateNewWindow>().call(&new_object);
@@ -2180,9 +2182,10 @@ void EWebView::InitializeContent() {
   if (!new_contents) {
     WebContents::CreateParams params(context_->browser_context());
     params.initial_size = gfx::Size(width, height);
-    params.platform_data = this;
-    web_contents_.reset(WebContents::Create(params));
-    LOG(INFO) << "Initial WebContents size: " << params.initial_size.ToString();
+    web_contents_.reset(new WebContentsImplEfl(
+        context_->browser_context(), NULL, this));
+    static_cast<WebContentsImpl*>(web_contents_.get())->Init(params);
+    VLOG(1) << "Initial WebContents size: " << params.initial_size.ToString();
   } else {
     web_contents_.reset(new_contents);
   }
@@ -2190,6 +2193,9 @@ void EWebView::InitializeContent() {
   web_contents_->SetDelegate(web_contents_delegate_.get());
   GetWebContentsViewEfl()->SetEflDelegate(
       new WebContentsViewEflDelegateEwk(this));
+  WebContentsImplEfl* wc_efl = static_cast<WebContentsImplEfl*>(
+      web_contents_.get());
+  wc_efl->SetEflDelegate(new WebContentsEflDelegateEwk(this));
   back_forward_list_.reset(new _Ewk_Back_Forward_List(
       web_contents_->GetController()));
   back_forward_list_.reset(
index ff8ff6f..781235d 100644 (file)
@@ -27,6 +27,7 @@
 #include "content/common/input/input_event_ack_state.h"
 #include "content/public/browser/navigation_controller.h"
 #include "content/public/browser/web_contents_delegate.h"
+#include "content/public/browser/web_contents_efl_delegate.h"
 #include "content/public/common/menu_item.h"
 #include "base/id_map.h"
 #include "context_menu_controller_efl.h"
@@ -215,7 +216,7 @@ class EWebView {
   // call this once after created and before use
   void Initialize();
 
-  void CreateNewWindow(content::WebContentsDelegate::WebContentsCreateCallback);
+  void CreateNewWindow(content::WebContentsEflDelegate::WebContentsCreateCallback);
   static Evas_Object* GetHostWindowDelegate(const content::WebContents*);
 
   tizen_webview::WebView* GetPublicWebView();
@@ -534,7 +535,7 @@ class EWebView {
 
   scoped_ptr<_Ewk_Back_Forward_List> back_forward_list_;
 
-  static content::WebContentsDelegate::WebContentsCreateCallback
+  static content::WebContentsEflDelegate::WebContentsCreateCallback
       create_new_window_web_contents_cb_;
 
 private:
index 6b24a45..ba8276f 100644 (file)
@@ -92,7 +92,7 @@ _Ewk_Policy_Decision::_Ewk_Policy_Decision(const NavigationPolicyParams &params,
 }
 
 _Ewk_Policy_Decision::_Ewk_Policy_Decision(EWebView* view,
-    content::WebContentsDelegate::NewWindowDecideCallback callback)
+    content::WebContentsEflDelegate::NewWindowDecideCallback callback)
   : web_view_(view)
   , window_create_callback_(callback)
   , responseHeaders_(NULL)
index 12afbda..fb41395 100644 (file)
@@ -14,7 +14,7 @@
 #include "base/memory/scoped_ptr.h"
 #include "browser/navigation_policy_handler_efl.h"
 #include "browser/policy_response_delegate_efl.h"
-#include "content/public/browser/web_contents_delegate.h"
+#include "content/public/browser/web_contents_efl_delegate.h"
 #include "content/public/common/resource_type.h"
 #include "public/ewk_policy_decision.h"
 #include "third_party/WebKit/public/web/WebViewModeEnums.h"
@@ -55,7 +55,7 @@ class _Ewk_Policy_Decision {
   * Constructs _Ewk_Policy_Decision with navigation type POLICY_NEWWINDOW
   */
   explicit _Ewk_Policy_Decision(EWebView* view,
-      content::WebContentsDelegate::NewWindowDecideCallback);
+      content::WebContentsEflDelegate::NewWindowDecideCallback);
 
   ~_Ewk_Policy_Decision();
 
@@ -109,7 +109,7 @@ private:
   scoped_refptr<PolicyResponseDelegateEfl> policy_response_delegate_;
   scoped_ptr<NavigationPolicyHandlerEfl> navigation_policy_handler_;
   scoped_ptr<_Ewk_Frame> frame_;
-  content::WebContentsDelegate::NewWindowDecideCallback window_create_callback_;
+  content::WebContentsEflDelegate::NewWindowDecideCallback window_create_callback_;
   std::string cookie_;
   std::string url_;
   std::string httpMethod_;
index c7e9585..be53edc 100644 (file)
@@ -181,29 +181,6 @@ bool WebContentsDelegateEfl::ShouldCreateWebContents(
   return false;
 }
 
-bool WebContentsDelegateEfl::ShouldCreateWebContentsAsync(
-    NewWindowDecideCallback callback, const GURL& target_url) {
-  // this method is called ONLY when creating new window - no matter what type
-  scoped_ptr<_Ewk_Policy_Decision> pd(
-      new _Ewk_Policy_Decision(web_view_, callback));
-  pd->ParseUrl(target_url);
-  web_view_->SmartCallback<EWebViewCallbacks::NewWindowPolicyDecision>().call(pd.get());
-
-  if (pd->isSuspended()) {
-    // it will be deleted later after it's used/ignored/downloaded
-    pd.release();
-  } else if (!pd->isDecided()) {
-    pd->Use();
-  }
-  return true;
-}
-
-bool WebContentsDelegateEfl::WebContentsCreateAsync(
-    WebContentsCreateCallback callback) {
-  web_view_->CreateNewWindow(callback);
-  return true;
-}
-
 void WebContentsDelegateEfl::CloseContents(WebContents* source) {
   web_view_->SmartCallback<EWebViewCallbacks::WindowClosed>().call();
 }
index 183b1b8..caa9df4 100644 (file)
@@ -56,10 +56,6 @@ class WebContentsDelegateEfl
       const std::string& partition_id,
       SessionStorageNamespace* session_storage_namespace) override;
 
-  bool ShouldCreateWebContentsAsync(NewWindowDecideCallback, const GURL&) override;
-
-  bool WebContentsCreateAsync(WebContentsCreateCallback) override;
-
   virtual void CloseContents(WebContents* source) override;
 
   void EnterFullscreenModeForTab(content::WebContents* web_contents,
diff --git a/tizen_src/ewk/efl_integration/web_contents_efl_delegate_ewk.cc b/tizen_src/ewk/efl_integration/web_contents_efl_delegate_ewk.cc
new file mode 100644 (file)
index 0000000..87648fc
--- /dev/null
@@ -0,0 +1,35 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "web_contents_efl_delegate_ewk.h"
+
+#include "eweb_view.h"
+
+WebContentsEflDelegateEwk::WebContentsEflDelegateEwk(EWebView* wv)
+    : web_view_(wv) {
+}
+
+bool WebContentsEflDelegateEwk::ShouldCreateWebContentsAsync(
+    content::WebContentsEflDelegate::NewWindowDecideCallback callback,
+    const GURL& target_url) {
+  // this method is called ONLY when creating new window - no matter what type
+  scoped_ptr<_Ewk_Policy_Decision> pd(
+      new _Ewk_Policy_Decision(web_view_, callback));
+  pd->ParseUrl(target_url);
+  web_view_->SmartCallback<EWebViewCallbacks::NewWindowPolicyDecision>().call(pd.get());
+
+  if (pd->isSuspended()) {
+    // it will be deleted later after it's used/ignored/downloaded
+    pd.release();
+  } else if (!pd->isDecided()) {
+    pd->Use();
+  }
+  return true;
+}
+
+bool WebContentsEflDelegateEwk::WebContentsCreateAsync(
+    content::WebContentsEflDelegate::WebContentsCreateCallback callback) {
+  web_view_->CreateNewWindow(callback);
+  return true;
+}
diff --git a/tizen_src/ewk/efl_integration/web_contents_efl_delegate_ewk.h b/tizen_src/ewk/efl_integration/web_contents_efl_delegate_ewk.h
new file mode 100644 (file)
index 0000000..12de17f
--- /dev/null
@@ -0,0 +1,27 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CONTENT_PUBLIC_BROWSER_WEB_CONTENTS_EFL_DELEGATE_EWK_H_
+#define CONTENT_PUBLIC_BROWSER_WEB_CONTENTS_EFL_DELEGATE_EWK_H_
+
+#include "content/public/browser/web_contents_efl_delegate.h"
+
+class EWebView;
+
+class WebContentsEflDelegateEwk : public content::WebContentsEflDelegate {
+ public:
+  WebContentsEflDelegateEwk(EWebView*);
+
+  bool ShouldCreateWebContentsAsync(
+      NewWindowDecideCallback, const GURL&) override;
+
+  bool WebContentsCreateAsync(WebContentsCreateCallback) override;
+
+ private:
+  EWebView* web_view_;
+
+  DISALLOW_COPY_AND_ASSIGN(WebContentsEflDelegateEwk);
+};
+
+#endif //  CONTENT_PUBLIC_BROWSER_WEB_CONTENTS_EFL_DELEGATE_EWK_H_