OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 var ExtensionOptionsConstants = | |
6 require('extensionOptionsConstants').ExtensionOptionsConstants; | |
5 var ExtensionOptionsEvents = | 7 var ExtensionOptionsEvents = |
6 require('extensionOptionsEvents').ExtensionOptionsEvents; | 8 require('extensionOptionsEvents').ExtensionOptionsEvents; |
7 var GuestView = require('guestView').GuestView; | |
8 var GuestViewContainer = require('guestViewContainer').GuestViewContainer; | 9 var GuestViewContainer = require('guestViewContainer').GuestViewContainer; |
9 | 10 |
10 function ExtensionOptionsImpl(extensionoptionsElement) { | 11 function ExtensionOptionsImpl(extensionoptionsElement) { |
11 GuestViewContainer.call(this, extensionoptionsElement, 'extensionoptions'); | 12 GuestViewContainer.call(this, extensionoptionsElement, 'extensionoptions'); |
12 | 13 |
13 new ExtensionOptionsEvents(this); | 14 new ExtensionOptionsEvents(this); |
14 this.setupElementProperties(); | |
15 }; | 15 }; |
16 | 16 |
17 ExtensionOptionsImpl.prototype.__proto__ = GuestViewContainer.prototype; | 17 ExtensionOptionsImpl.prototype.__proto__ = GuestViewContainer.prototype; |
18 | 18 |
19 ExtensionOptionsImpl.VIEW_TYPE = 'ExtensionOptions'; | 19 ExtensionOptionsImpl.VIEW_TYPE = 'ExtensionOptions'; |
20 | 20 |
21 ExtensionOptionsImpl.prototype.onElementAttached = function() { | 21 ExtensionOptionsImpl.prototype.onElementAttached = function() { |
22 this.createGuest(); | 22 this.createGuest(); |
23 } | 23 } |
24 | 24 |
25 ExtensionOptionsImpl.prototype.buildContainerParams = function() { | 25 ExtensionOptionsImpl.prototype.buildContainerParams = function() { |
26 return { | 26 return { |
27 'extensionId': this.element.getAttribute('extension') | 27 'extensionId': this.attributes[ |
Fady Samuel
2015/03/20 19:53:57
Can we simply iterate over the attributes array he
paulmeyer
2015/03/24 17:31:42
Done.
| |
28 ExtensionOptionsConstants.ATTRIBUTE_EXTENSION].getValue() | |
28 }; | 29 }; |
29 }; | 30 }; |
30 | 31 |
31 ExtensionOptionsImpl.prototype.createGuest = function() { | 32 ExtensionOptionsImpl.prototype.createGuest = function() { |
32 if (!this.elementAttached) { | 33 if (!this.elementAttached) { |
Fady Samuel
2015/03/20 20:11:12
Can we move some code to the ExtensionAttribute?
paulmeyer
2015/03/24 17:31:42
You're right about the check... but I think the re
| |
33 return; | 34 return; |
34 } | 35 } |
35 | 36 |
36 // Destroy the old guest if one exists. | 37 // Destroy the old guest if one exists. |
37 this.guest.destroy(); | 38 this.guest.destroy(); |
38 | 39 |
39 this.guest.create(this.buildParams(), function() { | 40 this.guest.create(this.buildParams(), function() { |
40 if (!this.guest.getId()) { | 41 if (!this.guest.getId()) { |
41 // Fire a createfailed event here rather than in ExtensionOptionsGuest | 42 // Fire a createfailed event here rather than in ExtensionOptionsGuest |
42 // because the guest will not be created, and cannot fire an event. | 43 // because the guest will not be created, and cannot fire an event. |
43 var createFailedEvent = new Event('createfailed', { bubbles: true }); | 44 var createFailedEvent = new Event('createfailed', { bubbles: true }); |
44 this.dispatchEvent(createFailedEvent); | 45 this.dispatchEvent(createFailedEvent); |
45 } else { | 46 } else { |
46 this.attachWindow(); | 47 this.attachWindow(); |
47 } | 48 } |
48 }.bind(this)); | 49 }.bind(this)); |
49 }; | 50 }; |
50 | 51 |
51 ExtensionOptionsImpl.prototype.handleAttributeMutation = | 52 GuestViewContainer.registerElement(ExtensionOptionsImpl); |
52 function(name, oldValue, newValue) { | |
53 // We treat null attribute (attribute removed) and the empty string as | |
54 // one case. | |
55 oldValue = oldValue || ''; | |
56 newValue = newValue || ''; | |
57 | 53 |
58 if (oldValue === newValue) | 54 // Exports. |
59 return; | 55 exports.ExtensionOptionsImpl = ExtensionOptionsImpl; |
60 | |
61 if (name == 'extension') { | |
62 this.createGuest(); | |
63 } | |
64 }; | |
65 | |
66 ExtensionOptionsImpl.prototype.setupElementProperties = function() { | |
67 $Object.defineProperty(this.element, 'extension', { | |
68 get: function() { | |
69 return this.element.getAttribute('extension'); | |
70 }.bind(this), | |
71 set: function(value) { | |
72 this.element.setAttribute('extension', value); | |
73 }.bind(this), | |
74 enumerable: true | |
75 }); | |
76 }; | |
77 | |
78 GuestViewContainer.registerElement(ExtensionOptionsImpl); | |
OLD | NEW |