// static v8::Handle<v8::Value> WebDevToolsAgentImpl::jsDispatchOnClient(const v8::Arguments& args) { v8::TryCatch exceptionCatcher; String message = WebCore::toWebCoreStringWithNullCheck(args[0]); if (message.isEmpty() || exceptionCatcher.HasCaught()) return v8::Undefined(); WebDevToolsAgentImpl* agent = static_cast<WebDevToolsAgentImpl*>(v8::External::Cast(*args.Data())->Value()); agent->m_toolsAgentDelegateStub->dispatchOnClient(message); return v8::Undefined(); }
v8::Handle<v8::Value> WebDevToolsFrontendImpl::jsShowContextMenu(const v8::Arguments& args) { if (args.Length() < 2) return v8::Undefined(); v8::Local<v8::Object> eventWrapper = v8::Local<v8::Object>::Cast(args[0]); if (V8DOMWrapper::domWrapperType(eventWrapper) != V8ClassIndex::MOUSEEVENT) return v8::Undefined(); Event* event = V8Event::toNative(eventWrapper); if (!args[1]->IsArray()) return v8::Undefined(); v8::Local<v8::Array> array = v8::Local<v8::Array>::Cast(args[1]); Vector<ContextMenuItem*> items; for (size_t i = 0; i < array->Length(); ++i) { v8::Local<v8::Object> item = v8::Local<v8::Object>::Cast(array->Get(v8::Integer::New(i))); v8::Local<v8::Value> label = item->Get(v8::String::New("label")); v8::Local<v8::Value> id = item->Get(v8::String::New("id")); if (label->IsUndefined() || id->IsUndefined()) { items.append(new ContextMenuItem(SeparatorType, ContextMenuItemTagNoAction, String())); } else { ContextMenuAction typedId = static_cast<ContextMenuAction>( ContextMenuItemBaseCustomTag + id->ToInt32()->Value()); items.append(new ContextMenuItem(ActionType, typedId, toWebCoreStringWithNullCheck(label))); } } WebDevToolsFrontendImpl* frontend = static_cast<WebDevToolsFrontendImpl*>(v8::External::Cast(*args.Data())->Value()); frontend->m_menuProvider = MenuProvider::create(frontend, items); ContextMenuController* menuController = frontend->m_webViewImpl->page()->contextMenuController(); menuController->showContextMenu(event, frontend->m_menuProvider); return v8::Undefined(); }
// FIXME: need comments. // Params: holder could be HTMLEmbedElement or NPObject static v8::Handle<v8::Value> npObjectInvokeImpl(const v8::Arguments& args, InvokeFunctionType functionId) { NPObject* npObject; // These three types are subtypes of HTMLPlugInElement. if (V8HTMLAppletElement::HasInstance(args.Holder()) || V8HTMLEmbedElement::HasInstance(args.Holder()) || V8HTMLObjectElement::HasInstance(args.Holder())) { // The holder object is a subtype of HTMLPlugInElement. HTMLPlugInElement* element = V8DOMWrapper::convertDOMWrapperToNode<HTMLPlugInElement>(args.Holder()); ScriptInstance scriptInstance = element->getInstance(); if (scriptInstance) npObject = V8DOMWrapper::convertToNativeObject<NPObject>(V8ClassIndex::NPOBJECT, scriptInstance->instance()); 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() != V8Custom::kNPObjectInternalFieldCount) return throwError("NPMethod called on non-NPObject", V8Proxy::ReferenceError); npObject = V8DOMWrapper::convertToNativeObject<NPObject>(V8ClassIndex::NPOBJECT, args.Holder()); } // Verify that our wrapper wasn't using a NPObject which has already been deleted. if (!npObject || !_NPN_IsAlive(npObject)) return throwError("NPObject deleted", V8Proxy::ReferenceError); // Wrap up parameters. int numArgs = args.Length(); OwnArrayPtr<NPVariant> npArgs(new NPVariant[numArgs]); for (int i = 0; i < numArgs; i++) convertV8ObjectToNPVariant(args[i], npObject, &npArgs[i]); NPVariant result; VOID_TO_NPVARIANT(result); switch (functionId) { case InvokeMethod: if (npObject->_class->invoke) { v8::Handle<v8::String> functionName(v8::String::Cast(*args.Data())); NPIdentifier identifier = getStringIdentifier(functionName); npObject->_class->invoke(npObject, identifier, npArgs.get(), numArgs, &result); } break; case InvokeConstruct: if (npObject->_class->construct) npObject->_class->construct(npObject, npArgs.get(), numArgs, &result); break; case InvokeDefault: if (npObject->_class->invokeDefault) npObject->_class->invokeDefault(npObject, npArgs.get(), numArgs, &result); break; default: break; } for (int i=0; i < numArgs; i++) _NPN_ReleaseVariantValue(&npArgs[i]); // Unwrap return values. v8::Handle<v8::Value> returnValue = convertNPVariantToV8Object(&result, npObject); _NPN_ReleaseVariantValue(&result); return returnValue; }
v8::Handle<v8::Value> WebDevToolsFrontendImpl::jsDebuggerPauseScript(const v8::Arguments& args) { WebDevToolsFrontendImpl* frontend = static_cast<WebDevToolsFrontendImpl*>(v8::External::Cast(*args.Data())->Value()); frontend->m_client->sendDebuggerPauseScript(); return v8::Undefined(); }
v8::Handle<v8::Value> WebDevToolsFrontendImpl::jsDebuggerCommand(const v8::Arguments& args) { WebDevToolsFrontendImpl* frontend = static_cast<WebDevToolsFrontendImpl*>(v8::External::Cast(*args.Data())->Value()); WebString command = WebCore::toWebCoreStringWithNullCheck(args[0]); frontend->m_client->sendDebuggerCommandToAgent(command); return v8::Undefined(); }
v8::Handle<v8::Value> WebDevToolsFrontendImpl::jsUndockWindow(const v8::Arguments& args) { WebDevToolsFrontendImpl* frontend = static_cast<WebDevToolsFrontendImpl*>(v8::External::Cast(*args.Data())->Value()); frontend->m_client->undockWindow(); return v8::Undefined(); }
v8::Handle<v8::Value> WebDevToolsFrontendImpl::jsLoaded(const v8::Arguments& args) { WebDevToolsFrontendImpl* frontend = static_cast<WebDevToolsFrontendImpl*>(v8::External::Cast(*args.Data())->Value()); frontend->m_loaded = true; // Grant the devtools page the ability to have source view iframes. Page* page = V8Proxy::retrieveFrameForEnteredContext()->page(); SecurityOrigin* origin = page->mainFrame()->domWindow()->securityOrigin(); origin->grantUniversalAccess(); for (Vector<Vector<String> >::iterator it = frontend->m_pendingIncomingMessages.begin(); it != frontend->m_pendingIncomingMessages.end(); ++it) { frontend->executeScript(*it); } frontend->m_pendingIncomingMessages.clear(); return v8::Undefined(); }
v8::Handle<v8::Value> CJavaBoundMethod::Caller(const v8::Arguments& args) { CJavaBoundMethod& func = *static_cast<CJavaBoundMethod *>(v8::Handle<v8::External>::Cast(args.Data())->Value()); JNIEnv *pEnv = func.GetEnv(); jobject thiz = func.GetThiz(); jmethodID mid = func.GetMid(); if (func.HasArgs()) { jni::V8Env env(func.GetEnv()); jobjectArray params = (jobjectArray) env.NewObjectArray(args.Length()); for (size_t i=0; i<args.Length(); i++) { env->SetObjectArrayElement(params, i, env.Wrap(args[i])); } if (func.IsVoid()) { pEnv->CallVoidMethod(thiz, mid, params); return v8::Null(); } else { jobject result = pEnv->CallObjectMethod(thiz, mid, params); return env.Wrap(result); } } else { if (func.IsVoid()) { pEnv->CallVoidMethod(thiz, mid); return v8::Null(); } else { jni::V8Env env(func.GetEnv()); jobject result = pEnv->CallObjectMethod(thiz, mid); return env.Wrap(result); } } }