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 var params = {}; |
27 'extensionId': this.element.getAttribute('extension') | 27 for (var i in this.attributes) { |
28 }; | 28 params[i] = this.attributes[i].getValue(); |
| 29 } |
| 30 return params; |
29 }; | 31 }; |
30 | 32 |
31 ExtensionOptionsImpl.prototype.createGuest = function() { | 33 ExtensionOptionsImpl.prototype.createGuest = function() { |
32 if (!this.elementAttached) { | |
33 return; | |
34 } | |
35 | |
36 // Destroy the old guest if one exists. | 34 // Destroy the old guest if one exists. |
37 this.guest.destroy(); | 35 this.guest.destroy(); |
38 | 36 |
39 this.guest.create(this.buildParams(), function() { | 37 this.guest.create(this.buildParams(), function() { |
40 if (!this.guest.getId()) { | 38 if (!this.guest.getId()) { |
41 // Fire a createfailed event here rather than in ExtensionOptionsGuest | 39 // Fire a createfailed event here rather than in ExtensionOptionsGuest |
42 // because the guest will not be created, and cannot fire an event. | 40 // because the guest will not be created, and cannot fire an event. |
43 var createFailedEvent = new Event('createfailed', { bubbles: true }); | 41 var createFailedEvent = new Event('createfailed', { bubbles: true }); |
44 this.dispatchEvent(createFailedEvent); | 42 this.dispatchEvent(createFailedEvent); |
45 } else { | 43 } else { |
46 this.attachWindow(); | 44 this.attachWindow(); |
47 } | 45 } |
48 }.bind(this)); | 46 }.bind(this)); |
49 }; | 47 }; |
50 | 48 |
51 ExtensionOptionsImpl.prototype.handleAttributeMutation = | 49 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 | 50 |
58 if (oldValue === newValue) | 51 // Exports. |
59 return; | 52 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 |