Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(311)

Side by Side Diff: chrome/renderer/resources/extensions/web_view_experimental.js

Issue 530043002: <webview> cleanup: Change self = this to bind(this) in web_view.js (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed rebase Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/renderer/resources/extensions/web_view_events.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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> Experimental API is only available on canary and dev channels of 8 // <webview> Experimental API is only available on canary and dev channels of
9 // Chrome. 9 // Chrome.
10 10
(...skipping 29 matching lines...) Expand all
40 * @constructor 40 * @constructor
41 */ 41 */
42 function ContextMenusOnClickedEvent(opt_eventName, 42 function ContextMenusOnClickedEvent(opt_eventName,
43 opt_argSchemas, 43 opt_argSchemas,
44 opt_eventOptions, 44 opt_eventOptions,
45 opt_webViewInstanceId) { 45 opt_webViewInstanceId) {
46 var subEventName = GetUniqueSubEventName(opt_eventName); 46 var subEventName = GetUniqueSubEventName(opt_eventName);
47 EventBindings.Event.call(this, subEventName, opt_argSchemas, opt_eventOptions, 47 EventBindings.Event.call(this, subEventName, opt_argSchemas, opt_eventOptions,
48 opt_webViewInstanceId); 48 opt_webViewInstanceId);
49 49
50 var self = this;
51 // TODO(lazyboy): When do we dispose this listener? 50 // TODO(lazyboy): When do we dispose this listener?
52 ContextMenusEvent.addListener(function() { 51 ContextMenusEvent.addListener(function() {
53 // Re-dispatch to subEvent's listeners. 52 // Re-dispatch to subEvent's listeners.
54 $Function.apply(self.dispatch, self, $Array.slice(arguments)); 53 $Function.apply(this.dispatch, this, $Array.slice(arguments));
55 }, {instanceId: opt_webViewInstanceId || 0}); 54 }.bind(this), {instanceId: opt_webViewInstanceId || 0});
56 } 55 }
57 56
58 ContextMenusOnClickedEvent.prototype = { 57 ContextMenusOnClickedEvent.prototype = {
59 __proto__: EventBindings.Event.prototype 58 __proto__: EventBindings.Event.prototype
60 }; 59 };
61 60
62 /** 61 /**
63 * An instance of this class is exposed as <webview>.contextMenus. 62 * An instance of this class is exposed as <webview>.contextMenus.
64 * @constructor 63 * @constructor
65 */ 64 */
(...skipping 21 matching lines...) Expand all
87 return $Function.apply(WebView.contextMenusUpdate, null, args); 86 return $Function.apply(WebView.contextMenusUpdate, null, args);
88 }; 87 };
89 88
90 var WebViewContextMenus = utils.expose( 89 var WebViewContextMenus = utils.expose(
91 'WebViewContextMenus', WebViewContextMenusImpl, 90 'WebViewContextMenus', WebViewContextMenusImpl,
92 { functions: ['create', 'remove', 'removeAll', 'update'] }); 91 { functions: ['create', 'remove', 'removeAll', 'update'] });
93 92
94 /** @private */ 93 /** @private */
95 WebViewInternal.prototype.maybeHandleContextMenu = function(e, webViewEvent) { 94 WebViewInternal.prototype.maybeHandleContextMenu = function(e, webViewEvent) {
96 var requestId = e.requestId; 95 var requestId = e.requestId;
97 var self = this;
98 // Construct the event.menu object. 96 // Construct the event.menu object.
99 var actionTaken = false; 97 var actionTaken = false;
100 var validateCall = function() { 98 var validateCall = function() {
101 var ERROR_MSG_CONTEXT_MENU_ACTION_ALREADY_TAKEN = '<webview>: ' + 99 var ERROR_MSG_CONTEXT_MENU_ACTION_ALREADY_TAKEN = '<webview>: ' +
102 'An action has already been taken for this "contextmenu" event.'; 100 'An action has already been taken for this "contextmenu" event.';
103 101
104 if (actionTaken) { 102 if (actionTaken) {
105 throw new Error(ERROR_MSG_CONTEXT_MENU_ACTION_ALREADY_TAKEN); 103 throw new Error(ERROR_MSG_CONTEXT_MENU_ACTION_ALREADY_TAKEN);
106 } 104 }
107 actionTaken = true; 105 actionTaken = true;
108 }; 106 };
109 var menu = { 107 var menu = {
110 show: function(items) { 108 show: function(items) {
111 validateCall(); 109 validateCall();
112 // TODO(lazyboy): WebViewShowContextFunction doesn't do anything useful 110 // TODO(lazyboy): WebViewShowContextFunction doesn't do anything useful
113 // with |items|, implement. 111 // with |items|, implement.
114 WebView.showContextMenu(self.guestInstanceId, requestId, items); 112 WebView.showContextMenu(this.guestInstanceId, requestId, items);
115 } 113 }.bind(this)
116 }; 114 };
117 webViewEvent.menu = menu; 115 webViewEvent.menu = menu;
118 var webviewNode = this.webviewNode; 116 var webviewNode = this.webviewNode;
119 var defaultPrevented = !webviewNode.dispatchEvent(webViewEvent); 117 var defaultPrevented = !webviewNode.dispatchEvent(webViewEvent);
120 if (actionTaken) { 118 if (actionTaken) {
121 return; 119 return;
122 } 120 }
123 if (!defaultPrevented) { 121 if (!defaultPrevented) {
124 actionTaken = true; 122 actionTaken = true;
125 // The default action is equivalent to just showing the context menu as is. 123 // The default action is equivalent to just showing the context menu as is.
126 WebView.showContextMenu(self.guestInstanceId, requestId, undefined); 124 WebView.showContextMenu(this.guestInstanceId, requestId, undefined);
127 125
128 // TODO(lazyboy): Figure out a way to show warning message only when 126 // TODO(lazyboy): Figure out a way to show warning message only when
129 // listeners are registered for this event. 127 // listeners are registered for this event.
130 } // else we will ignore showing the context menu completely. 128 } // else we will ignore showing the context menu completely.
131 }; 129 };
132 130
133 WebViewInternal.prototype.maybeGetExperimentalEvents = function() { 131 WebViewInternal.prototype.maybeGetExperimentalEvents = function() {
134 return {}; 132 return {};
135 }; 133 };
136 134
137 /** @private */ 135 /** @private */
138 WebViewInternal.prototype.maybeGetExperimentalPermissions = function() { 136 WebViewInternal.prototype.maybeGetExperimentalPermissions = function() {
139 return []; 137 return [];
140 }; 138 };
141 139
142 /** @private */ 140 /** @private */
143 WebViewInternal.prototype.captureVisibleRegion = function(spec, callback) { 141 WebViewInternal.prototype.captureVisibleRegion = function(spec, callback) {
144 WebView.captureVisibleRegion(this.guestInstanceId, spec, callback); 142 WebView.captureVisibleRegion(this.guestInstanceId, spec, callback);
145 }; 143 };
146 144
147 WebViewInternal.maybeRegisterExperimentalAPIs = function(proto) { 145 WebViewInternal.maybeRegisterExperimentalAPIs = function(proto) {
148 proto.captureVisibleRegion = function(spec, callback) { 146 proto.captureVisibleRegion = function(spec, callback) {
149 privates(this).internal.captureVisibleRegion(spec, callback); 147 privates(this).internal.captureVisibleRegion(spec, callback);
150 }; 148 };
151 }; 149 };
152 150
153 /** @private */ 151 /** @private */
154 WebViewInternal.prototype.setupExperimentalContextMenus = function() { 152 WebViewInternal.prototype.setupExperimentalContextMenus = function() {
155 var self = this;
156 var createContextMenus = function() { 153 var createContextMenus = function() {
157 return function() { 154 return function() {
158 if (self.contextMenus_) { 155 if (this.contextMenus_) {
159 return self.contextMenus_; 156 return this.contextMenus_;
160 } 157 }
161 158
162 self.contextMenus_ = new WebViewContextMenus(self.viewInstanceId); 159 this.contextMenus_ = new WebViewContextMenus(this.viewInstanceId);
163 160
164 // Define 'onClicked' event property on |self.contextMenus_|. 161 // Define 'onClicked' event property on |this.contextMenus_|.
165 var getOnClickedEvent = function() { 162 var getOnClickedEvent = function() {
166 return function() { 163 return function() {
167 if (!self.contextMenusOnClickedEvent_) { 164 if (!this.contextMenusOnClickedEvent_) {
168 var eventName = 'webViewInternal.onClicked'; 165 var eventName = 'webViewInternal.onClicked';
169 // TODO(lazyboy): Find event by name instead of events[0]. 166 // TODO(lazyboy): Find event by name instead of events[0].
170 var eventSchema = WebViewSchema.events[0]; 167 var eventSchema = WebViewSchema.events[0];
171 var eventOptions = {supportsListeners: true}; 168 var eventOptions = {supportsListeners: true};
172 var onClickedEvent = new ContextMenusOnClickedEvent( 169 var onClickedEvent = new ContextMenusOnClickedEvent(
173 eventName, eventSchema, eventOptions, self.viewInstanceId); 170 eventName, eventSchema, eventOptions, this.viewInstanceId);
174 self.contextMenusOnClickedEvent_ = onClickedEvent; 171 this.contextMenusOnClickedEvent_ = onClickedEvent;
175 return onClickedEvent; 172 return onClickedEvent;
176 } 173 }
177 return self.contextMenusOnClickedEvent_; 174 return this.contextMenusOnClickedEvent_;
178 } 175 }.bind(this);
179 }; 176 }.bind(this);
180 Object.defineProperty( 177 Object.defineProperty(
181 self.contextMenus_, 178 this.contextMenus_,
182 'onClicked', 179 'onClicked',
183 {get: getOnClickedEvent(), enumerable: true}); 180 {get: getOnClickedEvent(), enumerable: true});
184 181
185 return self.contextMenus_; 182 return this.contextMenus_;
186 }; 183 }.bind(this);
187 }; 184 }.bind(this);
188 185
189 // Expose <webview>.contextMenus object. 186 // Expose <webview>.contextMenus object.
190 Object.defineProperty( 187 Object.defineProperty(
191 this.webviewNode, 188 this.webviewNode,
192 'contextMenus', 189 'contextMenus',
193 { 190 {
194 get: createContextMenus(), 191 get: createContextMenus(),
195 enumerable: true 192 enumerable: true
196 }); 193 });
197 }; 194 };
OLDNEW
« no previous file with comments | « chrome/renderer/resources/extensions/web_view_events.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698