| 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 GuestViewInternal = | 10 var GuestViewInternal = |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 var WEB_VIEW_ATTRIBUTE_MINHEIGHT = 'minheight'; | 22 var WEB_VIEW_ATTRIBUTE_MINHEIGHT = 'minheight'; |
| 23 var WEB_VIEW_ATTRIBUTE_MINWIDTH = 'minwidth'; | 23 var WEB_VIEW_ATTRIBUTE_MINWIDTH = 'minwidth'; |
| 24 var AUTO_SIZE_ATTRIBUTES = [ | 24 var AUTO_SIZE_ATTRIBUTES = [ |
| 25 WEB_VIEW_ATTRIBUTE_AUTOSIZE, | 25 WEB_VIEW_ATTRIBUTE_AUTOSIZE, |
| 26 WEB_VIEW_ATTRIBUTE_MAXHEIGHT, | 26 WEB_VIEW_ATTRIBUTE_MAXHEIGHT, |
| 27 WEB_VIEW_ATTRIBUTE_MAXWIDTH, | 27 WEB_VIEW_ATTRIBUTE_MAXWIDTH, |
| 28 WEB_VIEW_ATTRIBUTE_MINHEIGHT, | 28 WEB_VIEW_ATTRIBUTE_MINHEIGHT, |
| 29 WEB_VIEW_ATTRIBUTE_MINWIDTH | 29 WEB_VIEW_ATTRIBUTE_MINWIDTH |
| 30 ]; | 30 ]; |
| 31 | 31 |
| 32 var WEB_VIEW_ATTRIBUTE_ALLOWTRANSPARENCY = "allowtransparency"; |
| 32 var WEB_VIEW_ATTRIBUTE_PARTITION = 'partition'; | 33 var WEB_VIEW_ATTRIBUTE_PARTITION = 'partition'; |
| 33 | 34 |
| 34 var ERROR_MSG_ALREADY_NAVIGATED = | 35 var ERROR_MSG_ALREADY_NAVIGATED = |
| 35 'The object has already navigated, so its partition cannot be changed.'; | 36 'The object has already navigated, so its partition cannot be changed.'; |
| 36 var ERROR_MSG_INVALID_PARTITION_ATTRIBUTE = 'Invalid partition attribute.'; | 37 var ERROR_MSG_INVALID_PARTITION_ATTRIBUTE = 'Invalid partition attribute.'; |
| 37 | 38 |
| 38 /** @type {Array.<string>} */ | |
| 39 var WEB_VIEW_ATTRIBUTES = [ | |
| 40 'allowtransparency', | |
| 41 ]; | |
| 42 | |
| 43 /** @class representing state of storage partition. */ | 39 /** @class representing state of storage partition. */ |
| 44 function Partition() { | 40 function Partition() { |
| 45 this.validPartitionId = true; | 41 this.validPartitionId = true; |
| 46 this.persistStorage = false; | 42 this.persistStorage = false; |
| 47 this.storagePartitionId = ''; | 43 this.storagePartitionId = ''; |
| 48 }; | 44 }; |
| 49 | 45 |
| 50 Partition.prototype.toAttribute = function() { | 46 Partition.prototype.toAttribute = function() { |
| 51 if (!this.validPartitionId) { | 47 if (!this.validPartitionId) { |
| 52 return ''; | 48 return ''; |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 } | 117 } |
| 122 | 118 |
| 123 /** | 119 /** |
| 124 * @private | 120 * @private |
| 125 */ | 121 */ |
| 126 WebViewInternal.prototype.createBrowserPluginNode = function() { | 122 WebViewInternal.prototype.createBrowserPluginNode = function() { |
| 127 // We create BrowserPlugin as a custom element in order to observe changes | 123 // We create BrowserPlugin as a custom element in order to observe changes |
| 128 // to attributes synchronously. | 124 // to attributes synchronously. |
| 129 var browserPluginNode = new WebViewInternal.BrowserPlugin(); | 125 var browserPluginNode = new WebViewInternal.BrowserPlugin(); |
| 130 privates(browserPluginNode).internal = this; | 126 privates(browserPluginNode).internal = this; |
| 131 | |
| 132 $Array.forEach(WEB_VIEW_ATTRIBUTES, function(attributeName) { | |
| 133 // Only copy attributes that have been assigned values, rather than copying | |
| 134 // a series of undefined attributes to BrowserPlugin. | |
| 135 if (this.webviewNode.hasAttribute(attributeName)) { | |
| 136 browserPluginNode.setAttribute( | |
| 137 attributeName, this.webviewNode.getAttribute(attributeName)); | |
| 138 } else if (this.webviewNode[attributeName]){ | |
| 139 // Reading property using has/getAttribute does not work on | |
| 140 // document.DOMContentLoaded event (but works on | |
| 141 // window.DOMContentLoaded event). | |
| 142 // So copy from property if copying from attribute fails. | |
| 143 browserPluginNode.setAttribute( | |
| 144 attributeName, this.webviewNode[attributeName]); | |
| 145 } | |
| 146 }, this); | |
| 147 | |
| 148 return browserPluginNode; | 127 return browserPluginNode; |
| 149 }; | 128 }; |
| 150 | 129 |
| 151 WebViewInternal.prototype.getGuestInstanceId = function() { | 130 WebViewInternal.prototype.getGuestInstanceId = function() { |
| 152 return this.guestInstanceId; | 131 return this.guestInstanceId; |
| 153 }; | 132 }; |
| 154 | 133 |
| 155 /** | 134 /** |
| 156 * Resets some state upon reattaching <webview> element to the DOM. | 135 * Resets some state upon reattaching <webview> element to the DOM. |
| 157 */ | 136 */ |
| (...skipping 30 matching lines...) Expand all Loading... |
| 188 if (!this.webviewNode.hasAttribute('tabIndex')) { | 167 if (!this.webviewNode.hasAttribute('tabIndex')) { |
| 189 // <webview> needs a tabIndex in order to be focusable. | 168 // <webview> needs a tabIndex in order to be focusable. |
| 190 // TODO(fsamuel): It would be nice to avoid exposing a tabIndex attribute | 169 // TODO(fsamuel): It would be nice to avoid exposing a tabIndex attribute |
| 191 // to allow <webview> to be focusable. | 170 // to allow <webview> to be focusable. |
| 192 // See http://crbug.com/231664. | 171 // See http://crbug.com/231664. |
| 193 this.webviewNode.setAttribute('tabIndex', -1); | 172 this.webviewNode.setAttribute('tabIndex', -1); |
| 194 } | 173 } |
| 195 var self = this; | 174 var self = this; |
| 196 this.webviewNode.addEventListener('focus', function(e) { | 175 this.webviewNode.addEventListener('focus', function(e) { |
| 197 // Focus the BrowserPlugin when the <webview> takes focus. | 176 // Focus the BrowserPlugin when the <webview> takes focus. |
| 198 self.browserPluginNode.focus(); | 177 this.browserPluginNode.focus(); |
| 199 }); | 178 }.bind(this)); |
| 200 this.webviewNode.addEventListener('blur', function(e) { | 179 this.webviewNode.addEventListener('blur', function(e) { |
| 201 // Blur the BrowserPlugin when the <webview> loses focus. | 180 // Blur the BrowserPlugin when the <webview> loses focus. |
| 202 self.browserPluginNode.blur(); | 181 this.browserPluginNode.blur(); |
| 203 }); | 182 }.bind(this)); |
| 204 }; | 183 }; |
| 205 | 184 |
| 206 /** | 185 /** |
| 207 * @private | 186 * @private |
| 208 */ | 187 */ |
| 209 WebViewInternal.prototype.back = function() { | 188 WebViewInternal.prototype.back = function() { |
| 210 return this.go(-1); | 189 return this.go(-1); |
| 211 }; | 190 }; |
| 212 | 191 |
| 213 /** | 192 /** |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 * @private | 301 * @private |
| 323 */ | 302 */ |
| 324 WebViewInternal.prototype.insertCSS = function(var_args) { | 303 WebViewInternal.prototype.insertCSS = function(var_args) { |
| 325 this.validateExecuteCodeCall(); | 304 this.validateExecuteCodeCall(); |
| 326 var args = $Array.concat([this.guestInstanceId, this.src], | 305 var args = $Array.concat([this.guestInstanceId, this.src], |
| 327 $Array.slice(arguments)); | 306 $Array.slice(arguments)); |
| 328 $Function.apply(WebView.insertCSS, null, args); | 307 $Function.apply(WebView.insertCSS, null, args); |
| 329 }; | 308 }; |
| 330 | 309 |
| 331 WebViewInternal.prototype.setupAutoSizeProperties = function() { | 310 WebViewInternal.prototype.setupAutoSizeProperties = function() { |
| 332 var self = this; | |
| 333 $Array.forEach(AUTO_SIZE_ATTRIBUTES, function(attributeName) { | 311 $Array.forEach(AUTO_SIZE_ATTRIBUTES, function(attributeName) { |
| 334 this[attributeName] = this.webviewNode.getAttribute(attributeName); | 312 this[attributeName] = this.webviewNode.getAttribute(attributeName); |
| 335 Object.defineProperty(this.webviewNode, attributeName, { | 313 Object.defineProperty(this.webviewNode, attributeName, { |
| 336 get: function() { | 314 get: function() { |
| 337 return self[attributeName]; | 315 return this[attributeName]; |
| 338 }, | 316 }.bind(this), |
| 339 set: function(value) { | 317 set: function(value) { |
| 340 self.webviewNode.setAttribute(attributeName, value); | 318 this.webviewNode.setAttribute(attributeName, value); |
| 341 }, | 319 }.bind(this), |
| 342 enumerable: true | 320 enumerable: true |
| 343 }); | 321 }); |
| 344 }, this); | 322 }.bind(this), this); |
| 345 }; | 323 }; |
| 346 | 324 |
| 347 /** | 325 /** |
| 348 * @private | 326 * @private |
| 349 */ | 327 */ |
| 350 WebViewInternal.prototype.setupWebviewNodeProperties = function() { | 328 WebViewInternal.prototype.setupWebviewNodeProperties = function() { |
| 351 var ERROR_MSG_CONTENTWINDOW_NOT_AVAILABLE = '<webview>: ' + | 329 var ERROR_MSG_CONTENTWINDOW_NOT_AVAILABLE = '<webview>: ' + |
| 352 'contentWindow is not available at this time. It will become available ' + | 330 'contentWindow is not available at this time. It will become available ' + |
| 353 'when the page has finished loading.'; | 331 'when the page has finished loading.'; |
| 354 | 332 |
| 355 this.setupAutoSizeProperties(); | 333 this.setupAutoSizeProperties(); |
| 356 var self = this; | |
| 357 var browserPluginNode = this.browserPluginNode; | |
| 358 // Expose getters and setters for the attributes. | |
| 359 $Array.forEach(WEB_VIEW_ATTRIBUTES, function(attributeName) { | |
| 360 Object.defineProperty(this.webviewNode, attributeName, { | |
| 361 get: function() { | |
| 362 if (browserPluginNode.hasOwnProperty(attributeName)) { | |
| 363 return browserPluginNode[attributeName]; | |
| 364 } else { | |
| 365 return browserPluginNode.getAttribute(attributeName); | |
| 366 } | |
| 367 }, | |
| 368 set: function(value) { | |
| 369 if (browserPluginNode.hasOwnProperty(attributeName)) { | |
| 370 // Give the BrowserPlugin first stab at the attribute so that it can | |
| 371 // throw an exception if there is a problem. This attribute will then | |
| 372 // be propagated back to the <webview>. | |
| 373 browserPluginNode[attributeName] = value; | |
| 374 } else { | |
| 375 browserPluginNode.setAttribute(attributeName, value); | |
| 376 } | |
| 377 }, | |
| 378 enumerable: true | |
| 379 }); | |
| 380 }, this); | |
| 381 | 334 |
| 382 // <webview> src does not quite behave the same as BrowserPlugin src, and so | 335 Object.defineProperty(this.webviewNode, |
| 383 // we don't simply keep the two in sync. | 336 WEB_VIEW_ATTRIBUTE_ALLOWTRANSPARENCY, { |
| 384 this.src = this.webviewNode.getAttribute('src'); | |
| 385 Object.defineProperty(this.webviewNode, 'src', { | |
| 386 get: function() { | 337 get: function() { |
| 387 return self.src; | 338 return this.allowtransparency; |
| 388 }, | 339 }.bind(this), |
| 389 set: function(value) { | 340 set: function(value) { |
| 390 self.webviewNode.setAttribute('src', value); | 341 this.webviewNode.setAttribute(WEB_VIEW_ATTRIBUTE_ALLOWTRANSPARENCY, |
| 391 }, | 342 value); |
| 392 // No setter. | 343 }.bind(this), |
| 393 enumerable: true | |
| 394 }); | |
| 395 | |
| 396 Object.defineProperty(this.webviewNode, 'name', { | |
| 397 get: function() { | |
| 398 return self.name; | |
| 399 }, | |
| 400 set: function(value) { | |
| 401 self.webviewNode.setAttribute('name', value); | |
| 402 }, | |
| 403 enumerable: true | |
| 404 }); | |
| 405 | |
| 406 Object.defineProperty(this.webviewNode, 'partition', { | |
| 407 get: function() { | |
| 408 return self.partition.toAttribute(); | |
| 409 }, | |
| 410 set: function(value) { | |
| 411 var result = self.partition.fromAttribute(value, self.hasNavigated()); | |
| 412 if (result.error) { | |
| 413 throw result.error; | |
| 414 } | |
| 415 self.webviewNode.setAttribute('partition', value); | |
| 416 }, | |
| 417 enumerable: true | 344 enumerable: true |
| 418 }); | 345 }); |
| 419 | 346 |
| 420 // We cannot use {writable: true} property descriptor because we want a | 347 // We cannot use {writable: true} property descriptor because we want a |
| 421 // dynamic getter value. | 348 // dynamic getter value. |
| 422 Object.defineProperty(this.webviewNode, 'contentWindow', { | 349 Object.defineProperty(this.webviewNode, 'contentWindow', { |
| 423 get: function() { | 350 get: function() { |
| 424 if (this.contentWindow) { | 351 if (this.contentWindow) { |
| 425 return this.contentWindow; | 352 return this.contentWindow; |
| 426 } | 353 } |
| 427 window.console.error(ERROR_MSG_CONTENTWINDOW_NOT_AVAILABLE); | 354 window.console.error(ERROR_MSG_CONTENTWINDOW_NOT_AVAILABLE); |
| 428 }.bind(this), | 355 }.bind(this), |
| 429 // No setter. | 356 // No setter. |
| 430 enumerable: true | 357 enumerable: true |
| 358 }); |
| 359 |
| 360 Object.defineProperty(this.webviewNode, 'name', { |
| 361 get: function() { |
| 362 return this.name; |
| 363 }.bind(this), |
| 364 set: function(value) { |
| 365 this.webviewNode.setAttribute('name', value); |
| 366 }.bind(this), |
| 367 enumerable: true |
| 368 }); |
| 369 |
| 370 Object.defineProperty(this.webviewNode, 'partition', { |
| 371 get: function() { |
| 372 return this.partition.toAttribute(); |
| 373 }.bind(this), |
| 374 set: function(value) { |
| 375 var result = this.partition.fromAttribute(value, this.hasNavigated()); |
| 376 if (result.error) { |
| 377 throw result.error; |
| 378 } |
| 379 this.webviewNode.setAttribute('partition', value); |
| 380 }.bind(this), |
| 381 enumerable: true |
| 382 }); |
| 383 |
| 384 this.src = this.webviewNode.getAttribute('src'); |
| 385 Object.defineProperty(this.webviewNode, 'src', { |
| 386 get: function() { |
| 387 return this.src; |
| 388 }.bind(this), |
| 389 set: function(value) { |
| 390 this.webviewNode.setAttribute('src', value); |
| 391 }.bind(this), |
| 392 // No setter. |
| 393 enumerable: true |
| 431 }); | 394 }); |
| 432 }; | 395 }; |
| 433 | 396 |
| 434 /** | 397 /** |
| 435 * @private | 398 * @private |
| 436 */ | 399 */ |
| 437 WebViewInternal.prototype.setupWebviewNodeAttributes = function() { | 400 WebViewInternal.prototype.setupWebviewNodeAttributes = function() { |
| 438 this.setupWebViewSrcAttributeMutationObserver(); | 401 this.setupWebViewSrcAttributeMutationObserver(); |
| 439 }; | 402 }; |
| 440 | 403 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 488 'min': { | 451 'min': { |
| 489 'width': parseInt(this.minwidth || 0), | 452 'width': parseInt(this.minwidth || 0), |
| 490 'height': parseInt(this.minheight || 0) | 453 'height': parseInt(this.minheight || 0) |
| 491 }, | 454 }, |
| 492 'max': { | 455 'max': { |
| 493 'width': parseInt(this.maxwidth || 0), | 456 'width': parseInt(this.maxwidth || 0), |
| 494 'height': parseInt(this.maxheight || 0) | 457 'height': parseInt(this.maxheight || 0) |
| 495 } | 458 } |
| 496 }); | 459 }); |
| 497 return; | 460 return; |
| 461 } else if (name == WEB_VIEW_ATTRIBUTE_ALLOWTRANSPARENCY) { |
| 462 // We treat null attribute (attribute removed) and the empty string as |
| 463 // one case. |
| 464 oldValue = oldValue || ''; |
| 465 newValue = newValue || ''; |
| 466 |
| 467 if (oldValue === newValue) { |
| 468 return; |
| 469 } |
| 470 this.allowtransparency = newValue != ''; |
| 471 |
| 472 if (!this.guestInstanceId) { |
| 473 return; |
| 474 } |
| 475 |
| 476 WebView.setAllowTransparency(this.guestInstanceId, this.allowtransparency); |
| 477 return; |
| 498 } else if (name == 'name') { | 478 } else if (name == 'name') { |
| 499 // We treat null attribute (attribute removed) and the empty string as | 479 // We treat null attribute (attribute removed) and the empty string as |
| 500 // one case. | 480 // one case. |
| 501 oldValue = oldValue || ''; | 481 oldValue = oldValue || ''; |
| 502 newValue = newValue || ''; | 482 newValue = newValue || ''; |
| 503 | 483 |
| 504 if (oldValue === newValue) { | 484 if (oldValue === newValue) { |
| 505 return; | 485 return; |
| 506 } | 486 } |
| 507 this.name = newValue; | 487 this.name = newValue; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 536 var result = {}; | 516 var result = {}; |
| 537 this.parseSrcAttribute(result); | 517 this.parseSrcAttribute(result); |
| 538 | 518 |
| 539 if (result.error) { | 519 if (result.error) { |
| 540 throw result.error; | 520 throw result.error; |
| 541 } | 521 } |
| 542 } else if (name == 'partition') { | 522 } else if (name == 'partition') { |
| 543 // Note that throwing error here won't synchronously propagate. | 523 // Note that throwing error here won't synchronously propagate. |
| 544 this.partition.fromAttribute(newValue, this.hasNavigated()); | 524 this.partition.fromAttribute(newValue, this.hasNavigated()); |
| 545 } | 525 } |
| 546 | |
| 547 // No <webview> -> <object> mutation propagation for these attributes. | |
| 548 if (name == 'src' || name == 'partition') { | |
| 549 return; | |
| 550 } | |
| 551 | |
| 552 if (this.browserPluginNode.hasOwnProperty(name)) { | |
| 553 this.browserPluginNode[name] = newValue; | |
| 554 } else { | |
| 555 this.browserPluginNode.setAttribute(name, newValue); | |
| 556 } | |
| 557 }; | 526 }; |
| 558 | 527 |
| 559 /** | 528 /** |
| 560 * @private | 529 * @private |
| 561 */ | 530 */ |
| 562 WebViewInternal.prototype.handleBrowserPluginAttributeMutation = | 531 WebViewInternal.prototype.handleBrowserPluginAttributeMutation = |
| 563 function(name, oldValue, newValue) { | 532 function(name, oldValue, newValue) { |
| 564 if (name == 'internalinstanceid' && !oldValue && !!newValue) { | 533 if (name == 'internalinstanceid' && !oldValue && !!newValue) { |
| 565 this.browserPluginNode.removeAttribute('internalinstanceid'); | 534 this.browserPluginNode.removeAttribute('internalinstanceid'); |
| 566 this.internalInstanceId = parseInt(newValue); | 535 this.internalInstanceId = parseInt(newValue); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 581 params, | 550 params, |
| 582 function(w) { | 551 function(w) { |
| 583 this.contentWindow = w; | 552 this.contentWindow = w; |
| 584 }.bind(this) | 553 }.bind(this) |
| 585 ); | 554 ); |
| 586 }.bind(this), 0); | 555 }.bind(this), 0); |
| 587 } | 556 } |
| 588 | 557 |
| 589 return; | 558 return; |
| 590 } | 559 } |
| 591 | |
| 592 // This observer monitors mutations to attributes of the BrowserPlugin and | |
| 593 // updates the <webview> attributes accordingly. | |
| 594 // |newValue| is null if the attribute |name| has been removed. | |
| 595 if (newValue != null) { | |
| 596 // Update the <webview> attribute to match the BrowserPlugin attribute. | |
| 597 // Note: Calling setAttribute on <webview> will trigger its mutation | |
| 598 // observer which will then propagate that attribute to BrowserPlugin. In | |
| 599 // cases where we permit assigning a BrowserPlugin attribute the same value | |
| 600 // again (such as navigation when crashed), this could end up in an infinite | |
| 601 // loop. Thus, we avoid this loop by only updating the <webview> attribute | |
| 602 // if the BrowserPlugin attributes differs from it. | |
| 603 if (newValue != this.webviewNode.getAttribute(name)) { | |
| 604 this.webviewNode.setAttribute(name, newValue); | |
| 605 } | |
| 606 } else { | |
| 607 // If an attribute is removed from the BrowserPlugin, then remove it | |
| 608 // from the <webview> as well. | |
| 609 this.webviewNode.removeAttribute(name); | |
| 610 } | |
| 611 }; | 560 }; |
| 612 | 561 |
| 613 WebViewInternal.prototype.onSizeChanged = function(webViewEvent) { | 562 WebViewInternal.prototype.onSizeChanged = function(webViewEvent) { |
| 614 var newWidth = webViewEvent.newWidth; | 563 var newWidth = webViewEvent.newWidth; |
| 615 var newHeight = webViewEvent.newHeight; | 564 var newHeight = webViewEvent.newHeight; |
| 616 | 565 |
| 617 var node = this.webviewNode; | 566 var node = this.webviewNode; |
| 618 | 567 |
| 619 var width = node.offsetWidth; | 568 var width = node.offsetWidth; |
| 620 var height = node.offsetHeight; | 569 var height = node.offsetHeight; |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 721 return this.guestInstanceId != undefined; | 670 return this.guestInstanceId != undefined; |
| 722 }; | 671 }; |
| 723 | 672 |
| 724 WebViewInternal.prototype.allocateInstanceId = function() { | 673 WebViewInternal.prototype.allocateInstanceId = function() { |
| 725 var storagePartitionId = | 674 var storagePartitionId = |
| 726 this.webviewNode.getAttribute(WEB_VIEW_ATTRIBUTE_PARTITION) || | 675 this.webviewNode.getAttribute(WEB_VIEW_ATTRIBUTE_PARTITION) || |
| 727 this.webviewNode[WEB_VIEW_ATTRIBUTE_PARTITION]; | 676 this.webviewNode[WEB_VIEW_ATTRIBUTE_PARTITION]; |
| 728 var params = { | 677 var params = { |
| 729 'storagePartitionId': storagePartitionId, | 678 'storagePartitionId': storagePartitionId, |
| 730 }; | 679 }; |
| 731 var self = this; | |
| 732 GuestViewInternal.createGuest( | 680 GuestViewInternal.createGuest( |
| 733 'webview', | 681 'webview', |
| 734 params, | 682 params, |
| 735 function(guestInstanceId) { | 683 function(guestInstanceId) { |
| 736 // TODO(lazyboy): Make sure this.autoNavigate_ stuff correctly updated | 684 this.attachWindow(guestInstanceId, false); |
| 737 // |self.src| at this point. | 685 }.bind(this) |
| 738 self.attachWindow(guestInstanceId, false); | 686 ); |
| 739 }); | |
| 740 }; | 687 }; |
| 741 | 688 |
| 742 WebViewInternal.prototype.onFrameNameChanged = function(name) { | 689 WebViewInternal.prototype.onFrameNameChanged = function(name) { |
| 743 this.name = name || ''; | 690 this.name = name || ''; |
| 744 if (this.name === '') { | 691 if (this.name === '') { |
| 745 this.webviewNode.removeAttribute('name'); | 692 this.webviewNode.removeAttribute('name'); |
| 746 } else { | 693 } else { |
| 747 this.webviewNode.setAttribute('name', this.name); | 694 this.webviewNode.setAttribute('name', this.name); |
| 748 } | 695 } |
| 749 }; | 696 }; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 761 * an event handler. | 708 * an event handler. |
| 762 */ | 709 */ |
| 763 WebViewInternal.prototype.setupEventProperty = function(eventName) { | 710 WebViewInternal.prototype.setupEventProperty = function(eventName) { |
| 764 var propertyName = 'on' + eventName.toLowerCase(); | 711 var propertyName = 'on' + eventName.toLowerCase(); |
| 765 Object.defineProperty(this.webviewNode, propertyName, { | 712 Object.defineProperty(this.webviewNode, propertyName, { |
| 766 get: function() { | 713 get: function() { |
| 767 return this.on[propertyName]; | 714 return this.on[propertyName]; |
| 768 }.bind(this), | 715 }.bind(this), |
| 769 set: function(value) { | 716 set: function(value) { |
| 770 if (this.on[propertyName]) | 717 if (this.on[propertyName]) |
| 771 this.webviewNode.removeEventListener(eventName, self.on[propertyName]); | 718 this.webviewNode.removeEventListener(eventName, this.on[propertyName]); |
| 772 this.on[propertyName] = value; | 719 this.on[propertyName] = value; |
| 773 if (value) | 720 if (value) |
| 774 this.webviewNode.addEventListener(eventName, value); | 721 this.webviewNode.addEventListener(eventName, value); |
| 775 }.bind(this), | 722 }.bind(this), |
| 776 enumerable: true | 723 enumerable: true |
| 777 }); | 724 }); |
| 778 }; | 725 }; |
| 779 | 726 |
| 780 // Updates state upon loadcommit. | 727 // Updates state upon loadcommit. |
| 781 WebViewInternal.prototype.onLoadCommit = function( | 728 WebViewInternal.prototype.onLoadCommit = function( |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 848 | 795 |
| 849 WebViewInternal.prototype.getZoom = function(callback) { | 796 WebViewInternal.prototype.getZoom = function(callback) { |
| 850 if (!this.guestInstanceId) { | 797 if (!this.guestInstanceId) { |
| 851 return; | 798 return; |
| 852 } | 799 } |
| 853 WebView.getZoom(this.guestInstanceId, callback); | 800 WebView.getZoom(this.guestInstanceId, callback); |
| 854 }; | 801 }; |
| 855 | 802 |
| 856 WebViewInternal.prototype.buildAttachParams = function(isNewWindow) { | 803 WebViewInternal.prototype.buildAttachParams = function(isNewWindow) { |
| 857 var params = { | 804 var params = { |
| 805 'allowtransparency': this.allowtransparency || false, |
| 858 'autosize': this.webviewNode.hasAttribute(WEB_VIEW_ATTRIBUTE_AUTOSIZE), | 806 'autosize': this.webviewNode.hasAttribute(WEB_VIEW_ATTRIBUTE_AUTOSIZE), |
| 859 'instanceId': this.viewInstanceId, | 807 'instanceId': this.viewInstanceId, |
| 860 'maxheight': parseInt(this.maxheight || 0), | 808 'maxheight': parseInt(this.maxheight || 0), |
| 861 'maxwidth': parseInt(this.maxwidth || 0), | 809 'maxwidth': parseInt(this.maxwidth || 0), |
| 862 'minheight': parseInt(this.minheight || 0), | 810 'minheight': parseInt(this.minheight || 0), |
| 863 'minwidth': parseInt(this.minwidth || 0), | 811 'minwidth': parseInt(this.minwidth || 0), |
| 864 'name': this.name, | 812 'name': this.name, |
| 865 // We don't need to navigate new window from here. | 813 // We don't need to navigate new window from here. |
| 866 'src': isNewWindow ? undefined : this.src, | 814 'src': isNewWindow ? undefined : this.src, |
| 867 // If we have a partition from the opener, that will also be already | 815 // If we have a partition from the opener, that will also be already |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1048 | 996 |
| 1049 /** | 997 /** |
| 1050 * Implemented when the experimental API is available. | 998 * Implemented when the experimental API is available. |
| 1051 * @private | 999 * @private |
| 1052 */ | 1000 */ |
| 1053 WebViewInternal.prototype.setupExperimentalContextMenus = function() { | 1001 WebViewInternal.prototype.setupExperimentalContextMenus = function() { |
| 1054 }; | 1002 }; |
| 1055 | 1003 |
| 1056 exports.WebView = WebView; | 1004 exports.WebView = WebView; |
| 1057 exports.WebViewInternal = WebViewInternal; | 1005 exports.WebViewInternal = WebViewInternal; |
| OLD | NEW |