Merge "fix: use EINA_* booleans instread of TRUE/FALSE" into tizen
[platform/framework/web/wrt.git] / src / view / webkit / injected-bundle / wrt-injected-bundle.cpp
index c4c87d1..5cc22ab 100644 (file)
 #include <string>
 #include <cstdio>
 #include <sstream>
-#include <sys/stat.h>
 #include <set>
-#include <openssl/sha.h>
-#include <openssl/hmac.h>
-#include <openssl/evp.h>
-#include <openssl/bio.h>
-#include <openssl/buffer.h>
+#include <memory>
 
-#include <dpl/log/log.h>
 #include <dpl/foreach.h>
 #include <dpl/assert.h>
 #include <dpl/wrt-dao-ro/WrtDatabase.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>
-#ifdef DECRYPT
-#include <FBaseByteBuffer.h>
-#include <security/FSecCrypto_TrustZoneService.h>
-#endif
 
+#include <dpl/log/secure_log.h>
 #include <wrt_plugin_module.h>
 #include <profiling_util.h>
 
-#include <vconf.h>
 #include <appcore-efl.h>
 
-#include "messages_names.h"
+#include <message_support.h>
 
 #include <scheme.h>
 #include <scheme_action_map_type.h>
 #include <scheme_action_map_data.h>
 
 #include <js_overlay_types.h>
+#include <dispatch_event_support.h>
+#include <plugins-ipc-message/ipc_message_support.h>
 
-#include <sys/time.h>
 #include <sys/resource.h>
 #include <privilege-control.h>
+#include <smack_labeling_support.h>
 
 // URI localization on WebProcess side
 #include "injected_bundle_uri_handling.h"
-extern "C" {
-void InitWebAppInfo(const char* appId, const char* rootPath);
-}
+#include "injected_bundle_decryption_support.h"
+#include "injected_bundle_viewmodes_support.h"
 
 namespace {
-const char * const uriBlockedMessageName = "uri_blocked_msg";
-#ifdef MULTIPROCESS_SERVICE_SUPPORT_INLINE
-const char * const webProcessPidMessageName = "web_process_pid_msg";
-#endif
-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";
-const char * const HTML_MIME = "text/html";
-const char * const PHP_MIME = "application/x-php";
-const char * const VIEWMODE_TYPE_FULLSCREEN = "fullscreen";
-const char * const VIEWMODE_TYPE_MAXIMIZED = "maximized";
+const char SCHEME_HTTP[] = "http";
+const char SCHEME_HTTPS[] = "https";
+const char SCHEME_FILE[] = "file";
+const char SCHEME_FILE_SLASH[] = "file://";
+const char SCHEME_BOX_SLASH[] = "box://";
+const char BLANK_PAGE_URL[] = "about:blank";
+const char SRC_DOC_PAGE_URL[] = "about:srcdoc";
+const char HTML_MIME[] = "text/html";
+const char PHP_MIME[] = "application/x-php";
+const char WRT_WILL_SEND_REQUEST_LOG_ENABLE[] = "WRT_WILL_SEND_REQUEST_LOG_ENABLE";
 const std::size_t FILE_BUF_MAX_SIZE = 1024; // bytes
 const std::size_t PLAIN_CHUNK_SIZE = 1008; // bytes
 const unsigned int UID_ROOT = 0;
 const unsigned int DEFAULT_PRIORITY = 0;
-const char * const PRIVILEGE_APP_TYPE = "wgt";
+const char PRIVILEGE_APP_TYPE[] = "wgt";
 #ifdef CORS_WHITELISTING_ENABLED
 const char * const warpAllowProtocolsForWildcard[] = { "http", "https" };
 #endif
-
-#ifdef DECRYPT
-static bool m_initWebApp = false;
-
-Tizen::Base::ByteBuffer *DecryptChunkByTrustZone(
-        Tizen::Base::ByteBuffer *appInfo,
-        const unsigned char *inBuffer,
-        int inBufSize)
-{
-    using namespace Tizen::Base;
-
-    if (!m_initWebApp) {
-        char* pAppId = null;
-        pAppId = (char*)calloc(appInfo->GetRemaining()+1, 1);
-        memcpy(pAppId, appInfo->GetPointer(), appInfo->GetRemaining());
-
-        InitWebAppInfo(pAppId, "");
-        free (pAppId);
-        m_initWebApp = true;
-    }
-
-    Tizen::Security::Crypto::_TrustZoneService* pInstance;
-    pInstance = Tizen::Security::Crypto::_TrustZoneService::GetInstance();
-
-    ByteBuffer pBuf;
-    pBuf.Construct(inBufSize);
-    const byte *pByte = reinterpret_cast<const byte*>(inBuffer);
-
-    if (pBuf.SetArray(pByte, 0, inBufSize) != E_SUCCESS) {
-        LogDebug("Couldnot set pBuf");
-        return NULL;
-    }
-
-    pBuf.Flip();
-
-    return pInstance->_TrustZoneService::DecryptN(*appInfo, pBuf);
-}
-#endif // DECRYPT
-
 }
 
 Bundle::Bundle(WKBundleRef bundle) :
@@ -157,18 +102,19 @@ Bundle::Bundle(WKBundleRef bundle) :
     m_encodedBundle(""),
     m_theme(""),
     m_willRemoveContext(NULL),
-    m_encrypted(false),
-    m_widgetType(WrtDB::APP_TYPE_UNKNOWN),
     m_securityModelVersion(
         WrtDB::WidgetSecurityModelVersion::WIDGET_SECURITY_MODEL_V1),
-    m_initialized(false)
+    m_initialized(false),
+    m_decryptionSupport(new InjectedBundle::DecryptionSupport())
 {
-    LOG_PROFILE_START("Bundle attachToThread");
-    WrtDB::WrtDatabase::attachToThreadRO();
-    LOG_PROFILE_STOP("Bundle attachToThread");
-#ifdef MULTIPROCESS_SERVICE_SUPPORT_INLINE
-    sendWebProcessPid();
-#endif
+    Try {
+        LOG_PROFILE_START("Bundle attachToThread");
+        WrtDB::WrtDatabase::attachToThreadRO();
+        LOG_PROFILE_STOP("Bundle attachToThread");
+    } Catch (DPL::DB::SqlConnection::Exception::Base) {
+        _E("## Db attach was failed! Terminate WebProcess by force. ##");
+        exit(-1);
+    }
 }
 
 Bundle::~Bundle()
@@ -176,7 +122,7 @@ Bundle::~Bundle()
     WrtDB::WrtDatabase::detachFromThread();
 
     if (!m_pagesList.empty()) {
-        LogError("There are not closed pages!");
+        _E("There are not closed pages!");
     }
     WKRelease(m_bundle);
 }
@@ -187,7 +133,6 @@ void Bundle::didCreatePageCallback(
     const void* clientInfo)
 {
     LOG_PROFILE_START("didCreatePageCallback");
-    LogDebug("didCreatePageCallback called");
     Bundle* This = static_cast<Bundle*>(const_cast<void*>(clientInfo));
     This->didCreatePage(page);
     LOG_PROFILE_STOP("didCreatePageCallback");
@@ -199,7 +144,6 @@ void Bundle::didReceiveMessageCallback(
     WKTypeRef messageBody,
     const void *clientInfo)
 {
-    LogDebug("didReceiveMessageCallback called");
     Bundle* bundle = static_cast<Bundle*>(const_cast<void*>(clientInfo));
     bundle->didReceiveMessage(messageName, messageBody);
 }
@@ -209,18 +153,24 @@ void Bundle::willDestroyPageCallback(
     WKBundlePageRef page,
     const void* clientInfo)
 {
-    LogDebug("willDestroyPageCallback called");
     Bundle* This = static_cast<Bundle*>(const_cast<void*>(clientInfo));
     This->willDestroyPage(page);
 }
 
 void Bundle::didCreatePage(WKBundlePageRef page)
 {
+    if (!m_initialized)
+    {
+        _E("## Injected-bundle was not initialized! Terminate WebProcess by force. ##");
+        exit(-1);
+    }
+
     auto mainFrame = WKBundlePageGetMainFrame(page);
     auto context = WKBundleFrameGetJavaScriptContext(mainFrame);
     m_pagesList.push_back(page);
     m_pageGlobalContext.insertContextForPage(page, context);
-    LogDebug("created Page : " << page << " created JSContext : " << context);
+    _D("created Page : %p created JSContext : %p", page, context);
+    m_viewmodesSupport->initialize(page);
 
     WKBundlePageResourceLoadClient resourceLoadClient = {
         kWKBundlePageResourceLoadClientCurrentVersion,  /* version */
@@ -229,7 +179,7 @@ void Bundle::didCreatePage(WKBundlePageRef page)
         willSendRequestForFrameCallback, /* willSendRequestForFrame */
         0, /* didReceiveResponseForResource */
         0, /* didReceiveContentLengthForResource */
-        didFinishLoadForResourceCallback, /* didFinishLoadForResource */
+        0, /* didFinishLoadForResource */
         0, /* didFailLoadForResource */
         0, /* shouldCacheResponse */
         0, /* shouldUseCredentialStorage */
@@ -286,12 +236,13 @@ void Bundle::didCreatePage(WKBundlePageRef page)
 
 void Bundle::willDestroyPage(WKBundlePageRef page)
 {
-    LogDebug("Destroyed page : " << page);
+    _D("Destroyed page : %p", page);
 
     auto context = m_pageGlobalContext.getContextForPage(page);
     m_pagesList.remove(page);
     m_pageGlobalContext.removeContextForPage(page);
     m_pageContext[page].erase(context);
+    m_viewmodesSupport->deinitialize(page);
 
     PluginModule::unloadFrame(context);
     PluginModule::stop(context);
@@ -338,8 +289,10 @@ void Bundle::bypassCORSforWARPAccessList(WrtDB::WidgetDAOReadOnly & dao)
         std::string source = DPL::ToUTF8String(dao.getFullPath());
 #endif
 
-        LogDebug("WARP to WK whitelist position: " << source << " for "
-            << access.strIRI << " subDomains: " << access.bSubDomains);
+        _D("WARP to WK whitelist position: %s for %s subDomains: %d",
+           source.c_str(),
+           DPL::ToUTF8String(access.strIRI).c_str(),
+           access.bSubDomains);
 
         WKStringRef wkSource = WKStringCreateWithUTF8CString(source.c_str());
         WKStringRef wkHost;
@@ -373,20 +326,18 @@ void Bundle::bypassCORSforWARPAccessList(WrtDB::WidgetDAOReadOnly & dao)
 
 void Bundle::didReceiveMessage(WKStringRef messageName, WKTypeRef messageBody)
 {
-    LogDebug("got message type: " << toString(messageName).c_str());
+    _D("message name: %s", toString(messageName).c_str());
     if (WKStringIsEqualToUTF8CString(messageName,
-                                     BundleMessages::START))
+                                     Message::ToInjectedBundle::START))
     {
         if (!messageBody || WKStringGetTypeID() != WKGetTypeID(messageBody)) {
-            LogError("Wrong message format received, ignoring");
+            _E("Wrong message format received, ignoring");
             return;
         }
 
-        auto msgString = toString(static_cast<WKStringRef>(messageBody));
-        LogDebug("Got message text: " << msgString);
-        LogDebug("loading Page : " << m_pagesList.back() <<
-                 " loading JSContext : " <<
-                 m_pageGlobalContext.getContextForPage(m_pagesList.back()));
+        std::string msgString =
+            toString(static_cast<WKStringRef>(messageBody));
+        _D("message body: %s", msgString.c_str());
         // set information from ui process
         std::stringstream ssMsg(msgString);
         std::string argScale;
@@ -400,30 +351,26 @@ void Bundle::didReceiveMessage(WKStringRef messageName, WKTypeRef messageBody)
         ssMsg >> argScale;
         ssMsg >> argEncodedBundle;
         ssMsg >> argTheme;
-        ssMsg >> m_encrypted;
-        LogWarning("m_encrypted : " << m_encrypted);
 
         // ** Language tags setting completed **
         fixWKMessageArgs(argScale, argEncodedBundle, argTheme);
     } else if (WKStringIsEqualToUTF8CString(messageName,
-                                            BundleMessages::SHUTDOWN))
+                                            Message::ToInjectedBundle::SHUTDOWN))
     {
-        LogDebug("shutdown plugins");
-
         if (m_pagesList.empty()) {
+            _D("shutdown plugins");
             PluginModule::shutdown();
         } else {
-            LogInfo(
-                "PluginModule shutdown ignored, there are still alive pages!");
+            _D("PluginModule shutdown ignored, there are still alive pages!");
         }
     }
     else if (WKStringIsEqualToUTF8CString(messageName,
-                                          BundleMessages::SET_CUSTOM_PROPERTIES))
+                                          Message::ToInjectedBundle::SET_CUSTOM_PROPERTIES))
     {
-        LogDebug("reset custom properties of window objects");
         // set information from ui process
-        auto msgString = toString(static_cast<WKStringRef>(messageBody));
-
+        std::string msgString =
+            toString(static_cast<WKStringRef>(messageBody));
+        _D("message body: %s", msgString.c_str());
         std::string argScale;
         std::string argEncodedBundle;
         std::string argTheme;
@@ -445,54 +392,51 @@ void Bundle::didReceiveMessage(WKStringRef messageName, WKTypeRef messageBody)
         }
     } else if (WKStringIsEqualToUTF8CString(
                    messageName,
-                   BundleMessages::DISPATCH_JAVASCRIPT_EVENT))
+                   Message::ToInjectedBundle::DISPATCH_JS_EVENT))
     {
-        LogDebug("dispatch javascript event to created frames");
+        _D("dispatch javascript event to created frames");
+        using namespace WrtPlugins::W3C;
+
         // set information from ui process
-        auto text = toString(static_cast<WKStringRef>(messageBody));
+        std::string text = toString(static_cast<WKStringRef>(messageBody));
         int eventType;
-        void *args = NULL;
+        SoftKeyboardChangeArgs softKeyboardArgs;
+
         std::stringstream ss(text);
         ss >> eventType;
 
-        using namespace WrtPlugins::W3C;
-        // set arguments to be sent to js handler of this custom event
-        if (eventType == SoftKeyboardChangeCustomEvent) {
-            args = new SoftKeyboardChangeArgs;
-            ss >> static_cast<SoftKeyboardChangeArgs *>(args)->state;
-            ss >> static_cast<SoftKeyboardChangeArgs *>(args)->width;
-            ss >> static_cast<SoftKeyboardChangeArgs *>(args)->height;
+        if (eventType == SoftKeyboardChangeCustomEvent)
+        {
+            ss >> softKeyboardArgs.state;
+            ss >> softKeyboardArgs.width;
+            ss >> softKeyboardArgs.height;
         }
 
         //apply for each context
         PageGlobalContextContainer::const_iterator it = m_pageGlobalContext.begin();
-        for (; it != m_pageGlobalContext.end(); ++it) {
-            PluginModule::dispatchJavaScriptEvent(
-                it->second,
-                static_cast<WrtPlugins::W3C::CustomEventType>(eventType),
-                args);
-        }
 
-        if (args) {
-            delete static_cast<SoftKeyboardChangeArgs *>(args);
+        for (; it != m_pageGlobalContext.end(); ++it)
+        {
+            if (eventType == SoftKeyboardChangeCustomEvent)
+            {
+                DispatchEventSupport::dispatchSoftKeyboardChangeEvent(it->second,
+                                                    softKeyboardArgs.state,
+                                                    softKeyboardArgs.width,
+                                                    softKeyboardArgs.height);
+            }
         }
     } else if (WKStringIsEqualToUTF8CString(
                    messageName,
-                   BundleMessages::INIT))
+                   Message::ToInjectedBundle::INIT))
     {
-        LogDebug("initializing plugins");
-
-        if (!m_initialized)
-        {
-            auto msgString = toString(static_cast<WKStringRef>(messageBody));
-
+        if (!m_initialized) {
+            _D("initialize");
+            std::string msgString = toString(static_cast<WKStringRef>(messageBody));
             m_widgetTizenId = DPL::FromASCIIString(msgString);
-
             WrtDB::WidgetDAOReadOnly dao(m_widgetTizenId);
 
             // process pool - set app_privilige
-            if (UID_ROOT == getuid())
-            {
+            if (UID_ROOT == getuid()) {
                 using namespace WrtDB::GlobalConfig;
 
                 std::string appPath;
@@ -507,8 +451,13 @@ void Bundle::didReceiveMessage(WKStringRef messageName, WKTypeRef messageBody)
                         GetUserWidgetExecPath() + "/" + tzAppId;
                 }
 
-                LogDebug("set_app_privilege(" << appPath << ")");
-                set_app_privilege(tzPkgId.c_str(), PRIVILEGE_APP_TYPE, appPath.c_str());
+                _D("set_app_smack_label(%s)", appPath.c_str());
+                if (set_app_smack_label(appPath.c_str()) != 0) {
+                    _E("set_app_smack_label() failed");
+                }
+
+                _D("perm_app_set_privilege(%s)", appPath.c_str());
+                perm_app_set_privilege(tzPkgId.c_str(), PRIVILEGE_APP_TYPE, appPath.c_str());
             }
 
             /* This type of message is received when widget is restarting
@@ -526,28 +475,78 @@ void Bundle::didReceiveMessage(WKStringRef messageName, WKTypeRef messageBody)
             }
             LanguageTags tags =
                 LanguageTagsProviderSingleton::Instance().getLanguageTags();
-            LogDebug("Current widget locales (language tags):");
+            _D("Current widget locales (language tags):");
             FOREACH(it, tags) {
-                LogDebug("Locale: " << *it);
+                _D("Locale: %s", DPL::ToUTF8String(*it).c_str());
             }
 
-            m_widgetType = dao.getWidgetType();
-            LogDebug("m_widgetType : " << m_widgetType.getApptypeToString() <<
-                     "(m_widgetTizenId:" << m_widgetTizenId << ")");
-
-            LogDebug("Preload PluginLogicSingleton");
+            _D("Preload PluginLogicSingleton");
             PluginModule::init(WrtDB::WidgetDAOReadOnly::getHandle(m_widgetTizenId));
-            LogDebug("Preload PluginLogicSingleton_end");
+            _D("Preload PluginLogicSingleton_end");
 
             m_securityModelVersion = dao.getSecurityModelVersion();
 #ifdef CORS_WHITELISTING_ENABLED
             bypassCORSforWARPAccessList(dao);
 #endif
+            m_decryptionSupport->initialize(m_widgetTizenId);
+            m_viewmodesSupport.reset(
+                new InjectedBundle::ViewmodesSupport(m_widgetTizenId));
             m_initialized = true;
+        } else {
+            _D("already initalized");
         }
-        else
-        {
-            LogDebug("already initalized");
+    } else if (WKStringIsEqualToUTF8CString(
+                   messageName,
+                   Message::ToInjectedBundle::SET_XWINDOW_HANDLE))
+    {
+            std::string msgString =
+                toString(static_cast<WKStringRef>(messageBody));
+#if 0 // sub mode disable
+            _D("set x window handle [%s]", msgString.c_str());
+            IPCMessageSupport::setXwindowHandle(atoi(msgString.c_str()));
+#else
+            _D("sub mode is disabled, set x window handle [NULL]");
+#endif
+
+    } else if (WKStringIsEqualToUTF8CString(
+                   messageName,
+                   Message::ToInjectedBundle::SET_VIEWMODES))
+    {
+        std::string msgBody =
+            toString(static_cast<WKStringRef>(messageBody));
+        _D("set viewmode to [%s]", msgBody.c_str());
+        if (msgBody == Message::ToInjectedBundle::SET_VIEWMODES_MSGBODY_EXIT) {
+            m_viewmodesSupport->exitViewmodesAllPages();
+        } else {
+            m_viewmodesSupport->enterViewmodesAllPages(msgBody);
+        }
+    }
+    else if (WKStringIsEqualToUTF8CString(messageName, IPCMessageSupport::REPLY_ASYNC))
+    {
+        using namespace IPCMessageSupport;
+
+        std::string msgBody = toString(static_cast<WKStringRef>(messageBody));
+
+        if (msgBody.find_first_of('_') != std::string::npos) {
+            std::string strHandle = msgBody.substr(0, msgBody.find_first_of('_'));
+            std::string strBody = msgBody.substr(msgBody.find_first_of('_')+1);
+
+            _D("handle: %s, , Body: %s", strHandle.c_str(), strBody.c_str());
+
+            int handle = atoi(strHandle.c_str());
+
+            AsyncConnectionPtr connection = AsyncConnectionManager::instance().getConnection(handle);
+
+            if (connection) {
+                if (connection->replyCallback) {
+                    _D("connection->replyCallback()");
+                    (connection->replyCallback)(handle, connection->data, strBody.c_str());
+                }
+
+                AsyncConnectionManager::instance().removeConnection(handle);
+            } else {
+                _D("Connection is not available. Ignored.");
+            }
         }
     }
 }
@@ -560,9 +559,10 @@ WKURLRequestRef Bundle::willSendRequestForFrameCallback(
     WKURLResponseRef /*response*/,
     const void *clientInfo)
 {
-    LogDebug("willSendRequestForFrameCallback called");
     Bundle* This = static_cast<Bundle*>(const_cast<void*>(clientInfo));
-    return This->willSendRequestForFrame(request);
+    WKURLRequestRef ret = This->willSendRequestForFrame(request);
+
+    return ret;
 }
 
 void Bundle::didStartProvisionalLoadForFrameCallback(
@@ -571,24 +571,9 @@ void Bundle::didStartProvisionalLoadForFrameCallback(
     WKTypeRef* /*userData*/,
     const void *clientInfo)
 {
-    LogDebug("didStartProvisionalLoadForFrameCallback called");
+    _D("called");
     Bundle* This = static_cast<Bundle*>(const_cast<void*>(clientInfo));
 
-    // set viewmode
-    WrtDB::WidgetDAOReadOnly dao(This->m_widgetTizenId);
-    WrtDB::WindowModeList modeList = dao.getWindowModes();
-    FOREACH(it, modeList) {
-        std::string viewMode = DPL::ToUTF8String(*it);
-        if (viewMode == VIEWMODE_TYPE_FULLSCREEN
-            || viewMode == VIEWMODE_TYPE_MAXIMIZED)
-        {
-            WKBundlePageSetViewMode(
-                page,
-                WKStringCreateWithUTF8CString(viewMode.c_str()));
-            break;
-        }
-    }
-
     if (This->m_pageGlobalContext.find(page) == This->m_pageGlobalContext.end()) {
         return;
     }
@@ -601,7 +586,7 @@ void Bundle::didStartProvisionalLoadForFrameCallback(
     ContextSet::iterator i = This->m_pageContext[page].find(context);
 
     if (i == This->m_pageContext[page].end()) {
-        LogDebug("Initially attached frame");
+        _D("Initially attached frame");
         return;
     }
 
@@ -615,11 +600,11 @@ void Bundle::didRemoveFrameFromHierarchyCallback(
     WKTypeRef* /*userData*/,
     const void *clientInfo)
 {
-    LogDebug("didRemoveFrameFromHierarchyCallback called");
+    _D("called");
     Bundle* This = static_cast<Bundle*>(const_cast<void*>(clientInfo));
 
     if (This->m_pageContext.count(page) == 0) {
-        LogDebug("his->m_pageContext.count(page) == 0");
+        _D("his->m_pageContext.count(page) == 0");
         return;
     }
 
@@ -628,7 +613,7 @@ void Bundle::didRemoveFrameFromHierarchyCallback(
     ContextSet::iterator i = This->m_pageContext[page].find(context);
 
     if (i == This->m_pageContext[page].end()) {
-        LogWarning("Tried to unload frame which has never been loaded");
+        _W("Tried to unload frame which has never been loaded");
         return;
     }
 
@@ -643,7 +628,7 @@ void Bundle::didFinishLoadForResourceCallback(
     uint64_t /*resourceIdentifier*/,
     const void* /*clientInfo*/)
 {
-    LogDebug("didFinishLoadForResourceCallback called");
+    _D("called");
 }
 
 void Bundle::didCommitLoadForFrameCallback(
@@ -652,14 +637,14 @@ void Bundle::didCommitLoadForFrameCallback(
     WKTypeRef* /*userData*/,
     const void *clientInfo)
 {
-    LogInfo("didCommitLoadForFrameCallback called");
+    _D("called");
     LOG_PROFILE_START("didCommitLoadForFrameCallback");
     Bundle* This = static_cast<Bundle*>(const_cast<void*>(clientInfo));
 
     WKURLRef url = WKBundleFrameCopyURL(frame);
 
     if (url == NULL) {
-        LogInfo("url is NULL");
+        _W("url is NULL");
         return;
     }
 
@@ -673,7 +658,7 @@ void Bundle::didCommitLoadForFrameCallback(
     This->m_pageContext[page].insert(context);
 
     if (!WKBundleFrameIsMainFrame(frame)) {
-        LogInfo("frame isn't main frame");
+        _D("frame isn't main frame");
         PluginModule::start(
             WrtDB::WidgetDAOReadOnly::getHandle(This->m_widgetTizenId),
             context,
@@ -685,14 +670,15 @@ void Bundle::didCommitLoadForFrameCallback(
     }
 
     std::string urlStr = toString(url);
+
     if (InjectedBundleURIHandling::processURIForPlugin(urlStr.c_str())) {
-        LogDebug("start plugin");
+        _D("start plugin");
         if(This->m_pageGlobalContext.find(page) != This->m_pageGlobalContext.end())
         {
-            LogDebug("Previous context: " << This->m_pageGlobalContext.getContextForPage(page));
+            _D("Previous context: %p", This->m_pageGlobalContext.getContextForPage(page));
             PluginModule::stop(This->m_pageGlobalContext.getContextForPage(page));
         }
-        LogDebug("New context: " << context);
+        _D("New context: %p", context);
         //note that since we need old context for unloading plugins it must be sotred
         //custom container take care of increamenting and decrementing references
         This->m_pageGlobalContext.insertContextForPage(page, context);
@@ -707,13 +693,13 @@ void Bundle::didCommitLoadForFrameCallback(
 
         PluginModule::loadFrame(context);
     } else {
-        LogDebug("stop plugin");
+        _D("stop plugin");
         if(This->m_pageGlobalContext.find(page) != This->m_pageGlobalContext.end())
         {
-            LogDebug("Previous context: " << This->m_pageGlobalContext.getContextForPage(page));
+            _D("Previous context: %p", This->m_pageGlobalContext.getContextForPage(page));
             PluginModule::stop(This->m_pageGlobalContext.getContextForPage(page));
         }
-        LogDebug("New context: " << context);
+        _D("New context: %p", context);
         This->m_pageGlobalContext.insertContextForPage(page, context);
     }
     LOG_PROFILE_STOP("didCommitLoadForFrameCallback");
@@ -727,8 +713,7 @@ WKBundlePagePolicyAction Bundle::decidePolicyForNavigationActionCallback(
     WKTypeRef* userData,
     const void* clientInfo)
 {
-    LogDebug("decidePolicyForNavigationActionCallback called");
-
+    _D("called");
     Bundle* This = static_cast<Bundle*>(const_cast<void*>(clientInfo));
     return This->decidePolicyForAction(false,
                                        page,
@@ -747,8 +732,7 @@ WKBundlePagePolicyAction Bundle::decidePolicyForNewWindowActionCallback(
     WKTypeRef* userData,
     const void* clientInfo)
 {
-    LogDebug("decidePolicyForNewWindowActionCallback called");
-
+    _D("called");
     Bundle* This = static_cast<Bundle*>(const_cast<void*>(clientInfo));
     return This->decidePolicyForAction(true,
                                        page,
@@ -766,21 +750,20 @@ WKBundlePagePolicyAction Bundle::decidePolicyForResponseCallback(
     WKTypeRef*          /* userData */,
     const void*         /* clientInfo */)
 {
-    LogDebug("decidePolicyForResponseCallback called");
-
+    _D("called");
     Assert(response);
     WKStringRef contentTypeRef = WKURLResponseEflCopyContentType(response);
 
     std::string contentType = toString(contentTypeRef);
-    LogDebug("contentTypeRef : " << contentType);
+    _D("contentTypeRef : %s", contentType.c_str());
     WKRelease(contentTypeRef);
 
     if (contentType == HTML_MIME) {
-        LogDebug("Accepting HTML_MIME type");
+        _D("Accepting HTML_MIME type");
         return WKBundlePagePolicyActionUse;
     }
     if (contentType == PHP_MIME) {
-        LogDebug("Accepting php type");
+        _D("Accepting php type");
         return WKBundlePagePolicyActionUse;
     }
 
@@ -789,38 +772,46 @@ WKBundlePagePolicyAction Bundle::decidePolicyForResponseCallback(
 
 WKURLRequestRef Bundle::willSendRequestForFrame(WKURLRequestRef request)
 {
-    LogDebug("willSendReq got " << toString(request).c_str());
-    WKURLRef url = WKURLRequestCopyURL(request);
-    WKStringRef urlStr = WKURLCopyString(url);
+    static bool logEnable = (getenv(WRT_WILL_SEND_REQUEST_LOG_ENABLE) != NULL);
 
-    DPL::String dplurl = DPL::FromUTF8String(toString(urlStr));
-    WKRelease(urlStr);
+    WKURLRef    wkUrl   = WKURLRequestCopyURL(request);
+    WKStringRef wkStr   = WKURLCopyString(wkUrl);
 
-    DPL::Optional<DPL::String> localizedUrl =
-        InjectedBundleURIHandling::localizeURI(dplurl, m_widgetTizenId);
-    bool ret =
-        InjectedBundleURIHandling::processURI(*localizedUrl,
-                                             m_widgetTizenId,
-                                             m_securityModelVersion);
+    std::string stdUrl  = Bundle::toString(wkStr);
+    std::string localizedUrl;
 
-    if (!ret) {
-        LogDebug("Not permitted resource: " << *localizedUrl);
-        return NULL;
-    }
+    WKRelease(wkStr);
+    WKRelease(wkUrl);
 
-    LogDebug("URI processing result: " << *localizedUrl);
-    std::string tmpUrlStr = DPL::ToUTF8String(*localizedUrl);
-    WKURLRef tmpUrl = WKURLCreateWithUTF8CString(tmpUrlStr.c_str());
-    std::string scheme = toString(WKURLCopyScheme(url)); //scheme of original request
-    WKRelease(url);
+    if (logEnable){ _D("willSendRequestForFrame : %s", stdUrl.c_str()); }
+
+    std::string scheme = stdUrl.substr(0, stdUrl.find_first_of(':'));
 
 #ifdef APP_SCHEME_ENABLED
-    if(scheme == SCHEME_FILE) {
-        LogError("File schema blocked for: " << dplurl);
+    if (scheme == SCHEME_FILE) {
+        _E("File schema blocked for: %s", stdUrl.c_str());
         return NULL;
     }
 #endif
 
+    // "about:blank"/"about:srcdoc" uri doesn't need uri processing.
+    if (stdUrl == BLANK_PAGE_URL || stdUrl == SRC_DOC_PAGE_URL) {
+        WKRetain(request);
+        return request;
+    }
+
+    localizedUrl = InjectedBundleURIHandling::localizeURI(stdUrl, DPL::ToUTF8String(m_widgetTizenId));
+    bool ret = InjectedBundleURIHandling::processURI(localizedUrl, m_widgetTizenId, m_securityModelVersion);
+
+    if (!ret) {
+        _D("Not permitted resource: %s", localizedUrl.c_str());
+        return NULL;
+    }
+
+    // log disabled for performance
+    //LogDebug("URI processing result: " << result);
+    scheme = localizedUrl.substr(0, localizedUrl.find_first_of(':'));
+
     // Return value must contain details information of input
     // WKURLRequestRef. Current webkit2 doesn't support api that
     // copy WKURLRequestRef or change url only. Before webkit2
@@ -829,48 +820,37 @@ WKURLRequestRef Bundle::willSendRequestForFrame(WKURLRequestRef request)
 
     // external scheme also need to send message to UI process for
     // checking roaming and security
+
     if (scheme == SCHEME_HTTP || scheme == SCHEME_HTTPS) {
-        LogDebug("external scheme return original WKURLRequestRef");
-        WKRelease(tmpUrl);
+        if (logEnable){ _D("external scheme return original WKURLRequestRef"); }
         WKRetain(request);
+
         return request;
     } else {
-        std::string checkUrl = toString(tmpUrl);
-
-        if (m_encrypted) {
-            int getFileSize;
-            if (isEncryptedResource(checkUrl, getFileSize)) {
-                std::string decryptString = DecryptResource(checkUrl,
-                                                            getFileSize);
-                if (!decryptString.empty()) {
-                    std::string destString = DATA_STRING;
-
-                    std::string mimeString =
-                        DPL::ToUTF8String(
-                            MimeTypeUtils::identifyFileMimeType(
-                                DPL::FromUTF8String(checkUrl)));
-
-                    destString += mimeString;
-                    destString += BASE64_STRING;
-
-                    decryptString.insert(0, destString);
-
-                    WKURLRef destUrl =
-                        WKURLCreateWithUTF8CString(decryptString.c_str());
-
-                    WKURLRequestRef req = WKURLRequestCreateWithWKURL(
-                            destUrl);
-                    WKRelease(destUrl);
-                    LogDebug("return value " << decryptString << "]]");
-                    return req;
-                }
-            }
+        std::string checkUrl = localizedUrl;
+
+        if (m_decryptionSupport->isNeedDecryption(checkUrl)) {
+            std::string decryptString =
+                m_decryptionSupport->decryptResource(checkUrl);
+
+            if (logEnable){ _D("return value : %s", decryptString.c_str()); }
+
+            WKURLRef destUrl =
+                WKURLCreateWithUTF8CString(decryptString.c_str());
+            WKURLRequestRef req = WKURLRequestCreateWithWKURL(destUrl);
+            WKRelease(destUrl);
+
+            return req;
         }
-        WKURLRequestRef req = WKURLRequestCreateWithWKURL(tmpUrl);
-        WKRelease(tmpUrl);
-        LogDebug("return value " << toString(req).c_str());
-        return req;
     }
+
+    WKURLRef newUrl = WKURLCreateWithUTF8CString(localizedUrl.c_str());
+    WKURLRequestRef req = WKURLRequestCreateWithWKURL(newUrl);
+    WKRelease(newUrl);
+
+    if (logEnable){ _D("return value : %s", localizedUrl.c_str()); }
+
+    return req;
 }
 
 WKBundlePagePolicyAction Bundle::decidePolicyForAction(
@@ -888,7 +868,7 @@ WKBundlePagePolicyAction Bundle::decidePolicyForAction(
 
     std::string request_uri = toString(request);
 
-    LogInfo("Uri being checked: " << request_uri);
+    _D("request uri : %s", request_uri.c_str());
 
     // exception uri
     if (request_uri == BLANK_PAGE_URL) {
@@ -907,15 +887,14 @@ WKBundlePagePolicyAction Bundle::decidePolicyForAction(
                                                        m_securityModelVersion);
     if (!ret) {
         std::string blockedUrl = DPL::ToUTF8String(dplUrl);
-        LogDebug("URI is blocked: " << blockedUrl);
+        _D("URI is blocked: %s", blockedUrl.c_str());
 
         // Send information about blocked URI to UIProcess
         WKStringRef urlStr = WKStringCreateWithUTF8CString(blockedUrl.c_str());
-        WKTypeRef retVal = NULL;
-        WKStringRef blockMessage = WKStringCreateWithUTF8CString(uriBlockedMessageName);
-        WKBundlePostSynchronousMessage(m_bundle, blockMessage, urlStr, &retVal);
+        WKStringRef blockMessage =
+            WKStringCreateWithUTF8CString(Message::ToUIProcess::BLOCKED_URL);
+        WKBundlePostMessage(m_bundle, blockMessage, urlStr);
         WKRelease(urlStr);
-        WKRelease(retVal);
         WKRelease(blockMessage);
         return WKBundlePagePolicyActionPassThrough;
     }
@@ -930,11 +909,9 @@ WKBundlePagePolicyAction Bundle::decidePolicyForAction(
 
     // scheme action
     Scheme scheme(request_scheme);
-    LogDebug("Scheme: " << request_scheme);
-
     Scheme::Type type = scheme.GetType();
     if (type < Scheme::FILE || type >= Scheme::COUNT) {
-        LogError("Invalid scheme: " << request_scheme);
+        _D("Unknown scheme : %s", request_scheme.c_str());
         return WKBundlePagePolicyActionPassThrough;
     }
 
@@ -944,20 +921,11 @@ WKBundlePagePolicyAction Bundle::decidePolicyForAction(
         ctx = NEW_WINDOW;
     }
 
-    LogDebug("Scheme type: " << type);
-    LogDebug("Navigation context: " << ctx);
-    LogDebug("Application type: " << m_widgetType.getApptypeToString());
-
-    UriAction action;
-
-    if (m_widgetType == WrtDB::APP_TYPE_TIZENWEBAPP) {
-        action = g_tizenActionMap[type][ctx];
-    } else {
-        LogError("Unsupported application type: " << type);
-        return WKBundlePagePolicyActionPassThrough;
-    }
-
-    LogDebug("Uri action: " << action);
+    UriAction action = g_tizenActionMap[type][ctx];
+    _D("Scheme type: %d, Navigation context: %d, Action: %d",
+       type,
+       ctx,
+       action);
 
     if (action != URI_ACTION_WRT) {
         return WKBundlePagePolicyActionPassThrough;
@@ -969,12 +937,15 @@ WKBundlePagePolicyAction Bundle::decidePolicyForAction(
 std::string Bundle::toString(WKStringRef str)
 {
     if (WKStringIsEmpty(str)) {
-        return std::string();
+        return "";
+    } else {
+        size_t size = WKStringGetMaximumUTF8CStringSize(str);
+
+        char buffer[size + 1];
+        WKStringGetUTF8CString(str, buffer, sizeof(buffer));
+
+        return buffer;
     }
-    size_t size = WKStringGetMaximumUTF8CStringSize(str);
-    char buffer[size + 1];
-    WKStringGetUTF8CString(str, buffer, size + 1);
-    return buffer;
 }
 
 std::string Bundle::toString(WKURLRef url)
@@ -1015,145 +986,16 @@ std::string Bundle::getScheme(std::string uri)
     return str;
 }
 
-bool Bundle::isEncryptedResource(std::string Url, int &size)
-{
-    if (m_encryptedFiles.empty()) {
-        WrtDB::WidgetDAOReadOnly(m_widgetTizenId).
-            getEncryptedFileList(m_encryptedFiles);
-    }
-
-    std::set<WrtDB::EncryptedFileInfo>::iterator it;
-    WrtDB::EncryptedFileInfo info;
-    std::string filePath;
-
-    if (0 != strncmp(Url.c_str(), SCHEME_FILE_SLASH, strlen(SCHEME_FILE_SLASH))) {
-        return false;
-    }
-
-    filePath = Url.substr(strlen(SCHEME_FILE_SLASH));
-    info.fileName = DPL::FromUTF8String(filePath);
-
-    if (m_encryptedFiles.end() != (it = m_encryptedFiles.find(info)))
-    {
-        LogDebug(" info file name : " << it->fileName);
-        LogDebug(" info file size : " << it->fileSize);
-        size = it->fileSize;
-        return true;
-    }
-    return false;
-}
-
-std::string Bundle::DecryptResource(std::string resource, int size)
-{
-#ifdef DECRYPT
-    std::string filePath;
-
-    size_t pos = resource.find_first_not_of(SCHEME_FILE_SLASH);
-    if (std::string::npos != pos) {
-        filePath = resource.substr(pos - 1);
-    }
-
-    struct stat buf;
-    if (0 == stat(filePath.c_str(), &buf)) {
-        const std::size_t fileSize = buf.st_size;
-        std::unique_ptr<unsigned char[]> inChunk;
-
-        FILE* fp = fopen(filePath.c_str(), "rb");
-        if (NULL == fp) {
-            LogDebug("Couldnot open file : " << filePath);
-            return std::string();
-        }
-
-        std::unique_ptr<unsigned char[]> DecryptedString(new unsigned
-                char[fileSize]);
-        std::string pkgid(DPL::ToUTF8String(m_widgetTizenId));
-
-        using namespace Tizen::Base;
-        const byte *b_pkgid = reinterpret_cast<const byte*>(pkgid.c_str());
-        ByteBuffer appInfo;
-        appInfo.Construct(pkgid.length());
-        if (appInfo.SetArray(b_pkgid, 0, pkgid.length()) != E_SUCCESS) {
-            LogDebug("Couldnot set appInfo");
-            fclose(fp);
-            return std::string();
-        }
-        appInfo.Flip();
-
-        int writeCount = 0;
-        do {
-            unsigned char getDecSize[4];
-            memset(getDecSize, 0x00, sizeof(getDecSize));
-
-            size_t readSize = fread(getDecSize, sizeof(unsigned char),
-                    sizeof(getDecSize), fp);
-            if (0 != readSize) {
-                int readBufSize = 0;
-                std::istringstream(std::string((char*)getDecSize)) >> readBufSize;
-                inChunk.reset(new unsigned char[readBufSize]);
-
-                size_t decReadSize = fread(inChunk.get(), sizeof(unsigned char),
-                        readBufSize, fp);
-                if (0 != decReadSize) {
-                    ByteBuffer *getBuffer =
-                        DecryptChunkByTrustZone(&appInfo, inChunk.get(),
-                                decReadSize);
-                    memcpy(DecryptedString.get() + writeCount,
-                            getBuffer->GetPointer(), getBuffer->GetRemaining());
-                    writeCount += getBuffer->GetRemaining();
-                    getBuffer->Reset();
-                }
-            }
-
-        } while( 0 == std::feof(fp));
-        fclose(fp);
-
-        memset(DecryptedString.get() + size, '\n', fileSize - size);
-        LogDebug("resource need to encoding base64");
-        BIO *bmem, *b64;
-        BUF_MEM *bptr;
-
-        b64 = BIO_new(BIO_f_base64());
-        bmem = BIO_new(BIO_s_mem());
-        b64 = BIO_push(b64, bmem);
-        BIO_write(b64, DecryptedString.get(), fileSize);
-        BIO_flush(b64);
-        BIO_get_mem_ptr(b64, &bptr);
-
-        std::string base64Enc((char *)bptr->data, bptr->length - 1);
-        BIO_free_all(b64);
-
-        return base64Enc;
-    }
-#endif
-    return std::string();
-}
-
-#ifdef MULTIPROCESS_SERVICE_SUPPORT_INLINE
-void Bundle::sendWebProcessPid()
-{
-    std::stringstream strPid;
-    strPid << getpid();
-    WKStringRef pidStr = WKStringCreateWithUTF8CString(strPid.str().c_str());
-    WKTypeRef retVal = NULL;
-    WKStringRef message = WKStringCreateWithUTF8CString(webProcessPidMessageName);
-    WKBundlePostSynchronousMessage(m_bundle, message, pidStr, &retVal);
-    WKRelease(pidStr);
-    WKRelease(retVal);
-    WKRelease(message);
-}
-#endif
-
 extern "C"
 {
 WK_EXPORT
 void WKBundleInitialize(WKBundleRef bundle,
                         WKTypeRef)
 {
-    DPL::Log::LogSystemSingleton::Instance().SetTag("WRT-BUNDLE");
-    LogDebug("Bundle initialized");
+    _D("Bundle initialized");
 
     DPL::Event::GetMainEventDispatcherInstance().ResetCrossEventCallHandler();
-    LogDebug("ResetCrossEventCallHandler()");
+    _D("ResetCrossEventCallHandler()");
 
     static Bundle s_bundle(bundle);
 
@@ -1168,9 +1010,9 @@ void WKBundleInitialize(WKBundleRef bundle,
     WKBundleSetClient(bundle, &client);
 
     // process pool - restore process priority
-    if (UID_ROOT == getuid())
-    {
+    if (UID_ROOT == getuid()) {
         setpriority(PRIO_PROCESS, 0, DEFAULT_PRIORITY);
     }
+    IPCMessageSupport::setWKBundleRef(bundle);
 }
 }