Gatekeeper and Mosaic

If you're seeing this page, you probably haven't encountered the problem discussed below, but then again, you might find this information interesting, anyway.

John Pierson Mayberry,jm6z+@andrew.cmu.edu, writes:

> The oddist thing happens when I open the gatekeeper contol panal and
> click on the word "Gatekeeper" on the middle of the window,it falshes a
> couple of times and Mosaic suddenly lanches! 
> 
> What is going on here? Has anyone else seen this, or can any of you
> replicat it?

...and...

John Young, young@fmd00.larc.nasa.gov, writes:

> No...  You are not crazy.  This happened to me also with B6 of Mosaic, if
> I remember correctly.  Within two days of this starting to happen, my
> hard disk became totally corrupted, and had to be rebuilt from scratch.
> 
> Don't know what the connection was, but it hasn't happened lately.
> (Am now running Mosaic 1.0.1)

To deal with the last issue first, there's no connection between hard disk corruption and the Mosaic feature hidden in Gatekeeper. The code for that feature isn't exactly controversial. Unfortunately, it isn't exactly reliable either, which brings me 'round to the first issue raised above....

Versions of Gatekeeper starting with the ill-fated 1.2.9 release have included a feature hidden "behind" the Gatekeeper logo in the Gatekeeper Controls control panel. If you click on it, the logo behaves like a conventional button or menu item (depending on how you look at it). In response to the click, Gatekeeper Controls attempts to launch Mosaic and then attempts to persuade Mosaic to connect with the Gatekeeper web pages on the Mac in my office here at the University of Texas at Austin.

The web pages contain an HTML version of the Gatekeeper documentation, offer the ability to download the latest versions of Gatekeeper and Disinfectant, describes the Gatekeeper mailing list (I can't stress the potential usefulness of that list enough), and will even show you a small selection of the postcards I've received from Gatekeeper users over the years. In the future it'll certainly do more.

If everyone had access to the Internet and robust Macs, nobody's network connection ever died, etc., I'd just remove the on-line help from Gatekeeper, delete the docs, and use such a link as the exclusive means of providing documentation, help, etc. to Gatekeeper users. Of course, that's totally out of the question, so the link to Mosaic remains a nifty (and somewhat enigmatic) hidden feature (until now, anyway :-).

That's the theory, of course. The practice is a bit problematic, sadly. The trouble is that while Mosaic loves to depend on applications to help it do things, it currently seems to have no intention of helping other applications do stuff. In other words it'll use "Helper Apps", but it refuses to be a "Helper App".

What's the problem? Basically, there needs to be some programmatic way to ask Mosaic to open a URL, or, at least, a local HTML document. Unfortunately for Gatekeeper, there isn't. So, when Gatekeeper wants to tell Mosaic to access the Gatekeeper web site, it can't just send some custom AppleEvent containing a URL, nor can it send a conventional Open event referring to a local HTML file. (Or, if there is a way, I sure as hell couldn't find it.) Instead, Gatekeeper has to simulate user keystrokes to Mosaic in order to trick Mosaic into opening the desired URL.

The process (from memory) goes something like this:

  1. Launch Mosaic (if it can be found) into the background.

  2. Put the URL for the main Gatekeeper web page into the scrap (Clipboard).

  3. Bring Mosaic to the foreground.

  4. Since Mosaic is probably still trying to load the default web page - and may miss Gatekeeper's simulated keystrokes as a result - we wait for it to finish loading the default web page.

    Since there's no way of knowing when Mosaic has really finished doing anything (not Mosaic's fault; without AppleScript there's not much of a way to do this with ANY application), step 4 is complicated by the inability to know if/when the loading ever completes. So we start guessing; we wait for the CPU time being used by Mosaic to drop below a certain percentage of total CPU time over a particular period. Both the percentage and the period were experimentally derived values that "seemed to work" about 90% of the time in my own tests on a variety of different Mac platforms.

  5. Assuming everything in step 4 went well, we send a Command-N ("New Window") to Mosaic, just in case Mosaic was already open when Gatekeeper "launched" it, but had no windows open at the time. Up until Mosaic 1.0.1, such a case meant that the "Open URL" option in the File menu would be disabled, and that option MUST be enabled in order for the rest of this to work.

  6. See step 4.

  7. Now that the new window is (hopefully) open and done (re)loading the default web page, we send a Command-U ("Open URL") to Mosaic.

  8. See step 4 again. (I think.)

  9. Hopefully the "Load URL" window is now open. Send a Command-V (Paste) to Mosaic to paste the URL we put in the scrap (step 2) into the edit field in the "Load URL" window.

  10. Send a carriage-return ('\r') character to Mosaic to simulate a click on the default "Open" button in the "Load URL" window.

After all this, if everything went well, you'll find yourself looking at the main Gatekeeper web page. Unfortunately, there's no guarantee that any of the steps above will work. If they fail, nothing bad will happen, but the desired effect won't be acheived. A common outcome when things don't go well is that the user is left looking at their default Web page in Mosaic, without a clue as to why Mosaic suddenly launched itself in the first place. :-)

Things that can go wrong include (but aren't limited to) any and all of the following:

  1. Mosaic's percentage use of CPU time may not drop below the required threshold on some machines that are unusually short of CPU time. (I did a number of successful tests on very slow Macs, but your mileage may vary.)

  2. Before Mosaic's CPU usage can drop below the required threshold (for one reason or another), timers in Gatekeeper may expire and cause it to abandon the attempt to control Mosaic. (I don't remember what the timeouts are off the top of my head, but they're a bit on the generous side.)

  3. Some or all of the keystrokes Gatekeeper is simulating to Mosaic may disappear into never-never land.

  4. User activity during this process is to likely prevent the attempt from completing successfully. (Be patient; it takes time for Gatekeeper to be sure Mosaic has completed some operations, even when it's perfectly obvious to the human staring at the screen that the operations are already complete.) Keystrokes, mouse clicks, bringing other apps to the foreground, etc., will all torpedo this kludge.

As has already been stated, there's currently NO reliable way for another program to get Mosaic to open a URL, so the aforementioned kludge was required.

One note about that kludge: no patches were required and only supported OS/Toolbox calls are used to implement it. If I'd started patching things, I could have increased the reliability, but it wasn't worth the compat- ibility risks, and the development/debugging time.

If any of the NCSA Mosaic Mac developers happen to read this, please consider it a subtle request for a tiny enhancement to a very nice product. :-)

In any case, I think this qualifies as one of the most elaborate (and potentially useful) "Easter Eggs" I've ever heard of.

When it works, that is. :-) :-)


Chris W. Johnson