Add the ability to code generated prepopulated static nested structs
[chromium-blink-merge.git] / extensions / renderer / resources / guest_view / extension_options / extension_options.js
blob7193607fabb089b8374d7c09bbd3defc8cbae0b8
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 ExtensionOptionsConstants =
6     require('extensionOptionsConstants').ExtensionOptionsConstants;
7 var ExtensionOptionsEvents =
8     require('extensionOptionsEvents').ExtensionOptionsEvents;
9 var GuestViewContainer = require('guestViewContainer').GuestViewContainer;
11 function ExtensionOptionsImpl(extensionoptionsElement) {
12   GuestViewContainer.call(this, extensionoptionsElement, 'extensionoptions');
14   new ExtensionOptionsEvents(this);
17 ExtensionOptionsImpl.prototype.__proto__ = GuestViewContainer.prototype;
19 ExtensionOptionsImpl.VIEW_TYPE = 'ExtensionOptions';
21 ExtensionOptionsImpl.prototype.onElementAttached = function() {
22   this.createGuest();
25 ExtensionOptionsImpl.prototype.buildContainerParams = function() {
26   var params = {};
27   for (var i in this.attributes) {
28     params[i] = this.attributes[i].getValue();
29   }
30   return params;
33 ExtensionOptionsImpl.prototype.createGuest = function() {
34   // Destroy the old guest if one exists.
35   this.guest.destroy();
37   this.guest.create(this.buildParams(), function() {
38     if (!this.guest.getId()) {
39       // Fire a createfailed event here rather than in ExtensionOptionsGuest
40       // because the guest will not be created, and cannot fire an event.
41       var createFailedEvent = new Event('createfailed', { bubbles: true });
42       this.dispatchEvent(createFailedEvent);
43     } else {
44       this.attachWindow$();
45     }
46   }.bind(this));
49 GuestViewContainer.registerElement(ExtensionOptionsImpl);
51 // Exports.
52 exports.ExtensionOptionsImpl = ExtensionOptionsImpl;