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 ExtensionView <extensionview>. | 5 // This module implements the ExtensionView <extensionview>. |
6 | 6 |
7 var GuestViewContainer = require('guestViewContainer').GuestViewContainer; | 7 var GuestViewContainer = require('guestViewContainer').GuestViewContainer; |
8 var ExtensionViewConstants = | 8 var ExtensionViewConstants = |
9 require('extensionViewConstants').ExtensionViewConstants; | 9 require('extensionViewConstants').ExtensionViewConstants; |
10 var ExtensionViewEvents = require('extensionViewEvents').ExtensionViewEvents; | 10 var ExtensionViewEvents = require('extensionViewEvents').ExtensionViewEvents; |
11 var ExtensionViewInternal = | 11 var ExtensionViewInternal = |
12 require('extensionViewInternal').ExtensionViewInternal; | 12 require('extensionViewInternal').ExtensionViewInternal; |
13 | 13 |
14 function ExtensionViewImpl(extensionviewElement) { | 14 function ExtensionViewImpl(extensionviewElement) { |
15 GuestViewContainer.call(this, extensionviewElement, 'extensionview'); | 15 GuestViewContainer.call(this, extensionviewElement, 'extensionview'); |
16 this.setupExtensionViewAttributes(); | |
17 | 16 |
18 new ExtensionViewEvents(this, this.viewInstanceId); | 17 new ExtensionViewEvents(this, this.viewInstanceId); |
19 } | 18 } |
20 | 19 |
21 ExtensionViewImpl.prototype.__proto__ = GuestViewContainer.prototype; | 20 ExtensionViewImpl.prototype.__proto__ = GuestViewContainer.prototype; |
22 | 21 |
23 ExtensionViewImpl.VIEW_TYPE = 'ExtensionView'; | 22 ExtensionViewImpl.VIEW_TYPE = 'ExtensionView'; |
24 | 23 |
25 ExtensionViewImpl.setupElement = function(proto) { | 24 ExtensionViewImpl.setupElement = function(proto) { |
26 var apiMethods = ExtensionViewImpl.getApiMethods(); | 25 var apiMethods = ExtensionViewImpl.getApiMethods(); |
27 | 26 |
28 GuestViewContainer.forwardApiMethods(proto, apiMethods); | 27 GuestViewContainer.forwardApiMethods(proto, apiMethods); |
29 }; | 28 }; |
30 | 29 |
31 ExtensionViewImpl.prototype.createGuest = function() { | 30 ExtensionViewImpl.prototype.createGuest = function() { |
32 this.guest.create(this.buildParams(), function() { | 31 this.guest.create(this.buildParams(), function() { |
33 this.attachWindow(); | 32 this.attachWindow(); |
34 }.bind(this)); | 33 }.bind(this)); |
35 }; | 34 }; |
36 | 35 |
37 ExtensionViewImpl.prototype.buildContainerParams = function() { | 36 ExtensionViewImpl.prototype.buildContainerParams = function() { |
38 var params = {}; | 37 var params = {}; |
39 for (var i in this.attributes) { | 38 for (var i in this.attributes) { |
40 params[i] = this.attributes[i].getValue(); | 39 params[i] = this.attributes[i].getValue(); |
41 } | 40 } |
42 return params; | 41 return params; |
43 }; | 42 }; |
44 | 43 |
45 // This observer monitors mutations to attributes of the <extensionview>. | |
46 ExtensionViewImpl.prototype.handleAttributeMutation = function( | |
47 attributeName, oldValue, newValue) { | |
48 if (!this.attributes[attributeName]) | |
49 return; | |
50 | |
51 // Let the changed attribute handle its own mutation. | |
52 this.attributes[attributeName].maybeHandleMutation(oldValue, newValue); | |
53 }; | |
54 | |
55 ExtensionViewImpl.prototype.onElementDetached = function() { | 44 ExtensionViewImpl.prototype.onElementDetached = function() { |
56 this.guest.destroy(); | 45 this.guest.destroy(); |
57 | 46 |
58 // Reset all attributes. | 47 // Reset all attributes. |
59 for (var i in this.attributes) { | 48 for (var i in this.attributes) { |
60 this.attributes[i].setValueIgnoreMutation(); | 49 this.attributes[i].setValueIgnoreMutation(); |
61 } | 50 } |
62 }; | 51 }; |
63 | 52 |
64 // Updates src upon loadcommit. | 53 // Updates src upon loadcommit. |
65 ExtensionViewImpl.prototype.onLoadCommit = function(url) { | 54 ExtensionViewImpl.prototype.onLoadCommit = function(url) { |
66 this.attributes[ExtensionViewConstants.ATTRIBUTE_SRC]. | 55 this.attributes[ExtensionViewConstants.ATTRIBUTE_SRC]. |
67 setValueIgnoreMutation(url); | 56 setValueIgnoreMutation(url); |
68 }; | 57 }; |
69 | 58 |
70 GuestViewContainer.registerElement(ExtensionViewImpl); | 59 GuestViewContainer.registerElement(ExtensionViewImpl); |
71 | 60 |
72 // Exports. | 61 // Exports. |
73 exports.ExtensionViewImpl = ExtensionViewImpl; | 62 exports.ExtensionViewImpl = ExtensionViewImpl; |
OLD | NEW |