Skip to content

Commit d80dbe7

Browse files
committed
fix security setup to make applets at least attempt to do the wrong thing
in case the applet is signed
1 parent 06223f4 commit d80dbe7

1 file changed

Lines changed: 89 additions & 84 deletions

File tree

core/src/processing/core/PApplet.java

Lines changed: 89 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -2150,15 +2150,6 @@ static public Process exec(String[] argv) {
21502150
public void die(String what) {
21512151
stop();
21522152
throw new RuntimeException(what);
2153-
/*
2154-
if (online) {
2155-
System.err.println("i'm dead.. " + what);
2156-
2157-
} else {
2158-
System.err.println(what);
2159-
System.exit(1);
2160-
}
2161-
*/
21622153
}
21632154

21642155

@@ -2179,12 +2170,6 @@ public void exit() {
21792170
if (thread == null) {
21802171
// exit immediately, stop() has already been called,
21812172
// meaning that the main thread has long since exited
2182-
//if ((leechErr == null) && !online) {
2183-
// if (!external && !online) {
2184-
// // don't want to call System.exit() when an applet,
2185-
// // or running inside the PDE (would kill the PDE)
2186-
// System.exit(0);
2187-
// }
21882173
exit2();
21892174

21902175
} else if (looping) {
@@ -2206,13 +2191,6 @@ public void exit() {
22062191

22072192

22082193
void exit2() {
2209-
//if ((leechErr == null) && !online) {
2210-
2211-
// if (!external && !online) {
2212-
// // don't want to call System.exit() when an applet,
2213-
// // or running inside the PDE (would kill the PDE)
2214-
// System.exit(0);
2215-
// }
22162194
try {
22172195
System.exit(0);
22182196
} catch (SecurityException e) {
@@ -2245,11 +2223,12 @@ public void save(String filename) {
22452223
* is specified it defaults to writing a tiff and adds a .tif suffix.
22462224
*/
22472225
public void saveFrame() {
2248-
if (online) {
2249-
System.err.println("Can't use saveFrame() when running in a browser.");
2250-
return;
2226+
try {
2227+
g.save(savePath("screen-" + nf(frameCount, 4) + ".tif"));
2228+
} catch (SecurityException se) {
2229+
System.err.println("Can't use saveFrame() when running in a browser, " +
2230+
"unless using a signed applet.");
22512231
}
2252-
g.save(savePath("screen-" + nf(frameCount, 4) + ".tif"));
22532232
}
22542233

22552234

@@ -2264,11 +2243,12 @@ public void saveFrame() {
22642243
* // #### signs with zeros and the frame number </PRE>
22652244
*/
22662245
public void saveFrame(String what) {
2267-
if (online) {
2268-
System.err.println("Can't use saveFrame() when running in a browser.");
2269-
return;
2246+
try {
2247+
g.save(savePath(insertFrame(what)));
2248+
} catch (SecurityException se) {
2249+
System.err.println("Can't use saveFrame() when running in a browser, " +
2250+
"unless using a signed applet.");
22702251
}
2271-
g.save(savePath(insertFrame(what)));
22722252
}
22732253

22742254

@@ -3580,21 +3560,39 @@ protected void checkParentFrame() {
35803560
}
35813561

35823562

3563+
/**
3564+
* Open a platform-specific file chooser dialog to select a file for input.
3565+
* @return full path to the selected file, or null if no selection.
3566+
*/
35833567
public String selectInput() {
35843568
return selectInput("Select a file...");
35853569
}
35863570

35873571

3588-
public String selectInput(final String prompt) {
3572+
/**
3573+
* Open a platform-specific file chooser dialog to select a file for input.
3574+
* @param prompt Mesage to show the user when prompting for a file.
3575+
* @return full path to the selected file, or null if canceled.
3576+
*/
3577+
public String selectInput(String prompt) {
35893578
return selectFileImpl(prompt, FileDialog.LOAD);
35903579
}
35913580

35923581

3582+
/**
3583+
* Open a platform-specific file save dialog to select a file for output.
3584+
* @return full path to the file entered, or null if canceled.
3585+
*/
35933586
public String selectOutput() {
35943587
return selectOutput("Save as...");
35953588
}
35963589

35973590

3591+
/**
3592+
* Open a platform-specific file save dialog to select a file for output.
3593+
* @param prompt Mesage to show the user when prompting for a file.
3594+
* @return full path to the file entered, or null if canceled.
3595+
*/
35983596
public String selectOutput(String prompt) {
35993597
return selectFileImpl(prompt, FileDialog.SAVE);
36003598
}
@@ -3624,11 +3622,20 @@ public void run() {
36243622
}
36253623

36263624

3625+
/**
3626+
* Open a platform-specific folder chooser dialog.
3627+
* @return full path to the selected folder, or null if no selection.
3628+
*/
36273629
public String selectFolder() {
36283630
return selectFolder("Select a folder...");
36293631
}
36303632

36313633

3634+
/**
3635+
* Open a platform-specific folder chooser dialog.
3636+
* @param prompt Mesage to show the user when prompting for a file.
3637+
* @return full path to the selected folder, or null if no selection.
3638+
*/
36323639
public String selectFolder(final String prompt) {
36333640
checkParentFrame();
36343641

@@ -3875,46 +3882,45 @@ public InputStream createInputRaw(String filename) {
38753882
// Moved this earlier than the getResourceAsStream() checks, because
38763883
// calling getResourceAsStream() on a directory lists its contents.
38773884
// http://dev.processing.org/bugs/show_bug.cgi?id=716
3878-
if (!online) {
3879-
try {
3880-
// first see if it's in a data folder
3881-
File file = new File(dataPath(filename));
3882-
if (!file.exists()) {
3883-
// next see if it's just in the sketch folder
3884-
file = new File(sketchPath, filename);
3885-
}
3886-
if (file.isDirectory()) {
3887-
return null;
3888-
}
3889-
if (file.exists()) {
3890-
try {
3891-
// handle case sensitivity check
3892-
String filePath = file.getCanonicalPath();
3893-
String filenameActual = new File(filePath).getName();
3894-
// make sure there isn't a subfolder prepended to the name
3895-
String filenameShort = new File(filename).getName();
3896-
// if the actual filename is the same, but capitalized
3897-
// differently, warn the user.
3898-
//if (filenameActual.equalsIgnoreCase(filenameShort) &&
3899-
//!filenameActual.equals(filenameShort)) {
3900-
if (!filenameActual.equals(filenameShort)) {
3901-
throw new RuntimeException("This file is named " +
3902-
filenameActual + " not " +
3903-
filename + ". Rename the file " +
3904-
"or change your code.");
3905-
}
3906-
} catch (IOException e) { }
3907-
}
3885+
try {
3886+
// First see if it's in a data folder. This may fail by throwing
3887+
// a SecurityException. If so, this whole block will be skipped.
3888+
File file = new File(dataPath(filename));
3889+
if (!file.exists()) {
3890+
// next see if it's just in the sketch folder
3891+
file = new File(sketchPath, filename);
3892+
}
3893+
if (file.isDirectory()) {
3894+
return null;
3895+
}
3896+
if (file.exists()) {
3897+
try {
3898+
// handle case sensitivity check
3899+
String filePath = file.getCanonicalPath();
3900+
String filenameActual = new File(filePath).getName();
3901+
// make sure there isn't a subfolder prepended to the name
3902+
String filenameShort = new File(filename).getName();
3903+
// if the actual filename is the same, but capitalized
3904+
// differently, warn the user.
3905+
//if (filenameActual.equalsIgnoreCase(filenameShort) &&
3906+
//!filenameActual.equals(filenameShort)) {
3907+
if (!filenameActual.equals(filenameShort)) {
3908+
throw new RuntimeException("This file is named " +
3909+
filenameActual + " not " +
3910+
filename + ". Rename the file " +
3911+
"or change your code.");
3912+
}
3913+
} catch (IOException e) { }
3914+
}
39083915

3909-
// if this file is ok, may as well just load it
3910-
stream = new FileInputStream(file);
3911-
if (stream != null) return stream;
3916+
// if this file is ok, may as well just load it
3917+
stream = new FileInputStream(file);
3918+
if (stream != null) return stream;
39123919

3913-
// have to break these out because a general Exception might
3914-
// catch the RuntimeException being thrown above
3915-
} catch (IOException ioe) {
3916-
} catch (SecurityException se) { }
3917-
}
3920+
// have to break these out because a general Exception might
3921+
// catch the RuntimeException being thrown above
3922+
} catch (IOException ioe) {
3923+
} catch (SecurityException se) { }
39183924

39193925
// Using getClassLoader() prevents java from converting dots
39203926
// to slashes or requiring a slash at the beginning.
@@ -4296,9 +4302,10 @@ static public void saveStrings(OutputStream output, String strings[]) {
42964302
*/
42974303
public String sketchPath(String where) {
42984304
if (sketchPath == null) {
4299-
throw new RuntimeException("The applet was not inited properly, " +
4300-
"or security restrictions prevented " +
4301-
"it from determining its path.");
4305+
return where;
4306+
// throw new RuntimeException("The applet was not inited properly, " +
4307+
// "or security restrictions prevented " +
4308+
// "it from determining its path.");
43024309
}
43034310
// isAbsolute() could throw an access exception, but so will writing
43044311
// to the local disk using the sketch path, so this is safe here.
@@ -4377,12 +4384,16 @@ public File dataFile(String where) {
43774384
* already exist. Useful when trying to save to a subfolder that
43784385
* may not actually exist.
43794386
*/
4380-
static public void createPath(String filename) {
4381-
File file = new File(filename);
4382-
String parent = file.getParent();
4383-
if (parent != null) {
4384-
File unit = new File(parent);
4385-
if (!unit.exists()) unit.mkdirs();
4387+
static public void createPath(String path) {
4388+
try {
4389+
File file = new File(path);
4390+
String parent = file.getParent();
4391+
if (parent != null) {
4392+
File unit = new File(parent);
4393+
if (!unit.exists()) unit.mkdirs();
4394+
}
4395+
} catch (SecurityException se) {
4396+
System.err.println("You don't have permissions to create " + path);
43864397
}
43874398
}
43884399

@@ -6635,12 +6646,6 @@ public void hint(int which) {
66356646
}
66366647

66376648

6638-
public void unhint(int which) {
6639-
if (recorder != null) recorder.unhint(which);
6640-
g.unhint(which);
6641-
}
6642-
6643-
66446649
public void beginShape() {
66456650
if (recorder != null) recorder.beginShape();
66466651
g.beginShape();

0 commit comments

Comments
 (0)