#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/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>
-#include <FBaseByteBuffer.h>
-#include <security/FSecCrypto_TrustZoneService.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>
// 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 std::size_t FILE_BUF_MAX_SIZE = 1024; // bytes
const std::size_t PLAIN_CHUNK_SIZE = 1008; // bytes
const unsigned int UID_ROOT = 0;
#ifdef CORS_WHITELISTING_ENABLED
const char * const warpAllowProtocolsForWildcard[] = { "http", "https" };
#endif
-
-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);
-}
-
}
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();
m_pagesList.push_back(page);
m_pageGlobalContext.insertContextForPage(page, context);
LogDebug("created Page : " << page << " created JSContext : " << context);
+ m_viewmodesSupport->initialize(page);
WKBundlePageResourceLoadClient resourceLoadClient = {
kWKBundlePageResourceLoadClientCurrentVersion, /* version */
willSendRequestForFrameCallback, /* willSendRequestForFrame */
0, /* didReceiveResponseForResource */
0, /* didReceiveContentLengthForResource */
- didFinishLoadForResourceCallback, /* didFinishLoadForResource */
+ 0, /* didFinishLoadForResource */
0, /* didFailLoadForResource */
0, /* shouldCacheResponse */
0, /* shouldUseCredentialStorage */
m_pagesList.remove(page);
m_pageGlobalContext.removeContextForPage(page);
m_pageContext[page].erase(context);
+ m_viewmodesSupport->deinitialize(page);
PluginModule::unloadFrame(context);
PluginModule::stop(context);
{
LogDebug("got message type: " << toString(messageName).c_str());
if (WKStringIsEqualToUTF8CString(messageName,
- BundleMessages::START))
+ Message::ToInjectedBundle::START))
{
if (!messageBody || WKStringGetTypeID() != WKGetTypeID(messageBody)) {
LogError("Wrong message format received, ignoring");
return;
}
- auto msgString = toString(static_cast<WKStringRef>(messageBody));
+ std::string msgString =
+ toString(static_cast<WKStringRef>(messageBody));
LogDebug("Got message text: " << msgString);
LogDebug("loading Page : " << m_pagesList.back() <<
" loading JSContext : " <<
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");
}
}
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));
std::string argScale;
std::string argEncodedBundle;
}
} else if (WKStringIsEqualToUTF8CString(
messageName,
- BundleMessages::DISPATCH_JAVASCRIPT_EVENT))
+ Message::ToInjectedBundle::DISPATCH_JS_EVENT))
{
LogDebug("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));
+ LogDebug("initialize");
+ if (!m_initialized) {
+ 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;
#ifdef CORS_WHITELISTING_ENABLED
bypassCORSforWARPAccessList(dao);
#endif
+ m_decryptionSupport->initialize(m_widgetTizenId);
+ m_viewmodesSupport.reset(
+ new InjectedBundle::ViewmodesSupport(m_widgetTizenId));
m_initialized = true;
- }
- else
- {
+ } else {
LogDebug("already initalized");
}
+ } else if (WKStringIsEqualToUTF8CString(
+ messageName,
+ Message::ToInjectedBundle::SET_XWINDOW_HANDLE))
+ {
+ std::string msgString =
+ toString(static_cast<WKStringRef>(messageBody));
+ LogDebug("set x window handle [" << msgString << "]");
+ IPCMessageSupport::setXwindowHandle(atoi(msgString.c_str()));
+ } else if (WKStringIsEqualToUTF8CString(
+ messageName,
+ Message::ToInjectedBundle::SET_VIEWMODES))
+ {
+ std::string msgBody =
+ toString(static_cast<WKStringRef>(messageBody));
+ LogDebug("set viewmode to [" << msgBody << "]");
+ if (msgBody == Message::ToInjectedBundle::SET_VIEWMODES_MSGBODY_EXIT) {
+ m_viewmodesSupport->exitViewmodesAllPages();
+ } else {
+ m_viewmodesSupport->enterViewmodesAllPages(msgBody);
+ }
}
}
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(
LogDebug("didStartProvisionalLoadForFrameCallback 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;
}
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);
+ WKRelease(wkStr);
+ WKRelease(wkUrl);
+
+ if (logEnable){ LogDebug("willSendRequestForFrame : " << stdUrl); }
+
+ localizedUrl = InjectedBundleURIHandling::localizeURI(stdUrl, DPL::ToUTF8String(m_widgetTizenId));
+ bool ret = InjectedBundleURIHandling::processURI(localizedUrl, m_widgetTizenId, m_securityModelVersion);
+
+ if (!ret)
+ {
+ LogDebug("Not permitted resource: " << localizedUrl);
return NULL;
}
- 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);
+ // log disabled for performance
+ //LogDebug("URI processing result: " << result);
+ std::string scheme = localizedUrl.substr(0, localizedUrl.find_first_of(':'));
#ifdef APP_SCHEME_ENABLED
- if(scheme == SCHEME_FILE) {
- LogError("File schema blocked for: " << dplurl);
+ if (scheme == SCHEME_FILE)
+ {
+ LogError("File schema blocked for: " << stdUrl);
return NULL;
}
#endif
// 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 (scheme == SCHEME_HTTP || scheme == SCHEME_HTTPS)
+ {
+ if (logEnable){ LogDebug("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;
- }
- }
+ }
+ else
+ {
+ std::string checkUrl = localizedUrl;
+
+ if (m_decryptionSupport->isNeedDecryption(checkUrl))
+ {
+ std::string decryptString =
+ m_decryptionSupport->decryptResource(checkUrl);
+
+ if (logEnable){ LogDebug("return value : " << decryptString ); }
+
+ 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){ LogDebug("return value : " << localizedUrl); }
+
+ return req;
}
WKBundlePagePolicyAction Bundle::decidePolicyForAction(
// 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;
}
std::string Bundle::toString(WKStringRef str)
{
- if (WKStringIsEmpty(str)) {
- return std::string();
+ if (WKStringIsEmpty(str))
+ {
+ 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)
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)
-{
- 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;
- }
- 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);
+ WKStringRef message =
+ WKStringCreateWithUTF8CString(
+ Message::ToUIProcess::SEND_WEBPROCESS_PID);
+ WKBundlePostMessage(m_bundle, message, pidStr);
WKRelease(pidStr);
- WKRelease(retVal);
WKRelease(message);
}
#endif
{
setpriority(PRIO_PROCESS, 0, DEFAULT_PRIORITY);
}
+ IPCMessageSupport::setWKBundleRef(bundle);
}
}