[WRTjs] Refactor popup
[platform/framework/web/chromium-efl.git] / wrt / src / browser / wrt_render_message_filter.cc
1 // Copyright 2019 Samsung Electronics. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "wrt_render_message_filter.h"
6
7 #if !defined(WRT_JS_BRINGUP)
8 #include "tizen_src/chromium_impl/content/public/browser/policy_decision_util.h"
9 #endif
10 #include "tizen_src/ewk/efl_integration/private/ewk_policy_decision_private.h"
11 #include "wrt/src/browser/native_web_runtime.h"
12 #include "wrt/src/browser/wrt_browser_context.h"
13
14 namespace {
15
16 static void NavigationPolicyDecision(void* /*data*/,
17                                      const std::string& url,
18                                      void* event_info) {
19   if (!event_info) {
20     LOG(ERROR) << "event_info is nullptr";
21     return;
22   }
23
24   auto policy_decision = static_cast<_Ewk_Policy_Decision*>(event_info);
25   if (wrt::NativeWebRuntime::GetInstance().ShouldAllowNavigation(url))
26     policy_decision->Use();
27   else
28     policy_decision->Ignore();
29 }
30
31 }  // namespace
32
33 namespace wrt {
34
35 WRTRenderMessageFilter::WRTRenderMessageFilter() {}
36
37 WRTRenderMessageFilter::~WRTRenderMessageFilter() {}
38
39 void WRTRenderMessageFilter::OnDecideNavigationPolicy(
40     const NavigationPolicyParams& params,
41     bool* handled) {
42   DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
43
44 #if defined(WRT_JS_BRINGUP)
45   *handled = false;
46 #else
47   std::unique_ptr<content::PolicyDecisionUtil> navigation(
48       new content::PolicyDecisionUtil());
49   auto* browser_context = WRTBrowserContext::GetInstance();
50   DCHECK(browser_context);
51   navigation->SetNavigationPolicyDecisionCallback(NavigationPolicyDecision);
52   navigation->PolicyNavigation(params, browser_context->GetProxyURI(), handled,
53                                nullptr);
54 #endif
55 }
56
57 } // namespace wrt