| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 // Shim extension to provide permission request API (and possibly other future | 5 // Shim extension to provide permission request API (and possibly other future |
| 6 // experimental APIs) for <webview> tag. | 6 // experimental APIs) for <webview> tag. |
| 7 // See web_view.js for details. | 7 // See web_view.js for details. |
| 8 // | 8 // |
| 9 // We want to control the permission API feature in <webview> separately from | 9 // We want to control the permission API feature in <webview> separately from |
| 10 // the <webview> feature itself. <webview> is available in stable channel, but | 10 // the <webview> feature itself. <webview> is available in stable channel, but |
| 11 // permission API would only be available for channels CHANNEL_DEV and | 11 // permission API would only be available for channels CHANNEL_DEV and |
| 12 // CHANNEL_CANARY. | 12 // CHANNEL_CANARY. |
| 13 | 13 |
| 14 var WebView = require('webView').WebView; | 14 var WebView = require('webView').WebView; |
| 15 | 15 |
| 16 var forEach = require('utils').forEach; |
| 17 |
| 16 /** @type {Array.<string>} */ | 18 /** @type {Array.<string>} */ |
| 17 var PERMISSION_TYPES = ['media', 'geolocation', 'pointerLock']; | 19 var PERMISSION_TYPES = ['media', 'geolocation', 'pointerLock']; |
| 18 | 20 |
| 19 /** @type {string} */ | 21 /** @type {string} */ |
| 20 var ERROR_MSG_PERMISSION_ALREADY_DECIDED = '<webview>: ' + | 22 var ERROR_MSG_PERMISSION_ALREADY_DECIDED = '<webview>: ' + |
| 21 'Permission has already been decided for this "permissionrequest" event.'; | 23 'Permission has already been decided for this "permissionrequest" event.'; |
| 22 | 24 |
| 23 var EXPOSED_PERMISSION_EVENT_ATTRIBS = [ | 25 var EXPOSED_PERMISSION_EVENT_ATTRIBS = [ |
| 24 'lastUnlockedBySelf', | 26 'lastUnlockedBySelf', |
| 25 'permission', | 27 'permission', |
| 26 'url', | 28 'url', |
| 27 'userGesture' | 29 'userGesture' |
| 28 ]; | 30 ]; |
| 29 | 31 |
| 30 /** | 32 /** |
| 31 * @param {!Object} detail The event details, originated from <object>. | 33 * @param {!Object} detail The event details, originated from <object>. |
| 32 * @private | 34 * @private |
| 33 */ | 35 */ |
| 34 WebView.prototype.maybeSetupPermissionEvent_ = function() { | 36 WebView.prototype.maybeSetupPermissionEvent_ = function() { |
| 35 var node = this.node_; | 37 var node = this.node_; |
| 36 var objectNode = this.objectNode_; | 38 var objectNode = this.objectNode_; |
| 37 this.objectNode_.addEventListener('-internal-permissionrequest', function(e) { | 39 this.objectNode_.addEventListener('-internal-permissionrequest', function(e) { |
| 38 var evt = new Event('permissionrequest', {bubbles: true, cancelable: true}); | 40 var evt = new Event('permissionrequest', {bubbles: true, cancelable: true}); |
| 39 var detail = e.detail ? JSON.parse(e.detail) : {}; | 41 var detail = e.detail ? JSON.parse(e.detail) : {}; |
| 40 EXPOSED_PERMISSION_EVENT_ATTRIBS.forEach(function(attribName) { | 42 forEach(EXPOSED_PERMISSION_EVENT_ATTRIBS, function(i, attribName) { |
| 41 if (detail[attribName] !== 'undefined') | 43 if (detail[attribName] !== 'undefined') |
| 42 evt[attribName] = detail[attribName]; | 44 evt[attribName] = detail[attribName]; |
| 43 }); | 45 }); |
| 44 var requestId = detail.requestId; | 46 var requestId = detail.requestId; |
| 45 | 47 |
| 46 if (detail.requestId !== 'undefined' && | 48 if (detail.requestId !== 'undefined' && |
| 47 PERMISSION_TYPES.indexOf(detail.permission) >= 0) { | 49 PERMISSION_TYPES.indexOf(detail.permission) >= 0) { |
| 48 // TODO(lazyboy): Also fill in evt.details (see webview specs). | 50 // TODO(lazyboy): Also fill in evt.details (see webview specs). |
| 49 // http://crbug.com/141197. | 51 // http://crbug.com/141197. |
| 50 var decisionMade = false; | 52 var decisionMade = false; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 */ | 89 */ |
| 88 WebView.prototype.maybeSetupExecuteScript_ = function() { | 90 WebView.prototype.maybeSetupExecuteScript_ = function() { |
| 89 var self = this; | 91 var self = this; |
| 90 this.node_['executeScript'] = function(var_args) { | 92 this.node_['executeScript'] = function(var_args) { |
| 91 var args = [self.objectNode_.getProcessId(), | 93 var args = [self.objectNode_.getProcessId(), |
| 92 self.objectNode_.getRouteId()].concat( | 94 self.objectNode_.getRouteId()].concat( |
| 93 Array.prototype.slice.call(arguments)); | 95 Array.prototype.slice.call(arguments)); |
| 94 chrome.webview.executeScript.apply(null, args); | 96 chrome.webview.executeScript.apply(null, args); |
| 95 } | 97 } |
| 96 }; | 98 }; |
| OLD | NEW |