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/log.h>
26 using namespace PluginModule;
29 const char *NAVIGATOR_PROPERTY_NAME = "navigator";
30 const char *SCALE_PROPERTY_NAME = "scale";
31 const char *BUNDLE_PROPERTY_NAME = "__bundle";
32 const char *THEME_PROPERTY_NAME = "theme";
34 WindowPropertySupport::WindowPropertySupport(
35 JSGlobalContextRef context):
43 WindowPropertySupport::~WindowPropertySupport()
47 float WindowPropertySupport::getScale() const
52 std::string WindowPropertySupport::getBundle() const
57 std::string WindowPropertySupport::getTheme() const
62 JSGlobalContextRef WindowPropertySupport::getJSContext() const
67 void WindowPropertySupport::setScaleToNavigatorProperty(const double scale)
69 LogInfo("set window.navigator.scale: " << scale);
73 setPropertyToNavigator(SCALE_PROPERTY_NAME, JSValueMakeNumber(m_context, scale));
76 void WindowPropertySupport::setBundleToWindowProperty(const char* bundle)
78 LogInfo("set window.__bundle: " << bundle);
84 JSStringRef bundleString = JSStringCreateWithUTF8CString(bundle);
86 setPropertyToWindow(BUNDLE_PROPERTY_NAME,
87 JSValueMakeString(m_context, bundleString));
89 JSStringRelease(bundleString);
94 void WindowPropertySupport::setBundleToNavigatorProperty(const char* bundle)
96 LogInfo("set window.navigator.__bundle: " << bundle);
102 JSStringRef bundleString = JSStringCreateWithUTF8CString(bundle);
104 setPropertyToNavigator(BUNDLE_PROPERTY_NAME,
105 JSValueMakeString(m_context, bundleString));
107 JSStringRelease(bundleString);
111 void WindowPropertySupport::setThemeToNavigatorProperty(const char* theme)
113 LogInfo("set window.navigator.__theme: " << theme);
119 JSStringRef themeString = JSStringCreateWithUTF8CString(theme);
121 setPropertyToNavigator(THEME_PROPERTY_NAME,
122 JSValueMakeString(m_context, themeString));
124 JSStringRelease(themeString);
128 void WindowPropertySupport::setPropertyToWindow(const char* propertyName,
133 JSObjectRef globalObject = JSContextGetGlobalObject(m_context);
135 JSStringRef propertyNameString =
136 JSStringCreateWithUTF8CString(propertyName);
137 JSObjectSetProperty(m_context,
141 kJSPropertyAttributeReadOnly,
144 JSStringRelease(propertyNameString);
148 void WindowPropertySupport::setPropertyToNavigator(const char* propertyName,
153 JSObjectRef globalObject = JSContextGetGlobalObject(m_context);
155 JSStringRef navigatorString =
156 JSStringCreateWithUTF8CString(NAVIGATOR_PROPERTY_NAME);
157 JSValueRef navigatorValue = JSObjectGetProperty(m_context,
162 JSStringRef propertyNameString =
163 JSStringCreateWithUTF8CString(propertyName);
164 JSObjectSetProperty(m_context,
165 JSValueToObject(m_context, navigatorValue, NULL),
168 kJSPropertyAttributeReadOnly,
171 JSStringRelease(propertyNameString);
172 JSStringRelease(navigatorString);