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

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

Issue 12189018: <webview>: Implement WebRequest API (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Diff from latest patch 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 unified diff | Download patch | Annotate | Revision Log
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 var GetExtensionAPIDefinition =
11 requireNative('apiDefinitions').GetExtensionAPIDefinition;
12 var WebRequestEvent = require('webRequest').webRequestEvent;
13
10 var watchForTag = require("tagWatcher").watchForTag; 14 var watchForTag = require("tagWatcher").watchForTag;
11 15
12 var WEB_VIEW_ATTRIBUTES = ['name', 'src', 'partition', 'autosize', 'minheight', 16 var WEB_VIEW_ATTRIBUTES = ['name', 'src', 'partition', 'autosize', 'minheight',
13 'minwidth', 'maxheight', 'maxwidth']; 17 'minwidth', 'maxheight', 'maxwidth'];
14 18
15 // All exposed api methods for <webview>, these are forwarded to the browser 19 // All exposed api methods for <webview>, these are forwarded to the browser
16 // plugin. 20 // plugin.
17 var WEB_VIEW_API_METHODS = [ 21 var WEB_VIEW_API_METHODS = [
18 'back', 22 'back',
19 'canGoBack', 23 'canGoBack',
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 get: function() { 108 get: function() {
105 return objectNode[attributeName]; 109 return objectNode[attributeName];
106 }, 110 },
107 set: function(value) { 111 set: function(value) {
108 objectNode[attributeName] = value; 112 objectNode[attributeName] = value;
109 }, 113 },
110 enumerable: true 114 enumerable: true
111 }); 115 });
112 }, this); 116 }, this);
113 117
118
119 // Populate the WebRequest events from the API definition.
120 var webRequestDefinition =
121 GetExtensionAPIDefinition('webRequest')[0];
122 for (var i = 0; i < webRequestDefinition.events.length; ++i) {
123 Object.defineProperty(self.node_, webRequestDefinition.events[i].name, {
124 get: function(webRequestEvent) {
125 return function() {
126 if (!self[webRequestEvent.name + '_']) {
127 self[webRequestEvent.name + '_'] =
128 new WebRequestEvent(
129 'webview.' + webRequestEvent.name,
130 webRequestEvent.parameters,
131 webRequestEvent.extraParameters, null,
132 self.objectNode_.getInstanceId());
133 }
134 return self[webRequestEvent.name + '_'];
135 }
136 }(webRequestDefinition.events[i]),
137 // No setter.
138 enumerable: true
139 });
140 }
141
114 // We cannot use {writable: true} property descriptor because we want dynamic 142 // We cannot use {writable: true} property descriptor because we want dynamic
115 // getter value. 143 // getter value.
116 Object.defineProperty(this.node_, 'contentWindow', { 144 Object.defineProperty(this.node_, 'contentWindow', {
117 get: function() { 145 get: function() {
118 // TODO(fsamuel): This is a workaround to enable 146 // TODO(fsamuel): This is a workaround to enable
119 // contentWindow.postMessage until http://crbug.com/152006 is fixed. 147 // contentWindow.postMessage until http://crbug.com/152006 is fixed.
120 if (objectNode.contentWindow) 148 if (objectNode.contentWindow)
121 return objectNode.contentWindow.self; 149 return objectNode.contentWindow.self;
122 console.error('contentWindow is not available at this time. ' + 150 console.error('contentWindow is not available at this time. ' +
123 'It will become available when the page has finished loading.'); 151 'It will become available when the page has finished loading.');
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 var node = this.node_; 196 var node = this.node_;
169 this.objectNode_.addEventListener('-internal-' + eventname, function(e) { 197 this.objectNode_.addEventListener('-internal-' + eventname, function(e) {
170 var evt = new Event(eventname, { bubbles: true }); 198 var evt = new Event(eventname, { bubbles: true });
171 var detail = e.detail ? JSON.parse(e.detail) : {}; 199 var detail = e.detail ? JSON.parse(e.detail) : {};
172 attribs.forEach(function(attribName) { 200 attribs.forEach(function(attribName) {
173 evt[attribName] = detail[attribName]; 201 evt[attribName] = detail[attribName];
174 }); 202 });
175 node.dispatchEvent(evt); 203 node.dispatchEvent(evt);
176 }); 204 });
177 } 205 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698