1 /* 2 * Copyright (C) 2007, 2008, 2009 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 #include "bindings/core/v8/V8HTMLDocument.h" 33 34 #include "bindings/core/v8/V8HTMLAllCollection.h" 35 #include "bindings/core/v8/V8HTMLCollection.h" 36 #include "bindings/core/v8/V8Node.h" 37 #include "bindings/core/v8/V8Window.h" 38 #include "bindings/v8/ScriptController.h" 39 #include "bindings/v8/V8Binding.h" 40 #include "core/HTMLNames.h" 41 #include "core/frame/LocalFrame.h" 42 #include "core/html/HTMLAllCollection.h" 43 #include "core/html/HTMLCollection.h" 44 #include "core/html/HTMLDocument.h" 45 #include "core/html/HTMLIFrameElement.h" 46 #include "wtf/OwnPtr.h" 47 #include "wtf/RefPtr.h" 48 #include "wtf/StdLibExtras.h" 49 50 namespace WebCore { 51 52 // HTMLDocument ---------------------------------------------------------------- 53 54 void V8HTMLDocument::openMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& info) 55 { 56 HTMLDocument* htmlDocument = V8HTMLDocument::toNative(info.Holder()); 57 58 if (info.Length() > 2) { 59 if (RefPtr<LocalFrame> frame = htmlDocument->frame()) { 60 // Fetch the global object for the frame. 61 v8::Local<v8::Context> context = toV8Context(frame.get(), DOMWrapperWorld::current(info.GetIsolate())); 62 // Bail out if we cannot get the context. 63 if (context.IsEmpty()) 64 return; 65 v8::Local<v8::Object> global = context->Global(); 66 // Get the open property of the global object. 67 v8::Local<v8::Value> function = global->Get(v8AtomicString(info.GetIsolate(), "open")); 68 // Failed; return without throwing (new) exception. 69 if (function.IsEmpty()) 70 return; 71 // If the open property is not a function throw a type error. 72 if (!function->IsFunction()) { 73 throwTypeError("open is not a function", info.GetIsolate()); 74 return; 75 } 76 // Wrap up the arguments and call the function. 77 OwnPtr<v8::Local<v8::Value>[]> params = adoptArrayPtr(new v8::Local<v8::Value>[info.Length()]); 78 for (int i = 0; i < info.Length(); i++) 79 params[i] = info[i]; 80 81 v8SetReturnValue(info, frame->script().callFunction(v8::Local<v8::Function>::Cast(function), global, info.Length(), params.get())); 82 return; 83 } 84 } 85 86 ExceptionState exceptionState(ExceptionState::ExecutionContext, "open", "Document", info.Holder(), info.GetIsolate()); 87 htmlDocument->open(callingDOMWindow(info.GetIsolate())->document(), exceptionState); 88 if (exceptionState.throwIfNeeded()) 89 return; 90 91 v8SetReturnValue(info, info.Holder()); 92 } 93 94 } // namespace WebCore 95