| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 // This module implements the attributes of the <extensionview> tag. | 5 // This module implements the attributes of the <extensionview> tag. |
| 6 | 6 |
| 7 var GuestViewInternal = | 7 var GuestViewAttributes = require('guestViewAttributes').GuestViewAttributes; |
| 8 require('binding').Binding.create('guestViewInternal').generate(); | |
| 9 var ExtensionViewImpl = require('extensionView').ExtensionViewImpl; | 8 var ExtensionViewImpl = require('extensionView').ExtensionViewImpl; |
| 10 var ExtensionViewConstants = | 9 var ExtensionViewConstants = |
| 11 require('extensionViewConstants').ExtensionViewConstants; | 10 require('extensionViewConstants').ExtensionViewConstants; |
| 12 var ExtensionViewInternal = | 11 var ExtensionViewInternal = |
| 13 require('extensionViewInternal').ExtensionViewInternal; | 12 require('extensionViewInternal').ExtensionViewInternal; |
| 14 | 13 |
| 15 // ----------------------------------------------------------------------------- | 14 // ----------------------------------------------------------------------------- |
| 16 // Attribute objects. | 15 // ExtensionAttribute object. |
| 17 | 16 |
| 18 // Default implementation of a ExtensionView attribute. | 17 // Attribute that handles extension binded to the extensionview. |
| 19 function ExtensionViewAttribute(name, extensionViewImpl) { | 18 function ExtensionAttribute(view) { |
| 20 this.name = name; | 19 GuestViewAttributes.ReadOnlyAttribute.call( |
| 21 this.extensionViewImpl = extensionViewImpl; | 20 this, ExtensionViewConstants.ATTRIBUTE_EXTENSION, view); |
| 22 this.ignoreMutation = false; | |
| 23 | |
| 24 this.defineProperty(); | |
| 25 } | 21 } |
| 26 | 22 |
| 27 // Retrieves and returns the attribute's value. | 23 ExtensionAttribute.prototype.__proto__ = |
| 28 ExtensionViewAttribute.prototype.getValue = function() { | 24 GuestViewAttributes.ReadOnlyAttribute.prototype; |
| 29 return this.extensionViewImpl.element.getAttribute(this.name) || ''; | |
| 30 }; | |
| 31 | 25 |
| 32 // Sets the attribute's value. | 26 // ----------------------------------------------------------------------------- |
| 33 ExtensionViewAttribute.prototype.setValue = function(value) { | 27 // SrcAttribute object. |
| 34 this.extensionViewImpl.element.setAttribute(this.name, value || ''); | |
| 35 }; | |
| 36 | 28 |
| 37 // Changes the attribute's value without triggering its mutation handler. | 29 // Attribute that handles the location and navigation of the extensionview. |
| 38 ExtensionViewAttribute.prototype.setValueIgnoreMutation = function(value) { | 30 function SrcAttribute(view) { |
| 39 this.ignoreMutation = true; | 31 GuestViewAttributes.Attribute.call( |
| 40 this.setValue(value); | 32 this, ExtensionViewConstants.ATTRIBUTE_SRC, view); |
| 41 this.ignoreMutation = false; | |
| 42 } | 33 } |
| 43 | 34 |
| 44 // Defines this attribute as a property on the extensionview node. | 35 SrcAttribute.prototype.__proto__ = GuestViewAttributes.Attribute.prototype; |
| 45 ExtensionViewAttribute.prototype.defineProperty = function() { | |
| 46 Object.defineProperty(this.extensionViewImpl.element, this.name, { | |
| 47 get: function() { | |
| 48 return this.getValue(); | |
| 49 }.bind(this), | |
| 50 set: function(value) { | |
| 51 this.setValue(value); | |
| 52 }.bind(this), | |
| 53 enumerable: true | |
| 54 }); | |
| 55 }; | |
| 56 | |
| 57 // Called when the attribute's value changes. | |
| 58 ExtensionViewAttribute.prototype.maybeHandleMutation = | |
| 59 function(oldValue, newValue) { | |
| 60 if (this.ignoreMutation) | |
| 61 return; | |
| 62 | |
| 63 this.handleMutation(oldValue, newValue); | |
| 64 } | |
| 65 | |
| 66 // Called when a change that isn't ignored occurs to the attribute's value. | |
| 67 ExtensionViewAttribute.prototype.handleMutation = | |
| 68 function(oldValue, newValue) {}; | |
| 69 | |
| 70 ExtensionViewAttribute.prototype.reset = function() { | |
| 71 this.setValueIgnoreMutation(); | |
| 72 } | |
| 73 | |
| 74 // Attribute that handles extension binded to the extensionview. | |
| 75 function ExtensionAttribute(extensionViewImpl) { | |
| 76 ExtensionViewAttribute.call(this, ExtensionViewConstants.ATTRIBUTE_EXTENSION, | |
| 77 extensionViewImpl); | |
| 78 } | |
| 79 | |
| 80 ExtensionAttribute.prototype.__proto__ = ExtensionViewAttribute.prototype; | |
| 81 | |
| 82 ExtensionAttribute.prototype.handleMutation = function(oldValue, newValue) { | |
| 83 this.setValueIgnoreMutation(oldValue); | |
| 84 } | |
| 85 | |
| 86 // Attribute that handles the location and navigation of the extensionview. | |
| 87 function SrcAttribute(extensionViewImpl) { | |
| 88 ExtensionViewAttribute.call(this, ExtensionViewConstants.ATTRIBUTE_SRC, | |
| 89 extensionViewImpl); | |
| 90 } | |
| 91 | |
| 92 SrcAttribute.prototype.__proto__ = ExtensionViewAttribute.prototype; | |
| 93 | 36 |
| 94 SrcAttribute.prototype.handleMutation = function(oldValue, newValue) { | 37 SrcAttribute.prototype.handleMutation = function(oldValue, newValue) { |
| 95 if (!newValue && oldValue) { | 38 if (!newValue && oldValue) { |
| 96 this.setValueIgnoreMutation(oldValue); | 39 this.setValueIgnoreMutation(oldValue); |
| 97 return; | 40 return; |
| 98 } | 41 } |
| 99 this.parse(); | 42 this.parse(); |
| 100 }; | 43 }; |
| 101 | 44 |
| 102 SrcAttribute.prototype.parse = function() { | 45 SrcAttribute.prototype.parse = function() { |
| 103 if (!this.extensionViewImpl.elementAttached || !this.getValue()) | 46 if (!this.view.elementAttached || !this.getValue() || |
| 47 !this.view.guest.getId()) { |
| 104 return; | 48 return; |
| 49 } |
| 105 | 50 |
| 106 if (!this.extensionViewImpl.guest.getId()) | 51 ExtensionViewInternal.navigate(this.view.guest.getId(), this.getValue()); |
| 107 return; | |
| 108 | |
| 109 ExtensionViewInternal.navigate(this.extensionViewImpl.guest.getId(), | |
| 110 this.getValue()); | |
| 111 }; | 52 }; |
| 112 | 53 |
| 113 // ----------------------------------------------------------------------------- | 54 // ----------------------------------------------------------------------------- |
| 114 | 55 |
| 115 // Sets up all of the extensionview attributes. | 56 // Sets up all of the extensionview attributes. |
| 116 ExtensionViewImpl.prototype.setupExtensionViewAttributes = function() { | 57 ExtensionViewImpl.prototype.setupExtensionViewAttributes = function() { |
| 117 this.attributes = {}; | 58 this.attributes = {}; |
| 118 this.attributes[ExtensionViewConstants.ATTRIBUTE_EXTENSION] = | 59 this.attributes[ExtensionViewConstants.ATTRIBUTE_EXTENSION] = |
| 119 new ExtensionAttribute(this); | 60 new ExtensionAttribute(this); |
| 120 this.attributes[ExtensionViewConstants.ATTRIBUTE_SRC] = | 61 this.attributes[ExtensionViewConstants.ATTRIBUTE_SRC] = |
| 121 new SrcAttribute(this); | 62 new SrcAttribute(this); |
| 122 }; | 63 }; |
| OLD | NEW |