Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / extensions / renderer / resources / guest_view / app_view / app_view.js
bloba164fab186541e8de9e60f91eeef5ddb6eb5ad4c
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');
12 this.app = '';
13 this.data = '';
16 AppViewImpl.prototype.__proto__ = GuestViewContainer.prototype;
18 AppViewImpl.VIEW_TYPE = 'AppView';
20 // Add extra functionality to |this.element|.
21 AppViewImpl.setupElement = function(proto) {
22 var apiMethods = [
23 'connect'
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() {
45 return {
46 'appId': this.app,
47 'data': this.data || {}
51 AppViewImpl.prototype.connect = function(app, data, callback) {
52 if (!this.elementAttached) {
53 if (callback) {
54 callback(false);
56 return;
59 this.app = app;
60 this.data = data;
62 this.guest.destroy();
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;
68 if (callback) {
69 callback(false);
71 return;
73 this.attachWindow$();
74 if (callback) {
75 callback(true);
77 }.bind(this));
80 GuestViewContainer.registerElement(AppViewImpl);