Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(82)

Unified Diff: chrome/test/data/extensions/test/TabsAPI/1/tabs_api.html

Issue 79026: added windows.getWindows() and tabs.moveTab() (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/renderer/resources/extension_process_bindings.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/test/data/extensions/test/TabsAPI/1/tabs_api.html
===================================================================
--- chrome/test/data/extensions/test/TabsAPI/1/tabs_api.html (revision 13890)
+++ chrome/test/data/extensions/test/TabsAPI/1/tabs_api.html (working copy)
@@ -2,73 +2,165 @@
<head>
<script src="jstemplate_compiled.js" type="text/javascript"></script>
<script>
-var tabs = {};
-function loadTabList() {
- chromium.tabs.getTabsForWindow(function(tabList) {
- tabs = tabList;
+tabs = {};
+tabIds = [];
+
+function loadWindowList() {
+ chromium.tabs.getWindows(undefined, function(windowList) {
+ tabs = {};
+ tabIds = [];
+ for (var i = 0; i < windowList.length; i++) {
+ for (var j = 0; j < windowList[i].tabs.length; j++) {
+ tabIds[tabIds.length] = windowList[i].tabs[j].id;
+ tabs[windowList[i].tabs[j].id] = windowList[i].tabs[j];
+ }
+ }
- var input = new JsExprContext(tabList);
- var output = document.getElementById('tabList');
+ var input = new JsExprContext(windowList);
+ var output = document.getElementById('windowList');
jstProcess(input, output);
});
}
-function getTabData(id) {
+function updateTabData(id) {
+ var retval = {
+ id: id,
+ url: document.getElementById('url_' + id).value,
+ windowId: parseInt(document.getElementById('windowId_' + id).value),
+ selected: document.getElementById('selected_' + id).value ? true : false
+ }
+
+ return retval;
+}
+
+function updateTab(id){
+ chromium.tabs.updateTab(updateTabData(id));
+}
+
+function moveTabData(id) {
+ return {
+ 'id': id,
+ 'index': parseInt(document.getElementById('index_' + id).value),
+ 'windowId': parseInt(document.getElementById('windowId_' + id).value)
+ }
+}
+function moveTab(id) {
+ chromium.tabs.moveTab(moveTabData(id));
+}
+
+function createTabData(id) {
return {
- 'id': id,
- 'index': parseInt(document.getElementById('index_' + id).value),
- 'windowId': document.getElementById('windowId_' + id).value,
- 'title': document.getElementById('title_' + id).value,
+ 'windowId': parseInt(document.getElementById('windowId_' + id).value),
'url': document.getElementById('url_' + id).value,
'selected': document.getElementById('selected_' + id).value ? true : false
}
}
-function updateTab(id){
- chromium.tabs.updateTab(getTabData(id));
-}
-
function createTab() {
- chromium.tabs.createTab(getTabData('new'));
+ chromium.tabs.createTab(createTabData('new'));
}
function updateAll() {
- for (var i = 0; i < tabs.length; i++) {
- chromium.tabs.updateTab(getTabData(tabs[i].id));
+
+ for (var i = 0; i < tabIds.length; i++) {
+ chromium.tabs.updateTab(updateTabData(tabIds[i]));
}
}
-chromium.tabs.onTabMoved.addListener(function(updateParams) {
- loadTabList();
+function moveAll() {
+ appendToLog('moving all');
+ for (var i = 0; i < tabIds.length; i++) {
+ chromium.tabs.moveTab(moveTabData(tabIds[i]));
+ }
+}
+
+function appendToLog(logLine) {
+ var log = document.getElementById('log');
+ log.innerHTML = '<div> &gt;&nbsp;' + logLine + '</div>' + log.innerHTML;
+}
+
+function clearLog() {
+ document.getElementById('log').innerHTML = '';
+}
+
+chromium.tabs.onTabMoved.addListener(function(data) {
+ appendToLog('onTabMoved: ' + data.tabId + ' from ' + data.fromIndex + ' to ' + data.toIndex);
+ loadWindowList();
});
</script>
</head>
- <body onload="loadTabList();">
- <div id="tabList">
- <div style="background-color: #EEEEEE; margin: 8px; padding: 4px" jsselect="$this">
- <div jscontent="'TabId: ' + id"></div>
- <div> index: <input style="width: 90%" type="text" jsvalues="value:$this.index;id:'index_' + id" /></div>
- <div> windowId: <input style="width: 40px" type="text" jsvalues="value:windowId;id:'windowId_' + id" /></div>
- <div> title: <input style="width: 90%" type="text" jsvalues="value:title;id:'title_' + id" /></div>
- <div> url: <input style="width: 90%" type="text" jsvalues="value:url;id:'url_' + id" /></div>
- <div jscontent="url"></div>
- <div> <input type="checkbox" jsvalues="checked:selected; id:'selected_' + id" /> Selected</div>
- <button onclick="updateTab(this.jstdata)" jsvalues=".jstdata:id">Update Tab</button>
- <button onclick="chromium.tabs.removeTab(this.jstdata);" jsvalues=".jstdata:id">Close Tab</button>
- </div>
- </div>
- <div style="background-color: #9999EE; margin: 8px; padding: 4px">
- <div> index: <input style="width: 90%" type="text" id="index_new" /></div>
- <div> windowId: <input style="width: 40px" type="text" id="windowId_new" /></div>
- <div> title: <input style="width: 90%" type="text" id="title_new" /></div>
- <div> url: <input style="width: 90%" type="text" id="url_new" /></div>
- <div> <input type="checkbox" id="selected_new" /> Selected</div>
- <button onclick="createTab();">Create Tab</button>
- </div>
- <button onclick="loadTabList();">Refresh</button>
- <button onclick="updateAll();">Update All</button>
+ <body onload="loadWindowList();">
+ <div id="windowList">
+ <div style="background-color: #AAEEEE; margin: 4px; padding: 8px; margin: 20px" jsselect="$this">
+ <div style="font-style: italic; width: 80px; display: inline-block">
+ Window: <span jscontent="id"></span>
+ </div>
+ <div style="display: inline-block">
+ left: <input style="width: 60px" type="text" jsvalues="value:$this.left;id:'left_' + id" />
+ top: <input style="width: 60px" type="text" jsvalues="value:$this.top;id:'top_' + id" />
+ width: <input style="width: 60px" type="text" jsvalues="value:$this.width;id:'width_' + id" />
+ height: <input style="width: 60px" type="text" jsvalues="value:$this.height;id:'height_' + id" />
+ <input type="checkbox" jsvalues="checked:focused; id:'focused_' + id" /> Focused
+ </div>
+ <div id="tabList">
+ <div style="background-color: #EEEEEE; margin: 8px; padding: 4px" jsselect="tabs">
+ <div style="margin: 8px">
+ <div style="font-style: italic; width: 80px; display: inline-block" jscontent="'TabId: ' + id"></div>
+ <div style="width: 300px; display: inline-block">
+ index: <input style="width: 20px" type="text" jsvalues="value:$this.index;id:'index_' + id" />
+ windowId: <input style="width: 20px" type="text" jsvalues="value:windowId;id:'windowId_' + id" />
+ <button onclick="moveTab(this.jstdata);" jsvalues=".jstdata:id">Move</button>
+ </div>
+ </div>
+ <div style="margin: 8px">
+ <div>
+ <div style="width: 40px; display:inline-block">title:</div>
+ <input style="width: 90%" type="text" jsvalues="value:title;id:'title_' + id" />
+ </div>
+ <div>
+ <div style="width: 40px; display:inline-block">url:</div>
+ <input style="width: 90%" type="text" jsvalues="value:url;id:'url_' + id" />
+ </div>
+ <div><input type="checkbox" jsvalues="checked:selected; id:'selected_' + id" /> Selected</div>
+ </div>
+ <button onclick="updateTab(this.jstdata)" jsvalues=".jstdata:id">Update Tab</button>
+ <button onclick="chromium.tabs.removeTab(this.jstdata);" jsvalues=".jstdata:id">Close Tab</button>
+ </div>
+ </div>
+ </div>
+ </div>
+ <div style="background-color: #EEEEAA; margin: 20px; padding: 8px">
+ <h3 style="text-align: center; margin: 8px"> Create Tab</h3>
+ <div style="margin: 8px">
+ <div style="width: 300px; display: inline-block">
+ index: <input style="width: 20px" type="text" id="index_new" />
+ windowId: <input style="width: 20px" type="text" id="windowId_new" />
+ <button onclick="moveTab(this.jstdata);" jsvalues=".jstdata:id">Move</button>
+ </div>
+ </div>
+ <div style="margin: 8px">
+ <div>
+ <div style="width: 40px; display:inline-block">title:</div>
+ <input style="width: 90%" type="text" id="title_new" />
+ </div>
+ <div>
+ <div style="width: 40px; display:inline-block">url:</div>
+ <input style="width: 90%" type="text" id="url_new" />
+ </div>
+ <div><input type="checkbox" id="selected_new" /> Selected</div>
+ </div>
+ <button onclick="createTab();">Create</button>
+ </div>
+ <div style="margin: 20px;">
+ <button onclick="loadWindowList();">Refresh</button>
+ <button onclick="updateAll();">Update All</button>
+ <button onclick="moveAll();">Move All</button>
+ <button onclick="clearLog();">-->Clear Log</button>
+ </div>
+ <div id="log" style="background-color: #EEAAEE; margin: 20px; padding: 8px">
+ </div>
</body>
</html>
« no previous file with comments | « chrome/renderer/resources/extension_process_bindings.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698