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; |
| 12 var ChromeWebViewSchema = |
| 13 requireNative('schema_registry').GetSchema('chromeWebViewInternal'); |
11 var ContextMenusSchema = | 14 var ContextMenusSchema = |
12 requireNative('schema_registry').GetSchema('contextMenus'); | 15 requireNative('schema_registry').GetSchema('contextMenus'); |
13 var CreateEvent = require('webViewEvents').CreateEvent; | 16 var CreateEvent = require('webViewEvents').CreateEvent; |
14 var EventBindings = require('event_bindings'); | 17 var EventBindings = require('event_bindings'); |
| 18 var idGeneratorNatives = requireNative('id_generator'); |
15 var MessagingNatives = requireNative('messaging_natives'); | 19 var MessagingNatives = requireNative('messaging_natives'); |
16 //var WebView = require('webViewInternal').WebView; | |
17 var ChromeWebView = require('chromeWebViewInternal').ChromeWebView; | |
18 var WebViewInternal = require('webView').WebViewInternal; | |
19 var ChromeWebViewSchema = | |
20 requireNative('schema_registry').GetSchema('chromeWebViewInternal'); | |
21 var idGeneratorNatives = requireNative('id_generator'); | |
22 var utils = require('utils'); | 20 var utils = require('utils'); |
| 21 var WebView = require('webView').WebView; |
23 | 22 |
24 function GetUniqueSubEventName(eventName) { | 23 function GetUniqueSubEventName(eventName) { |
25 return eventName + '/' + idGeneratorNatives.GetNextId(); | 24 return eventName + '/' + idGeneratorNatives.GetNextId(); |
26 } | 25 } |
27 | 26 |
28 // This is the only "webViewInternal.onClicked" named event for this renderer. | 27 // This is the only "webViewInternal.onClicked" named event for this renderer. |
29 // | 28 // |
30 // Since we need an event per <webview>, we define events with suffix | 29 // Since we need an event per <webview>, we define events with suffix |
31 // (subEventName) in each of the <webview>. Behind the scenes, this event is | 30 // (subEventName) in each of the <webview>. Behind the scenes, this event is |
32 // registered as a ContextMenusEvent, with filter set to the webview's | 31 // registered as a ContextMenusEvent, with filter set to the webview's |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 WebViewContextMenusImpl.prototype.update = function() { | 87 WebViewContextMenusImpl.prototype.update = function() { |
89 var args = $Array.concat([this.viewInstanceId_], $Array.slice(arguments)); | 88 var args = $Array.concat([this.viewInstanceId_], $Array.slice(arguments)); |
90 return $Function.apply(ChromeWebView.contextMenusUpdate, null, args); | 89 return $Function.apply(ChromeWebView.contextMenusUpdate, null, args); |
91 }; | 90 }; |
92 | 91 |
93 var WebViewContextMenus = utils.expose( | 92 var WebViewContextMenus = utils.expose( |
94 'WebViewContextMenus', WebViewContextMenusImpl, | 93 'WebViewContextMenus', WebViewContextMenusImpl, |
95 { functions: ['create', 'remove', 'removeAll', 'update'] }); | 94 { functions: ['create', 'remove', 'removeAll', 'update'] }); |
96 | 95 |
97 /** @private */ | 96 /** @private */ |
98 WebViewInternal.prototype.maybeHandleContextMenu = function(e, webViewEvent) { | 97 WebView.prototype.maybeHandleContextMenu = function(e, webViewEvent) { |
99 var requestId = e.requestId; | 98 var requestId = e.requestId; |
100 // Construct the event.menu object. | 99 // Construct the event.menu object. |
101 var actionTaken = false; | 100 var actionTaken = false; |
102 var validateCall = function() { | 101 var validateCall = function() { |
103 var ERROR_MSG_CONTEXT_MENU_ACTION_ALREADY_TAKEN = '<webview>: ' + | 102 var ERROR_MSG_CONTEXT_MENU_ACTION_ALREADY_TAKEN = '<webview>: ' + |
104 'An action has already been taken for this "contextmenu" event.'; | 103 'An action has already been taken for this "contextmenu" event.'; |
105 | 104 |
106 if (actionTaken) { | 105 if (actionTaken) { |
107 throw new Error(ERROR_MSG_CONTEXT_MENU_ACTION_ALREADY_TAKEN); | 106 throw new Error(ERROR_MSG_CONTEXT_MENU_ACTION_ALREADY_TAKEN); |
108 } | 107 } |
(...skipping 17 matching lines...) Expand all Loading... |
126 actionTaken = true; | 125 actionTaken = true; |
127 // The default action is equivalent to just showing the context menu as is. | 126 // The default action is equivalent to just showing the context menu as is. |
128 ChromeWebView.showContextMenu(this.guestInstanceId, requestId, undefined); | 127 ChromeWebView.showContextMenu(this.guestInstanceId, requestId, undefined); |
129 | 128 |
130 // TODO(lazyboy): Figure out a way to show warning message only when | 129 // TODO(lazyboy): Figure out a way to show warning message only when |
131 // listeners are registered for this event. | 130 // listeners are registered for this event. |
132 } // else we will ignore showing the context menu completely. | 131 } // else we will ignore showing the context menu completely. |
133 }; | 132 }; |
134 | 133 |
135 /** @private */ | 134 /** @private */ |
136 WebViewInternal.prototype.setupExperimentalContextMenus = function() { | 135 WebView.prototype.setupExperimentalContextMenus = function() { |
137 var createContextMenus = function() { | 136 var createContextMenus = function() { |
138 return function() { | 137 return function() { |
139 if (this.contextMenus_) { | 138 if (this.contextMenus_) { |
140 return this.contextMenus_; | 139 return this.contextMenus_; |
141 } | 140 } |
142 | 141 |
143 this.contextMenus_ = new WebViewContextMenus(this.viewInstanceId); | 142 this.contextMenus_ = new WebViewContextMenus(this.viewInstanceId); |
144 | 143 |
145 // Define 'onClicked' event property on |this.contextMenus_|. | 144 // Define 'onClicked' event property on |this.contextMenus_|. |
146 var getOnClickedEvent = function() { | 145 var getOnClickedEvent = function() { |
(...skipping 22 matching lines...) Expand all Loading... |
169 | 168 |
170 // Expose <webview>.contextMenus object. | 169 // Expose <webview>.contextMenus object. |
171 Object.defineProperty( | 170 Object.defineProperty( |
172 this.webviewNode, | 171 this.webviewNode, |
173 'contextMenus', | 172 'contextMenus', |
174 { | 173 { |
175 get: createContextMenus(), | 174 get: createContextMenus(), |
176 enumerable: true | 175 enumerable: true |
177 }); | 176 }); |
178 }; | 177 }; |
OLD | NEW |