15c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)/*
25c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Copyright (C) 2007, 2008, 2009 Google Inc. All rights reserved.
35c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *
45c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Redistribution and use in source and binary forms, with or without
55c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * modification, are permitted provided that the following conditions are
65c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * met:
75c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *
85c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *     * Redistributions of source code must retain the above copyright
95c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * notice, this list of conditions and the following disclaimer.
105c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *     * Redistributions in binary form must reproduce the above
115c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * copyright notice, this list of conditions and the following disclaimer
125c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * in the documentation and/or other materials provided with the
135c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * distribution.
145c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *     * Neither the name of Google Inc. nor the names of its
155c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * contributors may be used to endorse or promote products derived from
165c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * this software without specific prior written permission.
175c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *
185c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
205c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
215c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
225c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
235c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
245c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
255c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
265c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
275c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
285c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
295c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) */
305c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
315c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#include "config.h"
32d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)#include "bindings/core/v8/V8HTMLDocument.h"
335c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
34197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch#include "bindings/core/v8/ScriptController.h"
35197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch#include "bindings/core/v8/V8Binding.h"
36d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)#include "bindings/core/v8/V8HTMLAllCollection.h"
37d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)#include "bindings/core/v8/V8HTMLCollection.h"
38d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)#include "bindings/core/v8/V8Node.h"
39d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)#include "bindings/core/v8/V8Window.h"
4076c265b59aa821ccbf8c75ab2bb0d036e97d2956Torne (Richard Coles)#include "core/HTMLNames.h"
41d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)#include "core/frame/LocalFrame.h"
4253e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "core/html/HTMLAllCollection.h"
4353e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "core/html/HTMLCollection.h"
4453e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "core/html/HTMLDocument.h"
4553e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "core/html/HTMLIFrameElement.h"
461e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)#include "wtf/OwnPtr.h"
4753e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "wtf/RefPtr.h"
4853e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "wtf/StdLibExtras.h"
495c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
50c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)namespace blink {
515c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
525c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)// HTMLDocument ----------------------------------------------------------------
535c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
5419cde67944066db31e633d9e386f2aa9bf9fadb3Torne (Richard Coles)void V8HTMLDocument::openMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& info)
555c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
567242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    HTMLDocument* htmlDocument = V8HTMLDocument::toImpl(info.Holder());
575c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
5819cde67944066db31e633d9e386f2aa9bf9fadb3Torne (Richard Coles)    if (info.Length() > 2) {
597242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci        if (RefPtrWillBeRawPtr<LocalFrame> frame = htmlDocument->frame()) {
605c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            // Fetch the global object for the frame.
61f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)            v8::Local<v8::Context> context = toV8Context(frame.get(), DOMWrapperWorld::current(info.GetIsolate()));
625c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            // Bail out if we cannot get the context.
635c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            if (context.IsEmpty())
645267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)                return;
655c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            v8::Local<v8::Object> global = context->Global();
665c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            // Get the open property of the global object.
67a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)            v8::Local<v8::Value> function = global->Get(v8AtomicString(info.GetIsolate(), "open"));
68f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu            // Failed; return without throwing (new) exception.
69f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu            if (function.IsEmpty())
70f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu                return;
715c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            // If the open property is not a function throw a type error.
725267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)            if (!function->IsFunction()) {
73c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)                V8ThrowException::throwTypeError("open is not a function", info.GetIsolate());
745267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)                return;
755267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)            }
765c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)            // Wrap up the arguments and call the function.
7719cde67944066db31e633d9e386f2aa9bf9fadb3Torne (Richard Coles)            OwnPtr<v8::Local<v8::Value>[]> params = adoptArrayPtr(new v8::Local<v8::Value>[info.Length()]);
7819cde67944066db31e633d9e386f2aa9bf9fadb3Torne (Richard Coles)            for (int i = 0; i < info.Length(); i++)
7919cde67944066db31e633d9e386f2aa9bf9fadb3Torne (Richard Coles)                params[i] = info[i];
805c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
8119cde67944066db31e633d9e386f2aa9bf9fadb3Torne (Richard Coles)            v8SetReturnValue(info, frame->script().callFunction(v8::Local<v8::Function>::Cast(function), global, info.Length(), params.get()));
825267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)            return;
835c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        }
845c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    }
855c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
8610f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch    ExceptionState exceptionState(ExceptionState::ExecutionContext, "open", "Document", info.Holder(), info.GetIsolate());
8710f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch    htmlDocument->open(callingDOMWindow(info.GetIsolate())->document(), exceptionState);
8810f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch    if (exceptionState.throwIfNeeded())
8910f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch        return;
9010f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch
9119cde67944066db31e633d9e386f2aa9bf9fadb3Torne (Richard Coles)    v8SetReturnValue(info, info.Holder());
925c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
935c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
94c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)} // namespace blink
95