| 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 registration of guestview elements when | 5 // This module implements the registration of guestview elements when |
| 6 // permissions are not available. These elements exist only to provide a useful | 6 // permissions are not available. These elements exist only to provide a useful |
| 7 // error message when developers attempt to use them. | 7 // error message when developers attempt to use them. |
| 8 | 8 |
| 9 var DocumentNatives = requireNative('document_natives'); | 9 var DocumentNatives = requireNative('document_natives'); |
| 10 var GuestViewContainer = require('guestViewContainer').GuestViewContainer; | 10 var GuestViewContainer = require('guestViewContainer').GuestViewContainer; |
| 11 | 11 |
| 12 var ERROR_MESSAGE = 'You do not have permission to use the %1 element.' + | 12 var ERROR_MESSAGE = 'You do not have permission to use the %1 element.' + |
| 13 ' Be sure to declare the "%1" permission in your manifest file.'; | 13 ' Be sure to declare the "%1" permission in your manifest file.'; |
| 14 | 14 |
| 15 // A list of view types that will have custom elements registered if they are | 15 // A list of view types that will have custom elements registered if they are |
| 16 // not already registered by the time this module is loaded. | 16 // not already registered by the time this module is loaded. |
| 17 var VIEW_TYPES = [ | 17 var VIEW_TYPES = [ |
| 18 'AppView', | 18 'AppView', |
| 19 'ExtensionOptions', | 19 'ExtensionOptions', |
| 20 'ExtensionView', | 20 'ExtensionView', |
| 21 'SurfaceWorker', | |
| 22 'WebView' | 21 'WebView' |
| 23 ]; | 22 ]; |
| 24 | 23 |
| 25 // Registers a GuestView custom element. | 24 // Registers a GuestView custom element. |
| 26 function registerGuestViewElement(viewType) { | 25 function registerGuestViewElement(viewType) { |
| 27 var proto = Object.create(HTMLElement.prototype); | 26 var proto = Object.create(HTMLElement.prototype); |
| 28 | 27 |
| 29 proto.createdCallback = function() { | 28 proto.createdCallback = function() { |
| 30 window.console.error(ERROR_MESSAGE.replace(/%1/g, viewType.toLowerCase())); | 29 window.console.error(ERROR_MESSAGE.replace(/%1/g, viewType.toLowerCase())); |
| 31 }; | 30 }; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 50 // Register the error-providing custom element only for those view types | 49 // Register the error-providing custom element only for those view types |
| 51 // that have not already been registered. Since this module is always loaded | 50 // that have not already been registered. Since this module is always loaded |
| 52 // last, all the view types that are available (i.e. have the proper | 51 // last, all the view types that are available (i.e. have the proper |
| 53 // permissions) will have already been registered on |window|. | 52 // permissions) will have already been registered on |window|. |
| 54 if (!window[VIEW_TYPES[i]]) | 53 if (!window[VIEW_TYPES[i]]) |
| 55 registerGuestViewElement(VIEW_TYPES[i]); | 54 registerGuestViewElement(VIEW_TYPES[i]); |
| 56 } | 55 } |
| 57 | 56 |
| 58 window.removeEventListener(event.type, listener, useCapture); | 57 window.removeEventListener(event.type, listener, useCapture); |
| 59 }, useCapture); | 58 }, useCapture); |
| OLD | NEW |