| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 var DocumentNatives = requireNative('document_natives'); | |
| 6 var GuestView = require('guestView').GuestView; | |
| 7 var GuestViewContainer = require('guestViewContainer').GuestViewContainer; | |
| 8 var IdGenerator = requireNative('id_generator'); | |
| 9 | |
| 10 function AppViewImpl(appviewElement) { | |
| 11 GuestViewContainer.call(this, appviewElement, 'appview'); | |
| 12 | |
| 13 this.app = ''; | |
| 14 this.data = ''; | |
| 15 } | |
| 16 | |
| 17 AppViewImpl.prototype.__proto__ = GuestViewContainer.prototype; | |
| 18 | |
| 19 AppViewImpl.VIEW_TYPE = 'AppView'; | |
| 20 | |
| 21 // Add extra functionality to |this.element|. | |
| 22 AppViewImpl.setupElement = function(proto) { | |
| 23 var apiMethods = [ | |
| 24 'connect' | |
| 25 ]; | |
| 26 | |
| 27 // Forward proto.foo* method calls to AppViewImpl.foo*. | |
| 28 GuestViewContainer.forwardApiMethods(proto, apiMethods); | |
| 29 } | |
| 30 | |
| 31 AppViewImpl.prototype.getErrorNode = function() { | |
| 32 if (!this.errorNode) { | |
| 33 this.errorNode = document.createElement('div'); | |
| 34 this.errorNode.innerText = 'Unable to connect to app.'; | |
| 35 this.errorNode.style.position = 'absolute'; | |
| 36 this.errorNode.style.left = '0px'; | |
| 37 this.errorNode.style.top = '0px'; | |
| 38 this.errorNode.style.width = '100%'; | |
| 39 this.errorNode.style.height = '100%'; | |
| 40 this.element.shadowRoot.appendChild(this.errorNode); | |
| 41 } | |
| 42 return this.errorNode; | |
| 43 }; | |
| 44 | |
| 45 AppViewImpl.prototype.buildContainerParams = function() { | |
| 46 return { | |
| 47 'appId': this.app, | |
| 48 'data': this.data || {} | |
| 49 }; | |
| 50 }; | |
| 51 | |
| 52 AppViewImpl.prototype.connect = function(app, data, callback) { | |
| 53 if (!this.elementAttached) { | |
| 54 if (callback) { | |
| 55 callback(false); | |
| 56 } | |
| 57 return; | |
| 58 } | |
| 59 | |
| 60 this.app = app; | |
| 61 this.data = data; | |
| 62 | |
| 63 this.guest.destroy(); | |
| 64 this.guest.create(this.buildParams(), function() { | |
| 65 if (!this.guest.getId()) { | |
| 66 var errorMsg = 'Unable to connect to app "' + app + '".'; | |
| 67 window.console.warn(errorMsg); | |
| 68 this.getErrorNode().innerText = errorMsg; | |
| 69 if (callback) { | |
| 70 callback(false); | |
| 71 } | |
| 72 return; | |
| 73 } | |
| 74 this.attachWindow(); | |
| 75 if (callback) { | |
| 76 callback(true); | |
| 77 } | |
| 78 }.bind(this)); | |
| 79 }; | |
| 80 | |
| 81 GuestViewContainer.registerElement(AppViewImpl); | |
| OLD | NEW |