Difference between revisions of "Patch Browser Downloading Files"

From WebOS Internals
Jump to navigation Jump to search
m (note after Palm update)
m (Replied to suspicions about 1.1 update.)
Line 14: Line 14:
  
 
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.
 
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=
 
= PATCH=

Revision as of 04:11, 30 July 2009

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.

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):

luna-send -n 1 palm://com.palm.applicationManager/getResourceInfo '{"uri":"http://www.podtrac.com/pts/redirect.mp3/aolradio.podcast.aol.com/twit/TWiT0202H.mp3"}'

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

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

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.

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 page-assistant.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":

        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...

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 downloadResource (note that we are now presenting a confirmation dialog):

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();
};

add 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:

#{listElements}

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:

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');

};

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>


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.