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

Side by Side Diff: chrome/common/extensions/docs/examples/api/tabs/inspector/tabs_api.js

Issue 9289057: Changing manifest to v2 extension samples (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Adding zip files after rebasing with master Created 8 years, 10 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 unified diff | Download patch
OLDNEW
1 <html> 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 <head> 2 // Use of this source code is governed by a BSD-style license that can be
3 <script src="jstemplate_compiled.js" type="text/javascript"></script> 3 // found in the LICENSE file.
4 <script>
5 4
6 tabs = {}; 5 tabs = {};
7 tabIds = []; 6 tabIds = [];
8 7
9 focusedWindowId = undefined; 8 focusedWindowId = undefined;
10 currentWindowId = undefined; 9 currentWindowId = undefined;
11 10
12 function bootStrap() { 11 function bootStrap() {
13 chrome.windows.getCurrent(function(currentWindow) { 12 chrome.windows.getCurrent(function(currentWindow) {
14 currentWindowId = currentWindow.id; 13 currentWindowId = currentWindow.id;
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 appendToLog('windows.onFocusChanged -- window: ' + windowId); 149 appendToLog('windows.onFocusChanged -- window: ' + windowId);
151 loadWindowList(); 150 loadWindowList();
152 }); 151 });
153 152
154 chrome.windows.onRemoved.addListener(function(windowId) { 153 chrome.windows.onRemoved.addListener(function(windowId) {
155 appendToLog('windows.onRemoved -- window: ' + windowId); 154 appendToLog('windows.onRemoved -- window: ' + windowId);
156 loadWindowList(); 155 loadWindowList();
157 }); 156 });
158 157
159 chrome.tabs.onCreated.addListener(function(tab) { 158 chrome.tabs.onCreated.addListener(function(tab) {
160 appendToLog('tabs.onCreated -- window: ' + tab.windowId + ' tab: ' + tab.id + ' title: ' + tab.title + ' index ' + tab.index + ' url ' + tab.url); 159 appendToLog(
160 'tabs.onCreated -- window: ' + tab.windowId + ' tab: ' + tab.id +
161 ' title: ' + tab.title + ' index ' + tab.index + ' url ' + tab.url);
161 loadWindowList(); 162 loadWindowList();
162 }); 163 });
163 164
164 chrome.tabs.onAttached.addListener(function(tabId, props) { 165 chrome.tabs.onAttached.addListener(function(tabId, props) {
165 appendToLog('tabs.onAttached -- window: ' + props.newWindowId + ' tab: ' + tab Id + ' index ' + props.newPosition); 166 appendToLog(
167 'tabs.onAttached -- window: ' + props.newWindowId + ' tab: ' + tabId +
168 ' index ' + props.newPosition);
166 loadWindowList(); 169 loadWindowList();
167 }); 170 });
168 171
169 chrome.tabs.onMoved.addListener(function(tabId, props) { 172 chrome.tabs.onMoved.addListener(function(tabId, props) {
170 appendToLog('tabs.onMoved -- window: ' + props.windowId + ' tab: ' + tabId + ' from ' + props.fromIndex + ' to ' + props.toIndex); 173 appendToLog(
174 'tabs.onMoved -- window: ' + props.windowId + ' tab: ' + tabId +
175 ' from ' + props.fromIndex + ' to ' + props.toIndex);
171 loadWindowList(); 176 loadWindowList();
172 }); 177 });
173 178
174 function refreshTab(tabId) { 179 function refreshTab(tabId) {
175 chrome.tabs.get(tabId, function(tab) { 180 chrome.tabs.get(tabId, function(tab) {
176 var input = new JsExprContext(tab); 181 var input = new JsExprContext(tab);
177 var output = document.getElementById('tab_' + tab.id); 182 var output = document.getElementById('tab_' + tab.id);
178 jstProcess(input, output); 183 jstProcess(input, output);
179 appendToLog('tab refreshed -- tabId: ' + tab.id + ' url: ' + tab.url); 184 appendToLog('tab refreshed -- tabId: ' + tab.id + ' url: ' + tab.url);
180 }); 185 });
181 } 186 }
182 187
183 chrome.tabs.onUpdated.addListener(function(tabId, props) { 188 chrome.tabs.onUpdated.addListener(function(tabId, props) {
184 appendToLog('tabs.onUpdated -- tab: ' + tabId + ' status ' + props.status + ' url ' + props.url); 189 appendToLog(
190 'tabs.onUpdated -- tab: ' + tabId + ' status ' + props.status +
191 ' url ' + props.url);
185 refreshTab(tabId); 192 refreshTab(tabId);
186 }); 193 });
187 194
188 chrome.tabs.onDetached.addListener(function(tabId, props) { 195 chrome.tabs.onDetached.addListener(function(tabId, props) {
189 appendToLog('tabs.onDetached -- window: ' + props.oldWindowId + ' tab: ' + tab Id + ' index ' + props.oldPosition); 196 appendToLog(
197 'tabs.onDetached -- window: ' + props.oldWindowId + ' tab: ' + tabId +
198 ' index ' + props.oldPosition);
190 loadWindowList(); 199 loadWindowList();
191 }); 200 });
192 201
193 chrome.tabs.onSelectionChanged.addListener(function(tabId, props) { 202 chrome.tabs.onSelectionChanged.addListener(function(tabId, props) {
194 appendToLog('tabs.onSelectionChanged -- window: ' + props.windowId + ' tab: ' + tabId); 203 appendToLog(
204 'tabs.onSelectionChanged -- window: ' + props.windowId + ' tab: ' +
205 tabId);
195 loadWindowList(); 206 loadWindowList();
196 }); 207 });
197 208
198 chrome.tabs.onRemoved.addListener(function(tabId) { 209 chrome.tabs.onRemoved.addListener(function(tabId) {
199 appendToLog('tabs.onRemoved -- tab: ' + tabId); 210 appendToLog('tabs.onRemoved -- tab: ' + tabId);
200 loadWindowList(); 211 loadWindowList();
201 }); 212 });
202 213
203 function createWindow() { 214 function createWindow() {
204 var args = { 215 var args = {
(...skipping 22 matching lines...) Expand all
227 } 238 }
228 } 239 }
229 240
230 function refreshWindow(windowId) { 241 function refreshWindow(windowId) {
231 chrome.windows.get(windowId, function(window) { 242 chrome.windows.get(windowId, function(window) {
232 chrome.tabs.getAllInWindow(window.id, function(tabList) { 243 chrome.tabs.getAllInWindow(window.id, function(tabList) {
233 window.tabs = tabList; 244 window.tabs = tabList;
234 var input = new JsExprContext(window); 245 var input = new JsExprContext(window);
235 var output = document.getElementById('window_' + window.id); 246 var output = document.getElementById('window_' + window.id);
236 jstProcess(input, output); 247 jstProcess(input, output);
237 appendToLog('window refreshed -- windowId: ' + window.id + ' tab count:' + window.tabs.length); 248 appendToLog(
249 'window refreshed -- windowId: ' + window.id + ' tab count:' +
250 window.tabs.length);
238 }); 251 });
239 }); 252 });
240 } 253 }
241 254
242 function updateWindowData(id) { 255 function updateWindowData(id) {
243 var retval = { 256 var retval = {
244 left: parseInt(document.getElementById('left_' + id).value), 257 left: parseInt(document.getElementById('left_' + id).value),
245 top: parseInt(document.getElementById('top_' + id).value), 258 top: parseInt(document.getElementById('top_' + id).value),
246 width: parseInt(document.getElementById('width_' + id).value), 259 width: parseInt(document.getElementById('width_' + id).value),
247 height: parseInt(document.getElementById('height_' + id).value) 260 height: parseInt(document.getElementById('height_' + id).value)
(...skipping 26 matching lines...) Expand all
274 } catch (e) { 287 } catch (e) {
275 alert(e); 288 alert(e);
276 } 289 }
277 } 290 }
278 291
279 function refreshSelectedTab(windowId) { 292 function refreshSelectedTab(windowId) {
280 chrome.tabs.getSelected(windowId, function(tab) { 293 chrome.tabs.getSelected(windowId, function(tab) {
281 var input = new JsExprContext(tab); 294 var input = new JsExprContext(tab);
282 var output = document.getElementById('tab_' + tab.id); 295 var output = document.getElementById('tab_' + tab.id);
283 jstProcess(input, output); 296 jstProcess(input, output);
284 appendToLog('selected tab refreshed -- tabId: ' + tab.id + ' url:' + tab.url ); 297 appendToLog(
298 'selected tab refreshed -- tabId: ' + tab.id + ' url:' + tab.url);
285 }); 299 });
286 } 300 }
287 301
288 </script> 302 document.addEventListener('DOMContentLoaded', function() {
289 </head> 303 bootStrap();
290 <body onload="bootStrap();"> 304 });
291 <div id="windowList">
292 <div style="background-color: #AAEEEE; margin: 4px; padding: 8px; margin: 20px" jsselect="$this"
293 jsvalues="id:'window_' + id">
294 <div style="font-style: italic; width: 80px; display: inline-block">
295 Window: <span jscontent="id"></span>
296 </div>
297 <div style="display: inline-block">
298 left: <input style="width: 60px" type="text" jsvalues="value:$this.lef t;id:'left_' + id" />
299 top: <input style="width: 60px" type="text" jsvalues="value:$this.top; id:'top_' + id" />
300 width: <input style="width: 60px" type="text" jsvalues="value:$this.wi dth;id:'width_' + id" />
301 height: <input style="width: 60px" type="text" jsvalues="value:$this.h eight;id:'height_' + id" />
302 <input type="checkbox" jsvalues="checked:focused; id:'focused_' + id" /> Focused
303 <input type="checkbox" jsvalues="checked:current; id:'current_' + id" /> Current
304 <button onclick="refreshWindow(this.jstdata);" jsvalues=".jstdata:id"> Refresh</button>
305 </div>
306 <div id="tabList">
307 <div jsselect="tabs">
308 <div style="background-color: #EEEEEE; margin: 8px; padding: 4px" j svalues="id:'tab_' + id">
309 <div style="margin: 8px">
310 <div style="font-style: italic; width: 80px; display: inline-blo ck" jscontent="'TabId: ' + id"></div>
311 <div style="width: 300px; display: inline-block">
312 index: <input style="width: 20px" type="text" jsvalues="value: $this.index;id:'index_' + id" />
313 windowId: <input style="width: 20px" type="text" jsvalues="val ue:windowId;id:'windowId_' + id" />
314 <button onclick="moveTab(this.jstdata);" jsvalues=".jstdata:id ">Move</button>
315 <button onclick="refreshTab(this.jstdata);" jsvalues=".jstdata :id">Refresh</button>
316 </div>
317 </div>
318 <div style="margin: 8px">
319 <div>
320 <div style="width: 40px; display:inline-block">title:</div>
321 <input style="width: 90%" type="text" jsvalues="value:title;id :'title_' + id" />
322 </div>
323 <div>
324 <div style="width: 40px; display:inline-block">url:</div>
325 <input style="width: 90%" type="text" jsvalues="value:url;id:' url_' + id" />
326 </div>
327 <div><input type="checkbox" jsvalues="checked:selected; id:'sele cted_' + id" /> Selected</div>
328 </div>
329 <button onclick="updateTab(this.jstdata)" jsvalues=".jstdata:id">U pdate Tab</button>
330 <button onclick="removeTab(this.jstdata);" jsvalues=".jstdata:id"> Close Tab</button>
331 </div>
332 </div>
333 </div>
334 <button onclick="updateWindow(this.jstdata);" jsvalues=".jstdata:id">Upd ate Window</button>
335 <button onclick="removeWindow(this.jstdata);" jsvalues=".jstdata:id">Clo se Window</button>
336 <button onclick="refreshSelectedTab(this.jstdata);" jsvalues=".jstdata:i d">Refresh Selected Tab</button>
337 </div>
338 </div>
339 <div style="background-color: #EEEEBB; margin: 20px; padding: 8px">
340 <h3 style="text-align: center; margin: 8px"> Create Window</h3>
341 <div style="margin: 8px">
342 <div style="width: 300px; display: inline-block">
343 left: <input style="width: 20px" type="text" id="new_window_left" />
344 top: <input style="width: 20px" type="text" id="new_window_top" />
345 width: <input style="width: 20px" type="text" id="new_window_width" />
346 height: <input style="width: 20px" type="text" id="new_window_height" />
347 </div>
348 </div>
349 <div style="margin: 8px">
350 <div>
351 <div style="width: 40px; display:inline-block">url:</div>
352 <input style="width: 90%" type="text" id="new_window_url" />
353 </div>
354 </div>
355 <button onclick="createWindow();">Create</button>
356 </div>
357 <div style="background-color: #EEEEAA; margin: 20px; padding: 8px">
358 <h3 style="text-align: center; margin: 8px"> Create Tab</h3>
359 <div style="margin: 8px">
360 <div style="width: 300px; display: inline-block">
361 index: <input style="width: 20px" type="text" id="index_new" />
362 windowId: <input style="width: 20px" type="text" id="windowId_new" />
363 <button onclick="moveTab(this.jstdata);" jsvalues=".jstdata:id">Move</ button>
364 </div>
365 </div>
366 <div style="margin: 8px">
367 <div>
368 <div style="width: 40px; display:inline-block">title:</div>
369 <input style="width: 90%" type="text" id="title_new" />
370 </div>
371 <div>
372 <div style="width: 40px; display:inline-block">url:</div>
373 <input style="width: 90%" type="text" id="url_new" />
374 </div>
375 <div><input type="checkbox" id="selected_new" /> Selected</div>
376 </div>
377 <button onclick="createTab();">Create</button>
378 </div>
379 <div style="margin: 20px;">
380 <button onclick="loadWindowList();">Refresh</button>
381 <button onclick="updateAll();">Update All</button>
382 <button onclick="moveAll();">Move All</button>
383 <button onclick="clearLog();">-->Clear Log</button>
384 <button onclick="chrome.windows.create();">New Window</button>
385 </div>
386 <div id="log" style="background-color: #EEAAEE; margin: 20px; padding: 8px">
387 </div>
388 </body>
389 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698