|
Line 0
a/Source/WebCore/bindings/v8/custom/V8TextTrackCueCustom.cpp_sec1
|
|
|
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 are |
| 6 |
* met: |
| 7 |
* |
| 8 |
* * Redistributions of source code must retain the above copyright |
| 9 |
* notice, this list of conditions and the following disclaimer. |
| 10 |
* * Redistributions in binary form must reproduce the above |
| 11 |
* copyright notice, this list of conditions and the following disclaimer |
| 12 |
* in the documentation and/or other materials provided with the |
| 13 |
* distribution. |
| 14 |
* * Neither the name of Google Inc. nor the names of its |
| 15 |
* contributors may be used to endorse or promote products derived from |
| 16 |
* this software without specific prior written permission. |
| 17 |
* |
| 18 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 19 |
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 20 |
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 21 |
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 |
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 |
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 |
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 |
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 |
*/ |
| 30 |
|
| 31 |
#include "config.h" |
| 32 |
|
| 33 |
#if ENABLE(VIDEO_TRACK) |
| 34 |
|
| 35 |
#include "V8TextTrackCue.h" |
| 36 |
|
| 37 |
#include "WorkerContext.h" |
| 38 |
|
| 39 |
namespace WebCore { |
| 40 |
|
| 41 |
v8::Handle<v8::Value> V8TextTrackCue::constructorCallback(const v8::Arguments& args) |
| 42 |
{ |
| 43 |
INC_STATS("DOM.TextTrackCue.Constructor"); |
| 44 |
|
| 45 |
// If we return an already existing TextTrackCue (e.g. from |
| 46 |
// TextTrackCue.getCueById()), this code is called with a zero-length |
| 47 |
// argument list. The V8DOMWrapper will then set the internal pointer in |
| 48 |
// the newly created object. |
| 49 |
// Unfortunately it doesn't look like it's possible to distinguish between |
| 50 |
// this case and that where the user calls "new TextTrackCue(..)" from |
| 51 |
// JavaScript. To guard against problems, we always create at least an |
| 52 |
// "empty" TextTrackCue, even if it is immediately overwritten by the V8DOMWrapper. |
| 53 |
|
| 54 |
if (!args.IsConstructCall()) |
| 55 |
return throwError("DOM object custructor cannot be called as a function."); |
| 56 |
|
| 57 |
String id = ""; |
| 58 |
double startTime = 0; |
| 59 |
double endTime = 0; |
| 60 |
String content = ""; |
| 61 |
String settings = ""; |
| 62 |
bool pauseOnExit = false; |
| 63 |
|
| 64 |
if (args.Length() > 0) { |
| 65 |
|
| 66 |
if (args.Length() < 4) |
| 67 |
return throwError("Not enough arguments", V8Proxy::SyntaxError); |
| 68 |
|
| 69 |
v8::TryCatch tryCatch; |
| 70 |
id = toWebCoreString(args[0]); |
| 71 |
if (tryCatch.HasCaught()) |
| 72 |
return throwError(tryCatch.Exception()); |
| 73 |
if (id.isEmpty()) |
| 74 |
return throwError("Empty ID", V8Proxy::SyntaxError); |
| 75 |
|
| 76 |
startTime = args[1]->NumberValue(); |
| 77 |
if (tryCatch.HasCaught()) |
| 78 |
return throwError(tryCatch.Exception()); |
| 79 |
if (!startTime) |
| 80 |
return throwError("Empty startTime", V8Proxy::SyntaxError); |
| 81 |
|
| 82 |
endTime = args[2]->NumberValue(); |
| 83 |
if (tryCatch.HasCaught()) |
| 84 |
return throwError(tryCatch.Exception()); |
| 85 |
if (!endTime) |
| 86 |
return throwError("Empty endTime", V8Proxy::SyntaxError); |
| 87 |
|
| 88 |
content = toWebCoreString(args[3]); |
| 89 |
if (tryCatch.HasCaught()) |
| 90 |
return throwError(tryCatch.Exception()); |
| 91 |
if (content.isEmpty()) |
| 92 |
return throwError("Empty cue text", V8Proxy::SyntaxError); |
| 93 |
|
| 94 |
if (args.Length() > 4) |
| 95 |
settings = toWebCoreString(args[4]); |
| 96 |
if (args.Length() > 5) |
| 97 |
pauseOnExit = args[5]->BooleanValue(); |
| 98 |
} |
| 99 |
|
| 100 |
// Get the script execution context. |
| 101 |
ScriptExecutionContext* context = getScriptExecutionContext(); |
| 102 |
if (!context) |
| 103 |
return throwError("TextTrackCue constructor's associated frame is not available", V8Proxy::ReferenceError); |
| 104 |
|
| 105 |
RefPtr<TextTrackCue> cue = TextTrackCue::create(context, id, startTime, endTime, content, settings, pauseOnExit); |
| 106 |
|
| 107 |
// Setup the standard wrapper object internal fields. |
| 108 |
V8DOMWrapper::setDOMWrapper(args.Holder(), &info, cue.get()); |
| 109 |
|
| 110 |
// Add object to the wrapper map. |
| 111 |
cue->ref(); |
| 112 |
V8DOMWrapper::setJSWrapperForActiveDOMObject(cue.get(), v8::Persistent<v8::Object>::New(args.Holder())); |
| 113 |
|
| 114 |
return args.Holder(); |
| 115 |
} |
| 116 |
|
| 117 |
} // namespace WebCore |
| 118 |
|
| 119 |
#endif |