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 // This module implements Webview (<webview>) as a custom element that wraps a | 5 // This module implements Webview (<webview>) as a custom element that wraps a |
6 // BrowserPlugin object element. The object element is hidden within | 6 // BrowserPlugin object element. The object element is hidden within |
7 // the shadow DOM of the Webview element. | 7 // the shadow DOM of the Webview element. |
8 | 8 |
9 var DocumentNatives = requireNative('document_natives'); | 9 var DocumentNatives = requireNative('document_natives'); |
10 var EventBindings = require('event_bindings'); | 10 var EventBindings = require('event_bindings'); |
11 var GuestView = require('binding').Binding.create('guestview').generate(); | |
11 var IdGenerator = requireNative('id_generator'); | 12 var IdGenerator = requireNative('id_generator'); |
12 var MessagingNatives = requireNative('messaging_natives'); | 13 var MessagingNatives = requireNative('messaging_natives'); |
13 var WebRequestEvent = require('webRequestInternal').WebRequestEvent; | 14 var WebRequestEvent = require('webRequestInternal').WebRequestEvent; |
14 var WebRequestSchema = | 15 var WebRequestSchema = |
15 requireNative('schema_registry').GetSchema('webRequest'); | 16 requireNative('schema_registry').GetSchema('webRequest'); |
16 var DeclarativeWebRequestSchema = | 17 var DeclarativeWebRequestSchema = |
17 requireNative('schema_registry').GetSchema('declarativeWebRequest'); | 18 requireNative('schema_registry').GetSchema('declarativeWebRequest'); |
18 var WebView = require('webview').WebView; | 19 var WebView = require('webview').WebView; |
19 | 20 |
20 var WEB_VIEW_ATTRIBUTE_MAXHEIGHT = 'maxheight'; | 21 var WEB_VIEW_ATTRIBUTE_MAXHEIGHT = 'maxheight'; |
21 var WEB_VIEW_ATTRIBUTE_MAXWIDTH = 'maxwidth'; | 22 var WEB_VIEW_ATTRIBUTE_MAXWIDTH = 'maxwidth'; |
22 var WEB_VIEW_ATTRIBUTE_MINHEIGHT = 'minheight'; | 23 var WEB_VIEW_ATTRIBUTE_MINHEIGHT = 'minheight'; |
23 var WEB_VIEW_ATTRIBUTE_MINWIDTH = 'minwidth'; | 24 var WEB_VIEW_ATTRIBUTE_MINWIDTH = 'minwidth'; |
25 var WEB_VIEW_ATTRIBUTE_PARTITION = 'partition'; | |
26 | |
27 var ERROR_MSG_ALREADY_NAVIGATED = | |
28 'The object has already navigated, so its partition cannot be changed.'; | |
29 var ERROR_MSG_INVALID_PARTITION_ATTRIBUTE = 'Invalid partition attribute.'; | |
24 | 30 |
25 /** @type {Array.<string>} */ | 31 /** @type {Array.<string>} */ |
26 var WEB_VIEW_ATTRIBUTES = [ | 32 var WEB_VIEW_ATTRIBUTES = [ |
27 'allowtransparency', | 33 'allowtransparency', |
28 'autosize', | 34 'autosize', |
29 'partition', | |
30 WEB_VIEW_ATTRIBUTE_MINHEIGHT, | 35 WEB_VIEW_ATTRIBUTE_MINHEIGHT, |
31 WEB_VIEW_ATTRIBUTE_MINWIDTH, | 36 WEB_VIEW_ATTRIBUTE_MINWIDTH, |
32 WEB_VIEW_ATTRIBUTE_MAXHEIGHT, | 37 WEB_VIEW_ATTRIBUTE_MAXHEIGHT, |
33 WEB_VIEW_ATTRIBUTE_MAXWIDTH | 38 WEB_VIEW_ATTRIBUTE_MAXWIDTH |
34 ]; | 39 ]; |
35 | 40 |
41 /** @class representing state of storage partition. */ | |
42 function Partition() { | |
43 this.validPartitionId = true; | |
44 this.persist_storage_ = false; | |
45 this.storage_partition_id = ''; | |
46 }; | |
47 | |
48 Partition.prototype.toAttribute = function() { | |
49 if (!this.validPartitionId) { | |
50 return ''; | |
51 } | |
52 return (this.persist_storage_ ? 'persist:' : '') + this.storage_partition_id; | |
53 }; | |
54 | |
55 Partition.prototype.fromAttribute = function(value, hasNavigated) { | |
56 var result = {}; | |
57 if (hasNavigated) { | |
58 result.error = ERROR_MSG_ALREADY_NAVIGATED; | |
59 return result; | |
60 } | |
61 if (!value) { | |
62 value = ''; | |
63 } | |
64 | |
65 var LEN = 'persist:'.length; | |
66 if (value.substr(0, LEN) == 'persist:') { | |
67 value = value.substr(LEN); | |
68 if (!value) { | |
69 this.validPartitionId = false; | |
70 result.error = ERROR_MSG_INVALID_PARTITION_ATTRIBUTE; | |
71 return result; | |
72 } | |
73 this.persist_storage_ = true; | |
74 } else { | |
75 this.persist_storage_ = false; | |
76 } | |
77 | |
78 this.storage_partition_id = value; | |
79 return result; | |
80 }; | |
81 | |
36 var CreateEvent = function(name) { | 82 var CreateEvent = function(name) { |
37 var eventOpts = {supportsListeners: true, supportsFilters: true}; | 83 var eventOpts = {supportsListeners: true, supportsFilters: true}; |
38 return new EventBindings.Event(name, undefined, eventOpts); | 84 return new EventBindings.Event(name, undefined, eventOpts); |
39 }; | 85 }; |
40 | 86 |
41 // WEB_VIEW_EVENTS is a map of stable <webview> DOM event names to their | 87 // WEB_VIEW_EVENTS is a map of stable <webview> DOM event names to their |
42 // associated extension event descriptor objects. | 88 // associated extension event descriptor objects. |
43 // An event listener will be attached to the extension event |evt| specified in | 89 // An event listener will be attached to the extension event |evt| specified in |
44 // the descriptor. | 90 // the descriptor. |
45 // |fields| specifies the public-facing fields in the DOM event that are | 91 // |fields| specifies the public-facing fields in the DOM event that are |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
169 // Implemented when the experimental API is available. | 215 // Implemented when the experimental API is available. |
170 WebViewInternal.maybeRegisterExperimentalAPIs = function(proto) {} | 216 WebViewInternal.maybeRegisterExperimentalAPIs = function(proto) {} |
171 | 217 |
172 /** | 218 /** |
173 * @constructor | 219 * @constructor |
174 */ | 220 */ |
175 function WebViewInternal(webviewNode) { | 221 function WebViewInternal(webviewNode) { |
176 privates(webviewNode).internal = this; | 222 privates(webviewNode).internal = this; |
177 this.webviewNode = webviewNode; | 223 this.webviewNode = webviewNode; |
178 this.attached = false; | 224 this.attached = false; |
225 | |
226 this.beforeFirstNavigation = true; | |
227 this.validPartitionId = true; | |
228 | |
179 this.browserPluginNode = this.createBrowserPluginNode(); | 229 this.browserPluginNode = this.createBrowserPluginNode(); |
180 var shadowRoot = this.webviewNode.createShadowRoot(); | 230 var shadowRoot = this.webviewNode.createShadowRoot(); |
181 shadowRoot.appendChild(this.browserPluginNode); | 231 shadowRoot.appendChild(this.browserPluginNode); |
182 | 232 |
183 this.setupWebviewNodeAttributes(); | 233 this.setupWebviewNodeAttributes(); |
184 this.setupFocusPropagation(); | 234 this.setupFocusPropagation(); |
185 this.setupWebviewNodeProperties(); | 235 this.setupWebviewNodeProperties(); |
236 | |
237 this.viewInstanceId = IdGenerator.GetNextId(); | |
238 | |
239 //this.allocateInstanceId(); | |
Fady Samuel
2014/06/03 19:40:40
Remove?
lazyboy
2014/06/03 22:30:11
Done.
| |
240 this.partition = new Partition(); | |
241 this.parseAttributes(); | |
242 | |
186 this.setupWebviewNodeEvents(); | 243 this.setupWebviewNodeEvents(); |
187 } | 244 } |
188 | 245 |
189 /** | 246 /** |
190 * @private | 247 * @private |
191 */ | 248 */ |
192 WebViewInternal.prototype.createBrowserPluginNode = function() { | 249 WebViewInternal.prototype.createBrowserPluginNode = function() { |
193 // We create BrowserPlugin as a custom element in order to observe changes | 250 // We create BrowserPlugin as a custom element in order to observe changes |
194 // to attributes synchronously. | 251 // to attributes synchronously. |
195 var browserPluginNode = new WebViewInternal.BrowserPlugin(); | 252 var browserPluginNode = new WebViewInternal.BrowserPlugin(); |
196 privates(browserPluginNode).internal = this; | 253 privates(browserPluginNode).internal = this; |
197 | 254 |
198 var ALL_ATTRIBUTES = WEB_VIEW_ATTRIBUTES.concat(['src']); | 255 $Array.forEach(WEB_VIEW_ATTRIBUTES, function(attributeName) { |
199 $Array.forEach(ALL_ATTRIBUTES, function(attributeName) { | |
200 // Only copy attributes that have been assigned values, rather than copying | 256 // Only copy attributes that have been assigned values, rather than copying |
201 // a series of undefined attributes to BrowserPlugin. | 257 // a series of undefined attributes to BrowserPlugin. |
202 if (this.webviewNode.hasAttribute(attributeName)) { | 258 if (this.webviewNode.hasAttribute(attributeName)) { |
203 browserPluginNode.setAttribute( | 259 browserPluginNode.setAttribute( |
204 attributeName, this.webviewNode.getAttribute(attributeName)); | 260 attributeName, this.webviewNode.getAttribute(attributeName)); |
205 } else if (this.webviewNode[attributeName]){ | 261 } else if (this.webviewNode[attributeName]){ |
206 // Reading property using has/getAttribute does not work on | 262 // Reading property using has/getAttribute does not work on |
207 // document.DOMContentLoaded event (but works on | 263 // document.DOMContentLoaded event (but works on |
208 // window.DOMContentLoaded event). | 264 // window.DOMContentLoaded event). |
209 // So copy from property if copying from attribute fails. | 265 // So copy from property if copying from attribute fails. |
210 browserPluginNode.setAttribute( | 266 browserPluginNode.setAttribute( |
211 attributeName, this.webviewNode[attributeName]); | 267 attributeName, this.webviewNode[attributeName]); |
212 } | 268 } |
213 }, this); | 269 }, this); |
214 | 270 |
215 return browserPluginNode; | 271 return browserPluginNode; |
216 }; | 272 }; |
217 | 273 |
218 /** | 274 /** |
219 * @private | 275 * @private |
276 * Resets some state upon re-attaching <webview> element to the DOM. | |
277 */ | |
278 WebViewInternal.prototype.resetUponReAttachment = function() { | |
Fady Samuel
2014/06/03 19:40:40
Call it resetUponReattachment. Reattachment is one
lazyboy
2014/06/03 22:30:11
Done.
| |
279 this.instanceId = undefined; | |
280 this.beforeFirstNavigation = true; | |
281 this.validPartitionId = true; | |
282 this.partition.validPartitionId = true; | |
283 }; | |
284 | |
285 /** | |
286 * @private | |
220 */ | 287 */ |
221 WebViewInternal.prototype.setupFocusPropagation = function() { | 288 WebViewInternal.prototype.setupFocusPropagation = function() { |
222 if (!this.webviewNode.hasAttribute('tabIndex')) { | 289 if (!this.webviewNode.hasAttribute('tabIndex')) { |
223 // <webview> needs a tabIndex in order to be focusable. | 290 // <webview> needs a tabIndex in order to be focusable. |
224 // TODO(fsamuel): It would be nice to avoid exposing a tabIndex attribute | 291 // TODO(fsamuel): It would be nice to avoid exposing a tabIndex attribute |
225 // to allow <webview> to be focusable. | 292 // to allow <webview> to be focusable. |
226 // See http://crbug.com/231664. | 293 // See http://crbug.com/231664. |
227 this.webviewNode.setAttribute('tabIndex', -1); | 294 this.webviewNode.setAttribute('tabIndex', -1); |
228 } | 295 } |
229 var self = this; | 296 var self = this; |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
392 Object.defineProperty(this.webviewNode, 'name', { | 459 Object.defineProperty(this.webviewNode, 'name', { |
393 get: function() { | 460 get: function() { |
394 return self.name; | 461 return self.name; |
395 }, | 462 }, |
396 set: function(value) { | 463 set: function(value) { |
397 self.webviewNode.setAttribute('name', value); | 464 self.webviewNode.setAttribute('name', value); |
398 }, | 465 }, |
399 enumerable: true | 466 enumerable: true |
400 }); | 467 }); |
401 | 468 |
469 Object.defineProperty(this.webviewNode, 'partition', { | |
470 get: function() { | |
471 window.console.log('getter.partition'); | |
Fady Samuel
2014/06/03 19:40:40
Remove
lazyboy
2014/06/03 22:30:11
Wrong grep, fixed.
| |
472 var ret = self.partition.toAttribute(); | |
Fady Samuel
2014/06/03 19:40:40
Return this directly?
lazyboy
2014/06/03 22:30:11
Done.
| |
473 window.console.log('returning: ' + ret); | |
Fady Samuel
2014/06/03 19:40:40
Remove
lazyboy
2014/06/03 22:30:11
Done.
| |
474 return ret; | |
475 }, | |
476 set: function(value) { | |
477 window.console.log('setter.partition, value: ' + value); | |
Fady Samuel
2014/06/03 19:40:40
Remove.
lazyboy
2014/06/03 22:30:11
Done.
| |
478 var result = self.partition.fromAttribute(value, self.hasNavigated()); | |
479 if (result.error) { | |
480 throw result.error; | |
481 } | |
482 self.webviewNode.setAttribute('partition', value); | |
483 | |
484 // TODO(lazyboy): CanRemovePartitionAttribute() when removeAttribute(). | |
Fady Samuel
2014/06/03 19:40:40
Fix this?
lazyboy
2014/06/03 22:30:11
This should be taken care of.
I was thinking webvi
| |
485 }, | |
486 enumerable: true | |
487 }); | |
488 | |
402 // We cannot use {writable: true} property descriptor because we want a | 489 // We cannot use {writable: true} property descriptor because we want a |
403 // dynamic getter value. | 490 // dynamic getter value. |
404 Object.defineProperty(this.webviewNode, 'contentWindow', { | 491 Object.defineProperty(this.webviewNode, 'contentWindow', { |
405 get: function() { | 492 get: function() { |
406 if (browserPluginNode.contentWindow) | 493 if (browserPluginNode.contentWindow) |
407 return browserPluginNode.contentWindow; | 494 return browserPluginNode.contentWindow; |
408 window.console.error(ERROR_MSG_CONTENTWINDOW_NOT_AVAILABLE); | 495 window.console.error(ERROR_MSG_CONTENTWINDOW_NOT_AVAILABLE); |
409 }, | 496 }, |
410 // No setter. | 497 // No setter. |
411 enumerable: true | 498 enumerable: true |
(...skipping 10 matching lines...) Expand all Loading... | |
422 /** | 509 /** |
423 * @private | 510 * @private |
424 */ | 511 */ |
425 WebViewInternal.prototype.setupWebViewSrcAttributeMutationObserver = | 512 WebViewInternal.prototype.setupWebViewSrcAttributeMutationObserver = |
426 function() { | 513 function() { |
427 // The purpose of this mutation observer is to catch assignment to the src | 514 // The purpose of this mutation observer is to catch assignment to the src |
428 // attribute without any changes to its value. This is useful in the case | 515 // attribute without any changes to its value. This is useful in the case |
429 // where the webview guest has crashed and navigating to the same address | 516 // where the webview guest has crashed and navigating to the same address |
430 // spawns off a new process. | 517 // spawns off a new process. |
431 var self = this; | 518 var self = this; |
432 this.srcObserver = new MutationObserver(function(mutations) { | 519 this.srcAndPartitionObserver = new MutationObserver(function(mutations) { |
433 $Array.forEach(mutations, function(mutation) { | 520 $Array.forEach(mutations, function(mutation) { |
434 var oldValue = mutation.oldValue; | 521 var oldValue = mutation.oldValue; |
435 var newValue = self.webviewNode.getAttribute(mutation.attributeName); | 522 var newValue = self.webviewNode.getAttribute(mutation.attributeName); |
436 if (oldValue != newValue) { | 523 if (oldValue != newValue) { |
437 return; | 524 return; |
438 } | 525 } |
439 self.handleWebviewAttributeMutation( | 526 self.handleWebviewAttributeMutation( |
440 mutation.attributeName, oldValue, newValue); | 527 mutation.attributeName, oldValue, newValue); |
441 }); | 528 }); |
442 }); | 529 }); |
443 var params = { | 530 var params = { |
444 attributes: true, | 531 attributes: true, |
445 attributeOldValue: true, | 532 attributeOldValue: true, |
446 attributeFilter: ['src'] | 533 attributeFilter: ['src', 'partition'] |
447 }; | 534 }; |
448 this.srcObserver.observe(this.webviewNode, params); | 535 this.srcAndPartitionObserver.observe(this.webviewNode, params); |
449 }; | 536 }; |
450 | 537 |
451 /** | 538 /** |
452 * @private | 539 * @private |
453 */ | 540 */ |
454 WebViewInternal.prototype.handleWebviewAttributeMutation = | 541 WebViewInternal.prototype.handleWebviewAttributeMutation = |
455 function(name, oldValue, newValue) { | 542 function(name, oldValue, newValue) { |
543 window.console.log('handleWebviewAttributeMutation, name = ' + name); | |
456 // This observer monitors mutations to attributes of the <webview> and | 544 // This observer monitors mutations to attributes of the <webview> and |
457 // updates the BrowserPlugin properties accordingly. In turn, updating | 545 // updates the BrowserPlugin properties accordingly. In turn, updating |
458 // a BrowserPlugin property will update the corresponding BrowserPlugin | 546 // a BrowserPlugin property will update the corresponding BrowserPlugin |
459 // attribute, if necessary. See BrowserPlugin::UpdateDOMAttribute for more | 547 // attribute, if necessary. See BrowserPlugin::UpdateDOMAttribute for more |
460 // details. | 548 // details. |
461 if (name == 'name') { | 549 if (name == 'name') { |
462 // We treat null attribute (attribute removed) and the empty string as | 550 // We treat null attribute (attribute removed) and the empty string as |
463 // one case. | 551 // one case. |
464 oldValue = oldValue || ''; | 552 oldValue = oldValue || ''; |
465 newValue = newValue || ''; | 553 newValue = newValue || ''; |
(...skipping 19 matching lines...) Expand all Loading... | |
485 // src attribute changes normally initiate a navigation. We suppress | 573 // src attribute changes normally initiate a navigation. We suppress |
486 // the next src attribute handler call to avoid reloading the page | 574 // the next src attribute handler call to avoid reloading the page |
487 // on every guest-initiated navigation. | 575 // on every guest-initiated navigation. |
488 this.ignoreNextSrcAttributeChange = true; | 576 this.ignoreNextSrcAttributeChange = true; |
489 this.webviewNode.setAttribute('src', oldValue); | 577 this.webviewNode.setAttribute('src', oldValue); |
490 return; | 578 return; |
491 } | 579 } |
492 this.src = newValue; | 580 this.src = newValue; |
493 if (this.ignoreNextSrcAttributeChange) { | 581 if (this.ignoreNextSrcAttributeChange) { |
494 // Don't allow the src mutation observer to see this change. | 582 // Don't allow the src mutation observer to see this change. |
495 this.srcObserver.takeRecords(); | 583 this.srcAndPartitionObserver.takeRecords(); |
496 this.ignoreNextSrcAttributeChange = false; | 584 this.ignoreNextSrcAttributeChange = false; |
497 return; | 585 return; |
498 } | 586 } |
587 var result = {}; | |
588 this.parseSrcAttribute(result); | |
589 | |
590 if (result.error) { | |
591 throw result.error; | |
592 } | |
593 } else if (name == 'partition') { | |
594 // TODO(lazyboy): Do we do extra work here if we get here from | |
595 // Object.set.partition? | |
596 this.partition.fromAttribute(newValue, this.hasNavigated()); | |
499 } | 597 } |
598 | |
599 // No <webview> -> <object> mutation propagation for these attributes. | |
600 if (name == 'src' || name == 'partition') { | |
601 return; | |
602 } | |
603 | |
500 if (this.browserPluginNode.hasOwnProperty(name)) { | 604 if (this.browserPluginNode.hasOwnProperty(name)) { |
501 this.browserPluginNode[name] = newValue; | 605 this.browserPluginNode[name] = newValue; |
502 } else { | 606 } else { |
503 this.browserPluginNode.setAttribute(name, newValue); | 607 this.browserPluginNode.setAttribute(name, newValue); |
504 } | 608 } |
505 }; | 609 }; |
506 | 610 |
507 /** | 611 /** |
508 * @private | 612 * @private |
509 */ | 613 */ |
510 WebViewInternal.prototype.handleBrowserPluginAttributeMutation = | 614 WebViewInternal.prototype.handleBrowserPluginAttributeMutation = |
511 function(name, newValue) { | 615 function(name, newValue) { |
616 if (name == 'src') { | |
lazyboy
2014/06/03 22:30:11
FYI,
I'm removing this part as this won't help wit
| |
617 // name == 'src' here implies autoNavigate = true; | |
618 this.autoNavigate_ = true; | |
619 this.partition.fromAttribute('persist:custom_plugin', this.hasNavigated()); | |
620 } | |
621 | |
512 // This observer monitors mutations to attributes of the BrowserPlugin and | 622 // This observer monitors mutations to attributes of the BrowserPlugin and |
513 // updates the <webview> attributes accordingly. | 623 // updates the <webview> attributes accordingly. |
514 // |newValue| is null if the attribute |name| has been removed. | 624 // |newValue| is null if the attribute |name| has been removed. |
515 if (newValue != null) { | 625 if (newValue != null) { |
516 // Update the <webview> attribute to match the BrowserPlugin attribute. | 626 // Update the <webview> attribute to match the BrowserPlugin attribute. |
517 // Note: Calling setAttribute on <webview> will trigger its mutation | 627 // Note: Calling setAttribute on <webview> will trigger its mutation |
518 // observer which will then propagate that attribute to BrowserPlugin. In | 628 // observer which will then propagate that attribute to BrowserPlugin. In |
519 // cases where we permit assigning a BrowserPlugin attribute the same value | 629 // cases where we permit assigning a BrowserPlugin attribute the same value |
520 // again (such as navigation when crashed), this could end up in an infinite | 630 // again (such as navigation when crashed), this could end up in an infinite |
521 // loop. Thus, we avoid this loop by only updating the <webview> attribute | 631 // loop. Thus, we avoid this loop by only updating the <webview> attribute |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
590 if (webViewEvent.newWidth >= minWidth && | 700 if (webViewEvent.newWidth >= minWidth && |
591 webViewEvent.newWidth <= maxWidth && | 701 webViewEvent.newWidth <= maxWidth && |
592 webViewEvent.newHeight >= minHeight && | 702 webViewEvent.newHeight >= minHeight && |
593 webViewEvent.newHeight <= maxHeight) { | 703 webViewEvent.newHeight <= maxHeight) { |
594 node.style.width = webViewEvent.newWidth + 'px'; | 704 node.style.width = webViewEvent.newWidth + 'px'; |
595 node.style.height = webViewEvent.newHeight + 'px'; | 705 node.style.height = webViewEvent.newHeight + 'px'; |
596 } | 706 } |
597 node.dispatchEvent(webViewEvent); | 707 node.dispatchEvent(webViewEvent); |
598 }; | 708 }; |
599 | 709 |
710 WebViewInternal.prototype.hasNavigated = function() { | |
711 return !this.beforeFirstNavigation; | |
712 }; | |
713 | |
714 /** @return {boolean} */ | |
715 WebViewInternal.prototype.parseSrcAttribute = function(result) { | |
716 if (!this.partition.validPartitionId) { | |
717 result.error = ERROR_MSG_INVALID_PARTITION_ATTRIBUTE; | |
718 return false; | |
719 } | |
720 this.src = this.webviewNode.getAttribute('src'); | |
721 | |
722 if (!this.src) { | |
723 return true; | |
724 } | |
725 | |
726 if (!this.hasGuestInstanceID()) { | |
727 if (this.beforeFirstNavigation) { | |
728 this.beforeFirstNavigation = false; | |
729 this.allocateInstanceId(); | |
730 } | |
731 return true; | |
732 } | |
733 | |
734 // Navigate to this.src. | |
735 WebView.navigate(this.instanceId, this.src); | |
736 return true; | |
737 }; | |
738 | |
739 /** @return {boolean} */ | |
740 WebViewInternal.prototype.parseAttributes = function() { | |
741 var hasNavigated = this.hasNavigated(); | |
742 | |
Fady Samuel
2014/06/03 19:40:40
Unnecessary new line?
lazyboy
2014/06/03 22:30:11
Removed.
| |
743 var attributeValue = this.webviewNode.getAttribute('partition'); | |
744 var result = this.partition.fromAttribute(attributeValue, hasNavigated); | |
745 return this.parseSrcAttribute(result); | |
746 }; | |
747 | |
748 WebViewInternal.prototype.hasGuestInstanceID = function() { | |
749 return this.instanceId != undefined; | |
750 }; | |
751 | |
752 WebViewInternal.prototype.allocateInstanceId = function() { | |
753 // Parse .src and .partition. | |
754 var self = this; | |
755 GuestView.allocateInstanceId( | |
756 function(info) { | |
Fady Samuel
2014/06/03 19:40:40
Give it a more specific name? instanceId?
lazyboy
2014/06/03 22:30:11
Done.
| |
757 self.instanceId = info; | |
758 // TODO(lazyboy): Make sure this.autoNavigate_ stuff correctly updated | |
759 // |self.src| at this point. | |
760 self.attachWindowAndSetUpEvents(self.instanceId, self.src); | |
761 }); | |
762 }; | |
763 | |
600 /** | 764 /** |
601 * @private | 765 * @private |
602 */ | 766 */ |
603 WebViewInternal.prototype.setupWebviewNodeEvents = function() { | 767 WebViewInternal.prototype.setupWebviewNodeEvents = function() { |
604 var self = this; | |
605 this.viewInstanceId = IdGenerator.GetNextId(); | |
606 var onInstanceIdAllocated = function(e) { | |
607 var detail = e.detail ? JSON.parse(e.detail) : {}; | |
608 self.attachWindowAndSetUpEvents(detail.windowId); | |
609 }; | |
610 this.browserPluginNode.addEventListener('-internal-instanceid-allocated', | |
611 onInstanceIdAllocated); | |
612 this.setupWebRequestEvents(); | 768 this.setupWebRequestEvents(); |
613 this.setupExperimentalContextMenus_(); | 769 this.setupExperimentalContextMenus_(); |
614 | 770 |
615 this.on = {}; | 771 this.on = {}; |
616 var events = self.getEvents(); | 772 var events = this.getEvents(); |
617 for (var eventName in events) { | 773 for (var eventName in events) { |
618 this.setupEventProperty(eventName); | 774 this.setupEventProperty(eventName); |
619 } | 775 } |
620 }; | 776 }; |
621 | 777 |
622 /** | 778 /** |
623 * @private | 779 * @private |
624 */ | 780 */ |
625 WebViewInternal.prototype.setupNameAttribute = function() { | 781 WebViewInternal.prototype.setupNameAttribute = function() { |
626 var self = this; | 782 var self = this; |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
838 validateCall(); | 994 validateCall(); |
839 if (!webview || !webview.tagName || webview.tagName != 'WEBVIEW') | 995 if (!webview || !webview.tagName || webview.tagName != 'WEBVIEW') |
840 throw new Error(ERROR_MSG_WEBVIEW_EXPECTED); | 996 throw new Error(ERROR_MSG_WEBVIEW_EXPECTED); |
841 // Attach happens asynchronously to give the tagWatcher an opportunity | 997 // Attach happens asynchronously to give the tagWatcher an opportunity |
842 // to pick up the new webview before attach operates on it, if it hasn't | 998 // to pick up the new webview before attach operates on it, if it hasn't |
843 // been attached to the DOM already. | 999 // been attached to the DOM already. |
844 // Note: Any subsequent errors cannot be exceptions because they happen | 1000 // Note: Any subsequent errors cannot be exceptions because they happen |
845 // asynchronously. | 1001 // asynchronously. |
846 setTimeout(function() { | 1002 setTimeout(function() { |
847 var webViewInternal = privates(webview).internal; | 1003 var webViewInternal = privates(webview).internal; |
1004 if (event.storagePartitionId) { | |
1005 webViewInternal.webviewNode.setAttribute('partition', | |
1006 event.storagePartitionId); | |
1007 var partition = new Partition(); | |
1008 partition.fromAttribute(event.storagePartitionId, | |
1009 webViewInternal.hasNavigated()); | |
1010 webViewInternal.partition = partition; | |
1011 } | |
1012 | |
848 var attached = | 1013 var attached = |
849 webViewInternal.attachWindowAndSetUpEvents(event.windowId); | 1014 webViewInternal.attachWindowAndSetUpEvents( |
1015 event.windowId, undefined, event.storagePartitionId); | |
850 | 1016 |
851 if (!attached) { | 1017 if (!attached) { |
852 window.console.error(ERROR_MSG_NEWWINDOW_UNABLE_TO_ATTACH); | 1018 window.console.error(ERROR_MSG_NEWWINDOW_UNABLE_TO_ATTACH); |
853 } | 1019 } |
854 // If the object being passed into attach is not a valid <webview> | 1020 // If the object being passed into attach is not a valid <webview> |
855 // then we will fail and it will be treated as if the new window | 1021 // then we will fail and it will be treated as if the new window |
856 // was rejected. The permission API plumbing is used here to clean | 1022 // was rejected. The permission API plumbing is used here to clean |
857 // up the state created for the new window if attaching fails. | 1023 // up the state created for the new window if attaching fails. |
858 WebView.setPermission( | 1024 WebView.setPermission( |
859 self.instanceId, requestId, attached ? 'allow' : 'deny'); | 1025 self.instanceId, requestId, attached ? 'allow' : 'deny'); |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1093 this.userAgentOverride = userAgentOverride; | 1259 this.userAgentOverride = userAgentOverride; |
1094 if (!this.instanceId) { | 1260 if (!this.instanceId) { |
1095 // If we are not attached yet, then we will pick up the user agent on | 1261 // If we are not attached yet, then we will pick up the user agent on |
1096 // attachment. | 1262 // attachment. |
1097 return; | 1263 return; |
1098 } | 1264 } |
1099 WebView.overrideUserAgent(this.instanceId, userAgentOverride); | 1265 WebView.overrideUserAgent(this.instanceId, userAgentOverride); |
1100 }; | 1266 }; |
1101 | 1267 |
1102 /** @private */ | 1268 /** @private */ |
1103 WebViewInternal.prototype.attachWindowAndSetUpEvents = function(instanceId) { | 1269 WebViewInternal.prototype.attachWindowAndSetUpEvents = function( |
1270 instanceId, opt_src, opt_partitionId) { | |
1104 this.instanceId = instanceId; | 1271 this.instanceId = instanceId; |
1272 // If we have a partition from the opener, use that instead. | |
1273 var storagePartitionId = | |
1274 opt_partitionId || | |
1275 this.webviewNode.getAttribute(WEB_VIEW_ATTRIBUTE_PARTITION) || | |
1276 this.webviewNode[WEB_VIEW_ATTRIBUTE_PARTITION]; | |
1105 var params = { | 1277 var params = { |
1106 'api': 'webview', | 1278 'api': 'webview', |
1107 'instanceId': this.viewInstanceId, | 1279 'instanceId': this.viewInstanceId, |
1108 'name': this.name | 1280 'name': this.name, |
1281 'src': opt_src, | |
1282 'storagePartitionId': storagePartitionId, | |
1283 'userAgentOverride': this.userAgentOverride | |
1109 }; | 1284 }; |
1110 if (this.userAgentOverride) { | |
1111 params['userAgentOverride'] = this.userAgentOverride; | |
1112 } | |
1113 this.setupNameAttribute(); | 1285 this.setupNameAttribute(); |
1114 var events = this.getEvents(); | 1286 var events = this.getEvents(); |
1115 for (var eventName in events) { | 1287 for (var eventName in events) { |
1116 this.setupEvent(eventName, events[eventName]); | 1288 this.setupEvent(eventName, events[eventName]); |
1117 } | 1289 } |
1118 | 1290 |
1119 return this.browserPluginNode['-internal-attach'](this.instanceId, params); | 1291 return this.browserPluginNode['-internal-attach'](this.instanceId, params); |
1120 }; | 1292 }; |
1121 | 1293 |
1122 // Registers browser plugin <object> custom element. | 1294 // Registers browser plugin <object> custom element. |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1154 } | 1326 } |
1155 | 1327 |
1156 // Registers <webview> custom element. | 1328 // Registers <webview> custom element. |
1157 function registerWebViewElement() { | 1329 function registerWebViewElement() { |
1158 var proto = Object.create(HTMLElement.prototype); | 1330 var proto = Object.create(HTMLElement.prototype); |
1159 | 1331 |
1160 proto.createdCallback = function() { | 1332 proto.createdCallback = function() { |
1161 new WebViewInternal(this); | 1333 new WebViewInternal(this); |
1162 }; | 1334 }; |
1163 | 1335 |
1336 proto.customElementDetached = false; | |
1337 | |
1164 proto.attributeChangedCallback = function(name, oldValue, newValue) { | 1338 proto.attributeChangedCallback = function(name, oldValue, newValue) { |
1165 var internal = privates(this).internal; | 1339 var internal = privates(this).internal; |
1166 if (!internal) { | 1340 if (!internal) { |
1167 return; | 1341 return; |
1168 } | 1342 } |
1169 internal.handleWebviewAttributeMutation(name, oldValue, newValue); | 1343 internal.handleWebviewAttributeMutation(name, oldValue, newValue); |
1170 }; | 1344 }; |
1171 | 1345 |
1346 proto.detachedCallback = function() { | |
1347 this.customElementDetached = true; | |
1348 }; | |
1349 | |
1350 proto.attachedCallback = function() { | |
1351 if (this.customElementDetached) { | |
1352 var otherThis = privates(this).internal; | |
Fady Samuel
2014/06/03 19:40:40
otherThis is a confusing name. This is grabbing th
lazyboy
2014/06/03 22:30:11
Done.
| |
1353 otherThis.resetUponReAttachment(); | |
1354 otherThis.allocateInstanceId(); | |
1355 } | |
1356 this.customElementDetached = false; | |
Fady Samuel
2014/06/03 19:40:40
Can't we move this to resetUponReattachment?
lazyboy
2014/06/03 22:30:11
Doesn't seem like, resetUponReattachment is under
| |
1357 }; | |
1358 | |
1172 proto.back = function() { | 1359 proto.back = function() { |
1173 this.go(-1); | 1360 this.go(-1); |
1174 }; | 1361 }; |
1175 | 1362 |
1176 proto.forward = function() { | 1363 proto.forward = function() { |
1177 this.go(1); | 1364 this.go(1); |
1178 }; | 1365 }; |
1179 | 1366 |
1180 proto.canGoBack = function() { | 1367 proto.canGoBack = function() { |
1181 return privates(this).internal.canGoBack(); | 1368 return privates(this).internal.canGoBack(); |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1285 | 1472 |
1286 /** | 1473 /** |
1287 * Implemented when the experimental API is available. | 1474 * Implemented when the experimental API is available. |
1288 * @private | 1475 * @private |
1289 */ | 1476 */ |
1290 WebViewInternal.prototype.setupExperimentalContextMenus_ = function() {}; | 1477 WebViewInternal.prototype.setupExperimentalContextMenus_ = function() {}; |
1291 | 1478 |
1292 exports.WebView = WebView; | 1479 exports.WebView = WebView; |
1293 exports.WebViewInternal = WebViewInternal; | 1480 exports.WebViewInternal = WebViewInternal; |
1294 exports.CreateEvent = CreateEvent; | 1481 exports.CreateEvent = CreateEvent; |
OLD | NEW |