Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: chrome/ext/background.js

Issue 29336084: Issue 2426 - Open block.html as a popup window (Closed)
Patch Set: Addressed some initial feedback Created Feb. 10, 2016, 2:18 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « blockElement.postload.js ('k') | ext/background.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/ext/background.js
diff --git a/chrome/ext/background.js b/chrome/ext/background.js
index 1e3753ab985cd10ebe6561d6283b1469aa4e2994..63a4463c985026024db47668a4c3bb4413b976d6 100644
--- a/chrome/ext/background.js
+++ b/chrome/ext/background.js
@@ -21,7 +21,7 @@
var Page = ext.Page = function(tab)
{
- this._id = tab.id;
+ this.id = tab.id;
this._url = tab.url && new URL(tab.url);
this.browserAction = new BrowserAction(tab.id);
@@ -38,7 +38,7 @@
// but sometimes we only have the tab id when we create a Page object.
// In that case we get the url from top frame of the tab, recorded by
// the onBeforeRequest handler.
- var frames = framesOfTabs[this._id];
+ var frames = framesOfTabs[this.id];
if (frames)
{
var frame = frames[0];
@@ -48,35 +48,41 @@
},
sendMessage: function(message, responseCallback)
{
- chrome.tabs.sendMessage(this._id, message, responseCallback);
+ chrome.tabs.sendMessage(this.id, message, responseCallback);
}
};
- ext._getPage = function(id)
+ ext.getPage = function(id)
{
return new Page({id: parseInt(id, 10)});
};
- ext.pages = {
- open: function(url, callback)
+ function afterTabLoaded(callback, getTab)
+ {
+ if (callback)
{
- if (callback)
+ return function(openedTab)
{
- chrome.tabs.create({url: url}, function(openedTab)
+ if (getTab)
+ openedTab = getTab(openedTab);
+
+ var onUpdated = function(tabId, changeInfo, tab)
{
- var onUpdated = function(tabId, changeInfo, tab)
+ if (tabId == openedTab.id && changeInfo.status == "complete")
{
- if (tabId == openedTab.id && changeInfo.status == "complete")
- {
- chrome.tabs.onUpdated.removeListener(onUpdated);
- callback(new Page(tab));
- }
- };
- chrome.tabs.onUpdated.addListener(onUpdated);
- });
- }
- else
- chrome.tabs.create({url: url});
+ chrome.tabs.onUpdated.removeListener(onUpdated);
+ callback(new Page(openedTab));
+ }
+ };
+ chrome.tabs.onUpdated.addListener(onUpdated);
+ };
+ }
+ }
+
+ ext.pages = {
+ open: function(url, callback)
+ {
+ chrome.tabs.create({url: url}, afterTabLoaded(callback));
},
query: function(info, callback)
{
@@ -100,7 +106,8 @@
});
},
onLoading: new ext._EventTarget(),
- onActivated: new ext._EventTarget()
+ onActivated: new ext._EventTarget(),
+ onRemoved: new ext._EventTarget()
};
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab)
@@ -138,6 +145,8 @@
function forgetTab(tabId)
{
+ ext.pages.onRemoved._dispatch(tabId);
+
ext._removeFromAllPageMaps(tabId);
delete framesOfTabs[tabId];
}
@@ -149,7 +158,7 @@
chrome.tabs.onRemoved.addListener(forgetTab);
- chrome.tabs.onActivated.addListener(details =>
+ chrome.tabs.onActivated.addListener(function(details)
{
ext.pages.onActivated._dispatch(new Page({id: details.tabId}));
});
@@ -273,7 +282,7 @@
if (tabs.length == 0)
return;
- var items = contextMenuItems.get({_id: tabs[0].id});
+ var items = contextMenuItems.get({id: tabs[0].id});
if (!items)
return;
@@ -586,4 +595,16 @@
});
});
};
+
+ /* Windows */
+ ext.windows = {
+ create: function(createData, callback)
+ {
+ function getFirstTab(createdWindow)
+ {
+ return createdWindow.tabs[0];
Sebastian Noack 2016/02/10 14:43:24 Why don't you simply pass the tab in instead of a
kzar 2016/02/11 15:20:21 Done.
+ }
+ chrome.windows.create(createData, afterTabLoaded(callback, getFirstTab));
+ }
+ };
})();
« no previous file with comments | « blockElement.postload.js ('k') | ext/background.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld