initial import
[vuplus_webkit] / Source / WebCore / bindings / v8 / custom / V8NavigatorCustom.cpp
1 /*
2  * Copyright (C) 2011 Google Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1.  Redistributions of source code must retain the above copyright
8  *     notice, this list of conditions and the following disclaimer.
9  * 2.  Redistributions in binary form must reproduce the above copyright
10  *     notice, this list of conditions and the following disclaimer in the
11  *     documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16  * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
17  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23  */
24
25 #include "config.h"
26 #include "V8Navigator.h"
27
28 #if ENABLE(MEDIA_STREAM)
29
30 #include "ExceptionCode.h"
31 #include "Navigator.h"
32 #include "V8Binding.h"
33 #include "V8NavigatorUserMediaErrorCallback.h"
34 #include "V8NavigatorUserMediaSuccessCallback.h"
35 #include "V8Utilities.h"
36
37 using namespace WTF;
38
39 namespace WebCore {
40
41 v8::Handle<v8::Value> V8Navigator::webkitGetUserMediaCallback(const v8::Arguments& args)
42 {
43     INC_STATS("DOM.Navigator.webkitGetUserMedia()");
44
45     v8::TryCatch exceptionCatcher;
46     v8::Handle<v8::String> options = args[0]->ToString();
47     if (exceptionCatcher.HasCaught())
48         return throwError(exceptionCatcher.Exception());
49
50     bool succeeded = false;
51     RefPtr<NavigatorUserMediaSuccessCallback> successCallback = createFunctionOnlyCallback<V8NavigatorUserMediaSuccessCallback>(args[1], succeeded);
52     if (!succeeded)
53         return v8::Undefined();
54
55     // Argument is optional, hence undefined is allowed.
56     RefPtr<NavigatorUserMediaErrorCallback> errorCallback = createFunctionOnlyCallback<V8NavigatorUserMediaErrorCallback>(args[2], succeeded, CallbackAllowUndefined);
57     if (!succeeded)
58         return v8::Undefined();
59
60     ExceptionCode ec = 0;
61     Navigator* navigator = V8Navigator::toNative(args.Holder());
62     navigator->webkitGetUserMedia(toWebCoreString(options), successCallback.release(), errorCallback.release(), ec);
63     return throwError(ec);
64 }
65
66 } // namespace WebCore
67
68 #endif // ENABLE(MEDIA_STREAM)