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

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

Issue 11968054: <webview>: Implement ExecuteScript (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Renamed misnamed variable Created 7 years, 11 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 watchForTag = require("tagWatcher").watchForTag; 10 var watchForTag = require("tagWatcher").watchForTag;
11 var sendRequest = require("sendRequest").sendRequest;
11 12
12 var WEB_VIEW_ATTRIBUTES = ['name', 'src', 'partition']; 13 var WEB_VIEW_ATTRIBUTES = ['name', 'src', 'partition'];
13 14
14 // All exposed api methods for <webview>, these are forwarded to the browser 15 // All exposed api methods for <webview>, these are forwarded to the browser
15 // plugin. 16 // plugin.
16 var WEB_VIEW_API_METHODS = [ 17 var WEB_VIEW_API_METHODS = [
17 'back', 18 'back',
18 'canGoBack', 19 'canGoBack',
19 'canGoForward', 20 'canGoForward',
20 'forward', 21 'forward',
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 65
65 // this.objectNode_[apiMethod] are not necessarily defined immediately after 66 // this.objectNode_[apiMethod] are not necessarily defined immediately after
66 // the shadow object is appended to the shadow root. 67 // the shadow object is appended to the shadow root.
67 var self = this; 68 var self = this;
68 WEB_VIEW_API_METHODS.forEach(function(apiMethod) { 69 WEB_VIEW_API_METHODS.forEach(function(apiMethod) {
69 node[apiMethod] = function(var_args) { 70 node[apiMethod] = function(var_args) {
70 return self.objectNode_[apiMethod].apply(self.objectNode_, arguments); 71 return self.objectNode_[apiMethod].apply(self.objectNode_, arguments);
71 }; 72 };
72 }, this); 73 }, this);
73 74
75 node['executeScript'] = function(var_args) {
76 var args = [self.objectNode_.getProcessId(),
77 self.objectNode_.getRouteId()].concat(
78 Array.prototype.slice.call(arguments));
79 sendRequest('webview.executeScript', args,
80 [{ "type": "integer", "name": "processId" },
81 { "type": "integer", "name": "routeId" },
82 { "type": "object", "name": "details" },
83 { "type": "function", "name": "callback", "optional": true }]);
Matt Perry 2013/01/23 02:50:49 If you need to expose more APIs to webview, I reco
Fady Samuel 2013/01/23 20:12:03 Done.
84 }
85
74 // Map attribute modifications on the <webview> tag to property changes in 86 // Map attribute modifications on the <webview> tag to property changes in
75 // the underlying <object> node. 87 // the underlying <object> node.
76 var handleMutation = this.handleMutation_.bind(this); 88 var handleMutation = this.handleMutation_.bind(this);
77 var observer = new WebKitMutationObserver(function(mutations) { 89 var observer = new WebKitMutationObserver(function(mutations) {
78 mutations.forEach(handleMutation); 90 mutations.forEach(handleMutation);
79 }); 91 });
80 observer.observe( 92 observer.observe(
81 this.node_, 93 this.node_,
82 {attributes: true, attributeFilter: WEB_VIEW_ATTRIBUTES}); 94 {attributes: true, attributeFilter: WEB_VIEW_ATTRIBUTES});
83 95
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 var node = this.node_; 169 var node = this.node_;
158 this.objectNode_.addEventListener('-internal-' + eventname, function(e) { 170 this.objectNode_.addEventListener('-internal-' + eventname, function(e) {
159 var evt = new Event(eventname); 171 var evt = new Event(eventname);
160 var detail = e.detail ? JSON.parse(e.detail) : {}; 172 var detail = e.detail ? JSON.parse(e.detail) : {};
161 attribs.forEach(function(attribName) { 173 attribs.forEach(function(attribName) {
162 evt[attribName] = detail[attribName]; 174 evt[attribName] = detail[attribName];
163 }); 175 });
164 node.dispatchEvent(evt); 176 node.dispatchEvent(evt);
165 }); 177 });
166 } 178 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698