Skip to content
This repository has been archived by the owner on Dec 15, 2018. It is now read-only.

Commit

Permalink
Send placesLinks on getInitialState instead of initializeGrid.
Browse files Browse the repository at this point in the history
  • Loading branch information
Marina Samuel authored and oyiptong committed Nov 17, 2015
1 parent 6821596 commit 00f6aab
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 32 deletions.
35 changes: 8 additions & 27 deletions browser/base/content/remote-newtab/newTab.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,15 @@ XPCOMUtils.defineLazyModuleGetter(this, "Services",
registerEvent(data.type);
break;
case "NewTab:GetInitialState":
getInitialState();
break;
data = {};
data.windowID = window.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils).outerWindowID;
data.privateBrowsingMode = PrivateBrowsingUtils.isContentWindowPrivate(window);
// Fallthrough - more handling required.
default:
commandHandled = false;
}
return commandHandled;
return {commandHandled, data};
}

function initRemotePage(initData) {
Expand All @@ -68,9 +71,9 @@ XPCOMUtils.defineLazyModuleGetter(this, "Services",
remoteIFrame.contentDocument.addEventListener("NewTabCommand", (e) => {
// If the commands are not handled within this content frame, the command will be
// passed on to main process, in RemoteAboutNewTab.jsm
let handled = handleCommand(e.detail.command, e.detail.data);
let {handled, data} = handleCommand(e.detail.command, e.detail.data);
if (!handled) {
sendAsyncMessage(e.detail.command, e.detail.data);
sendAsyncMessage(e.detail.command, data);
}
});
registerEvent("NewTab:Observe");
Expand All @@ -95,28 +98,6 @@ XPCOMUtils.defineLazyModuleGetter(this, "Services",
});
}

/**
* Sends the initial data payload to a content IFrame so it can bootstrap
*/
function getInitialState() {
let prefs = Services.prefs;
let isPrivate = PrivateBrowsingUtils.isContentWindowPrivate(window);
let state = {
enabled: prefs.getBoolPref("browser.newtabpage.enabled"),
enhanced: prefs.getBoolPref("browser.newtabpage.enhanced"),
rows: prefs.getIntPref("browser.newtabpage.rows"),
columns: prefs.getIntPref("browser.newtabpage.columns"),
introShown: prefs.getBoolPref("browser.newtabpage.introShown"),
windowID: window.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils).outerWindowID,
privateBrowsingMode: isPrivate
};
remoteIFrame.contentWindow.postMessage({
name: "NewTab:State",
data: state
}, remoteNewTabLocation.origin);
}

addMessageListener("NewTabFrame:Init", function loadHandler(message) {
// Everything is loaded. Initialize the New Tab Page.
removeMessageListener("NewTabFrame:Init", loadHandler);
Expand Down
27 changes: 22 additions & 5 deletions browser/components/newtab/RemoteAboutNewTab.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ let RemoteAboutNewTab = {
this.pageListener.addMessageListener("NewTab:ManageEngines", this.manageEngines.bind(this));
this.pageListener.addMessageListener("NewTab:SetCurrentEngine", this.setCurrentEngine.bind(this));
this.pageListener.addMessageListener("NewTabFrame:GetInit", this.initContentFrame.bind(this));
this.pageListener.addMessageListener("NewTab:GetInitialState", this.getInitialState.bind(this));

this._addObservers();
},
Expand Down Expand Up @@ -159,17 +160,14 @@ let RemoteAboutNewTab = {
* @param {Object} message
* A RemotePageManager message.
*/
initializeGrid: Task.async(function*(message) {
let placesLinks = yield PlacesProvider.links.getLinks();

initializeGrid(message) {
RemoteNewTabUtils.links.populateCache(() => {
message.target.sendAsyncMessage("NewTab:InitializeLinks", {
links: RemoteNewTabUtils.links.getLinks(),
enhancedLinks: this.getEnhancedLinks(),
placesLinks
});
});
}),
},

/**
* Inits the content iframe with the newtab location
Expand All @@ -181,6 +179,25 @@ let RemoteAboutNewTab = {
});
},

/**
* Sends the initial data payload to a content IFrame so it can bootstrap
*/
getInitialState: Task.async(function* (message) {
let placesLinks = yield PlacesProvider.links.getLinks();
let prefs = Services.prefs;
let state = {
enabled: prefs.getBoolPref("browser.newtabpage.enabled"),
enhanced: prefs.getBoolPref("browser.newtabpage.enhanced"),
rows: prefs.getIntPref("browser.newtabpage.rows"),
columns: prefs.getIntPref("browser.newtabpage.columns"),
introShown: prefs.getBoolPref("browser.newtabpage.introShown"),
windowID: message.data.windowID,
privateBrowsingMode: message.data.privateBrowsingMode,
placesLinks
};
message.target.sendAsyncMessage("NewTab:State", state);
}),

/**
* Updates the grid by getting a new set of links.
*
Expand Down

0 comments on commit 00f6aab

Please sign in to comment.