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;
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 LogInfo("set window.navigator.scale: " << scale);
70 setPropertyToNavigator(SCALE_PROPERTY_NAME,
71 JSValueMakeNumber(m_context, scale));
74 void WindowPropertySupport::setBundleToWindowProperty(const char* bundle)
76 LogInfo("set window.__bundle: " << bundle);
81 JSStringRef bundleString = JSStringCreateWithUTF8CString(bundle);
83 setPropertyToWindow(BUNDLE_PROPERTY_NAME,
84 JSValueMakeString(m_context, bundleString));
86 JSStringRelease(bundleString);
90 void WindowPropertySupport::setThemeToNavigatorProperty(const char* theme)
92 LogInfo("set window.navigator.__theme: " << theme);
97 JSStringRef themeString = JSStringCreateWithUTF8CString(theme);
99 setPropertyToNavigator(THEME_PROPERTY_NAME,
100 JSValueMakeString(m_context, themeString));
102 JSStringRelease(themeString);
106 void WindowPropertySupport::setPropertyToWindow(const char* propertyName,
110 JSObjectRef globalObject = JSContextGetGlobalObject(m_context);
112 JSStringRef propertyNameString =
113 JSStringCreateWithUTF8CString(propertyName);
114 JSObjectSetProperty(m_context,
118 kJSPropertyAttributeReadOnly,
121 JSStringRelease(propertyNameString);
125 void WindowPropertySupport::setPropertyToNavigator(const char* propertyName,
129 JSObjectRef globalObject = JSContextGetGlobalObject(m_context);
131 JSStringRef navigatorString =
132 JSStringCreateWithUTF8CString(NAVIGATOR_PROPERTY_NAME);
133 JSValueRef navigatorValue = JSObjectGetProperty(m_context,
138 JSStringRef propertyNameString =
139 JSStringCreateWithUTF8CString(propertyName);
140 JSObjectSetProperty(m_context,
141 JSValueToObject(m_context, navigatorValue, NULL),
144 kJSPropertyAttributeReadOnly,
147 JSStringRelease(propertyNameString);
148 JSStringRelease(navigatorString);