Patch Browser Downloading Files

NOTE -- This is newly 1.1 compatible

8/15/09 -1.1 Working Patch Up And Ready

Edit: Anything can be downloaded in this patch, but must download directly from the download link/url.

Must Be In [root@castle:/#] not [username@castle] to work !

cd /opt/src/modifications git pull

quilt import /opt/src/modifications/browser/enable-browser-downloads.patch

cd / quilt push reboot

'''-All Done Patch Applied! NO NEED TO DO ANY PORTION AT BOTTOM'''

NOTE- Swipe to remove finished downloads widget at the bottom of the page, Must not be zoomed in to view

=
=====================================================================================================

As of 2009/07/06, all parts of this modification have been incorporated into the patch file at http://gitorious.org/webos-internals/modifications/blobs/raw/master/browser/enable-browser-downloads.patch.

If further modifications are made, but for whatever reason the patch cannot be updated according to the steps at Applying Patches, please place these changes above the "PATCH" line so that someone else can incorporate them into the patch (and then note that they have been incorporated)

Also included is a change to DownloadDialogAssistant that clears out the onDismiss function when streaming. Otherwise, anytime you selected stream, the file would be downloaded as well (in the cleanup function).

It would be good if the developers contributing code could get gitorious accounts and keep this patch updated ...A

=Please add this code change to the patch file= The problem of links not launching apps (Phone app, Google Maps app, YouTube app) has been fixed. Open global_code.js, find the PageAssistant.prototype._streamResource function. Under the Mojo.Log.error... line (at the top of the fn), add the following: if(appid === 'com.palm.app.phone' || 'com.palm.app.maps' || 'com.palm.app.youtube' ) {   //a phone #, Google Map, or 'Get Directions', or YouTube link was clicked, so we bypass the download dialog and open the app. var params = {target: uri, mimeType: mimeType}; this.controller.serviceRequest('palm://com.palm.applicationManager',{       method: 'open',        parameters: {            'id': appid,            'params': params        }}    ); return; }

Right under there, the code continues on at this._downloadWidgetElement = .....

= PATCH= CODE The first step is to enable the required javascript sources through sources.json:

{	"source":"app\/models\/download-model.js" }, {	"source":"app\/controllers\/download-request.js" }, {	"source":"app\/controllers\/download-controller.js" }, {   "source":"app\/controllers\/downloaddialog-assistant.js" },

I put them directly before the import for global_code.js, as that is where they will be used from.

Next, at the end of the global_code.js function "PageAssistant.prototype.setup" (right before the } catch(e){...):

this._downloadController = new DownloadController(this.controller); this._downloadController.setup;

SUCCESS - 6/24/2009 mdklein has fixed the infinite loop bug with browsers and unknown filetypes. It's a simple modification. Please let me know if this breaks anything...

'''I left the following out of the 1.1 patch update, since that part of the browser code has changed since 1.0, and we might not need it. (Works for mp3s, anyway... might need to be refactored yet.)''' in page-assistant.js change the if statement "&& response.mimeByExtenstion" is added to verify we know it's a mime type. (yes, Palm typoed) writing it this way in case they fix the typo in the future. // Yes, palm, I caught your typo... writing it this way in case you fix it? function returns mimeByExtenstion... guessing it should be mimeByExtension if (response.returnValue && response.canStream && (response.mimeByExtenstion||response.mimeByExtension)) { this._streamResource(event.url, response.appIdByExtension, (response.mimeByExtenstion||response.mimeByExtenstion)); }

And then the downloadResource function, also in global_code.cs (note that we are now presenting a confirmation dialog). Replace the current function with this: PageAssistant.prototype._downloadResource = function(uri) {

Mojo.Log.info("Downloading: " + uri);

try { // We should no longer download a resource but inform the user // we are unable to perform the download. if (!this._downloadWidgetElement) { this._downloadWidgetElement = this.controller.showDialog({                               template: 'download/download-popup',                                assistant: new DownloadDialogAssistant({ sceneAssistant: this, onDismiss: function { //this._onPopupHandler('close'); delete this._downloadWidgetElement; }.bind(this), onAccept: function { //this._onPopupHandler('close'); this._downloadController.downloadResource(uri); }.bind(this)})                               });

// Record we have a popup //this._onPopupHandler('open'); }	} catch (e) { Mojo.Log.logException(e, "#_downloadResource"); }

// Hide the address bar. this._addressBar.hide; this._webView.mojo.focus; }; NOTE I commented out the lines that called _onPopupHandler, since there seems to be no such handler now in 1.1 (that I could find), and it didn't seem to matter.

Now we change the PageAssistant.prototype._streamResource function (also in global_code.js) to this: PageAssistant.prototype._streamResource = function(uri, appid, mimeType){

Mojo.Log.error("Streaming: '%s' with '%s' (%s)", uri, appid, mimeType);

this._downloadWidgetElement = this.controller.showDialog({       uri: uri,        mimeType: mimeType,        appid: appid,        template: 'download/download-stream-popup',        assistant: new DownloadDialogAssistant({ sceneAssistant: this, onDismiss: function(cParams) { // DOWNLOAD //this._onPopupHandler('close'); this._downloadController.downloadResource(uri); }.bind(this), onAccept: function(cParams) { // STREAM var params = {target: uri, mimeType: mimeType, appid: appid}; // Only a few select applications can be               var crossAppScene = { 'com.palm.app.videoplayer': 'nowplaying', 'com.palm.app.streamingmusicplayer': 'nowplaying' };               //this._onPopupHandler('close'); if (crossAppScene[appid]) { var args = { appId: appid, name: crossAppScene[appid] }; this.controller.stageController.pushScene(args, params); }               else { this._downloadController.downloadResource(uri); }       }.bind(this)})    }); // Record we have a popup //this._onPopupHandler('open');

}; NOTE again that I commented out the _onPopupHandler calls.

Then we add a new file /usr/palm/applications/com.palm.app.browser/app/controllers/downloaddialog-assistant.js /** * A dialog assistant for display of yes/no box. */ DownloadDialogAssistant = Class.create({

initialize: function(params) { this.onDismiss = params.onDismiss; this.onAccept = params.onAccept; this.controller= params.sceneAssistant.controller;

// Button handlers. this.onDismissHandler = this.handleDismiss.bindAsEventListener(this); this.onAcceptHandler = this.handleAccept.bindAsEventListener(this); },

setup: function(widget) { this.widget = widget; this.controller.get('acceptButton').addEventListener(Mojo.Event.tap, this.onAcceptHandler); this.controller.get('acceptButton').focus; this.controller.get('dismissButton').addEventListener(Mojo.Event.tap, this.onDismissHandler); this.controller.get('dismissButton').focus; },

handleDismiss: function { this.onDismiss; delete this.onDismiss; this.widget.mojo.close; },       handleAccept: function { this.onAccept; delete this.onAccept; this.widget.mojo.close; },

cleanup: function { Mojo.Log.info("NetworkDialogAssistant#cleanup"); Mojo.Event.stopListening(this.controller.get('dismissButton'), Mojo.Event.tap, this.onDismissHandler); Mojo.Event.stopListening(this.controller.get('acceptButton'), Mojo.Event.tap, this.onAcceptHandler);

// Send a dismiss if NOT already sent a response if (this.onDismiss) { this.onDismiss; }       } });

RESOURCES That is all the "code" that needs to be fixed. The rest would be considered resources.

you also need a /usr/palm/applications/com.palm.app.browser/app/views/download/download-popup.html Cannot find an application which can open this file. Would you like to download it to /media/internal/downloads?

Yes No

In app/views/page/page-scene.html, we append:

and then in app/views/download/download-container.html, replace the contents with: NOTE: the 1.0 version did not have a '-' before "listElements", but we need that hyphen there.
 * 1) {-listElements}

You will also need to create download-stream-popup.html in app/views/download: This file type has been registered as a streaming media file. Would you like to download it to /media/internal/downloads instead?

Stream Download

IMPORTANT NOTES:

The download widgets will be added to the bottom of the currently rendered page. If you are zoomed in, you probably won't be able to see them.

Swipe-to-delete works, but not the way you think. The widget will disappear, but the download will finish if it has not already, and will persist afterward. You will have to use a PC and mount the mass storage controller to remove downloads later.

SUCCESS - 6/23/2009 chris_phelps has completed a "Download" feature that creates it's own Scene for completed downloads in the browser.



This however, was not the correct way to do things as the system is already keeping track of all downloads in it's own database. chris_phelps will be moving the code created specifically for the Download scene in the browser application into it's own application. Expect this by the end of the day maybe (6/24/2009) depending on how good the weather gets.

PATCH CODE
Index: /usr/palm/applications/com.palm.app.browser/app/controllers/downloaddialog-assistant.js

=
====================================================== --- /dev/null +++ /usr/palm/applications/com.palm.app.browser/app/controllers/downloaddialog-assistant.js @@ -0,0 +1,45 @@ +/** + * A dialog assistant for display of yes/no box. + */ +DownloadDialogAssistant = Class.create({ + +       initialize: function(params) { +                this.onDismiss = params.onDismiss; +                this.onAccept = params.onAccept; +                this.controller= params.sceneAssistant.controller; + +                // Button handlers. +                this.onDismissHandler = this.handleDismiss.bindAsEventListener(this); +                this.onAcceptHandler = this.handleAccept.bindAsEventListener(this); +        }, + +        setup: function(widget) { +                this.widget = widget; +                this.controller.get('acceptButton').addEventListener(Mojo.Event.tap, this.onAcceptHandler); +                this.controller.get('acceptButton').focus; +                this.controller.get('dismissButton').addEventListener(Mojo.Event.tap, this.onDismissHandler); +                this.controller.get('dismissButton').focus; +       }, + +        handleDismiss: function { +               this.onDismiss; +               delete this.onDismiss; +               this.widget.mojo.close; +       }, +        handleAccept: function { +               this.onAccept; +               delete this.onAccept; +               this.widget.mojo.close; +       }, + +        cleanup: function { +               Mojo.Log.info("NetworkDialogAssistant#cleanup"); +               Mojo.Event.stopListening(this.controller.get('dismissButton'), Mojo.Event.tap, this.onDismissHandler); +               Mojo.Event.stopListening(this.controller.get('acceptButton'), Mojo.Event.tap, this.onAcceptHandler); + +               // Send a dismiss if NOT already sent a response +               if (this.onDismiss) { +                       this.onDismiss; +               } +        } +}); Index: /usr/palm/applications/com.palm.app.browser/app/controllers/global_code.js

=
====================================================== --- .orig/usr/palm/applications/com.palm.app.browser/app/controllers/global_code.js +++ /usr/palm/applications/com.palm.app.browser/app/controllers/global_code.js @@ -1449,6 +1449,8 @@ PageAssistant.prototype.setup = function this._webView.addEventListener(Mojo.Event.webViewUrlRedirect, this._onUrlRedirect.bind(this), false); this._webView.addEventListener(Mojo.Event.webViewModifierTap, this._onModifierTapHandler, false); this._webView.addEventListener(Mojo.Event.webViewUpdateHistory, this._onUpdateHistoryHandler, false); +	   this._downloadController = new DownloadController(this.controller); +       this._downloadController.setup; } 	catch (e) { Mojo.Log.logException(e, 'PageAssistant#setup'); @@ -2287,28 +2289,39 @@ PageAssistant.prototype._newBrowserPage */ PageAssistant.prototype._streamResource = function(uri, appid, mimeType){ -	Mojo.Log.info("Streaming: '%s' with '%s' (%s)", uri, appid, mimeType); +	Mojo.Log.error("Streaming: '%s' with '%s' (%s)", uri, appid, mimeType); -	// Only a few select applications can be -	crossAppScene = { -		'com.palm.app.videoplayer': 'nowplaying', -		'com.palm.app.streamingmusicplayer': 'nowplaying' -	}; -	var params = {target: uri, mimeType: mimeType}; -	if (crossAppScene[appid]) { +   this._downloadWidgetElement = this.controller.showDialog({ +        uri: uri, +        mimeType: mimeType, +        appid: appid, +        template: 'download/download-stream-popup', +        assistant: new DownloadDialogAssistant({ +       sceneAssistant: this, +       onDismiss: function(cParams) { // DOWNLOAD +               //this._onPopupHandler('close'); +               this._downloadController.downloadResource(uri); +       }.bind(this), +       onAccept: function(cParams) { // STREAM +               var params = {target: uri, mimeType: mimeType, appid: appid}; +               // Only a few select applications can be +                var crossAppScene = { +                   'com.palm.app.videoplayer': 'nowplaying', +                   'com.palm.app.streamingmusicplayer': 'nowplaying' +               }; +                //this._onPopupHandler('close'); +               if (crossAppScene[appid]) { +                   var args = { appId: appid, name: crossAppScene[appid] }; +                   this.controller.stageController.pushScene(args, params); +               } +                else { +                   this._downloadController.downloadResource(uri); +               } +        }.bind(this)}) +    }); +   // Record we have a popup +   //this._onPopupHandler('open'); -		var args = { appId: appid, name: crossAppScene[appid] }; -		this.controller.stageController.pushScene(args, params); -	} -	else { -		this.controller.serviceRequest('palm://com.palm.applicationManager', { -			method: 'open', -			parameters: { -				'id': appid, -				'params': params -			} -		}); -	} }; /** @@ -2318,16 +2331,29 @@ PageAssistant.prototype._streamResource */ PageAssistant.prototype._downloadResource = function(uri) { -	Mojo.Log.info("Downloading: " + uri); +       Mojo.Log.info("Downloading: " + uri); -	try { -		// We should no longer download a resource but inform the user -		// we are unable to perform the download. -		this.controller.showAlertDialog({ -			onChoose: function(value) { /* Do Nothing */}, -			message: $L('Cannot find an application which can open this file.'), -			choices:[{label:$L('OK'), value:'1', type:'dismiss'}] -		}); +       try { +               // We should no longer download a resource but inform the user +               // we are unable to perform the download. +               if (!this._downloadWidgetElement) { +                       this._downloadWidgetElement = this.controller.showDialog({ +                                template: 'download/download-popup', +                                assistant: new DownloadDialogAssistant({ +                                       sceneAssistant: this, +                                       onDismiss: function { +                                               //this._onPopupHandler('close'); +                                               delete this._downloadWidgetElement; +                                       }.bind(this), +                                       onAccept: function { +                                               //this._onPopupHandler('close'); +                                               this._downloadController.downloadResource(uri); +                                       }.bind(this)}) +                                }); + +                       // Record we have a popup +                       //this._onPopupHandler('open'); +               } 	} catch (e) { Mojo.Log.logException(e, "#_downloadResource"); } Index: /usr/palm/applications/com.palm.app.browser/app/views/download/download-container.html

=
====================================================== --- .orig/usr/palm/applications/com.palm.app.browser/app/views/download/download-container.html +++ /usr/palm/applications/com.palm.app.browser/app/views/download/download-container.html @@ -1,3 +1,3 @@ -	#{listElements} +	#{-listElements} \ No newline at end of file Index: /usr/palm/applications/com.palm.app.browser/app/views/download/download-popup.html

=
====================================================== --- /dev/null +++ /usr/palm/applications/com.palm.app.browser/app/views/download/download-popup.html @@ -0,0 +1,8 @@ + +       Cannot find an application which can open this file. Would you like to download it to /media/internal/downloads? + + + +       Yes +       No + Index: /usr/palm/applications/com.palm.app.browser/app/views/download/download-stream-popup.html

=
====================================================== --- /dev/null +++ /usr/palm/applications/com.palm.app.browser/app/views/download/download-stream-popup.html @@ -0,0 +1,8 @@ + +       This file type has been registered as a streaming media file. Would you like to download it to /media/internal/downloads instead? + + + +       Stream +       Download + Index: /usr/palm/applications/com.palm.app.browser/app/views/page/page-scene.html

=
====================================================== --- .orig/usr/palm/applications/com.palm.app.browser/app/views/page/page-scene.html +++ /usr/palm/applications/com.palm.app.browser/app/views/page/page-scene.html @@ -16,5 +16,9 @@ + +	 + + Index: /usr/palm/applications/com.palm.app.browser/sources.json

=
====================================================== --- .orig/usr/palm/applications/com.palm.app.browser/sources.json +++ /usr/palm/applications/com.palm.app.browser/sources.json @@ -1,5 +1,17 @@ -[ +[  { -  "source": "app\/controllers\/global_code.js" +	"source":"app\/models\/download-model.js" + }, + { +	"source":"app\/controllers\/download-request.js" + }, + { +	"source":"app\/controllers\/download-controller.js" + }, + { +   "source":"app\/controllers\/downloaddialog-assistant.js" + }, + { +   "source": "app\/controllers\/global_code.js" } ]