Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 /** | |
| 6 * @fileoverview | |
| 7 * 'protocol-handlers' is the polymer element for showing the | |
| 8 * protocol handlers category under Site Settings. | |
| 9 */ | |
| 10 | |
| 11 var MenuActions = { | |
| 12 SET_DEFAULT: 'SetDefault', | |
| 13 REMOVE: 'Remove', | |
| 14 }; | |
| 15 | |
| 16 /** | |
| 17 * @typedef {{host: string, | |
| 18 * protocol: string, | |
| 19 * spec: string}} | |
| 20 */ | |
| 21 var HandlerEntry; | |
| 22 | |
| 23 /** | |
| 24 * @typedef {{default_handler: number, | |
| 25 * handlers: !Array<!HandlerEntry>, | |
| 26 * has_policy_recommendations: boolean, | |
| 27 * is_default_handler_set_by_user: boolean, | |
| 28 * protocol: string}} | |
| 29 */ | |
| 30 var ProtocolEntry; | |
| 31 | |
| 32 Polymer({ | |
| 33 is: 'protocol-handlers', | |
| 34 | |
| 35 behaviors: [SiteSettingsBehavior, WebUIListenerBehavior], | |
| 36 | |
| 37 properties: { | |
| 38 /** | |
| 39 * Represents the state of the main toggle shown for the category. | |
| 40 */ | |
| 41 categoryEnabled: Boolean, | |
| 42 | |
| 43 /** | |
| 44 * Array of protocols and their handlers. | |
| 45 * @type {!Array<!ProtocolEntry>} | |
| 46 */ | |
| 47 protocols: Array, | |
| 48 }, | |
| 49 | |
| 50 ready: function() { | |
| 51 this.addWebUIListener('setHandlersEnabled', | |
| 52 this.setHandlersEnabled.bind(this)); | |
| 53 this.addWebUIListener('setProtocolHandlers', | |
| 54 this.setProtocolHandlers.bind(this)); | |
| 55 this.addWebUIListener('setIgnoredProtocolHandlers', | |
| 56 this.setIgnoredProtocolHandlers.bind(this)); | |
| 57 this.browserProxy.initializeProtocolHandlerList(); | |
| 58 this.MenuActions = MenuActions; | |
|
michaelpg
2016/07/08 20:56:00
this should be in properties to use inside <templa
Finnur
2016/07/10 00:40:16
Done... I think. :)
| |
| 59 }, | |
| 60 | |
| 61 /** | |
| 62 * Obtains the description for the main toggle. | |
| 63 * @param {number} categoryEnabled Whether the main toggle is enabled. | |
| 64 * @return {string} The description to use. | |
| 65 * @private | |
| 66 */ | |
| 67 computeHandlersDescription_: function(categoryEnabled) { | |
| 68 return this.computeCategoryDesc( | |
| 69 settings.ContentSettingsTypes.PROTOCOL_HANDLERS, categoryEnabled, true); | |
| 70 }, | |
| 71 | |
| 72 /** | |
| 73 * Returns whether the given index matches the default handler. | |
| 74 * @param {number} index The index to evaluate. | |
| 75 * @param {number} defaultHandler The default handler index. | |
| 76 * @return {boolean} Whether the item is default. | |
| 77 * @private | |
| 78 */ | |
| 79 isDefault_: function(index, defaultHandler) { | |
| 80 return defaultHandler == index; | |
| 81 }, | |
| 82 | |
| 83 /** | |
| 84 * Updates the main toggle to set it enabled/disabled. | |
| 85 * @param {boolean} The state to set. | |
|
michaelpg
2016/07/08 20:56:00
these three are missing param names: @param {boole
Finnur
2016/07/10 00:40:16
Good catch. Done.
| |
| 86 */ | |
|
michaelpg
2016/07/08 20:56:00
looks like these three should be @private: setHand
Finnur
2016/07/10 00:40:16
Done.
| |
| 87 setHandlersEnabled: function(enabled) { | |
| 88 this.categoryEnabled = enabled; | |
| 89 }, | |
| 90 | |
| 91 /** | |
| 92 * Updates the list of protocol handlers. | |
| 93 * @param {!Array<!ProtocolEntry>} The new protocol handler list. | |
| 94 */ | |
| 95 setProtocolHandlers: function(protocols) { | |
| 96 this.protocols = protocols; | |
| 97 }, | |
| 98 | |
| 99 /** | |
| 100 * Updates the list of ignored protocol handlers. | |
| 101 * @param {!Array<!ProtocolEntry>} The new (ignored) protocol handler list. | |
| 102 */ | |
| 103 setIgnoredProtocolHandlers: function(args) { | |
| 104 // TODO(finnur): Figure this out. Have yet to be able to trigger the C++ | |
| 105 // side to send this. | |
| 106 }, | |
| 107 | |
| 108 /** | |
| 109 * A handler when the toggle is flipped. | |
| 110 * @private | |
| 111 */ | |
| 112 onToggleChange_: function(event) { | |
| 113 this.browserProxy.setProtocolHandlerDefault(this.categoryEnabled); | |
| 114 }, | |
| 115 | |
| 116 /** | |
| 117 * A handler when an action is selected in the action menu. | |
| 118 * @private | |
| 119 */ | |
| 120 onActionMenuIronActivate_: function(event) { | |
| 121 var protocol = event.model.item.protocol; | |
| 122 var url = event.model.item.spec; | |
| 123 if (event.detail.selected == MenuActions.SET_DEFAULT) { | |
| 124 this.browserProxy.setProtocolDefault(protocol, url); | |
| 125 } else if (event.detail.selected == MenuActions.REMOVE) { | |
| 126 this.browserProxy.removeProtocolHandler(protocol, url); | |
| 127 } | |
| 128 }, | |
| 129 }); | |
| OLD | NEW |