Skip to content

Commit

Permalink
changed NPVariantRefs over to JSValueRefs. Officially no longer pursu…
Browse files Browse the repository at this point in the history
…ing compatability with old RFirefox extension
  • Loading branch information
gmbecker committed Jan 16, 2013
1 parent 126e983 commit 05f5261
Show file tree
Hide file tree
Showing 8 changed files with 255 additions and 55 deletions.
3 changes: 2 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ useDynLib(RBrowserPlugin)

#exportClasses("JavaScriptRef")
#exportClasses("nsIDocument", "nsINode")
exportClasses("NPObjectRef", "NPVariantRef", "NPNFunctionsRef", "PluginInstance")
#exportClasses("NPObjectRef", "NPVariantRef", "NPNFunctionsRef", "PluginInstance")
exportClasses("JSValueRef", "NPNFunctionsRef", "PluginInstance")
exportPattern(".*")

exportMethods("coerce")
Expand Down
2 changes: 2 additions & 0 deletions R/NPAPI.R
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ getConvEnum = function(x, several.ok = FALSE)
{
if(!length(x))
x = "default"
nas = which(is.na(x))
x[nas] = "default"
if(is.character(x))
{
x = match.arg(x, c("default", "reference", "copy", "custom"), several.ok = several.ok)
Expand Down
48 changes: 8 additions & 40 deletions R/classes.R
Original file line number Diff line number Diff line change
@@ -1,47 +1,14 @@
if(FALSE)
{
setClass("RC++NativeReference", representation(ref = "externalptr"))

setClass("nsPIDOMWindow", contains = "RC++NativeReference")

setClass("JavaScriptRef", contains = "RC++NativeReference")

setClass("nsINode", contains = "JavaScriptRef")
setClass("nsIDocument", contains = "nsINode")

setAs("JavaScriptRef", "nsIDocument",
function(from)
nsIDocument(from))

setClass("XPCOMInterfaceInfo",
representation(name = "character",
parent = "character",
iid = "character", #XXX use class from Ruuid package.
methods = "list",
constants = "list",
isScriptable = "logical",
isFunction = "logical"))

setClass("XPTConstant",
representation(name = "character",
type = "ANY",
value = "ANY"
))

#added by Gabe
setClass("nsIWebBrowser", contains = "RC++NativeReference")
setClass("nsIScriptContext", contains = "RC++NativeReference")
setClass("MozGtkBrowser", contains = "RC++NativeReference")
setClass("JSContextRef", contains = "RC++NativeReference")

}


setClass("JSValueRef", contains = "RCReference")
setClass("PluginInstance", representation=representation(funcs = "NPNFunctionsRef"), contains="RCStructReference")
setClass("NPNFunctionsRef", contains = "RCStructReference")
if(FALSE)
{
setClass("NPObjectRef", contains = "RCStructReference")
setClass("NPVariantRef", contains = "RCReference")
setClass("NPDOMWindowRef", contains = "NPVariantRef")
setClass("NPNFunctionsRef", contains = "RCStructReference")
setClass("PluginInstance", representation=representation(funcs = "NPNFunctionsRef"), contains="RCStructReference")



setClass('JSObjectRef', contains = "RCStructReference")
setClass('jsvalRef', contains = "RCStructReference")
Expand All @@ -66,3 +33,4 @@ setAs("jsvalRef", "JSValueRef",
#XXX this doesn't appear to be working...
setIs("JSValueRef", "NPVariantRef")
setIs( "JSValueRef", "jsvalRef")
}
237 changes: 233 additions & 4 deletions R/unified.R
Original file line number Diff line number Diff line change
Expand Up @@ -144,20 +144,20 @@ setMethod("names", "JSValueRef", function(x)

#Name of arguments???
#setMethod("[[", "JSValueRef", function(x, i, ...)
setMethod("[[", c("NPVariantRef", "character", "missing"), function(x, i, ...)
setMethod("[[", c("JSValueRef", "character", "missing"), function(x, i, ...)
{
jsProperty(x, i, ...)
})


setMethod("[[<-", c("NPVariantRef", "character", "missing"), function(x, i, ..., value)
setMethod("[[<-", c("JSValueRef", "character", "missing"), function(x, i, ..., value)
{
jsProperty(x, i, ...) <- value
})

#setGeneric("$", function(x, name, ...) standardGeneric("$"))
#setMethod("$", "JSValueRef",
setMethod("$", "NPVariantRef",
setMethod("$", "JSValueRef",
function(x, name)
{

Expand Down Expand Up @@ -187,7 +187,236 @@ setMethod("newJSObject", "character",
newJSObject(obj, ...)
})

setMethod("newJSObject", "NPVariantRef",
setMethod("newJSObject", "JSValueRef",
function(obj, ...)
{
paramlist = c(obj, list(...))
fun = switch(length(paramlist),
JS$create0,
JS$create1,
JS$create2,
JS$create3,
JS$create4,
default=stop("Creation of JS objects whose constructors require more than 4 arguments via newJSObject is not currently supported."))
do.call(fun, paramlist)
})


setMethod("[[", c("JSValueRef", "character", "missing"), function(x, i, ...)
{
jsProperty(x, i, ...)
})


setMethod("[[<-", c("JSValueRef", "character", "missing"), function(x, i, ..., value)
{
jsProperty(x, i, ...) <- value
})

#setGeneric("$", function(x, name, ...) standardGeneric("$"))
#setMethod("$", "JSValueRef",
setMethod("$", "JSValueRef",
function(x, name)
{

#fun = function( ..., keepResult = TRUE, returnRef = FALSE, convertArgs)
fun = function( ..., keepResult = TRUE, convertRet = "default", convertArgs = NULL)
{

args = list(...)
if(length(args) > 1)
multipleArgs = TRUE
else
multipleArgs = FALSE

callJavaScript(object = x,name = name, ... , multipleArgs = multipleArgs, keepResult = keepResult, convertRet = convertRet, convertArgs = convertArgs)
}
attr(fun, "NPRef") <- x[[name]]
fun
}
)

setGeneric("newJSObject", function(obj, ...) standardGeneric("newJSObject"))

setMethod("newJSObject", "character",
function(obj, ...)
{
obj = evalJavaScript(obj)
newJSObject(obj, ...)
})

setMethod("newJSObject", "JSValueRef",
function(obj, ...)
{
paramlist = c(obj, list(...))
fun = switch(length(paramlist),
JS$create0,
JS$create1,
JS$create2,
JS$create3,
JS$create4,
default=stop("Creation of JS objects whose constructors require more than 4 arguments via newJSObject is not currently supported."))
do.call(fun, paramlist)
})

setMethod("[[", c("JSValueRef", "character", "missing"), function(x, i, ...)
{
jsProperty(x, i, ...)
})


setMethod("[[<-", c("JSValueRef", "character", "missing"), function(x, i, ..., value)
{
jsProperty(x, i, ...) <- value
})

#setGeneric("$", function(x, name, ...) standardGeneric("$"))
#setMethod("$", "JSValueRef",
setMethod("$", "JSValueRef",
function(x, name)
{

#fun = function( ..., keepResult = TRUE, returnRef = FALSE, convertArgs)
fun = function( ..., keepResult = TRUE, convertRet = "default", convertArgs = NULL)
{

args = list(...)
if(length(args) > 1)
multipleArgs = TRUE
else
multipleArgs = FALSE

callJavaScript(object = x,name = name, ... , multipleArgs = multipleArgs, keepResult = keepResult, convertRet = convertRet, convertArgs = convertArgs)
}
attr(fun, "NPRef") <- x[[name]]
fun
}
)

setGeneric("newJSObject", function(obj, ...) standardGeneric("newJSObject"))

setMethod("newJSObject", "character",
function(obj, ...)
{
obj = evalJavaScript(obj)
newJSObject(obj, ...)
})

setMethod("newJSObject", "JSValueRef",
function(obj, ...)
{
paramlist = c(obj, list(...))
fun = switch(length(paramlist),
JS$create0,
JS$create1,
JS$create2,
JS$create3,
JS$create4,
default=stop("Creation of JS objects whose constructors require more than 4 arguments via newJSObject is not currently supported."))
do.call(fun, paramlist)
})

setMethod("[[", c("JSValueRef", "character", "missing"), function(x, i, ...)
{
jsProperty(x, i, ...)
})


setMethod("[[<-", c("JSValueRef", "character", "missing"), function(x, i, ..., value)
{
jsProperty(x, i, ...) <- value
})

#setGeneric("$", function(x, name, ...) standardGeneric("$"))
#setMethod("$", "JSValueRef",
setMethod("$", "JSValueRef",
function(x, name)
{

#fun = function( ..., keepResult = TRUE, returnRef = FALSE, convertArgs)
fun = function( ..., keepResult = TRUE, convertRet = "default", convertArgs = NULL)
{

args = list(...)
if(length(args) > 1)
multipleArgs = TRUE
else
multipleArgs = FALSE

callJavaScript(object = x,name = name, ... , multipleArgs = multipleArgs, keepResult = keepResult, convertRet = convertRet, convertArgs = convertArgs)
}
attr(fun, "NPRef") <- x[[name]]
fun
}
)

setGeneric("newJSObject", function(obj, ...) standardGeneric("newJSObject"))

setMethod("newJSObject", "character",
function(obj, ...)
{
obj = evalJavaScript(obj)
newJSObject(obj, ...)
})

setMethod("newJSObject", "JSValueRef",
function(obj, ...)
{
paramlist = c(obj, list(...))
fun = switch(length(paramlist),
JS$create0,
JS$create1,
JS$create2,
JS$create3,
JS$create4,
default=stop("Creation of JS objects whose constructors require more than 4 arguments via newJSObject is not currently supported."))
do.call(fun, paramlist)
})

setMethod("[[", c("JSValueRef", "character", "missing"), function(x, i, ...)
{
jsProperty(x, i, ...)
})


setMethod("[[<-", c("JSValueRef", "character", "missing"), function(x, i, ..., value)
{
jsProperty(x, i, ...) <- value
})

#setGeneric("$", function(x, name, ...) standardGeneric("$"))
#setMethod("$", "JSValueRef",
setMethod("$", "JSValueRef",
function(x, name)
{

#fun = function( ..., keepResult = TRUE, returnRef = FALSE, convertArgs)
fun = function( ..., keepResult = TRUE, convertRet = "default", convertArgs = NULL)
{

args = list(...)
if(length(args) > 1)
multipleArgs = TRUE
else
multipleArgs = FALSE

callJavaScript(object = x,name = name, ... , multipleArgs = multipleArgs, keepResult = keepResult, convertRet = convertRet, convertArgs = convertArgs)
}
attr(fun, "NPRef") <- x[[name]]
fun
}
)

setGeneric("newJSObject", function(obj, ...) standardGeneric("newJSObject"))

setMethod("newJSObject", "character",
function(obj, ...)
{
obj = evalJavaScript(obj)
newJSObject(obj, ...)
})

setMethod("newJSObject", "JSValueRef",
function(obj, ...)
{
paramlist = c(obj, list(...))
Expand Down
4 changes: 2 additions & 2 deletions R/utilities.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ getJSMethodObj = function(obj)
if(is(obj, "function"))
ret = attr(obj, "NPRef")

else if(is(obj, "NPVariantRef"))
else if(is(obj, "JSValueRef"))
ret = obj
else
stop("Unable to find a NPVariantRef associated with obj")
stop("Unable to find a JSValueRef associated with obj")
ret
}
6 changes: 3 additions & 3 deletions inst/NPAPI/NPConversions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -536,10 +536,10 @@ bool NPArrayToR(NPVariant *arr, int len, int simplify, NPP inst, NPNetscapeFuncs
SEXP MakeNPRefForR(NPVariant *ref)
{
SEXP klass, ans, Rptr;
PROTECT( klass = MAKE_CLASS( "NPVariantRef" ) );
PROTECT( klass = MAKE_CLASS( "JSValueRef" ) );
PROTECT( ans = NEW( klass ) );
PROTECT( Rptr = R_MakeExternalPtr( ref ,
Rf_install( "NPVariantRef" ),
Rf_install( "JSValueRef" ),
R_NilValue));

//XXX need to add finalizer!!
Expand Down Expand Up @@ -692,7 +692,7 @@ bool CheckSEXPForJSRef(SEXP obj, NPP inst)
SETCAR(ptr, obj);
ptr = CDR(ptr);
// SETCAR(ptr, ScalarString(mkChar("JSValueRef")));
SETCAR(ptr, ScalarString(mkChar("NPVariantRef")));
SETCAR(ptr, ScalarString(mkChar("JSValueRef")));

PROTECT(ans = rQueue.requestRCall(call, R_GlobalEnv, &err, inst));
bool ret;
Expand Down
2 changes: 1 addition & 1 deletion inst/NPAPI/WebRMutex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ void makeRGlobals(NPP inst)
*/
NPVariant *winvar = (NPVariant *) myNPNFuncs->memalloc(sizeof(NPVariant));
getWindowVariant(inst, winvar);
PROTECT( klass3 = MAKE_CLASS( "NPVariantRef" ) );
PROTECT( klass3 = MAKE_CLASS( "JSValueRef" ) );
PROTECT( ans3 = NEW( klass3 ) );
PROTECT( ptr3 = R_MakeExternalPtr( winvar,
Rf_install("DomWindow"),
Expand Down
Loading

0 comments on commit 05f5261

Please sign in to comment.