1635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project/* 22daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben Murdoch * Copyright (C) 2011 Google Inc. All rights reserved. 32daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben Murdoch * 42daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben Murdoch * Redistribution and use in source and binary forms, with or without 52daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben Murdoch * modification, are permitted provided that the following conditions 62daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben Murdoch * are met: 72daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben Murdoch * 1. Redistributions of source code must retain the above copyright 82daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben Murdoch * notice, this list of conditions and the following disclaimer. 92daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben Murdoch * 2. Redistributions in binary form must reproduce the above copyright 102daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben Murdoch * notice, this list of conditions and the following disclaimer in the 112daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben Murdoch * documentation and/or other materials provided with the distribution. 122daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben Murdoch * 132daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben Murdoch * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY 142daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben Murdoch * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 152daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben Murdoch * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 162daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben Murdoch * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY 172daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben Murdoch * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 182daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben Murdoch * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 192daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben Murdoch * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 202daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben Murdoch * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 212daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben Murdoch * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 222daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben Murdoch * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project */ 24635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project 25635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project#include "config.h" 26d0825bca7fe65beaee391d30da42e937db621564Steve Block#include "V8Navigator.h" 27635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project 28bbcce278be9be6a85f47928c38a74c8d36a13a85Ben Murdoch#if ENABLE(MEDIA_STREAM) || (PLATFORM(ANDROID) && ENABLE(APPLICATION_INSTALLED)) 29151150803320bb522017b71c36e1855764d640f8Andrei Popescu 30bbcce278be9be6a85f47928c38a74c8d36a13a85Ben Murdoch#include "Navigator.h" 31bbcce278be9be6a85f47928c38a74c8d36a13a85Ben Murdoch#include "V8Binding.h" 32bbcce278be9be6a85f47928c38a74c8d36a13a85Ben Murdoch#include "V8NavigatorUserMediaErrorCallback.h" 33bbcce278be9be6a85f47928c38a74c8d36a13a85Ben Murdoch#include "V8NavigatorUserMediaSuccessCallback.h" 34bbcce278be9be6a85f47928c38a74c8d36a13a85Ben Murdoch#include "V8Utilities.h" 35bbcce278be9be6a85f47928c38a74c8d36a13a85Ben Murdoch 36bbcce278be9be6a85f47928c38a74c8d36a13a85Ben Murdoch#if PLATFORM(ANDROID) && ENABLE(APPLICATION_INSTALLED) 3728d479b346abf9bc37692d5542fdfaef7b8b0532Steve Block#include "ExceptionCode.h" 38151150803320bb522017b71c36e1855764d640f8Andrei Popescu#include "V8CustomApplicationInstalledCallback.h" 391eef9cbdc7e99b57fa05bfd7e4baefc4a452fbe8Steve Block#include "V8Proxy.h" 40bbcce278be9be6a85f47928c38a74c8d36a13a85Ben Murdoch#endif 41bbcce278be9be6a85f47928c38a74c8d36a13a85Ben Murdoch 42bbcce278be9be6a85f47928c38a74c8d36a13a85Ben Murdochusing namespace WTF; 43635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project 44635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Projectnamespace WebCore { 45bbcce278be9be6a85f47928c38a74c8d36a13a85Ben Murdoch#if ENABLE(MEDIA_STREAM) // ANDROID 46bbcce278be9be6a85f47928c38a74c8d36a13a85Ben Murdochv8::Handle<v8::Value> V8Navigator::webkitGetUserMediaCallback(const v8::Arguments& args) 47bbcce278be9be6a85f47928c38a74c8d36a13a85Ben Murdoch{ 48bbcce278be9be6a85f47928c38a74c8d36a13a85Ben Murdoch INC_STATS("DOM.Navigator.webkitGetUserMedia()"); 49bbcce278be9be6a85f47928c38a74c8d36a13a85Ben Murdoch 50bbcce278be9be6a85f47928c38a74c8d36a13a85Ben Murdoch v8::TryCatch exceptionCatcher; 51bbcce278be9be6a85f47928c38a74c8d36a13a85Ben Murdoch String options = toWebCoreString(args[0]); 52bbcce278be9be6a85f47928c38a74c8d36a13a85Ben Murdoch if (exceptionCatcher.HasCaught()) 53bbcce278be9be6a85f47928c38a74c8d36a13a85Ben Murdoch return throwError(exceptionCatcher.Exception()); 54bbcce278be9be6a85f47928c38a74c8d36a13a85Ben Murdoch 55bbcce278be9be6a85f47928c38a74c8d36a13a85Ben Murdoch bool succeeded = false; 56bbcce278be9be6a85f47928c38a74c8d36a13a85Ben Murdoch 57bbcce278be9be6a85f47928c38a74c8d36a13a85Ben Murdoch RefPtr<NavigatorUserMediaSuccessCallback> successCallback = createFunctionOnlyCallback<V8NavigatorUserMediaSuccessCallback>(args[1], succeeded); 58bbcce278be9be6a85f47928c38a74c8d36a13a85Ben Murdoch if (!succeeded) 59bbcce278be9be6a85f47928c38a74c8d36a13a85Ben Murdoch return v8::Undefined(); 60bbcce278be9be6a85f47928c38a74c8d36a13a85Ben Murdoch 61bbcce278be9be6a85f47928c38a74c8d36a13a85Ben Murdoch // Argument is optional, hence undefined is allowed. 62bbcce278be9be6a85f47928c38a74c8d36a13a85Ben Murdoch RefPtr<NavigatorUserMediaErrorCallback> errorCallback = createFunctionOnlyCallback<V8NavigatorUserMediaErrorCallback>(args[2], succeeded, CallbackAllowUndefined); 63bbcce278be9be6a85f47928c38a74c8d36a13a85Ben Murdoch if (!succeeded) 64bbcce278be9be6a85f47928c38a74c8d36a13a85Ben Murdoch return v8::Undefined(); 65bbcce278be9be6a85f47928c38a74c8d36a13a85Ben Murdoch 66bbcce278be9be6a85f47928c38a74c8d36a13a85Ben Murdoch Navigator* navigator = V8Navigator::toNative(args.Holder()); 67bbcce278be9be6a85f47928c38a74c8d36a13a85Ben Murdoch navigator->webkitGetUserMedia(options, successCallback.release(), errorCallback.release()); 68bbcce278be9be6a85f47928c38a74c8d36a13a85Ben Murdoch return v8::Undefined(); 69bbcce278be9be6a85f47928c38a74c8d36a13a85Ben Murdoch} 70bbcce278be9be6a85f47928c38a74c8d36a13a85Ben Murdoch#endif // ANDROID 71635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project 72bbcce278be9be6a85f47928c38a74c8d36a13a85Ben Murdoch#if PLATFORM(ANDROID) && ENABLE(APPLICATION_INSTALLED) 73151150803320bb522017b71c36e1855764d640f8Andrei Popescustatic PassRefPtr<ApplicationInstalledCallback> createApplicationInstalledCallback( 74151150803320bb522017b71c36e1855764d640f8Andrei Popescu v8::Local<v8::Value> value, bool& succeeded) 75151150803320bb522017b71c36e1855764d640f8Andrei Popescu{ 76151150803320bb522017b71c36e1855764d640f8Andrei Popescu succeeded = true; 77151150803320bb522017b71c36e1855764d640f8Andrei Popescu 78151150803320bb522017b71c36e1855764d640f8Andrei Popescu if (!value->IsFunction()) { 79151150803320bb522017b71c36e1855764d640f8Andrei Popescu succeeded = false; 80151150803320bb522017b71c36e1855764d640f8Andrei Popescu throwError("The second argument should be a function"); 81151150803320bb522017b71c36e1855764d640f8Andrei Popescu return 0; 82151150803320bb522017b71c36e1855764d640f8Andrei Popescu } 83151150803320bb522017b71c36e1855764d640f8Andrei Popescu 84151150803320bb522017b71c36e1855764d640f8Andrei Popescu Frame* frame = V8Proxy::retrieveFrameForCurrentContext(); 85151150803320bb522017b71c36e1855764d640f8Andrei Popescu return V8CustomApplicationInstalledCallback::create(value, frame); 86151150803320bb522017b71c36e1855764d640f8Andrei Popescu} 87151150803320bb522017b71c36e1855764d640f8Andrei Popescu 88151150803320bb522017b71c36e1855764d640f8Andrei Popescuv8::Handle<v8::Value> V8Navigator::isApplicationInstalledCallback(const v8::Arguments& args) 89151150803320bb522017b71c36e1855764d640f8Andrei Popescu{ 90151150803320bb522017b71c36e1855764d640f8Andrei Popescu INC_STATS("DOM.isApplicationInstalled()"); 91151150803320bb522017b71c36e1855764d640f8Andrei Popescu bool succeeded = false; 92151150803320bb522017b71c36e1855764d640f8Andrei Popescu 93151150803320bb522017b71c36e1855764d640f8Andrei Popescu if (args.Length() < 2) 94151150803320bb522017b71c36e1855764d640f8Andrei Popescu return throwError("Two arguments required: an application name and a callback.", V8Proxy::SyntaxError); 95151150803320bb522017b71c36e1855764d640f8Andrei Popescu 96151150803320bb522017b71c36e1855764d640f8Andrei Popescu if (!args[0]->IsString()) 97151150803320bb522017b71c36e1855764d640f8Andrei Popescu return throwError("The first argument should be a string."); 98151150803320bb522017b71c36e1855764d640f8Andrei Popescu 99151150803320bb522017b71c36e1855764d640f8Andrei Popescu RefPtr<ApplicationInstalledCallback> callback = 100151150803320bb522017b71c36e1855764d640f8Andrei Popescu createApplicationInstalledCallback(args[1], succeeded); 101151150803320bb522017b71c36e1855764d640f8Andrei Popescu if (!succeeded) 102151150803320bb522017b71c36e1855764d640f8Andrei Popescu return v8::Undefined(); 103151150803320bb522017b71c36e1855764d640f8Andrei Popescu 104151150803320bb522017b71c36e1855764d640f8Andrei Popescu ASSERT(callback); 105151150803320bb522017b71c36e1855764d640f8Andrei Popescu 106151150803320bb522017b71c36e1855764d640f8Andrei Popescu Navigator* navigator = V8Navigator::toNative(args.Holder()); 1079fed475722a5da7e9fac4d78715b17ca5ed29335Andrei Popescu if (!navigator->isApplicationInstalled(toWebCoreString(args[0]), callback.release())) 1089fed475722a5da7e9fac4d78715b17ca5ed29335Andrei Popescu return throwError(INVALID_STATE_ERR); 1099fed475722a5da7e9fac4d78715b17ca5ed29335Andrei Popescu 110151150803320bb522017b71c36e1855764d640f8Andrei Popescu return v8::Undefined(); 111151150803320bb522017b71c36e1855764d640f8Andrei Popescu} 112bbcce278be9be6a85f47928c38a74c8d36a13a85Ben Murdoch#endif // PLATFORM(ANDROID) && ENABLE(APPLICATION_INSTALLED) 113151150803320bb522017b71c36e1855764d640f8Andrei Popescu 114635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project} // namespace WebCore 1150a06e7e772d95238accdb0139e5069b3e75091b1Steve Block 116bbcce278be9be6a85f47928c38a74c8d36a13a85Ben Murdoch#endif // ENABLE(MEDIA_STREAM) || PLATFORM(ANDROID) && ENABLE(APPLICATION_INSTALLED) 117bbcce278be9be6a85f47928c38a74c8d36a13a85Ben Murdoch 118