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

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

Issue 541753004: Split web_view_internal_api and move part of it to extensions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebasing 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
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
11 var ContextMenusSchema = 11 var ContextMenusSchema =
12 requireNative('schema_registry').GetSchema('contextMenus'); 12 requireNative('schema_registry').GetSchema('contextMenus');
13 var CreateEvent = require('webViewEvents').CreateEvent; 13 var CreateEvent = require('webViewEvents').CreateEvent;
14 var EventBindings = require('event_bindings'); 14 var EventBindings = require('event_bindings');
15 var MessagingNatives = requireNative('messaging_natives'); 15 var MessagingNatives = requireNative('messaging_natives');
16 var WebView = require('webViewInternal').WebView; 16 //var WebView = require('webViewInternal').WebView;
17 var ChromeWebView = require('chromeWebViewInternal').ChromeWebView;
17 var WebViewInternal = require('webView').WebViewInternal; 18 var WebViewInternal = require('webView').WebViewInternal;
18 var WebViewSchema = 19 var ChromeWebViewSchema =
19 requireNative('schema_registry').GetSchema('webViewInternal'); 20 requireNative('schema_registry').GetSchema('chromeWebViewInternal');
20 var idGeneratorNatives = requireNative('id_generator'); 21 var idGeneratorNatives = requireNative('id_generator');
21 var utils = require('utils'); 22 var utils = require('utils');
22 23
23 function GetUniqueSubEventName(eventName) { 24 function GetUniqueSubEventName(eventName) {
24 return eventName + "/" + idGeneratorNatives.GetNextId(); 25 return eventName + "/" + idGeneratorNatives.GetNextId();
25 } 26 }
26 27
27 // This is the only "webViewInternal.onClicked" named event for this renderer. 28 // This is the only "webViewInternal.onClicked" named event for this renderer.
28 // 29 //
29 // Since we need an event per <webview>, we define events with suffix 30 // 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 31 // (subEventName) in each of the <webview>. Behind the scenes, this event is
31 // registered as a ContextMenusEvent, with filter set to the webview's 32 // registered as a ContextMenusEvent, with filter set to the webview's
32 // |viewInstanceId|. Any time a ContextMenusEvent is dispatched, we re-dispatch 33 // |viewInstanceId|. Any time a ContextMenusEvent is dispatched, we re-dispatch
33 // it to the subEvent's listeners. This way 34 // it to the subEvent's listeners. This way
34 // <webview>.contextMenus.onClicked behave as a regular chrome Event type. 35 // <webview>.contextMenus.onClicked behave as a regular chrome Event type.
35 var ContextMenusEvent = CreateEvent('webViewInternal.onClicked'); 36 var ContextMenusEvent = CreateEvent('chromeWebViewInternal.onClicked');
36 37
37 /** 38 /**
38 * This event is exposed as <webview>.contextMenus.onClicked. 39 * This event is exposed as <webview>.contextMenus.onClicked.
39 * 40 *
40 * @constructor 41 * @constructor
41 */ 42 */
42 function ContextMenusOnClickedEvent(opt_eventName, 43 function ContextMenusOnClickedEvent(opt_eventName,
43 opt_argSchemas, 44 opt_argSchemas,
44 opt_eventOptions, 45 opt_eventOptions,
45 opt_webViewInstanceId) { 46 opt_webViewInstanceId) {
(...skipping 15 matching lines...) Expand all
61 /** 62 /**
62 * An instance of this class is exposed as <webview>.contextMenus. 63 * An instance of this class is exposed as <webview>.contextMenus.
63 * @constructor 64 * @constructor
64 */ 65 */
65 function WebViewContextMenusImpl(viewInstanceId) { 66 function WebViewContextMenusImpl(viewInstanceId) {
66 this.viewInstanceId_ = viewInstanceId; 67 this.viewInstanceId_ = viewInstanceId;
67 }; 68 };
68 69
69 WebViewContextMenusImpl.prototype.create = function() { 70 WebViewContextMenusImpl.prototype.create = function() {
70 var args = $Array.concat([this.viewInstanceId_], $Array.slice(arguments)); 71 var args = $Array.concat([this.viewInstanceId_], $Array.slice(arguments));
71 return $Function.apply(WebView.contextMenusCreate, null, args); 72 return $Function.apply(ChromeWebView.contextMenusCreate, null, args);
72 }; 73 };
73 74
74 WebViewContextMenusImpl.prototype.remove = function() { 75 WebViewContextMenusImpl.prototype.remove = function() {
75 var args = $Array.concat([this.viewInstanceId_], $Array.slice(arguments)); 76 var args = $Array.concat([this.viewInstanceId_], $Array.slice(arguments));
76 return $Function.apply(WebView.contextMenusRemove, null, args); 77 return $Function.apply(ChromeWebView.contextMenusRemove, null, args);
77 }; 78 };
78 79
79 WebViewContextMenusImpl.prototype.removeAll = function() { 80 WebViewContextMenusImpl.prototype.removeAll = function() {
80 var args = $Array.concat([this.viewInstanceId_], $Array.slice(arguments)); 81 var args = $Array.concat([this.viewInstanceId_], $Array.slice(arguments));
81 return $Function.apply(WebView.contextMenusRemoveAll, null, args); 82 return $Function.apply(ChromeWebView.contextMenusRemoveAll, null, args);
82 }; 83 };
83 84
84 WebViewContextMenusImpl.prototype.update = function() { 85 WebViewContextMenusImpl.prototype.update = function() {
85 var args = $Array.concat([this.viewInstanceId_], $Array.slice(arguments)); 86 var args = $Array.concat([this.viewInstanceId_], $Array.slice(arguments));
86 return $Function.apply(WebView.contextMenusUpdate, null, args); 87 return $Function.apply(ChromeWebView.contextMenusUpdate, null, args);
87 }; 88 };
88 89
89 var WebViewContextMenus = utils.expose( 90 var WebViewContextMenus = utils.expose(
90 'WebViewContextMenus', WebViewContextMenusImpl, 91 'WebViewContextMenus', WebViewContextMenusImpl,
91 { functions: ['create', 'remove', 'removeAll', 'update'] }); 92 { functions: ['create', 'remove', 'removeAll', 'update'] });
92 93
93 /** @private */ 94 /** @private */
94 WebViewInternal.prototype.maybeHandleContextMenu = function(e, webViewEvent) { 95 WebViewInternal.prototype.maybeHandleContextMenu = function(e, webViewEvent) {
95 var requestId = e.requestId; 96 var requestId = e.requestId;
96 // Construct the event.menu object. 97 // Construct the event.menu object.
97 var actionTaken = false; 98 var actionTaken = false;
98 var validateCall = function() { 99 var validateCall = function() {
99 var ERROR_MSG_CONTEXT_MENU_ACTION_ALREADY_TAKEN = '<webview>: ' + 100 var ERROR_MSG_CONTEXT_MENU_ACTION_ALREADY_TAKEN = '<webview>: ' +
100 'An action has already been taken for this "contextmenu" event.'; 101 'An action has already been taken for this "contextmenu" event.';
101 102
102 if (actionTaken) { 103 if (actionTaken) {
103 throw new Error(ERROR_MSG_CONTEXT_MENU_ACTION_ALREADY_TAKEN); 104 throw new Error(ERROR_MSG_CONTEXT_MENU_ACTION_ALREADY_TAKEN);
104 } 105 }
105 actionTaken = true; 106 actionTaken = true;
106 }; 107 };
107 var menu = { 108 var menu = {
108 show: function(items) { 109 show: function(items) {
109 validateCall(); 110 validateCall();
110 // TODO(lazyboy): WebViewShowContextFunction doesn't do anything useful 111 // TODO(lazyboy): WebViewShowContextFunction doesn't do anything useful
111 // with |items|, implement. 112 // with |items|, implement.
112 WebView.showContextMenu(this.guestInstanceId, requestId, items); 113 ChromeWebView.showContextMenu(this.guestInstanceId, requestId, items);
113 }.bind(this) 114 }.bind(this)
114 }; 115 };
115 webViewEvent.menu = menu; 116 webViewEvent.menu = menu;
116 var webviewNode = this.webviewNode; 117 var webviewNode = this.webviewNode;
117 var defaultPrevented = !webviewNode.dispatchEvent(webViewEvent); 118 var defaultPrevented = !webviewNode.dispatchEvent(webViewEvent);
118 if (actionTaken) { 119 if (actionTaken) {
119 return; 120 return;
120 } 121 }
121 if (!defaultPrevented) { 122 if (!defaultPrevented) {
122 actionTaken = true; 123 actionTaken = true;
123 // The default action is equivalent to just showing the context menu as is. 124 // The default action is equivalent to just showing the context menu as is.
124 WebView.showContextMenu(this.guestInstanceId, requestId, undefined); 125 ChromeWebView.showContextMenu(this.guestInstanceId, requestId, undefined);
125 126
126 // TODO(lazyboy): Figure out a way to show warning message only when 127 // TODO(lazyboy): Figure out a way to show warning message only when
127 // listeners are registered for this event. 128 // listeners are registered for this event.
128 } // else we will ignore showing the context menu completely. 129 } // else we will ignore showing the context menu completely.
129 }; 130 };
130 131
131 WebViewInternal.prototype.maybeGetExperimentalEvents = function() { 132 WebViewInternal.prototype.maybeGetExperimentalEvents = function() {
132 return {}; 133 return {};
133 }; 134 };
134 135
(...skipping 20 matching lines...) Expand all
155 if (this.contextMenus_) { 156 if (this.contextMenus_) {
156 return this.contextMenus_; 157 return this.contextMenus_;
157 } 158 }
158 159
159 this.contextMenus_ = new WebViewContextMenus(this.viewInstanceId); 160 this.contextMenus_ = new WebViewContextMenus(this.viewInstanceId);
160 161
161 // Define 'onClicked' event property on |this.contextMenus_|. 162 // Define 'onClicked' event property on |this.contextMenus_|.
162 var getOnClickedEvent = function() { 163 var getOnClickedEvent = function() {
163 return function() { 164 return function() {
164 if (!this.contextMenusOnClickedEvent_) { 165 if (!this.contextMenusOnClickedEvent_) {
165 var eventName = 'webViewInternal.onClicked'; 166 var eventName = 'chromeWebViewInternal.onClicked';
166 // TODO(lazyboy): Find event by name instead of events[0]. 167 // TODO(lazyboy): Find event by name instead of events[0].
167 var eventSchema = WebViewSchema.events[0]; 168 var eventSchema = ChromeWebViewSchema.events[0];
168 var eventOptions = {supportsListeners: true}; 169 var eventOptions = {supportsListeners: true};
169 var onClickedEvent = new ContextMenusOnClickedEvent( 170 var onClickedEvent = new ContextMenusOnClickedEvent(
170 eventName, eventSchema, eventOptions, this.viewInstanceId); 171 eventName, eventSchema, eventOptions, this.viewInstanceId);
171 this.contextMenusOnClickedEvent_ = onClickedEvent; 172 this.contextMenusOnClickedEvent_ = onClickedEvent;
172 return onClickedEvent; 173 return onClickedEvent;
173 } 174 }
174 return this.contextMenusOnClickedEvent_; 175 return this.contextMenusOnClickedEvent_;
175 }.bind(this); 176 }.bind(this);
176 }.bind(this); 177 }.bind(this);
177 Object.defineProperty( 178 Object.defineProperty(
178 this.contextMenus_, 179 this.contextMenus_,
179 'onClicked', 180 'onClicked',
180 {get: getOnClickedEvent(), enumerable: true}); 181 {get: getOnClickedEvent(), enumerable: true});
181 182
182 return this.contextMenus_; 183 return this.contextMenus_;
183 }.bind(this); 184 }.bind(this);
184 }.bind(this); 185 }.bind(this);
185 186
186 // Expose <webview>.contextMenus object. 187 // Expose <webview>.contextMenus object.
187 Object.defineProperty( 188 Object.defineProperty(
188 this.webviewNode, 189 this.webviewNode,
189 'contextMenus', 190 'contextMenus',
190 { 191 {
191 get: createContextMenus(), 192 get: createContextMenus(),
192 enumerable: true 193 enumerable: true
193 }); 194 });
194 }; 195 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698