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

Side by Side Diff: chrome/renderer/resources/extensions/web_view.js

Issue 28273006: <webview>: Implement declarativeWebRequest API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added tests Created 7 years, 1 month 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 that simulates a <webview> tag via Mutation Observers. 5 // Shim that simulates a <webview> tag via Mutation Observers.
6 // 6 //
7 // The actual tag is implemented via the browser plugin. The internals of this 7 // The actual tag is implemented via the browser plugin. The internals of this
8 // are hidden via Shadow DOM. 8 // are hidden via Shadow DOM.
9 9
10 'use strict'; 10 'use strict';
11 11
12 var DocumentNatives = requireNative('document_natives'); 12 var DocumentNatives = requireNative('document_natives');
13 var EventBindings = require('event_bindings'); 13 var EventBindings = require('event_bindings');
14 var IdGenerator = requireNative('id_generator');
14 var MessagingNatives = requireNative('messaging_natives'); 15 var MessagingNatives = requireNative('messaging_natives');
15 var WebRequestEvent = require('webRequestInternal').WebRequestEvent; 16 var WebRequestEvent = require('webRequestInternal').WebRequestEvent;
16 var WebRequestSchema = 17 var WebRequestSchema =
17 requireNative('schema_registry').GetSchema('webRequest'); 18 requireNative('schema_registry').GetSchema('webRequest');
19 var DeclarativeWebRequestSchema =
20 requireNative('schema_registry').GetSchema('declarativeWebRequest');
18 var WebView = require('binding').Binding.create('webview').generate(); 21 var WebView = require('binding').Binding.create('webview').generate();
19 var idGenerator = requireNative('id_generator');
20 22
21 // This secret enables hiding <webview> private members from the outside scope. 23 // This secret enables hiding <webview> private members from the outside scope.
22 // Outside of this file, |secret| is inaccessible. The only way to access the 24 // Outside of this file, |secret| is inaccessible. The only way to access the
23 // <webview> element's internal members is via the |secret|. Since it's only 25 // <webview> element's internal members is via the |secret|. Since it's only
24 // accessible by code here (and in web_view_experimental), only <webview>'s 26 // accessible by code here (and in web_view_experimental), only <webview>'s
25 // API can access it and not external developers. 27 // API can access it and not external developers.
26 var secret = {}; 28 var secret = {};
27 29
28 var WEB_VIEW_ATTRIBUTE_MAXHEIGHT = 'maxheight'; 30 var WEB_VIEW_ATTRIBUTE_MAXHEIGHT = 'maxheight';
29 var WEB_VIEW_ATTRIBUTE_MAXWIDTH = 'maxwidth'; 31 var WEB_VIEW_ATTRIBUTE_MAXWIDTH = 'maxwidth';
(...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after
549 node.style.height = webViewEvent.newHeight + 'px'; 551 node.style.height = webViewEvent.newHeight + 'px';
550 } 552 }
551 node.dispatchEvent(webViewEvent); 553 node.dispatchEvent(webViewEvent);
552 }; 554 };
553 555
554 /** 556 /**
555 * @private 557 * @private
556 */ 558 */
557 WebViewInternal.prototype.setupWebviewNodeEvents_ = function() { 559 WebViewInternal.prototype.setupWebviewNodeEvents_ = function() {
558 var self = this; 560 var self = this;
559 this.viewInstanceId_ = idGenerator.GetNextId(); 561 this.viewInstanceId_ = IdGenerator.GetNextId();
560 var onInstanceIdAllocated = function(e) { 562 var onInstanceIdAllocated = function(e) {
561 var detail = e.detail ? JSON.parse(e.detail) : {}; 563 var detail = e.detail ? JSON.parse(e.detail) : {};
562 self.instanceId_ = detail.windowId; 564 self.instanceId_ = detail.windowId;
563 var params = { 565 var params = {
564 'api': 'webview', 566 'api': 'webview',
565 'instanceId': self.viewInstanceId_ 567 'instanceId': self.viewInstanceId_
566 }; 568 };
567 if (self.userAgentOverride_) { 569 if (self.userAgentOverride_) {
568 params['userAgentOverride'] = self.userAgentOverride_; 570 params['userAgentOverride'] = self.userAgentOverride_;
569 } 571 }
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
864 WebViewInternal.prototype.setupWebRequestEvents_ = function() { 866 WebViewInternal.prototype.setupWebRequestEvents_ = function() {
865 var self = this; 867 var self = this;
866 var request = {}; 868 var request = {};
867 var createWebRequestEvent = function(webRequestEvent) { 869 var createWebRequestEvent = function(webRequestEvent) {
868 return function() { 870 return function() {
869 if (!self[webRequestEvent.name + '_']) { 871 if (!self[webRequestEvent.name + '_']) {
870 self[webRequestEvent.name + '_'] = 872 self[webRequestEvent.name + '_'] =
871 new WebRequestEvent( 873 new WebRequestEvent(
872 'webview.' + webRequestEvent.name, 874 'webview.' + webRequestEvent.name,
873 webRequestEvent.parameters, 875 webRequestEvent.parameters,
874 webRequestEvent.extraParameters, null, 876 webRequestEvent.extraParameters, webRequestEvent.options,
875 self.viewInstanceId_); 877 self.viewInstanceId_);
876 } 878 }
877 return self[webRequestEvent.name + '_']; 879 return self[webRequestEvent.name + '_'];
878 }; 880 };
879 }; 881 };
880 882
883 for (var i = 0; i < DeclarativeWebRequestSchema.events.length; ++i) {
884 var eventSchema = DeclarativeWebRequestSchema.events[i];
885 var webRequestEvent = createWebRequestEvent(eventSchema);
886 Object.defineProperty(
887 request,
888 DeclarativeWebRequestSchema.events[i].name,
889 {
890 get: webRequestEvent,
891 enumerable: true
892 }
893 );
894 }
895
881 // Populate the WebRequest events from the API definition. 896 // Populate the WebRequest events from the API definition.
882 for (var i = 0; i < WebRequestSchema.events.length; ++i) { 897 for (var i = 0; i < WebRequestSchema.events.length; ++i) {
883 var webRequestEvent = createWebRequestEvent(WebRequestSchema.events[i]); 898 var webRequestEvent = createWebRequestEvent(WebRequestSchema.events[i]);
884 Object.defineProperty( 899 Object.defineProperty(
885 request, 900 request,
886 WebRequestSchema.events[i].name, 901 WebRequestSchema.events[i].name,
887 { 902 {
888 get: webRequestEvent, 903 get: webRequestEvent,
889 enumerable: true 904 enumerable: true
890 } 905 }
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
1029 * Implemented when the experimental API is available. 1044 * Implemented when the experimental API is available.
1030 * @private 1045 * @private
1031 */ 1046 */
1032 WebViewInternal.prototype.maybeGetExperimentalPermissions_ = function() { 1047 WebViewInternal.prototype.maybeGetExperimentalPermissions_ = function() {
1033 return []; 1048 return [];
1034 }; 1049 };
1035 1050
1036 exports.WebView = WebView; 1051 exports.WebView = WebView;
1037 exports.WebViewInternal = WebViewInternal; 1052 exports.WebViewInternal = WebViewInternal;
1038 exports.CreateEvent = CreateEvent; 1053 exports.CreateEvent = CreateEvent;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698