Hmm, so I went and tried to make a test case and it's fussy. I actually see two related bugs here:
1. If the global variable is first accessed from a trusted function, or from an unsaved new document (no filename associated with it), then it doesn't need a trusted function in future.
2. If the global variable is first accessed (without a trusted function) from a saved file, then that filename is associated with it, and you can't even access it from a trusted function.
Case 1
Make two new documents, and DO NOT save them.
Document 1 button mouseup event:
Code: Select all
console.println(global["testVariable"]);
global["testVariable"]="hello world";
global.setPersistent( "testVariable", true);
Document 2 button mouseup event:
Code: Select all
console.println(global["testVariable"]);
global["testVariable"]="goodbye cruel world";
global.setPersistent( "testVariable", true);
You'll be able to access the global variable in both (open the JS console to see output). Now save them. Quit and restart just to be sure. Now load both those documents, and you'll still be able to access from both.
Note that in GlobData, the variable is saved as if it were set up by a trusted function:
/testVariable <<
/V (goodbye cruel world)
>>
Case 2
Edit GlobData to remove the lines above, and save before starting PDFXChange.
First: Open PDFXChange and with no document active, run this to make a trusted function, and set up a toolbar button. Don't click yet.
Code: Select all
// run in the console
var TEST_GLOBAL_VALS = new class {
constructor(name) {
this.get = app.trustedFunction(() => {
app.beginPriv();
return global[name];
});
this.set = app.trustedFunction( value => {
app.beginPriv();
global[name] = value;
global.setPersistent( name, true);
});
}
}("testVariable")
app.addToolButton( {
cName: "testGlobalButton",
cLabel: "Test",
cExec: "app.alert(TEST_GLOBAL_VALS.get())" }
)
Open both the above saved files, and try clicking the buttons in the documents. Only one document can reach it.
Now try clicking the toolbar button. The toolbar button (using the trusted function) will only be able to access the global variable from the document where it was first accessed, even though we have a trusted function with elevated privilege.
Case 1b
This actually follows from case 1. You can use the trusted function above to test it by first deleting the variable from GlobData, then running
. Both documents will be able to access it.