Note this post refers to the first Silverlight 4.0 Beta (release November 2009) – future releases may cause readers to be confused and misled – you get that.
Silverlight 4.0 offers a number of new features that I am really keen to try out for ButtercupReader. In particular,
- Using the WebBrowser control to render the book contents rather than having to convert HTML into XAML.
- Using ComAutomationFactory to create the SAPI objects for self voicing text-to-speech (rather than relying on doing this in JavaScript)
- Using MyDocuments storage instead of IsolatedStorage to store loaded books locally.
I’ll cover some of these features in future posts.
Now all the features require Silverlight to be running Out-Of-Browser (OOB) with elevated privileges. So my first task (after upgrading the source code from Silverlight 3.0 to 4.0 – harder than it should have been, but I’ll leave that to another post) was to see if ButtercupReader would run OOB. It won’t. The main reasons is that ButtercupReader relies on the HTML Bridge to make JavaScript calls.
By design, OOB applications can not access the HTML Bridge like HtmlPage.Window.Invoke(). Bugger.
Now I am probably going to be able to do away with my dependency on JavaScript but I did discover a way to allow OOB applications to use (some) JavaScript.
You need to create two Silverlight applications. One that simply contains a WebBrowser control (new to 4.0) and acts as the container for the page that hosts your main Silverlight application. The host web page for the container application will be the new entry point to your main application. You simply set the location of the WebBrowser control to your (original) main application host. Something like,
browserControl.Navigate(new Uri(“http://buttercup/default.html”));
Where, http://buttercup/default.html, is the location of the page that hosts your main Silverlight application.
You can now run the application OOB and interact with the Silverlight application hosted within the WebBrowser control and be able to execute JavaScript via the HTML Bridge. BUT (you knew it was coming), the WebBrowser does not currently support all Javascript functionality. I haven’t seen a complete lists but this forum indicated that calls to “alert, confirm and some other window.* methods are blocked”. I couldn’t get ButtercupReader to work (didn’t try that hard though) so there are obviously some other restrictions.
So, there you have it, could be an option if your application relies on the HTML Bridge and you want to take advantage of the new features that rely on OOB.