Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2013 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. | |
| 4 | |
| 5 // Shim extension to provide permission request API (and possibly other future | |
| 6 // experimental APIs) for <webview> tag. | |
| 7 // See web_view.js for details. | |
| 8 // | |
| 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 | |
| 11 // permission API would only be available for channels CHANNEL_DEV and | |
| 12 // CHANNEL_CANARY. | |
| 13 | |
| 14 var WebView = require('webview').WebView; | |
| 15 | |
| 16 /** @type {string} */ | |
| 17 var REQUEST_TYPE_MEDIA = 'media'; | |
| 18 | |
| 19 /** @type {string} */ | |
| 20 var ERROR_MSG_PERMISSION_ALREADY_DECIDED = '<webview>: ' + | |
| 21 'Permission has already been decided for this "permissionrequest" event.'; | |
| 22 | |
| 23 /** | |
| 24 * @param {!Object} detail The event details, originated from <object>. | |
| 25 * @private | |
| 26 */ | |
| 27 WebView.prototype.maybeSetupPermissionEvent_ = function() { | |
| 28 var node = this.node_; | |
| 29 var objectNode = this.objectNode_; | |
| 30 this.objectNode_.addEventListener('-internal-permissionrequest', function(e) { | |
| 31 var evt = new Event('permissionrequest', {bubbles: true, cancelable: true}); | |
| 32 var detail = e.detail ? JSON.parse(e.detail) : {}; | |
| 33 ['permission', 'url'].forEach(function(attribName) { | |
| 34 evt[attribName] = detail[attribName]; | |
| 35 }); | |
| 36 var requestId = detail.requestId; | |
| 37 | |
| 38 if (detail.permission == REQUEST_TYPE_MEDIA && | |
| 39 detail.requestId !== undefined) { | |
| 40 // TODO(lazyboy): Also fill in evt.details (see webview specs). | |
| 41 // http://crbug.com/141197. | |
| 42 var decisionMade = false; | |
| 43 // Construct the event.request object. | |
| 44 var request = { | |
| 45 allow: function() { | |
| 46 if (decisionMade) { | |
| 47 throw new Error(ERROR_MSG_PERMISSION_ALREADY_DECIDED); | |
| 48 } else { | |
| 49 objectNode['-internal-setPermission'](requestId, true); | |
|
abarth-chromium
2013/02/20 20:46:44
Do you intend to call this function with |this| se
lazyboy
2013/02/20 22:09:36
Did you mean to set |this| to null?
objectNode['-i
| |
| 50 decisionMade = true; | |
| 51 } | |
| 52 }, | |
| 53 deny: function() { | |
| 54 if (decisionMade) { | |
| 55 throw new Error(ERROR_MSG_PERMISSION_ALREADY_DECIDED); | |
| 56 } else { | |
| 57 objectNode['-internal-setPermission'](requestId, false); | |
| 58 decisionMade = true; | |
| 59 } | |
| 60 } | |
| 61 }; | |
| 62 evt.request = request; | |
| 63 | |
| 64 // Make browser plugin track lifetime of |request|. | |
| 65 objectNode['-internal-persistObject']( | |
| 66 request, REQUEST_TYPE_MEDIA, requestId); | |
| 67 | |
| 68 var defaultPrevented = !node.dispatchEvent(evt); | |
| 69 if (!decisionMade && !defaultPrevented) { | |
| 70 decisionMade = true; | |
| 71 objectNode['-internal-setPermission'](requestId, false); | |
| 72 } | |
| 73 } | |
| 74 }); | |
| 75 }; | |
| 76 | |
| OLD | NEW |