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

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: Updated stale browser_plugin_messages.h 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 chrome.webview.executeScript.apply(null, args);
80 }
81
74 // Map attribute modifications on the <webview> tag to property changes in 82 // Map attribute modifications on the <webview> tag to property changes in
75 // the underlying <object> node. 83 // the underlying <object> node.
76 var handleMutation = this.handleMutation_.bind(this); 84 var handleMutation = this.handleMutation_.bind(this);
77 var observer = new WebKitMutationObserver(function(mutations) { 85 var observer = new WebKitMutationObserver(function(mutations) {
78 mutations.forEach(handleMutation); 86 mutations.forEach(handleMutation);
79 }); 87 });
80 observer.observe( 88 observer.observe(
81 this.node_, 89 this.node_,
82 {attributes: true, attributeFilter: WEB_VIEW_ATTRIBUTES}); 90 {attributes: true, attributeFilter: WEB_VIEW_ATTRIBUTES});
83 91
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 var node = this.node_; 168 var node = this.node_;
161 this.objectNode_.addEventListener('-internal-' + eventname, function(e) { 169 this.objectNode_.addEventListener('-internal-' + eventname, function(e) {
162 var evt = new Event(eventname); 170 var evt = new Event(eventname);
163 var detail = e.detail ? JSON.parse(e.detail) : {}; 171 var detail = e.detail ? JSON.parse(e.detail) : {};
164 attribs.forEach(function(attribName) { 172 attribs.forEach(function(attribName) {
165 evt[attribName] = detail[attribName]; 173 evt[attribName] = detail[attribName];
166 }); 174 });
167 node.dispatchEvent(evt); 175 node.dispatchEvent(evt);
168 }); 176 });
169 } 177 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698