작성자: [hyacinth] 작성일: [[Date(2013-04-01T05:38:07)]] [[TableOfContents]] == 들어가며 == NPAPI과 NPRuntime에 대해 알고 싶으면 여기[[Footnote(http://theweak.tistory.com/1)]][[Footnote(http://breakstone.blog.qrobo.com/2009/05/28/npruntime-0-compile/)]] 등을 참조하면 된다. 요약하면 옛날 넷스케이프 시절 개발되던 플러그인 API가 이후 모질라 계열 브라우저에서 계속 남아있어서 파이어폭스, 크롬, 사파리, 오페라에서 지원하게 되었고 따라서 NPAPI 플러그인을 만들면 '''IE를 제외한 대부분의 브라우저에서''' 돌아가게 된 것이다. NPRuntime은 플러그인에서 웹브라우저로 명령을 전달해 줄 수 있는 NPAPI의 확장버전이다. 즉 NPAPI+추가API의 형태다. 이 페이지에서는 2013년 4월 1일 현재 최신 Gecko SDK[[Footnote(XULRunner SDK로도 알려져 있다.)]](19.0.2)와 최신 비주얼 스튜디오(VS2008/2010/2012)를 사용한 NPAPI Hello world 를 만드는 방법을 소개한다. Gecko SDK 1.9 부터 프로젝트 구성 방법과 헤더와 타입이 많이 바뀌었기 때문에 1.9 버전 예제들은 변경이 필요하다. 이에 대한 자세한 방법을 소개한다. 레퍼런스 사이트 https://developer.mozilla.org/en-US/docs/Plugins == Gecko SDK 빌드 환경 구성 == === 다운로드 === https://developer.mozilla.org/en-US/docs/Gecko_SDK 1. Get SDK for Windows 2. 특정 디렉토리에 압축을 해제한다. 3. 압축을 해제한 곳으로 VC++ 포함 파일 디렉터리를 설정한다. {{{ \xulrunner-sdk\include }}} == NPAPI 프로젝트 만들기 == === Hello World 프로젝트 === || attachment:nphelloplugin_vs2008.zip || [GitHub:rhealovekr/np-hello-plugin] === 빈 프로젝트 생성 === Win32 프로젝트 > 응용 프로그램 종류 DLL > 빈 프로젝트 === 파일 추가 === 모듈 정의 파일 (.def) 리소스 파일 (.rc) Sources np_entry.cpp npn_gate.cpp npp_gate.cpp plugin.cpp Header plugin.h === 코드 추가 === npHelloPlugin.def {{{#!gcode LIBRARY "npHelloPlugin" EXPORTS NP_GetEntryPoints @1 NP_Initialize @2 NP_Shutdown @3 }}} npHelloPlugin.rc {{{#!gcode ... BEGIN BLOCK "StringFileInfo" BEGIN BLOCK "040904e4" BEGIN ... VALUE "MIMEType", "application/hello-plugin" // npHelloPlugin.rc를 코드 보기로 열어 추가 ... }}} np_entry.cpp 예제 프로젝트 참조 npn_gate.cpp 예제 프로젝트 참조 npp_gate.cpp 예제 프로젝트 참조 plugin.cpp 예제 프로젝트 참조 plugin.h 예제 프로젝트 참조 === 프로젝트 속성 === C/C++ {{{ 추가 포함 디렉터리 "D:\...\xulrunner-sdk\include" 전처리기 _X86_ 추가 }}} === 빌드 === === 조건 === 1. 플러그인 dll '''파일 이름'''이 '''반드시''' np로 시작해야 한다. 2. 리소스(.rc)의 빌드 언어 설정이 영어(미국)이여야만 한다. (한글이라면 크롬에서는 플러그인으로 인식하지만 파이어폭스에서는 플러그인을 찾을 수 없다.) == NPAPI 프로젝트 만들기 (2) == === 메서드 추가 === TestMethod1 라는 메서드를 만들어 보자. 1. plugin.cpp 식별자 추가 {{{#!gcode static NPIdentifier sfuncTestMethod1_id; CPlugin::CPlugin(NPP pNPInstance) : m_pNPInstance(pNPInstance), m_pNPStream(NULL), m_bInitialized(FALSE), m_pScriptableObject(NULL) { ... sfuncTestMethod1_id = NPN_GetStringIdentifier("TestMethod1"); ... } }}} bool HasMethod() {{{#!gcode bool ScriptablePluginObject::HasMethod(NPIdentifier name) { return (name == sFoo_id)|| (name == sfuncTestMethod1_id); // ... 식별자 추가 } }}} bool Invoke() {{{#!gcode bool ScriptablePluginObject::Invoke(NPIdentifier name, const NPVariant *args, uint32_t argCount, NPVariant *result) { if (name == sfuncTestMethod1_id) { // 메서드 동작 구현 및 예 char buffer[] = "sfuncTestMethod1_id called"; uint32_t len = strlen(buffer) + 1; char *copy = (char*)NPN_MemAlloc(len); strncpy(copy, buffer, len); STRINGZ_TO_NPVARIANT(copy, *result); return PR_TRUE; } return PR_FALSE; } }}} * NPAPI 플러그인에서 메모리 할당은 반드시 NPN_MemAlloc을 써야한다. == 플러그인을 웹 페이지에 추가 == {{{#!gcode
}}} ---- CategoryDocument