Patch Browser Delete Individual History Items

From WebOS Internals
Revision as of 19:10, 22 October 2009 by Wtgreen (talk | contribs) (Added link to 1.2.1 .patch file, added line number and more comments for 1.2/1.2.1)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
<<- Return to webOS Patches


This will enable swipe-deletion of individual history items from the Browser history list.

A .patch file for webOS 1.2.1 is here

Manual Editing Instructions

Note: When I first attempted these changes, I edited the code in the files where you'd expect them to be (controllers/history-assistant.js, models/history-store.js), and found that no functionality changed. I grepped around and found that all the code from those two files (and many others is duplicated in controllers/global_code.js, and that only after I changed *that* file did it work. I don't know why, but oh well... So you'll only have to modify one file to get this working.

First, backup the file we're going to edit.

cd /usr/palm/applications/
cp global_code.js global_code.js.bkp

[Note for WebOS 1.2/1.2.1: The filename has changed. The following changes should be made to /usr/palm/applications/ instead of global.js. The line numbers aren't the same, but the section of code you should look for are.]

Then, open global_code.js file for editing.

First, we add the ability to swipe-delete to the historyList control itself: Find (1.1: global_code.js, line 1101 1.2.1: history-assistant.js, line 34)

		this.controller.setupWidget('historyList', {

Add a comma to the end of the last parameter line, and then add the swipeToDelete and autoconfirmDelete parameters, so it looks like this:

		this.controller.setupWidget('historyList', {

NOTE: if you want history item deletes to have the Delete/Cancel confirmation, change autoconfirmDelete to false. But with autoconfirmDelete:true, you can delete multiple pages quickly.

Next, we want to hook the delete event of the historyList to a handler. A few lines down, right after

this._onListSelectionHandler = this._onListSelection.bindAsEventListener(this);

Add the following line:

this._onListDeleteHandler = this._onListDelete.bindAsEventListener(this);

Then we need to add a listener for that event. About 20 lines down in the HistoryAssistant.prototype.activate function (1.2.1: line 65), right after this line:

this._historyListWidget.addEventListener(Mojo.Event.listTap, this._onListSelectionHandler);

add this:

this._historyListWidget.addEventListener(Mojo.Event.listDelete, this._onListDeleteHandler);

Then we need to add the stopListening in the deactivate function (just a few lines down). Right after this line (1.2.1: line 74):

Mojo.Event.stopListening(this._historyListWidget, Mojo.Event.listTap, this._onListSelectionHandler);

add this:

Mojo.Event.stopListening(this._historyListWidget, Mojo.Event.listDelete, this._onListDeleteHandler);

Then we add the handler itself. About 80 lines down, right after the HistoryAssistant.prototype._onListSelection function (though it doesn't *really* matter where you put it.. I'm just putting like things together), add this (1.2.1: line 153):

HistoryAssistant.prototype._onListDelete = function(event) {
	this.historyStore.deleteHistoryEntry(event.item.url, function() {}, function() {});

Ok! The event is all hooked up to the handler, and the list is swipeable. Now we just need to add code to the history-store model to delete the actual item from the database.

[Note for WebOS 1.2/1.2.1: The changes below should be made to /usr/palm/applications/ instead of global.js. The line numbers aren't the same, but the section of code you should look for are.]

Look for this function: (1.1: global_code.js, line 7350 1.2.1: history-store.js, line 17

function HistoryStore(options, onSuccess, onFailure) {
	try {
		this.displayName = options.displayName ||;
		this.estimatedSize = options.estimatedSize;
		this.database = options.database;
		this.database.transaction(this._createTable.bind(this, onSuccess, onFailure));
	} catch (e) {
		Mojo.Log.logException(e, 'HistoryStore()');

After that, add this:

HistoryStore.prototype._deleteHistoryEntry = function(url, onSuccess, onFailure, transaction) {
	this._executeSql(transaction, onSuccess, onFailure,
		"DELETE FROM 'history' WHERE url = ?", [url] );

HistoryStore.prototype.deleteHistoryEntry = function(url, onSuccess, onFailure) {
        this.database.transaction(this._deleteHistoryEntry.bind(this, url, onSuccess, onFailure));

Note: because of the simplicity of the SQL statement (basically "delete all history items with this url"), one swipe could delete multiple history items. For example, if you swipe an item with the url, and you have more than one of them in your history, they will all be deleted. This may or may not be what you want.

That's all.. reboot your pre and give it a try!