bool JSObjectDeclaration::checkIframesSupported() const
{
+ LogDebug("Check iframe supported");
if (!m_options ||
m_options->getIframeObject() == Options::IFrameObject::None)
{
+ LogDebug("Iframe NOT supported for object: " << getName());
return false;
}
+ LogDebug("Iframe supported for object: " << getName());
+
return true;
}
JSObjectDeclaration::Options::ClassType
JSObjectDeclaration::Options::getType() const
{
+ LogDebug("Get type field from declaration's option");
Assert(m_options && "Pointer to options is NULL");
switch (m_options->type) {
JSObjectDeclaration::Options::IFrameObject
JSObjectDeclaration::Options::getIframeObject() const
{
+ LogDebug("Get Frame Option");
Assert(m_options && "Options object is NULL");
switch (m_options->iframe_option) {
case NONE: return IFrameObject::None;
- case REFERENCE: return IFrameObject::Reference; // deprecated
+ case REFERENCE: return IFrameObject::Reference;
case CREATE_INSTANCE: return IFrameObject::CreateInstance;
default:
Assert(0 && "Wrong value of behaviour type");
JSObjectDeclaration::Options::IFrameNotice
JSObjectDeclaration::Options::getIframeNotice() const
{
+ LogDebug("Get Frame Option");
Assert(m_options && "Pointer to options is null");
switch (m_options->iframe_notice) {
}
}
+JSObjectDeclaration::Options::IFrameOverlay
+JSObjectDeclaration::Options::getIframeOverlay() const
+{
+ LogDebug("Get Frame Option");
+ Assert(m_options && "Pointer to options is null");
+
+ switch (m_options->iframe_overlay) {
+ case IGNORED: return IFrameOverlay::Ignored;
+ case USE_OVERLAYED: return IFrameOverlay::UseOverlayed;
+ case OVERLAYED_BEFORE_ORIGINAL:
+ return IFrameOverlay::OverlayedBeforeOriginal;
+ default:
+ Assert(0 && "Wrong value of overlay option");
+ }
+}
+
js_function_impl JSObjectDeclaration::Options::getFunctionImpl() const
{
Assert(m_options && "Pointer to options is null");
enum class IFrameOverlay
{
Ignored,
- UseOverlayed, //deprecated
- OverlayedBeforeOriginal //deprecated
+ UseOverlayed,
+ OverlayedBeforeOriginal
};
typedef js_object_instance_t ObjectInstance;
IFrameObject getIframeObject() const;
IFrameNotice getIframeNotice() const;
+ IFrameOverlay getIframeOverlay() const;
js_function_impl getFunctionImpl() const;
void invokeCallback(JsContext ctx,
SET(TARGET_NAME ${TARGET_JS_OVERLAY})
SET(SRCS
+ ${CMAKE_CURRENT_SOURCE_DIR}/js_overlay_support.cpp
${CMAKE_CURRENT_SOURCE_DIR}/js_function_manager.cpp
${CMAKE_CURRENT_SOURCE_DIR}/js_overlay_functions.cpp
)
Api::IPluginManager::PropertyList PluginManager::getProperties() const
{
- using namespace WrtDB;
-
if (!m_propertyCache.IsNull()) {
return *m_propertyCache;
}
m_propertyCache = PropertyList();
- WidgetDAOReadOnly dao(m_widgetHandle);
+ WrtDB::WidgetDAOReadOnly dao(m_widgetHandle);
string localUri = m_objectUri + SEPARATOR;
- if (dao.getWidgetType() == APP_TYPE_TIZENWEBAPP)
- {
- static ImplementedObjectsList implObjectList =
- PluginDAOReadOnly::getImplementedObjects();
+ if (dao.getWidgetType() == WrtDB::APP_TYPE_TIZENWEBAPP) {
+ WrtDB::PluginHandleList pluginHandleList =
+ WrtDB::PluginDAOReadOnly::getPluginHandleList();
- FOREACH(it_implObject, implObjectList)
+ FOREACH(it_pluginHandle, pluginHandleList)
{
- //check if implemented object stats with localUri
- if (it_implObject->find(localUri) == 0) {
- string property = *it_implObject;
- //remove local uri that predicts property name.
- property.erase(0, localUri.size());
- //check if property has its own properties.
- size_t pos = property.find(SEPARATOR);
- if (pos != string::npos) {
- //if so then remove them.
- property.erase(pos);
- }
+ WrtDB::ImplementedObjectsList implObjectList =
+ WrtDB::PluginDAOReadOnly::getImplementedObjectsForPluginHandle(
+ *it_pluginHandle);
- m_propertyCache->push_back(property);
+ FOREACH(it_implObject, implObjectList)
+ {
+ //check if implemented object stats with localUri
+ if (it_implObject->find(localUri) == 0) {
+ string property = *it_implObject;
+ //remove local uri that predicts property name.
+ property.erase(0, localUri.size());
+ //check if property has its own properties.
+ size_t pos = property.find(SEPARATOR);
+ if (pos != string::npos) {
+ //if so then remove them.
+ property.erase(pos);
+ }
+ m_propertyCache->push_back(property);
+ }
}
}
- }
- else
- {
- DbWidgetFeatureSet features;
+ } else {
+ WrtDB::DbWidgetFeatureSet features;
Try
{
features = dao.getFeaturesList();
}
- Catch(WidgetDAOReadOnly::Exception::Base)
+ Catch(WrtDB::WidgetDAOReadOnly::Exception::Base)
{
LogError("Cannot get feature list");
ReThrow(Commons::PlatformException);
}
- DbWidgetFeatureSet::const_iterator feature = features.begin();
+ WrtDB::DbWidgetFeatureSet::const_iterator feature = features.begin();
for (; feature != features.end(); ++feature) {
- ImplementedObjectsList implObjs =
- PluginDAOReadOnly::getImplementedObjectsForPluginHandle(
+ WrtDB::ImplementedObjectsList implObjs =
+ WrtDB::PluginDAOReadOnly::getImplementedObjectsForPluginHandle(
feature->pluginId);
FOREACH(it, implObjs) {
//check if implemented object stats with localUri
#include "plugin_property_support.h"
// JS overlay
+#include <js_overlay_support.h>
#include <js_overlay_types.h>
namespace {
m_globalObject =
JavaScriptInterfaceSingleton::Instance().getGlobalObject(context);
+ LogDebug("Register main frame");
//register main frame;
m_iframeSupport.registerIframe(m_globalObject);
JSObjectPtr Explorer::getJSObjectProperty(const std::string& propertyName,
JSObjectPtr object)
{
+ LogDebug("Get object property " << propertyName);
return JavaScriptInterfaceSingleton::Instance().getJSObjectProperty(
m_context, object, propertyName);
}
bool Explorer::registerObject(const JSObjectDeclarationPtr& declaration,
JSGlobalContextRef context)
{
+ LogDebug("Register to global object");
+
bool retValue;
if (declaration->getParentName() == GLOBAL_OBJECT_NAME) {
+ LogDebug("Connect to Global object");
retValue = register_(declaration, m_globalObject, context);
} else { //PIM support
+ LogDebug("Connect to NOT global object");
//it should be master object name
string masterName = declaration->getParentName();
auto pos = masterName.find(".");
}
if (declaration->checkIframesSupported()) {
+ LogDebug("Iframe supported");
m_iframeSupport.registerDeclaration(declaration);
// m_iframeSupport.invokeCallbackForMainFrame(m_context,
// declaration,
// newObject);
+ } else {
+ LogDebug("Iframe NOT supported");
}
return retValue;
JSObjectPtr providedObject,
JSGlobalContextRef context)
{
- LogDebug("'" << providedObjectName << "' <- '" << declaration->getName() << "'");
+ LogDebug(
+ "Register object. Provided object name: '" << providedObjectName
+ <<
+ "', registration of: '" << declaration->getName() << "'");
std::string fullParentName = declaration->getParentName();
+ LogDebug("Parent name: " << declaration->getParentName());
if (fullParentName == providedObjectName) {
+ LogDebug("Provided object match equaly to requested parent");
return register_(declaration, providedObject, context);
}
- LogDebug("Provided object was not matched!!");
-
//check if object exists in fullParentName
auto pos = fullParentName.find(providedObjectName);
if (pos == string::npos) {
typedef JSObjectDeclaration::Options JO;
JSGlobalContextRef gContext = (context == NULL) ? m_context : context;
+ JSObjectPtr newObject;
+
JSObjectPtr objectInstance = JavaScriptInterfaceSingleton::Instance().
createObject(gContext, declaration);
+ //function creation
+ if (declaration->getOptions() &&
+ declaration->getOptions()->getType() == JO::ClassType::Function)
+ {
+ LogDebug("Loading function object " << declaration->getName());
+
+ auto type = declaration->getOptions()->getIframeOverlay();
+ if (JO::IFrameOverlay::OverlayedBeforeOriginal == type) {
+ LogDebug("Create overlayed function");
+ JSObjectPtr original =
+ JavaScriptInterfaceSingleton::Instance().
+ getJSObjectProperty(gContext,
+ parent,
+ declaration->getName());
+ newObject = JSOverlaySupport::
+ createWrappedFunction(gContext,
+ original,
+ objectInstance,
+ declaration->getName());
+ } else {
+ LogDebug("create normal function");
+ newObject = objectInstance;
+ }
+ } else { //object creation
+ newObject = objectInstance;
+ }
+
JavaScriptInterfaceSingleton::Instance().setObjectProperty(
gContext,
parent,
declaration->getName(),
- objectInstance);
+ newObject);
//notice
if (declaration->getOptions() &&
m_iframeSupport.clean();
}
-void Explorer::callEventListeners(CustomEventType /*eventType*/, void* /*data*/)
+void Explorer::callEventListeners(CustomEventType eventType, void* data)
{
#if 0 // deprecated
using namespace WrtPlugins::Tizen;
const std::string &propertyName,
const JSObjectPtr& propertyObject)
{
- LogInfo("JSObjectSetProperty(" << context << ", \"" << propertyName << "\")");
+ LogInfo("Webkit:setting property --" << propertyName << "--");
//create name
JSStringRef name = JSStringCreateWithUTF8CString(propertyName.c_str());
//nothing to do -> no context
return;
}
- LogDebug("JSObjectDeleteProperty(" << context << ", \"" << propertyName << "\")");
+ LogDebug("Deleting property --" << propertyName << "--");
JSStringRef name = JSStringCreateWithUTF8CString(propertyName.c_str());
JSObjectDeleteProperty(
const std::string &name,
js_function_impl functionImplementation) const
{
- LogDebug("JSObjectMakeFunctionWithCallback(" << context << ", \"" << name << "\")");
+ LogDebug("Create JS function");
JSStringRef jsFunName = JSStringCreateWithUTF8CString(name.c_str());
JSObjectRef object = JSObjectMakeFunctionWithCallback(
JSGlobalContextRef context,
JSObjectDeclaration::ConstClassTemplate classTemplate) const
{
- LogDebug("JSObjectMake(" << context << ")");
+ LogDebug("Create JS object");
JSObjectRef object = JSObjectMake(
context,
static_cast<JSClassRef>(
JSGlobalContextRef context,
const std::string &interfaceName) const
{
- LogDebug("makeJSObjectBasedOnInterface(" << context << ", \"" << interfaceName << "\"");
+ LogDebug("Create JS object base on interface: " << interfaceName);
+ LogDebug("Context: " << context);
JSObjectPtr jsInterfaceObj = getJSObjectProperty(context,
getGlobalObject(
const std::string& name)
const
{
- LogDebug("getJSObjectProperty(" << ctx << ", \"" << name << "\")");
-
JSObjectRef frame_js = static_cast<JSObjectRef>(frame->getObject());
JSValueRef property = getPropertyObj(ctx, frame_js, name.c_str());
private:
PluginPtr loadLibrary(PluginModelPtr& pluginModel);
+ void loadInjectedJavaScript();
void installStandardFunctions();
- void installRootPlugins();
+ void installRootPlugins();
void installRequestedFeatures();
//returns true if success or false if failed
m_sessionStarted(false),
m_objectExplorer(NULL)
{
+ // DPL::Log::LogSystemSingleton::Instance().SetTag("WRT_PLUGINS");
LogDebug("Initializing Page Session");
m_pluginsSupport = support;
+
+ // explicit call to keep singleton's lifetime until calling destructor.
+ // JsFunctionManagerSingleton::Instance();
+ // JavaScriptInterfaceSingleton::Instance();
}
JSPageSession::Impl::~Impl()
m_objectExplorer->registerObject(*it, NULL);
}
- LogInfo("Installing standard functions...[done]");
+ LogInfo("Standard functions installed.");
}
void JSPageSession::Impl::installRootPlugins()
installPlugin(*it);
}
- LogInfo("Installing requested root plugins...[done]");
+ LogInfo("requested root plugins installed.");
}
bool JSPageSession::Impl::installPlugin(PluginModelPtr plugin)
return false;
}
- LogInfo("Install Plugin : " << library->GetFileName());
+ LogInfo("Install Plugin '" << library->GetFileName());
// Register new class
FOREACH(it, *(library->GetClassList()))
}
}
- LogInfo("Install Plugin [done]");
+ LogDebug("Registered feature.");
return true;
}
m_objectExplorer->callEventListeners(eventType, data);
}
+void JSPageSession::Impl::loadInjectedJavaScript()
+{
+ LogInfo("Entered");
+
+ std::string DIR_PATH = "/usr/etc/wrt/injected-javascript";
+ std::string JS_EXTENSION = ".js";
+
+ DIR *dir = opendir(DIR_PATH.c_str());
+
+ if (!dir) {
+ LogError("opendir(\"" << DIR_PATH << "\") error!");
+ return;
+ }
+
+ int return_code;
+ struct dirent libdir;
+ struct dirent* result;
+ std::list<std::string> jsFiles;
+
+ // make file list from DIR_PATH
+ for (return_code = readdir_r(dir, &libdir, &result);
+ result != NULL && return_code == 0;
+ return_code = readdir_r(dir, &libdir, &result)) {
+ if (strncmp(libdir.d_name, ".", 2) == 0 ||
+ strncmp(libdir.d_name, "..", 3) == 0)
+ {
+ continue;
+ }
+
+ std::string filepath = DIR_PATH;
+ filepath += "/";
+ filepath += libdir.d_name;
+
+ std::string lowercase = filepath;
+ std::transform(lowercase.begin(), lowercase.end(), lowercase.begin(),
+ towlower);
+
+ if (lowercase.rfind(JS_EXTENSION) == std::string::npos ||
+ lowercase.length() !=
+ lowercase.rfind(JS_EXTENSION) + JS_EXTENSION.length() )
+ {
+ LogError("This is not js file" << filepath);
+ continue;
+ }
+
+ struct stat tmp;
+
+ if (stat(filepath.c_str(), &tmp) == -1) {
+ LogError("Failed to open file " << filepath);
+ continue;
+ }
+
+ if (!S_ISREG(tmp.st_mode)) {
+ LogError("This is not a regular file " << filepath);
+ continue;
+ }
+
+ LogInfo("Added : " << filepath);
+ jsFiles.push_back(filepath);
+ }
+ if (0 != return_code)
+ LogError("Error while reading directory.");
+
+ closedir(dir);
+
+ FOREACH(it, jsFiles)
+ {
+ LogDebug("load file : " << (*it));
+ // load file
+ std::string content;
+ std::ifstream fin(it->c_str());
+
+ while (fin.good()) {
+ string line;
+ std::getline(fin, line);
+ content += line + "\n";
+ }
+
+ fin.close();
+ // execute
+ if (!content.empty()) {
+ JSValueRef exception = NULL;
+ JSStringRef script =
+ JSStringCreateWithUTF8CString(content.c_str());
+
+ JSEvaluateScript(m_context, script, NULL, NULL, 1, &exception);
+
+ JSStringRelease(script);
+
+ if (exception) {
+ LogDebug("Exception Occured while injecting javascript "
+ "file. : " << *it);
+
+ JSStringRef exceptionJSString =
+ JSValueToStringCopy(m_context, exception, NULL);
+ size_t size =
+ JSStringGetMaximumUTF8CStringSize(exceptionJSString);
+ char* exceptionString = new char[size];
+ JSStringGetUTF8CString(exceptionJSString,
+ exceptionString, size);
+ LogDebug("Exception : " << exceptionString);
+
+ delete[] exceptionString;
+ JSStringRelease(exceptionJSString);
+ }
+ }
+ }
+}
+
void JSPageSession::Impl::startSession(int widgetHandle,
JSGlobalContextRef context,
double scaleFactor,
// set scale, bundle as window's property
setCustomProperties(scaleFactor, encodedBundle, theme);
- LogInfo("Starting widget session...[done]");
+ // Load injected javascript files
+ loadInjectedJavaScript();
+ LogInfo("Widget session started.");
}
void JSPageSession::Impl::stopSession()
FOREACH(pluginIt, m_loadedPlugins)
{
- LogDebug("Try to call 'OnFrameLoad' callback : " << (*pluginIt)->GetFileName());
+ LogDebug("load plugin to frame" << (*pluginIt)->GetFileName());
(*pluginIt)->OnFrameLoad(context);
}
FOREACH(pluginIt, m_loadedPlugins)
{
- LogDebug("Try to call 'OnFrameUnload' callback : " << (*pluginIt)->GetFileName());
+ LogDebug("unload plugin to frame" << (*pluginIt)->GetFileName());
(*pluginIt)->OnFrameUnload(context);
}
{
if (NULL != m_apiOnWidgetStart) {
(*m_apiOnWidgetStart)(widgetId);
- LogInfo("Called!");
+ } else {
+ LogWarning("OnWidgetStart not set!");
}
}
Assert(NULL != mapping && "NULL mapping interface provided");
if (NULL != m_apiOnWidgetInit) {
(*m_apiOnWidgetInit)(mapping);
- LogInfo("Called!");
+ } else {
+ LogWarning("OnWidgetInit not set!");
}
}
{
if (NULL != m_apiOnWidgetStop) {
(*m_apiOnWidgetStop)(widgetId);
- LogInfo("Called!");
+ } else {
+ LogWarning("OnWidgetStop not set!");
}
}
{
if (NULL != m_apiOnFrameLoad) {
(*m_apiOnFrameLoad)(context);
- LogInfo("Called!");
+ } else {
+ LogWarning("OnFrameLoad not set!");
}
}
{
if (NULL != m_apiOnFrameUnload) {
(*m_apiOnFrameUnload)(context);
- LogInfo("Called!");
+ } else {
+ LogWarning("OnFrameUnload not set!");
}
}
void JSWidget::initialize(JSContextRef context,
JSObjectRef object)
{
- LogDebug("entered. Context : " << context << ", Object: " << object);
+ LogDebug("entered. Context : " << context);
+ LogDebug("Object: " << object);
JSWidgetPrivateObject* priv =
static_cast<JSWidgetPrivateObject*>(JSObjectGetPrivate(object));
priv = new JSWidgetPrivateObject(context, widgetPriv);
JSObjectSetPrivate(object, priv);
+ LogDebug("private object created");
}
Catch(Commons::InvalidArgumentException){
LogError("You should register widget id in ON_WIDGET_START");
}
void JSWidget::acquireGlobalContext(java_script_context_t global_context,
- js_object_instance_t /*iframe*/,
- js_object_instance_t /*object*/)
+ js_object_instance_t iframe,
+ js_object_instance_t object)
{
if (!m_globalContext) {
m_globalContext = static_cast<JSContextRef>(global_context);