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