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.
5 var DocumentNatives
= requireNative('document_natives');
6 var GuestViewContainer
= require('guestViewContainer').GuestViewContainer
;
7 var IdGenerator
= requireNative('id_generator');
9 function AppViewImpl(appviewElement
) {
10 GuestViewContainer
.call(this, appviewElement
, 'appview');
16 AppViewImpl
.prototype.__proto__
= GuestViewContainer
.prototype;
18 AppViewImpl
.VIEW_TYPE
= 'AppView';
20 // Add extra functionality to |this.element|.
21 AppViewImpl
.setupElement = function(proto
) {
26 // Forward proto.foo* method calls to AppViewImpl.foo*.
27 GuestViewContainer
.forwardApiMethods(proto
, apiMethods
);
30 AppViewImpl
.prototype.getErrorNode = function() {
31 if (!this.errorNode
) {
32 this.errorNode
= document
.createElement('div');
33 this.errorNode
.innerText
= 'Unable to connect to app.';
34 this.errorNode
.style
.position
= 'absolute';
35 this.errorNode
.style
.left
= '0px';
36 this.errorNode
.style
.top
= '0px';
37 this.errorNode
.style
.width
= '100%';
38 this.errorNode
.style
.height
= '100%';
39 this.element
.shadowRoot
.appendChild(this.errorNode
);
41 return this.errorNode
;
44 AppViewImpl
.prototype.buildContainerParams = function() {
47 'data': this.data
|| {}
51 AppViewImpl
.prototype.connect = function(app
, data
, callback
) {
52 if (!this.elementAttached
) {
63 this.guest
.create(this.buildParams(), function() {
64 if (!this.guest
.getId()) {
65 var errorMsg
= 'Unable to connect to app "' + app
+ '".';
66 window
.console
.warn(errorMsg
);
67 this.getErrorNode().innerText
= errorMsg
;
80 GuestViewContainer
.registerElement(AppViewImpl
);