2 // Tizen Web Device API
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 #include <ArgumentValidator.h>
20 #include <GlobalContextManager.h>
22 #include <JSWebAPIError.h>
24 #include <MultiCallbackUserData.h>
25 #include <PlatformException.h>
26 #include <SecurityExceptions.h>
28 #include "plugin_config.h"
29 #include "JSWebSettingManager.h"
31 using namespace WrtDeviceApis::Commons;
32 using namespace DeviceAPI::Common;
39 JSClassDefinition JSWebSettingManager::m_classInfo =
42 kJSClassAttributeNone,
46 m_function, //StaticFunctions
47 initialize, //Initialize
52 NULL, //DeleteProperty,
53 NULL, //GetPropertyNames,
54 NULL, //CallAsFunction,
55 NULL, //CallAsConstructor,
60 JSStaticFunction JSWebSettingManager::m_function[] =
62 { WEB_SETTING_MANAGER_API_SET_USER_AGENT_STRING, setUserAgentString, kJSPropertyAttributeNone },
63 { WEB_SETTING_MANAGER_API_REMOVE_ALL_COOKIES, removeAllCookies, kJSPropertyAttributeNone },
67 JSClassRef JSWebSettingManager::m_jsClassRef = JSClassCreate(JSWebSettingManager::getClassInfo());
69 const JSClassRef JSWebSettingManager::getClassRef()
73 m_jsClassRef = JSClassCreate(&m_classInfo);
78 const JSClassDefinition* JSWebSettingManager::getClassInfo()
83 void JSWebSettingManager::initialize(JSContextRef context, JSObjectRef object)
85 if (!JSObjectGetPrivate(object))
87 SLoggerI("JSWebSettingManager::initialize called...");
88 WebSettingManager *priv = WebSettingManager::getInstance();
89 JSObjectSetPrivate(object, static_cast<void*>(priv));
93 void JSWebSettingManager::finalize(JSObjectRef object)
95 SLoggerI("JSWebSettingManager::finalize called...");
96 WebSettingManager *priv = static_cast<WebSettingManager*>(JSObjectGetPrivate(object));
99 JSObjectSetPrivate(object, NULL);
103 JSValueRef JSWebSettingManager::setUserAgentString(JSContextRef context,
105 JSObjectRef thisObject,
106 size_t argumentCount,
107 const JSValueRef arguments[],
108 JSValueRef* exception)
113 WebSettingManager *priv = static_cast<WebSettingManager*>(JSObjectGetPrivate(thisObject));
116 throw TypeMismatchException("Private object is NULL.");
118 ArgumentValidator validator(context, argumentCount, arguments);
119 MultiCallbackUserData* callbacks = new MultiCallbackUserData(GlobalContextManager::getInstance()->getGlobalContext(context));
122 std::string userAgent = validator.toString(0);
125 JSObjectRef successCallbackObj = validator.toFunction(1, true);
126 if (successCallbackObj)
128 callbacks->setCallback("onsuccess", successCallbackObj);
132 JSObjectRef errorCallbackObj = validator.toFunction(2, true);
134 if (errorCallbackObj)
136 callbacks->setCallback("onerror", errorCallbackObj);
139 priv->setUserAgentString(userAgent, callbacks);
141 return JSValueMakeUndefined(context);
143 catch (const BasePlatformException &err)
145 SLoggerE(err.getName().c_str() << ":" << err.getMessage().c_str());
146 return JSWebAPIErrorFactory::postException(context, exception, err);
150 DeviceAPI::Common::UnknownException err("Unknown Error in WebSettingManager.setUserAgentString().");
151 SLoggerE(err.getName().c_str() << ":" << err.getMessage().c_str());
152 return JSWebAPIErrorFactory::postException(context, exception, err);
156 JSValueRef JSWebSettingManager::removeAllCookies(JSContextRef context,
158 JSObjectRef thisObject,
159 size_t argumentCount,
160 const JSValueRef arguments[],
161 JSValueRef* exception)
163 AceSecurityStatus status = WEB_SETTING_CHECK_ACCESS(WEB_SETTING_MANAGER_API_REMOVE_ALL_COOKIES);
164 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
165 SLoggerI("removeAllCookies::TIZEN_SYNC_ACCESS_HANDLER succeeded.");
170 WebSettingManager *priv = static_cast<WebSettingManager*>(JSObjectGetPrivate(thisObject));
173 throw TypeMismatchException("Private object is NULL.");
176 ArgumentValidator validator(context, argumentCount, arguments);
177 MultiCallbackUserData* callbacks = new MultiCallbackUserData(GlobalContextManager::getInstance()->getGlobalContext(context));
180 JSObjectRef successCallbackObj = validator.toFunction(0, true);
181 if (successCallbackObj)
183 callbacks->setCallback("onsuccess", successCallbackObj);
187 JSObjectRef errorCallbackObj = validator.toFunction(1, true);
188 if (errorCallbackObj)
190 callbacks->setCallback("onerror", errorCallbackObj);
192 priv->removeAllCookies(callbacks);
193 return JSValueMakeUndefined(context);
195 catch (const BasePlatformException &err)
197 SLoggerE(err.getName().c_str() << ":" << err.getMessage().c_str());
198 return JSWebAPIErrorFactory::postException(context, exception, err);
202 DeviceAPI::Common::UnknownException err("Unknown Error in WebSettingManager.removeAllCookies().");
203 SLoggerE(err.getName().c_str() << ":" << err.getMessage().c_str());
204 return JSWebAPIErrorFactory::postException(context, exception, err);