Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 // This module implements experimental API for <webview>. | 5 // This module implements experimental API for <webview>. |
| 6 // See web_view.js for details. | 6 // See web_view.js for details. |
| 7 // | 7 // |
| 8 // <webview> Chrome Experimental API is only available on canary and dev | 8 // <webview> Chrome Experimental API is only available on canary and dev |
| 9 // channels of Chrome. | 9 // channels of Chrome. |
| 10 | 10 |
| 11 var ChromeWebView = require('chromeWebViewInternal').ChromeWebView; | 11 var ChromeWebView = require('chromeWebViewInternal').ChromeWebView; |
| 12 var ChromeWebViewSchema = | 12 var ChromeWebViewSchema = |
| 13 requireNative('schema_registry').GetSchema('chromeWebViewInternal'); | 13 requireNative('schema_registry').GetSchema('chromeWebViewInternal'); |
| 14 var ContextMenusSchema = | 14 var ContextMenusSchema = |
| 15 requireNative('schema_registry').GetSchema('contextMenus'); | 15 requireNative('schema_registry').GetSchema('contextMenus'); |
| 16 var CreateEvent = require('webViewEvents').CreateEvent; | 16 var CreateEvent = require('webViewEvents').CreateEvent; |
| 17 var EventBindings = require('event_bindings'); | 17 var EventBindings = require('event_bindings'); |
| 18 var idGeneratorNatives = requireNative('id_generator'); | 18 var idGeneratorNatives = requireNative('id_generator'); |
| 19 var MessagingNatives = requireNative('messaging_natives'); | 19 var MessagingNatives = requireNative('messaging_natives'); |
| 20 var utils = require('utils'); | 20 var utils = require('utils'); |
| 21 var WebViewImpl = require('webView').WebViewImpl; | 21 var WebViewImpl = require('webView').WebViewImpl; |
| 22 var WebRequestEvent = require('webRequestInternal').WebRequestEvent; | |
| 23 var DeclarativeContentSchema = | |
| 24 requireNative('schema_registry').GetSchema('declarativeContent'); | |
| 22 | 25 |
| 23 function GetUniqueSubEventName(eventName) { | 26 function GetUniqueSubEventName(eventName) { |
| 24 return eventName + '/' + idGeneratorNatives.GetNextId(); | 27 return eventName + '/' + idGeneratorNatives.GetNextId(); |
| 25 } | 28 } |
| 26 | 29 |
| 27 // This is the only "webViewInternal.onClicked" named event for this renderer. | 30 // This is the only "webViewInternal.onClicked" named event for this renderer. |
| 28 // | 31 // |
| 29 // Since we need an event per <webview>, we define events with suffix | 32 // Since we need an event per <webview>, we define events with suffix |
| 30 // (subEventName) in each of the <webview>. Behind the scenes, this event is | 33 // (subEventName) in each of the <webview>. Behind the scenes, this event is |
| 31 // registered as a ContextMenusEvent, with filter set to the webview's | 34 // registered as a ContextMenusEvent, with filter set to the webview's |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 168 | 171 |
| 169 // Expose <webview>.contextMenus object. | 172 // Expose <webview>.contextMenus object. |
| 170 Object.defineProperty( | 173 Object.defineProperty( |
| 171 this.element, | 174 this.element, |
| 172 'contextMenus', | 175 'contextMenus', |
| 173 { | 176 { |
| 174 get: createContextMenus(), | 177 get: createContextMenus(), |
| 175 enumerable: true | 178 enumerable: true |
| 176 }); | 179 }); |
| 177 }; | 180 }; |
| 181 | |
| 182 WebViewImpl.prototype.maybeSetupExperimentalChromeWebViewEvents = function( | |
| 183 request) { | |
| 184 var createDeclarativeContentEvent = function(declarativeContentEvent) { | |
| 185 return function() { | |
| 186 if (!this[declarativeContentEvent.name]) { | |
| 187 this[declarativeContentEvent.name] = | |
| 188 new WebRequestEvent( | |
|
Fady Samuel
2014/12/09 22:09:47
Use EventBindings.Event instead: https://code.goog
Xi Han
2014/12/10 14:57:12
Updated.
| |
| 189 'webViewInternal.declarativeContent.' + | |
| 190 declarativeContentEvent.name, | |
| 191 declarativeContentEvent.parameters, | |
| 192 declarativeContentEvent.extraParameters, | |
| 193 declarativeContentEvent.options, | |
| 194 this.viewInstanceId); | |
| 195 } | |
| 196 return this[declarativeContentEvent.name]; | |
| 197 }.bind(this); | |
| 198 }.bind(this); | |
| 199 | |
| 200 for (var i = 0; i < DeclarativeContentSchema.events.length; ++i) { | |
| 201 var eventSchema = DeclarativeContentSchema.events[i]; | |
| 202 var declarativeContentEvent = createDeclarativeContentEvent(eventSchema); | |
| 203 Object.defineProperty( | |
| 204 request, | |
| 205 eventSchema.name, | |
| 206 { | |
| 207 get: declarativeContentEvent, | |
| 208 enumerable: true | |
| 209 } | |
| 210 ); | |
| 211 } | |
| 212 return request; | |
| 213 }; | |
| 214 | |
| OLD | NEW |