/wrt/src/view/webkit/bundles/wrt-wk2-bundle.cpp
C++ | 770 lines | 631 code | 105 blank | 34 comment | 96 complexity | 8da0474af47d037555cccdf27687d314 MD5 | raw file
Possible License(s): GPL-3.0, AGPL-3.0, GPL-2.0, MPL-2.0, JSON, WTFPL, CC-BY-SA-4.0, CC-BY-3.0, BSD-3-Clause, LGPL-2.0, MPL-2.0-no-copyleft-exception, AGPL-1.0, 0BSD, Zlib, Unlicense, BSD-2-Clause, Apache-2.0, LGPL-3.0, ISC, MIT, CC-BY-SA-3.0, CC0-1.0, LGPL-2.1
- /*
- * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- /**
- * @file wrt-wk2-bundle.cpp
- * @author Lukasz Wrzosek (l.wrzosek@samsung.com)
- * @brief Implementation file for view logic for Webkit2
- */
- #include "wrt-wk2-bundle.h"
- #include <WKBundle.h>
- #include <WKBundleInitialize.h>
- #include <WKBundlePage.h>
- #include <WKBundleFrame.h>
- #include <WKURLRequest.h>
- #include <WKString.h>
- #include <WKType.h>
- #include <WKURL.h>
- #include <WKError.h>
- #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 <dpl/log/log.h>
- #include <dpl/foreach.h>
- #include <dpl/assert.h>
- #include <dpl/wrt-dao-ro/WrtDatabase.h>
- #include <dpl/localization/localization_utils.h>
- #include <dpl/string.h>
- #include <dpl/wrt-dao-ro/widget_dao_read_only.h>
- #include <dpl/utils/mime_type_utils.h>
- #include <wrt_plugin_module.h>
- #include <vconf.h>
- #include <appcore-efl.h>
- #include "messages_names.h"
- namespace {
- const char * const willSendMessageName = "will_send_msg";
- const char * const uriChangedMessageName = "uri_changed_msg";
- const char * const URICHANGE_PLUGIN_STOP_ONLY = "plugin_stop_only";
- const char * const URICHANGE_PLUGIN_RESTART = "plugin_restart";
- const char * const URICHANGE_PLUGIN_NO_CHANGE = "plugin_no_change";
- const char * const URICHANGE_BLOCKED_URL = "null";
- const char * const SCHEME_HTTP = "http";
- const char * const SCHEME_HTTPS = "https";
- const char * const SCHEME_FILE = "file://";
- const char * const DATA_STRING = "data:";
- const char * const BASE64_STRING = ";base64,";
- }
- Bundle::Bundle(WKBundleRef bundle) :
- m_willSendMessage(0),
- m_bundle(bundle),
- m_widgetHandle(-1),
- m_scale(0),
- m_encodedBundle(""),
- m_theme(""),
- m_resDec(NULL),
- m_encrypted(false)
- {
- WrtDB::WrtDatabase::attachToThreadRO();
- m_willSendMessage = WKStringCreateWithUTF8CString(willSendMessageName);
- m_uriChangedMessage = WKStringCreateWithUTF8CString(uriChangedMessageName);
- LogDebug("message will be named " << toString(m_willSendMessage).c_str());
- }
- Bundle::~Bundle()
- {
- WrtDB::WrtDatabase::detachFromThread();
- if (!m_pagesList.empty())
- {
- LogError("There are not closed pages!");
- }
- WKRelease(m_willSendMessage);
- WKRelease(m_uriChangedMessage);
- WKRelease(m_bundle);
- }
- void Bundle::didCreatePageCallback(
- WKBundleRef /*bundle*/,
- WKBundlePageRef page,
- const void* clientInfo)
- {
- LogDebug("didCreatePageCallback called");
- Bundle* This = static_cast<Bundle*>(const_cast<void*>(clientInfo));
- This->didCreatePage(page);
- }
- void Bundle::didReceiveMessageCallback(
- WKBundleRef /*bundle*/,
- WKStringRef messageName,
- WKTypeRef messageBody,
- const void *clientInfo)
- {
- LogDebug("didReceiveMessageCallback called");
- Bundle* bundle = static_cast<Bundle*>(const_cast<void*>(clientInfo));
- bundle->didReceiveMessage(messageName, messageBody);
- }
- void Bundle::willDestroyPageCallback(
- WKBundleRef /*bundle*/,
- 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)
- {
- auto mainFrame = WKBundlePageGetMainFrame(page);
- auto context = WKBundleFrameGetJavaScriptContext(mainFrame);
- m_pagesList.push_back(page);
- m_pageGlobalContext[page] = context;
- LogDebug("created Page : " << page << " created JSContext : " << context);
- WKBundlePageResourceLoadClient resourceLoadClient = {
- kWKBundlePageResourceLoadClientCurrentVersion, /* version */
- this, /* clientinfo */
- 0, /* didInitiateLoadForResource */
- willSendRequestForFrameCallback, /* willSendRequestForFrame */
- 0, /* didReceiveResponseForResource */
- 0, /* didReceiveContentLengthForResource */
- didFinishLoadForResourceCallback, /* didFinishLoadForResource */
- 0, /* didFailLoadForResource */
- 0, /* shouldCacheResponse */
- 0, /* shouldUseCredentialStorage */
- };
- WKBundlePageSetResourceLoadClient(page, &resourceLoadClient);
- WKBundlePageLoaderClient loaderClient = {
- kWKBundlePageLoaderClientCurrentVersion,
- this, /* clientinfo */
- didStartProvisionalLoadForFrameCallback, /* didStartProvisionalLoadForFrame */
- 0, /* didReceiveServerRedirectForProvisionalLoadForFrame */
- 0, /* didFailProvisionalLoadWithErrorForFrame */
- didCommitLoadForFrameCallback, /* didCommitLoadForFrame */
- 0, /* didFinishDocumentLoadForFrame */
- 0, /* didFinishLoadForFrame */
- 0, /* didFailLoadWithErrorForFrame */
- 0, /* didSameDocumentNavigationForFrame */
- 0, /* didReceiveTitleForFrame */
- 0, /* didFirstLayoutForFrame */
- 0, /* didFirstVisuallyNonEmptyLayoutForFrame */
- didRemoveFrameFromHierarchyCallback, /* didRemoveFrameFromHierarchy */
- 0, /* didDisplayInsecureContentForFrame */
- 0, /* didRunInsecureContentForFrame */
- 0, /* didClearWindowObjectForFrame */
- 0, /* didCancelClientRedirectForFrame */
- 0, /* willPerformClientRedirectForFrame */
- 0, /* didHandleOnloadEventsForFrame */
- 0, /* didLayoutForFrame */
- 0, /* didNewFirstVisuallyNonEmptyLayout */
- 0, /* didDetectXSSForFrame */
- 0, /* shouldGoToBackForwardListItem */
- 0, /* globalObjectIsAvailableForFrame */
- 0, /* willDisconnectDOMWindowExtensionFromGlobalObject */
- 0, /* didReconnectDOMWindowExtensionToGlobalObject */
- 0, /* willDestroyGlobalObjectForDOMWindowExtension */
- 0, /* didFinishProgress */
- 0, /* shouldForceUniversalAccessFromLocalURL */
- };
- WKBundlePageSetPageLoaderClient(page, &loaderClient);
- }
- void Bundle::willDestroyPage(WKBundlePageRef page)
- {
- LogDebug("Destroyed page : " << page);
- auto context = m_pageGlobalContext[page];
- m_pagesList.remove(page);
- m_pageGlobalContext.erase(page);
- m_pageContext.erase(page);
- PluginModule::stop(context);
- }
- void Bundle::didReceiveMessage(WKStringRef messageName, WKTypeRef messageBody)
- {
- LogDebug("got message type: " << toString(messageName).c_str());
- if (WKStringIsEqualToUTF8CString(messageName,
- BundleMessages::START))
- {
- if (!messageBody || WKStringGetTypeID() != WKGetTypeID(messageBody)) {
- LogError("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[m_pagesList.back()]);
- // set information from ui process
- std::stringstream ssMsg(msgString);
- std::string argScale;
- std::string argEncodedBundle;
- std::string argTheme;
- ssMsg >> m_widgetHandle;
- ssMsg >> argScale;
- ssMsg >> argEncodedBundle;
- ssMsg >> argTheme;
- ssMsg >> m_encrypted;
- if (argScale != "null" && argScale[0] == '_')
- {
- argScale.erase(0, 1);
- std::stringstream ssScale(argScale);
- ssScale >> m_scale;
- }
- if (argEncodedBundle != "null" && argEncodedBundle[0] == '_')
- {
- argEncodedBundle.erase(0, 1);
- m_encodedBundle = argEncodedBundle;
- }
- if (argTheme != "null" && argTheme[0] == '_')
- {
- argTheme.erase(0, 1);
- m_theme = argTheme;
- }
- }
- else if (WKStringIsEqualToUTF8CString(messageName,
- BundleMessages::SHUTDOWN))
- {
- LogDebug("shutdown plugins");
- if (m_pagesList.empty())
- {
- PluginModule::shutdown();
- }
- else
- {
- LogInfo("PluginModule shutdown ignored, there are still alive pages!");
- }
- }
- else if (WKStringIsEqualToUTF8CString(messageName,
- BundleMessages::SET_CUSTOM_PROPERTIES))
- {
- LogDebug("reset custom properties of window objects");
- // set information from ui process
- auto msgString = toString(static_cast<WKStringRef>(messageBody));
- std::string argScale;
- std::string argEncodedBundle;
- std::string argTheme;
- std::stringstream ssMsg(msgString);
- ssMsg >> argScale;
- ssMsg >> argEncodedBundle;
- ssMsg >> argTheme;
- if(argScale != "null" && argScale[0] == '_')
- {
- argScale.erase(0, 1);
- std::stringstream ssScale(argScale);
- ssScale >> m_scale;
- }
- if(argEncodedBundle != "null" && argEncodedBundle[0] == '_')
- {
- argEncodedBundle.erase(0, 1);
- m_encodedBundle = argEncodedBundle;
- }
- if(argTheme != "null" && argTheme[0] == '_')
- {
- argTheme.erase(0, 1);
- m_theme = argTheme;
- }
- //apply for each context
- PageGlobalContext::iterator it = m_pageGlobalContext.begin();
- for (; it != m_pageGlobalContext.end(); ++it)
- {
- PluginModule::setCustomProperties(it->second,
- m_scale,
- m_encodedBundle.c_str(),
- m_theme.c_str());
- }
- }
- else if (WKStringIsEqualToUTF8CString(
- messageName,
- BundleMessages::DISPATCH_JAVASCRIPT_EVENT))
- {
- LogDebug("dispatch javascript event to created frames");
- // set information from ui process
- auto text = toString(static_cast<WKStringRef>(messageBody));
- int eventType;
- std::stringstream ss(text);
- ss >> eventType;
- //apply for each context
- PageGlobalContext::iterator it = m_pageGlobalContext.begin();
- for (; it != m_pageGlobalContext.end(); ++it)
- {
- PluginModule::dispatchJavaScriptEvent(
- it->second,
- static_cast<WrtPlugins::W3C::CustomEventType>(eventType));
- }
- }
- }
- WKURLRequestRef Bundle::willSendRequestForFrameCallback(
- WKBundlePageRef /*page*/,
- WKBundleFrameRef /*frame*/,
- uint64_t /*resourceIdentifier*/,
- WKURLRequestRef request,
- WKURLResponseRef /*response*/,
- const void *clientInfo)
- {
- LogDebug("willSendRequestForFrameCallback called");
- Bundle* This = static_cast<Bundle*>(const_cast<void*>(clientInfo));
- return This->willSendRequestForFrame(request);
- }
- void Bundle::didStartProvisionalLoadForFrameCallback(
- WKBundlePageRef page,
- WKBundleFrameRef frame,
- WKTypeRef* /*userData*/,
- const void *clientInfo)
- {
- LogDebug("didStartProvisionalLoadForFrameCallback called");
- Bundle* This = static_cast<Bundle*>(const_cast<void*>(clientInfo));
- if (This->m_pageGlobalContext.count(page) == 0)
- {
- return;
- }
- if (This->m_pageContext.count(page) == 0)
- {
- return;
- }
- JSGlobalContextRef context = WKBundleFrameGetJavaScriptContext(frame);
- ContextSet::iterator i = This->m_pageContext[page].find(context);
- if (i == This->m_pageContext[page].end())
- {
- LogDebug("Initially attached frame");
- return;
- }
- This->m_pageContext[page].erase(i);
- PluginModule::unloadFrame(context);
- }
- void Bundle::didRemoveFrameFromHierarchyCallback(
- WKBundlePageRef page,
- WKBundleFrameRef frame,
- WKTypeRef* /*userData*/,
- const void *clientInfo)
- {
- LogDebug("didFinishLoadForResourceCallback called");
- Bundle* This = static_cast<Bundle*>(const_cast<void*>(clientInfo));
- if (This->m_pageGlobalContext.count(page) == 0)
- {
- return;
- }
- if (This->m_pageContext.count(page) == 0)
- {
- return;
- }
- JSGlobalContextRef context = WKBundleFrameGetJavaScriptContext(frame);
- 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");
- return;
- }
- This->m_pageContext[page].erase(i);
- PluginModule::unloadFrame(context);
- }
- void Bundle::didFinishLoadForResourceCallback(
- WKBundlePageRef /*page*/,
- WKBundleFrameRef frame,
- uint64_t /*resourceIdentifier*/,
- const void* clientInfo)
- {
- LogDebug("didFinishLoadForResourceCallback called");
- Bundle* This = static_cast<Bundle*>(const_cast<void*>(clientInfo));
- WKURLRef url = WKBundleFrameCopyURL(frame);
- WKTypeRef retVal = NULL;
- // If url is NULL, this url has been already blocked by willsend
- // So current page should be moved to previous page
- if (url == NULL)
- {
- if (WKBundleFrameIsMainFrame(frame))
- {
- LogInfo("url is NULL. Go back to previous view");
- WKStringRef blockedURL =
- WKStringCreateWithUTF8CString(URICHANGE_BLOCKED_URL);
- WKBundlePostSynchronousMessage(This->m_bundle,
- This->m_uriChangedMessage,
- blockedURL,
- &retVal);
- }
- else
- {
- LogInfo("Blocked uri in IFrame.");
- }
- return;
- }
- WKRelease(url);
- }
- void Bundle::didCommitLoadForFrameCallback(
- WKBundlePageRef page,
- WKBundleFrameRef frame,
- WKTypeRef* /*userData*/,
- const void *clientInfo)
- {
- LogInfo("didCommitLoadForFrameCallback called");
- Bundle* This = static_cast<Bundle*>(const_cast<void*>(clientInfo));
- WKURLRef url = WKBundleFrameCopyURL(frame);
- WKTypeRef retVal = NULL;
- if (url == NULL) {
- LogInfo("url is NULL");
- return;
- }
- JSGlobalContextRef context = WKBundleFrameGetJavaScriptContext(frame);
- This->m_pageContext[page].insert(context);
- if (!WKBundleFrameIsMainFrame(frame))
- {
- LogInfo("frame isn't main frame");
- PluginModule::start(This->m_widgetHandle,
- context,
- This->m_scale,
- This->m_encodedBundle.c_str(),
- This->m_theme.c_str());
- PluginModule::loadFrame(context);
- return;
- }
- WKStringRef urlStr = WKURLCopyString(url);
- WKBundlePostSynchronousMessage(This->m_bundle,
- This->m_uriChangedMessage,
- urlStr,
- &retVal);
- WKRelease(url);
- WKRelease(urlStr);
- std::string result = toString(static_cast<WKStringRef>(retVal));
- LogInfo("result from UI process : " << result);
- if (result == URICHANGE_PLUGIN_STOP_ONLY)
- {
- PluginModule::stop(context);
- }
- else if (result == URICHANGE_PLUGIN_RESTART)
- {
- PluginModule::stop(context);
- This->m_pageGlobalContext[page] = context;
- PluginModule::start(This->m_widgetHandle,
- context,
- This->m_scale,
- This->m_encodedBundle.c_str(),
- This->m_theme.c_str() );
- PluginModule::loadFrame(context);
- }
- }
- WKURLRequestRef Bundle::willSendRequestForFrame(WKURLRequestRef request)
- {
- LogDebug("willSendReq got " << toString(request).c_str());
- WKURLRef url = WKURLRequestCopyURL(request);
- WKStringRef urlStr = WKURLCopyString(url);
- WKTypeRef retVal = NULL;
- WKBundlePostSynchronousMessage(m_bundle,
- m_willSendMessage,
- urlStr,
- &retVal);
- WKRelease(urlStr);
- if (NULL == retVal) {
- LogDebug("uri is blocked");
- WKRelease(url);
- return NULL;
- } else if (retVal && WKStringGetTypeID() == WKGetTypeID(retVal)) {
- std::string tmpUrlStr = toString(static_cast<WKStringRef>(retVal));
- WKRelease(retVal);
- if (tmpUrlStr.empty()) {
- LogDebug("uri is blocked");
- WKRelease(url);
- return NULL;
- }
- WKURLRef tmpUrl = WKURLCreateWithUTF8CString(tmpUrlStr.c_str());
- std::string scheme = toString(WKURLCopyScheme(url));
- WKRelease(url);
- // Return value must contain details information of input
- // WKURLRequestRef. Current webkit2 doesn't support api that
- // copy WKURLRequestRef or change url only. Before webkit2
- // support api, callback return original WKURLRequestRef in the
- // case of external scheme
- // 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);
- WKRetain(request);
- return request;
- } else {
- std::string checkUrl = toString(tmpUrl);
- int getFileSize;
- if(m_encrypted) {
- 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;
- }
- }
- }
- WKURLRequestRef req = WKURLRequestCreateWithWKURL(tmpUrl);
- WKRelease(tmpUrl);
- LogDebug("return value " << toString(req).c_str());
- return req;
- }
- } else {
- Assert(false && "not common case need to check work flow");
- }
- }
- std::string Bundle::toString(WKStringRef str)
- {
- if (WKStringIsEmpty(str)) {
- return std::string();
- }
- size_t size = WKStringGetMaximumUTF8CStringSize(str);
- char buffer[size + 1];
- WKStringGetUTF8CString(str, buffer, size + 1);
- return buffer;
- }
- std::string Bundle::toString(WKURLRef url)
- {
- WKStringRef urlStr = WKURLCopyString(url);
- std::string str = toString(urlStr);
- WKRelease(urlStr);
- return str;
- }
- std::string Bundle::toString(WKURLRequestRef req)
- {
- WKURLRef reqUrl = WKURLRequestCopyURL(req);
- std::string str = toString(reqUrl);
- WKRelease(reqUrl);
- return str;
- }
- std::string Bundle::toString(WKErrorRef err)
- {
- WKStringRef domErr = WKErrorCopyDomain(err);
- WKStringRef desc = WKErrorCopyLocalizedDescription(err);
- std::string str = toString(domErr) + "\n" + toString(desc);
- WKRelease(domErr);
- WKRelease(desc);
- return str;
- }
- bool Bundle::isEncryptedResource(std::string Url, int &size)
- {
- std::string filePath;
- size_t pos = Url.find_first_not_of(SCHEME_FILE);
- if ( std::string::npos != pos) {
- filePath = Url.substr(pos-1);
- }
- if (m_encryptedFiles.empty()) {
- WrtDB::WidgetDAOReadOnly(m_widgetHandle).
- getEncryptedFileList(m_encryptedFiles);
- }
- WrtDB::EncryptedFileInfo info;
- std::set<WrtDB::EncryptedFileInfo>::iterator it;
- info.fileName = DPL::FromUTF8String(filePath);
- if ((0 == strncmp(Url.c_str(), SCHEME_FILE, strlen(SCHEME_FILE))) &&
- (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);
- if ( std::string::npos != pos) {
- filePath = resource.substr(pos-1);
- }
- struct stat buf;
- if (0 == stat(filePath.c_str(), &buf)) {
- if (NULL == m_resDec) {
- using namespace WrtDB;
- DPL::Optional<DPL::String> pkgName =
- WidgetDAOReadOnly(m_widgetHandle).getPkgname();
- m_resDec = new
- WRTDecryptor::ResourceDecryptor(DPL::ToUTF8String(*pkgName));
- WrtDB::WidgetDAOReadOnly(m_widgetHandle).
- getEncryptedFileList(m_encryptedFiles);
- }
- size_t bufSize = buf.st_size;
- unsigned char contents[bufSize];
- memset(contents, 0, bufSize);
- FILE* fp = fopen(filePath.c_str(), "rb");
- if ( NULL == fp) {
- LogDebug("Couldnot open file : " << filePath);
- return std::string();
- }
- fread(contents, sizeof(unsigned char), buf.st_size, fp);
- fclose(fp);
- LogDebug("resource is encrypted. decrypting....");
- unsigned char outDecBuf[bufSize];
- memset(outDecBuf, 0, bufSize);
- m_resDec->GetDecryptedChunk(contents, outDecBuf, bufSize);
- memset(outDecBuf+size, '\n', bufSize - 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, outDecBuf, bufSize);
- 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();
- }
- namespace {
- static int LanguageChanged(void *)
- {
- char* lang = vconf_get_str(VCONFKEY_LANGSET);
- if (!lang) {
- LogError("Cannot get locale settings from vconf");
- return 0;
- }
- LogDebug("Language set to: " << lang);
- LanguageTagsList list;
- list.push_back(DPL::FromUTF8String(lang));
- LocalizationUtils::SetSystemLanguageTags(list);
- LogDebug("LanguageChanged to " << lang);
- return 0;
- }
- void Initialize()
- {
- appcore_set_event_callback(
- APPCORE_EVENT_LANG_CHANGE,
- &LanguageChanged,
- NULL);
- LanguageChanged(NULL); // updating language for the first time
- }
- }
- extern "C"
- {
- WK_EXPORT
- void WKBundleInitialize(WKBundleRef bundle,
- WKTypeRef)
- {
- DPL::Log::LogSystemSingleton::Instance().SetTag("WRT-BUNDLE");
- Initialize();
- LogDebug("Bundle initialized");
- static Bundle s_bundle = Bundle(bundle);
- WKBundleClient client = {
- kWKBundleClientCurrentVersion,
- &s_bundle,
- &Bundle::didCreatePageCallback,
- &Bundle::willDestroyPageCallback,
- 0, /* didInitializePageGroup */
- &Bundle::didReceiveMessageCallback
- };
- WKBundleSetClient(bundle, &client);
- }
- }