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 as 'experimental'. | |
| 12 | |
| 13 var WebView = require('webview').WebView; | |
| 14 | |
| 15 /** | |
| 16 * @param {!Object} detail The event details, originated from <object>. | |
| 17 * @private | |
| 18 */ | |
| 19 WebView.prototype.maybeSetupPermissionEvent_ = function() { | |
| 20 var node = this.node_; | |
| 21 var objectNode = this.objectNode_; | |
| 22 this.objectNode_.addEventListener('-internal-permissionrequest', function(e) { | |
| 23 var evt = new Event('permissionrequest', {bubbles: true, cancelable: true}); | |
| 24 var detail = e.detail ? JSON.parse(e.detail) : {}; | |
| 25 ['permission', 'url'].forEach(function(attribName) { | |
| 26 evt[attribName] = detail[attribName]; | |
| 27 }); | |
| 28 var requestId = detail.requestId; | |
| 29 | |
| 30 if (detail.permission == 'media' && detail.requestId !== undefined) { | |
| 31 // TODO(lazyboy): Also fill in evt.details (see webview specs). | |
| 32 // http://crbug.com/141197. | |
| 33 var decisionMade = false; | |
| 34 // Construct the event.request object. | |
| 35 var request = { | |
| 36 allow: function() { | |
| 37 if (decisionMade) { | |
| 38 throw 'permissionrequest decision has already been made'; | |
|
Charlie Reis
2013/02/11 22:20:56
This is a string shown to web developers in the ex
lazyboy
2013/02/12 05:03:45
I'll ask asargent@, he recently added exception me
| |
| 39 } else { | |
| 40 objectNode['-internal-setPermission']('media', requestId, true); | |
|
Charlie Reis
2013/02/11 22:20:56
Can we check anywhere else that we don't call this
lazyboy
2013/02/12 05:03:45
Calling this > 1 times is no-op since the 'pending
| |
| 41 decisionMade = true; | |
| 42 } | |
| 43 }, | |
| 44 deny: function() { | |
| 45 if (decisionMade) { | |
| 46 throw 'permissionrequest decision has already been made'; | |
| 47 } else { | |
| 48 objectNode['-internal-setPermission']('media', requestId, false); | |
| 49 decisionMade = true; | |
| 50 } | |
| 51 } | |
| 52 }; | |
| 53 evt.request = request; | |
| 54 | |
| 55 // Make browser plugin track lifetime of |request|. | |
| 56 objectNode['-internal-persistObject'](request, requestId); | |
| 57 | |
| 58 var defaultPrevented = !node.dispatchEvent(evt); | |
| 59 if (!decisionMade && !defaultPrevented) { | |
| 60 decisionMade = true; | |
| 61 objectNode['-internal-setPermission']('media', requestId, false); | |
| 62 } | |
| 63 } | |
| 64 }); | |
| 65 }; | |
| 66 | |
| OLD | NEW |