OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 chrome-specific <webview> API. | 5 // This module implements chrome-specific <webview> API. |
6 // See web_view_api_methods.js for details. | 6 // See web_view_api_methods.js for details. |
7 | 7 |
8 var ChromeWebView = require('chromeWebViewInternal').ChromeWebView; | 8 var ChromeWebView = require('chromeWebViewInternal').ChromeWebView; |
9 var ChromeWebViewSchema = | 9 var ChromeWebViewSchema = |
10 requireNative('schema_registry').GetSchema('chromeWebViewInternal'); | 10 requireNative('schema_registry').GetSchema('chromeWebViewInternal'); |
(...skipping 19 matching lines...) Expand all Loading... | |
30 | 30 |
31 // ----------------------------------------------------------------------------- | 31 // ----------------------------------------------------------------------------- |
32 // ContextMenusOnClickedEvent object. | 32 // ContextMenusOnClickedEvent object. |
33 | 33 |
34 // This event is exposed as <webview>.contextMenus.onClicked. | 34 // This event is exposed as <webview>.contextMenus.onClicked. |
35 function ContextMenusOnClickedEvent(webViewInstanceId, | 35 function ContextMenusOnClickedEvent(webViewInstanceId, |
36 opt_eventName, | 36 opt_eventName, |
37 opt_argSchemas, | 37 opt_argSchemas, |
38 opt_eventOptions) { | 38 opt_eventOptions) { |
39 var subEventName = GetUniqueSubEventName(opt_eventName); | 39 var subEventName = GetUniqueSubEventName(opt_eventName); |
40 EventBindings.Event.call(this, | 40 $Function.call(EventBindings.Event, this, |
41 subEventName, | 41 subEventName, opt_argSchemas, opt_eventOptions, webViewInstanceId); |
Devlin
2016/04/26 22:41:25
nit: prefer to line these params up (multiple line
robwu
2016/04/26 23:14:33
Done.
| |
42 opt_argSchemas, | |
43 opt_eventOptions, | |
44 webViewInstanceId); | |
45 | 42 |
46 var view = GuestViewInternalNatives.GetViewFromID(webViewInstanceId); | 43 var view = GuestViewInternalNatives.GetViewFromID(webViewInstanceId); |
47 if (!view) { | 44 if (!view) { |
48 return; | 45 return; |
49 } | 46 } |
50 view.events.addScopedListener(ContextMenusEvent, function() { | 47 view.events.addScopedListener(ContextMenusEvent, function() { |
51 // Re-dispatch to subEvent's listeners. | 48 // Re-dispatch to subEvent's listeners. |
52 $Function.apply(this.dispatch, this, $Array.slice(arguments)); | 49 $Function.apply(this.dispatch, this, $Array.slice(arguments)); |
53 }.bind(this), {instanceId: webViewInstanceId}); | 50 }.bind(this), {instanceId: webViewInstanceId}); |
54 } | 51 } |
52 $Object.setPrototypeOf( | |
53 ContextMenusOnClickedEvent.prototype, EventBindings.Event.prototype); | |
55 | 54 |
56 ContextMenusOnClickedEvent.prototype.__proto__ = EventBindings.Event.prototype; | 55 // This event is exposed as <webview>.contextMenus.onShow. |
57 | |
58 function ContextMenusOnContextMenuEvent(webViewInstanceId, | 56 function ContextMenusOnContextMenuEvent(webViewInstanceId, |
59 opt_eventName, | 57 opt_eventName, |
60 opt_argSchemas, | 58 opt_argSchemas, |
61 opt_eventOptions) { | 59 opt_eventOptions) { |
62 var subEventName = GetUniqueSubEventName(opt_eventName); | 60 var subEventName = GetUniqueSubEventName(opt_eventName); |
63 EventBindings.Event.call(this, | 61 $Function.call(EventBindings.Event, this, |
64 subEventName, | 62 subEventName, opt_argSchemas, opt_eventOptions, webViewInstanceId); |
65 opt_argSchemas, | |
66 opt_eventOptions, | |
67 webViewInstanceId); | |
68 | 63 |
69 var view = GuestViewInternalNatives.GetViewFromID(webViewInstanceId); | 64 var view = GuestViewInternalNatives.GetViewFromID(webViewInstanceId); |
70 if (!view) { | 65 if (!view) { |
71 return; | 66 return; |
72 } | 67 } |
73 view.events.addScopedListener(ContextMenusHandlerEvent, function(e) { | 68 view.events.addScopedListener(ContextMenusHandlerEvent, function(e) { |
74 var defaultPrevented = false; | 69 var defaultPrevented = false; |
75 var event = { | 70 var event = { |
76 'preventDefault': function() { defaultPrevented = true; } | 71 'preventDefault': function() { defaultPrevented = true; } |
77 }; | 72 }; |
78 | 73 |
79 // Re-dispatch to subEvent's listeners. | 74 // Re-dispatch to subEvent's listeners. |
80 $Function.apply(this.dispatch, this, [event]); | 75 $Function.apply(this.dispatch, this, [event]); |
81 | 76 |
82 if (!defaultPrevented) { | 77 if (!defaultPrevented) { |
83 // TODO(lazyboy): Remove |items| parameter completely from | 78 // TODO(lazyboy): Remove |items| parameter completely from |
84 // ChromeWebView.showContextMenu as we don't do anything useful with it | 79 // ChromeWebView.showContextMenu as we don't do anything useful with it |
85 // currently. | 80 // currently. |
86 var items = []; | 81 var items = []; |
87 var guestInstanceId = GuestViewInternalNatives. | 82 var guestInstanceId = GuestViewInternalNatives. |
88 GetViewFromID(webViewInstanceId).guest.getId(); | 83 GetViewFromID(webViewInstanceId).guest.getId(); |
89 ChromeWebView.showContextMenu(guestInstanceId, e.requestId, items); | 84 ChromeWebView.showContextMenu(guestInstanceId, e.requestId, items); |
90 } | 85 } |
91 }.bind(this), {instanceId: webViewInstanceId}); | 86 }.bind(this), {instanceId: webViewInstanceId}); |
92 } | 87 } |
93 | 88 |
94 ContextMenusOnContextMenuEvent.prototype.__proto__ = | 89 $Object.setPrototypeOf( |
95 EventBindings.Event.prototype; | 90 ContextMenusOnContextMenuEvent.prototype, EventBindings.Event.prototype); |
96 | 91 |
97 // ----------------------------------------------------------------------------- | 92 // ----------------------------------------------------------------------------- |
98 // WebViewContextMenusImpl object. | 93 // WebViewContextMenusImpl object. |
99 | 94 |
100 // An instance of this class is exposed as <webview>.contextMenus. | 95 // An instance of this class is exposed as <webview>.contextMenus. |
101 function WebViewContextMenusImpl(viewInstanceId) { | 96 function WebViewContextMenusImpl(viewInstanceId) { |
102 this.viewInstanceId_ = viewInstanceId; | 97 this.viewInstanceId_ = viewInstanceId; |
103 } | 98 } |
99 $Object.setPrototypeOf(WebViewContextMenusImpl, null); | |
100 $Object.setPrototypeOf(WebViewContextMenusImpl.prototype, null); | |
104 | 101 |
105 WebViewContextMenusImpl.prototype.create = function() { | 102 WebViewContextMenusImpl.prototype.create = function() { |
106 var args = $Array.concat([this.viewInstanceId_], $Array.slice(arguments)); | 103 var args = $Array.concat([this.viewInstanceId_], $Array.slice(arguments)); |
107 return $Function.apply(ChromeWebView.contextMenusCreate, null, args); | 104 return $Function.apply(ChromeWebView.contextMenusCreate, null, args); |
108 }; | 105 }; |
109 | 106 |
110 WebViewContextMenusImpl.prototype.remove = function() { | 107 WebViewContextMenusImpl.prototype.remove = function() { |
111 var args = $Array.concat([this.viewInstanceId_], $Array.slice(arguments)); | 108 var args = $Array.concat([this.viewInstanceId_], $Array.slice(arguments)); |
112 return $Function.apply(ChromeWebView.contextMenusRemove, null, args); | 109 return $Function.apply(ChromeWebView.contextMenusRemove, null, args); |
113 }; | 110 }; |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
181 get: this.weakWrapper(function() { | 178 get: this.weakWrapper(function() { |
182 return this.contextMenusOnContextMenuEvent_; | 179 return this.contextMenusOnContextMenuEvent_; |
183 }), | 180 }), |
184 enumerable: true | 181 enumerable: true |
185 }); | 182 }); |
186 return this.contextMenus_; | 183 return this.contextMenus_; |
187 }); | 184 }); |
188 }.bind(this); | 185 }.bind(this); |
189 | 186 |
190 // Expose <webview>.contextMenus object. | 187 // Expose <webview>.contextMenus object. |
191 // TODO(lazyboy): Add documentation for contextMenus: | |
192 // http://crbug.com/470979. | |
193 $Object.defineProperty( | 188 $Object.defineProperty( |
194 this.element, | 189 this.element, |
195 'contextMenus', | 190 'contextMenus', |
196 { | 191 { |
197 get: createContextMenus(), | 192 get: createContextMenus(), |
198 enumerable: true | 193 enumerable: true |
199 }); | 194 }); |
200 }; | 195 }; |
201 | 196 |
202 function GetUniqueSubEventName(eventName) { | 197 function GetUniqueSubEventName(eventName) { |
203 return eventName + '/' + idGeneratorNatives.GetNextId(); | 198 return eventName + '/' + idGeneratorNatives.GetNextId(); |
204 } | 199 } |
OLD | NEW |