Replace LogInfo to LogDebug
[framework/web/wrt-plugins-common.git] / src / plugin-loading / plugin_property_support.cpp
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 /**
17  * @file    plugin_property_support.cpp
18  * @author  Yunchan Cho (yunchan.cho@samsung.com)
19  * @version 1.0
20  * @brief
21  */
22
23 #include "plugin_property_support.h"
24 #include <dpl/log/log.h>
25
26 using namespace PluginModule;
27
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";
32
33 WindowPropertySupport::WindowPropertySupport(
34     JSGlobalContextRef context) :
35     m_scale(0),
36     m_bundle(""),
37     m_theme(""),
38     m_context(context)
39 {}
40
41 WindowPropertySupport::~WindowPropertySupport()
42 {}
43
44 float WindowPropertySupport::getScale() const
45 {
46     return m_scale;
47 }
48
49 std::string WindowPropertySupport::getBundle() const
50 {
51     return m_bundle;
52 }
53
54 std::string WindowPropertySupport::getTheme() const
55 {
56     return m_theme;
57 }
58
59 JSGlobalContextRef WindowPropertySupport::getJSContext() const
60 {
61     return m_context;
62 }
63
64 void WindowPropertySupport::setScaleToNavigatorProperty(const double scale)
65 {
66     LogDebug("set window.navigator.scale: " << scale);
67
68     m_scale = scale;
69
70     setPropertyToNavigator(SCALE_PROPERTY_NAME,
71                            JSValueMakeNumber(m_context, scale));
72 }
73
74 void WindowPropertySupport::setBundleToWindowProperty(const char* bundle)
75 {
76     LogDebug("set window.__bundle: " << bundle);
77
78     if (bundle) {
79         m_bundle = bundle;
80
81         JSStringRef bundleString = JSStringCreateWithUTF8CString(bundle);
82
83         setPropertyToWindow(BUNDLE_PROPERTY_NAME,
84                             JSValueMakeString(m_context, bundleString));
85
86         JSStringRelease(bundleString);
87     }
88 }
89
90 void WindowPropertySupport::setThemeToNavigatorProperty(const char* theme)
91 {
92     LogDebug("set window.navigator.__theme: " << theme);
93
94     if (theme) {
95         m_theme = theme;
96
97         JSStringRef themeString = JSStringCreateWithUTF8CString(theme);
98
99         setPropertyToNavigator(THEME_PROPERTY_NAME,
100                                JSValueMakeString(m_context, themeString));
101
102         JSStringRelease(themeString);
103     }
104 }
105
106 void WindowPropertySupport::setPropertyToWindow(const char* propertyName,
107                                                 JSValueRef jsValue)
108 {
109     if (propertyName) {
110         JSObjectRef globalObject = JSContextGetGlobalObject(m_context);
111
112         JSStringRef propertyNameString =
113             JSStringCreateWithUTF8CString(propertyName);
114         JSObjectSetProperty(m_context,
115                             globalObject,
116                             propertyNameString,
117                             jsValue,
118                             kJSPropertyAttributeReadOnly,
119                             NULL);
120
121         JSStringRelease(propertyNameString);
122     }
123 }
124
125 void WindowPropertySupport::setPropertyToNavigator(const char* propertyName,
126                                                    JSValueRef jsValue)
127 {
128     if (propertyName) {
129         JSObjectRef globalObject = JSContextGetGlobalObject(m_context);
130
131         JSStringRef navigatorString =
132             JSStringCreateWithUTF8CString(NAVIGATOR_PROPERTY_NAME);
133         JSValueRef navigatorValue = JSObjectGetProperty(m_context,
134                                                         globalObject,
135                                                         navigatorString,
136                                                         NULL);
137
138         JSStringRef propertyNameString =
139             JSStringCreateWithUTF8CString(propertyName);
140         JSObjectSetProperty(m_context,
141                             JSValueToObject(m_context, navigatorValue, NULL),
142                             propertyNameString,
143                             jsValue,
144                             kJSPropertyAttributeReadOnly,
145                             NULL);
146
147         JSStringRelease(propertyNameString);
148         JSStringRelease(navigatorString);
149     }
150 }
151