2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 * @file plugin_property_support.cpp
18 * @author Yunchan Cho (yunchan.cho@samsung.com)
23 #include "plugin_property_support.h"
24 #include <dpl/log/secure_log.h>
26 using namespace PluginModule;
28 const char *NAVIGATOR_PROPERTY_NAME = "navigator";
29 const char *SCALE_PROPERTY_NAME = "scale";
30 const char *BUNDLE_PROPERTY_NAME = "__bundle";
31 const char *THEME_PROPERTY_NAME = "theme";
33 WindowPropertySupport::WindowPropertySupport(
34 JSGlobalContextRef context) :
41 WindowPropertySupport::~WindowPropertySupport()
44 float WindowPropertySupport::getScale() const
49 std::string WindowPropertySupport::getBundle() const
54 std::string WindowPropertySupport::getTheme() const
59 JSGlobalContextRef WindowPropertySupport::getJSContext() const
64 void WindowPropertySupport::setScaleToNavigatorProperty(const double scale)
66 _D("set window.navigator.scale: %ld", scale);
68 setPropertyToNavigator(SCALE_PROPERTY_NAME,
69 JSValueMakeNumber(m_context, scale));
72 void WindowPropertySupport::setBundleToWindowProperty(const char* bundle)
74 _D("set window.__bundle: %s", bundle);
77 JSStringRef bundleString = JSStringCreateWithUTF8CString(bundle);
78 setPropertyToWindow(BUNDLE_PROPERTY_NAME,
79 JSValueMakeString(m_context, bundleString));
80 JSStringRelease(bundleString);
84 void WindowPropertySupport::setThemeToNavigatorProperty(const char* theme)
86 _D("set window.navigator.__theme: %s", theme);
89 JSStringRef themeString = JSStringCreateWithUTF8CString(theme);
90 setPropertyToNavigator(THEME_PROPERTY_NAME,
91 JSValueMakeString(m_context, themeString));
92 JSStringRelease(themeString);
96 void WindowPropertySupport::setPropertyToWindow(const char* propertyName,
99 _D("et property to window : %s", propertyName);
101 JSObjectRef globalObject = JSContextGetGlobalObject(m_context);
102 JSStringRef propertyNameString =
103 JSStringCreateWithUTF8CString(propertyName);
104 JSObjectSetProperty(m_context,
108 kJSPropertyAttributeReadOnly,
110 JSStringRelease(propertyNameString);
114 void WindowPropertySupport::setPropertyToNavigator(const char* propertyName,
117 _D("set property to navigator : %s", propertyName);
119 JSObjectRef globalObject = JSContextGetGlobalObject(m_context);
121 JSStringRef navigatorString =
122 JSStringCreateWithUTF8CString(NAVIGATOR_PROPERTY_NAME);
123 JSValueRef navigatorValue = JSObjectGetProperty(m_context,
128 JSStringRef propertyNameString =
129 JSStringCreateWithUTF8CString(propertyName);
130 JSObjectSetProperty(m_context,
131 JSValueToObject(m_context, navigatorValue, NULL),
134 kJSPropertyAttributeReadOnly,
137 JSStringRelease(propertyNameString);
138 JSStringRelease(navigatorString);