V8NavigatorCustom.cpp revision 2daae5fd11344eaa88a0d92b0f6d65f8d2255c00
1/* 2<<<<<<< HEAD 3 * Copyright (C) 2010 Google Inc. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: 8 * 9 * * Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * * Redistributions in binary form must reproduce the above 12 * copyright notice, this list of conditions and the following disclaimer 13 * in the documentation and/or other materials provided with the 14 * distribution. 15 * * Neither the name of Google Inc. nor the names of its 16 * contributors may be used to endorse or promote products derived from 17 * this software without specific prior written permission. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30======= 31 * Copyright (C) 2011 Google Inc. All rights reserved. 32 * 33 * Redistribution and use in source and binary forms, with or without 34 * modification, are permitted provided that the following conditions 35 * are met: 36 * 1. Redistributions of source code must retain the above copyright 37 * notice, this list of conditions and the following disclaimer. 38 * 2. Redistributions in binary form must reproduce the above copyright 39 * notice, this list of conditions and the following disclaimer in the 40 * documentation and/or other materials provided with the distribution. 41 * 42 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY 43 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 44 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 45 * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY 46 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 47 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 48 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 49 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 50 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 51 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 52>>>>>>> WebKit.org at r84325 53 */ 54 55#include "config.h" 56#include "V8Navigator.h" 57 58<<<<<<< HEAD 59#if PLATFORM(ANDROID) && ENABLE(APPLICATION_INSTALLED) 60 61#include "ExceptionCode.h" 62#include "V8CustomApplicationInstalledCallback.h" 63#include "V8Binding.h" 64#include "V8Proxy.h" 65 66namespace WebCore { 67 68static PassRefPtr<ApplicationInstalledCallback> createApplicationInstalledCallback( 69 v8::Local<v8::Value> value, bool& succeeded) 70{ 71 succeeded = true; 72 73 if (!value->IsFunction()) { 74 succeeded = false; 75 throwError("The second argument should be a function"); 76 return 0; 77 } 78 79 Frame* frame = V8Proxy::retrieveFrameForCurrentContext(); 80 return V8CustomApplicationInstalledCallback::create(value, frame); 81} 82 83v8::Handle<v8::Value> V8Navigator::isApplicationInstalledCallback(const v8::Arguments& args) 84{ 85 INC_STATS("DOM.isApplicationInstalled()"); 86 bool succeeded = false; 87 88 if (args.Length() < 2) 89 return throwError("Two arguments required: an application name and a callback.", V8Proxy::SyntaxError); 90 91 if (!args[0]->IsString()) 92 return throwError("The first argument should be a string."); 93 94 RefPtr<ApplicationInstalledCallback> callback = 95 createApplicationInstalledCallback(args[1], succeeded); 96 if (!succeeded) 97 return v8::Undefined(); 98 99 ASSERT(callback); 100 101 Navigator* navigator = V8Navigator::toNative(args.Holder()); 102 if (!navigator->isApplicationInstalled(toWebCoreString(args[0]), callback.release())) 103 return throwError(INVALID_STATE_ERR); 104 105======= 106#if ENABLE(MEDIA_STREAM) 107 108#include "Navigator.h" 109#include "V8Binding.h" 110#include "V8NavigatorUserMediaErrorCallback.h" 111#include "V8NavigatorUserMediaSuccessCallback.h" 112#include "V8Utilities.h" 113 114using namespace WTF; 115 116namespace WebCore { 117 118v8::Handle<v8::Value> V8Navigator::webkitGetUserMediaCallback(const v8::Arguments& args) 119{ 120 INC_STATS("DOM.Navigator.webkitGetUserMedia()"); 121 122 v8::TryCatch exceptionCatcher; 123 String options = toWebCoreString(args[0]); 124 if (exceptionCatcher.HasCaught()) 125 return throwError(exceptionCatcher.Exception()); 126 127 bool succeeded = false; 128 129 RefPtr<NavigatorUserMediaSuccessCallback> successCallback = createFunctionOnlyCallback<V8NavigatorUserMediaSuccessCallback>(args[1], succeeded); 130 if (!succeeded) 131 return v8::Undefined(); 132 133 // Argument is optional, hence undefined is allowed. 134 RefPtr<NavigatorUserMediaErrorCallback> errorCallback = createFunctionOnlyCallback<V8NavigatorUserMediaErrorCallback>(args[2], succeeded, CallbackAllowUndefined); 135 if (!succeeded) 136 return v8::Undefined(); 137 138 Navigator* navigator = V8Navigator::toNative(args.Holder()); 139 navigator->webkitGetUserMedia(options, successCallback.release(), errorCallback.release()); 140>>>>>>> WebKit.org at r84325 141 return v8::Undefined(); 142} 143 144} // namespace WebCore 145 146<<<<<<< HEAD 147#endif // PLATFORM(ANDROID) && ENABLE(APPLICATION_INSTALLED) 148======= 149#endif // ENABLE(MEDIA_STREAM) 150>>>>>>> WebKit.org at r84325 151