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 * The possible menu actions. | |
| 51 * @type {MenuActions} | |
| 52 */ | |
| 53 menuActions_: Object, | |
|
michaelpg
2016/07/10 17:54:43
let's do: {
type: Object,
value: MenuActions,
| |
| 54 }, | |
| 55 | |
| 56 ready: function() { | |
| 57 this.addWebUIListener('setHandlersEnabled', | |
| 58 this.setHandlersEnabled_.bind(this)); | |
| 59 this.addWebUIListener('setProtocolHandlers', | |
| 60 this.setProtocolHandlers_.bind(this)); | |
| 61 this.addWebUIListener('setIgnoredProtocolHandlers', | |
| 62 this.setIgnoredProtocolHandlers_.bind(this)); | |
| 63 this.browserProxy.initializeProtocolHandlerList(); | |
| 64 this.menuActions_ = MenuActions; | |
| 65 }, | |
| 66 | |
| 67 /** | |
| 68 * Obtains the description for the main toggle. | |
| 69 * @param {number} categoryEnabled Whether the main toggle is enabled. | |
| 70 * @return {string} The description to use. | |
| 71 * @private | |
| 72 */ | |
| 73 computeHandlersDescription_: function(categoryEnabled) { | |
| 74 return this.computeCategoryDesc( | |
| 75 settings.ContentSettingsTypes.PROTOCOL_HANDLERS, categoryEnabled, true); | |
| 76 }, | |
| 77 | |
| 78 /** | |
| 79 * Returns whether the given index matches the default handler. | |
| 80 * @param {number} index The index to evaluate. | |
| 81 * @param {number} defaultHandler The default handler index. | |
| 82 * @return {boolean} Whether the item is default. | |
| 83 * @private | |
| 84 */ | |
| 85 isDefault_: function(index, defaultHandler) { | |
| 86 return defaultHandler == index; | |
| 87 }, | |
| 88 | |
| 89 /** | |
| 90 * Updates the main toggle to set it enabled/disabled. | |
| 91 * @param {boolean} enabled The state to set. | |
| 92 * @private | |
| 93 */ | |
| 94 setHandlersEnabled_: function(enabled) { | |
| 95 this.categoryEnabled = enabled; | |
| 96 }, | |
| 97 | |
| 98 /** | |
| 99 * Updates the list of protocol handlers. | |
| 100 * @param {!Array<!ProtocolEntry>} protocols The new protocol handler list. | |
| 101 * @private | |
| 102 */ | |
| 103 setProtocolHandlers_: function(protocols) { | |
| 104 this.protocols = protocols; | |
| 105 }, | |
| 106 | |
| 107 /** | |
| 108 * Updates the list of ignored protocol handlers. | |
| 109 * @param {!Array<!ProtocolEntry>} args The new (ignored) protocol handler | |
| 110 * list. | |
| 111 * @private | |
| 112 */ | |
| 113 setIgnoredProtocolHandlers_: function(args) { | |
| 114 // TODO(finnur): Figure this out. Have yet to be able to trigger the C++ | |
| 115 // side to send this. | |
| 116 }, | |
| 117 | |
| 118 /** | |
| 119 * A handler when the toggle is flipped. | |
| 120 * @private | |
| 121 */ | |
| 122 onToggleChange_: function(event) { | |
| 123 this.browserProxy.setProtocolHandlerDefault(this.categoryEnabled); | |
| 124 }, | |
| 125 | |
| 126 /** | |
| 127 * A handler when an action is selected in the action menu. | |
| 128 * @private | |
| 129 */ | |
| 130 onActionMenuIronActivate_: function(event) { | |
| 131 var protocol = event.model.item.protocol; | |
| 132 var url = event.model.item.spec; | |
| 133 if (event.detail.selected == MenuActions.SET_DEFAULT) { | |
| 134 this.browserProxy.setProtocolDefault(protocol, url); | |
| 135 } else if (event.detail.selected == MenuActions.REMOVE) { | |
| 136 this.browserProxy.removeProtocolHandler(protocol, url); | |
| 137 } | |
| 138 }, | |
| 139 }); | |
| OLD | NEW |