Difference between revisions of "Patch Browser Downloading Files"

From WebOS Internals
Jump to navigation Jump to search
(→‎Related Links: Removed advertising spam)
 
(16 intermediate revisions by 5 users not shown)
Line 1: Line 1:
 
{{template:patch}}
 
{{template:patch}}
  
'''NOTE -- This is newly 1.1 compatible, but the Patch file linked below has not been updated. Anybody wanna do that for me?'''
+
'''NOTE -- This is newly 1.1 compatible'''
  
'''-1.1 Working Patch Up And Ready http://filebin.ca/xfjjme/enable-browser-downloads110.patch'''
+
8/15/09 -1.1 Working Patch Up And Ready
  
'''ANOTHER NOTE -- I haven't extensively tested the 1.1 version of the changes. I've confirmed that it works for mp3s, but not other filetypes yet.'''
+
Edit: Anything can be downloaded in this patch, but must download directly from the download link/url.
  
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.
+
Must Be In '''[root@castle:/#]''' not '''[username@castle]''' to work !
 +
 
 +
<pre>
 +
cd /opt/src/modifications
 +
git pull
 +
 
 +
quilt import /opt/src/modifications/browser/enable-browser-downloads.patch
 +
 
 +
cd /
 +
quilt push
 +
 +
reboot
 +
</pre>
 +
 
 +
'''-All Done Patch Applied! NO NEED TO DO ANY PORTION AT BOTTOM'''
  
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)
+
NOTE- Swipe to remove finished downloads widget at the bottom of the page, Must not be zoomed in to view
  
'''NOTE''' from dizzwave -- sorry I didn't follow this rule, but since so much stuff got moved around, I didn't see the point of moving everything above the PATCH line. I hope that's ok.
+
==================================================================================================================
  
This patch file contains all of the modifications described below the PATCH line, as well as a typo correction (believe it or not, mimeByExtenstion '''IS''' correct, see the following output if you don't believe it):
+
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.
  
<pre><nowiki>
+
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)
luna-send -n 1 palm://com.palm.applicationManager/getResourceInfo '{"uri":"http://www.podtrac.com/pts/redirect.mp3/aolradio.podcast.aol.com/twit/TWiT0202H.mp3"}'
 
</nowiki></pre>
 
'''NOTE''' They seem to have fixed that typo in 1.1.  :)
 
  
  
Line 25: Line 36:
 
It would be good if the developers contributing code could get gitorious accounts and keep this patch updated ...A
 
It would be good if the developers contributing code could get gitorious accounts and keep this patch updated ...A
  
Note: WOW! I used this a lot before and can't wait to use it post-1.1.  How do I apply it from Quilt?  I don't see it listed there.
 
  
Reply: Yep, i haven't updated the patch yet, just the code changing instructions. I'll try to get on that! -dizz
+
=Please add this code change to the patch file=
= PATCH=
+
'''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:
 +
<pre><nowiki>
 +
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;
 +
}</nowiki></pre>
  
 +
Right under there, the code continues on at this._downloadWidgetElement = .....
  
NOTE: 6/24/2009
 
chris_phelps merged all of the sections from mdklein back into one set of directions. If you have already done the first part, you will have to figure out what is left for yourself.
 
  
NOTE: 8/11/2009 (dizzwave) Making some minor changes to the code below so as to work with 1.1. My changes in '''bold''', with the old stuff <s>struckthrough</s>, for clarity (and to help whoever fixes up the patch file!:)).
 
  
  
During some of my initial digging in the Browser application, I discovered that Palm developers had left quite a bit of code in place to enable downloading via the web interface. User mdklein was interested in the same fix at the same time (6/22/2009), so we shared information as we moved forward.
+
= PATCH=
 
 
 
'''CODE'''
 
'''CODE'''
 
The first step is to enable the required javascript sources through sources.json:
 
The first step is to enable the required javascript sources through sources.json:
Line 57: Line 80:
 
</nowiki></pre>
 
</nowiki></pre>
  
I put them directly before the import for <s>page-assistant.js</s>'''global_code.js''', as that is where they will be used from.
+
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 <s>app/controllers/page-assistant.js</s>'''global_code.js''' function "PageAssistant.prototype.setup" (right before the ''} catch(e){...)'':
+
Next, at the end of the global_code.js function "PageAssistant.prototype.setup" (right before the ''} catch(e){...)'':
  
 
<pre><nowiki>
 
<pre><nowiki>
Line 70: Line 93:
 
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...
 
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 this out for now, 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.)'''
+
'''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.)'''
 
<s>
 
<s>
 
in page-assistant.js change the if statement "&& response.mimeByExtenstion" is added to verify we know it's a mime type.  (yes, Palm typoed)
 
in page-assistant.js change the if statement "&& response.mimeByExtenstion" is added to verify we know it's a mime type.  (yes, Palm typoed)
Line 83: Line 106:
 
</s>  
 
</s>  
  
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:
+
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:
 
<pre><nowiki>
 
<pre><nowiki>
 
PageAssistant.prototype._downloadResource = function(uri) {
 
PageAssistant.prototype._downloadResource = function(uri) {
Line 119: Line 142:
 
};
 
};
 
</nowiki></pre>
 
</nowiki></pre>
'''NOTE I commented out the lines that called _onPopupHandler, since there seems to be no such handler now (that I could find), and it didn't seem to matter.'''
+
'''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:
+
Now we change the PageAssistant.prototype._streamResource function (also in global_code.js) to this:
 
<pre><nowiki>
 
<pre><nowiki>
 
PageAssistant.prototype._streamResource = function(uri, appid, mimeType){
 
PageAssistant.prototype._streamResource = function(uri, appid, mimeType){
Line 277: Line 300:
  
 
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.
 
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=====
 +
<pre>
 +
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 @@
 +
<div x-mojo-elements="List" class="palm-list no-lines">
 +
- #{listElements}
 +
+ #{-listElements}
 +
</div>
 +
\ 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 @@
 +
+<div id="palm-dialog-content" class="palm-dialog-content">
 +
+        <div class="dialog-message" x-mojo-loc=""> Cannot find an application which can open this file. Would you like to download it to /media/internal/downloads?</div>
 +
+</div>
 +
+
 +
+<div class="palm-dialog-buttons">
 +
+        <div class="dismiss palm-button" id="acceptButton" x-mojo-loc="" x-mojo-tap-highlight="momentary">Yes</div>
 +
+        <div class="dismiss palm-button" id="dismissButton" x-mojo-loc="" x-mojo-tap-highlight="momentary">No</div>
 +
+</div>
 +
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 @@
 +
+<div id="palm-dialog-content" class="palm-dialog-content">
 +
+        <div class="dialog-message" x-mojo-loc="">This file type has been registered as a streaming media file. Would you like to download it to /media/internal/downloads instead?</div>
 +
+</div>
 +
+
 +
+<div class="palm-dialog-buttons">
 +
+        <div class="dismiss palm-button" id="acceptButton" x-mojo-loc="" x-mojo-tap-highlight="momentary">Stream</div>
 +
+        <div class="dismiss palm-button" id="dismissButton" x-mojo-loc="" x-mojo-tap-highlight="momentary">Download</div>
 +
+</div>
 +
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 @@
 +
<div id="server-disconnected" class="palm-scrim">
 +
<div id="server-disconnected-spinner" x-mojo-element="Spinner"></div>
 +
</div>
 +
+<div id="downloadListScroller" class="browser-download" x-mojo-element="Scroller">
 +
+ <div id="downloadList" class="palm-list" x-mojo-element="List"></div>
 +
+</div>
 +
+
 +
 +
 +
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"
 +
  }
 +
]
 +
</pre>
 +
 +
==Related Links==

Latest revision as of 22:52, 28 January 2011


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

<div id="palm-dialog-content" class="palm-dialog-content">
        <div class="dialog-message" x-mojo-loc=""> Cannot find an application which can open this file. Would you like to download it to /media/internal/downloads?</div>
</div>

<div class="palm-dialog-buttons">
        <div class="dismiss palm-button" id="acceptButton" x-mojo-loc="" x-mojo-tap-highlight="momentary">Yes</div>
        <div class="dismiss palm-button" id="dismissButton" x-mojo-loc="" x-mojo-tap-highlight="momentary">No</div>
</div>

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

<div id="downloadListScroller" class="browser-download" x-mojo-element="Scroller">
	<div id="downloadList" class="palm-list" x-mojo-element="List"></div>
</div>

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.

#{-listElements}


You will also need to create download-stream-popup.html in app/views/download:

<div id="palm-dialog-content" class="palm-dialog-content">
        <div class="dialog-message" x-mojo-loc="">This file type has been registered as a streaming media file. Would you like to download it to /media/internal/downloads instead?</div>
</div>

<div class="palm-dialog-buttons">
        <div class="dismiss palm-button" id="acceptButton" x-mojo-loc="" x-mojo-tap-highlight="momentary">Stream</div>
        <div class="dismiss palm-button" id="dismissButton" x-mojo-loc="" x-mojo-tap-highlight="momentary">Download</div>
</div>



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.

Dl-browser1.png Dl-browser2.png Dl-browser3.png

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 @@
 <div x-mojo-elements="List" class="palm-list no-lines">
-	#{listElements}
+	#{-listElements}
 </div>
\ 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 @@
+<div id="palm-dialog-content" class="palm-dialog-content">
+        <div class="dialog-message" x-mojo-loc=""> Cannot find an application which can open this file. Would you like to download it to /media/internal/downloads?</div>
+</div>
+
+<div class="palm-dialog-buttons">
+        <div class="dismiss palm-button" id="acceptButton" x-mojo-loc="" x-mojo-tap-highlight="momentary">Yes</div>
+        <div class="dismiss palm-button" id="dismissButton" x-mojo-loc="" x-mojo-tap-highlight="momentary">No</div>
+</div>
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 @@
+<div id="palm-dialog-content" class="palm-dialog-content">
+        <div class="dialog-message" x-mojo-loc="">This file type has been registered as a streaming media file. Would you like to download it to /media/internal/downloads instead?</div>
+</div>
+
+<div class="palm-dialog-buttons">
+        <div class="dismiss palm-button" id="acceptButton" x-mojo-loc="" x-mojo-tap-highlight="momentary">Stream</div>
+        <div class="dismiss palm-button" id="dismissButton" x-mojo-loc="" x-mojo-tap-highlight="momentary">Download</div>
+</div>
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 @@
 <div id="server-disconnected" class="palm-scrim"> 
 	<div id="server-disconnected-spinner" x-mojo-element="Spinner"></div> 
 </div> 
+<div id="downloadListScroller" class="browser-download" x-mojo-element="Scroller">
+	<div id="downloadList" class="palm-list" x-mojo-element="List"></div>
+</div>
+
 
 
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"
  }
 ]

Related Links