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 DeclarativeContentSchema = | |
23 requireNative('schema_registry').GetSchema('declarativeContent'); | |
24 | |
25 var DeclarativeContentEvent = function(opt_eventName, | |
26 opt_argSchemas, | |
27 opt_eventOptions, | |
28 opt_webViewInstanceId) { | |
29 EventBindings.Event.call(this, | |
30 opt_eventName, | |
31 opt_argSchemas, | |
32 opt_eventOptions, | |
33 opt_webViewInstanceId); | |
34 } | |
35 | |
36 DeclarativeContentEvent.prototype = { | |
37 __proto__: EventBindings.Event.prototype | |
38 }; | |
22 | 39 |
23 function GetUniqueSubEventName(eventName) { | 40 function GetUniqueSubEventName(eventName) { |
24 return eventName + '/' + idGeneratorNatives.GetNextId(); | 41 return eventName + '/' + idGeneratorNatives.GetNextId(); |
25 } | 42 } |
26 | 43 |
27 // This is the only "webViewInternal.onClicked" named event for this renderer. | 44 // This is the only "webViewInternal.onClicked" named event for this renderer. |
28 // | 45 // |
29 // Since we need an event per <webview>, we define events with suffix | 46 // 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 | 47 // (subEventName) in each of the <webview>. Behind the scenes, this event is |
31 // registered as a ContextMenusEvent, with filter set to the webview's | 48 // 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 | 185 |
169 // Expose <webview>.contextMenus object. | 186 // Expose <webview>.contextMenus object. |
170 Object.defineProperty( | 187 Object.defineProperty( |
171 this.element, | 188 this.element, |
172 'contextMenus', | 189 'contextMenus', |
173 { | 190 { |
174 get: createContextMenus(), | 191 get: createContextMenus(), |
175 enumerable: true | 192 enumerable: true |
176 }); | 193 }); |
177 }; | 194 }; |
195 | |
196 WebViewImpl.prototype.maybeSetupExperimentalChromeWebViewEvents = function( | |
197 request) { | |
198 var createDeclarativeContentEvent = function(declarativeContentEvent) { | |
199 return function() { | |
200 if (!this[declarativeContentEvent.name]) { | |
201 this[declarativeContentEvent.name] = | |
202 new DeclarativeContentEvent( | |
203 'webViewInternal.declarativeContent.' + | |
Fady Samuel
2014/12/10 15:56:47
Can we try calling this by its original name?
Xi Han
2014/12/11 16:40:04
Done.
| |
204 declarativeContentEvent.name, | |
205 declarativeContentEvent.parameters, | |
206 declarativeContentEvent.options, | |
207 this.viewInstanceId); | |
208 } | |
209 return this[declarativeContentEvent.name]; | |
210 }.bind(this); | |
211 }.bind(this); | |
212 | |
213 for (var i = 0; i < DeclarativeContentSchema.events.length; ++i) { | |
214 var eventSchema = DeclarativeContentSchema.events[i]; | |
215 var declarativeContentEvent = createDeclarativeContentEvent(eventSchema); | |
216 Object.defineProperty( | |
217 request, | |
218 eventSchema.name, | |
219 { | |
220 get: declarativeContentEvent, | |
221 enumerable: true | |
222 } | |
223 ); | |
224 } | |
225 return request; | |
226 }; | |
227 | |
OLD | NEW |