OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // Shim that simulates a <webview> tag via Mutation Observers. | 5 // Shim that simulates a <webview> tag via Mutation Observers. |
6 // | 6 // |
7 // The actual tag is implemented via the browser plugin. The internals of this | 7 // The actual tag is implemented via the browser plugin. The internals of this |
8 // are hidden via Shadow DOM. | 8 // are hidden via Shadow DOM. |
9 | 9 |
10 'use strict'; | 10 'use strict'; |
11 | 11 |
12 var eventBindings = require('event_bindings'); | 12 var eventBindings = require('event_bindings'); |
13 var DocumentNatives = requireNative('document_natives'); | 13 var DocumentNatives = requireNative('document_natives'); |
14 var messagingNatives = requireNative('messaging_natives'); | 14 var messagingNatives = requireNative('messaging_natives'); |
15 var WebRequestEvent = require('webRequestInternal').WebRequestEvent; | 15 var WebRequestEvent = require('webRequestInternal').WebRequestEvent; |
16 var webRequestSchema = | 16 var webRequestSchema = |
17 requireNative('schema_registry').GetSchema('webRequest'); | 17 requireNative('schema_registry').GetSchema('webRequest'); |
18 var webView = require('binding').Binding.create('webview').generate(); | 18 var webView = require('binding').Binding.create('webview').generate(); |
19 | 19 |
20 // This secret enables hiding <webview> private members from the outside scope. | 20 // This secret enables hiding <webview> private members from the outside scope. |
21 // Outside of this file, |secret| is inaccessible. The only way to access the | 21 // Outside of this file, |secret| is inaccessible. The only way to access the |
22 // <webview> element's internal members is via the |secret|. Since it's only | 22 // <webview> element's internal members is via the |secret|. Since it's only |
23 // accessible by code here (and in web_view_experimental), only <webview>'s | 23 // accessible by code here (and in web_view_experimental), only <webview>'s |
24 // API can access it and not external developers. | 24 // API can access it and not external developers. |
25 var secret = {}; | 25 var secret = {}; |
26 | 26 |
27 var WEB_VIEW_ATTRIBUTE_MAXHEIGHT = 'maxheight'; | |
28 var WEB_VIEW_ATTRIBUTE_MAXWIDTH = 'maxwidth'; | |
29 var WEB_VIEW_ATTRIBUTE_MINHEIGHT = 'minheight'; | |
30 var WEB_VIEW_ATTRIBUTE_MINWIDTH = 'minwidth'; | |
31 | |
27 /** @type {Array.<string>} */ | 32 /** @type {Array.<string>} */ |
28 var WEB_VIEW_ATTRIBUTES = ['name', 'src', 'partition', 'autosize', 'minheight', | 33 var WEB_VIEW_ATTRIBUTES = [ |
29 'minwidth', 'maxheight', 'maxwidth']; | 34 'name', |
35 'src', | |
36 'partition', | |
37 'autosize', | |
38 WEB_VIEW_ATTRIBUTE_MINHEIGHT, | |
39 WEB_VIEW_ATTRIBUTE_MINWIDTH, | |
40 WEB_VIEW_ATTRIBUTE_MAXHEIGHT, | |
41 WEB_VIEW_ATTRIBUTE_MAXWIDTH | |
42 ]; | |
30 | 43 |
31 var webViewInstanceIdCounter = 0; | 44 var webViewInstanceIdCounter = 0; |
32 | 45 |
33 var createEvent = function(name) { | 46 var createEvent = function(name) { |
34 var eventOpts = {supportsListeners: true, supportsFilters: true}; | 47 var eventOpts = {supportsListeners: true, supportsFilters: true}; |
35 return new eventBindings.Event(name, undefined, eventOpts); | 48 return new eventBindings.Event(name, undefined, eventOpts); |
36 }; | 49 }; |
37 | 50 |
38 var WEB_VIEW_EXT_EVENTS = { | 51 var WEB_VIEW_EXT_EVENTS = { |
39 'close': { | 52 'close': { |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
107 'requestMethod', | 120 'requestMethod', |
108 'url', | 121 'url', |
109 'userGesture' | 122 'userGesture' |
110 ] | 123 ] |
111 }, | 124 }, |
112 'responsive': { | 125 'responsive': { |
113 evt: createEvent('webview.onResponsive'), | 126 evt: createEvent('webview.onResponsive'), |
114 fields: ['processId'] | 127 fields: ['processId'] |
115 }, | 128 }, |
116 'sizechanged': { | 129 'sizechanged': { |
130 customHandler: function(webview, event, webviewEvent) { | |
131 var node = webview.webviewNode_; | |
Fady Samuel
2013/08/28 19:14:38
Could you please move all this code to a helper me
| |
132 | |
133 // Check the current bounds to make sure we do not resize <webview> | |
134 // outside of current constraints. | |
135 var minWidth = 0; | |
136 if (node.hasAttribute(WEB_VIEW_ATTRIBUTE_MINWIDTH) && | |
137 node[WEB_VIEW_ATTRIBUTE_MINWIDTH]) { | |
138 minWidth = node[WEB_VIEW_ATTRIBUTE_MINWIDTH]; | |
139 } | |
140 var maxWidth; | |
141 if (node.hasAttribute(WEB_VIEW_ATTRIBUTE_MAXWIDTH) && | |
142 node[WEB_VIEW_ATTRIBUTE_MAXWIDTH]) { | |
143 maxWidth = node[WEB_VIEW_ATTRIBUTE_MAXWIDTH]; | |
144 } else { | |
145 maxWidth = node.offsetWidth; | |
146 } | |
147 if (minWidth > maxWidth) { | |
148 minWidth = maxWidth; | |
149 } | |
150 | |
151 var minHeight = 0; | |
152 if (node.hasAttribute(WEB_VIEW_ATTRIBUTE_MINHEIGHT) && | |
153 node[WEB_VIEW_ATTRIBUTE_MINHEIGHT]) { | |
154 minHeight = node[WEB_VIEW_ATTRIBUTE_MINHEIGHT]; | |
155 } | |
156 var maxHeight; | |
157 if (node.hasAttribute(WEB_VIEW_ATTRIBUTE_MAXHEIGHT) && | |
158 node[WEB_VIEW_ATTRIBUTE_MAXHEIGHT]) { | |
159 maxHeight = node[WEB_VIEW_ATTRIBUTE_MAXHEIGHT]; | |
160 } else { | |
161 maxHeight = node.offsetHeight; | |
162 } | |
163 if (minHeight > maxHeight) { | |
164 minHeight = maxHeight; | |
165 } | |
166 | |
167 if (webviewEvent.newWidth >= minWidth && | |
168 webviewEvent.newWidth <= maxWidth && | |
169 webviewEvent.newHeight >= minHeight && | |
170 webviewEvent.newHeight <= maxHeight) { | |
171 webview.webviewNode_.style.width = webviewEvent.newWidth + 'px'; | |
172 webview.webviewNode_.style.height = webviewEvent.newHeight + 'px'; | |
173 } | |
174 webview.webviewNode_.dispatchEvent(webviewEvent); | |
175 }, | |
117 evt: createEvent('webview.onSizeChanged'), | 176 evt: createEvent('webview.onSizeChanged'), |
118 fields: ['oldHeight', 'oldWidth', 'newHeight', 'newWidth'] | 177 fields: ['oldHeight', 'oldWidth', 'newHeight', 'newWidth'] |
119 }, | 178 }, |
120 'unresponsive': { | 179 'unresponsive': { |
121 evt: createEvent('webview.onUnresponsive'), | 180 evt: createEvent('webview.onUnresponsive'), |
122 fields: ['processId'] | 181 fields: ['processId'] |
123 } | 182 } |
124 }; | 183 }; |
125 | 184 |
126 // Implemented when the experimental API is available. | 185 // Implemented when the experimental API is available. |
(...skipping 677 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
804 | 863 |
805 /** | 864 /** |
806 * Implemented when the experimental API is available. | 865 * Implemented when the experimental API is available. |
807 * @private | 866 * @private |
808 */ | 867 */ |
809 WebViewInternal.prototype.maybeAttachWebRequestEventToWebview_ = function() {}; | 868 WebViewInternal.prototype.maybeAttachWebRequestEventToWebview_ = function() {}; |
810 | 869 |
811 exports.webView = webView; | 870 exports.webView = webView; |
812 exports.WebViewInternal = WebViewInternal; | 871 exports.WebViewInternal = WebViewInternal; |
813 exports.CreateEvent = createEvent; | 872 exports.CreateEvent = createEvent; |
OLD | NEW |