void CPluginBase::onNPP_DestroyStream(NPStream * pStream) { // if this is a stream created by tester, reflect the fact it is destroyed if(pStream == m_pStream) m_pStream = NULL; // if this is a script stream, reflect the fact it is destroyed too, and execute the script if(pStream == m_pScriptStream) { m_pScriptStream = NULL; if(!XP_IsFile(m_szScriptCacheFile)) return; CScripter * pScripter = new CScripter(); pScripter->associate(this); if(pScripter->createScriptFromFile(m_szScriptCacheFile)) { char szOutput[128]; char szExecutingScript[] = "Executing script..."; strcpy(szOutput, szExecutingScript); NPN_Status(m_pNPInstance, szOutput); int iRepetitions = pScripter->getCycleRepetitions(); int iDelay = pScripter->getCycleDelay(); if(iDelay < 0) iDelay = 0; assert(pLogger != NULL); pLogger->resetStartTime(); pLogger->setLogToFileFlag(TRUE); pLogger->blockDumpToFile(FALSE); for(int i = 0; i < iRepetitions; i++) { wsprintf(szOutput, "%s %i", szExecutingScript, i); NPN_Status(m_pNPInstance, szOutput); pScripter->executeScript(); if(iDelay != 0) XP_Sleep(iDelay); } } else NPN_Status(m_pNPInstance, "Cannot create script..."); pLogger->setLogToFileFlag(FALSE); delete pScripter; m_szScriptCacheFile[0] = '\0'; NPN_Status(m_pNPInstance, "Script execution complete"); } }
NPError NPP_DestroyStream( NPP instance, NPStream *stream, NPError reason ) { BlenderPluginInstance* This = NULL; log_entry("NPP_DestroyStream"); if (instance == NULL) return NPERR_INVALID_INSTANCE_ERROR; This = (BlenderPluginInstance*) instance->pdata; if (This) { if (reason != NPRES_DONE) { if (stream == This->main_file_stream) { // stream destroyed by NPP_Destroy NPN_Status(instance, "Cannot read animation file"); //main_file_failed(This->application); } } return NPERR_NO_ERROR; } else { return NPERR_INVALID_INSTANCE_ERROR; } }
static int ShowStatus(jint id, char* status) { PluginInstance* inst; inst = GetInstance(id); if (!inst) return JNI_FALSE; NPN_Status(inst->m_peer, status); return JNI_TRUE; }
NS_METHOD CPluginInstancePeer::ShowStatus(const char* message) { assert( message != NULL ); NPN_Status(npp, message); return NS_OK; }
void CPlugin::SetStatus(const CString& text) { if (m_pNPInstance) { char* message = CStringToNPStringCharacters(text); NPN_Status(m_pNPInstance, message); NPN_MemFree(message); } }
void pdfmoz_warn(pdfmoz_t *moz, const char *fmt, ...) { char buf[1024]; va_list ap; va_start(ap, fmt); vsprintf(buf, fmt, ap); va_end(ap); strcpy(moz->error, buf); InvalidateRect(moz->hwnd, NULL, FALSE); NPN_Status(moz->inst, moz->error); }
LRESULT CIEDlg::OnUpdateStatus(WPARAM wp, LPARAM lp) { if (m_PluginInst) { UINT len = m_StatusText.GetLength() + 1; UINT ulen = MultiByteToWideChar( CP_ACP, 0, LPCTSTR(m_StatusText), len, NULL, 0 ); WCHAR* utext = new WCHAR[ ulen ]; if( utext ) { ulen = MultiByteToWideChar( CP_ACP, 0, LPCTSTR(m_StatusText), len, utext, ulen ); len = WideCharToMultiByte( CP_UTF8, 0, utext, ulen, NULL, 0, NULL, NULL ); char* u8text = new char[ len ]; WideCharToMultiByte( CP_UTF8, 0, utext, ulen, u8text, len, NULL, NULL ); NPN_Status( m_PluginInst->getInstance(), u8text ); delete []u8text; delete []utext; return 0; } else NPN_Status( m_PluginInst->getInstance(), "" ); } return LRESULT(0); }
NPError NPP_New( NPMIMEType pluginType, NPP instance, uint16 mode, int16 argc, char * argn[], char * argv[], NPSavedData * saved ) { NPError status; #if 1 log_function(); #endif if (instance == 0) { log_debug("NPERR_INVALID_INSTANCE_ERROR"); return NPERR_INVALID_INSTANCE_ERROR; } g_instance = instance; little_shoot_plugin * plugin = new little_shoot_plugin(instance, mode); if (0 == plugin) { log_debug("NPERR_OUT_OF_MEMORY_ERROR"); return NPERR_OUT_OF_MEMORY_ERROR; } status = plugin->init( argc, const_cast<const char **> (argn), const_cast<const char **> (argv) ); if (NPERR_NO_ERROR == status) { log_debug("NPERR_NO_ERROR"); instance->pdata = reinterpret_cast<void *>(plugin); NPN_Status(instance, "LittleShoot P2P Plugin loaded."); #if 0 NPN_SetValue(instance, NPPVpluginWindowBool, (void *)false); NPN_SetValue(instance, NPPVpluginTransparentBool, (void *)false); #endif } else { delete plugin; } return status; }
void CPlugin::SetStatus(const CString& text) { if (ShouldShowStatusOurselves()) { FireEvent(_T("IEStatusChanged"), text); return; } if (m_pNPInstance) { char* message = CStringToNPStringCharacters(text); NPN_Status(m_pNPInstance, message); NPN_MemFree(message); } }
/*! Sets the status message in the browser containing this instance. See also: <a href=http://developer.netscape.com/library/documentation/communicator/plugin/refpgve.htm#npnstatus> Netscape: NPN_Status method</a> */ void QNPInstance::status(const char* msg) { NPN_Status(pi->npp, msg); }
void pdfmoz_error(pdfmoz_t *moz, fz_error error) { fz_catch(error, "unhandled error"); InvalidateRect(moz->hwnd, NULL, FALSE); NPN_Status(moz->inst, "mupdf error"); }
LRESULT CALLBACK MozWinProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { pdfmoz_t *moz = (pdfmoz_t*) GetWindowLongPtr(hwnd, GWLP_USERDATA); char buf[256]; int x = (signed short) LOWORD(lParam); int y = (signed short) HIWORD(lParam); int i, h; SCROLLINFO si; PAINTSTRUCT ps; HDC hdc; RECT rc; RECT pad; WORD sendmsg; float zoom; GetClientRect(hwnd, &rc); h = rc.bottom - rc.top; if (strlen(moz->error)) { if (msg == WM_PAINT) { hdc = BeginPaint(hwnd, &ps); FillRect(hdc, &rc, GetStockBrush(WHITE_BRUSH)); rc.top += 10; rc.bottom -= 10; rc.left += 10; rc.right -= 10; DrawText(hdc, moz->error, strlen(moz->error), &rc, 0); // DT_SINGLELINE|DT_CENTER|DT_VCENTER); EndPaint(hwnd, &ps); } if (msg == WM_MOUSEMOVE) { SetCursor(moz->arrow); } return 0; } switch (msg) { case WM_PAINT: GetClientRect(moz->hwnd, &rc); si.cbSize = sizeof(si); si.fMask = SIF_ALL; GetScrollInfo(hwnd, SB_VERT, &si); decodescroll(moz, si.nPos); /* evict out-of-range images and pages */ for (i = 0; i < moz->pagecount; i++) { if (i < moz->scrollpage - 2 || i > moz->scrollpage + 6) { if (moz->pages[i].page) { pdf_droppage(moz->pages[i].page); moz->pages[i].page = nil; } } if (i < moz->scrollpage - 1 || i > moz->scrollpage + 3) { if (moz->pages[i].image) { fz_droppixmap(moz->pages[i].image); moz->pages[i].image = nil; } } } i = moz->scrollpage; pdfmoz_loadpage(moz, i); if (moz->error[0]) return 0; pdfmoz_drawpage(moz, i); if (moz->error[0]) return 0; y = -moz->scrollyofs; while (y < h && i < moz->pagecount) { pdfmoz_loadpage(moz, i); if (moz->error[0]) return 0; pdfmoz_drawpage(moz, i); if (moz->error[0]) return 0; y += moz->pages[i].image->h; i ++; } hdc = BeginPaint(hwnd, &ps); pad.left = rc.left; pad.right = rc.right; i = moz->scrollpage; y = -moz->scrollyofs; while (y < h && i < moz->pagecount) { drawimage(hdc, moz, moz->pages[i].image, y); y += moz->pages[i].image->h; i ++; pad.top = y; pad.bottom = y + PAD; FillRect(hdc, &pad, moz->graybrush); y += PAD; } if (y < h) { pad.top = y; pad.bottom = h; FillRect(hdc, &pad, moz->graybrush); } EndPaint(hwnd, &ps); return 0; case WM_SIZE: ShowScrollBar(moz->hwnd, SB_VERT, TRUE); GetClientRect(moz->hwnd, &rc); si.cbSize = sizeof(si); si.fMask = SIF_POS | SIF_RANGE | SIF_PAGE; si.nPos = 0; si.nMin = 0; si.nMax = 0; // si.nPage = MAX(30, rc.bottom - rc.top - 30); si.nPage = rc.bottom - rc.top; for (i = 0; i < moz->pagecount; i++) { zoom = (rc.right - rc.left) / (float) moz->pages[i].w; moz->pages[i].px = zoom * moz->pages[i].h + PAD; if (moz->scrollpage == i) { si.nPos = si.nMax; if (moz->pages[i].image) { si.nPos += moz->pages[i].px * moz->scrollyofs / moz->pages[i].image->h + 1; } } if (moz->pages[i].image) { fz_droppixmap(moz->pages[i].image); moz->pages[i].image = nil; } si.nMax += moz->pages[i].px; } si.nMax --; SetScrollInfo(moz->hwnd, SB_VERT, &si, TRUE); break; case WM_MOUSEMOVE: pdfmoz_onmouse(moz, x, y, 0); break; case WM_LBUTTONDOWN: SetFocus(hwnd); pdfmoz_onmouse(moz, x, y, 1); break; case WM_VSCROLL: si.cbSize = sizeof(si); si.fMask = SIF_ALL; GetScrollInfo(hwnd, SB_VERT, &si); switch (LOWORD(wParam)) { case SB_BOTTOM: si.nPos = si.nMax; break; case SB_TOP: si.nPos = 0; break; case SB_LINEUP: si.nPos -= 50; break; case SB_LINEDOWN: si.nPos += 50; break; case SB_PAGEUP: si.nPos -= si.nPage; break; case SB_PAGEDOWN: si.nPos += si.nPage; break; case SB_THUMBTRACK: si.nPos = si.nTrackPos; break; case SB_THUMBPOSITION: si.nPos = si.nTrackPos; break; } si.fMask = SIF_POS; si.nPos = MAX(0, MIN(si.nPos, si.nMax)); SetScrollInfo(hwnd, SB_VERT, &si, TRUE); InvalidateRect(moz->hwnd, NULL, FALSE); decodescroll(moz, si.nPos); sprintf(buf, "Page %d of %d", moz->scrollpage + 1, moz->pagecount); NPN_Status(moz->inst, buf); return 0; case WM_MOUSEWHEEL: if ((signed short)HIWORD(wParam) > 0) SendMessage(hwnd, WM_VSCROLL, MAKELONG(SB_LINEUP, 0), 0); else SendMessage(hwnd, WM_VSCROLL, MAKELONG(SB_LINEDOWN, 0), 0); break; case WM_KEYDOWN: sendmsg = 0xFFFF; switch (wParam) { case VK_UP: sendmsg = SB_LINEUP; break; case VK_PRIOR: sendmsg = SB_PAGEUP; break; case ' ': case VK_NEXT: sendmsg = SB_PAGEDOWN; break; case '\r': case VK_DOWN: sendmsg = SB_LINEDOWN; break; case VK_HOME: sendmsg = SB_TOP; break; case VK_END: sendmsg = SB_BOTTOM; break; } if (sendmsg != 0xFFFF) SendMessage(hwnd, WM_VSCROLL, MAKELONG(sendmsg, 0), 0); /* ick! someone eats events instead of bubbling... not my fault! */ break; default: break; } return moz->winproc(hwnd, msg, wParam, lParam); }
void pdfmoz_onmouse(pdfmoz_t *moz, int x, int y, int click) { char buf[512]; pdf_link *link; fz_matrix ctm; fz_point p; int pi; int py; if (!moz->pages) return; pi = moz->scrollpage; py = -moz->scrollyofs; while (pi < moz->pagecount) { if (!moz->pages[pi].image) return; if (y > py && y < moz->pages[pi].px) break; py += moz->pages[pi].px; pi ++; } if (pi == moz->pagecount) return; p.x = x + moz->pages[pi].image->x; p.y = y + moz->pages[pi].image->y - py; ctm = pdfmoz_pagectm(moz, pi); ctm = fz_invertmatrix(ctm); p = fz_transformpoint(ctm, p); for (link = moz->pages[pi].page->links; link; link = link->next) { if (p.x >= link->rect.x0 && p.x <= link->rect.x1) if (p.y >= link->rect.y0 && p.y <= link->rect.y1) break; } if (link) { SetCursor(moz->hand); if (click) { if (link->kind == PDF_LURI) pdfmoz_gotouri(moz, link->dest); else if (link->kind == PDF_LGOTO) pdfmoz_gotopage(moz, link->dest); return; } else { if (fz_isstring(link->dest)) { memcpy(buf, fz_tostrbuf(link->dest), fz_tostrlen(link->dest)); buf[fz_tostrlen(link->dest)] = 0; NPN_Status(moz->inst, buf); } else if (fz_isindirect(link->dest)) { sprintf(buf, "Go to page %d", pdfmoz_getpagenum(moz, link->dest) + 1); NPN_Status(moz->inst, buf); } else NPN_Status(moz->inst, "Say what?"); } } else { sprintf(buf, "Page %d of %d", moz->scrollpage + 1, moz->pagecount); NPN_Status(moz->inst, buf); SetCursor(moz->arrow); } }
int QtSignalForwarder::qt_metacall(QMetaObject::Call call, int index, void **args) { // no support for QObject method/properties etc! if (!This || !This->npp || call != QMetaObject::InvokeMetaMethod || !This->qt.object) return index; switch (index) { case -1: { QString msg = *(QString*)args[1]; NPN_Status(This->npp, msg.toLocal8Bit().constData()); } break; default: { QObject *qobject = This->qt.object; if (!domNode) NPN_GetValue(This->npp, NPNVPluginElementNPObject, &domNode); if (!domNode) break; const QMetaObject *metaObject = qobject->metaObject(); if (index < metaOffset(metaObject, MetaMethod)) break; const QMetaMethod method = metaObject->method(index); Q_ASSERT(method.methodType() == QMetaMethod::Signal); QByteArray signalSignature = method.signature(); QByteArray scriptFunction = signalSignature.left(signalSignature.indexOf('(')); NPIdentifier id = NPN_GetStringIdentifier(scriptFunction.constData()); if (NPN_HasMethod(This->npp, domNode, id)) { QList<QByteArray> parameterTypes = method.parameterTypes(); QVector<NPVariant> parameters; NPVariant result; bool error = false; for (int p = 0; p < parameterTypes.count(); ++p) { QVariant::Type type = QVariant::nameToType(parameterTypes.at(p)); if (type == QVariant::Invalid) { NPN_SetException(domNode, QByteArray("Unsupported parameter type in ") + scriptFunction); error = true; break; } QVariant qvar(type, args[p + 1]); NPVariant npvar = NPVariant::fromQVariant(This, qvar); if (npvar.type == NPVariant::Null || npvar.type == NPVariant::Void) { NPN_SetException(domNode, QByteArray("Unsupported parameter value in ") + scriptFunction); error =true; break; } parameters += npvar; } if (error) break; NPError nperror = NPN_Invoke(This->npp, domNode, id, parameters.constData(), parameters.count(), &result); if (nperror != NPERR_NO_ERROR && false) { // disabled, as NPN_Invoke seems to always return GENERICERROR NPN_SetException(domNode, QByteArray("Error invoking event handler ") + scriptFunction); } // ### TODO: update return value (args[0]) (out-parameters not supported anyway) NPN_ReleaseVariantValue(&result); } } break; } return index; }
void CJavaInstanceCB::showStatus(char * mess) { NPN_Status(m_npp,mess); }
DWORD CPluginBase::makeNPNCall(NPAPI_Action action, DWORD dw1, DWORD dw2, DWORD dw3, DWORD dw4, DWORD dw5, DWORD dw6, DWORD dw7) { DWORD dwRet = 0L; DWORD dwTickEnter = XP_GetTickCount(); switch (action) { case action_invalid: assert(0); break; case action_npn_version: { static int iP_maj = 0; static int iP_min = 0; static int iN_maj = 0; static int iN_min = 0; if(dw1 == DEFAULT_DWARG_VALUE) dw1 = (DWORD)&iP_maj; if(dw2 == DEFAULT_DWARG_VALUE) dw2 = (DWORD)&iP_min; if(dw3 == DEFAULT_DWARG_VALUE) dw3 = (DWORD)&iN_maj; if(dw4 == DEFAULT_DWARG_VALUE) dw4 = (DWORD)&iN_min; NPN_Version((int *)dw1, (int *)dw2, (int *)dw3, (int *)dw4); break; } case action_npn_get_url_notify: if(dw1 == DEFAULT_DWARG_VALUE) dw1 = (DWORD)m_pNPInstance; dwRet = NPN_GetURLNotify((NPP)dw1, (char *)dw2, (char *)dw3, (void *)dw4); break; case action_npn_get_url: if(dw1 == DEFAULT_DWARG_VALUE) dw1 = (DWORD)m_pNPInstance; dwRet = NPN_GetURL((NPP)dw1, (char *)dw2, (char *)dw3); break; case action_npn_post_url_notify: if(dw1 == DEFAULT_DWARG_VALUE) dw1 = (DWORD)m_pNPInstance; dwRet = NPN_PostURLNotify((NPP)dw1, (char *)dw2, (char *)dw3, (int32)dw4, (char *)dw5, (BOOL)dw6, (void *)dw7); break; case action_npn_post_url: if(dw1 == DEFAULT_DWARG_VALUE) dw1 = (DWORD)m_pNPInstance; dwRet = NPN_PostURL((NPP)dw1, (char *)dw2, (char *)dw3, (int32)dw4, (char *)dw5, (BOOL)dw6); break; case action_npn_new_stream: assert(m_pStream == NULL); if(dw1 == DEFAULT_DWARG_VALUE) dw1 = (DWORD)m_pNPInstance; if(dw4 == DEFAULT_DWARG_VALUE) dw4 = (DWORD)&m_pStream; dwRet = NPN_NewStream((NPP)dw1, (char *)dw2, (char *)dw3, (NPStream **)dw4); break; case action_npn_destroy_stream: assert(m_pStream != NULL); if(dw1 == DEFAULT_DWARG_VALUE) dw1 = (DWORD)m_pNPInstance; if(dw2 == DEFAULT_DWARG_VALUE) dw2 = (DWORD)m_pStream; dwRet = NPN_DestroyStream((NPP)dw1, (NPStream *)dw2, (NPError)dw3); m_pStream = NULL; break; case action_npn_request_read: break; case action_npn_write: if(dw1 == DEFAULT_DWARG_VALUE) dw1 = (DWORD)m_pNPInstance; if(dw2 == DEFAULT_DWARG_VALUE) dw2 = (DWORD)m_pStream; dwRet = NPN_Write((NPP)dw1, (NPStream *)dw2, (int32)dw3, (void *)dw4); break; case action_npn_status: if(dw1 == DEFAULT_DWARG_VALUE) dw1 = (DWORD)m_pNPInstance; NPN_Status((NPP)dw1, (char *)dw2); break; case action_npn_user_agent: if(dw1 == DEFAULT_DWARG_VALUE) dw1 = (DWORD)m_pNPInstance; dwRet = (DWORD)NPN_UserAgent((NPP)dw1); break; case action_npn_mem_alloc: assert(m_pNPNAlloced == NULL); m_pNPNAlloced = NPN_MemAlloc((int32)dw1); dwRet = (DWORD)m_pNPNAlloced; if(m_pNPNAlloced != NULL) { for(int i = 0; i < (int)dw1; i++) *(((BYTE *)m_pNPNAlloced) + i) = 255; } break; case action_npn_mem_free: assert(m_pNPNAlloced != NULL); dw1 = (DWORD)m_pNPNAlloced; NPN_MemFree((void *)dw1); m_pNPNAlloced = NULL; break; case action_npn_mem_flush: dwRet = (DWORD)NPN_MemFlush((int32)dw1); break; case action_npn_reload_plugins: NPN_ReloadPlugins((NPBool)dw1); break; case action_npn_get_java_env: dwRet = (DWORD)NPN_GetJavaEnv(); break; case action_npn_get_java_peer: if(dw1 == DEFAULT_DWARG_VALUE) dw1 = (DWORD)m_pNPInstance; dwRet = (DWORD)NPN_GetJavaPeer((NPP)dw1); break; case action_npn_get_value: if(dw1 == DEFAULT_DWARG_VALUE) dw1 = (DWORD)m_pNPInstance; if(dw3 == DEFAULT_DWARG_VALUE) dw3 = (DWORD)m_pValue; dwRet = (DWORD)NPN_GetValue((NPP)dw1, (NPNVariable)dw2, (void *)dw3); break; case action_npn_set_value: if(dw1 == DEFAULT_DWARG_VALUE) dw1 = (DWORD)m_pNPInstance; if(dw3 == DEFAULT_DWARG_VALUE) dw3 = (DWORD)m_pValue; // note that Mozilla expects boolean values not as a pointer to BOOL // but rather as simply null and not null, let's convert if((dw2 == NPPVpluginWindowBool) || (dw2 == NPPVpluginTransparentBool) || (dw2 == NPPVpluginKeepLibraryInMemory)) { dwRet = (DWORD)NPN_SetValue((NPP)dw1, (NPPVariable)dw2, (void *)(*(BOOL *)dw3)); } else dwRet = (DWORD)NPN_SetValue((NPP)dw1, (NPPVariable)dw2, (void *)dw3); break; case action_npn_invalidate_rect: if(dw1 == DEFAULT_DWARG_VALUE) dw1 = (DWORD)m_pNPInstance; NPN_InvalidateRect((NPP)dw1, (NPRect *)dw2); break; case action_npn_invalidate_region: if(dw1 == DEFAULT_DWARG_VALUE) dw1 = (DWORD)m_pNPInstance; NPN_InvalidateRegion((NPP)dw1, (NPRegion)dw2); break; case action_npn_force_redraw: if(dw1 == DEFAULT_DWARG_VALUE) dw1 = (DWORD)m_pNPInstance; NPN_ForceRedraw((NPP)dw1); break; default: assert(0); break; } DWORD dwTickReturn = XP_GetTickCount(); pLogger->appendToLog(action, dwTickEnter, dwTickReturn, dwRet, dw1, dw2, dw3, dw4, dw5, dw6, dw7); return dwRet; }