[M108 Migration] Enable proper functionality for ewk_policy_decision_* APIs. 73/286873/3
authorayush.k123 <ayush.k123@samsung.com>
Thu, 12 Jan 2023 11:24:39 +0000 (16:54 +0530)
committerBot Blink <blinkbot@samsung.com>
Mon, 16 Jan 2023 09:48:38 +0000 (09:48 +0000)
This patch migrates the following commits to enables proper functionality
of ewk_policy_decision_* APIs

Reference:
1. https://review.tizen.org/gerrit/273968/
2. https://review.tizen.org/gerrit/279203/
3. https://review.tizen.org/gerrit/280669/

Change-Id: Ic599e5a9d0d9bfa345ab06dc045227814bd6c931
Signed-off-by: Ayush Kumar <ayush.k123@samsung.com>
24 files changed:
tizen_src/ewk/efl_integration/BUILD.gn
tizen_src/ewk/efl_integration/browser/navigation_policy_handler_efl.cc
tizen_src/ewk/efl_integration/browser/navigation_policy_handler_efl.h
tizen_src/ewk/efl_integration/browser/navigation_throttle_efl.cc
tizen_src/ewk/efl_integration/browser/navigation_throttle_efl.h
tizen_src/ewk/efl_integration/browser/network_service/browser_url_loader_throttle_efl.cc [new file with mode: 0644]
tizen_src/ewk/efl_integration/browser/network_service/browser_url_loader_throttle_efl.h [new file with mode: 0644]
tizen_src/ewk/efl_integration/browser/policy_response_delegate_efl.cc
tizen_src/ewk/efl_integration/browser/policy_response_delegate_efl.h
tizen_src/ewk/efl_integration/browser/policy_response_params.h [new file with mode: 0644]
tizen_src/ewk/efl_integration/browser/render_message_filter_efl.cc
tizen_src/ewk/efl_integration/browser/resource_dispatcher_host_delegate_efl.h [deleted file]
tizen_src/ewk/efl_integration/browser/resource_throttle_efl.cc [deleted file]
tizen_src/ewk/efl_integration/browser/resource_throttle_efl.h [deleted file]
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/eweb_view.cc
tizen_src/ewk/efl_integration/eweb_view.h
tizen_src/ewk/efl_integration/private/ewk_frame_private.cc
tizen_src/ewk/efl_integration/private/ewk_frame_private.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/public/ewk_policy_decision.cc
tizen_src/ewk/unittest/utc_blink_ewk_policy_decision_scheme_get_func.cpp [changed mode: 0755->0644]

index 67046b2..78c3d88 100644 (file)
@@ -215,8 +215,6 @@ shared_library("chromium-ewk") {
     "browser/quota_permission_context_efl.h",
     "browser/render_message_filter_efl.cc",
     "browser/render_message_filter_efl.h",
-    "browser/resource_throttle_efl.cc",
-    "browser/resource_throttle_efl.h",
     "browser/scoped_allow_wait_for_legacy_web_view_api.h",
     "browser/scoped_wait_for_ewk.h",
     "browser/sound_effect.cc",
@@ -314,6 +312,8 @@ shared_library("chromium-ewk") {
     "browser/inputpicker/InputPicker.h",
     "browser/inputpicker/color_chooser_efl.cc",
     "browser/inputpicker/color_chooser_efl.h",
+    "browser/network_service/browser_url_loader_throttle_efl.cc",
+    "browser/network_service/browser_url_loader_throttle_efl.h",
     "browser/notification/notification_controller_efl.cc",
     "browser/notification/notification_controller_efl.h",
     "browser/notification/notification_helper.cc",
@@ -322,6 +322,7 @@ shared_library("chromium-ewk") {
     "browser/password_manager/password_manager_client_efl.h",
     "browser/password_manager/password_store_factory.cc",
     "browser/password_manager/password_store_factory.h",
+    "browser/policy_response_params.h",
     "browser/selectpicker/popup_menu_item.cc",
     "browser/selectpicker/popup_menu_item.h",
     "browser/selectpicker/popup_menu_item_private.h",
@@ -577,8 +578,6 @@ shared_library("chromium-ewk") {
     sources += [
       "browser/editor_client_observer.cc",
       "browser/editor_client_observer.h",
-      "browser/resource_dispatcher_host_delegate_efl.cc",
-      "browser/resource_dispatcher_host_delegate_efl.h",
       "chromium_ewk.gypi",
       "file_chooser_controller_efl.cc",
       "file_chooser_controller_efl.h",
index ded3e67..ae82bd9 100644 (file)
@@ -4,39 +4,9 @@
 
 #include "browser/navigation_policy_handler_efl.h"
 
-#include "content/browser/renderer_host/render_view_host_delegate.h"
-#include "content/common/render_messages_efl.h"
-#include "content/public/browser/render_view_host.h"
-#include "ipc/ipc_message.h"
-
-NavigationPolicyHandlerEfl::NavigationPolicyHandlerEfl(
-    content::RenderViewHost* rvh,
-    const NavigationPolicyParams& params)
-        : rvh_(rvh),
-          decision_(Undecied),
-          params_(params) {
-  DCHECK(rvh);
-}
-
-NavigationPolicyHandlerEfl::~NavigationPolicyHandlerEfl() {
-}
-
-void NavigationPolicyHandlerEfl::DownloadNavigation() {
-  // indicate that we handle it
-  if (SetDecision(Handled)) {
-    NOTIMPLEMENTED() << "[M37] RequestOpenURL was moved to WebContentsImpl, "
-                     << "how to access it from here?";
-#if !defined(EWK_BRINGUP)
-    WindowOpenDisposition disposition = SAVE_TO_DISK;
-    rvh_->GetDelegate()->RequestOpenURL(rvh_, params_.url, params_.referrer,
-      disposition, params_.frame_id, params_.is_redirect, false);
-#endif
-  }
-}
-
-bool NavigationPolicyHandlerEfl::SetDecision(NavigationPolicyHandlerEfl::Decision d) {
-  if (decision_ == Undecied && d != Undecied) {
-    decision_ = d;
+bool NavigationPolicyHandlerEfl::SetDecision(Decision decision) {
+  if (decision_ == Undecided && decision != Undecided) {
+    decision_ = decision;
     return true;
   }
 
index cfa8a44..f048259 100644 (file)
@@ -5,36 +5,22 @@
 #ifndef NAVIGATION_POLICY_HANDLER_EFL_H_
 #define NAVIGATION_POLICY_HANDLER_EFL_H_
 
-#include "common/navigation_policy_params.h"
-
-namespace content {
-class RenderViewHost;
-}
-
-namespace IPC {
-class Message;
-}
-
 class NavigationPolicyHandlerEfl {
  public:
-  enum Decision {
-    Undecied = 0,
-    Handled,
-    Unhandled
-  };
+  enum Decision { Undecided = 0, Handled, Unhandled };
+
+  NavigationPolicyHandlerEfl() = default;
+  ~NavigationPolicyHandlerEfl() = default;
+
+  NavigationPolicyHandlerEfl(const NavigationPolicyHandlerEfl&) = delete;
+  NavigationPolicyHandlerEfl& operator=(const NavigationPolicyHandlerEfl&) =
+      delete;
 
-  NavigationPolicyHandlerEfl(
-      content::RenderViewHost* rvh,
-      const NavigationPolicyParams& params);
-  virtual ~NavigationPolicyHandlerEfl();
-  void DownloadNavigation();
   Decision GetDecision() const { return decision_; }
   bool SetDecision(Decision);
 
  private:
-  content::RenderViewHost* rvh_;
-  Decision decision_;
-  NavigationPolicyParams params_;
+  Decision decision_ = Undecided;
 };
 
 #endif /* NAVIGATION_POLICY_HANDLER_EFL_H_ */
index a0cecf5..a49a7b0 100644 (file)
@@ -4,9 +4,14 @@
 
 #include "browser/navigation_throttle_efl.h"
 
+#include "base/bind.h"
+#include "common/navigation_policy_params.h"
 #include "common/web_contents_utils.h"
+#include "content/public/browser/browser_thread.h"
 #include "content/public/browser/navigation_handle.h"
 #include "eweb_view.h"
+#include "third_party/blink/public/platform/web_string.h"
+#include "third_party/blink/public/web/web_navigation_type.h"
 
 #if BUILDFLAG(IS_TIZEN_TV)
 #include "common/application_type.h"
 
 namespace content {
 
+static blink::WebNavigationType GetNavigationTypeFromPageTransition(
+    const ui::PageTransition& transition) {
+  switch (ui::PageTransitionStripQualifier(transition)) {
+    case ui::PAGE_TRANSITION_LINK:
+      return (transition & ui::PAGE_TRANSITION_FORWARD_BACK)
+                 ? blink::kWebNavigationTypeBackForward
+                 : blink::kWebNavigationTypeLinkClicked;
+    case ui::PAGE_TRANSITION_FORM_SUBMIT:
+      return (transition & ui::PAGE_TRANSITION_FORWARD_BACK)
+                 ? blink::kWebNavigationTypeFormResubmittedBackForward
+                 : blink::kWebNavigationTypeFormSubmitted;
+    case ui::PAGE_TRANSITION_RELOAD:
+      return blink::kWebNavigationTypeReload;
+    default:
+      return blink::kWebNavigationTypeOther;
+  }
+  NOTREACHED();
+  return blink::kWebNavigationTypeOther;
+}
+
 NavigationThrottleEfl::NavigationThrottleEfl(
     NavigationHandle* navigation_handle)
-    : NavigationThrottle(navigation_handle) {}
+    : NavigationThrottle(navigation_handle), weak_factory_(this) {}
 
 NavigationThrottleEfl::~NavigationThrottleEfl() = default;
 
 NavigationThrottle::ThrottleCheckResult
+NavigationThrottleEfl::WillStartRequest() {
+  return HandleNavigation(false /* is_redirect */);
+}
+
+NavigationThrottle::ThrottleCheckResult
+NavigationThrottleEfl::WillRedirectRequest() {
+  return HandleNavigation(true /* is_redirect */);
+}
+
+NavigationThrottle::ThrottleCheckResult
 NavigationThrottleEfl::WillFailRequest() {
   auto* handle = navigation_handle();
   auto* web_view =
       web_contents_utils::WebViewFromWebContents(handle->GetWebContents());
-  if (web_view) {
+  if (handle->IsInMainFrame() && web_view) {
     int error_code = handle->GetNetErrorCode();
     web_view->InvokeLoadError(handle->GetURL(), error_code,
                               error_code == net::ERR_ABORTED);
@@ -42,4 +77,81 @@ const char* NavigationThrottleEfl::GetNameForLogging() {
   return "NavigationThrottleEfl";
 }
 
+NavigationThrottle::ThrottleCheckResult NavigationThrottleEfl::HandleNavigation(
+    bool is_redirect) {
+#if BUILDFLAG(IS_TIZEN_TV)
+  if ((IsTIZENWRT() && navigation_handle()->GetURL().SchemeIsFileSystem()) ||
+      navigation_handle()->GetURL().SchemeIs(url::kDataScheme))
+    return NavigationThrottle::PROCEED;
+#endif
+  if (ShouldHandleAsyncronously()) {
+    GetUIThreadTaskRunner({})->PostTask(
+        FROM_HERE, base::BindOnce(&NavigationThrottleEfl::HandleNavigationAsync,
+                                  weak_factory_.GetWeakPtr(),
+                                  GetNavigationPolicyParams(is_redirect)));
+    return NavigationThrottle::DEFER;
+  }
+  return HandleNavigationImpl(GetNavigationPolicyParams(is_redirect))
+             ? NavigationThrottle::CANCEL_AND_IGNORE
+             : NavigationThrottle::PROCEED;
+}
+
+void NavigationThrottleEfl::HandleNavigationAsync(
+    const NavigationPolicyParams& params) {
+  if (HandleNavigationImpl(params))
+    CancelDeferredNavigation(NavigationThrottle::CANCEL_AND_IGNORE);
+  else
+    Resume();
+}
+
+bool NavigationThrottleEfl::HandleNavigationImpl(
+    const NavigationPolicyParams& params) {
+  auto* web_view = web_contents_utils::WebViewFromWebContents(
+      navigation_handle()->GetWebContents());
+  if (!web_view)
+    return false;
+
+  bool handled = false;
+  web_view->InvokePolicyNavigationCallback(params, &handled);
+  return handled;
+}
+
+bool NavigationThrottleEfl::ShouldHandleAsyncronously() const {
+  // Ported from InterceptNavigationThrottle::ShouldCheckAsynchronously,
+  // see components/navigation_interception/intercept_navigation_throttle.cc
+  //
+  // Do not apply the async optimization for:
+  // - POST navigations, to ensure we aren't violating idempotency.
+  // - Subframe navigations, which aren't observed on Android, and should be
+  //   fast on other platforms.
+  // - non-http/s URLs, which are more likely to be intercepted.
+  return navigation_handle()->IsInMainFrame() &&
+         !navigation_handle()->IsPost() &&
+         navigation_handle()->GetURL().SchemeIsHTTPOrHTTPS();
+}
+
+NavigationPolicyParams NavigationThrottleEfl::GetNavigationPolicyParams(
+    bool is_redirect) const {
+  auto* handle = navigation_handle();
+  NavigationPolicyParams params;
+
+  params.url = handle->GetURL();
+  params.httpMethod = handle->IsPost() ? "POST" : "GET";
+  params.type =
+      GetNavigationTypeFromPageTransition(handle->GetPageTransition());
+  std::string auth;
+  handle->GetRequestHeaders().GetHeader(net::HttpRequestHeaders::kAuthorization,
+                                        &auth);
+  params.auth = blink::WebString::FromUTF8(auth);
+  std::string cookie;
+  handle->GetRequestHeaders().GetHeader(net::HttpRequestHeaders::kCookie,
+                                        &cookie);
+  params.cookie = cookie;
+  params.should_replace_current_entry = handle->DidReplaceEntry();
+  params.is_main_frame = handle->IsInMainFrame();
+  params.is_redirect = is_redirect;
+
+  return params;
+}
+
 }  // namespace content
index d138db2..039a52a 100644 (file)
@@ -5,8 +5,11 @@
 #ifndef NAVIGATION_THROTTLE_EFL_H_
 #define NAVIGATION_THROTTLE_EFL_H_
 
+#include "base/memory/weak_ptr.h"
 #include "content/public/browser/navigation_throttle.h"
 
+struct NavigationPolicyParams;
+
 namespace content {
 class NavigationThrottleEfl : public NavigationThrottle {
  public:
@@ -17,9 +20,20 @@ class NavigationThrottleEfl : public NavigationThrottle {
 
   ~NavigationThrottleEfl() override;
 
+  NavigationThrottle::ThrottleCheckResult WillStartRequest() override;
+  NavigationThrottle::ThrottleCheckResult WillRedirectRequest() override;
   NavigationThrottle::ThrottleCheckResult WillFailRequest() override;
 
   const char* GetNameForLogging() override;
+
+ private:
+  NavigationThrottle::ThrottleCheckResult HandleNavigation(bool is_redirect);
+  void HandleNavigationAsync(const NavigationPolicyParams& params);
+  bool HandleNavigationImpl(const NavigationPolicyParams& params);
+  bool ShouldHandleAsyncronously() const;
+  NavigationPolicyParams GetNavigationPolicyParams(bool is_redirect) const;
+
+  base::WeakPtrFactory<NavigationThrottleEfl> weak_factory_;
 };
 
 }  // namespace content
diff --git a/tizen_src/ewk/efl_integration/browser/network_service/browser_url_loader_throttle_efl.cc b/tizen_src/ewk/efl_integration/browser/network_service/browser_url_loader_throttle_efl.cc
new file mode 100644 (file)
index 0000000..ec9dd71
--- /dev/null
@@ -0,0 +1,72 @@
+// Copyright 2020 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 "browser/network_service/browser_url_loader_throttle_efl.h"
+
+#include "browser/policy_response_delegate_efl.h"
+#include "services/network/public/mojom/url_response_head.mojom.h"
+#include "third_party/blink/public/common/loader/resource_type_util.h"
+#include "tizen/system_info.h"
+#include "url/gurl.h"
+
+// static
+std::unique_ptr<BrowserURLLoaderThrottleEfl>
+BrowserURLLoaderThrottleEfl::MaybeCreate(
+    const network::ResourceRequest& request,
+    const base::RepeatingCallback<content::WebContents*()>&
+        web_contents_getter) {
+  if (IsMobileProfile() &&
+      !blink::IsResourceTypeFrame(
+          static_cast<blink::mojom::ResourceType>(request.resource_type))) {
+    return nullptr;
+  }
+
+  if (!request.url.SchemeIsHTTPOrHTTPS() && !request.url.SchemeIsFile())
+    return nullptr;
+
+  return base::WrapUnique(
+      new BrowserURLLoaderThrottleEfl(request, web_contents_getter));
+}
+
+BrowserURLLoaderThrottleEfl::BrowserURLLoaderThrottleEfl(
+    const network::ResourceRequest& request,
+    const base::RepeatingCallback<content::WebContents*()>& web_contents_getter)
+    : request_(request), web_contents_getter_(web_contents_getter) {}
+
+BrowserURLLoaderThrottleEfl::~BrowserURLLoaderThrottleEfl() {
+  if (policy_response_delegate_)
+    policy_response_delegate_->ThrottleDestroyed();
+}
+
+void BrowserURLLoaderThrottleEfl::WillProcessResponse(
+    const GURL& response_url,
+    network::mojom::URLResponseHead* response_head,
+    bool* defer) {
+  auto* web_contents = web_contents_getter_.Run();
+  if (!web_contents) {
+    // The request is not associated with a WebContents. We will just use a
+    // response in this case.
+    return;  // LCOV_EXCL_LINE
+  }
+  policy_response_delegate_ = new PolicyResponseDelegateEfl(
+      request_, response_head, web_contents, this, defer);
+}
+
+void BrowserURLLoaderThrottleEfl::UpdateDeferredResponseHead(
+    const network::mojom::URLResponseHead* new_response_head) {
+  if (delegate_) {
+    delegate_->UpdateDeferredResponseHead(new_response_head->Clone(),
+                                          mojo::ScopedDataPipeConsumerHandle());
+  }
+}
+
+void BrowserURLLoaderThrottleEfl::Resume() {
+  if (delegate_)
+    delegate_->Resume();
+}
+
+void BrowserURLLoaderThrottleEfl::Ignore() {
+  if (delegate_)
+    delegate_->CancelWithError(net::ERR_ABORTED);
+}
diff --git a/tizen_src/ewk/efl_integration/browser/network_service/browser_url_loader_throttle_efl.h b/tizen_src/ewk/efl_integration/browser/network_service/browser_url_loader_throttle_efl.h
new file mode 100644 (file)
index 0000000..e64776d
--- /dev/null
@@ -0,0 +1,56 @@
+// Copyright 2020 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 BROWSER_URL_LOADER_THROTTLE_EFL_H_
+#define BROWSER_URL_LOADER_THROTTLE_EFL_H_
+
+#include <memory>
+
+#include "base/callback.h"
+#include "base/memory/scoped_refptr.h"
+#include "services/network/public/cpp/resource_request.h"
+#include "third_party/blink/public/common/loader/url_loader_throttle.h"
+
+namespace content {
+class WebContents;
+}
+
+class PolicyResponseDelegateEfl;
+
+class BrowserURLLoaderThrottleEfl : public blink::URLLoaderThrottle {
+ public:
+  static std::unique_ptr<BrowserURLLoaderThrottleEfl> MaybeCreate(
+      const network::ResourceRequest& request,
+      const base::RepeatingCallback<content::WebContents*()>&
+          web_contents_getter);
+
+  ~BrowserURLLoaderThrottleEfl() override;
+
+  // blink::URLLoaderThrottle implementation:
+  void WillProcessResponse(const GURL& response_url,
+                           network::mojom::URLResponseHead* response_head,
+                           bool* defer) override;
+
+  void UpdateDeferredResponseHead(
+      const network::mojom::URLResponseHead* new_response_head);
+
+  void Resume();
+  void Ignore();
+
+ private:
+  BrowserURLLoaderThrottleEfl(
+      const network::ResourceRequest& request,
+      const base::RepeatingCallback<content::WebContents*()>&
+          web_contents_getter);
+
+  BrowserURLLoaderThrottleEfl(const BrowserURLLoaderThrottleEfl&) = delete;
+  BrowserURLLoaderThrottleEfl& operator=(const BrowserURLLoaderThrottleEfl&) =
+      delete;
+
+  network::ResourceRequest request_;
+  base::RepeatingCallback<content::WebContents*()> web_contents_getter_;
+  scoped_refptr<PolicyResponseDelegateEfl> policy_response_delegate_;
+};
+
+#endif  // URL_LOADER_THROTTLE_EFL_H_
index d782c80..0378c0d 100644 (file)
 
 #include "browser/policy_response_delegate_efl.h"
 
+#include <vector>
+
 #include "base/task/thread_pool.h"
 #include "browser/mime_override_manager_efl.h"
-#include "browser/resource_throttle_efl.h"
+#include "browser/network_service/browser_url_loader_throttle_efl.h"
+#include "browser/policy_response_params.h"
 #include "common/web_contents_utils.h"
-#include "content/public/browser/browser_thread.h"
 #include "content/public/browser/render_frame_host.h"
-#include "content/public/browser/render_view_host.h"
-#include "content/public/browser/web_contents.h"
 #include "eweb_view.h"
+#include "net/base/upload_bytes_element_reader.h"
 #include "private/ewk_policy_decision_private.h"
-
-using content::BrowserThread;
-using content::RenderViewHost;
-using content::RenderFrameHost;
-using content::WebContents;
-
-using web_contents_utils::WebContentsFromFrameID;
-using web_contents_utils::WebContentsFromViewID;
+#include "services/network/public/cpp/data_element.h"
+#include "services/network/public/cpp/features.h"
+#include "services/network/public/mojom/url_response_head.mojom-forward.h"
 
 using web_contents_utils::WebViewFromWebContents;
 
+// Network service
 PolicyResponseDelegateEfl::PolicyResponseDelegateEfl(
-    net::URLRequest* request,
-    ResourceThrottleEfl* throttle)
-    : policy_decision_(new _Ewk_Policy_Decision(request->url(),
-                                               request,
-                                               this)),
-      throttle_(throttle),
-      render_process_id_(0),
-      render_frame_id_(0),
-      render_view_id_(0) {
-  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
-#if !defined(EWK_BRINGUP)  // FIXME: m85 bringup
-  ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request);
-
-  if (info) {
-    info->GetAssociatedRenderFrame(&render_process_id_, &render_frame_id_);
-    render_view_id_ = info->GetRouteID();
-
-  } else {
-    ResourceRequestInfo::GetRenderFrameForRequest(request, &render_process_id_, &render_frame_id_);
-  }
-#endif
-  // Chromium internal downloads are not associated with any frame or view, we should
-  // accept them without EWK-specific logic. For example notification icon is internal
-  // chromium download
-  if (render_process_id_ > 0 && (render_frame_id_ > 0 || render_view_id_ > 0)) {
-    base::ThreadPool::PostTask(
-        FROM_HERE, {BrowserThread::UI},
-        base::BindOnce(
-            &PolicyResponseDelegateEfl::HandlePolicyResponseOnUIThread, this));
-  } else {
-    // Async call required!
-    base::ThreadPool::PostTask(
-        FROM_HERE, {BrowserThread::IO},
-        base::BindOnce(&PolicyResponseDelegateEfl::UseResponseOnIOThread,
-                       this));
+    const network::ResourceRequest& request,
+    network::mojom::URLResponseHead* response_head,
+    content::WebContents* web_contents,
+    BrowserURLLoaderThrottleEfl* throttle,
+    bool* defer)
+    : response_head_(response_head), url_loader_throttle_(throttle) {
+  PolicyResponseParams params;
+  params.request_url = request.url;
+
+  OverrideMimeTypeIfNeeded(web_contents, request.url.spec(), response_head);
+  params.mime_type = response_head->mime_type;
+
+  if (request.request_body) {
+    for (const auto& element : *request.request_body->elements()) {
+      if (element.type() != network::DataElement::Tag::kBytes)
+        break;
+
+      const std::vector<uint8_t>& bytes =
+          element.As<network::DataElementBytes>().bytes();
+      params.post_data.append(reinterpret_cast<const char*>(bytes.data()),
+                              bytes.size());
+    }
   }
-}
-
-void PolicyResponseDelegateEfl::HandlePolicyResponseOnUIThread() {
-  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
-  DCHECK(policy_decision_.get());
-
-  WebContents* web_contents = NULL;
+  params.is_main_frame = request.is_outermost_main_frame;
+  params.response_headers = response_head->headers;
 
-  DCHECK(render_process_id_ > 0);
-  DCHECK(render_frame_id_ > 0 || render_view_id_ > 0);
+  policy_decision_.reset(new _Ewk_Policy_Decision(params, this));
 
-  if (render_frame_id_ > 0) {
-    web_contents = WebContentsFromFrameID(
-      render_process_id_, render_frame_id_);
-  } else {
-    web_contents = WebContentsFromViewID(render_process_id_, render_view_id_);
-  }
+  // web_view_ takes owenership of Ewk_Policy_Decision. This is same as
+  // WK2/Tizen
+  WebViewFromWebContents(web_contents)
+      ->InvokePolicyResponseCallback(policy_decision_.release(), defer);
+  deferred_ = *defer;
+}
 
-  if (!web_contents) {
-    // this is a situation where we had frame/view info on IO thread but it
-    // does not exist now in UI. We'll ignore such responses
-    IgnoreResponse();
+/* LCOV_EXCL_START */
+void PolicyResponseDelegateEfl::OverrideMimeTypeIfNeeded(
+    content::WebContents* web_contents,
+    const std::string& url_spec,
+    network::mojom::URLResponseHead* response_head) {
+  auto* browser_context = static_cast<content::BrowserContextEfl*>(
+      web_contents->GetBrowserContext());
+  if (!browser_context)
     return;
-  }
 
-  content::BrowserContextEfl* browser_context =
-      static_cast<content::BrowserContextEfl*>(
-          web_contents->GetBrowserContext());
-  if (browser_context) {
-    std::string mime_type;
-    const char* mime_type_chars = policy_decision_->GetResponseMime();
-    if (mime_type_chars)
-      mime_type.assign(mime_type_chars);
-
-    std::string url_spec;
-    const char* url_spec_chars = policy_decision_->GetUrl();
-    if (url_spec_chars)
-      url_spec.assign(url_spec_chars);
-
-    std::string new_mime_type;
-    if (browser_context->WebContext()->OverrideMimeForURL(
-        url_spec, mime_type, new_mime_type)) {
-      MimeOverrideManagerEfl* mime_override_manager_efl =
-          MimeOverrideManagerEfl::GetInstance();
-      mime_override_manager_efl->PushOverriddenMime(url_spec, new_mime_type);
-    }
+  std::string new_mime_type;
+  if (browser_context->WebContext()->OverrideMimeForURL(
+          url_spec, response_head->mime_type, new_mime_type)) {
+    response_head->mime_type = new_mime_type;
   }
-
-  // Delegate may be retrieved ONLY on UI thread
-  policy_decision_->InitializeOnUIThread();
-
-  // web_view_ takes owenership of Ewk_Policy_Decision. This is same as WK2/Tizen
-  WebViewFromWebContents(web_contents)->
-      InvokePolicyResponseCallback(policy_decision_.release());
 }
+/* LCOV_EXCL_STOP */
 
 void PolicyResponseDelegateEfl::UseResponse() {
-  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
-  base::ThreadPool::PostTask(
-      FROM_HERE, {BrowserThread::IO},
-      base::BindOnce(&PolicyResponseDelegateEfl::UseResponseOnIOThread, this));
-}
-
-void PolicyResponseDelegateEfl::IgnoreResponse() {
-  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
-  base::ThreadPool::PostTask(
-      FROM_HERE, {BrowserThread::IO},
-      base::BindOnce(&PolicyResponseDelegateEfl::IgnoreResponseOnIOThread,
-                     this));
-}
-
-void PolicyResponseDelegateEfl::UseResponseOnIOThread() {
-  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
-  if (throttle_) {
-    throttle_->Resume();
-    // decision is already taken so there is no need to use throttle anymore.
-    throttle_ = NULL;
+  if (url_loader_throttle_ && deferred_) {
+    url_loader_throttle_->Resume();
+    url_loader_throttle_ = nullptr;
   }
 }
 
-void PolicyResponseDelegateEfl::IgnoreResponseOnIOThread() {
-  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
-  if (throttle_) {
-    throttle_->Ignore();
-    throttle_ = NULL;
-
+/* LCOV_EXCL_START */
+void PolicyResponseDelegateEfl::IgnoreResponse() {
+  if (url_loader_throttle_) {
+    url_loader_throttle_->Ignore();
+    url_loader_throttle_ = nullptr;
   }
 }
+/* LCOV_EXCL_STOP */
 
 void PolicyResponseDelegateEfl::ThrottleDestroyed(){
-  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
-   // The throttle has gone so don't try to do anything about it further.
-  throttle_ = NULL;
+  // The throttle has gone so don't try to do anything about it further.
+  url_loader_throttle_ = nullptr;
 }
index 2d8d300..dbb8013 100644 (file)
@@ -6,6 +6,8 @@
 #define POLICY_RESPONSE_DELEGATE_EFL_H_
 
 #include "base/memory/ref_counted.h"
+#include "base/memory/weak_ptr.h"
+#include "content/public/browser/web_contents.h"
 #include "private/ewk_policy_decision_private.h"
 #include "public/ewk_policy_decision.h"
 #include "url/gurl.h"
@@ -15,40 +17,47 @@ class URLRequest;
 class HttpResponseHeaders;
 }
 
-namespace content {
-class ResourceController;
-}
+namespace network {
+struct ResourceRequest;
+namespace mojom {
+class URLResponseHead;
+}  // namespace mojom
+}  // namespace network
 
-class ResourceThrottleEfl;
+class BrowserURLLoaderThrottleEfl;
 class _Ewk_Policy_Decision;
 
-class PolicyResponseDelegateEfl: public base::RefCountedThreadSafe<PolicyResponseDelegateEfl> {
+class PolicyResponseDelegateEfl
+    : public base::RefCountedThreadSafe<PolicyResponseDelegateEfl>,
+      public base::SupportsWeakPtr<PolicyResponseDelegateEfl> {
  public:
-  PolicyResponseDelegateEfl(net::URLRequest* request,
-                            ResourceThrottleEfl* throttle);
+  PolicyResponseDelegateEfl(const network::ResourceRequest& request,
+                            network::mojom::URLResponseHead* response_head,
+                            content::WebContents* web_contents,
+                            BrowserURLLoaderThrottleEfl* throttle,
+                            bool* defer);
+
+  PolicyResponseDelegateEfl(const PolicyResponseDelegateEfl&) = delete;
+  PolicyResponseDelegateEfl& operator=(const PolicyResponseDelegateEfl&) =
+      delete;
 
   void UseResponse();
   void IgnoreResponse();
   void ThrottleDestroyed();
 
-  int GetRenderProcessId() const { return render_process_id_; }
-  int GetRenderFrameId() const { return render_frame_id_; }
-  int GetRenderViewId() const { return render_view_id_; }
-
  private:
   friend class base::RefCountedThreadSafe<PolicyResponseDelegateEfl>;
 
-  void HandlePolicyResponseOnUIThread();
-  void UseResponseOnIOThread();
-  void IgnoreResponseOnIOThread();
+  void OverrideMimeTypeIfNeeded(content::WebContents* web_contents,
+                                const std::string& url_spec,
+                                network::mojom::URLResponseHead* response_head);
 
   std::unique_ptr<_Ewk_Policy_Decision> policy_decision_;
+  network::mojom::URLResponseHead* response_head_ = nullptr;
   // A throttle which blocks response and invokes policy mechanism.
   // It is used to cancel or resume response processing.
-  ResourceThrottleEfl* throttle_;
-  int render_process_id_;
-  int render_frame_id_;
-  int render_view_id_;
+  BrowserURLLoaderThrottleEfl* url_loader_throttle_ = nullptr;
+  bool deferred_ = false;
 };
 
 #endif /* POLICY_RESPONSE_DELEGATE_EFL_H_ */
diff --git a/tizen_src/ewk/efl_integration/browser/policy_response_params.h b/tizen_src/ewk/efl_integration/browser/policy_response_params.h
new file mode 100644 (file)
index 0000000..a03b929
--- /dev/null
@@ -0,0 +1,26 @@
+// Copyright 2020 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 POLICY_RESPONSE_PARAMS_H_
+#define POLICY_RESPONSE_PARAMS_H_
+
+#include <string>
+
+#include "net/http/http_response_headers.h"
+#include "url/gurl.h"
+
+struct PolicyResponseParams {
+  PolicyResponseParams() = default;
+  PolicyResponseParams(const PolicyResponseParams& params) = default;
+  ~PolicyResponseParams() = default;
+
+  GURL request_url;
+  std::string mime_type;
+  std::string post_data;
+  bool is_main_frame = false;
+  bool allow_download = false;
+  scoped_refptr<net::HttpResponseHeaders> response_headers;
+};
+
+#endif  // POLICY_RESPONSE_PARAMS_H_
index d459bac..436d7da 100644 (file)
@@ -61,8 +61,8 @@ void RenderMessageFilterEfl::OnDecideNavigationPolicy(
 
   if (content::WebContents* web_contents =
       WebContentsFromViewID(render_process_id_, params.render_view_id)) {
-    WebViewFromWebContents(web_contents)->InvokePolicyNavigationCallback(
-        web_contents->GetRenderViewHost(), params, handled);
+    WebViewFromWebContents(web_contents)
+        ->InvokePolicyNavigationCallback(params, handled);
   }
 }
 
diff --git a/tizen_src/ewk/efl_integration/browser/resource_dispatcher_host_delegate_efl.h b/tizen_src/ewk/efl_integration/browser/resource_dispatcher_host_delegate_efl.h
deleted file mode 100644 (file)
index 4e0dac5..0000000
+++ /dev/null
@@ -1,67 +0,0 @@
-// Copyright 2014 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 RESOURCE_DISPATCHER_HOST_DELEGATE_EFL_H
-#define RESOURCE_DISPATCHER_HOST_DELEGATE_EFL_H
-
-#include "base/compiler_specific.h"
-
-namespace net {
-class AuthChallengeInfo;
-class URLRequest;
-}
-
-namespace content {
-
-class ResourceDispatcherHostLoginDelegate;
-
-class ResourceDispatcherHostDelegateEfl
-    : public ResourceDispatcherHostDelegate {
- public:
-  ResourceDispatcherHostDelegateEfl() {}
-
-  // ResourceDispatcherHostDelegate implementation.
-  //
-  // Called after ShouldBeginRequest to allow the embedder to add resource
-  // throttles.
-  void RequestBeginning(net::URLRequest* request,
-                        content::ResourceContext* resource_context,
-                        content::AppCacheService* appcache_service,
-                        std::vector<std::unique_ptr<content::ResourceThrottle>>*
-                            throttles) override;
-
-  // Called to trigger download.
-  void DownloadStarting(net::URLRequest* request,
-                        content::ResourceContext* resource_context,
-                        bool is_content_initiated,
-                        bool must_download,
-                        bool is_new_request,
-                        std::vector<std::unique_ptr<content::ResourceThrottle>>*
-                            throttles) override;
-
-// Create login delegate.
-#if !defined(EWK_BRINGUP)  // FIXME: m67 bringup
-  content::ResourceDispatcherHostLoginDelegate* CreateLoginDelegate(
-      net::AuthChallengeInfo* auth_info,
-      net::URLRequest* request) override;
-#endif
-
-  // EWK_BRINGUP: Removed in upversion.
-  // Returns true if mime type should be overridden, otherwise returns false.
-  bool ShouldOverrideMimeType(const GURL& url,
-                              std::string& new_mime_type) const;
-
- private:
-  void TriggerNewDownloadStartCallback(net::URLRequest* request,
-                                       const std::string& user_agent,
-                                       const std::string& content_disposition,
-                                       const std::string& mime_type,
-                                       int64_t content_length,
-                                       int render_process_id,
-                                       int render_view_id);
-};
-
-}  // namespace content
-
-#endif  // RESOURCE_DISPATCHER_HOST_DELEGATE_EFL_H
diff --git a/tizen_src/ewk/efl_integration/browser/resource_throttle_efl.cc b/tizen_src/ewk/efl_integration/browser/resource_throttle_efl.cc
deleted file mode 100644 (file)
index 67c1a7e..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-// Copyright 2014 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 "browser/policy_response_delegate_efl.h"
-#include "browser/resource_throttle_efl.h"
-
-ResourceThrottleEfl::~ResourceThrottleEfl() {
-  if (policy_delegate_.get()) {
-    //If resourceThrottleEfl is destroyed, inform delegate that it cannot
-    //use controller anymore.
-    policy_delegate_->ThrottleDestroyed();
-  }
-}
-
-void ResourceThrottleEfl::WillProcessResponse(
-    const GURL& response_url,
-    network::mojom::URLResponseHead* response_head,
-    bool* defer) {
-  //Stop processing until decision will be granted.
-  *defer = true;
-
-  policy_delegate_ = new PolicyResponseDelegateEfl(&request_,
-                                                   this);
-}
diff --git a/tizen_src/ewk/efl_integration/browser/resource_throttle_efl.h b/tizen_src/ewk/efl_integration/browser/resource_throttle_efl.h
deleted file mode 100644 (file)
index b8c6446..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-// Copyright 2014 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 RESOURCE_THROTTLE__EFL_H_
-#define RESOURCE_THROTTLE__EFL_H_
-
-#include "browser/policy_response_delegate_efl.h"
-#include "net/url_request/url_request.h"
-#include "third_party/blink/public/common/loader/url_loader_throttle.h"
-
-class ResourceThrottleEfl : public blink::URLLoaderThrottle {
- public:
-  ResourceThrottleEfl(net::URLRequest& request)
-      : request_(request), policy_delegate_(nullptr) {}
-
-  ~ResourceThrottleEfl() override;
-
-  // blink::URLLoaderThrottle overrides;
-  void WillProcessResponse(const GURL& response_url,
-                           network::mojom::URLResponseHead* response_head,
-                           bool* defer) override;
-
-  void Resume() {
-    // EWK_BRINGUP. Removed in upstream
-    // 64fa092bc4ccdcb1c0cc08b93d6c1bd49363adb0
-    // controller()->Resume();
-#if !defined(EWK_BRINGUP)  // FIXME: m85 bringup
-    Resume();
-#endif
-  }
-
-  void Ignore() {
-    // EWK_BRINGUP. Removed in upstream
-    // 64fa092bc4ccdcb1c0cc08b93d6c1bd49363adb0
-    // controller()->CancelAndIgnore();
-#if !defined(EWK_BRINGUP)  // FIXME: m85 bringup
-    Cancel();
-#endif
-  }
-
- private:
-  net::URLRequest& request_;
-  scoped_refptr<PolicyResponseDelegateEfl> policy_delegate_;
-};
-#endif /*RESOURCE_THROTTLE__EFL_H_*/
index 0140567..4529c67 100644 (file)
@@ -8,6 +8,7 @@
 #include "base/strings/string_number_conversions.h"
 #include "browser/editor_client_observer.h"
 #include "browser/navigation_throttle_efl.h"
+#include "browser/network_service/browser_url_loader_throttle_efl.h"
 #include "browser/network_service/proxying_url_loader_factory_efl.h"
 #include "browser/notification/notification_controller_efl.h"
 #include "browser/quota_permission_context_efl.h"
@@ -28,6 +29,7 @@
 #include "content/public/common/content_switches.h"
 #include "devtools_manager_delegate_efl.h"
 #include "eweb_context.h"
+#include "services/network/public/cpp/features.h"
 #include "shared_url_loader_factory_efl.h"
 #include "web_contents_delegate_efl.h"
 #include "web_contents_view_delegate_ewk.h"
@@ -550,4 +552,21 @@ bool ContentBrowserClientEfl::WillCreateURLLoaderFactory(
   return true;
 }
 
+std::vector<std::unique_ptr<blink::URLLoaderThrottle>>
+ContentBrowserClientEfl::CreateURLLoaderThrottles(
+    const network::ResourceRequest& request,
+    content::BrowserContext* browser_context,
+    const base::RepeatingCallback<content::WebContents*()>& wc_getter,
+    content::NavigationUIData* navigation_ui_data,
+    int frame_tree_node_id) {
+  std::vector<std::unique_ptr<blink::URLLoaderThrottle>> result;
+
+  auto browser_throttle =
+      BrowserURLLoaderThrottleEfl::MaybeCreate(request, wc_getter);
+  if (browser_throttle)
+    result.push_back(std::move(browser_throttle));
+
+  return result;
+}
+
 }  // namespace content
index 6bee4ac..cef8cb6 100644 (file)
@@ -8,6 +8,7 @@
 #include "content/public/browser/browser_context.h"
 #include "content/public/browser/content_browser_client.h"
 #include "net/cookies/canonical_cookie.h"
+#include "third_party/blink/public/common/loader/url_loader_throttle.h"
 #include "third_party/blink/public/web/web_window_features.h"
 
 namespace base {
@@ -128,6 +129,13 @@ class ContentBrowserClientEfl : public ContentBrowserClient {
   void RemoveAcceptLangsChangedCallback(AcceptLangsChangedCallback callback);
   std::vector<std::unique_ptr<NavigationThrottle>> CreateThrottlesForNavigation(
       NavigationHandle* handle) override;
+  std::vector<std::unique_ptr<blink::URLLoaderThrottle>>
+  CreateURLLoaderThrottles(
+      const network::ResourceRequest& request,
+      content::BrowserContext* browser_context,
+      const base::RepeatingCallback<content::WebContents*()>& wc_getter,
+      content::NavigationUIData* navigation_ui_data,
+      int frame_tree_node_id) override;
 
  private:
   bool WillCreateURLLoaderFactory(
index f8af786..70727b5 100644 (file)
@@ -573,29 +573,31 @@ void EWebView::InvokeAuthCallback(LoginDelegateEfl* login_delegate,
 }
 
 void EWebView::InvokePolicyResponseCallback(
-    _Ewk_Policy_Decision* policy_decision) {
+    _Ewk_Policy_Decision* policy_decision,
+    bool* defer) {
   SmartCallback<EWebViewCallbacks::PolicyResponseDecide>().call(
       policy_decision);
 
-  if (policy_decision->isSuspended())
+  if (policy_decision->isSuspended()) {
+    *defer = true;
     return;
+  }
 
   if (!policy_decision->isDecided())
     policy_decision->Use();
 
-  delete policy_decision;
+  policy_decision->SelfDeleteIfNecessary();
 }
 
 void EWebView::InvokePolicyNavigationCallback(
-    RenderViewHost* rvh,
-    const NavigationPolicyParams params,
+    const NavigationPolicyParams& params,
     bool* handled) {
   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
 
   SmartCallback<EWebViewCallbacks::SaveSessionData>().call();
 
   std::unique_ptr<_Ewk_Policy_Decision> policy_decision(
-      new _Ewk_Policy_Decision(params, rvh));
+      new _Ewk_Policy_Decision(params));
 
   SmartCallback<EWebViewCallbacks::NavigationPolicyDecision>().call(
       policy_decision.get());
index 00a71e1..83b9bd4 100644 (file)
@@ -326,9 +326,9 @@ class EWebView {
   bool GetSnapshotAsync(Eina_Rectangle rect,
                         Ewk_Web_App_Screenshot_Captured_Callback callback,
                         void* user_data);
-  void InvokePolicyResponseCallback(_Ewk_Policy_Decision* policy_decision);
-  void InvokePolicyNavigationCallback(content::RenderViewHost* rvh,
-                                      NavigationPolicyParams params,
+  void InvokePolicyResponseCallback(_Ewk_Policy_Decision* policy_decision,
+                                    bool* defer);
+  void InvokePolicyNavigationCallback(const NavigationPolicyParams& params,
                                       bool* handled);
   void UseSettingsFont();
 
index b3c6754..5e64e46 100644 (file)
@@ -28,8 +28,7 @@ _Ewk_Frame::_Ewk_Frame(RenderFrameHost* rfh)
   is_main_frame_ = wc->GetPrimaryMainFrame() == rfh;
 }
 
-_Ewk_Frame::_Ewk_Frame(const NavigationPolicyParams &params)
-  : is_main_frame_(params.is_main_frame)
-{
-}
+_Ewk_Frame::_Ewk_Frame(const NavigationPolicyParams& params)
+    : is_main_frame_(params.is_main_frame) {}
 
+_Ewk_Frame::_Ewk_Frame(bool is_main_frame) : is_main_frame_(is_main_frame) {}
index 83e58da..60236b4 100644 (file)
@@ -14,7 +14,8 @@ struct NavigationPolicyParams;
 class _Ewk_Frame {
 public:
   _Ewk_Frame(content::RenderFrameHost* rfh);
-  _Ewk_Frame(const NavigationPolicyParams &params);
+  _Ewk_Frame(const NavigationPolicyParams& params);
+  _Ewk_Frame(bool is_main_frame);
 
   bool IsMainFrame() const { return is_main_frame_; }
 
index 2a11597..4d94bc8 100644 (file)
@@ -6,17 +6,16 @@
 
 #include <algorithm>
 
+#include "browser/policy_response_params.h"
+#include "common/navigation_policy_params.h"
+#include "content/browser/loader/download_utils_impl.h"
 #include "content/public/browser/browser_thread.h"
-#include "content/public/browser/render_view_host.h"
 #include "eweb_view.h"
 #include "net/http/http_response_headers.h"
 #include "net/url_request/url_request_context.h"
 #include "private/ewk_frame_private.h"
-#include "third_party/blink/public/common/mime_util/mime_util.h"
 
 using content::BrowserThread;
-using content::RenderFrameHost;
-using content::RenderViewHost;
 
 namespace {
 void FreeStringShare(void* data) {
@@ -24,11 +23,13 @@ void FreeStringShare(void* data) {
 }
 }
 
-_Ewk_Policy_Decision::_Ewk_Policy_Decision(const GURL& request_url,
-                                           net::URLRequest* request,
+_Ewk_Policy_Decision::_Ewk_Policy_Decision(const PolicyResponseParams& params,
                                            PolicyResponseDelegateEfl* delegate)
     : web_view_(NULL),
-      policy_response_delegate_(delegate),
+      policy_response_delegate_(AsWeakPtr(delegate)),
+      frame_(new _Ewk_Frame(params.is_main_frame)),
+      http_body_(params.post_data),
+      response_mime_(params.mime_type),
       response_headers_(NULL),
       decision_type_(EWK_POLICY_DECISION_USE),
       navigation_type_(EWK_POLICY_NAVIGATION_TYPE_OTHER),
@@ -37,46 +38,36 @@ _Ewk_Policy_Decision::_Ewk_Policy_Decision(const GURL& request_url,
       response_status_code_(0),
       type_(POLICY_RESPONSE) {
   DCHECK(delegate);
-  DCHECK(request);
 
-  net::HttpResponseHeaders* response_headers = request->response_headers();
+  ParseUrl(params.request_url);
 
-  ParseUrl(request_url);
-  if (response_headers) {
-    response_status_code_ = response_headers->response_code();
-
-    request->GetMimeType(&response_mime_);
+  if (!params.response_headers)
+    return;
 
-#if !defined(EWK_BRINGUP)  // FIXME: m76 bringup
-    if ((!content::IsResourceTypeFrame(resource_type) &&
-         !resource_type == content::RESOURCE_TYPE_FAVICON) ||
-        (!blink::IsSupportedMimeType(response_mime_))) {
-      decision_type_ = EWK_POLICY_DECISION_DOWNLOAD;
-    }
-#endif
+  response_status_code_ = params.response_headers->response_code();
 
-    if (request_url.has_password() && request_url.has_username())
-      SetAuthorizationIfNecessary(request_url);
+  if (content::download_utils::IsDownload(
+          params.request_url, params.response_headers.get(), response_mime_))
+    decision_type_ = EWK_POLICY_DECISION_DOWNLOAD;
 
-    std::string set_cookie_;
+  if (params.request_url.has_password() && params.request_url.has_username())
+    SetAuthorizationIfNecessary(params.request_url);
 
-    if (response_headers->EnumerateHeader(NULL, "Set-Cookie", &set_cookie_))
-      cookie_ = set_cookie_;
+  params.response_headers->EnumerateHeader(nullptr, "Set-Cookie", &cookie_);
 
-    size_t iter = 0;
-    std::string name;
-    std::string value;
-    response_headers_ = eina_hash_string_small_new(FreeStringShare);
-    while (response_headers->EnumerateHeaderLines(&iter, &name, &value))
-      eina_hash_add(response_headers_, name.c_str(),
-                    eina_stringshare_add(value.c_str()));
+  size_t iter = 0;
+  std::string name;
+  std::string value;
+  response_headers_ = eina_hash_string_small_new(FreeStringShare);
+  while (params.response_headers->EnumerateHeaderLines(&iter, &name, &value)) {
+    eina_hash_add(response_headers_, name.c_str(),
+                  eina_stringshare_add(value.c_str()));
   }
 }
 
-_Ewk_Policy_Decision::_Ewk_Policy_Decision(const NavigationPolicyParams& params,
-                                           content::RenderViewHost* rvh)
+_Ewk_Policy_Decision::_Ewk_Policy_Decision(const NavigationPolicyParams& params)
     : web_view_(NULL),
-      navigation_policy_handler_(new NavigationPolicyHandlerEfl(rvh, params)),
+      navigation_policy_handler_(new NavigationPolicyHandlerEfl()),
       frame_(new _Ewk_Frame(params)),
       cookie_(params.cookie),
       http_method_(params.httpMethod),
@@ -106,11 +97,10 @@ _Ewk_Policy_Decision::_Ewk_Policy_Decision(EWebView* view)
   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
   DCHECK(view);
 
-  RenderFrameHost* rfh = NULL;
+  content::RenderFrameHost* rfh = nullptr;
   // we can use main frame here
-  if (view) {
-    view->web_contents().GetPrimaryMainFrame();
-  }
+  if (view)
+    rfh = view->web_contents().GetPrimaryMainFrame();
 
   frame_.reset(new _Ewk_Frame(rfh));
 }
@@ -120,6 +110,7 @@ _Ewk_Policy_Decision::~_Ewk_Policy_Decision() {
 }
 
 void _Ewk_Policy_Decision::Use() {
+  DCHECK(policy_response_delegate_.get());
   is_decided_ = true;
   switch (type_) {
     case POLICY_RESPONSE:
@@ -138,11 +129,13 @@ void _Ewk_Policy_Decision::Use() {
   }
 
   if (isSuspended()) {
-    BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE, this);
+    is_suspended_ = false;
+    SelfDeleteIfNecessary();
   }
 }
 
 void _Ewk_Policy_Decision::Ignore() {
+  DCHECK(policy_response_delegate_.get());
   is_decided_ = true;
   switch (type_) {
     case _Ewk_Policy_Decision::POLICY_RESPONSE:
@@ -161,29 +154,8 @@ void _Ewk_Policy_Decision::Ignore() {
   }
 
   if (isSuspended()) {
-    BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE, this);
-  }
-}
-
-void _Ewk_Policy_Decision::Download() {
-  is_decided_ = true;
-  switch (type_) {
-    case _Ewk_Policy_Decision::POLICY_RESPONSE:
-      policy_response_delegate_->UseResponse();
-      break;
-    case _Ewk_Policy_Decision::POLICY_NAVIGATION:
-      navigation_policy_handler_->DownloadNavigation();
-      break;
-    case _Ewk_Policy_Decision::POLICY_NEWWINDOW:
-      can_create_window_ = false;
-      break;
-    default:
-      NOTREACHED();
-      break;
-  }
-
-  if (isSuspended()) {
-    BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE, this);
+    is_suspended_ = false;
+    SelfDeleteIfNecessary();
   }
 }
 
@@ -197,41 +169,6 @@ bool _Ewk_Policy_Decision::Suspend() {
   return false;
 }
 
-void _Ewk_Policy_Decision::InitializeOnUIThread() {
-  DCHECK(type_ == _Ewk_Policy_Decision::POLICY_RESPONSE);
-  DCHECK(policy_response_delegate_.get());
-
-  if (policy_response_delegate_.get()) {
-    RenderFrameHost* host =
-        RenderFrameHost::FromID(policy_response_delegate_->GetRenderProcessId(),
-                                policy_response_delegate_->GetRenderFrameId());
-
-    // Download request has no render frame id, they're detached. We override it
-    // with main frame from render view id
-    if (!host) {
-      RenderViewHost* viewhost = RenderViewHost::FromID(
-          policy_response_delegate_->GetRenderProcessId(),
-          policy_response_delegate_->GetRenderViewId());
-
-      // DCHECK(viewhost);
-      if (viewhost) {
-        content::WebContents* web_contents =
-            content::WebContents::FromRenderViewHost(viewhost);
-        host = web_contents->GetPrimaryMainFrame();
-      }
-    }
-
-    if (host) {
-      /*
-       * In some situations there is no renderer associated to the response
-       * Such case can be observed while running TC
-       * utc_blink_ewk_geolocation_permission_request_suspend_func
-       */
-      frame_.reset(new _Ewk_Frame(host));
-    }
-  }
-}
-
 _Ewk_Frame* _Ewk_Policy_Decision::GetFrameRef() const {
   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
   // Ups, forgot to initialize something?
@@ -282,29 +219,41 @@ const char* _Ewk_Policy_Decision::GetCookie() const {
 }
 
 const char* _Ewk_Policy_Decision::GetAuthUser() const {
-  return auth_user_.empty() ? NULL : auth_user_.c_str();
+  return auth_user_.c_str();
 }
 
 const char* _Ewk_Policy_Decision::GetAuthPassword() const {
-  return auth_password_.empty() ? NULL : auth_password_.c_str();
+  return auth_password_.c_str();
 }
 
 const char* _Ewk_Policy_Decision::GetUrl() const {
-  return url_.empty() ? NULL : url_.c_str();
+  return url_.c_str();
 }
 
 const char* _Ewk_Policy_Decision::GetHttpMethod() const {
-  return http_method_.empty() ? NULL : http_method_.c_str();
+  return http_method_.c_str();
+}
+
+const char* _Ewk_Policy_Decision::GetHttpBody() const {
+  return http_body_.c_str();
 }
 
 const char* _Ewk_Policy_Decision::GetScheme() const {
-  return scheme_.empty() ? NULL : scheme_.c_str();
+  return scheme_.c_str();
 }
 
 const char* _Ewk_Policy_Decision::GetHost() const {
-  return host_.empty() ? NULL : host_.c_str();
+  return host_.c_str();
 }
 
 const char* _Ewk_Policy_Decision::GetResponseMime() const {
-  return response_mime_.empty() ? NULL : response_mime_.c_str();
+  return response_mime_.c_str();
+}
+
+void _Ewk_Policy_Decision::SelfDeleteIfNecessary() {
+  if (!deleted_) {
+    content::BrowserThread::DeleteSoon(content::BrowserThread::UI, FROM_HERE,
+                                       this);
+    deleted_ = true;
+  }
 }
index f5dc3c5..ac7df3e 100644 (file)
 // Basic type of authorization - 'type username:password'
 #define BASIC_AUTHORIZATION "BASIC"
 
-namespace net {
-class URLRequest;
-}
-
 class EWebView;
 class GURL;
-struct NavigationPolicyParams;
+struct PolicyResponseParams;
 class PolicyResponseDelegateEfl;
-class _Ewk_Frame;
+struct NavigationPolicyParams;
+struct _Ewk_Frame;
 
 namespace content {
 class RenderViewHost;
@@ -36,14 +33,13 @@ class _Ewk_Policy_Decision {
  /**
   * Constructs _Ewk_Policy_Decision with navigation type POLICY_RESPONSE
   */
-  explicit _Ewk_Policy_Decision(const GURL& request_url,
-                                net::URLRequest* request,
+  explicit _Ewk_Policy_Decision(const PolicyResponseParams& params,
                                 PolicyResponseDelegateEfl* delegate);
 
- /**
-  * Constructs _Ewk_Policy_Decision with navigation type POLICY_NAVIGATION
-  */
-  explicit _Ewk_Policy_Decision(const NavigationPolicyParams &params, content::RenderViewHost* rvh);
 /**
+   * Constructs _Ewk_Policy_Decision with navigation type POLICY_NAVIGATION
+   */
+  explicit _Ewk_Policy_Decision(const NavigationPolicyParams& params);
 
   /**
    * Constructs _Ewk_Policy_Decision with navigation type POLICY_NEWWINDOW
@@ -54,7 +50,6 @@ class _Ewk_Policy_Decision {
 
   void Use();
   void Ignore();
-  void Download();
   bool Suspend();
 
   bool isDecided() const { return is_decided_; }
@@ -66,6 +61,7 @@ class _Ewk_Policy_Decision {
   const char* GetAuthPassword() const;
   const char* GetUrl() const;
   const char* GetHttpMethod() const;
+  const char* GetHttpBody() const;
   const char* GetScheme() const;
   const char* GetHost() const;
   const char* GetResponseMime() const;
@@ -77,10 +73,10 @@ class _Ewk_Policy_Decision {
 
   _Ewk_Frame* GetFrameRef() const;
 
-  void InitializeOnUIThread();
   void ParseUrl(const GURL& url);
+  void SelfDeleteIfNecessary();
 
-private:
+ private:
   /**
    * @brief sets userID and password
    * @param request_url requested url - user:password@address
@@ -100,12 +96,13 @@ private:
   };
 
   EWebView* web_view_;
-  scoped_refptr<PolicyResponseDelegateEfl> policy_response_delegate_;
+  base::WeakPtr<PolicyResponseDelegateEfl> policy_response_delegate_;
   std::unique_ptr<NavigationPolicyHandlerEfl> navigation_policy_handler_;
   std::unique_ptr<_Ewk_Frame> frame_;
   std::string cookie_;
   std::string url_;
   std::string http_method_;
+  std::string http_body_;
   std::string host_;
   std::string scheme_;
   std::string response_mime_;
@@ -119,6 +116,7 @@ private:
   std::string auth_password_;
   PolicyType type_;
   bool can_create_window_ = true;
+  bool deleted_ = false;
 };
 
 #endif // ewk_policy_decision_private_h
index 50b8a9a..caa6621 100644 (file)
@@ -143,6 +143,6 @@ Eina_Bool ewk_policy_decision_is_main_frame(const Ewk_Policy_Decision* policyDec
 
 const char* ewk_policy_decision_http_body_get(Ewk_Policy_Decision* policyDecision)
 {
-  LOG_EWK_API_MOCKUP();
-  return NULL;
+  EINA_SAFETY_ON_NULL_RETURN_VAL(policyDecision, NULL);
+  return policyDecision->GetHttpBody();
 }
old mode 100755 (executable)
new mode 100644 (file)
index 547e681..fb48564
@@ -1,4 +1,4 @@
-// Copyright 2014 Samsung Electronics. All rights reserved.
+// Copyright 2014-2016 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.
 
@@ -13,47 +13,66 @@ protected:
     evas_object_smart_callback_add(GetEwkWebView(), "policy,navigation,decide", policy_navigation_decide, this);
   }
 
-  void PreTearDown()
-  {
-    evas_object_smart_callback_del(GetEwkWebView(), "policy,navigation,decide", policy_navigation_decide);
-  }
+  utc_blink_ewk_policy_decision_scheme_get() : received_scheme_(nullptr) {}
 
-  void LoadFinished(Evas_Object* webview) {
-
-    EventLoopStop(utc_blink_ewk_base::Failure);
+  void PreTearDown() {
+    evas_object_smart_callback_del(GetEwkWebView(), "policy,navigation,decide",
+                                   policy_navigation_decide);
   }
 
-  static void policy_navigation_decide(void* data, Evas_Object* webview, void* event_info)
-  {
+  static void policy_navigation_decide(void* data,
+                                       Evas_Object* webview,
+                                       void* event_info) {
     utc_message("[policy_navigation_decide] :: \n");
-    utc_blink_ewk_policy_decision_scheme_get *owner = static_cast<utc_blink_ewk_policy_decision_scheme_get*>(data);
-    Ewk_Policy_Decision* policy_decision = (Ewk_Policy_Decision*)event_info;
+    auto owner = static_cast<utc_blink_ewk_policy_decision_scheme_get*>(data);
+    auto policy_decision = static_cast<Ewk_Policy_Decision*>(event_info);
+    if (!policy_decision) {
+      utc_message("[policy_navigation_decide] :: policy_decision is nullptr");
+      owner->EventLoopStop(Failure);
+      return;
+    }
+    owner->received_scheme_ = ewk_policy_decision_scheme_get(policy_decision);
+    owner->EventLoopStop(Success);
+  }
 
-    if (policy_decision && ewk_policy_decision_scheme_get(policy_decision)) {
+  static void job_do_http(utc_blink_ewk_base* data) {
+    auto owner = static_cast<utc_blink_ewk_policy_decision_scheme_get*>(data);
+    ASSERT_EQ(EINA_TRUE, ewk_view_url_set(owner->GetEwkWebView(),
+                                          "http://www.google.com"));
+  }
 
-      owner->EventLoopStop(utc_blink_ewk_base::Success);
-    }
+  static void job_do_mailto(utc_blink_ewk_base* data) {
+    auto owner = static_cast<utc_blink_ewk_policy_decision_scheme_get*>(data);
+    ASSERT_EQ(EINA_TRUE, ewk_view_url_set(owner->GetEwkWebView(),
+                                          "mailto:someone@example.com"));
   }
+
+  const char* received_scheme_;
 };
 
 /**
- * @brief Tests if the scheme for policy decision is returned properly.
+ * @brief Tests if the scheme for policy decision is returned properly. Expected
+ * scheme is http.
+ */
+TEST_F(utc_blink_ewk_policy_decision_scheme_get, POS_HTTP) {
+  SetTestJob(utc_blink_ewk_policy_decision_scheme_get::job_do_http);
+  ASSERT_EQ(Success, EventLoopStart());
+  ASSERT_STREQ("http", received_scheme_);
+}
+
+/**
+ * @brief Tests if the scheme for policy decision is returned properly. Expected
+ * scheme is mailto.
  */
-TEST_F(utc_blink_ewk_policy_decision_scheme_get, POS_TEST)
-{
-  Eina_Bool result = ewk_view_url_set(GetEwkWebView(), "http://www.google.com");
-  if (!result)
-    FAIL();
-
-  utc_blink_ewk_base::MainLoopResult main_result = EventLoopStart();
-  if (main_result != utc_blink_ewk_base::Success)
-    FAIL();
+TEST_F(utc_blink_ewk_policy_decision_scheme_get, POS_MAILTO) {
+  SetTestJob(utc_blink_ewk_policy_decision_scheme_get::job_do_mailto);
+  ASSERT_EQ(Success, EventLoopStart());
+  ASSERT_STREQ("mailto", received_scheme_);
 }
 
 /**
  * @brief Tests if function works properly in case of NULL of a webview
  */
-TEST_F(utc_blink_ewk_policy_decision_scheme_get, NEG_TEST)
-{
-  utc_check_eq(0, ewk_policy_decision_scheme_get(0));
+TEST_F(utc_blink_ewk_policy_decision_scheme_get, NEG_INVALID_PARAM) {
+  ASSERT_EQ(nullptr, ewk_policy_decision_scheme_get(nullptr));
 }