1
# Copyright (C) 2007, One Laptop Per Child
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
# http://lxr.mozilla.org/seamonkey/source/browser/components/sessionstore
22
from xpcom import components
23
from xpcom.components import interfaces
25
def get_session(browser):
26
session_history = browser.web_navigation.sessionHistory
28
if session_history.count == 0:
30
return _get_history(session_history)
32
def set_session(browser, data):
33
_set_history(browser.web_navigation.sessionHistory, data)
36
browser.web_navigation.gotoIndex(len(data) - 1)
38
browser.load_uri('about:blank')
40
def _get_history(history):
41
logging.debug('%r' % history.count)
43
for i in range(0, history.count):
44
entry_orig = history.getEntryAtIndex(i, False)
45
entry_dest = {'url': entry_orig.URI.spec,
46
'title': entry_orig.title}
48
entries_dest.append(entry_dest)
52
def _set_history(history, history_data):
53
history_internal = history.queryInterface(interfaces.nsISHistoryInternal);
55
if history_internal.count > 0:
56
history_internal.purgeHistory(history_internal.count);
58
for entry_dict in history_data:
59
logging.debug('entry_dict: %r' % entry_dict)
60
entry_class = components.classes["@mozilla.org/browser/session-history-entry;1"]
61
entry = entry_class.createInstance(interfaces.nsISHEntry)
63
io_service_class = components.classes["@mozilla.org/network/io-service;1"]
64
io_service = io_service_class.getService(interfaces.nsIIOService)
65
entry.setURI(io_service.newURI(entry_dict['url'], None, None));
66
entry.setTitle(entry_dict['title']);
68
history_internal.addEntry(entry, True)