Difference between revisions of "Patch Browser Downloading Files"

From WebOS Internals
Jump to navigation Jump to search
m (cleanup)
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'''
 
'''-1.1 Working Patch Up And Ready http://filebin.ca/xfjjme/enable-browser-downloads110.patch'''
  
'''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.'''
+
'''Patch still needs to be uploaded to gitorious to replace the 1.0 patch below:'''
  
 
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.
 
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)
 
'''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):
 
 
<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>
 
'''NOTE''' They seem to have fixed that typo in 1.1.  :)
 
  
  
Line 25: Line 16:
 
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
 
 
= PATCH=
 
= PATCH=
 
 
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.
 
 
 
'''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 35:
 
</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 48:
 
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 61:
 
</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 97:
 
};
 
};
 
</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){

Revision as of 07:34, 15 August 2009


NOTE -- This is newly 1.1 compatible

-1.1 Working Patch Up And Ready http://filebin.ca/xfjjme/enable-browser-downloads110.patch

Patch still needs to be uploaded to gitorious to replace the 1.0 patch below:

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

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.