Enable the API of setContentSecurityPolicyUsingHeader
authorKamil Lysik <k.lysik@samsung.com>
Thu, 23 Oct 2014 06:59:59 +0000 (14:59 +0800)
committerYoungsoo Choi <kenshin.choi@samsung.com>
Tue, 10 Jul 2018 06:57:09 +0000 (06:57 +0000)
The API is  to set a content security policy based on a header type.

Merge from M34: http://suprem.sec.samsung.net/gerrit/#/c/964/

Together with: I47676118df40c3c9f0deaf9b1d14db548c02a2cf
Bug: http://107.108.218.239/bugzilla/show_bug.cgi?id=9538
Reviewed by: Antonio Gomes, DONGJUN KiM, Piotr Tworek

Change-Id: I594fef3cdaa93e6040c2059be0e99271511804a4
Signed-off-by: Kamil Lysik <k.lysik@samsung.com>
tizen_src/impl/renderer/render_view_observer_efl.cc
tizen_src/impl/web_contents_delegate_efl.cc

index 6b92798e9d934cd84f34b551de746951e59e164c..ea18e0c1b0a3e38c78eccdc132e5908805882d49 100644 (file)
@@ -44,6 +44,20 @@ using blink::WebURLRequest;
 
 namespace {
 
+typedef blink::WebDocument::WebContentSecurityPolicyHeaderType SecurityPolicyHeaderType;
+
+COMPILE_ASSERT(
+    int(SecurityPolicyHeaderType::WebContentSecurityPolicyHeaderTypeReport) ==
+    int(tizen_webview::TW_CSP_REPORT_ONLY), mismatching_enums);
+COMPILE_ASSERT(
+    int(SecurityPolicyHeaderType::WebContentSecurityPolicyHeaderTypeEnforce) ==
+    int(tizen_webview::TW_CSP_ENFORCE_POLICY), mismatching_enums);
+
+SecurityPolicyHeaderType ToSecurityPolicyHeaderType(
+    tizen_webview::ContentSecurityPolicyType type) {
+  return static_cast<SecurityPolicyHeaderType>(type);
+}
+
 bool GetGRBAValuesFromString(const std::string& input, int* r, int* g, int* b, int* a)
 {
   bool parsing_status = false;
@@ -174,22 +188,21 @@ void RenderViewObserverEfl::DidCreateDocumentElement(blink::WebLocalFrame* frame
   tizen_webview::ContentSecurityPolicyType type = TW_CSP_DEFAULT_POLICY;
   Send(new EwkHostMsg_GetContentSecurityPolicy(render_view()->GetRoutingID(), &policy, &type));
 
-#if !defined(EWK_BRINGUP)
   // Since, Webkit supports some more types and we cast ewk type to Webkit type.
   // We allow only ewk types.
-  if (type == TW_CSP_REPORT_ONLY || type == TW_CSP_ENFORCE_POLICY)
-    frame->document().setContentSecurityPolicyUsingHeader(blink::WebString::fromUTF8(policy), type);
-#endif
+  if (type == TW_CSP_REPORT_ONLY || type == TW_CSP_ENFORCE_POLICY) {
+    frame->document().setContentSecurityPolicyUsingHeader(
+        blink::WebString::fromUTF8(policy), ToSecurityPolicyHeaderType(type));
+  }
 }
 
 void RenderViewObserverEfl::OnSetContentSecurityPolicy(const std::string& policy, tizen_webview::ContentSecurityPolicyType header_type)
 {
-#if !defined(EWK_BRINGUP)
   blink::WebView* view = render_view()->GetWebView();
   DCHECK(view);
   blink::WebDocument document = view->mainFrame()->document();
-  document.setContentSecurityPolicyUsingHeader(blink::WebString::fromUTF8(policy), header_type);
-#endif
+  document.setContentSecurityPolicyUsingHeader(blink::WebString::fromUTF8(policy),
+      ToSecurityPolicyHeaderType(header_type));
 }
 
 void RenderViewObserverEfl::OnScale(double scale_factor, int x, int y)
index b4ce9416e7f882ed355152048f0869ab50c4bf9d..66d0449b358144ae4446945b7f71af45adc65fbf 100644 (file)
@@ -401,9 +401,6 @@ void WebContentsDelegateEfl::RequestCertificateConfirm(WebContents* /*web_conten
 }
 
 void WebContentsDelegateEfl::SetContentSecurityPolicy(const std::string& policy, tizen_webview::ContentSecurityPolicyType header_type) {
-  // Might makes sense as it only uses existing functionality already exposed for javascript. Needs extra api at blink side.
-  // Not necessary for eflwebview bringup.
-#if !defined(EWK_BRINGUP)
   if (document_created_) {
     RenderViewHost* rvh = web_contents_.GetRenderViewHost();
     rvh->Send(new EwkViewMsg_SetCSP(rvh->GetRoutingID(), policy, header_type));
@@ -411,7 +408,6 @@ void WebContentsDelegateEfl::SetContentSecurityPolicy(const std::string& policy,
     DCHECK(!pending_content_security_policy_.get());
     pending_content_security_policy_.reset(new ContentSecurityPolicy(policy, header_type));
   }
-#endif
 }
 
 void WebContentsDelegateEfl::ShowPopupMenu(RenderFrameHost* render_frame_host,