void V8DOMWindowShell::createContext() { // The activeDocumentLoader pointer could be 0 during frame shutdown. // FIXME: Can we remove this check? if (!m_frame->loader()->activeDocumentLoader()) return; // Create a new environment using an empty template for the shadow // object. Reuse the global object if one has been created earlier. v8::Persistent<v8::ObjectTemplate> globalTemplate = V8DOMWindow::GetShadowObjectTemplate(m_isolate); if (globalTemplate.IsEmpty()) return; // Used to avoid sleep calls in unload handlers. ScriptController::registerExtensionIfNeeded(DateExtension::get()); #if ENABLE(JAVASCRIPT_I18N_API) // Enables experimental i18n API in V8. if (RuntimeEnabledFeatures::javaScriptI18NAPIEnabled()) ScriptController::registerExtensionIfNeeded(v8_i18n::Extension::get()); #endif // Dynamically tell v8 about our extensions now. const V8Extensions& extensions = ScriptController::registeredExtensions(); OwnArrayPtr<const char*> extensionNames = adoptArrayPtr(new const char*[extensions.size()]); int index = 0; int extensionGroup = m_world->extensionGroup(); int worldId = m_world->worldId(); for (size_t i = 0; i < extensions.size(); ++i) { // Ensure our date extension is always allowed. if (extensions[i] != DateExtension::get() && !m_frame->loader()->client()->allowScriptExtension(extensions[i]->name(), extensionGroup, worldId)) continue; extensionNames[index++] = extensions[i]->name(); } v8::ExtensionConfiguration extensionConfiguration(index, extensionNames.get()); m_context.adopt(v8::Context::New(&extensionConfiguration, globalTemplate, m_global.get())); }
static WKURLRef createWKURL(const char* pathOrURL) { if (strstr(pathOrURL, "http://") || strstr(pathOrURL, "https://") || strstr(pathOrURL, "file://")) return WKURLCreateWithUTF8CString(pathOrURL); // Creating from filesytem path. size_t length = strlen(pathOrURL); if (!length) return 0; #if OS(WINDOWS) const char separator = '\\'; bool isAbsolutePath = length >= 3 && pathOrURL[1] == ':' && pathOrURL[2] == separator; // FIXME: Remove the "localhost/" suffix once <http://webkit.org/b/55683> is fixed. const char* filePrefix = "file://localhost/"; #else const char separator = '/'; bool isAbsolutePath = pathOrURL[0] == separator; const char* filePrefix = "file://"; #endif static const size_t prefixLength = strlen(filePrefix); OwnArrayPtr<char> buffer; if (isAbsolutePath) { buffer = adoptArrayPtr(new char[prefixLength + length + 1]); strcpy(buffer.get(), filePrefix); strcpy(buffer.get() + prefixLength, pathOrURL); } else { buffer = adoptArrayPtr(new char[prefixLength + PATH_MAX + length + 2]); // 1 for the separator strcpy(buffer.get(), filePrefix); if (!getcwd(buffer.get() + prefixLength, PATH_MAX)) return 0; size_t numCharacters = strlen(buffer.get()); buffer[numCharacters] = separator; strcpy(buffer.get() + numCharacters + 1, pathOrURL); } return WKURLCreateWithUTF8CString(buffer.get()); }
void V8HTMLDocument::openMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& args) { HTMLDocument* htmlDocument = V8HTMLDocument::toNative(args.Holder()); if (args.Length() > 2) { if (RefPtr<Frame> frame = htmlDocument->frame()) { // Fetch the global object for the frame. v8::Local<v8::Context> context = frame->script()->currentWorldContext(); // Bail out if we cannot get the context. if (context.IsEmpty()) return; v8::Local<v8::Object> global = context->Global(); // Get the open property of the global object. v8::Local<v8::Value> function = global->Get(v8::String::NewSymbol("open")); // If the open property is not a function throw a type error. if (!function->IsFunction()) { throwTypeError("open is not a function", args.GetIsolate()); return; } // Wrap up the arguments and call the function. OwnArrayPtr<v8::Local<v8::Value> > params = adoptArrayPtr(new v8::Local<v8::Value>[args.Length()]); for (int i = 0; i < args.Length(); i++) params[i] = args[i]; v8SetReturnValue(args, frame->script()->callFunction(v8::Local<v8::Function>::Cast(function), global, args.Length(), params.get())); return; } } htmlDocument->open(activeDOMWindow()->document()); v8SetReturnValue(args, args.Holder()); }
int getGDKKeySymForKeyRef(WKStringRef keyRef, unsigned location, guint* modifiers) { if (location == DOMKeyLocationNumpad) { if (WKStringIsEqualToUTF8CString(keyRef, "leftArrow")) return GDK_KEY_KP_Left; if (WKStringIsEqualToUTF8CString(keyRef, "rightArror")) return GDK_KEY_KP_Right; if (WKStringIsEqualToUTF8CString(keyRef, "upArrow")) return GDK_KEY_KP_Up; if (WKStringIsEqualToUTF8CString(keyRef, "downArrow")) return GDK_KEY_KP_Down; if (WKStringIsEqualToUTF8CString(keyRef, "pageUp")) return GDK_KEY_KP_Page_Up; if (WKStringIsEqualToUTF8CString(keyRef, "pageDown")) return GDK_KEY_KP_Page_Down; if (WKStringIsEqualToUTF8CString(keyRef, "home")) return GDK_KEY_KP_Home; if (WKStringIsEqualToUTF8CString(keyRef, "end")) return GDK_KEY_KP_End; if (WKStringIsEqualToUTF8CString(keyRef, "insert")) return GDK_KEY_KP_Insert; if (WKStringIsEqualToUTF8CString(keyRef, "delete")) return GDK_KEY_KP_Delete; return GDK_KEY_VoidSymbol; } if (WKStringIsEqualToUTF8CString(keyRef, "leftArrow")) return GDK_KEY_Left; if (WKStringIsEqualToUTF8CString(keyRef, "rightArrow")) return GDK_KEY_Right; if (WKStringIsEqualToUTF8CString(keyRef, "upArrow")) return GDK_KEY_Up; if (WKStringIsEqualToUTF8CString(keyRef, "downArrow")) return GDK_KEY_Down; if (WKStringIsEqualToUTF8CString(keyRef, "pageUp")) return GDK_KEY_Page_Up; if (WKStringIsEqualToUTF8CString(keyRef, "pageDown")) return GDK_KEY_Page_Down; if (WKStringIsEqualToUTF8CString(keyRef, "home")) return GDK_KEY_Home; if (WKStringIsEqualToUTF8CString(keyRef, "end")) return GDK_KEY_End; if (WKStringIsEqualToUTF8CString(keyRef, "insert")) return GDK_KEY_Insert; if (WKStringIsEqualToUTF8CString(keyRef, "delete")) return GDK_KEY_Delete; if (WKStringIsEqualToUTF8CString(keyRef, "printScreen")) return GDK_KEY_Print; if (WKStringIsEqualToUTF8CString(keyRef, "menu")) return GDK_KEY_Menu; if (WKStringIsEqualToUTF8CString(keyRef, "F1")) return GDK_KEY_F1; if (WKStringIsEqualToUTF8CString(keyRef, "F2")) return GDK_KEY_F2; if (WKStringIsEqualToUTF8CString(keyRef, "F3")) return GDK_KEY_F3; if (WKStringIsEqualToUTF8CString(keyRef, "F4")) return GDK_KEY_F4; if (WKStringIsEqualToUTF8CString(keyRef, "F5")) return GDK_KEY_F5; if (WKStringIsEqualToUTF8CString(keyRef, "F6")) return GDK_KEY_F6; if (WKStringIsEqualToUTF8CString(keyRef, "F7")) return GDK_KEY_F7; if (WKStringIsEqualToUTF8CString(keyRef, "F8")) return GDK_KEY_F8; if (WKStringIsEqualToUTF8CString(keyRef, "F9")) return GDK_KEY_F9; if (WKStringIsEqualToUTF8CString(keyRef, "F10")) return GDK_KEY_F10; if (WKStringIsEqualToUTF8CString(keyRef, "F11")) return GDK_KEY_F11; if (WKStringIsEqualToUTF8CString(keyRef, "F12")) return GDK_KEY_F12; size_t bufferSize = WKStringGetMaximumUTF8CStringSize(keyRef); OwnArrayPtr<char> buffer = adoptArrayPtr(new char[bufferSize]); WKStringGetUTF8CString(keyRef, buffer.get(), bufferSize); char charCode = buffer.get()[0]; if (charCode == '\n' || charCode == '\r') return GDK_KEY_Return; if (charCode == '\t') return GDK_KEY_Tab; if (charCode == '\x8') return GDK_KEY_BackSpace; if (WTF::isASCIIUpper(charCode)) *modifiers |= GDK_SHIFT_MASK; return gdk_unicode_to_keyval(static_cast<guint32>(buffer.get()[0])); }
JavaValue JavaInstance::invokeMethod(const JavaMethod* method, JavaValue* args) { ASSERT(getClass()->methodsNamed(method->name().utf8().data()).find(method) != notFound); unsigned int numParams = method->numParameters(); OwnArrayPtr<jvalue> jvalueArgs = adoptArrayPtr(new jvalue[numParams]); for (unsigned int i = 0; i < numParams; ++i) jvalueArgs[i] = javaValueToJvalue(args[i]); jvalue result = callJNIMethod(javaInstance(), method->returnType(), method->name().utf8().data(), method->signature(), jvalueArgs.get()); return jvalueToJavaValue(result, method->returnType()); }
void GraphicsContext3DPrivate::paintToTextureMapper(TextureMapper* textureMapper, const FloatRect& targetRect, const TransformationMatrix& matrix, float opacity) { if (!m_glContext) return; ASSERT(m_renderStyle == GraphicsContext3D::RenderOffscreen); m_context->markLayerComposited(); // FIXME: We do not support mask for the moment with TextureMapperImageBuffer. if (textureMapper->accelerationMode() != TextureMapper::OpenGLMode) { GraphicsContext* context = textureMapper->graphicsContext(); context->save(); context->platformContext()->setGlobalAlpha(opacity); const int height = m_context->m_currentHeight; const int width = m_context->m_currentWidth; int totalBytes = width * height * 4; OwnArrayPtr<unsigned char> pixels = adoptArrayPtr(new unsigned char[totalBytes]); if (!pixels) return; // OpenGL keeps the pixels stored bottom up, so we need to flip the image here. context->translate(0, height); context->scale(FloatSize(1, -1)); context->concatCTM(matrix.toAffineTransform()); m_context->readRenderingResults(pixels.get(), totalBytes); // Premultiply alpha. for (int i = 0; i < totalBytes; i += 4) if (pixels[i + 3] != 255) { pixels[i + 0] = min(255, pixels[i + 0] * pixels[i + 3] / 255); pixels[i + 1] = min(255, pixels[i + 1] * pixels[i + 3] / 255); pixels[i + 2] = min(255, pixels[i + 2] * pixels[i + 3] / 255); } RefPtr<cairo_surface_t> imageSurface = adoptRef(cairo_image_surface_create_for_data( const_cast<unsigned char*>(pixels.get()), CAIRO_FORMAT_ARGB32, width, height, width * 4)); context->platformContext()->drawSurfaceToContext(imageSurface.get(), targetRect, IntRect(0, 0, width, height), context); context->restore(); return; } #if USE(TEXTURE_MAPPER_GL) if (m_context->m_attrs.antialias && m_context->m_state.boundFBO == m_context->m_multisampleFBO) { GLContext* previousActiveContext = GLContext::getCurrent(); if (previousActiveContext != m_glContext) m_context->makeContextCurrent(); m_context->resolveMultisamplingIfNecessary(); ::glBindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_context->m_state.boundFBO); if (previousActiveContext && previousActiveContext != m_glContext) previousActiveContext->makeContextCurrent(); } TextureMapperGL* texmapGL = static_cast<TextureMapperGL*>(textureMapper); TextureMapperGL::Flags flags = TextureMapperGL::ShouldFlipTexture | (m_context->m_attrs.alpha ? TextureMapperGL::ShouldBlend : 0); IntSize textureSize(m_context->m_currentWidth, m_context->m_currentHeight); texmapGL->drawTexture(m_context->m_texture, flags, textureSize, targetRect, matrix, opacity); #endif // USE(ACCELERATED_COMPOSITING_GL) }
ScriptValue ScriptFunctionCall::call(bool& hadException, bool reportExceptions) { ScriptScope scope(m_scriptState, reportExceptions); v8::Handle<v8::Object> thisObject = m_thisObject.v8Object(); v8::Local<v8::Value> value = thisObject->Get(v8String(m_name, m_scriptState->isolate())); if (!scope.success()) { hadException = true; return ScriptValue(); } ASSERT(value->IsFunction()); v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(value); OwnArrayPtr<v8::Handle<v8::Value> > args = adoptArrayPtr(new v8::Handle<v8::Value>[m_arguments.size()]); for (size_t i = 0; i < m_arguments.size(); ++i) { args[i] = m_arguments[i].v8Value(); ASSERT(!args[i].IsEmpty()); } v8::Local<v8::Value> result = V8ScriptRunner::callFunction(function, getScriptExecutionContext(), thisObject, m_arguments.size(), args.get()); if (!scope.success()) { hadException = true; return ScriptValue(); } return ScriptValue(result); }
// ANDROID JavaValue JavaInstanceJobject::invokeMethod(const JavaMethod* method, JavaValue* args, bool& didRaiseUncaughtException) { didRaiseUncaughtException = false; // END ANDROID ASSERT(getClass()->methodsNamed(method->name().utf8().data()).find(method) != notFound); unsigned int numParams = method->numParameters(); OwnArrayPtr<jvalue> jvalueArgs = adoptArrayPtr(new jvalue[numParams]); for (unsigned int i = 0; i < numParams; ++i) jvalueArgs[i] = javaValueToJvalue(args[i]); jvalue result = callJNIMethod(javaInstance(), method->returnType(), method->name().utf8().data(), method->signature(), jvalueArgs.get()); // ANDROID JNIEnv* env = getJNIEnv(); if (env->ExceptionCheck() != JNI_FALSE) { env->ExceptionClear(); didRaiseUncaughtException = true; return JavaValue(); } return jvalueToJavaValue(result, method->returnType()); // END ANDROID }
void TestShell::dumpImage(SkCanvas* canvas) const { // Fix the alpha. The expected PNGs on Mac have an alpha channel, so we want // to keep it. On Windows, the alpha channel is wrong since text/form control // drawing may have erased it in a few places. So on Windows we force it to // opaque and also don't write the alpha channel for the reference. Linux // doesn't have the wrong alpha like Windows, but we match Windows. #if OS(MAC_OS_X) bool discardTransparency = false; #else bool discardTransparency = true; makeCanvasOpaque(canvas); #endif const SkBitmap& sourceBitmap = canvas->getTopDevice()->accessBitmap(false); SkAutoLockPixels sourceBitmapLock(sourceBitmap); // Compute MD5 sum. MD5 digester; Vector<uint8_t, 16> digestValue; #if OS(ANDROID) // On Android, pixel layout is RGBA (see third_party/skia/include/core/SkColorPriv.h); // however, other Chrome platforms use BGRA (see skia/config/SkUserConfig.h). // To match the checksum of other Chrome platforms, we need to reorder the layout of pixels. // NOTE: The following code assumes we use SkBitmap::kARGB_8888_Config, // which has been checked in device.makeOpaque() (see above). const uint8_t* rawPixels = reinterpret_cast<const uint8_t*>(sourceBitmap.getPixels()); size_t bitmapSize = sourceBitmap.getSize(); OwnArrayPtr<uint8_t> reorderedPixels = adoptArrayPtr(new uint8_t[bitmapSize]); for (size_t i = 0; i < bitmapSize; i += 4) { reorderedPixels[i] = rawPixels[i + 2]; // R reorderedPixels[i + 1] = rawPixels[i + 1]; // G reorderedPixels[i + 2] = rawPixels[i]; // B reorderedPixels[i + 3] = rawPixels[i + 3]; // A } digester.addBytes(reorderedPixels.get(), bitmapSize); reorderedPixels.clear(); #else digester.addBytes(reinterpret_cast<const uint8_t*>(sourceBitmap.getPixels()), sourceBitmap.getSize()); #endif digester.checksum(digestValue); string md5hash; md5hash.reserve(16 * 2); for (unsigned i = 0; i < 16; ++i) { char hex[3]; // Use "x", not "X". The string must be lowercased. sprintf(hex, "%02x", digestValue[i]); md5hash.append(hex); } // Only encode and dump the png if the hashes don't match. Encoding the // image is really expensive. if (md5hash.compare(m_params.pixelHash)) { std::vector<unsigned char> png; #if OS(ANDROID) webkit_support::EncodeRGBAPNGWithChecksum(reinterpret_cast<const unsigned char*>(sourceBitmap.getPixels()), sourceBitmap.width(), sourceBitmap.height(), static_cast<int>(sourceBitmap.rowBytes()), discardTransparency, md5hash, &png); #else webkit_support::EncodeBGRAPNGWithChecksum(reinterpret_cast<const unsigned char*>(sourceBitmap.getPixels()), sourceBitmap.width(), sourceBitmap.height(), static_cast<int>(sourceBitmap.rowBytes()), discardTransparency, md5hash, &png); #endif m_printer->handleImage(md5hash.c_str(), m_params.pixelHash.c_str(), &png[0], png.size(), m_params.pixelFileName.c_str()); } else m_printer->handleImage(md5hash.c_str(), m_params.pixelHash.c_str(), 0, 0, m_params.pixelFileName.c_str()); }
JavaValue JavaInstanceJobject::invokeMethod(const JavaMethod* method, JavaValue* args) { ASSERT(getClass()->methodsNamed(method->name().utf8().data()).find(method) != notFound); unsigned int numParams = method->numParameters(); OwnArrayPtr<jvalue> jvalueArgs = adoptArrayPtr(new jvalue[numParams]); for (unsigned int i = 0; i < numParams; ++i) jvalueArgs[i] = javaValueToJvalue(args[i]); jvalue result = callJNIMethod(javaInstance(), method->returnType(), method->name().utf8().data(), method->signature(), jvalueArgs.get()); //CVE-2012-5114 : Control access to inherited methods of jsinterface objects //return jvalueToJavaValue(result, method->returnType()); return jvalueToJavaValue(result, method->returnType(), m_requireAnnotation); }
// FIXME: need comments. // Params: holder could be HTMLEmbedElement or NPObject static void npObjectInvokeImpl(const v8::FunctionCallbackInfo<v8::Value>& args, InvokeFunctionType functionId) { NPObject* npObject; WrapperWorldType currentWorldType = worldType(args.GetIsolate()); // These three types are subtypes of HTMLPlugInElement. if (V8HTMLAppletElement::HasInstance(args.Holder(), args.GetIsolate(), currentWorldType) || V8HTMLEmbedElement::HasInstance(args.Holder(), args.GetIsolate(), currentWorldType) || V8HTMLObjectElement::HasInstance(args.Holder(), args.GetIsolate(), currentWorldType)) { // The holder object is a subtype of HTMLPlugInElement. HTMLPlugInElement* element; if (V8HTMLAppletElement::HasInstance(args.Holder(), args.GetIsolate(), currentWorldType)) element = V8HTMLAppletElement::toNative(args.Holder()); else if (V8HTMLEmbedElement::HasInstance(args.Holder(), args.GetIsolate(), currentWorldType)) element = V8HTMLEmbedElement::toNative(args.Holder()); else element = V8HTMLObjectElement::toNative(args.Holder()); ScriptInstance scriptInstance = element->getInstance(); if (scriptInstance) { v8::Isolate* isolate = v8::Isolate::GetCurrent(); v8::HandleScope handleScope(isolate); npObject = v8ObjectToNPObject(scriptInstance->newLocal(isolate)); } else npObject = 0; } else { // The holder object is not a subtype of HTMLPlugInElement, it must be an NPObject which has three // internal fields. if (args.Holder()->InternalFieldCount() != npObjectInternalFieldCount) { throwError(v8ReferenceError, "NPMethod called on non-NPObject", args.GetIsolate()); return; } npObject = v8ObjectToNPObject(args.Holder()); } // Verify that our wrapper wasn't using a NPObject which has already been deleted. if (!npObject || !_NPN_IsAlive(npObject)) { throwError(v8ReferenceError, "NPObject deleted", args.GetIsolate()); return; } // Wrap up parameters. int numArgs = args.Length(); OwnArrayPtr<NPVariant> npArgs = adoptArrayPtr(new NPVariant[numArgs]); for (int i = 0; i < numArgs; i++) convertV8ObjectToNPVariant(args[i], npObject, &npArgs[i]); NPVariant result; VOID_TO_NPVARIANT(result); bool retval = true; switch (functionId) { case InvokeMethod: if (npObject->_class->invoke) { v8::Handle<v8::String> functionName = v8::Handle<v8::String>::Cast(args.Data()); NPIdentifier identifier = getStringIdentifier(functionName); retval = npObject->_class->invoke(npObject, identifier, npArgs.get(), numArgs, &result); } break; case InvokeConstruct: if (npObject->_class->construct) retval = npObject->_class->construct(npObject, npArgs.get(), numArgs, &result); break; case InvokeDefault: if (npObject->_class->invokeDefault) retval = npObject->_class->invokeDefault(npObject, npArgs.get(), numArgs, &result); break; default: break; } if (!retval) throwError(v8GeneralError, "Error calling method on NPObject.", args.GetIsolate()); for (int i = 0; i < numArgs; i++) _NPN_ReleaseVariantValue(&npArgs[i]); // Unwrap return values. v8::Handle<v8::Value> returnValue; if (_NPN_IsAlive(npObject)) returnValue = convertNPVariantToV8Object(&result, npObject, args.GetIsolate()); _NPN_ReleaseVariantValue(&result); v8SetReturnValue(args, returnValue); }
short V8NodeFilterCondition::acceptNode(ScriptState* state, Node* node) const { ASSERT(v8::Context::InContext()); v8::Isolate* isolate = state->isolate(); v8::HandleScope handleScope(isolate); v8::Handle<v8::Value> filter = m_filter.newLocal(isolate); ASSERT(!filter.IsEmpty()); if (!filter->IsObject()) return NodeFilter::FILTER_ACCEPT; v8::TryCatch exceptionCatcher; v8::Handle<v8::Function> callback; if (filter->IsFunction()) callback = v8::Handle<v8::Function>::Cast(filter); else { v8::Local<v8::Value> value = filter->ToObject()->Get(v8::String::NewSymbol("acceptNode")); if (!value->IsFunction()) { throwTypeError("NodeFilter object does not have an acceptNode function", state->isolate()); return NodeFilter::FILTER_REJECT; } callback = v8::Handle<v8::Function>::Cast(value); } OwnArrayPtr<v8::Handle<v8::Value> > args = adoptArrayPtr(new v8::Handle<v8::Value>[1]); args[0] = toV8(node, v8::Handle<v8::Object>(), state->isolate()); v8::Handle<v8::Object> object = v8::Context::GetCurrent()->Global(); v8::Handle<v8::Value> result = ScriptController::callFunctionWithInstrumentation(0, callback, object, 1, args.get(), isolate); if (exceptionCatcher.HasCaught()) { state->setException(exceptionCatcher.Exception()); return NodeFilter::FILTER_REJECT; } ASSERT(!result.IsEmpty()); return result->Int32Value(); }
bool _NPN_Construct(NPP npp, NPObject* npObject, const NPVariant* arguments, uint32_t argumentCount, NPVariant* result) { if (!npObject) return false; v8::Isolate* isolate = v8::Isolate::GetCurrent(); if (npObject->_class == npScriptObjectClass) { V8NPObject* object = reinterpret_cast<V8NPObject*>(npObject); v8::HandleScope handleScope; v8::Handle<v8::Context> context = toV8Context(npp, npObject); if (context.IsEmpty()) return false; v8::Context::Scope scope(context); ExceptionCatcher exceptionCatcher; // Lookup the constructor function. v8::Handle<v8::Object> ctorObj(object->v8Object); if (!ctorObj->IsFunction()) return false; // Call the constructor. v8::Local<v8::Value> resultObject; v8::Handle<v8::Function> ctor(v8::Function::Cast(*ctorObj)); if (!ctor->IsNull()) { Frame* frame = object->rootObject->frame(); ASSERT(frame); OwnArrayPtr<v8::Handle<v8::Value> > argv = createValueListFromVariantArgs(arguments, argumentCount, npObject, isolate); resultObject = V8ObjectConstructor::newInstanceInDocument(ctor, argumentCount, argv.get(), frame ? frame->document() : 0); } if (resultObject.IsEmpty()) return false; convertV8ObjectToNPVariant(resultObject, npObject, result); return true; } if (NP_CLASS_STRUCT_VERSION_HAS_CTOR(npObject->_class) && npObject->_class->construct) return npObject->_class->construct(npObject, arguments, argumentCount, result); return false; }
// FIXME: Fix it same as _NPN_Invoke (HandleScope and such). bool _NPN_InvokeDefault(NPP npp, NPObject* npObject, const NPVariant* arguments, uint32_t argumentCount, NPVariant* result) { if (!npObject) return false; v8::Isolate* isolate = v8::Isolate::GetCurrent(); if (npObject->_class != npScriptObjectClass) { if (npObject->_class->invokeDefault) return npObject->_class->invokeDefault(npObject, arguments, argumentCount, result); VOID_TO_NPVARIANT(*result); return true; } V8NPObject* v8NpObject = reinterpret_cast<V8NPObject*>(npObject); VOID_TO_NPVARIANT(*result); v8::HandleScope handleScope; v8::Handle<v8::Context> context = toV8Context(npp, npObject); if (context.IsEmpty()) return false; v8::Context::Scope scope(context); ExceptionCatcher exceptionCatcher; // Lookup the function object and call it. v8::Handle<v8::Object> functionObject(v8NpObject->v8Object); if (!functionObject->IsFunction()) return false; v8::Local<v8::Value> resultObject; v8::Handle<v8::Function> function(v8::Function::Cast(*functionObject)); if (!function->IsNull()) { Frame* frame = v8NpObject->rootObject->frame(); ASSERT(frame); OwnArrayPtr<v8::Handle<v8::Value> > argv = createValueListFromVariantArgs(arguments, argumentCount, npObject, isolate); resultObject = frame->script()->callFunction(function, functionObject, argumentCount, argv.get()); } // If we had an error, return false. The spec is a little unclear here, but says "Returns true if the method was // successfully invoked". If we get an error return value, was that successfully invoked? if (resultObject.IsEmpty()) return false; convertV8ObjectToNPVariant(resultObject, npObject, result); return true; }
bool _NPN_Invoke(NPP npp, NPObject* npObject, NPIdentifier methodName, const NPVariant* arguments, uint32_t argumentCount, NPVariant* result) { if (!npObject) return false; v8::Isolate* isolate = v8::Isolate::GetCurrent(); if (npObject->_class != npScriptObjectClass) { if (npObject->_class->invoke) return npObject->_class->invoke(npObject, methodName, arguments, argumentCount, result); VOID_TO_NPVARIANT(*result); return true; } V8NPObject* v8NpObject = reinterpret_cast<V8NPObject*>(npObject); PrivateIdentifier* identifier = static_cast<PrivateIdentifier*>(methodName); if (!identifier->isString) return false; if (!strcmp(identifier->value.string, "eval")) { if (argumentCount != 1) return false; if (arguments[0].type != NPVariantType_String) return false; return _NPN_Evaluate(npp, npObject, const_cast<NPString*>(&arguments[0].value.stringValue), result); } v8::HandleScope handleScope; // FIXME: should use the plugin's owner frame as the security context. v8::Handle<v8::Context> context = toV8Context(npp, npObject); if (context.IsEmpty()) return false; v8::Context::Scope scope(context); ExceptionCatcher exceptionCatcher; v8::Handle<v8::Value> functionObject = v8NpObject->v8Object->Get(v8::String::NewSymbol(identifier->value.string)); if (functionObject.IsEmpty() || functionObject->IsNull()) { NULL_TO_NPVARIANT(*result); return false; } if (functionObject->IsUndefined()) { VOID_TO_NPVARIANT(*result); return false; } Frame* frame = v8NpObject->rootObject->frame(); ASSERT(frame); // Call the function object. v8::Handle<v8::Function> function = v8::Handle<v8::Function>::Cast(functionObject); OwnArrayPtr<v8::Handle<v8::Value> > argv = createValueListFromVariantArgs(arguments, argumentCount, npObject, isolate); v8::Local<v8::Value> resultObject = frame->script()->callFunction(function, v8NpObject->v8Object, argumentCount, argv.get()); // If we had an error, return false. The spec is a little unclear here, but says "Returns true if the method was // successfully invoked". If we get an error return value, was that successfully invoked? if (resultObject.IsEmpty()) return false; convertV8ObjectToNPVariant(resultObject, npObject, result); return true; }
// FIXME: There is a lot of duplication with SetTimeoutOrInterval() in V8WorkerGlobalScopeCustom.cpp. // We should refactor this. void WindowSetTimeoutImpl(const v8::FunctionCallbackInfo<v8::Value>& args, bool singleShot) { int argumentCount = args.Length(); if (argumentCount < 1) return; DOMWindow* imp = V8Window::toNative(args.Holder()); ScriptExecutionContext* scriptContext = static_cast<ScriptExecutionContext*>(imp->document()); if (!scriptContext) { setDOMException(InvalidAccessError, args.GetIsolate()); return; } v8::Handle<v8::Value> function = args[0]; String functionString; if (!function->IsFunction()) { if (function->IsString()) { functionString = toWebCoreString(function); } else { v8::Handle<v8::Value> v8String = function->ToString(); // Bail out if string conversion failed. if (v8String.IsEmpty()) return; functionString = toWebCoreString(v8String); } // Don't allow setting timeouts to run empty functions! // (Bug 1009597) if (!functionString.length()) return; } if (!BindingSecurity::shouldAllowAccessToFrame(imp->frame())) return; OwnPtr<ScheduledAction> action; if (function->IsFunction()) { int paramCount = argumentCount >= 2 ? argumentCount - 2 : 0; OwnArrayPtr<v8::Local<v8::Value> > params; if (paramCount > 0) { params = adoptArrayPtr(new v8::Local<v8::Value>[paramCount]); for (int i = 0; i < paramCount; i++) { // parameters must be globalized params[i] = args[i+2]; } } // params is passed to action, and released in action's destructor ASSERT(imp->frame()); action = adoptPtr(new ScheduledAction(imp->frame()->script()->currentWorldContext(), v8::Handle<v8::Function>::Cast(function), paramCount, params.get(), args.GetIsolate())); } else { if (imp->document() && !imp->document()->contentSecurityPolicy()->allowEval()) { v8SetReturnValue(args, 0); return; } ASSERT(imp->frame()); action = adoptPtr(new ScheduledAction(imp->frame()->script()->currentWorldContext(), functionString, KURL(), args.GetIsolate())); } int32_t timeout = argumentCount >= 2 ? args[1]->Int32Value() : 0; int timerId; if (singleShot) timerId = DOMWindowTimers::setTimeout(imp, action.release(), timeout); else timerId = DOMWindowTimers::setInterval(imp, action.release(), timeout); // Try to do the idle notification before the timeout expires to get better // use of any idle time. Aim for the middle of the interval for simplicity. if (timeout >= 0) { double maximumFireInterval = static_cast<double>(timeout) / 1000 / 2; V8GCForContextDispose::instance().notifyIdleSooner(maximumFireInterval); } v8SetReturnValue(args, timerId); }
ScriptObject ScriptFunctionCall::construct(bool& hadException, bool reportExceptions) { ScriptScope scope(m_scriptState, reportExceptions); v8::Local<v8::Object> thisObject = m_thisObject.v8Object(); v8::Local<v8::Value> value = thisObject->Get(v8String(m_name)); if (!scope.success()) { hadException = true; return ScriptObject(); } ASSERT(value->IsFunction()); v8::Local<v8::Function> constructor(v8::Function::Cast(*value)); OwnArrayPtr<v8::Handle<v8::Value> > args = adoptArrayPtr(new v8::Handle<v8::Value>[m_arguments.size()]); for (size_t i = 0; i < m_arguments.size(); ++i) args[i] = m_arguments[i].v8Value(); v8::Local<v8::Object> result = SafeAllocation::newInstance(constructor, m_arguments.size(), args.get()); if (!scope.success()) { hadException = true; return ScriptObject(); } return ScriptObject(m_scriptState, result); }
static const PassRefPtr<KeyEventInfo> keyName(WKStringRef keyRef) { if (WKStringIsEqualToUTF8CString(keyRef, "leftArrow")) return adoptRef(new KeyEventInfo("Left", "")); if (WKStringIsEqualToUTF8CString(keyRef, "rightArrow")) return adoptRef(new KeyEventInfo("Right", "")); if (WKStringIsEqualToUTF8CString(keyRef, "upArrow")) return adoptRef(new KeyEventInfo("Up", "")); if (WKStringIsEqualToUTF8CString(keyRef, "downArrow")) return adoptRef(new KeyEventInfo("Down", "")); if (WKStringIsEqualToUTF8CString(keyRef, "pageUp")) return adoptRef(new KeyEventInfo("Prior", "")); if (WKStringIsEqualToUTF8CString(keyRef, "pageDown")) return adoptRef(new KeyEventInfo("Next", "")); if (WKStringIsEqualToUTF8CString(keyRef, "home")) return adoptRef(new KeyEventInfo("Home", "")); if (WKStringIsEqualToUTF8CString(keyRef, "end")) return adoptRef(new KeyEventInfo("End", "")); if (WKStringIsEqualToUTF8CString(keyRef, "insert")) return adoptRef(new KeyEventInfo("Insert", "")); if (WKStringIsEqualToUTF8CString(keyRef, "delete")) return adoptRef(new KeyEventInfo("Delete", "")); if (WKStringIsEqualToUTF8CString(keyRef, "printScreen")) return adoptRef(new KeyEventInfo("Print", "")); if (WKStringIsEqualToUTF8CString(keyRef, "menu")) return adoptRef(new KeyEventInfo("Menu", "")); if (WKStringIsEqualToUTF8CString(keyRef, "leftControl")) return adoptRef(new KeyEventInfo("Control_L", "")); if (WKStringIsEqualToUTF8CString(keyRef, "rightControl")) return adoptRef(new KeyEventInfo("Control_R", "")); if (WKStringIsEqualToUTF8CString(keyRef, "leftShift")) return adoptRef(new KeyEventInfo("Shift_L", "")); if (WKStringIsEqualToUTF8CString(keyRef, "rightShift")) return adoptRef(new KeyEventInfo("Shift_R", "")); if (WKStringIsEqualToUTF8CString(keyRef, "leftAlt")) return adoptRef(new KeyEventInfo("Alt_L", "")); if (WKStringIsEqualToUTF8CString(keyRef, "rightAlt")) return adoptRef(new KeyEventInfo("Alt_R", "")); if (WKStringIsEqualToUTF8CString(keyRef, "F1")) return adoptRef(new KeyEventInfo("F1", "")); if (WKStringIsEqualToUTF8CString(keyRef, "F2")) return adoptRef(new KeyEventInfo("F2", "")); if (WKStringIsEqualToUTF8CString(keyRef, "F3")) return adoptRef(new KeyEventInfo("F3", "")); if (WKStringIsEqualToUTF8CString(keyRef, "F4")) return adoptRef(new KeyEventInfo("F4", "")); if (WKStringIsEqualToUTF8CString(keyRef, "F5")) return adoptRef(new KeyEventInfo("F5", "")); if (WKStringIsEqualToUTF8CString(keyRef, "F6")) return adoptRef(new KeyEventInfo("F6", "")); if (WKStringIsEqualToUTF8CString(keyRef, "F7")) return adoptRef(new KeyEventInfo("F7", "")); if (WKStringIsEqualToUTF8CString(keyRef, "F8")) return adoptRef(new KeyEventInfo("F8", "")); if (WKStringIsEqualToUTF8CString(keyRef, "F9")) return adoptRef(new KeyEventInfo("F9", "")); if (WKStringIsEqualToUTF8CString(keyRef, "F10")) return adoptRef(new KeyEventInfo("F10", "")); if (WKStringIsEqualToUTF8CString(keyRef, "F11")) return adoptRef(new KeyEventInfo("F11", "")); if (WKStringIsEqualToUTF8CString(keyRef, "F12")) return adoptRef(new KeyEventInfo("F12", "")); size_t bufferSize = WKStringGetMaximumUTF8CStringSize(keyRef); OwnArrayPtr<char> buffer = adoptArrayPtr(new char[bufferSize]); WKStringGetUTF8CString(keyRef, buffer.get(), bufferSize); char charCode = buffer.get()[0]; if (charCode == '\n' || charCode == '\r') return adoptRef(new KeyEventInfo("Return", "\r")); if (charCode == '\t') return adoptRef(new KeyEventInfo("Tab", "\t")); if (charCode == '\x8') return adoptRef(new KeyEventInfo("BackSpace", "\x8")); if (charCode == ' ') return adoptRef(new KeyEventInfo("space", " ")); return adoptRef(new KeyEventInfo(buffer.get(), buffer.get())); }
ScriptValue ScriptCallback::call() { ASSERT(v8::Context::InContext()); ASSERT(m_function.v8Value()->IsFunction()); v8::TryCatch exceptionCatcher; exceptionCatcher.SetVerbose(true); v8::Handle<v8::Object> object = v8::Context::GetCurrent()->Global(); v8::Handle<v8::Function> function = v8::Handle<v8::Function>::Cast(m_function.v8Value()); OwnArrayPtr<v8::Handle<v8::Value> > args = adoptArrayPtr(new v8::Handle<v8::Value>[m_arguments.size()]); for (size_t i = 0; i < m_arguments.size(); ++i) args[i] = m_arguments[i].v8Value(); v8::Handle<v8::Value> result = ScriptController::callFunctionWithInstrumentation(0, function, object, m_arguments.size(), args.get()); return ScriptValue(result); }
short V8NodeFilterCondition::acceptNode(ScriptState* state, Node* node) const { ASSERT(v8::Context::InContext()); if (!m_filter->IsObject()) return NodeFilter::FILTER_ACCEPT; v8::TryCatch exceptionCatcher; v8::Handle<v8::Function> callback; if (m_filter->IsFunction()) callback = v8::Handle<v8::Function>::Cast(m_filter); else { v8::Local<v8::Value> value = m_filter->ToObject()->Get(v8::String::New("acceptNode")); if (!value->IsFunction()) { V8Proxy::throwError(V8Proxy::TypeError, "NodeFilter object does not have an acceptNode function"); return NodeFilter::FILTER_REJECT; } callback = v8::Handle<v8::Function>::Cast(value); } v8::Handle<v8::Object> object = v8::Context::GetCurrent()->Global(); OwnArrayPtr<v8::Handle<v8::Value> > args = adoptArrayPtr(new v8::Handle<v8::Value>[1]); args[0] = toV8(node); v8::Handle<v8::Value> result = V8Proxy::callFunctionWithoutFrame(callback, object, 1, args.get()); if (exceptionCatcher.HasCaught()) { state->setException(exceptionCatcher.Exception()); return NodeFilter::FILTER_REJECT; } ASSERT(!result.IsEmpty()); return result->Int32Value(); }
static float calculateDifference(Evas_Object* baselineImage, Evas_Object* actualImage, RefPtr<Evas_Object>& differenceImage) { int width, height, baselineWidth, baselineHeight; evas_object_image_size_get(actualImage, &width, &height); evas_object_image_size_get(baselineImage, &baselineWidth, &baselineHeight); if (width != baselineWidth || height != baselineHeight) { printf("Error, test and reference image have different sizes.\n"); return 100; // Completely different. } OwnArrayPtr<unsigned char> diffBuffer = adoptArrayPtr(new unsigned char[width * height]); if (!diffBuffer) abortWithErrorMessage("could not create difference buffer"); const int actualRowStride = evas_object_image_stride_get(actualImage); const int baseRowStride = evas_object_image_stride_get(baselineImage); unsigned numberOfDifferentPixels = 0; float totalDistance = 0; float maxDistance = 0; unsigned char* actualPixels = static_cast<unsigned char*>(evas_object_image_data_get(actualImage, EINA_FALSE)); unsigned char* basePixels = static_cast<unsigned char*>(evas_object_image_data_get(baselineImage, EINA_FALSE)); unsigned char* currentDiffPixel = diffBuffer.get(); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { unsigned char* actualPixel = pixelFromImageData(actualPixels, actualRowStride, x, y); unsigned char* basePixel = pixelFromImageData(basePixels, baseRowStride, x, y); const float distance = calculatePixelDifference(basePixel, actualPixel); *currentDiffPixel++ = static_cast<unsigned char>(distance * 255.0f); if (distance >= 1.0f / 255.0f) { ++numberOfDifferentPixels; totalDistance += distance; maxDistance = std::max<float>(maxDistance, distance); } } } // When using evas_object_image_data_get(), a complementary evas_object_data_set() must be // issued to balance the reference count, even if the image hasn't been changed. evas_object_image_data_set(baselineImage, basePixels); evas_object_image_data_set(actualImage, actualPixels); // Compute the difference as a percentage combining both the number of // different pixels and their difference amount i.e. the average distance // over the entire image float difference = 0; if (numberOfDifferentPixels) difference = 100.0f * totalDistance / (height * width); if (difference <= gTolerance) difference = 0; else { difference = roundf(difference * 100.0f) / 100.0f; difference = std::max(difference, 0.01f); // round to 2 decimal places differenceImage = adoptRef(differenceImageFromDifferenceBuffer(evas_object_evas_get(baselineImage), diffBuffer.get(), width, height)); } return difference; }
ScriptValue ScriptCallback::call(bool& hadException) { ASSERT(v8::Context::InContext()); ASSERT(m_function.v8Value()->IsFunction()); v8::TryCatch exceptionCatcher; v8::Handle<v8::Object> object = v8::Context::GetCurrent()->Global(); v8::Handle<v8::Function> function = v8::Handle<v8::Function>::Cast(m_function.v8Value()); OwnArrayPtr<v8::Handle<v8::Value> > args = adoptArrayPtr(new v8::Handle<v8::Value>[m_arguments.size()]); for (size_t i = 0; i < m_arguments.size(); ++i) args[i] = m_arguments[i].v8Value(); v8::Handle<v8::Value> result = V8Proxy::instrumentedCallFunction(0 /* frame */, function, object, m_arguments.size(), args.get()); if (exceptionCatcher.HasCaught()) { hadException = true; m_scriptState->setException(exceptionCatcher.Exception()); return ScriptValue(); } return ScriptValue(result); }
bool PluginPackage::fetchInfo() { DWORD versionInfoSize, zeroHandle; versionInfoSize = GetFileVersionInfoSizeW(const_cast<UChar*>(m_path.charactersWithNullTermination()), &zeroHandle); if (versionInfoSize == 0) return false; OwnArrayPtr<char> versionInfoData = adoptArrayPtr(new char[versionInfoSize]); if (!GetFileVersionInfoW(const_cast<UChar*>(m_path.charactersWithNullTermination()), 0, versionInfoSize, versionInfoData.get())) return false; m_name = getVersionInfo(versionInfoData.get(), "ProductName"); m_description = getVersionInfo(versionInfoData.get(), "FileDescription"); if (m_name.isNull() || m_description.isNull()) return false; VS_FIXEDFILEINFO* info; UINT infoSize; if (!VerQueryValueW(versionInfoData.get(), L"\\", (LPVOID*) &info, &infoSize) || infoSize < sizeof(VS_FIXEDFILEINFO)) return false; m_moduleVersion.leastSig = info->dwFileVersionLS; m_moduleVersion.mostSig = info->dwFileVersionMS; if (isPluginBlacklisted()) return false; Vector<String> types; getVersionInfo(versionInfoData.get(), "MIMEType").split('|', types); Vector<String> extensionLists; getVersionInfo(versionInfoData.get(), "FileExtents").split('|', extensionLists); Vector<String> descriptions; getVersionInfo(versionInfoData.get(), "FileOpenName").split('|', descriptions); for (unsigned i = 0; i < types.size(); i++) { String type = types[i].lower(); String description = i < descriptions.size() ? descriptions[i] : ""; String extensionList = i < extensionLists.size() ? extensionLists[i] : ""; Vector<String> extensionsVector; extensionList.split(',', extensionsVector); // Get rid of the extension list that may be at the end of the description string. int pos = description.find("(*"); if (pos != -1) { // There might be a space that we need to get rid of. if (pos > 1 && description[pos - 1] == ' ') pos--; description = description.left(pos); } // Determine the quirks for the MIME types this plug-in supports determineQuirks(type); m_mimeToExtensions.add(type, extensionsVector); m_mimeToDescriptions.add(type, description); } return true; }