1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
|
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// This module implements chrome-specific <webview> API.
var ChromeWebView = require('chromeWebViewInternal').ChromeWebView;
var CreateEvent = require('webViewEvents').CreateEvent;
var DeclarativeWebRequestSchema =
requireNative('schema_registry').GetSchema('declarativeWebRequest');
var EventBindings = require('event_bindings');
var IdGenerator = requireNative('id_generator');
var WebRequestEvent = require('webRequestInternal').WebRequestEvent;
var WebRequestSchema =
requireNative('schema_registry').GetSchema('webRequest');
var WebViewInternal = require('webView').WebViewInternal
var WebRequestMessageEvent = CreateEvent('webViewInternal.onMessage');
var CHROME_WEB_VIEW_EVENTS = {
'contextmenu': {
evt: CreateEvent('chromeWebViewInternal.contextmenu'),
cancelable: true,
customHandler: function(handler, event, webViewEvent) {
handler.webViewInternal.maybeHandleContextMenu(event, webViewEvent);
},
fields: ['items']
}
};
function DeclarativeWebRequestEvent(opt_eventName,
opt_argSchemas,
opt_eventOptions,
opt_webViewInstanceId) {
var subEventName = opt_eventName + '/' + IdGenerator.GetNextId();
EventBindings.Event.call(this, subEventName, opt_argSchemas, opt_eventOptions,
opt_webViewInstanceId);
// TODO(lazyboy): When do we dispose this listener?
WebRequestMessageEvent.addListener(function() {
// Re-dispatch to subEvent's listeners.
$Function.apply(this.dispatch, this, $Array.slice(arguments));
}.bind(this), {instanceId: opt_webViewInstanceId || 0});
}
DeclarativeWebRequestEvent.prototype = {
__proto__: EventBindings.Event.prototype
};
/**
* Implemented when the ChromeWebView API is available.
* @private
*/
WebViewInternal.prototype.maybeGetChromeWebViewEvents = function() {
return CHROME_WEB_VIEW_EVENTS;
};
/**
* Calls to show contextmenu right away instead of dispatching a 'contextmenu'
* event.
* This will be overridden in chrome_web_view_experimental.js to implement
* contextmenu API.
*/
WebViewInternal.prototype.maybeHandleContextMenu = function(e, webViewEvent) {
var requestId = e.requestId;
// Setting |params| = undefined will show the context menu unmodified, hence
// the 'contextmenu' API is disabled for stable channel.
var params = undefined;
ChromeWebView.showContextMenu(this.guestInstanceId, requestId, params);
};
WebViewInternal.prototype.maybeSetupChromeWebViewEvents = function() {
var request = {};
var createWebRequestEvent = function(webRequestEvent) {
return function() {
if (!this[webRequestEvent.name]) {
this[webRequestEvent.name] =
new WebRequestEvent(
'webViewInternal.' + webRequestEvent.name,
webRequestEvent.parameters,
webRequestEvent.extraParameters, webRequestEvent.options,
this.viewInstanceId);
}
return this[webRequestEvent.name];
}.bind(this);
}.bind(this);
var createDeclarativeWebRequestEvent = function(webRequestEvent) {
return function() {
if (!this[webRequestEvent.name]) {
// The onMessage event gets a special event type because we want
// the listener to fire only for messages targeted for this particular
// <webview>.
var EventClass = webRequestEvent.name === 'onMessage' ?
DeclarativeWebRequestEvent : EventBindings.Event;
this[webRequestEvent.name] =
new EventClass(
'webViewInternal.' + webRequestEvent.name,
webRequestEvent.parameters,
webRequestEvent.options,
this.viewInstanceId);
}
return this[webRequestEvent.name];
}.bind(this);
}.bind(this);
for (var i = 0; i < DeclarativeWebRequestSchema.events.length; ++i) {
var eventSchema = DeclarativeWebRequestSchema.events[i];
var webRequestEvent = createDeclarativeWebRequestEvent(eventSchema);
Object.defineProperty(
request,
eventSchema.name,
{
get: webRequestEvent,
enumerable: true
}
);
}
// Populate the WebRequest events from the API definition.
for (var i = 0; i < WebRequestSchema.events.length; ++i) {
var webRequestEvent = createWebRequestEvent(WebRequestSchema.events[i]);
Object.defineProperty(
request,
WebRequestSchema.events[i].name,
{
get: webRequestEvent,
enumerable: true
}
);
}
this.setRequestPropertyOnWebViewNode(request);
};
|