| 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; | 11 var ChromeWebView = require('chromeWebViewInternal').ChromeWebView; |
| 12 var ChromeWebViewSchema = | 12 var ChromeWebViewSchema = |
| 13 requireNative('schema_registry').GetSchema('chromeWebViewInternal'); | 13 requireNative('schema_registry').GetSchema('chromeWebViewInternal'); |
| 14 var ContextMenusSchema = | 14 var ContextMenusSchema = |
| 15 requireNative('schema_registry').GetSchema('contextMenus'); | 15 requireNative('schema_registry').GetSchema('contextMenus'); |
| 16 var CreateEvent = require('guestViewEvents').CreateEvent; | 16 var CreateEvent = require('guestViewEvents').CreateEvent; |
| 17 var EventBindings = require('event_bindings'); | 17 var EventBindings = require('event_bindings'); |
| 18 var idGeneratorNatives = requireNative('id_generator'); | 18 var idGeneratorNatives = requireNative('id_generator'); |
| 19 var MessagingNatives = requireNative('messaging_natives'); | 19 var MessagingNatives = requireNative('messaging_natives'); |
| 20 var utils = require('utils'); | 20 var utils = require('utils'); |
| 21 var WebViewEvents = require('webViewEvents').WebViewEvents; |
| 21 var WebViewImpl = require('webView').WebViewImpl; | 22 var WebViewImpl = require('webView').WebViewImpl; |
| 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 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 WebViewContextMenusImpl.prototype.update = function() { | 88 WebViewContextMenusImpl.prototype.update = function() { |
| 88 var args = $Array.concat([this.viewInstanceId_], $Array.slice(arguments)); | 89 var args = $Array.concat([this.viewInstanceId_], $Array.slice(arguments)); |
| 89 return $Function.apply(ChromeWebView.contextMenusUpdate, null, args); | 90 return $Function.apply(ChromeWebView.contextMenusUpdate, null, args); |
| 90 }; | 91 }; |
| 91 | 92 |
| 92 var WebViewContextMenus = utils.expose( | 93 var WebViewContextMenus = utils.expose( |
| 93 'WebViewContextMenus', WebViewContextMenusImpl, | 94 'WebViewContextMenus', WebViewContextMenusImpl, |
| 94 { functions: ['create', 'remove', 'removeAll', 'update'] }); | 95 { functions: ['create', 'remove', 'removeAll', 'update'] }); |
| 95 | 96 |
| 96 /** @private */ | 97 /** @private */ |
| 97 WebViewImpl.prototype.maybeHandleContextMenu = function(e, webViewEvent) { | 98 WebViewEvents.prototype.handleContextMenu = function(event, eventName) { |
| 98 var requestId = e.requestId; | 99 var webViewEvent = this.makeDomEvent(event, eventName); |
| 100 var requestId = event.requestId; |
| 99 // Construct the event.menu object. | 101 // Construct the event.menu object. |
| 100 var actionTaken = false; | 102 var actionTaken = false; |
| 101 var validateCall = function() { | 103 var validateCall = function() { |
| 102 var ERROR_MSG_CONTEXT_MENU_ACTION_ALREADY_TAKEN = '<webview>: ' + | 104 var ERROR_MSG_CONTEXT_MENU_ACTION_ALREADY_TAKEN = '<webview>: ' + |
| 103 'An action has already been taken for this "contextmenu" event.'; | 105 'An action has already been taken for this "contextmenu" event.'; |
| 104 | 106 |
| 105 if (actionTaken) { | 107 if (actionTaken) { |
| 106 throw new Error(ERROR_MSG_CONTEXT_MENU_ACTION_ALREADY_TAKEN); | 108 throw new Error(ERROR_MSG_CONTEXT_MENU_ACTION_ALREADY_TAKEN); |
| 107 } | 109 } |
| 108 actionTaken = true; | 110 actionTaken = true; |
| 109 }; | 111 }; |
| 110 var menu = { | 112 var menu = { |
| 111 show: function(items) { | 113 show: function(items) { |
| 112 validateCall(); | 114 validateCall(); |
| 113 // TODO(lazyboy): WebViewShowContextFunction doesn't do anything useful | 115 // TODO(lazyboy): WebViewShowContextFunction doesn't do anything useful |
| 114 // with |items|, implement. | 116 // with |items|, implement. |
| 115 ChromeWebView.showContextMenu(this.guest.getId(), requestId, items); | 117 ChromeWebView.showContextMenu(this.view.guest.getId(), requestId, items); |
| 116 }.bind(this) | 118 }.bind(this) |
| 117 }; | 119 }; |
| 118 webViewEvent.menu = menu; | 120 webViewEvent.menu = menu; |
| 119 var element = this.element; | 121 var element = this.view.element; |
| 120 var defaultPrevented = !element.dispatchEvent(webViewEvent); | 122 var defaultPrevented = !element.dispatchEvent(webViewEvent); |
| 121 if (actionTaken) { | 123 if (actionTaken) { |
| 122 return; | 124 return; |
| 123 } | 125 } |
| 124 if (!defaultPrevented) { | 126 if (!defaultPrevented) { |
| 125 actionTaken = true; | 127 actionTaken = true; |
| 126 // The default action is equivalent to just showing the context menu as is. | 128 // The default action is equivalent to just showing the context menu as is. |
| 127 ChromeWebView.showContextMenu(this.guest.getId(), requestId, undefined); | 129 ChromeWebView.showContextMenu( |
| 130 this.view.guest.getId(), requestId, undefined); |
| 128 | 131 |
| 129 // TODO(lazyboy): Figure out a way to show warning message only when | 132 // TODO(lazyboy): Figure out a way to show warning message only when |
| 130 // listeners are registered for this event. | 133 // listeners are registered for this event. |
| 131 } // else we will ignore showing the context menu completely. | 134 } // else we will ignore showing the context menu completely. |
| 132 }; | 135 }; |
| 133 | 136 |
| 134 /** @private */ | 137 /** @private */ |
| 135 WebViewImpl.prototype.setupExperimentalContextMenus = function() { | 138 WebViewImpl.prototype.setupExperimentalContextMenus = function() { |
| 136 var createContextMenus = function() { | 139 var createContextMenus = function() { |
| 137 return function() { | 140 return function() { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 168 | 171 |
| 169 // Expose <webview>.contextMenus object. | 172 // Expose <webview>.contextMenus object. |
| 170 Object.defineProperty( | 173 Object.defineProperty( |
| 171 this.element, | 174 this.element, |
| 172 'contextMenus', | 175 'contextMenus', |
| 173 { | 176 { |
| 174 get: createContextMenus(), | 177 get: createContextMenus(), |
| 175 enumerable: true | 178 enumerable: true |
| 176 }); | 179 }); |
| 177 }; | 180 }; |
| OLD | NEW |