| OLD | NEW |
| 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; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 | 64 |
| 65 // this.objectNode_[apiMethod] are not necessarily defined immediately after | 65 // this.objectNode_[apiMethod] are not necessarily defined immediately after |
| 66 // the shadow object is appended to the shadow root. | 66 // the shadow object is appended to the shadow root. |
| 67 var self = this; | 67 var self = this; |
| 68 WEB_VIEW_API_METHODS.forEach(function(apiMethod) { | 68 WEB_VIEW_API_METHODS.forEach(function(apiMethod) { |
| 69 node[apiMethod] = function(var_args) { | 69 node[apiMethod] = function(var_args) { |
| 70 return self.objectNode_[apiMethod].apply(self.objectNode_, arguments); | 70 return self.objectNode_[apiMethod].apply(self.objectNode_, arguments); |
| 71 }; | 71 }; |
| 72 }, this); | 72 }, this); |
| 73 | 73 |
| 74 node['executeScript'] = function(var_args) { |
| 75 var args = [self.objectNode_.getProcessId(), |
| 76 self.objectNode_.getRouteId()].concat( |
| 77 Array.prototype.slice.call(arguments)); |
| 78 chrome.webview.executeScript.apply(null, args); |
| 79 } |
| 80 |
| 74 // Map attribute modifications on the <webview> tag to property changes in | 81 // Map attribute modifications on the <webview> tag to property changes in |
| 75 // the underlying <object> node. | 82 // the underlying <object> node. |
| 76 var handleMutation = this.handleMutation_.bind(this); | 83 var handleMutation = this.handleMutation_.bind(this); |
| 77 var observer = new WebKitMutationObserver(function(mutations) { | 84 var observer = new WebKitMutationObserver(function(mutations) { |
| 78 mutations.forEach(handleMutation); | 85 mutations.forEach(handleMutation); |
| 79 }); | 86 }); |
| 80 observer.observe( | 87 observer.observe( |
| 81 this.node_, | 88 this.node_, |
| 82 {attributes: true, attributeFilter: WEB_VIEW_ATTRIBUTES}); | 89 {attributes: true, attributeFilter: WEB_VIEW_ATTRIBUTES}); |
| 83 | 90 |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 var node = this.node_; | 167 var node = this.node_; |
| 161 this.objectNode_.addEventListener('-internal-' + eventname, function(e) { | 168 this.objectNode_.addEventListener('-internal-' + eventname, function(e) { |
| 162 var evt = new Event(eventname); | 169 var evt = new Event(eventname); |
| 163 var detail = e.detail ? JSON.parse(e.detail) : {}; | 170 var detail = e.detail ? JSON.parse(e.detail) : {}; |
| 164 attribs.forEach(function(attribName) { | 171 attribs.forEach(function(attribName) { |
| 165 evt[attribName] = detail[attribName]; | 172 evt[attribName] = detail[attribName]; |
| 166 }); | 173 }); |
| 167 node.dispatchEvent(evt); | 174 node.dispatchEvent(evt); |
| 168 }); | 175 }); |
| 169 } | 176 } |
| OLD | NEW |