Difference between revisions of "Patch Browser Downloading Files"

From WebOS Internals
Jump to navigation Jump to search
m (Replied to suspicions about 1.1 update.)
(→‎Related Links: Removed advertising spam)
 
(27 intermediate revisions by 9 users not shown)
Line 1: Line 1:
As of 2009/07/06, all parts of this modification have been incorporated into the path file at http://gitorious.org/webos-internals/modifications/blobs/raw/master/browser/enable-browser-downloads.patch.
+
{{template:patch}}
 +
 
 +
'''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 !
 +
 
 +
<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'''
 +
 
 +
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)
 
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)
  
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):
 
 
<pre><nowiki>
 
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>
 
  
 
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).
 
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).
Line 13: 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: 7/25/2009 Doesn't seem to work with 1.1 update (?) Worked great for months, update, now doesn't.  Other patches work ok after update.
 
REPLY: 8/29/2009 Indeed. I never even got around to using it until now. It's too bad.
 
  
= PATCH=
+
=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:
 +
<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.
 
  
  
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 43: Line 80:
 
</nowiki></pre>
 
</nowiki></pre>
  
I put them directly before the import for page-assistant.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 app/controllers/page-assistant.js function "PageAssistant.prototype.setup":
+
Next, at the end of the global_code.js function "PageAssistant.prototype.setup" (right before the ''} catch(e){...)'':
  
 
<pre><nowiki>
 
<pre><nowiki>
Line 56: 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 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>
 
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)
 
writing it this way in case they fix the typo in the future.
 
writing it this way in case they fix the typo in the future.
Line 65: Line 104:
  
 
</nowiki></pre>
 
</nowiki></pre>
 +
</s>
  
And then downloadResource (note that we are now presenting a confirmation dialog):
+
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 81: Line 121:
 
                                         sceneAssistant: this,
 
                                         sceneAssistant: this,
 
                                         onDismiss: function() {
 
                                         onDismiss: function() {
                                                 this._onPopupHandler('close');
+
                                                 //this._onPopupHandler('close');
 
                                                 delete this._downloadWidgetElement;
 
                                                 delete this._downloadWidgetElement;
 
                                         }.bind(this),
 
                                         }.bind(this),
 
                                         onAccept: function() {
 
                                         onAccept: function() {
                                                 this._onPopupHandler('close');
+
                                                 //this._onPopupHandler('close');
 
                                                 this._downloadController.downloadResource(uri);
 
                                                 this._downloadController.downloadResource(uri);
 
                                         }.bind(this)})
 
                                         }.bind(this)})
Line 91: Line 131:
  
 
                         // Record we have a popup
 
                         // Record we have a popup
                         this._onPopupHandler('open');
+
                         //this._onPopupHandler('open');
 
                 }
 
                 }
 
} catch (e) {
 
} catch (e) {
Line 102: Line 142:
 
};
 
};
 
</nowiki></pre>
 
</nowiki></pre>
 +
'''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.'''
  
add file /usr/palm/applications/com.palm.app.browser/app/controllers/downloaddialog-assistant.js
+
Now we change the PageAssistant.prototype._streamResource function (also in global_code.js) to this:
 +
<pre><nowiki>
 +
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');
 +
 
 +
};
 +
</nowiki></pre>
 +
'''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
 
<pre><nowiki>
 
<pre><nowiki>
 
/**
 
/**
Line 177: Line 260:
  
 
and then in app/views/download/download-container.html, replace the contents with:
 
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.'''
 
<pre><nowiki>
 
<pre><nowiki>
#{listElements}
+
#{-listElements}
 
</nowiki></pre>
 
</nowiki></pre>
  
'''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.
 
 
'''NEW FEATURE''' - 6/24/2009 chris_phelps
 
After coming across several people in the forums wanting to download mp3 files from the web for ringtones, I decided we needed a dialog to ask the user if they would rather download a streamable file than stream it.
 
 
The new streamResource function looks like this:
 
<pre><nowiki>
 
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');
 
 
};
 
</nowiki></pre>
 
  
 
You will also need to create download-stream-popup.html in app/views/download:
 
You will also need to create download-stream-popup.html in app/views/download:
 
 
<pre><nowiki>
 
<pre><nowiki>
 
<div id="palm-dialog-content" class="palm-dialog-content">
 
<div id="palm-dialog-content" class="palm-dialog-content">
Line 243: Line 277:
 
</div>
 
</div>
 
</nowiki></pre>
 
</nowiki></pre>
 +
 +
 +
 +
 +
'''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.
 +
 +
 +
 +
  
  
Line 253: 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