Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(274)

Unified Diff: chrome/renderer/resources/extensions/web_view_experimental.js

Issue 11093080: <webview>: First stab at implementing media permission request for guests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix header guard name. Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/renderer/resources/extensions/web_view_experimental.js
diff --git a/chrome/renderer/resources/extensions/web_view_experimental.js b/chrome/renderer/resources/extensions/web_view_experimental.js
new file mode 100644
index 0000000000000000000000000000000000000000..b8454dd46715791618b8272e86a4cfeb822313b4
--- /dev/null
+++ b/chrome/renderer/resources/extensions/web_view_experimental.js
@@ -0,0 +1,76 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Shim extension to provide permission request API (and possibly other future
+// experimental APIs) for <webview> tag.
+// See web_view.js for details.
+//
+// We want to control the permission API feature in <webview> separately from
+// the <webview> feature itself. <webview> is available in stable channel, but
+// permission API would only be available for channels CHANNEL_DEV and
+// CHANNEL_CANARY.
+
+var WebView = require('webview').WebView;
+
+/** @type {string} */
+var REQUEST_TYPE_MEDIA = 'media';
+
+/** @type {string} */
+var ERROR_MSG_PERMISSION_ALREADY_DECIDED = '<webview>: ' +
+ 'Permission has already been decided for this "permissionrequest" event.';
+
+/**
+ * @param {!Object} detail The event details, originated from <object>.
+ * @private
+ */
+WebView.prototype.maybeSetupPermissionEvent_ = function() {
+ var node = this.node_;
+ var objectNode = this.objectNode_;
+ this.objectNode_.addEventListener('-internal-permissionrequest', function(e) {
+ var evt = new Event('permissionrequest', {bubbles: true, cancelable: true});
+ var detail = e.detail ? JSON.parse(e.detail) : {};
+ ['permission', 'url'].forEach(function(attribName) {
+ evt[attribName] = detail[attribName];
+ });
+ var requestId = detail.requestId;
+
+ if (detail.permission == REQUEST_TYPE_MEDIA &&
+ detail.requestId !== undefined) {
+ // TODO(lazyboy): Also fill in evt.details (see webview specs).
+ // http://crbug.com/141197.
+ var decisionMade = false;
+ // Construct the event.request object.
+ var request = {
+ allow: function() {
+ if (decisionMade) {
+ throw new Error(ERROR_MSG_PERMISSION_ALREADY_DECIDED);
+ } else {
+ 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
+ decisionMade = true;
+ }
+ },
+ deny: function() {
+ if (decisionMade) {
+ throw new Error(ERROR_MSG_PERMISSION_ALREADY_DECIDED);
+ } else {
+ objectNode['-internal-setPermission'](requestId, false);
+ decisionMade = true;
+ }
+ }
+ };
+ evt.request = request;
+
+ // Make browser plugin track lifetime of |request|.
+ objectNode['-internal-persistObject'](
+ request, REQUEST_TYPE_MEDIA, requestId);
+
+ var defaultPrevented = !node.dispatchEvent(evt);
+ if (!decisionMade && !defaultPrevented) {
+ decisionMade = true;
+ objectNode['-internal-setPermission'](requestId, false);
+ }
+ }
+ });
+};
+

Powered by Google App Engine
This is Rietveld 408576698