OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 <include src="../uber/uber_utils.js"> | 5 <include src="../uber/uber_utils.js"> |
6 <include src="history_focus_manager.js"> | 6 <include src="history_focus_manager.js"> |
7 | 7 |
8 /////////////////////////////////////////////////////////////////////////////// | 8 /////////////////////////////////////////////////////////////////////////////// |
9 // Globals: | 9 // Globals: |
10 /** @const */ var RESULTS_PER_PAGE = 150; | 10 /** @const */ var RESULTS_PER_PAGE = 150; |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 * @param {Object} result An object containing the visit's data. | 80 * @param {Object} result An object containing the visit's data. |
81 * @param {boolean} continued Whether this visit is on the same day as the | 81 * @param {boolean} continued Whether this visit is on the same day as the |
82 * visit before it. | 82 * visit before it. |
83 * @param {HistoryModel} model The model object this entry belongs to. | 83 * @param {HistoryModel} model The model object this entry belongs to. |
84 * @constructor | 84 * @constructor |
85 */ | 85 */ |
86 function Visit(result, continued, model) { | 86 function Visit(result, continued, model) { |
87 this.model_ = model; | 87 this.model_ = model; |
88 this.title_ = result.title; | 88 this.title_ = result.title; |
89 this.url_ = result.url; | 89 this.url_ = result.url; |
| 90 this.domain_ = result.domain; |
90 this.starred_ = result.starred; | 91 this.starred_ = result.starred; |
91 this.snippet_ = result.snippet || ''; | 92 this.snippet_ = result.snippet || ''; |
92 | 93 |
93 // These identify the name and type of the device on which this visit | 94 // These identify the name and type of the device on which this visit |
94 // occurred. They will be empty if the visit occurred on the current device. | 95 // occurred. They will be empty if the visit occurred on the current device. |
95 this.deviceName = result.deviceName; | 96 this.deviceName = result.deviceName; |
96 this.deviceType = result.deviceType; | 97 this.deviceType = result.deviceType; |
97 | 98 |
98 // The ID will be set according to when the visit was displayed, not | 99 // The ID will be set according to when the visit was displayed, not |
99 // received. Set to -1 to show that it has not been set yet. | 100 // received. Set to -1 to show that it has not been set yet. |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 // Keep track of the drop down that triggered the menu, so we know | 170 // Keep track of the drop down that triggered the menu, so we know |
170 // which element to apply the command to. | 171 // which element to apply the command to. |
171 // TODO(dubroy): Ideally we'd use 'activate', but MenuButton swallows it. | 172 // TODO(dubroy): Ideally we'd use 'activate', but MenuButton swallows it. |
172 var self = this; | 173 var self = this; |
173 var setActiveVisit = function(e) { | 174 var setActiveVisit = function(e) { |
174 activeVisit = self; | 175 activeVisit = self; |
175 var menu = $('action-menu'); | 176 var menu = $('action-menu'); |
176 menu.dataset.devicename = self.deviceName; | 177 menu.dataset.devicename = self.deviceName; |
177 menu.dataset.devicetype = self.deviceType; | 178 menu.dataset.devicetype = self.deviceType; |
178 }; | 179 }; |
179 domain.textContent = this.getDomainFromURL_(this.url_); | 180 domain.textContent = this.domain_; |
180 | 181 |
181 entryBox.appendChild(time); | 182 entryBox.appendChild(time); |
182 | 183 |
183 var bookmarkSection = createElementWithClassName('div', 'bookmark-section'); | 184 var bookmarkSection = createElementWithClassName('div', 'bookmark-section'); |
184 if (this.starred_) { | 185 if (this.starred_) { |
185 bookmarkSection.classList.add('starred'); | 186 bookmarkSection.classList.add('starred'); |
186 bookmarkSection.addEventListener('click', function f(e) { | 187 bookmarkSection.addEventListener('click', function f(e) { |
187 recordUmaAction('HistoryPage_BookmarkStarClicked'); | 188 recordUmaAction('HistoryPage_BookmarkStarClicked'); |
188 bookmarkSection.classList.remove('starred'); | 189 bookmarkSection.classList.remove('starred'); |
189 chrome.send('removeBookmark', [self.url_]); | 190 chrome.send('removeBookmark', [self.url_]); |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 recordUmaAction('HistoryPage_EntryMenuRemoveFromHistory'); | 276 recordUmaAction('HistoryPage_EntryMenuRemoveFromHistory'); |
276 var self = this; | 277 var self = this; |
277 this.model_.removeVisitsFromHistory([this], function() { | 278 this.model_.removeVisitsFromHistory([this], function() { |
278 removeEntryFromView(self.domNode_); | 279 removeEntryFromView(self.domNode_); |
279 }); | 280 }); |
280 }; | 281 }; |
281 | 282 |
282 // Visit, private: ------------------------------------------------------------ | 283 // Visit, private: ------------------------------------------------------------ |
283 | 284 |
284 /** | 285 /** |
285 * Extracts and returns the domain (and subdomains) from a URL. | |
286 * @param {string} url The url. | |
287 * @return {string} The domain. An empty string is returned if no domain can | |
288 * be found. | |
289 * @private | |
290 */ | |
291 Visit.prototype.getDomainFromURL_ = function(url) { | |
292 // TODO(sergiu): Extract the domain from the C++ side and send it here. | |
293 var domain = url.replace(/^.+?:\/\//, '').match(/[^/]+/); | |
294 return domain ? domain[0] : ''; | |
295 }; | |
296 | |
297 /** | |
298 * Add child text nodes to a node such that occurrences of the specified text is | 286 * Add child text nodes to a node such that occurrences of the specified text is |
299 * highlighted. | 287 * highlighted. |
300 * @param {Node} node The node under which new text nodes will be made as | 288 * @param {Node} node The node under which new text nodes will be made as |
301 * children. | 289 * children. |
302 * @param {string} content Text to be added beneath |node| as one or more | 290 * @param {string} content Text to be added beneath |node| as one or more |
303 * text nodes. | 291 * text nodes. |
304 * @param {string} highlightText Occurences of this text inside |content| will | 292 * @param {string} highlightText Occurences of this text inside |content| will |
305 * be highlighted. | 293 * be highlighted. |
306 * @private | 294 * @private |
307 */ | 295 */ |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
368 /** | 356 /** |
369 * Returns the DOM element containing the text for a blocked visit attempt. | 357 * Returns the DOM element containing the text for a blocked visit attempt. |
370 * @return {Element} DOM representation of the visit attempt. | 358 * @return {Element} DOM representation of the visit attempt. |
371 * @private | 359 * @private |
372 */ | 360 */ |
373 Visit.prototype.getVisitAttemptDOM_ = function() { | 361 Visit.prototype.getVisitAttemptDOM_ = function() { |
374 var node = createElementWithClassName('div', 'title'); | 362 var node = createElementWithClassName('div', 'title'); |
375 node.innerHTML = loadTimeData.getStringF('blockedVisitText', | 363 node.innerHTML = loadTimeData.getStringF('blockedVisitText', |
376 this.url_, | 364 this.url_, |
377 this.id_, | 365 this.id_, |
378 this.getDomainFromURL_(this.url_)); | 366 this.domain_); |
379 return node; | 367 return node; |
380 }; | 368 }; |
381 | 369 |
382 /** | 370 /** |
383 * Set the favicon for an element. | 371 * Set the favicon for an element. |
384 * @param {Element} el The DOM element to which to add the icon. | 372 * @param {Element} el The DOM element to which to add the icon. |
385 * @private | 373 * @private |
386 */ | 374 */ |
387 Visit.prototype.addFaviconToElement_ = function(el) { | 375 Visit.prototype.addFaviconToElement_ = function(el) { |
388 var url = isMobileVersion() ? | 376 var url = isMobileVersion() ? |
389 getFaviconImageSet(this.url_, 32, 'touch-icon') : | 377 getFaviconImageSet(this.url_, 32, 'touch-icon') : |
390 getFaviconImageSet(this.url_); | 378 getFaviconImageSet(this.url_); |
391 el.style.backgroundImage = url; | 379 el.style.backgroundImage = url; |
392 }; | 380 }; |
393 | 381 |
394 /** | 382 /** |
395 * Launch a search for more history entries from the same domain. | 383 * Launch a search for more history entries from the same domain. |
396 * @private | 384 * @private |
397 */ | 385 */ |
398 Visit.prototype.showMoreFromSite_ = function() { | 386 Visit.prototype.showMoreFromSite_ = function() { |
399 recordUmaAction('HistoryPage_EntryMenuShowMoreFromSite'); | 387 recordUmaAction('HistoryPage_EntryMenuShowMoreFromSite'); |
400 historyView.setSearch(this.getDomainFromURL_(this.url_)); | 388 historyView.setSearch(this.domain_); |
401 }; | 389 }; |
402 | 390 |
403 // Visit, private, static: ---------------------------------------------------- | 391 // Visit, private, static: ---------------------------------------------------- |
404 | 392 |
405 /** | 393 /** |
406 * Quote a string so it can be used in a regular expression. | 394 * Quote a string so it can be used in a regular expression. |
407 * @param {string} str The source string. | 395 * @param {string} str The source string. |
408 * @return {string} The escaped string. | 396 * @return {string} The escaped string. |
409 * @private | 397 * @private |
410 */ | 398 */ |
(...skipping 706 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1117 * @param {Array} visits Visits received from the query results. | 1105 * @param {Array} visits Visits received from the query results. |
1118 * @param {Element} results Object where the results are added to. | 1106 * @param {Element} results Object where the results are added to. |
1119 * @private | 1107 * @private |
1120 */ | 1108 */ |
1121 HistoryView.prototype.groupVisitsByDomain_ = function(visits, results) { | 1109 HistoryView.prototype.groupVisitsByDomain_ = function(visits, results) { |
1122 var visitsByDomain = {}; | 1110 var visitsByDomain = {}; |
1123 var domains = []; | 1111 var domains = []; |
1124 | 1112 |
1125 // Group the visits into a dictionary and generate a list of domains. | 1113 // Group the visits into a dictionary and generate a list of domains. |
1126 for (var i = 0, visit; visit = visits[i]; i++) { | 1114 for (var i = 0, visit; visit = visits[i]; i++) { |
1127 var domain = visit.getDomainFromURL_(visit.url_); | 1115 var domain = visit.domain_; |
1128 if (!visitsByDomain[domain]) { | 1116 if (!visitsByDomain[domain]) { |
1129 visitsByDomain[domain] = []; | 1117 visitsByDomain[domain] = []; |
1130 domains.push(domain); | 1118 domains.push(domain); |
1131 } | 1119 } |
1132 visitsByDomain[domain].push(visit); | 1120 visitsByDomain[domain].push(visit); |
1133 } | 1121 } |
1134 var sortByVisits = function(a, b) { | 1122 var sortByVisits = function(a, b) { |
1135 return visitsByDomain[b].length - visitsByDomain[a].length; | 1123 return visitsByDomain[b].length - visitsByDomain[a].length; |
1136 }; | 1124 }; |
1137 domains.sort(sortByVisits); | 1125 domains.sort(sortByVisits); |
(...skipping 785 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1923 historyView.reload(); | 1911 historyView.reload(); |
1924 } | 1912 } |
1925 | 1913 |
1926 // Add handlers to HTML elements. | 1914 // Add handlers to HTML elements. |
1927 document.addEventListener('DOMContentLoaded', load); | 1915 document.addEventListener('DOMContentLoaded', load); |
1928 | 1916 |
1929 // This event lets us enable and disable menu items before the menu is shown. | 1917 // This event lets us enable and disable menu items before the menu is shown. |
1930 document.addEventListener('canExecute', function(e) { | 1918 document.addEventListener('canExecute', function(e) { |
1931 e.canExecute = true; | 1919 e.canExecute = true; |
1932 }); | 1920 }); |
OLD | NEW |