📄 netscapeplugininstanceproxy.mm
字号:
WebFrame *frame = nil; NSURL *URL = [request URL]; NSString *JSString = [URL _webkit_scriptIfJavaScriptURL]; ASSERT(frameName || JSString); if (frameName) { // FIXME - need to get rid of this window creation which // bypasses normal targeted link handling frame = kit(core([m_pluginView webFrame])->loader()->findFrameForNavigation(frameName)); if (!frame) { WebView *currentWebView = [m_pluginView webView]; NSDictionary *features = [[NSDictionary alloc] init]; WebView *newWebView = [[currentWebView _UIDelegateForwarder] webView:currentWebView createWebViewWithRequest:nil windowFeatures:features]; [features release]; if (!newWebView) { _WKPHLoadURLNotify(m_pluginHostProxy->port(), m_pluginID, pluginRequest->requestID(), NPERR_GENERIC_ERROR); return; } frame = [newWebView mainFrame]; core(frame)->tree()->setName(frameName); [[newWebView _UIDelegateForwarder] webViewShow:newWebView]; } } if (JSString) { ASSERT(!frame || [m_pluginView webFrame] == frame); evaluateJavaScript(pluginRequest); } else [frame loadRequest:request];}void NetscapePluginInstanceProxy::evaluateJavaScript(PluginRequest* pluginRequest){ NSURL *URL = [pluginRequest->request() URL]; NSString *JSString = [URL _webkit_scriptIfJavaScriptURL]; ASSERT(JSString); NSString *result = [[m_pluginView webFrame] _stringByEvaluatingJavaScriptFromString:JSString forceUserGesture:pluginRequest->didStartFromUserGesture()]; // Don't continue if stringByEvaluatingJavaScriptFromString caused the plug-in to stop. if (!m_pluginHostProxy) return; if (pluginRequest->frameName() != nil) return; if ([result length] > 0) { // Don't call NPP_NewStream and other stream methods if there is no JS result to deliver. This is what Mozilla does. NSData *JSData = [result dataUsingEncoding:NSUTF8StringEncoding]; RefPtr<HostedNetscapePluginStream> stream = HostedNetscapePluginStream::create(this, pluginRequest->requestID(), pluginRequest->request()); RetainPtr<NSURLResponse> response(AdoptNS, [[NSURLResponse alloc] initWithURL:URL MIMEType:@"text/plain" expectedContentLength:[JSData length] textEncodingName:nil]); stream->startStreamWithResponse(response.get()); stream->didReceiveData(0, static_cast<const char*>([JSData bytes]), [JSData length]); stream->didFinishLoading(0); }}void NetscapePluginInstanceProxy::requestTimerFired(Timer<NetscapePluginInstanceProxy>*){ ASSERT(!m_pluginRequests.isEmpty()); PluginRequest* request = m_pluginRequests.first(); m_pluginRequests.removeFirst(); if (!m_pluginRequests.isEmpty()) m_requestTimer.startOneShot(0); performRequest(request); delete request;} NPError NetscapePluginInstanceProxy::loadRequest(NSURLRequest *request, const char* cTarget, bool currentEventIsUserGesture, uint32_t& requestID){ NSURL *URL = [request URL]; if (!URL) return NPERR_INVALID_URL; // Don't allow requests to be loaded when the document loader is stopping all loaders. if ([[m_pluginView dataSource] _documentLoader]->isStopping()) return NPERR_GENERIC_ERROR; NSString *target = nil; if (cTarget) { // Find the frame given the target string. target = [NSString stringWithCString:cTarget encoding:NSISOLatin1StringEncoding]; } WebFrame *frame = [m_pluginView webFrame]; // don't let a plugin start any loads if it is no longer part of a document that is being // displayed unless the loads are in the same frame as the plugin. if ([[m_pluginView dataSource] _documentLoader] != core([m_pluginView webFrame])->loader()->activeDocumentLoader() && (!cTarget || [frame findFrameNamed:target] != frame)) { return NPERR_GENERIC_ERROR; } NSString *JSString = [URL _webkit_scriptIfJavaScriptURL]; if (JSString != nil) { if (![[[m_pluginView webView] preferences] isJavaScriptEnabled]) { // Return NPERR_GENERIC_ERROR if JS is disabled. This is what Mozilla does. return NPERR_GENERIC_ERROR; } } else { if (!FrameLoader::canLoad(URL, String(), core([m_pluginView webFrame])->document())) return NPERR_GENERIC_ERROR; } // FIXME: Handle wraparound requestID = ++m_currentRequestID; if (cTarget || JSString) { // Make when targetting a frame or evaluating a JS string, perform the request after a delay because we don't // want to potentially kill the plug-in inside of its URL request. if (JSString && target && [frame findFrameNamed:target] != frame) { // For security reasons, only allow JS requests to be made on the frame that contains the plug-in. return NPERR_INVALID_PARAM; } PluginRequest* pluginRequest = new PluginRequest(requestID, request, target, currentEventIsUserGesture); m_pluginRequests.append(pluginRequest); m_requestTimer.startOneShot(0); } else { RefPtr<HostedNetscapePluginStream> stream = HostedNetscapePluginStream::create(this, requestID, request); m_streams.add(requestID, stream); stream->start(); } return NPERR_NO_ERROR;}void NetscapePluginInstanceProxy::processRequestsAndWaitForReply(){ while (!m_currentReply.get()) { if (!m_pluginHostProxy->processRequests()) { m_currentReply.reset(); break; } }} uint32_t NetscapePluginInstanceProxy::idForObject(JSObject* object){ uint32_t objectID = 0; // Assign an object ID. do { objectID = ++m_objectIDCounter; } while (!m_objectIDCounter || m_objectIDCounter == static_cast<uint32_t>(-1) || m_objects.contains(objectID)); m_objects.set(objectID, object); return objectID;}// NPRuntime supportbool NetscapePluginInstanceProxy::getWindowNPObject(uint32_t& objectID){ Frame* frame = core([m_pluginView webFrame]); if (!frame) return false; if (!frame->script()->isEnabled()) objectID = 0; else objectID = idForObject(frame->script()->windowShell()->window()); return true;}bool NetscapePluginInstanceProxy::getPluginElementNPObject(uint32_t& objectID){ Frame* frame = core([m_pluginView webFrame]); if (!frame) return false; if (JSObject* object = frame->script()->jsObjectForPluginElement([m_pluginView element])) objectID = idForObject(object); else objectID = 0; return true;}void NetscapePluginInstanceProxy::releaseObject(uint32_t objectID){ m_objects.remove(objectID);} bool NetscapePluginInstanceProxy::evaluate(uint32_t objectID, const String& script, data_t& resultData, mach_msg_type_number_t& resultLength){ resultData = 0; resultLength = 0; if (!m_objects.contains(objectID)) return false; Frame* frame = core([m_pluginView webFrame]); if (!frame) return false; JSLock lock(false); ProtectedPtr<JSGlobalObject> globalObject = frame->script()->globalObject(); ExecState* exec = globalObject->globalExec(); globalObject->globalData()->timeoutChecker.start(); Completion completion = JSC::evaluate(exec, globalObject->globalScopeChain(), makeSource(script)); globalObject->globalData()->timeoutChecker.stop(); ComplType type = completion.complType(); JSValuePtr result; if (type == Normal) result = completion.value(); if (!result) result = jsUndefined(); marshalValue(exec, result, resultData, resultLength); exec->clearException(); return true;}bool NetscapePluginInstanceProxy::invoke(uint32_t objectID, const Identifier& methodName, data_t argumentsData, mach_msg_type_number_t argumentsLength, data_t& resultData, mach_msg_type_number_t& resultLength){ resultData = 0; resultLength = 0; 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 function = object->get(exec, methodName); CallData callData; CallType callType = function.getCallData(callData); if (callType == CallTypeNone) return false; ArgList argList; demarshalValues(exec, argumentsData, argumentsLength, argList); ProtectedPtr<JSGlobalObject> globalObject = frame->script()->globalObject(); globalObject->globalData()->timeoutChecker.start(); JSValuePtr value = call(exec, function, callType, callData, object, argList); globalObject->globalData()->timeoutChecker.stop(); marshalValue(exec, value, resultData, resultLength); exec->clearException(); return true;}bool NetscapePluginInstanceProxy::invokeDefault(uint32_t objectID, data_t argumentsData, mach_msg_type_number_t argumentsLength, 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); CallData callData; CallType callType = object->getCallData(callData); if (callType == CallTypeNone) return false; ArgList argList; demarshalValues(exec, argumentsData, argumentsLength, argList); ProtectedPtr<JSGlobalObject> globalObject = frame->script()->globalObject(); globalObject->globalData()->timeoutChecker.start(); JSValuePtr value = call(exec, object, callType, callData, object, argList); globalObject->globalData()->timeoutChecker.stop(); marshalValue(exec, value, resultData, resultLength); exec->clearException(); return true;}bool NetscapePluginInstanceProxy::construct(uint32_t objectID, data_t argumentsData, mach_msg_type_number_t argumentsLength, 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); ConstructData constructData; ConstructType constructType = object->getConstructData(constructData); if (constructType == ConstructTypeNone) return false; ArgList argList; demarshalValues(exec, argumentsData, argumentsLength, argList); ProtectedPtr<JSGlobalObject> globalObject = frame->script()->globalObject(); globalObject->globalData()->timeoutChecker.start(); JSValuePtr value = JSC::construct(exec, object, constructType, constructData, argList); globalObject->globalData()->timeoutChecker.stop(); marshalValue(exec, value, resultData, resultLength); exec->clearException(); return true;}bool NetscapePluginInstanceProxy::getProperty(uint32_t objectID, const Identifier& propertyName, 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); JSValuePtr value = object->get(exec, propertyName); marshalValue(exec, value, resultData, resultLength); exec->clearException(); return true;} bool NetscapePluginInstanceProxy::getProperty(uint32_t objectID, unsigned propertyName, 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); JSValuePtr value = object->get(exec, propertyName); marshalValue(exec, value, resultData, resultLength); exec->clearException(); return true;}bool NetscapePluginInstanceProxy::setProperty(uint32_t objectID, const Identifier& propertyName, data_t valueData, mach_msg_type_number_t valueLength){ JSObject* object = m_objects.get(objectID); if (!object) return false;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -