v8::Handle<v8::Value> V8Location::replaceCallback(const v8::Arguments& args) { Location* impl = V8Location::toNative(args.Holder()); BindingState* state = BindingState::instance(); // FIXME: Handle exceptions correctly. String urlString = toWebCoreString(args[0]); impl->replace(urlString, activeDOMWindow(state), firstDOMWindow(state)); return v8::Undefined(); }
static v8::Handle<v8::Value> start2Callback(const v8::Arguments& args) { FeatureObserver::observe(activeDOMWindow(BindingState::instance()), FeatureObserver::WebAudioStart); if (args.Length() < 2) return throwNotEnoughArgumentsError(args.GetIsolate()); AudioBufferSourceNode* imp = V8AudioBufferSourceNode::toNative(args.Holder()); V8TRYCATCH(double, when, static_cast<double>(MAYBE_MISSING_PARAMETER(args, 0, DefaultIsUndefined)->NumberValue())); V8TRYCATCH(double, grainOffset, static_cast<double>(MAYBE_MISSING_PARAMETER(args, 1, DefaultIsUndefined)->NumberValue())); imp->startGrain(when, grainOffset); return v8Undefined(); }
void JSDOMWindow::setLocation(ExecState* exec, JSValue value) { #if ENABLE(DASHBOARD_SUPPORT) // To avoid breaking old widgets, make "var location =" in a top-level frame create // a property named "location" instead of performing a navigation (<rdar://problem/5688039>). if (Frame* activeFrame = activeDOMWindow(exec).frame()) { if (activeFrame->settings().usesDashboardBackwardCompatibilityMode() && !activeFrame->tree().parent()) { if (BindingSecurity::shouldAllowAccessToDOMWindow(exec, impl())) putDirect(exec->vm(), Identifier(exec, "location"), value); return; } } #endif String locationString = value.toString(exec)->value(exec); if (exec->hadException()) return; if (Location* location = impl().location()) location->setHref(locationString, activeDOMWindow(exec), firstDOMWindow(exec)); }
void JSDocument::setLocation(ExecState* exec, JSValue value) { Frame* frame = static_cast<Document*>(impl())->frame(); if (!frame) return; String locationString = value.toString(exec)->value(exec); if (exec->hadException()) return; if (Location* location = frame->document()->domWindow()->location()) location->setHref(locationString, activeDOMWindow(exec), firstDOMWindow(exec)); }
void V8Location::protocolAccessorSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info) { Location* impl = V8Location::toNative(info.Holder()); BindingState* state = BindingState::instance(); // FIXME: Handle exceptions correctly. String protocol = toWebCoreString(value); ExceptionCode ec = 0; impl->setProtocol(protocol, activeDOMWindow(state), firstDOMWindow(state), ec); if (UNLIKELY(ec)) setDOMException(ec, info.GetIsolate()); }
static bool canAccessDocument(Document* targetDocument, SecurityReportingOption reportingOption = ReportSecurityError) { DOMWindow* activeWindow = activeDOMWindow(); if (isDocumentAccessibleFromDOMWindow(targetDocument, activeWindow)) return true; if (reportingOption == ReportSecurityError) { if (Frame* frame = targetDocument->frame()) frame->domWindow()->printErrorMessage(targetDocument->domWindow()->crossDomainAccessErrorMessage(activeWindow)); } return false; }
static v8::Handle<v8::Value> startCallback(const v8::Arguments& args) { FeatureObserver::observe(activeDOMWindow(BindingState::instance()), FeatureObserver::WebAudioStart); if (args.Length() == 1) return start1Callback(args); if (args.Length() == 2) return start2Callback(args); if (args.Length() == 3) return start3Callback(args); if (args.Length() < 1) return throwNotEnoughArgumentsError(args.GetIsolate()); return throwTypeError(0, args.GetIsolate()); }
void JSDocument::setLocation(ExecState* exec, JSValue value) { String locationString = value.toString(exec)->value(exec); if (exec->hadException()) return; RefPtr<Frame> frame = impl().frame(); if (!frame) return; if (RefPtr<Location> location = frame->document()->domWindow()->location()) location->setHref(locationString, activeDOMWindow(exec), firstDOMWindow(exec)); }
void JSDOMWindow::setLocation(ExecState& state, JSValue value) { VM& vm = state.vm(); auto scope = DECLARE_THROW_SCOPE(vm); #if ENABLE(DASHBOARD_SUPPORT) // To avoid breaking old widgets, make "var location =" in a top-level frame create // a property named "location" instead of performing a navigation (<rdar://problem/5688039>). if (Frame* activeFrame = activeDOMWindow(&state).frame()) { if (activeFrame->settings().usesDashboardBackwardCompatibilityMode() && !activeFrame->tree().parent()) { if (BindingSecurity::shouldAllowAccessToDOMWindow(&state, wrapped())) putDirect(state.vm(), Identifier::fromString(&state, "location"), value); return; } } #endif String locationString = value.toString(&state)->value(&state); RETURN_IF_EXCEPTION(scope, void()); if (Location* location = wrapped().location()) location->setHref(activeDOMWindow(&state), firstDOMWindow(&state), locationString); }
void V8Window::locationAttrSetterCustom(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<void>& info) { DOMWindow* imp = V8Window::toNative(info.Holder()); DOMWindow* active = activeDOMWindow(); if (!active) return; DOMWindow* first = firstDOMWindow(); if (!first) return; if (Location* location = imp->location()) location->setHref(active, first, toWebCoreString(value)); }
void V8Window::showModalDialogMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& args) { DOMWindow* impl = V8Window::toNative(args.Holder()); if (!BindingSecurity::shouldAllowAccessToFrame(impl->frame())) return; // FIXME: Handle exceptions properly. String urlString = toWebCoreStringWithUndefinedOrNullCheck(args[0]); DialogHandler handler(args[1]); String dialogFeaturesString = toWebCoreStringWithUndefinedOrNullCheck(args[2]); impl->showModalDialog(urlString, dialogFeaturesString, activeDOMWindow(), firstDOMWindow(), setUpDialog, &handler); v8SetReturnValue(args, handler.returnValue()); }
JSValue JSDOMWindow::showModalDialog(ExecState* exec) { String urlString = valueToStringWithUndefinedOrNullCheck(exec, exec->argument(0)); if (exec->hadException()) return jsUndefined(); String dialogFeaturesString = valueToStringWithUndefinedOrNullCheck(exec, exec->argument(2)); if (exec->hadException()) return jsUndefined(); DialogHandler handler(exec); impl()->showModalDialog(urlString, dialogFeaturesString, activeDOMWindow(exec), firstDOMWindow(exec), setUpDialog, &handler); return handler.returnValue(); }
void V8Window::postMessageMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& info) { // None of these need to be RefPtr because info and context are guaranteed // to hold on to them. DOMWindow* window = V8Window::toNative(info.Holder()); DOMWindow* source = activeDOMWindow(); // If called directly by WebCore we don't have a calling context. if (!source) { throwUninformativeAndGenericTypeError(info.GetIsolate()); return; } // This function has variable arguments and can be: // Per current spec: // postMessage(message, targetOrigin) // postMessage(message, targetOrigin, {sequence of transferrables}) // Legacy non-standard implementations in webkit allowed: // postMessage(message, {sequence of transferrables}, targetOrigin); MessagePortArray portArray; ArrayBufferArray arrayBufferArray; int targetOriginArgIndex = 1; if (info.Length() > 2) { int transferablesArgIndex = 2; if (isLegacyTargetOriginDesignation(info[2])) { targetOriginArgIndex = 2; transferablesArgIndex = 1; } bool notASequence = false; if (!extractTransferables(info[transferablesArgIndex], portArray, arrayBufferArray, notASequence, info.GetIsolate())) { if (notASequence) throwTypeError(ExceptionMessages::failedToExecute("postMessage", "Window", ExceptionMessages::notAnArrayTypeArgumentOrValue(transferablesArgIndex + 1)), info.GetIsolate()); return; } } V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<WithUndefinedOrNullCheck>, targetOrigin, info[targetOriginArgIndex]); bool didThrow = false; RefPtr<SerializedScriptValue> message = SerializedScriptValue::create(info[0], &portArray, &arrayBufferArray, didThrow, info.GetIsolate()); if (didThrow) return; ExceptionState exceptionState(ExceptionState::ExecutionContext, "postMessage", "Window", info.Holder(), info.GetIsolate()); window->postMessage(message.release(), &portArray, targetOrigin, source, exceptionState); exceptionState.throwIfNeeded(); }
static bool canAccessDocument(BindingState* state, Document* targetDocument, SecurityReportingOption reportingOption = ReportSecurityError) { if (!targetDocument) return false; DOMWindow* active = activeDOMWindow(state); if (!active) return false; if (active->document()->securityOrigin()->canAccess(targetDocument->securityOrigin())) return true; if (reportingOption == ReportSecurityError) printErrorMessageForFrame(targetDocument->frame(), targetDocument->domWindow()->crossDomainAccessErrorMessage(active)); return false; }
void V8Window::showModalDialogMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& info) { DOMWindow* impl = V8Window::toNative(info.Holder()); ExceptionState exceptionState(ExceptionState::ExecutionContext, "showModalDialog", "Window", info.Holder(), info.GetIsolate()); if (!BindingSecurity::shouldAllowAccessToFrame(impl->frame(), exceptionState)) { exceptionState.throwIfNeeded(); return; } // FIXME: Handle exceptions properly. String urlString = toCoreStringWithUndefinedOrNullCheck(info[0]); DialogHandler handler(info[1]); String dialogFeaturesString = toCoreStringWithUndefinedOrNullCheck(info[2]); impl->showModalDialog(urlString, dialogFeaturesString, activeDOMWindow(), firstDOMWindow(), setUpDialog, &handler); v8SetReturnValue(info, handler.returnValue(info.GetIsolate())); }
void V8Document::locationAttrSetterCustom(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<void>& info) { Document* document = V8Document::toNative(info.Holder()); if (!document->frame()) return; DOMWindow* active = activeDOMWindow(); if (!active) return; DOMWindow* first = firstDOMWindow(); if (!first) return; DOMWindow* window = document->domWindow(); if (Location* location = window->location()) location->setHref(active, first, toWebCoreString(value)); }
void V8Document::locationAccessorSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info) { Document* document = V8Document::toNative(info.Holder()); if (!document->frame()) return; BindingState* state = BindingState::instance(); DOMWindow* active = activeDOMWindow(state); if (!active) return; DOMWindow* first = firstDOMWindow(state); if (!first) return; DOMWindow* window = document->domWindow(); if (Location* location = window->location()) location->setHref(toWebCoreString(value), active, first); }
JSValue JSDOMWindow::showModalDialog(ExecState& state) { VM& vm = state.vm(); auto scope = DECLARE_THROW_SCOPE(vm); if (UNLIKELY(state.argumentCount() < 1)) return throwException(&state, scope, createNotEnoughArgumentsError(&state)); String urlString = convert<IDLNullable<IDLDOMString>>(state, state.argument(0)); RETURN_IF_EXCEPTION(scope, JSValue()); String dialogFeaturesString = convert<IDLNullable<IDLDOMString>>(state, state.argument(2)); RETURN_IF_EXCEPTION(scope, JSValue()); DialogHandler handler(state); wrapped().showModalDialog(urlString, dialogFeaturesString, activeDOMWindow(&state), firstDOMWindow(&state), [&handler](DOMWindow& dialog) { handler.dialogCreated(dialog); }); return handler.returnValue(); }
static JSValue handlePostMessage(DOMWindow* impl, ExecState* exec) { MessagePortArray messagePorts; ArrayBufferArray arrayBuffers; // This function has variable arguments and can be: // Per current spec: // postMessage(message, targetOrigin) // postMessage(message, targetOrigin, {sequence of transferrables}) // Legacy non-standard implementations in webkit allowed: // postMessage(message, {sequence of transferrables}, targetOrigin); int targetOriginArgIndex = 1; if (exec->argumentCount() > 2) { int transferablesArgIndex = 2; if (exec->argument(2).isString()) { targetOriginArgIndex = 2; transferablesArgIndex = 1; } fillMessagePortArray(exec, exec->argument(transferablesArgIndex), messagePorts, arrayBuffers); } if (exec->hadException()) return jsUndefined(); RefPtr<SerializedScriptValue> message = SerializedScriptValue::create(exec, exec->argument(0), &messagePorts, &arrayBuffers); if (exec->hadException()) return jsUndefined(); String targetOrigin = valueToStringWithUndefinedOrNullCheck(exec, exec->argument(targetOriginArgIndex)); if (exec->hadException()) return jsUndefined(); ExceptionCode ec = 0; impl->postMessage(message.release(), &messagePorts, targetOrigin, activeDOMWindow(exec), ec); setDOMException(exec, ec); return jsUndefined(); }
JSValue JSLocation::reload(ExecState* exec) { impl()->reload(activeDOMWindow(exec)); return jsUndefined(); }
void V8Window::openMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& info) { DOMWindow* impl = V8Window::toNative(info.Holder()); ExceptionState exceptionState(ExceptionState::ExecutionContext, "open", "Window", info.Holder(), info.GetIsolate()); if (!BindingSecurity::shouldAllowAccessToFrame(impl->frame(), exceptionState)) { exceptionState.throwIfNeeded(); return; } V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<WithUndefinedOrNullCheck>, urlString, info[0]); AtomicString frameName; if (info[1]->IsUndefined() || info[1]->IsNull()) { frameName = "_blank"; } else { V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, frameNameResource, info[1]); frameName = frameNameResource; } V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<WithUndefinedOrNullCheck>, windowFeaturesString, info[2]); RefPtr<DOMWindow> openedWindow = impl->open(urlString, frameName, windowFeaturesString, activeDOMWindow(), firstDOMWindow()); if (!openedWindow) return; v8SetReturnValueFast(info, openedWindow.release(), impl); }
v8::Handle<v8::Value> V8HTMLDocument::writelnMethodCustom(const v8::Arguments& args) { HTMLDocument* htmlDocument = V8HTMLDocument::toNative(args.Holder()); htmlDocument->writeln(writeHelperGetString(args), activeDOMWindow()->document()); return v8::Undefined(); }
JSValue JSDOMWindow::open(ExecState* exec) { String urlString = valueToStringWithUndefinedOrNullCheck(exec, exec->argument(0)); if (exec->hadException()) return jsUndefined(); AtomicString frameName = exec->argument(1).isUndefinedOrNull() ? "_blank" : exec->argument(1).toString(exec)->value(exec); if (exec->hadException()) return jsUndefined(); String windowFeaturesString = valueToStringWithUndefinedOrNullCheck(exec, exec->argument(2)); if (exec->hadException()) return jsUndefined(); RefPtr<DOMWindow> openedWindow = impl()->open(urlString, frameName, windowFeaturesString, activeDOMWindow(exec), firstDOMWindow(exec)); if (!openedWindow) return jsUndefined(); return toJS(exec, openedWindow.get()); }
void V8Window::openMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& args) { DOMWindow* impl = V8Window::toNative(args.Holder()); if (!BindingSecurity::shouldAllowAccessToFrame(impl->frame())) return; // FIXME: Handle exceptions properly. String urlString = toWebCoreStringWithUndefinedOrNullCheck(args[0]); AtomicString frameName = (args[1]->IsUndefined() || args[1]->IsNull()) ? "_blank" : AtomicString(toWebCoreString(args[1])); String windowFeaturesString = toWebCoreStringWithUndefinedOrNullCheck(args[2]); RefPtr<DOMWindow> openedWindow = impl->open(urlString, frameName, windowFeaturesString, activeDOMWindow(), firstDOMWindow()); if (!openedWindow) return; v8SetReturnValue(args, toV8Fast(openedWindow.release(), args, impl)); }
void V8HTMLDocument::writelnMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& args) { HTMLDocument* htmlDocument = V8HTMLDocument::toNative(args.Holder()); htmlDocument->writeln(writeHelperGetString(args), activeDOMWindow()->document()); }
JSValue JSDOMWindow::open(ExecState& state) { VM& vm = state.vm(); auto scope = DECLARE_THROW_SCOPE(vm); String urlString = convert<IDLNullable<IDLUSVString>>(state, state.argument(0)); RETURN_IF_EXCEPTION(scope, JSValue()); JSValue targetValue = state.argument(1); AtomicString target = targetValue.isUndefinedOrNull() ? AtomicString("_blank", AtomicString::ConstructFromLiteral) : targetValue.toString(&state)->toAtomicString(&state); RETURN_IF_EXCEPTION(scope, JSValue()); String windowFeaturesString = convert<IDLNullable<IDLDOMString>>(state, state.argument(2)); RETURN_IF_EXCEPTION(scope, JSValue()); RefPtr<DOMWindow> openedWindow = wrapped().open(urlString, target, windowFeaturesString, activeDOMWindow(&state), firstDOMWindow(&state)); if (!openedWindow) return jsNull(); return toJS(&state, openedWindow.get()); }