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

Side by Side Diff: chrome/browser/resources/md_downloads/crisper.js

Issue 1846383002: MD Downloads: fix vulcanize issues by excluding higher up in the dependency tree (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: just polymer.html Created 4 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 unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/resources/md_downloads/vulcanize.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 /** 5 /**
6 * @fileoverview PromiseResolver is a helper class that allows creating a 6 * @fileoverview PromiseResolver is a helper class that allows creating a
7 * Promise that will be fulfilled (resolved or rejected) some time later. 7 * Promise that will be fulfilled (resolved or rejected) some time later.
8 * 8 *
9 * Example: 9 * Example:
10 * var resolver = new PromiseResolver(); 10 * var resolver = new PromiseResolver();
(...skipping 1413 matching lines...) Expand 10 before | Expand all | Expand 10 after
1424 var elm = document.createElement(type); 1424 var elm = document.createElement(type);
1425 elm.className = className; 1425 elm.className = className;
1426 return elm; 1426 return elm;
1427 } 1427 }
1428 1428
1429 /** 1429 /**
1430 * webkitTransitionEnd does not always fire (e.g. when animation is aborted 1430 * webkitTransitionEnd does not always fire (e.g. when animation is aborted
1431 * or when no paint happens during the animation). This function sets up 1431 * or when no paint happens during the animation). This function sets up
1432 * a timer and emulate the event if it is not fired when the timer expires. 1432 * a timer and emulate the event if it is not fired when the timer expires.
1433 * @param {!HTMLElement} el The element to watch for webkitTransitionEnd. 1433 * @param {!HTMLElement} el The element to watch for webkitTransitionEnd.
1434 * @param {number} timeOut The maximum wait time in milliseconds for the 1434 * @param {number=} opt_timeOut The maximum wait time in milliseconds for the
1435 * webkitTransitionEnd to happen. 1435 * webkitTransitionEnd to happen. If not specified, it is fetched from |el|
1436 * using the transitionDuration style value.
1436 */ 1437 */
1437 function ensureTransitionEndEvent(el, timeOut) { 1438 function ensureTransitionEndEvent(el, opt_timeOut) {
1439 if (opt_timeOut === undefined) {
1440 var style = getComputedStyle(el);
1441 opt_timeOut = parseFloat(style.transitionDuration) * 1000;
1442
1443 // Give an additional 50ms buffer for the animation to complete.
1444 opt_timeOut += 50;
1445 }
1446
1438 var fired = false; 1447 var fired = false;
1439 el.addEventListener('webkitTransitionEnd', function f(e) { 1448 el.addEventListener('webkitTransitionEnd', function f(e) {
1440 el.removeEventListener('webkitTransitionEnd', f); 1449 el.removeEventListener('webkitTransitionEnd', f);
1441 fired = true; 1450 fired = true;
1442 }); 1451 });
1443 window.setTimeout(function() { 1452 window.setTimeout(function() {
1444 if (!fired) 1453 if (!fired)
1445 cr.dispatchSimpleEvent(el, 'webkitTransitionEnd', true); 1454 cr.dispatchSimpleEvent(el, 'webkitTransitionEnd', true);
1446 }, timeOut); 1455 }, opt_timeOut);
1447 } 1456 }
1448 1457
1449 /** 1458 /**
1450 * Alias for document.scrollTop getter. 1459 * Alias for document.scrollTop getter.
1451 * @param {!HTMLDocument} doc The document node where information will be 1460 * @param {!HTMLDocument} doc The document node where information will be
1452 * queried from. 1461 * queried from.
1453 * @return {number} The Y document scroll offset. 1462 * @return {number} The Y document scroll offset.
1454 */ 1463 */
1455 function scrollTopForDocument(doc) { 1464 function scrollTopForDocument(doc) {
1456 return doc.documentElement.scrollTop || doc.body.scrollTop; 1465 return doc.documentElement.scrollTop || doc.body.scrollTop;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
1515 } 1524 }
1516 1525
1517 /** 1526 /**
1518 * Quote a string so it can be used in a regular expression. 1527 * Quote a string so it can be used in a regular expression.
1519 * @param {string} str The source string. 1528 * @param {string} str The source string.
1520 * @return {string} The escaped string. 1529 * @return {string} The escaped string.
1521 */ 1530 */
1522 function quoteString(str) { 1531 function quoteString(str) {
1523 return str.replace(/([\\\.\+\*\?\[\^\]\$\(\)\{\}\=\!\<\>\|\:])/g, '\\$1'); 1532 return str.replace(/([\\\.\+\*\?\[\^\]\$\(\)\{\}\=\!\<\>\|\:])/g, '\\$1');
1524 }; 1533 };
1525 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
1526 // Use of this source code is governed by a BSD-style license that can be
1527 // found in the LICENSE file.
1528
1529 /**
1530 * @fileoverview Assertion support.
1531 */
1532
1533 /**
1534 * Verify |condition| is truthy and return |condition| if so.
1535 * @template T
1536 * @param {T} condition A condition to check for truthiness. Note that this
1537 * may be used to test whether a value is defined or not, and we don't want
1538 * to force a cast to Boolean.
1539 * @param {string=} opt_message A message to show on failure.
1540 * @return {T} A non-null |condition|.
1541 */
1542 function assert(condition, opt_message) {
1543 if (!condition) {
1544 var message = 'Assertion failed';
1545 if (opt_message)
1546 message = message + ': ' + opt_message;
1547 var error = new Error(message);
1548 var global = function() { return this; }();
1549 if (global.traceAssertionsForTesting)
1550 console.warn(error.stack);
1551 throw error;
1552 }
1553 return condition;
1554 }
1555
1556 /**
1557 * Call this from places in the code that should never be reached.
1558 *
1559 * For example, handling all the values of enum with a switch() like this:
1560 *
1561 * function getValueFromEnum(enum) {
1562 * switch (enum) {
1563 * case ENUM_FIRST_OF_TWO:
1564 * return first
1565 * case ENUM_LAST_OF_TWO:
1566 * return last;
1567 * }
1568 * assertNotReached();
1569 * return document;
1570 * }
1571 *
1572 * This code should only be hit in the case of serious programmer error or
1573 * unexpected input.
1574 *
1575 * @param {string=} opt_message A message to show when this is hit.
1576 */
1577 function assertNotReached(opt_message) {
1578 assert(false, opt_message || 'Unreachable code hit');
1579 }
1580
1581 /**
1582 * @param {*} value The value to check.
1583 * @param {function(new: T, ...)} type A user-defined constructor.
1584 * @param {string=} opt_message A message to show when this is hit.
1585 * @return {T}
1586 * @template T
1587 */
1588 function assertInstanceof(value, type, opt_message) {
1589 // We don't use assert immediately here so that we avoid constructing an error
1590 // message if we don't have to.
1591 if (!(value instanceof type)) {
1592 assertNotReached(opt_message || 'Value ' + value +
1593 ' is not a[n] ' + (type.name || typeof type));
1594 }
1595 return value;
1596 };
1597 // Copyright 2015 The Chromium Authors. All rights reserved.
1598 // Use of this source code is governed by a BSD-style license that can be
1599 // found in the LICENSE file.
1600
1601 cr.define('downloads', function() {
1602 /**
1603 * @param {string} chromeSendName
1604 * @return {function(string):void} A chrome.send() callback with curried name.
1605 */
1606 function chromeSendWithId(chromeSendName) {
1607 return function(id) { chrome.send(chromeSendName, [id]); };
1608 }
1609
1610 /** @constructor */
1611 function ActionService() {
1612 /** @private {Array<string>} */
1613 this.searchTerms_ = [];
1614 }
1615
1616 /**
1617 * @param {string} s
1618 * @return {string} |s| without whitespace at the beginning or end.
1619 */
1620 function trim(s) { return s.trim(); }
1621
1622 /**
1623 * @param {string|undefined} value
1624 * @return {boolean} Whether |value| is truthy.
1625 */
1626 function truthy(value) { return !!value; }
1627
1628 /**
1629 * @param {string} searchText Input typed by the user into a search box.
1630 * @return {Array<string>} A list of terms extracted from |searchText|.
1631 */
1632 ActionService.splitTerms = function(searchText) {
1633 // Split quoted terms (e.g., 'The "lazy" dog' => ['The', 'lazy', 'dog']).
1634 return searchText.split(/"([^"]*)"/).map(trim).filter(truthy);
1635 };
1636
1637 ActionService.prototype = {
1638 /** @param {string} id ID of the download to cancel. */
1639 cancel: chromeSendWithId('cancel'),
1640
1641 /** Instructs the browser to clear all finished downloads. */
1642 clearAll: function() {
1643 if (loadTimeData.getBoolean('allowDeletingHistory')) {
1644 chrome.send('clearAll');
1645 this.search('');
1646 }
1647 },
1648
1649 /** @param {string} id ID of the dangerous download to discard. */
1650 discardDangerous: chromeSendWithId('discardDangerous'),
1651
1652 /** @param {string} url URL of a file to download. */
1653 download: function(url) {
1654 var a = document.createElement('a');
1655 a.href = url;
1656 a.setAttribute('download', '');
1657 a.click();
1658 },
1659
1660 /** @param {string} id ID of the download that the user started dragging. */
1661 drag: chromeSendWithId('drag'),
1662
1663 /** Loads more downloads with the current search terms. */
1664 loadMore: function() {
1665 chrome.send('getDownloads', this.searchTerms_);
1666 },
1667
1668 /**
1669 * @return {boolean} Whether the user is currently searching for downloads
1670 * (i.e. has a non-empty search term).
1671 */
1672 isSearching: function() {
1673 return this.searchTerms_.length > 0;
1674 },
1675
1676 /** Opens the current local destination for downloads. */
1677 openDownloadsFolder: chrome.send.bind(chrome, 'openDownloadsFolder'),
1678
1679 /**
1680 * @param {string} id ID of the download to run locally on the user's box.
1681 */
1682 openFile: chromeSendWithId('openFile'),
1683
1684 /** @param {string} id ID the of the progressing download to pause. */
1685 pause: chromeSendWithId('pause'),
1686
1687 /** @param {string} id ID of the finished download to remove. */
1688 remove: chromeSendWithId('remove'),
1689
1690 /** @param {string} id ID of the paused download to resume. */
1691 resume: chromeSendWithId('resume'),
1692
1693 /**
1694 * @param {string} id ID of the dangerous download to save despite
1695 * warnings.
1696 */
1697 saveDangerous: chromeSendWithId('saveDangerous'),
1698
1699 /** @param {string} searchText What to search for. */
1700 search: function(searchText) {
1701 var searchTerms = ActionService.splitTerms(searchText);
1702 var sameTerms = searchTerms.length == this.searchTerms_.length;
1703
1704 for (var i = 0; sameTerms && i < searchTerms.length; ++i) {
1705 if (searchTerms[i] != this.searchTerms_[i])
1706 sameTerms = false;
1707 }
1708
1709 if (sameTerms)
1710 return;
1711
1712 this.searchTerms_ = searchTerms;
1713 this.loadMore();
1714 },
1715
1716 /**
1717 * Shows the local folder a finished download resides in.
1718 * @param {string} id ID of the download to show.
1719 */
1720 show: chromeSendWithId('show'),
1721
1722 /** Undo download removal. */
1723 undo: chrome.send.bind(chrome, 'undo'),
1724 };
1725
1726 cr.addSingletonGetter(ActionService);
1727
1728 return {ActionService: ActionService};
1729 });
1730 // Copyright 2015 The Chromium Authors. All rights reserved.
1731 // Use of this source code is governed by a BSD-style license that can be
1732 // found in the LICENSE file.
1733
1734 cr.define('downloads', function() {
1735 /**
1736 * Explains why a download is in DANGEROUS state.
1737 * @enum {string}
1738 */
1739 var DangerType = {
1740 NOT_DANGEROUS: 'NOT_DANGEROUS',
1741 DANGEROUS_FILE: 'DANGEROUS_FILE',
1742 DANGEROUS_URL: 'DANGEROUS_URL',
1743 DANGEROUS_CONTENT: 'DANGEROUS_CONTENT',
1744 UNCOMMON_CONTENT: 'UNCOMMON_CONTENT',
1745 DANGEROUS_HOST: 'DANGEROUS_HOST',
1746 POTENTIALLY_UNWANTED: 'POTENTIALLY_UNWANTED',
1747 };
1748
1749 /**
1750 * The states a download can be in. These correspond to states defined in
1751 * DownloadsDOMHandler::CreateDownloadItemValue
1752 * @enum {string}
1753 */
1754 var States = {
1755 IN_PROGRESS: 'IN_PROGRESS',
1756 CANCELLED: 'CANCELLED',
1757 COMPLETE: 'COMPLETE',
1758 PAUSED: 'PAUSED',
1759 DANGEROUS: 'DANGEROUS',
1760 INTERRUPTED: 'INTERRUPTED',
1761 };
1762
1763 return {
1764 DangerType: DangerType,
1765 States: States,
1766 };
1767 });
1768 // Copyright 2014 The Chromium Authors. All rights reserved.
1769 // Use of this source code is governed by a BSD-style license that can be
1770 // found in the LICENSE file.
1771
1772 // Action links are elements that are used to perform an in-page navigation or
1773 // action (e.g. showing a dialog).
1774 //
1775 // They look like normal anchor (<a>) tags as their text color is blue. However,
1776 // they're subtly different as they're not initially underlined (giving users a
1777 // clue that underlined links navigate while action links don't).
1778 //
1779 // Action links look very similar to normal links when hovered (hand cursor,
1780 // underlined). This gives the user an idea that clicking this link will do
1781 // something similar to navigation but in the same page.
1782 //
1783 // They can be created in JavaScript like this:
1784 //
1785 // var link = document.createElement('a', 'action-link'); // Note second arg.
1786 //
1787 // or with a constructor like this:
1788 //
1789 // var link = new ActionLink();
1790 //
1791 // They can be used easily from HTML as well, like so:
1792 //
1793 // <a is="action-link">Click me!</a>
1794 //
1795 // NOTE: <action-link> and document.createElement('action-link') don't work.
1796
1797 /**
1798 * @constructor
1799 * @extends {HTMLAnchorElement}
1800 */
1801 var ActionLink = document.registerElement('action-link', {
1802 prototype: {
1803 __proto__: HTMLAnchorElement.prototype,
1804
1805 /** @this {ActionLink} */
1806 createdCallback: function() {
1807 // Action links can start disabled (e.g. <a is="action-link" disabled>).
1808 this.tabIndex = this.disabled ? -1 : 0;
1809
1810 if (!this.hasAttribute('role'))
1811 this.setAttribute('role', 'link');
1812
1813 this.addEventListener('keydown', function(e) {
1814 if (!this.disabled && e.keyIdentifier == 'Enter' && !this.href) {
1815 // Schedule a click asynchronously because other 'keydown' handlers
1816 // may still run later (e.g. document.addEventListener('keydown')).
1817 // Specifically options dialogs break when this timeout isn't here.
1818 // NOTE: this affects the "trusted" state of the ensuing click. I
1819 // haven't found anything that breaks because of this (yet).
1820 window.setTimeout(this.click.bind(this), 0);
1821 }
1822 });
1823
1824 function preventDefault(e) {
1825 e.preventDefault();
1826 }
1827
1828 function removePreventDefault() {
1829 document.removeEventListener('selectstart', preventDefault);
1830 document.removeEventListener('mouseup', removePreventDefault);
1831 }
1832
1833 this.addEventListener('mousedown', function() {
1834 // This handlers strives to match the behavior of <a href="...">.
1835
1836 // While the mouse is down, prevent text selection from dragging.
1837 document.addEventListener('selectstart', preventDefault);
1838 document.addEventListener('mouseup', removePreventDefault);
1839
1840 // If focus started via mouse press, don't show an outline.
1841 if (document.activeElement != this)
1842 this.classList.add('no-outline');
1843 });
1844
1845 this.addEventListener('blur', function() {
1846 this.classList.remove('no-outline');
1847 });
1848 },
1849
1850 /** @type {boolean} */
1851 set disabled(disabled) {
1852 if (disabled)
1853 HTMLAnchorElement.prototype.setAttribute.call(this, 'disabled', '');
1854 else
1855 HTMLAnchorElement.prototype.removeAttribute.call(this, 'disabled');
1856 this.tabIndex = disabled ? -1 : 0;
1857 },
1858 get disabled() {
1859 return this.hasAttribute('disabled');
1860 },
1861
1862 /** @override */
1863 setAttribute: function(attr, val) {
1864 if (attr.toLowerCase() == 'disabled')
1865 this.disabled = true;
1866 else
1867 HTMLAnchorElement.prototype.setAttribute.apply(this, arguments);
1868 },
1869
1870 /** @override */
1871 removeAttribute: function(attr) {
1872 if (attr.toLowerCase() == 'disabled')
1873 this.disabled = false;
1874 else
1875 HTMLAnchorElement.prototype.removeAttribute.apply(this, arguments);
1876 },
1877 },
1878
1879 extends: 'a',
1880 });
1881 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
1882 // Use of this source code is governed by a BSD-style license that can be
1883 // found in the LICENSE file.
1884
1885 // <include src="../../../../ui/webui/resources/js/i18n_template_no_process.js">
1886
1887 i18nTemplate.process(document, loadTimeData);
1888 /** 1534 /**
1889 * `IronResizableBehavior` is a behavior that can be used in Polymer elements to 1535 * `IronResizableBehavior` is a behavior that can be used in Polymer elements to
1890 * coordinate the flow of resize events between "resizers" (elements that cont rol the 1536 * coordinate the flow of resize events between "resizers" (elements that cont rol the
1891 * size or hidden state of their children) and "resizables" (elements that nee d to be 1537 * size or hidden state of their children) and "resizables" (elements that nee d to be
1892 * notified when they are resized or un-hidden by their parents in order to ta ke 1538 * notified when they are resized or un-hidden by their parents in order to ta ke
1893 * action on their new measurements). 1539 * action on their new measurements).
1894 * 1540 *
1895 * Elements that perform measurement should add the `IronResizableBehavior` be havior to 1541 * Elements that perform measurement should add the `IronResizableBehavior` be havior to
1896 * their element definition and listen for the `iron-resize` event on themselv es. 1542 * their element definition and listen for the `iron-resize` event on themselv es.
1897 * This event will be fired when they become showing after having been hidden, 1543 * This event will be fired when they become showing after having been hidden,
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
2138 */ 1784 */
2139 var ARROW_KEY = /^arrow/; 1785 var ARROW_KEY = /^arrow/;
2140 1786
2141 /** 1787 /**
2142 * Matches space keys everywhere (notably including IE10's exceptional name 1788 * Matches space keys everywhere (notably including IE10's exceptional name
2143 * `spacebar`). 1789 * `spacebar`).
2144 */ 1790 */
2145 var SPACE_KEY = /^space(bar)?/; 1791 var SPACE_KEY = /^space(bar)?/;
2146 1792
2147 /** 1793 /**
1794 * Matches ESC key.
1795 *
1796 * Value from: http://w3c.github.io/uievents-key/#key-Escape
1797 */
1798 var ESC_KEY = /^escape$/;
1799
1800 /**
2148 * Transforms the key. 1801 * Transforms the key.
2149 * @param {string} key The KeyBoardEvent.key 1802 * @param {string} key The KeyBoardEvent.key
2150 * @param {Boolean} [noSpecialChars] Limits the transformation to 1803 * @param {Boolean} [noSpecialChars] Limits the transformation to
2151 * alpha-numeric characters. 1804 * alpha-numeric characters.
2152 */ 1805 */
2153 function transformKey(key, noSpecialChars) { 1806 function transformKey(key, noSpecialChars) {
2154 var validKey = ''; 1807 var validKey = '';
2155 if (key) { 1808 if (key) {
2156 var lKey = key.toLowerCase(); 1809 var lKey = key.toLowerCase();
2157 if (lKey === ' ' || SPACE_KEY.test(lKey)) { 1810 if (lKey === ' ' || SPACE_KEY.test(lKey)) {
2158 validKey = 'space'; 1811 validKey = 'space';
1812 } else if (ESC_KEY.test(lKey)) {
1813 validKey = 'esc';
2159 } else if (lKey.length == 1) { 1814 } else if (lKey.length == 1) {
2160 if (!noSpecialChars || KEY_CHAR.test(lKey)) { 1815 if (!noSpecialChars || KEY_CHAR.test(lKey)) {
2161 validKey = lKey; 1816 validKey = lKey;
2162 } 1817 }
2163 } else if (ARROW_KEY.test(lKey)) { 1818 } else if (ARROW_KEY.test(lKey)) {
2164 validKey = lKey.replace('arrow', ''); 1819 validKey = lKey.replace('arrow', '');
2165 } else if (lKey == 'multiply') { 1820 } else if (lKey == 'multiply') {
2166 // numpad '*' can map to Multiply on IE/Windows 1821 // numpad '*' can map to Multiply on IE/Windows
2167 validKey = '*'; 1822 validKey = '*';
2168 } else { 1823 } else {
(...skipping 23 matching lines...) Expand all
2192 if (Number(keyCode)) { 1847 if (Number(keyCode)) {
2193 if (keyCode >= 65 && keyCode <= 90) { 1848 if (keyCode >= 65 && keyCode <= 90) {
2194 // ascii a-z 1849 // ascii a-z
2195 // lowercase is 32 offset from uppercase 1850 // lowercase is 32 offset from uppercase
2196 validKey = String.fromCharCode(32 + keyCode); 1851 validKey = String.fromCharCode(32 + keyCode);
2197 } else if (keyCode >= 112 && keyCode <= 123) { 1852 } else if (keyCode >= 112 && keyCode <= 123) {
2198 // function keys f1-f12 1853 // function keys f1-f12
2199 validKey = 'f' + (keyCode - 112); 1854 validKey = 'f' + (keyCode - 112);
2200 } else if (keyCode >= 48 && keyCode <= 57) { 1855 } else if (keyCode >= 48 && keyCode <= 57) {
2201 // top 0-9 keys 1856 // top 0-9 keys
2202 validKey = String(48 - keyCode); 1857 validKey = String(keyCode - 48);
2203 } else if (keyCode >= 96 && keyCode <= 105) { 1858 } else if (keyCode >= 96 && keyCode <= 105) {
2204 // num pad 0-9 1859 // num pad 0-9
2205 validKey = String(96 - keyCode); 1860 validKey = String(keyCode - 96);
2206 } else { 1861 } else {
2207 validKey = KEY_CODE[keyCode]; 1862 validKey = KEY_CODE[keyCode];
2208 } 1863 }
2209 } 1864 }
2210 return validKey; 1865 return validKey;
2211 } 1866 }
2212 1867
2213 /** 1868 /**
2214 * Calculates the normalized key for a KeyboardEvent. 1869 * Calculates the normalized key for a KeyboardEvent.
2215 * @param {KeyboardEvent} keyEvent 1870 * @param {KeyboardEvent} keyEvent
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
2360 2015
2361 /** 2016 /**
2362 * When called, will remove all imperatively-added key bindings. 2017 * When called, will remove all imperatively-added key bindings.
2363 */ 2018 */
2364 removeOwnKeyBindings: function() { 2019 removeOwnKeyBindings: function() {
2365 this._imperativeKeyBindings = {}; 2020 this._imperativeKeyBindings = {};
2366 this._prepKeyBindings(); 2021 this._prepKeyBindings();
2367 this._resetKeyEventListeners(); 2022 this._resetKeyEventListeners();
2368 }, 2023 },
2369 2024
2025 /**
2026 * Returns true if a keyboard event matches `eventString`.
2027 *
2028 * @param {KeyboardEvent} event
2029 * @param {string} eventString
2030 * @return {boolean}
2031 */
2370 keyboardEventMatchesKeys: function(event, eventString) { 2032 keyboardEventMatchesKeys: function(event, eventString) {
2371 var keyCombos = parseEventString(eventString); 2033 var keyCombos = parseEventString(eventString);
2372 for (var i = 0; i < keyCombos.length; ++i) { 2034 for (var i = 0; i < keyCombos.length; ++i) {
2373 if (keyComboMatchesEvent(keyCombos[i], event)) { 2035 if (keyComboMatchesEvent(keyCombos[i], event)) {
2374 return true; 2036 return true;
2375 } 2037 }
2376 } 2038 }
2377 return false; 2039 return false;
2378 }, 2040 },
2379 2041
(...skipping 1712 matching lines...) Expand 10 before | Expand all | Expand 10 after
4092 this._focusPhysicalItem(this._focusedIndex + 1); 3754 this._focusPhysicalItem(this._focusedIndex + 1);
4093 }, 3755 },
4094 3756
4095 _didEnter: function(e) { 3757 _didEnter: function(e) {
4096 this._focusPhysicalItem(this._focusedIndex); 3758 this._focusPhysicalItem(this._focusedIndex);
4097 this._selectionHandler(e.detail.keyboardEvent); 3759 this._selectionHandler(e.detail.keyboardEvent);
4098 } 3760 }
4099 }); 3761 });
4100 3762
4101 })(); 3763 })();
3764 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
3765 // Use of this source code is governed by a BSD-style license that can be
3766 // found in the LICENSE file.
3767
3768 /**
3769 * @fileoverview Assertion support.
3770 */
3771
3772 /**
3773 * Verify |condition| is truthy and return |condition| if so.
3774 * @template T
3775 * @param {T} condition A condition to check for truthiness. Note that this
3776 * may be used to test whether a value is defined or not, and we don't want
3777 * to force a cast to Boolean.
3778 * @param {string=} opt_message A message to show on failure.
3779 * @return {T} A non-null |condition|.
3780 */
3781 function assert(condition, opt_message) {
3782 if (!condition) {
3783 var message = 'Assertion failed';
3784 if (opt_message)
3785 message = message + ': ' + opt_message;
3786 var error = new Error(message);
3787 var global = function() { return this; }();
3788 if (global.traceAssertionsForTesting)
3789 console.warn(error.stack);
3790 throw error;
3791 }
3792 return condition;
3793 }
3794
3795 /**
3796 * Call this from places in the code that should never be reached.
3797 *
3798 * For example, handling all the values of enum with a switch() like this:
3799 *
3800 * function getValueFromEnum(enum) {
3801 * switch (enum) {
3802 * case ENUM_FIRST_OF_TWO:
3803 * return first
3804 * case ENUM_LAST_OF_TWO:
3805 * return last;
3806 * }
3807 * assertNotReached();
3808 * return document;
3809 * }
3810 *
3811 * This code should only be hit in the case of serious programmer error or
3812 * unexpected input.
3813 *
3814 * @param {string=} opt_message A message to show when this is hit.
3815 */
3816 function assertNotReached(opt_message) {
3817 assert(false, opt_message || 'Unreachable code hit');
3818 }
3819
3820 /**
3821 * @param {*} value The value to check.
3822 * @param {function(new: T, ...)} type A user-defined constructor.
3823 * @param {string=} opt_message A message to show when this is hit.
3824 * @return {T}
3825 * @template T
3826 */
3827 function assertInstanceof(value, type, opt_message) {
3828 // We don't use assert immediately here so that we avoid constructing an error
3829 // message if we don't have to.
3830 if (!(value instanceof type)) {
3831 assertNotReached(opt_message || 'Value ' + value +
3832 ' is not a[n] ' + (type.name || typeof type));
3833 }
3834 return value;
3835 };
3836 // Copyright 2015 The Chromium Authors. All rights reserved.
3837 // Use of this source code is governed by a BSD-style license that can be
3838 // found in the LICENSE file.
3839
3840 cr.define('downloads', function() {
3841 /**
3842 * @param {string} chromeSendName
3843 * @return {function(string):void} A chrome.send() callback with curried name.
3844 */
3845 function chromeSendWithId(chromeSendName) {
3846 return function(id) { chrome.send(chromeSendName, [id]); };
3847 }
3848
3849 /** @constructor */
3850 function ActionService() {
3851 /** @private {Array<string>} */
3852 this.searchTerms_ = [];
3853 }
3854
3855 /**
3856 * @param {string} s
3857 * @return {string} |s| without whitespace at the beginning or end.
3858 */
3859 function trim(s) { return s.trim(); }
3860
3861 /**
3862 * @param {string|undefined} value
3863 * @return {boolean} Whether |value| is truthy.
3864 */
3865 function truthy(value) { return !!value; }
3866
3867 /**
3868 * @param {string} searchText Input typed by the user into a search box.
3869 * @return {Array<string>} A list of terms extracted from |searchText|.
3870 */
3871 ActionService.splitTerms = function(searchText) {
3872 // Split quoted terms (e.g., 'The "lazy" dog' => ['The', 'lazy', 'dog']).
3873 return searchText.split(/"([^"]*)"/).map(trim).filter(truthy);
3874 };
3875
3876 ActionService.prototype = {
3877 /** @param {string} id ID of the download to cancel. */
3878 cancel: chromeSendWithId('cancel'),
3879
3880 /** Instructs the browser to clear all finished downloads. */
3881 clearAll: function() {
3882 if (loadTimeData.getBoolean('allowDeletingHistory')) {
3883 chrome.send('clearAll');
3884 this.search('');
3885 }
3886 },
3887
3888 /** @param {string} id ID of the dangerous download to discard. */
3889 discardDangerous: chromeSendWithId('discardDangerous'),
3890
3891 /** @param {string} url URL of a file to download. */
3892 download: function(url) {
3893 var a = document.createElement('a');
3894 a.href = url;
3895 a.setAttribute('download', '');
3896 a.click();
3897 },
3898
3899 /** @param {string} id ID of the download that the user started dragging. */
3900 drag: chromeSendWithId('drag'),
3901
3902 /** Loads more downloads with the current search terms. */
3903 loadMore: function() {
3904 chrome.send('getDownloads', this.searchTerms_);
3905 },
3906
3907 /**
3908 * @return {boolean} Whether the user is currently searching for downloads
3909 * (i.e. has a non-empty search term).
3910 */
3911 isSearching: function() {
3912 return this.searchTerms_.length > 0;
3913 },
3914
3915 /** Opens the current local destination for downloads. */
3916 openDownloadsFolder: chrome.send.bind(chrome, 'openDownloadsFolder'),
3917
3918 /**
3919 * @param {string} id ID of the download to run locally on the user's box.
3920 */
3921 openFile: chromeSendWithId('openFile'),
3922
3923 /** @param {string} id ID the of the progressing download to pause. */
3924 pause: chromeSendWithId('pause'),
3925
3926 /** @param {string} id ID of the finished download to remove. */
3927 remove: chromeSendWithId('remove'),
3928
3929 /** @param {string} id ID of the paused download to resume. */
3930 resume: chromeSendWithId('resume'),
3931
3932 /**
3933 * @param {string} id ID of the dangerous download to save despite
3934 * warnings.
3935 */
3936 saveDangerous: chromeSendWithId('saveDangerous'),
3937
3938 /** @param {string} searchText What to search for. */
3939 search: function(searchText) {
3940 var searchTerms = ActionService.splitTerms(searchText);
3941 var sameTerms = searchTerms.length == this.searchTerms_.length;
3942
3943 for (var i = 0; sameTerms && i < searchTerms.length; ++i) {
3944 if (searchTerms[i] != this.searchTerms_[i])
3945 sameTerms = false;
3946 }
3947
3948 if (sameTerms)
3949 return;
3950
3951 this.searchTerms_ = searchTerms;
3952 this.loadMore();
3953 },
3954
3955 /**
3956 * Shows the local folder a finished download resides in.
3957 * @param {string} id ID of the download to show.
3958 */
3959 show: chromeSendWithId('show'),
3960
3961 /** Undo download removal. */
3962 undo: chrome.send.bind(chrome, 'undo'),
3963 };
3964
3965 cr.addSingletonGetter(ActionService);
3966
3967 return {ActionService: ActionService};
3968 });
3969 // Copyright 2015 The Chromium Authors. All rights reserved.
3970 // Use of this source code is governed by a BSD-style license that can be
3971 // found in the LICENSE file.
3972
3973 cr.define('downloads', function() {
3974 /**
3975 * Explains why a download is in DANGEROUS state.
3976 * @enum {string}
3977 */
3978 var DangerType = {
3979 NOT_DANGEROUS: 'NOT_DANGEROUS',
3980 DANGEROUS_FILE: 'DANGEROUS_FILE',
3981 DANGEROUS_URL: 'DANGEROUS_URL',
3982 DANGEROUS_CONTENT: 'DANGEROUS_CONTENT',
3983 UNCOMMON_CONTENT: 'UNCOMMON_CONTENT',
3984 DANGEROUS_HOST: 'DANGEROUS_HOST',
3985 POTENTIALLY_UNWANTED: 'POTENTIALLY_UNWANTED',
3986 };
3987
3988 /**
3989 * The states a download can be in. These correspond to states defined in
3990 * DownloadsDOMHandler::CreateDownloadItemValue
3991 * @enum {string}
3992 */
3993 var States = {
3994 IN_PROGRESS: 'IN_PROGRESS',
3995 CANCELLED: 'CANCELLED',
3996 COMPLETE: 'COMPLETE',
3997 PAUSED: 'PAUSED',
3998 DANGEROUS: 'DANGEROUS',
3999 INTERRUPTED: 'INTERRUPTED',
4000 };
4001
4002 return {
4003 DangerType: DangerType,
4004 States: States,
4005 };
4006 });
4007 // Copyright 2014 The Chromium Authors. All rights reserved.
4008 // Use of this source code is governed by a BSD-style license that can be
4009 // found in the LICENSE file.
4010
4011 // Action links are elements that are used to perform an in-page navigation or
4012 // action (e.g. showing a dialog).
4013 //
4014 // They look like normal anchor (<a>) tags as their text color is blue. However,
4015 // they're subtly different as they're not initially underlined (giving users a
4016 // clue that underlined links navigate while action links don't).
4017 //
4018 // Action links look very similar to normal links when hovered (hand cursor,
4019 // underlined). This gives the user an idea that clicking this link will do
4020 // something similar to navigation but in the same page.
4021 //
4022 // They can be created in JavaScript like this:
4023 //
4024 // var link = document.createElement('a', 'action-link'); // Note second arg.
4025 //
4026 // or with a constructor like this:
4027 //
4028 // var link = new ActionLink();
4029 //
4030 // They can be used easily from HTML as well, like so:
4031 //
4032 // <a is="action-link">Click me!</a>
4033 //
4034 // NOTE: <action-link> and document.createElement('action-link') don't work.
4035
4036 /**
4037 * @constructor
4038 * @extends {HTMLAnchorElement}
4039 */
4040 var ActionLink = document.registerElement('action-link', {
4041 prototype: {
4042 __proto__: HTMLAnchorElement.prototype,
4043
4044 /** @this {ActionLink} */
4045 createdCallback: function() {
4046 // Action links can start disabled (e.g. <a is="action-link" disabled>).
4047 this.tabIndex = this.disabled ? -1 : 0;
4048
4049 if (!this.hasAttribute('role'))
4050 this.setAttribute('role', 'link');
4051
4052 this.addEventListener('keydown', function(e) {
4053 if (!this.disabled && e.keyIdentifier == 'Enter' && !this.href) {
4054 // Schedule a click asynchronously because other 'keydown' handlers
4055 // may still run later (e.g. document.addEventListener('keydown')).
4056 // Specifically options dialogs break when this timeout isn't here.
4057 // NOTE: this affects the "trusted" state of the ensuing click. I
4058 // haven't found anything that breaks because of this (yet).
4059 window.setTimeout(this.click.bind(this), 0);
4060 }
4061 });
4062
4063 function preventDefault(e) {
4064 e.preventDefault();
4065 }
4066
4067 function removePreventDefault() {
4068 document.removeEventListener('selectstart', preventDefault);
4069 document.removeEventListener('mouseup', removePreventDefault);
4070 }
4071
4072 this.addEventListener('mousedown', function() {
4073 // This handlers strives to match the behavior of <a href="...">.
4074
4075 // While the mouse is down, prevent text selection from dragging.
4076 document.addEventListener('selectstart', preventDefault);
4077 document.addEventListener('mouseup', removePreventDefault);
4078
4079 // If focus started via mouse press, don't show an outline.
4080 if (document.activeElement != this)
4081 this.classList.add('no-outline');
4082 });
4083
4084 this.addEventListener('blur', function() {
4085 this.classList.remove('no-outline');
4086 });
4087 },
4088
4089 /** @type {boolean} */
4090 set disabled(disabled) {
4091 if (disabled)
4092 HTMLAnchorElement.prototype.setAttribute.call(this, 'disabled', '');
4093 else
4094 HTMLAnchorElement.prototype.removeAttribute.call(this, 'disabled');
4095 this.tabIndex = disabled ? -1 : 0;
4096 },
4097 get disabled() {
4098 return this.hasAttribute('disabled');
4099 },
4100
4101 /** @override */
4102 setAttribute: function(attr, val) {
4103 if (attr.toLowerCase() == 'disabled')
4104 this.disabled = true;
4105 else
4106 HTMLAnchorElement.prototype.setAttribute.apply(this, arguments);
4107 },
4108
4109 /** @override */
4110 removeAttribute: function(attr) {
4111 if (attr.toLowerCase() == 'disabled')
4112 this.disabled = false;
4113 else
4114 HTMLAnchorElement.prototype.removeAttribute.apply(this, arguments);
4115 },
4116 },
4117
4118 extends: 'a',
4119 });
4102 (function() { 4120 (function() {
4103 4121
4104 // monostate data 4122 // monostate data
4105 var metaDatas = {}; 4123 var metaDatas = {};
4106 var metaArrays = {}; 4124 var metaArrays = {};
4107 var singleton = null; 4125 var singleton = null;
4108 4126
4109 Polymer.IronMeta = Polymer({ 4127 Polymer.IronMeta = Polymer({
4110 4128
4111 is: 'iron-meta', 4129 is: 'iron-meta',
(...skipping 5828 matching lines...) Expand 10 before | Expand all | Expand 10 after
9940 You can use custom validators that implement `Polymer.IronValidatorBehavior` wit h `<iron-input>`. 9958 You can use custom validators that implement `Polymer.IronValidatorBehavior` wit h `<iron-input>`.
9941 9959
9942 <input is="iron-input" validator="my-custom-validator"> 9960 <input is="iron-input" validator="my-custom-validator">
9943 9961
9944 ### Stopping invalid input 9962 ### Stopping invalid input
9945 9963
9946 It may be desirable to only allow users to enter certain characters. You can use the 9964 It may be desirable to only allow users to enter certain characters. You can use the
9947 `prevent-invalid-input` and `allowed-pattern` attributes together to accomplish this. This feature 9965 `prevent-invalid-input` and `allowed-pattern` attributes together to accomplish this. This feature
9948 is separate from validation, and `allowed-pattern` does not affect how the input is validated. 9966 is separate from validation, and `allowed-pattern` does not affect how the input is validated.
9949 9967
9950 <!-- only allow characters that match [0-9] --> 9968 \x3c!-- only allow characters that match [0-9] --\x3e
9951 <input is="iron-input" prevent-invalid-input allowed-pattern="[0-9]"> 9969 <input is="iron-input" prevent-invalid-input allowed-pattern="[0-9]">
9952 9970
9953 @hero hero.svg 9971 @hero hero.svg
9954 @demo demo/index.html 9972 @demo demo/index.html
9955 */ 9973 */
9956 9974
9957 Polymer({ 9975 Polymer({
9958 9976
9959 is: 'iron-input', 9977 is: 'iron-input',
9960 9978
(...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after
10470 10488
10471 /** 10489 /**
10472 * Returns the value of the search field. 10490 * Returns the value of the search field.
10473 * @return {string} 10491 * @return {string}
10474 */ 10492 */
10475 getValue: function() { 10493 getValue: function() {
10476 var searchInput = this.getSearchInput_(); 10494 var searchInput = this.getSearchInput_();
10477 return searchInput ? searchInput.value : ''; 10495 return searchInput ? searchInput.value : '';
10478 }, 10496 },
10479 10497
10498 /**
10499 * Sets the value of the search field, if it exists.
10500 * @param {string} value
10501 */
10502 setValue: function(value) {
10503 var searchInput = this.getSearchInput_();
10504 if (searchInput)
10505 searchInput.value = value;
10506 },
10507
10480 /** @param {SearchFieldDelegate} delegate */ 10508 /** @param {SearchFieldDelegate} delegate */
10481 setDelegate: function(delegate) { 10509 setDelegate: function(delegate) {
10482 this.delegate_ = delegate; 10510 this.delegate_ = delegate;
10483 }, 10511 },
10484 10512
10513 /** @return {Promise<boolean>} */
10485 showAndFocus: function() { 10514 showAndFocus: function() {
10486 this.showingSearch_ = true; 10515 this.showingSearch_ = true;
10487 this.focus_(); 10516 return this.focus_();
10488 },
10489
10490 /** @private */
10491 focus_: function() {
10492 this.async(function() {
10493 if (!this.showingSearch_)
10494 return;
10495
10496 var searchInput = this.getSearchInput_();
10497 if (searchInput)
10498 searchInput.focus();
10499 });
10500 }, 10517 },
10501 10518
10502 /** 10519 /**
10520 * @return {Promise<boolean>}
10521 * @private
10522 */
10523 focus_: function() {
10524 return new Promise(function(resolve) {
10525 this.async(function() {
10526 if (this.showingSearch_) {
10527 var searchInput = this.getSearchInput_();
10528 if (searchInput)
10529 searchInput.focus();
10530 }
10531 resolve(this.showingSearch_);
10532 });
10533 }.bind(this));
10534 },
10535
10536 /**
10503 * @return {?Element} 10537 * @return {?Element}
10504 * @private 10538 * @private
10505 */ 10539 */
10506 getSearchInput_: function() { 10540 getSearchInput_: function() {
10507 return this.$$('#search-input'); 10541 return this.$$('#search-input');
10508 }, 10542 },
10509 10543
10510 /** @private */ 10544 /** @private */
10511 onSearchTermSearch_: function() { 10545 onSearchTermSearch_: function() {
10512 if (this.delegate_) 10546 if (this.delegate_)
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
10816 Manager.removeItem = function(index) { 10850 Manager.removeItem = function(index) {
10817 Manager.get().removeItem_(index); 10851 Manager.get().removeItem_(index);
10818 }; 10852 };
10819 10853
10820 Manager.updateItem = function(index, data) { 10854 Manager.updateItem = function(index, data) {
10821 Manager.get().updateItem_(index, data); 10855 Manager.get().updateItem_(index, data);
10822 }; 10856 };
10823 10857
10824 return {Manager: Manager}; 10858 return {Manager: Manager};
10825 }); 10859 });
10860 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
10861 // Use of this source code is governed by a BSD-style license that can be
10862 // found in the LICENSE file.
10863
10864 // <include src="../../../../ui/webui/resources/js/i18n_template_no_process.js">
10865
10866 i18nTemplate.process(document, loadTimeData);
10826 // Copyright 2015 The Chromium Authors. All rights reserved. 10867 // Copyright 2015 The Chromium Authors. All rights reserved.
10827 // Use of this source code is governed by a BSD-style license that can be 10868 // Use of this source code is governed by a BSD-style license that can be
10828 // found in the LICENSE file. 10869 // found in the LICENSE file.
10829 10870
10830 window.addEventListener('load', downloads.Manager.onLoad); 10871 window.addEventListener('load', downloads.Manager.onLoad);
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/resources/md_downloads/vulcanize.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698