initial import
[vuplus_webkit] / Source / WebCore / bindings / js / JSNavigatorCustom.cpp
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 "ExceptionCode.h"
28 #include "JSNavigatorUserMediaErrorCallback.h"
29 #include "JSNavigatorUserMediaSuccessCallback.h"
30 #include "Navigator.h"
31
32 namespace WebCore {
33
34 using namespace JSC;
35
36 #if ENABLE(MEDIA_STREAM)
37 JSValue JSNavigator::webkitGetUserMedia(ExecState* exec)
38 {
39     // Arguments: Options, successCallback, (optional)errorCallback
40
41     String options = ustringToString(exec->argument(0).toString(exec));
42     if (exec->hadException())
43         return jsUndefined();
44
45     RefPtr<NavigatorUserMediaSuccessCallback> successCallback = createFunctionOnlyCallback<JSNavigatorUserMediaSuccessCallback>(exec, static_cast<JSDOMGlobalObject*>(exec->lexicalGlobalObject()), exec->argument(1));
46     if (exec->hadException())
47         return jsUndefined();
48
49     RefPtr<NavigatorUserMediaErrorCallback> errorCallback = createFunctionOnlyCallback<JSNavigatorUserMediaErrorCallback>(exec, static_cast<JSDOMGlobalObject*>(exec->lexicalGlobalObject()), exec->argument(2), CallbackAllowUndefined);
50     if (exec->hadException())
51         return jsUndefined();
52
53     ExceptionCode ec = 0;
54     m_impl->webkitGetUserMedia(options, successCallback.release(), errorCallback.release(), ec);
55
56     if (ec)
57         setDOMException(exec, ec);
58
59     return jsUndefined();
60 }
61 #endif // ENABLE(MEDIA_STREAM)
62
63 }