| 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, |
| 41 subEventName, | 41 this, |
| 42 opt_argSchemas, | 42 subEventName, |
| 43 opt_eventOptions, | 43 opt_argSchemas, |
| 44 webViewInstanceId); | 44 opt_eventOptions, |
| 45 webViewInstanceId); |
| 45 | 46 |
| 46 var view = GuestViewInternalNatives.GetViewFromID(webViewInstanceId); | 47 var view = GuestViewInternalNatives.GetViewFromID(webViewInstanceId); |
| 47 if (!view) { | 48 if (!view) { |
| 48 return; | 49 return; |
| 49 } | 50 } |
| 50 view.events.addScopedListener(ContextMenusEvent, function() { | 51 view.events.addScopedListener(ContextMenusEvent, function() { |
| 51 // Re-dispatch to subEvent's listeners. | 52 // Re-dispatch to subEvent's listeners. |
| 52 $Function.apply(this.dispatch, this, $Array.slice(arguments)); | 53 $Function.apply(this.dispatch, this, $Array.slice(arguments)); |
| 53 }.bind(this), {instanceId: webViewInstanceId}); | 54 }.bind(this), {instanceId: webViewInstanceId}); |
| 54 } | 55 } |
| 56 $Object.setPrototypeOf(ContextMenusOnClickedEvent.prototype, |
| 57 EventBindings.Event.prototype); |
| 55 | 58 |
| 56 ContextMenusOnClickedEvent.prototype.__proto__ = EventBindings.Event.prototype; | 59 // This event is exposed as <webview>.contextMenus.onShow. |
| 57 | |
| 58 function ContextMenusOnContextMenuEvent(webViewInstanceId, | 60 function ContextMenusOnContextMenuEvent(webViewInstanceId, |
| 59 opt_eventName, | 61 opt_eventName, |
| 60 opt_argSchemas, | 62 opt_argSchemas, |
| 61 opt_eventOptions) { | 63 opt_eventOptions) { |
| 62 var subEventName = GetUniqueSubEventName(opt_eventName); | 64 var subEventName = GetUniqueSubEventName(opt_eventName); |
| 63 EventBindings.Event.call(this, | 65 $Function.call(EventBindings.Event, |
| 64 subEventName, | 66 this, |
| 65 opt_argSchemas, | 67 subEventName, |
| 66 opt_eventOptions, | 68 opt_argSchemas, |
| 67 webViewInstanceId); | 69 opt_eventOptions, |
| 70 webViewInstanceId); |
| 68 | 71 |
| 69 var view = GuestViewInternalNatives.GetViewFromID(webViewInstanceId); | 72 var view = GuestViewInternalNatives.GetViewFromID(webViewInstanceId); |
| 70 if (!view) { | 73 if (!view) { |
| 71 return; | 74 return; |
| 72 } | 75 } |
| 73 view.events.addScopedListener(ContextMenusHandlerEvent, function(e) { | 76 view.events.addScopedListener(ContextMenusHandlerEvent, function(e) { |
| 74 var defaultPrevented = false; | 77 var defaultPrevented = false; |
| 75 var event = { | 78 var event = { |
| 76 'preventDefault': function() { defaultPrevented = true; } | 79 'preventDefault': function() { defaultPrevented = true; } |
| 77 }; | 80 }; |
| 78 | 81 |
| 79 // Re-dispatch to subEvent's listeners. | 82 // Re-dispatch to subEvent's listeners. |
| 80 $Function.apply(this.dispatch, this, [event]); | 83 $Function.apply(this.dispatch, this, [event]); |
| 81 | 84 |
| 82 if (!defaultPrevented) { | 85 if (!defaultPrevented) { |
| 83 // TODO(lazyboy): Remove |items| parameter completely from | 86 // TODO(lazyboy): Remove |items| parameter completely from |
| 84 // ChromeWebView.showContextMenu as we don't do anything useful with it | 87 // ChromeWebView.showContextMenu as we don't do anything useful with it |
| 85 // currently. | 88 // currently. |
| 86 var items = []; | 89 var items = []; |
| 87 var guestInstanceId = GuestViewInternalNatives. | 90 var guestInstanceId = GuestViewInternalNatives. |
| 88 GetViewFromID(webViewInstanceId).guest.getId(); | 91 GetViewFromID(webViewInstanceId).guest.getId(); |
| 89 ChromeWebView.showContextMenu(guestInstanceId, e.requestId, items); | 92 ChromeWebView.showContextMenu(guestInstanceId, e.requestId, items); |
| 90 } | 93 } |
| 91 }.bind(this), {instanceId: webViewInstanceId}); | 94 }.bind(this), {instanceId: webViewInstanceId}); |
| 92 } | 95 } |
| 93 | 96 |
| 94 ContextMenusOnContextMenuEvent.prototype.__proto__ = | 97 $Object.setPrototypeOf(ContextMenusOnContextMenuEvent.prototype, |
| 95 EventBindings.Event.prototype; | 98 EventBindings.Event.prototype); |
| 96 | 99 |
| 97 // ----------------------------------------------------------------------------- | 100 // ----------------------------------------------------------------------------- |
| 98 // WebViewContextMenusImpl object. | 101 // WebViewContextMenusImpl object. |
| 99 | 102 |
| 100 // An instance of this class is exposed as <webview>.contextMenus. | 103 // An instance of this class is exposed as <webview>.contextMenus. |
| 101 function WebViewContextMenusImpl(viewInstanceId) { | 104 function WebViewContextMenusImpl(viewInstanceId) { |
| 102 this.viewInstanceId_ = viewInstanceId; | 105 this.viewInstanceId_ = viewInstanceId; |
| 103 } | 106 } |
| 107 $Object.setPrototypeOf(WebViewContextMenusImpl.prototype, null); |
| 104 | 108 |
| 105 WebViewContextMenusImpl.prototype.create = function() { | 109 WebViewContextMenusImpl.prototype.create = function() { |
| 106 var args = $Array.concat([this.viewInstanceId_], $Array.slice(arguments)); | 110 var args = $Array.concat([this.viewInstanceId_], $Array.slice(arguments)); |
| 107 return $Function.apply(ChromeWebView.contextMenusCreate, null, args); | 111 return $Function.apply(ChromeWebView.contextMenusCreate, null, args); |
| 108 }; | 112 }; |
| 109 | 113 |
| 110 WebViewContextMenusImpl.prototype.remove = function() { | 114 WebViewContextMenusImpl.prototype.remove = function() { |
| 111 var args = $Array.concat([this.viewInstanceId_], $Array.slice(arguments)); | 115 var args = $Array.concat([this.viewInstanceId_], $Array.slice(arguments)); |
| 112 return $Function.apply(ChromeWebView.contextMenusRemove, null, args); | 116 return $Function.apply(ChromeWebView.contextMenusRemove, null, args); |
| 113 }; | 117 }; |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 get: this.weakWrapper(function() { | 185 get: this.weakWrapper(function() { |
| 182 return this.contextMenusOnContextMenuEvent_; | 186 return this.contextMenusOnContextMenuEvent_; |
| 183 }), | 187 }), |
| 184 enumerable: true | 188 enumerable: true |
| 185 }); | 189 }); |
| 186 return this.contextMenus_; | 190 return this.contextMenus_; |
| 187 }); | 191 }); |
| 188 }.bind(this); | 192 }.bind(this); |
| 189 | 193 |
| 190 // Expose <webview>.contextMenus object. | 194 // Expose <webview>.contextMenus object. |
| 191 // TODO(lazyboy): Add documentation for contextMenus: | |
| 192 // http://crbug.com/470979. | |
| 193 $Object.defineProperty( | 195 $Object.defineProperty( |
| 194 this.element, | 196 this.element, |
| 195 'contextMenus', | 197 'contextMenus', |
| 196 { | 198 { |
| 197 get: createContextMenus(), | 199 get: createContextMenus(), |
| 198 enumerable: true | 200 enumerable: true |
| 199 }); | 201 }); |
| 200 }; | 202 }; |
| 201 | 203 |
| 202 function GetUniqueSubEventName(eventName) { | 204 function GetUniqueSubEventName(eventName) { |
| 203 return eventName + '/' + idGeneratorNatives.GetNextId(); | 205 return eventName + '/' + idGeneratorNatives.GetNextId(); |
| 204 } | 206 } |
| OLD | NEW |