Bug 1221050 - part 2: migrate data into bookmarks, r?ttaubert,mak
--- a/browser/modules/TabGroupsMigrator.jsm
+++ b/browser/modules/TabGroupsMigrator.jsm
@@ -16,16 +16,18 @@ XPCOMUtils.defineLazyModuleGetter(this,
XPCOMUtils.defineLazyModuleGetter(this, "AsyncShutdown", "resource://gre/modules/AsyncShutdown.jsm");
XPCOMUtils.defineLazyGetter(this, "gBrowserBundle", function() {
return Services.strings.createBundle('chrome://browser/locale/browser.properties');
});
this.TabGroupsMigrator = {
+ bookmarkedGroupsPromise: null,
+
/**
* If this state contains tab groups, migrate the user's data. This means:
* - make a backup of the user's data.
* - create bookmarks of all the user's tab groups in a single folder
* - append a tab to the active window that lets the user restore background
* groups.
* - remove all the tabs hidden through tab groups from the state data.
*/
@@ -125,17 +127,53 @@ this.TabGroupsMigrator = {
return allGroupData;
},
_createBackup(stateStr) {
// TODO
},
_bookmarkAllGroupsFromState: Task.async(function*(groupData) {
- // TODO
+ // First create a folder in which to put all these bookmarks:
+ this.bookmarkedGroupsPromise = PlacesUtils.bookmarks.insert({
+ parentGuid: PlacesUtils.bookmarks.menuGuid,
+ type: PlacesUtils.bookmarks.TYPE_FOLDER,
+ index: 0,
+ title: gBrowserBundle.GetStringFromName("tabgroups.migration.tabGroupBookmarkFolderName"),
+ }).catch(Cu.reportError);
+ let tabgroupsFolder = yield this.bookmarkedGroupsPromise;
+
+ for (let [, windowGroupMap] of groupData) {
+ let windowGroups = [... windowGroupMap.values()].sort((a, b) => {
+ if (!a.anonGroupID) {
+ return -1;
+ }
+ if (!b.anonGroupID) {
+ return 1;
+ }
+ return a.anonGroupID - b.anonGroupID;
+ });
+ for (let group of windowGroups) {
+ let groupFolder = yield PlacesUtils.bookmarks.insert({
+ parentGuid: tabgroupsFolder.guid,
+ type: PlacesUtils.bookmarks.TYPE_FOLDER,
+ title: group.title ||
+ gBrowserBundle.formatStringFromName("tabgroups.migration.anonGroup", [group.anonGroupID], 1),
+ }).catch(Cu.reportError);
+
+ for (let tab of group.tabs) {
+ let entry = tab.entries[tab.index - 1];
+ yield PlacesUtils.bookmarks.insert({
+ parentGuid: groupFolder.guid,
+ title: tab.title || entry.title,
+ url: entry.url,
+ }).catch(Cu.reportError);
+ }
+ }
+ }
}),
_removeHiddenTabGroupsFromState(state, groupData) {
// TODO
},
_createBackgroundTabGroupRestorationPage(state, backgroundData) {
// TODO