[Release] wrt_0.8.191
[platform/framework/web/wrt.git] / src / view / webkit / view_logic.cpp
index 96d7569..aedcd73 100644 (file)
@@ -110,6 +110,14 @@ const int W3C_ORIENTATION_PORTRAIT_PRIMARY_ANGLE = 0;
 const int W3C_ORIENTATION_PORTRAIT_SECONDARY_ANGLE = 180;
 const int W3C_ORIENTATION_LANDSCAPE_PRIMARY_ANGLE = 90;
 const int W3C_ORIENTATION_LANDSCAPE_SECONDARY_ANGLE = -90;
+
+const char* const DEFAULT_ENCODING = "UTF-8";
+#ifdef CSP_ENABLED
+const char* const DEFAULT_CSP_POLICY =
+    "default-src '*'; script-src 'self'; style-src 'self'; object-src 'none';";
+#endif
+// SCHEME
+const char * const SCHEME_BOX_SLASH = "box://";
 } // anonymous namespace
 
 std::map<const std::string,
@@ -649,45 +657,6 @@ void ViewLogic::prepareEwkView(Evas_Object *wkView)
 {
     LogDebug("prepareEwkView called");
     Assert(wkView);
-
-#ifdef CSP_ENABLED
-    LogInfo("Setting CSP default policy");
-    ewk_context_tizen_extensible_api_set(
-        m_ewkContext, EWK_EXTENSIBLE_API_CSP, true);
-    // setting CSP policy rules
-    // temporary turn off
-    //ewk_view_content_security_policy_set(
-    //    wkView,
-    //    "default-src '*'; script-src 'self'; style-src 'self'; object-src 'none';",
-    //    EWK_ENFORCE_POLICY);
-    //LogInfo("Default policy set");
-
-    DPL::OptionalString policy = m_model->CspReportOnlyPolicy.Get();
-
-    if (!(policy.IsNull()))
-    {
-        LogDebug("CSP report only policy present in manifest: " << *policy);
-        ewk_view_content_security_policy_set(
-            wkView, DPL::ToUTF8String(*policy).c_str(), EWK_REPORT_ONLY);
-    } else {
-        LogDebug("Config CSP report only policy is not present");
-    }
-
-    policy = m_model->CspPolicy.Get();
-
-    if (!(policy.IsNull()))
-    {
-        LogDebug("CSP policy present in manifest: " << *policy);
-        ewk_view_content_security_policy_set(
-            wkView, DPL::ToUTF8String(*policy).c_str(), EWK_ENFORCE_POLICY);
-    } else {
-        LogDebug("Config CSP policy is not present");
-    }
-
-
-    LogInfo("CSP set.");
-#endif
-
     Ewk_Settings* settings = ewk_view_settings_get(wkView);
 
     // set user agent
@@ -717,15 +686,6 @@ void ViewLogic::prepareEwkView(Evas_Object *wkView)
 
     // webkit NPAPI plugins is always on in wrt
     ewk_settings_plugins_enabled_set(settings, EINA_TRUE);
-
-    // The followings are not implemeted yet by webkit2
-    //      ewk_view_setting_accelerated_compositing_enable_set(EINA_TRUE);
-    //      ewk_view_mode_set();
-    //      ewk_view_setting_enable_specified_plugin_set(EINA_TRUE,
-    // FLASH_MIME_TYPE);
-    //      ewk_view_setting_html5video_external_player_enable_set(EINA_FALSE);
-    //      ewk_view_show_ime_on_autofocus_set(EINA_TRUE);
-    //      elm_webview_show_magnifier_set(EINA_FALSE);
     ewk_settings_javascript_enabled_set(settings, EINA_TRUE);
     ewk_settings_loads_images_automatically_set(settings, EINA_TRUE);
     // WRT should not fit web contents to device width automatically as default.
@@ -734,34 +694,53 @@ void ViewLogic::prepareEwkView(Evas_Object *wkView)
     ewk_settings_autofill_password_form_enabled_set(settings, EINA_TRUE);
     ewk_settings_form_candidate_data_enabled_set(settings, EINA_TRUE);
 
-    // disable zoom option when user click the input field
-    // this option is useful with the normal website
-    // for the make user friendly, disable auto zoom in the webapp
-    // The followings are not implemeted yet by webkit2
-    //      elm_webview_input_field_zoom_set(EINA_FALSE);
-
-    // set cookie database path
-    // The followings are not implemeted yet by webkit2
-    //      ewk_cookies_file_set(dao.getCookieDatabasePath().c_str()));
-
-    // set visibility to WebCore. This value will be used for html5.
-    // also, this value will be changed in the suspend, resume
-    // or create window, close window.
     ewk_view_page_visibility_state_set(wkView,
                                        EWK_PAGE_VISIBILITY_STATE_VISIBLE,
                                        EINA_TRUE);
 
-    std::string encoding="UTF-8";
-    OptionalWidgetStartFileInfo fileInfo = W3CFileLocalization::getStartFileInfo(m_model->TizenId);
-    if(!fileInfo.IsNull()){
-        encoding=DPL::ToUTF8String((*fileInfo).encoding);
+    std::string encoding = DEFAULT_ENCODING;
+    OptionalWidgetStartFileInfo fileInfo =
+        W3CFileLocalization::getStartFileInfo(m_model->TizenId);
+    if (!fileInfo.IsNull()) {
+        encoding = DPL::ToUTF8String((*fileInfo).encoding);
         LogInfo("Found custom encoding in DB: " << encoding);
     }
     LogInfo("Setting encoding: " << encoding);
-    if(ewk_settings_default_encoding_set(settings,encoding.c_str()))
+    if (ewk_settings_default_encoding_set(settings,encoding.c_str())) {
         LogInfo("Encoding set properly");
-    else
-        LogInfo("Error while setting encoding");
+    } else {
+        LogError("Error while setting encoding");
+    }
+
+#ifdef CSP_ENABLED
+    if (m_model->SecurityModelVersion.Get() ==
+         WrtDB::WidgetSecurityModelVersion::WIDGET_SECURITY_MODEL_V2)
+    {
+        // setting CSP policy rules
+        DPL::OptionalString policy = m_model->CspReportOnlyPolicy.Get();
+        if (!policy.IsNull()) {
+            LogDebug("CSP report only policy present in manifest: " << *policy);
+            ewk_view_content_security_policy_set(
+                wkView,
+                DPL::ToUTF8String(*policy).c_str(),
+                EWK_REPORT_ONLY);
+        }
+
+        policy = m_model->CspPolicy.Get();
+        if (!policy.IsNull()) {
+            LogDebug("CSP policy present in manifest: " << *policy);
+            ewk_view_content_security_policy_set(
+                wkView,
+                DPL::ToUTF8String(*policy).c_str(),
+                EWK_ENFORCE_POLICY);
+        } else {
+            ewk_view_content_security_policy_set(
+                wkView,
+                DEFAULT_CSP_POLICY,
+                EWK_ENFORCE_POLICY);
+        }
+    }
+#endif
 }
 
 void ViewLogic::removeEwkView(Evas_Object *wkView)
@@ -1057,7 +1036,7 @@ void ViewLogic::closeWindowCallback(
 
 void ViewLogic::policyNavigationDecideCallback(
     void* data,
-    Evas_Object* /*obj*/,
+    Evas_Object* obj,
     void* eventInfo)
 {
     LogDebug("policyNavigationDecideCallback called");
@@ -1069,6 +1048,17 @@ void ViewLogic::policyNavigationDecideCallback(
 
     // handle blocked url
     const char* url = ewk_policy_decision_url_get(policyDecision);
+
+    // call user delegate callback
+    if (!This->m_cbs->navigationDecide.empty()) {
+        std::string navigationUri(url);
+        This->m_cbs->navigationDecide(obj, navigationUri);
+        if (!navigationUri.compare(0, 6, SCHEME_BOX_SLASH)) {
+            ewk_policy_decision_ignore(policyDecision);
+            return;
+        }
+    }
+
     if (url && strlen(url) != 0) {
         if (This->m_blockedUri == url) {
             LogDebug("Blocked url = " << url);
@@ -1130,6 +1120,17 @@ void ViewLogic::policyNewWindowDecideCallback(
     Ewk_Policy_Decision* policyDecision =
         static_cast<Ewk_Policy_Decision*>(eventInfo);
 
+    // handle blocked url
+    const char* url = ewk_policy_decision_url_get(policyDecision);
+    if (url && strlen(url) != 0) {
+        if (This->m_blockedUri == url) {
+            LogDebug("Blocked url = " << url);
+            This->m_blockedUri = std::string();
+            ewk_policy_decision_ignore(policyDecision);
+            return;
+        }
+    }
+
     if (This->m_schemeSupport->filterURIByScheme(policyDecision,
                                                  true,
                                                  This->m_model,