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 
31 namespace WebCore {
32 
33 using namespace JSC;
34 
35 #if ENABLE(MEDIA_STREAM)
webkitGetUserMedia(ExecState * exec)36 JSValue JSNavigator::webkitGetUserMedia(ExecState* exec)
37 {
38     // Arguments: Options, successCallback, (optional)errorCallback
39 
40     String options = ustringToString(exec->argument(0).toString(exec));
41     if (exec->hadException())
42         return jsUndefined();
43 
44     RefPtr<NavigatorUserMediaSuccessCallback> successCallback = createFunctionOnlyCallback<JSNavigatorUserMediaSuccessCallback>(exec, static_cast<JSDOMGlobalObject*>(exec->lexicalGlobalObject()), exec->argument(1));
45     if (exec->hadException())
46         return jsUndefined();
47 
48     RefPtr<NavigatorUserMediaErrorCallback> errorCallback = createFunctionOnlyCallback<JSNavigatorUserMediaErrorCallback>(exec, static_cast<JSDOMGlobalObject*>(exec->lexicalGlobalObject()), exec->argument(2), CallbackAllowUndefined);
49     if (exec->hadException())
50         return jsUndefined();
51 
52     m_impl->webkitGetUserMedia(options, successCallback.release(), errorCallback.release());
53     return jsUndefined();
54 }
55 #endif // ENABLE(MEDIA_STREAM)
56 
57 }
58