1/*
2 *  Copyright (C) 2000 Harri Porten (porten@kde.org)
3 *  Copyright (c) 2000 Daniel Molkentin (molkentin@kde.org)
4 *  Copyright (c) 2000 Stefan Schimanski (schimmi@kde.org)
5 *  Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All Rights Reserved.
6 *  Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
7 *
8 *  This library is free software; you can redistribute it and/or
9 *  modify it under the terms of the GNU Lesser General Public
10 *  License as published by the Free Software Foundation; either
11 *  version 2 of the License, or (at your option) any later version.
12 *
13 *  This library is distributed in the hope that it will be useful,
14 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 *  Lesser General Public License for more details.
17 *
18 *  You should have received a copy of the GNU Lesser General Public
19 *  License along with this library; if not, write to the Free Software
20 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
21 */
22
23#include "config.h"
24#include "JSNavigator.h"
25
26#include "CallbackFunction.h"
27#include "JSNavigatorUserMediaErrorCallback.h"
28#include "JSNavigatorUserMediaSuccessCallback.h"
29#include "Navigator.h"
30#include <runtime/InternalFunction.h>
31
32#if PLATFORM(ANDROID)
33#include "ExceptionCode.h"
34#include "JSCustomApplicationInstalledCallback.h"
35#endif
36
37namespace WebCore {
38
39using namespace JSC;
40
41void JSNavigator::markChildren(MarkStack& markStack)
42{
43    Base::markChildren(markStack);
44
45    JSGlobalData& globalData = *Heap::heap(this)->globalData();
46
47    markDOMObjectWrapper(markStack, globalData, impl()->optionalGeolocation());
48}
49
50#if ENABLE(MEDIA_STREAM)
51JSValue JSNavigator::webkitGetUserMedia(ExecState* exec)
52{
53    // Arguments: Options, successCallback, (optional)errorCallback
54
55    String options = ustringToString(exec->argument(0).toString(exec));
56    if (exec->hadException())
57        return jsUndefined();
58
59    RefPtr<NavigatorUserMediaSuccessCallback> successCallback = createFunctionOnlyCallback<JSNavigatorUserMediaSuccessCallback>(exec, static_cast<JSDOMGlobalObject*>(exec->lexicalGlobalObject()), exec->argument(1));
60    if (exec->hadException())
61        return jsUndefined();
62
63    RefPtr<NavigatorUserMediaErrorCallback> errorCallback = createFunctionOnlyCallback<JSNavigatorUserMediaErrorCallback>(exec, static_cast<JSDOMGlobalObject*>(exec->lexicalGlobalObject()), exec->argument(2), CallbackAllowUndefined);
64    if (exec->hadException())
65        return jsUndefined();
66
67    m_impl->webkitGetUserMedia(options, successCallback.release(), errorCallback.release());
68    return jsUndefined();
69}
70#endif // ENABLE(MEDIA_STREAM)
71
72#if PLATFORM(ANDROID) && ENABLE(APPLICATION_INSTALLED)
73JSC::JSValue  WebCore::JSNavigator::isApplicationInstalled(JSC::ExecState* exec)
74{
75    if (exec->argumentCount() < 2) {
76        setDOMException(exec, SYNTAX_ERR);
77        return jsUndefined();
78    }
79
80    if (!exec->argument(1).inherits(&InternalFunction::s_info)) {
81        setDOMException(exec, TYPE_MISMATCH_ERR);
82        return jsUndefined();
83    }
84
85    String appName = ustringToString(exec->argument(0).toString(exec));
86
87    JSObject* object;
88    if (!(object = exec->argument(1).getObject())) {
89        setDOMException(exec, TYPE_MISMATCH_ERR);
90        return jsUndefined();
91    }
92
93    RefPtr<ApplicationInstalledCallback> callback(JSCustomApplicationInstalledCallback::create(
94            object, static_cast<JSDOMGlobalObject*>(exec->dynamicGlobalObject())));
95
96    if (!m_impl->isApplicationInstalled(appName, callback.release()))
97        setDOMException(exec, INVALID_STATE_ERR);
98    return jsUndefined();
99}
100#endif
101
102}
103