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

Side by Side Diff: chrome/browser/resources/sessions.js

Issue 6969016: Adding chrome://sessions webui for prototyping NTP stuff. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 6 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 | Annotate | Revision Log
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 localStrings = new LocalStrings();
6
7 // UTF8 sequence for an arrow triangle pointing down.
8 kExpandedArrow = "\u25BE";
9 // UTF8 sequence for an arrow triangle pointing right.
10 kCollapsedArrow = "\u25B8";
11
12 /**
13 * Requests the list of sessions from the backend.
14 */
15 function requestSessions() {
16 chrome.send('requestSessionList', [])
17 }
18
19 /**
20 * Expands or collapses the specified list.
21 */
22 function toggleExpandedState(div) {
23 if (div.textContent.indexOf(kExpandedArrow) != -1) {
24 div.textContent = div.textContent.replace(kExpandedArrow, kCollapsedArrow);
25 div.parentNode.querySelector(".indent").hidden = true;
26 } else {
27 div.textContent = div.textContent.replace(kCollapsedArrow, kExpandedArrow);
28 div.parentNode.querySelector(".indent").hidden = false;
29 }
30 }
31
32 /**
33 * Creates a div element to serve as an expandable/collapsable
34 * title for a list of windows or tabs.
35 */
36 function createTitleDiv(className, textContent) {
37 var div = document.createElement('div');
38 div.className = className + ' expandable';
39 div.textContent = kExpandedArrow + ' ' + textContent;
40 div.onclick = Function('toggleExpandedState(this)');
41 return div;
42 }
43
44 /**
45 * Utility function to call |transformFn| on each element of |from|
46 * and add them to a div which is then added to |container|.
47 */
48 function addItems(container, from, transformFn) {
49 var divBlock = document.createElement('div');
50 divBlock.className = 'indent';
51 for (var i = 0; i < from.length; i++) {
52 divBlock.appendChild(transformFn(from[i]));
53 }
54 container.appendChild(divBlock);
55 }
56
57 /**
58 * Transforms a tab into an HTML element.
59 */
60 function transformTab(tab) {
61 var tabItem = document.createElement('a');
62 tabItem.setAttribute('href', tab.url);
63 tabItem.textContent = tab.title;
64 tabItem.className = 'tab-link';
65 tabItem.style.backgroundImage = url('chrome://favicon/' + tab.url);
66 return tabItem;
67 }
68
69 /**
70 * Transforms a window into an HTML element.
71 */
72 function transformWindow(window) {
73 var windowDiv = document.createElement('div');
74 windowDiv.className = "window";
75 windowDiv.appendChild(createTitleDiv('windowTitle', 'Window'));
76 addItems(windowDiv, window.tabs, transformTab);
77 return windowDiv;
78 }
79
80 /**
81 * Transforms a session into an HTML element.
82 */
83 function transformSession(session) {
84 var sessionDiv = document.createElement('div');
85 sessionDiv.className = "session";
86 sessionDiv.appendChild(
87 createTitleDiv('sessionTitle', 'Session'));
88 addItems(sessionDiv, session.windows, transformWindow);
89 return sessionDiv;
90 }
91
92 /**
93 * Creates the UI for the sessions tree.
94 */
95 function createSessionTreeUI(sessionList) {
96 $('sessionsSummaryText').textContent =
97 localStrings.getStringF('sessionsCountFormat', sessionList.length);
98
99 var sessionSection = $('sessionList');
100
101 // Clear any previous list.
102 sessionSection.textContent = '';
103
104 var sectionDiv = document.createElement('div');
105 addItems(sectionDiv, sessionList, transformSession);
106 sessionSection.appendChild(sectionDiv);
107
108 $('noSessions').hidden = sessionList.length != 0;
109 }
110
111 /**
112 * Creates the UI for the "magic" list.
113 */
114 function createMagicListUI(magicList) {
115 $('magicSummaryText').textContent =
116 localStrings.getStringF('magicCountFormat', magicList.length);
117
118 var magicSection = $('magicList');
119
120 // Clear any previous list.
121 magicSection.textContent = '';
122
123 var sectionDiv = document.createElement('div');
124 addItems(sectionDiv, magicList, transformTab);
125 magicSection.appendChild(sectionDiv);
126
127 $('noMagic').hidden = magicList.length != 0;
128 }
129
130 /**
131 * Callback from backend with the list of sessions. Builds the UI.
132 * @param {array} sessionList The list of sessions.
133 * @param {array} magicList List of "interesting" tabs.
134 */
135 function updateSessionList(sessionList, magicList) {
136 createSessionTreeUI(sessionList);
137 createMagicListUI(magicList);
138 }
139
140 document.addEventListener('DOMContentLoaded', requestSessions);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698