📄 netscapeplugininstanceproxy.mm
字号:
Frame* frame = core([m_pluginView webFrame]); if (!frame) return false; ExecState* exec = frame->script()->globalObject()->globalExec(); JSLock lock(false); JSValuePtr value = demarshalValue(exec, valueData, valueLength); PutPropertySlot slot; object->put(exec, propertyName, value, slot); exec->clearException(); return true;}bool NetscapePluginInstanceProxy::setProperty(uint32_t objectID, unsigned propertyName, data_t valueData, mach_msg_type_number_t valueLength){ JSObject* object = m_objects.get(objectID); if (!object) return false; Frame* frame = core([m_pluginView webFrame]); if (!frame) return false; ExecState* exec = frame->script()->globalObject()->globalExec(); JSLock lock(false); JSValuePtr value = demarshalValue(exec, valueData, valueLength); object->put(exec, propertyName, value); exec->clearException(); return true;}bool NetscapePluginInstanceProxy::removeProperty(uint32_t objectID, const Identifier& propertyName){ JSObject* object = m_objects.get(objectID); if (!object) return false; Frame* frame = core([m_pluginView webFrame]); if (!frame) return false; ExecState* exec = frame->script()->globalObject()->globalExec(); if (!object->hasProperty(exec, propertyName)) { exec->clearException(); return false; } JSLock lock(false); object->deleteProperty(exec, propertyName); exec->clearException(); return true;} bool NetscapePluginInstanceProxy::removeProperty(uint32_t objectID, unsigned propertyName){ JSObject* object = m_objects.get(objectID); if (!object) return false; Frame* frame = core([m_pluginView webFrame]); if (!frame) return false; ExecState* exec = frame->script()->globalObject()->globalExec(); if (!object->hasProperty(exec, propertyName)) { exec->clearException(); return false; } JSLock lock(false); object->deleteProperty(exec, propertyName); exec->clearException(); return true;}bool NetscapePluginInstanceProxy::hasProperty(uint32_t objectID, const Identifier& propertyName){ JSObject* object = m_objects.get(objectID); if (!object) return false; Frame* frame = core([m_pluginView webFrame]); if (!frame) return false; ExecState* exec = frame->script()->globalObject()->globalExec(); bool result = object->hasProperty(exec, propertyName); exec->clearException(); return result;}bool NetscapePluginInstanceProxy::hasProperty(uint32_t objectID, unsigned propertyName){ JSObject* object = m_objects.get(objectID); if (!object) return false; Frame* frame = core([m_pluginView webFrame]); if (!frame) return false; ExecState* exec = frame->script()->globalObject()->globalExec(); bool result = object->hasProperty(exec, propertyName); exec->clearException(); return result;} bool NetscapePluginInstanceProxy::hasMethod(uint32_t objectID, const Identifier& methodName){ JSObject* object = m_objects.get(objectID); if (!object) return false; Frame* frame = core([m_pluginView webFrame]); if (!frame) return false; ExecState* exec = frame->script()->globalObject()->globalExec(); JSLock lock(false); JSValuePtr func = object->get(exec, methodName); exec->clearException(); return !func.isUndefined();}bool NetscapePluginInstanceProxy::enumerate(uint32_t objectID, data_t& resultData, mach_msg_type_number_t& resultLength){ JSObject* object = m_objects.get(objectID); if (!object) return false; Frame* frame = core([m_pluginView webFrame]); if (!frame) return false; ExecState* exec = frame->script()->globalObject()->globalExec(); JSLock lock(false); PropertyNameArray propertyNames(exec); object->getPropertyNames(exec, propertyNames); NSMutableArray *array = [[NSMutableArray alloc] init]; for (unsigned i = 0; i < propertyNames.size(); i++) { uint64_t methodName = reinterpret_cast<uint64_t>(_NPN_GetStringIdentifier(propertyNames[i].ustring().UTF8String().c_str())); [array addObject:[NSNumber numberWithLongLong:methodName]]; } NSData *data = [NSPropertyListSerialization dataFromPropertyList:array format:NSPropertyListBinaryFormat_v1_0 errorDescription:0]; ASSERT(data); resultLength = [data length]; mig_allocate(reinterpret_cast<vm_address_t*>(&resultData), resultLength); memcpy(resultData, [data bytes], resultLength); exec->clearException(); return true;}void NetscapePluginInstanceProxy::addValueToArray(NSMutableArray *array, ExecState* exec, JSValuePtr value){ JSLock lock(false); if (value.isString()) { [array addObject:[NSNumber numberWithInt:StringValueType]]; [array addObject:String(value.toString(exec))]; } else if (value.isNumber()) { [array addObject:[NSNumber numberWithInt:DoubleValueType]]; [array addObject:[NSNumber numberWithDouble:value.toNumber(exec)]]; } else if (value.isBoolean()) { [array addObject:[NSNumber numberWithInt:BoolValueType]]; [array addObject:[NSNumber numberWithBool:value.toBoolean(exec)]]; } else if (value.isNull()) [array addObject:[NSNumber numberWithInt:NullValueType]]; else if (value.isObject()) { JSObject* object = asObject(value); if (object->classInfo() == &RuntimeObjectImp::s_info) { RuntimeObjectImp* imp = static_cast<RuntimeObjectImp*>(object); if (ProxyInstance* instance = static_cast<ProxyInstance*>(imp->getInternalInstance())) { [array addObject:[NSNumber numberWithInt:NPObjectValueType]]; [array addObject:[NSNumber numberWithInt:instance->objectID()]]; } } else { [array addObject:[NSNumber numberWithInt:JSObjectValueType]]; [array addObject:[NSNumber numberWithInt:idForObject(object)]]; } } else [array addObject:[NSNumber numberWithInt:VoidValueType]];}void NetscapePluginInstanceProxy::marshalValue(ExecState* exec, JSValuePtr value, data_t& resultData, mach_msg_type_number_t& resultLength){ RetainPtr<NSMutableArray*> array(AdoptNS, [[NSMutableArray alloc] init]); addValueToArray(array.get(), exec, value); RetainPtr<NSData *> data = [NSPropertyListSerialization dataFromPropertyList:array.get() format:NSPropertyListBinaryFormat_v1_0 errorDescription:0]; ASSERT(data); resultLength = [data.get() length]; mig_allocate(reinterpret_cast<vm_address_t*>(&resultData), resultLength); memcpy(resultData, [data.get() bytes], resultLength);}RetainPtr<NSData *> NetscapePluginInstanceProxy::marshalValues(ExecState* exec, const ArgList& args){ RetainPtr<NSMutableArray*> array(AdoptNS, [[NSMutableArray alloc] init]); for (unsigned i = 0; i < args.size(); i++) addValueToArray(array.get(), exec, args.at(exec, i)); RetainPtr<NSData *> data = [NSPropertyListSerialization dataFromPropertyList:array.get() format:NSPropertyListBinaryFormat_v1_0 errorDescription:0]; ASSERT(data); return data;} bool NetscapePluginInstanceProxy::demarshalValueFromArray(ExecState* exec, NSArray *array, NSUInteger& index, JSValuePtr& result){ if (index == [array count]) return false; int type = [[array objectAtIndex:index++] intValue]; switch (type) { case VoidValueType: result = jsUndefined(); return true; case NullValueType: result = jsNull(); return true; case BoolValueType: result = jsBoolean([[array objectAtIndex:index++] boolValue]); return true; case DoubleValueType: result = jsNumber(exec, [[array objectAtIndex:index++] doubleValue]); return true; case StringValueType: { NSString *string = [array objectAtIndex:index++]; result = jsString(exec, String(string)); return true; } case JSObjectValueType: { uint32_t objectID = [[array objectAtIndex:index++] intValue]; result = m_objects.get(objectID); ASSERT(result); return true; } case NPObjectValueType: { uint32_t objectID = [[array objectAtIndex:index++] intValue]; Frame* frame = core([m_pluginView webFrame]); if (!frame) return false; if (!frame->script()->isEnabled()) return false; RefPtr<RootObject> rootObject = frame->script()->createRootObject(m_pluginView); if (!rootObject) return false; result = ProxyInstance::create(rootObject.release(), this, objectID)->createRuntimeObject(exec); return true; } default: ASSERT_NOT_REACHED(); return false; }}JSValuePtr NetscapePluginInstanceProxy::demarshalValue(ExecState* exec, const char* valueData, mach_msg_type_number_t valueLength){ RetainPtr<NSData*> data(AdoptNS, [[NSData alloc] initWithBytesNoCopy:(void*)valueData length:valueLength freeWhenDone:NO]); RetainPtr<NSArray*> array = [NSPropertyListSerialization propertyListFromData:data.get() mutabilityOption:NSPropertyListImmutable format:0 errorDescription:0]; NSUInteger position = 0; JSValuePtr value; bool result = demarshalValueFromArray(exec, array.get(), position, value); ASSERT_UNUSED(result, result); return value;}void NetscapePluginInstanceProxy::demarshalValues(ExecState* exec, data_t valuesData, mach_msg_type_number_t valuesLength, ArgList& result){ RetainPtr<NSData*> data(AdoptNS, [[NSData alloc] initWithBytesNoCopy:valuesData length:valuesLength freeWhenDone:NO]); RetainPtr<NSArray*> array = [NSPropertyListSerialization propertyListFromData:data.get() mutabilityOption:NSPropertyListImmutable format:0 errorDescription:0]; NSUInteger position = 0; JSValuePtr value; while (demarshalValueFromArray(exec, array.get(), position, value)) result.append(value);}PassRefPtr<Instance> NetscapePluginInstanceProxy::createBindingsInstance(PassRefPtr<RootObject> rootObject){ if (_WKPHGetScriptableNPObject(m_pluginHostProxy->port(), m_pluginID) != KERN_SUCCESS) return 0; auto_ptr<GetScriptableNPObjectReply> reply = waitForReply<GetScriptableNPObjectReply>(); if (!reply.get()) return 0; if (!reply->m_objectID) return 0; return ProxyInstance::create(rootObject, this, reply->m_objectID);}void NetscapePluginInstanceProxy::addInstance(ProxyInstance* instance){ ASSERT(!m_instances.contains(instance)); m_instances.add(instance);} void NetscapePluginInstanceProxy::removeInstance(ProxyInstance* instance){ ASSERT(m_instances.contains(instance)); m_instances.remove(instance);} void NetscapePluginInstanceProxy::willCallPluginFunction(){ m_pluginFunctionCallDepth++;} void NetscapePluginInstanceProxy::didCallPluginFunction(){ ASSERT(m_pluginFunctionCallDepth > 0); m_pluginFunctionCallDepth--; // If -stop was called while we were calling into a plug-in function, and we're no longer // inside a plug-in function, stop now. if (!m_pluginFunctionCallDepth && m_shouldStopSoon) { m_shouldStopSoon = false; [m_pluginView stop]; }} bool NetscapePluginInstanceProxy::shouldStop(){ if (m_pluginFunctionCallDepth) { m_shouldStopSoon = true; return false; } return true;}} // namespace WebKit#endif // USE(PLUGIN_HOST_PROCESS)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -