[Release] wrt_0.8.191
[platform/framework/web/wrt.git] / src / view / webkit / bundles / wrt-wk2-bundle.cpp
index 25d3595..9c57018 100644 (file)
@@ -52,6 +52,7 @@
 #include <dpl/string.h>
 #include <dpl/wrt-dao-ro/global_config.h>
 #include <dpl/wrt-dao-ro/widget_dao_read_only.h>
+#include <dpl/wrt-dao-ro/common_dao_types.h>
 #include <dpl/utils/mime_type_utils.h>
 #include <dpl/localization/LanguageTagsProvider.h>
 #include <dpl/event/main_event_dispatcher.h>
@@ -96,6 +97,7 @@ const char * const SCHEME_HTTP = "http";
 const char * const SCHEME_HTTPS = "https";
 const char * const SCHEME_FILE = "file";
 const char * const SCHEME_FILE_SLASH = "file://";
+const char * const SCHEME_BOX_SLASH = "box://";
 const char * const DATA_STRING = "data:";
 const char * const BASE64_STRING = ";base64,";
 const char * const BLANK_PAGE_URL = "about:blank";
@@ -158,6 +160,8 @@ Bundle::Bundle(WKBundleRef bundle) :
     m_willRemoveContext(NULL),
     m_encrypted(false),
     m_widgetType(WrtDB::APP_TYPE_UNKNOWN),
+    m_securityModelVersion(
+        WrtDB::WidgetSecurityModelVersion::WIDGET_SECURITY_MODEL_V1),
     m_initialized(false)
 {
     LOG_PROFILE_START("Bundle attachToThread");
@@ -274,12 +278,12 @@ void Bundle::didCreatePage(WKBundlePageRef page)
 
 
     WKBundlePagePolicyClient policyClient = {
-        kWKBundlePagePolicyClientCurrentVersion,        /* version */
-        this,                                           /* clientInfo */
-        pageDecidePolicyForNavigationActionCallback,    /**/
-        0,                                 /* decidePolicyForNewWindowAction */
-        pageDecidePolicyForResponseCallback,    /* decidePolicyForResponse */
-        0,                                      /* unableToImplementPolicy */
+        kWKBundlePagePolicyClientCurrentVersion, /* version */
+        this,                                    /* clientInfo */
+        decidePolicyForNavigationActionCallback, /* decidePolicyForNavigationAction */
+        decidePolicyForNewWindowActionCallback,  /* decidePolicyForNavigationAction */
+        decidePolicyForResponseCallback,         /* decidePolicyForResponse */
+        0,                                       /* unableToImplementPolicy */
     };
     WKBundlePageSetPolicyClient(page, &policyClient);
 }
@@ -511,10 +515,6 @@ void Bundle::didReceiveMessage(WKStringRef messageName, WKTypeRef messageBody)
                 set_app_privilege(tzPkgId.c_str(), PRIVILEGE_APP_TYPE, appPath.c_str());
             }
 
-#ifdef CORS_WHITELISTING_ENABLED
-            bypassCORSforWARPAccessList(dao);
-#endif
-
             /* This type of message is received when widget is restarting
              * (proably in other situation too). Widget restart can be
              * called after system language change so language tags have to
@@ -543,6 +543,10 @@ void Bundle::didReceiveMessage(WKStringRef messageName, WKTypeRef messageBody)
             PluginModule::init(WrtDB::WidgetDAOReadOnly::getHandle(m_widgetTizenId));
             LogDebug("Preload PluginLogicSingleton_end");
 
+            m_securityModelVersion = dao.getSecurityModelVersion();
+#ifdef CORS_WHITELISTING_ENABLED
+            bypassCORSforWARPAccessList(dao);
+#endif
             m_initialized = true;
         }
         else
@@ -733,26 +737,46 @@ void Bundle::didCommitLoadForFrameCallback(
     LOG_PROFILE_STOP("didCommitLoadForFrameCallback");
 }
 
-WKBundlePagePolicyAction Bundle::pageDecidePolicyForNavigationActionCallback(
+WKBundlePagePolicyAction Bundle::decidePolicyForNavigationActionCallback(
     WKBundlePageRef page,
     WKBundleFrameRef frame,
     WKBundleNavigationActionRef navigationAction,
     WKURLRequestRef request,
-    WKTypeRef*                  userData,
-    const void*                 clientInfo)
+    WKTypeRef* userData,
+    const void* clientInfo)
 {
-    LogDebug("pageDecidePolicyForNavigationActionCallback called");
+    LogDebug("decidePolicyForNavigationActionCallback called");
 
     Bundle* This = static_cast<Bundle*>(const_cast<void*>(clientInfo));
+    return This->decidePolicyForAction(false,
+                                       page,
+                                       frame,
+                                       navigationAction,
+                                       request,
+                                       userData);
+}
+
+WKBundlePagePolicyAction Bundle::decidePolicyForNewWindowActionCallback(
+    WKBundlePageRef page,
+    WKBundleFrameRef frame,
+    WKBundleNavigationActionRef navigationAction,
+    WKURLRequestRef request,
+    WKStringRef /*frameName*/,
+    WKTypeRef* userData,
+    const void* clientInfo)
+{
+    LogDebug("decidePolicyForNewWindowActionCallback called");
 
-    return This->pageDecidePolicyForNavigationAction(page,
-                                                     frame,
-                                                     navigationAction,
-                                                     request,
-                                                     userData);
+    Bundle* This = static_cast<Bundle*>(const_cast<void*>(clientInfo));
+    return This->decidePolicyForAction(true,
+                                       page,
+                                       frame,
+                                       navigationAction,
+                                       request,
+                                       userData);
 }
 
-WKBundlePagePolicyAction Bundle::pageDecidePolicyForResponseCallback(
+WKBundlePagePolicyAction Bundle::decidePolicyForResponseCallback(
     WKBundlePageRef /* page */,
     WKBundleFrameRef /* frame */,
     WKURLResponseRef response,
@@ -760,7 +784,7 @@ WKBundlePagePolicyAction Bundle::pageDecidePolicyForResponseCallback(
     WKTypeRef*          /* userData */,
     const void*         /* clientInfo */)
 {
-    LogDebug("pageDecidePolicyForResponseCallback called");
+    LogDebug("decidePolicyForResponseCallback called");
 
     Assert(response);
     WKStringRef contentTypeRef = WKURLResponseEflCopyContentType(response);
@@ -787,17 +811,15 @@ WKURLRequestRef Bundle::willSendRequestForFrame(WKURLRequestRef request)
     WKURLRef url = WKURLRequestCopyURL(request);
     WKStringRef urlStr = WKURLCopyString(url);
 
-    bool is_xhr = true; // Webkit should inform if it's XHR
     DPL::String dplurl = DPL::FromUTF8String(toString(urlStr));
     WKRelease(urlStr);
 
     DPL::Optional<DPL::String> localizedUrl =
         BundleURIHandling::localizeURI(dplurl, m_widgetTizenId);
-    bool ret = BundleURIHandling::processURI(
-            *localizedUrl,
-            is_xhr,
-            m_widgetTizenId,
-            m_bundle);
+    bool ret =
+        BundleURIHandling::processURI(*localizedUrl,
+                                      m_widgetTizenId,
+                                      m_securityModelVersion);
 
     if (!ret) {
         LogDebug("Not permitted resource: " << *localizedUrl);
@@ -869,12 +891,13 @@ WKURLRequestRef Bundle::willSendRequestForFrame(WKURLRequestRef request)
     }
 }
 
-WKBundlePagePolicyAction Bundle::pageDecidePolicyForNavigationAction(
+WKBundlePagePolicyAction Bundle::decidePolicyForAction(
+    bool isNewWindow,
     WKBundlePageRef /* page */,
     WKBundleFrameRef frame,
     WKBundleNavigationActionRef /* navigationAction */,
     WKURLRequestRef request,
-    WKTypeRef*                  /* userData */)
+    WKTypeRef* /* userData */)
 {
     using namespace ViewModule;
     using namespace ViewModule::SchemeActionMap;
@@ -890,14 +913,18 @@ WKBundlePagePolicyAction Bundle::pageDecidePolicyForNavigationAction(
         return WKBundlePagePolicyActionUse;
     }
 
-    // WARP & ACE Check
+    // in case of box scheme, unconditionally PassThrough should be returned
+    if (!request_uri.compare(0, 6, SCHEME_BOX_SLASH)) {
+        return WKBundlePagePolicyActionPassThrough;
+    }
+
     DPL::String dplUrl = DPL::FromUTF8String(request_uri);
-    DPL::Optional<DPL::String> localizedUrl =
-        BundleURIHandling::localizeURI(dplUrl, m_widgetTizenId);
-    bool ret = BundleURIHandling::processURI(
-            *localizedUrl, true, m_widgetTizenId, m_bundle);
+    bool ret =
+        BundleURIHandling::processMainResource(dplUrl,
+                                               m_widgetTizenId,
+                                               m_securityModelVersion);
     if (!ret) {
-        std::string blockedUrl = DPL::ToUTF8String(*localizedUrl);
+        std::string blockedUrl = DPL::ToUTF8String(dplUrl);
         LogDebug("URI is blocked: " << blockedUrl);
 
         // Send information about blocked URI to UIProcess
@@ -931,6 +958,9 @@ WKBundlePagePolicyAction Bundle::pageDecidePolicyForNavigationAction(
 
     bool mainFrame = WKBundleFrameIsMainFrame(frame);
     NavigationContext ctx = mainFrame ? TOP_LEVEL : FRAME_LEVEL;
+    if (isNewWindow) {
+        ctx = NEW_WINDOW;
+    }
 
     LogDebug("Scheme type: " << type);
     LogDebug("Navigation context: " << ctx);
@@ -938,9 +968,7 @@ WKBundlePagePolicyAction Bundle::pageDecidePolicyForNavigationAction(
 
     UriAction action;
 
-    if (m_widgetType == WrtDB::APP_TYPE_WAC20) {
-        action = g_wacActionMap[type][ctx];
-    } else if (m_widgetType == WrtDB::APP_TYPE_TIZENWEBAPP) {
+    if (m_widgetType == WrtDB::APP_TYPE_TIZENWEBAPP) {
         action = g_tizenActionMap[type][ctx];
     } else {
         LogError("Unsupported application type: " << type);