| 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 var watchForTag = require('tagWatcher').watchForTag; | 10 var watchForTag = require('tagWatcher').watchForTag; |
| (...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 431 ]; | 431 ]; |
| 432 | 432 |
| 433 var self = this; | 433 var self = this; |
| 434 var node = this.webviewNode_; | 434 var node = this.webviewNode_; |
| 435 var browserPluginNode = this.browserPluginNode_; | 435 var browserPluginNode = this.browserPluginNode_; |
| 436 | 436 |
| 437 var onTrackedObjectGone = function(requestId, e) { | 437 var onTrackedObjectGone = function(requestId, e) { |
| 438 var detail = e.detail ? JSON.parse(e.detail) : {}; | 438 var detail = e.detail ? JSON.parse(e.detail) : {}; |
| 439 if (detail.id != requestId) | 439 if (detail.id != requestId) |
| 440 return; | 440 return; |
| 441 browserPluginNode['-internal-setPermission'](requestId, false); | 441 browserPluginNode['-internal-setPermission'](requestId, false, ''); |
| 442 } | 442 } |
| 443 | 443 |
| 444 browserPluginNode.addEventListener('-internal-newwindow', function(e) { | 444 browserPluginNode.addEventListener('-internal-newwindow', function(e) { |
| 445 var evt = new Event('newwindow', { bubbles: true, cancelable: true }); | 445 var evt = new Event('newwindow', { bubbles: true, cancelable: true }); |
| 446 var detail = e.detail ? JSON.parse(e.detail) : {}; | 446 var detail = e.detail ? JSON.parse(e.detail) : {}; |
| 447 | 447 |
| 448 $Array.forEach(NEW_WINDOW_EVENT_ATTRIBUTES, function(attribName) { | 448 $Array.forEach(NEW_WINDOW_EVENT_ATTRIBUTES, function(attribName) { |
| 449 evt[attribName] = detail[attribName]; | 449 evt[attribName] = detail[attribName]; |
| 450 }); | 450 }); |
| 451 var requestId = detail.requestId; | 451 var requestId = detail.requestId; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 471 var attached = | 471 var attached = |
| 472 browserPluginNode['-internal-attachWindowTo'](webview, | 472 browserPluginNode['-internal-attachWindowTo'](webview, |
| 473 detail.windowId); | 473 detail.windowId); |
| 474 if (!attached) { | 474 if (!attached) { |
| 475 console.error(ERROR_MSG_NEWWINDOW_UNABLE_TO_ATTACH); | 475 console.error(ERROR_MSG_NEWWINDOW_UNABLE_TO_ATTACH); |
| 476 } | 476 } |
| 477 // If the object being passed into attach is not a valid <webview> | 477 // If the object being passed into attach is not a valid <webview> |
| 478 // then we will fail and it will be treated as if the new window | 478 // then we will fail and it will be treated as if the new window |
| 479 // was rejected. The permission API plumbing is used here to clean | 479 // was rejected. The permission API plumbing is used here to clean |
| 480 // up the state created for the new window if attaching fails. | 480 // up the state created for the new window if attaching fails. |
| 481 browserPluginNode['-internal-setPermission'](requestId, attached); | 481 browserPluginNode['-internal-setPermission'](requestId, attached, ''); |
| 482 }, 0); | 482 }, 0); |
| 483 }, | 483 }, |
| 484 discard: function() { | 484 discard: function() { |
| 485 validateCall(); | 485 validateCall(); |
| 486 browserPluginNode['-internal-setPermission'](requestId, false); | 486 browserPluginNode['-internal-setPermission'](requestId, false, ''); |
| 487 } | 487 } |
| 488 }; | 488 }; |
| 489 evt.window = window; | 489 evt.window = window; |
| 490 // Make browser plugin track lifetime of |window|. | 490 // Make browser plugin track lifetime of |window|. |
| 491 var onTrackedObjectGoneWithRequestId = | 491 var onTrackedObjectGoneWithRequestId = |
| 492 $Function.bind(onTrackedObjectGone, self, requestId); | 492 $Function.bind(onTrackedObjectGone, self, requestId); |
| 493 browserPluginNode.addEventListener('-internal-trackedobjectgone', | 493 browserPluginNode.addEventListener('-internal-trackedobjectgone', |
| 494 onTrackedObjectGoneWithRequestId); | 494 onTrackedObjectGoneWithRequestId); |
| 495 browserPluginNode['-internal-trackObjectLifetime'](window, requestId); | 495 browserPluginNode['-internal-trackObjectLifetime'](window, requestId); |
| 496 | 496 |
| 497 var defaultPrevented = !node.dispatchEvent(evt); | 497 var defaultPrevented = !node.dispatchEvent(evt); |
| 498 if (!actionTaken && !defaultPrevented) { | 498 if (!actionTaken && !defaultPrevented) { |
| 499 actionTaken = true; | 499 actionTaken = true; |
| 500 // The default action is to discard the window. | 500 // The default action is to discard the window. |
| 501 browserPluginNode['-internal-setPermission'](requestId, false); | 501 browserPluginNode['-internal-setPermission'](requestId, false, ''); |
| 502 console.warn(WARNING_MSG_NEWWINDOW_BLOCKED); | 502 console.warn(WARNING_MSG_NEWWINDOW_BLOCKED); |
| 503 } | 503 } |
| 504 }); | 504 }); |
| 505 }; | 505 }; |
| 506 | 506 |
| 507 /** | 507 /** |
| 508 * @private | 508 * @private |
| 509 */ | 509 */ |
| 510 WebView.prototype.setupExecuteCodeAPI_ = function() { | 510 WebView.prototype.setupExecuteCodeAPI_ = function() { |
| 511 var ERROR_MSG_CANNOT_INJECT_SCRIPT = '<webview>: ' + | 511 var ERROR_MSG_CANNOT_INJECT_SCRIPT = '<webview>: ' + |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 560 | 560 |
| 561 var self = this; | 561 var self = this; |
| 562 var node = this.webviewNode_; | 562 var node = this.webviewNode_; |
| 563 var browserPluginNode = this.browserPluginNode_; | 563 var browserPluginNode = this.browserPluginNode_; |
| 564 var internalevent = '-internal-permissionrequest'; | 564 var internalevent = '-internal-permissionrequest'; |
| 565 | 565 |
| 566 var onTrackedObjectGone = function(requestId, e) { | 566 var onTrackedObjectGone = function(requestId, e) { |
| 567 var detail = e.detail ? JSON.parse(e.detail) : {}; | 567 var detail = e.detail ? JSON.parse(e.detail) : {}; |
| 568 if (detail.id != requestId) | 568 if (detail.id != requestId) |
| 569 return; | 569 return; |
| 570 browserPluginNode['-internal-setPermission'](requestId, false); | 570 browserPluginNode['-internal-setPermission'](requestId, false, ''); |
| 571 } | 571 } |
| 572 | 572 |
| 573 browserPluginNode.addEventListener(internalevent, function(e) { | 573 browserPluginNode.addEventListener(internalevent, function(e) { |
| 574 var evt = new Event('permissionrequest', {bubbles: true, cancelable: true}); | 574 var evt = new Event('permissionrequest', {bubbles: true, cancelable: true}); |
| 575 var detail = e.detail ? JSON.parse(e.detail) : {}; | 575 var detail = e.detail ? JSON.parse(e.detail) : {}; |
| 576 $Array.forEach(EXPOSED_PERMISSION_EVENT_ATTRIBS, function(attribName) { | 576 $Array.forEach(EXPOSED_PERMISSION_EVENT_ATTRIBS, function(attribName) { |
| 577 if (detail[attribName] !== undefined) | 577 if (detail[attribName] !== undefined) |
| 578 evt[attribName] = detail[attribName]; | 578 evt[attribName] = detail[attribName]; |
| 579 }); | 579 }); |
| 580 var requestId = detail.requestId; | 580 var requestId = detail.requestId; |
| 581 | 581 |
| 582 if (detail.requestId !== undefined && | 582 if (detail.requestId !== undefined && |
| 583 PERMISSION_TYPES.indexOf(detail.permission) >= 0) { | 583 PERMISSION_TYPES.indexOf(detail.permission) >= 0) { |
| 584 // TODO(lazyboy): Also fill in evt.details (see webview specs). | 584 // TODO(lazyboy): Also fill in evt.details (see webview specs). |
| 585 // http://crbug.com/141197. | 585 // http://crbug.com/141197. |
| 586 var decisionMade = false; | 586 var decisionMade = false; |
| 587 // Construct the event.request object. | 587 // Construct the event.request object. |
| 588 var request = { | 588 var request = { |
| 589 allow: function() { | 589 allow: function() { |
| 590 if (decisionMade) { | 590 if (decisionMade) { |
| 591 throw new Error(ERROR_MSG_PERMISSION_ALREADY_DECIDED); | 591 throw new Error(ERROR_MSG_PERMISSION_ALREADY_DECIDED); |
| 592 } else { | 592 } else { |
| 593 browserPluginNode['-internal-setPermission'](requestId, true); | 593 browserPluginNode['-internal-setPermission'](requestId, true, ''); |
| 594 decisionMade = true; | 594 decisionMade = true; |
| 595 } | 595 } |
| 596 }, | 596 }, |
| 597 deny: function() { | 597 deny: function() { |
| 598 if (decisionMade) { | 598 if (decisionMade) { |
| 599 throw new Error(ERROR_MSG_PERMISSION_ALREADY_DECIDED); | 599 throw new Error(ERROR_MSG_PERMISSION_ALREADY_DECIDED); |
| 600 } else { | 600 } else { |
| 601 browserPluginNode['-internal-setPermission'](requestId, false); | 601 browserPluginNode['-internal-setPermission'](requestId, false, ''); |
| 602 decisionMade = true; | 602 decisionMade = true; |
| 603 } | 603 } |
| 604 } | 604 } |
| 605 }; | 605 }; |
| 606 evt.request = request; | 606 evt.request = request; |
| 607 | 607 |
| 608 // Make browser plugin track lifetime of |request|. | 608 // Make browser plugin track lifetime of |request|. |
| 609 var onTrackedObjectGoneWithRequestId = | 609 var onTrackedObjectGoneWithRequestId = |
| 610 $Function.bind(onTrackedObjectGone, self, requestId); | 610 $Function.bind(onTrackedObjectGone, self, requestId); |
| 611 browserPluginNode.addEventListener('-internal-trackedobjectgone', | 611 browserPluginNode.addEventListener('-internal-trackedobjectgone', |
| 612 onTrackedObjectGoneWithRequestId); | 612 onTrackedObjectGoneWithRequestId); |
| 613 browserPluginNode['-internal-trackObjectLifetime'](request, requestId); | 613 browserPluginNode['-internal-trackObjectLifetime'](request, requestId); |
| 614 | 614 |
| 615 var defaultPrevented = !node.dispatchEvent(evt); | 615 var defaultPrevented = !node.dispatchEvent(evt); |
| 616 if (!decisionMade && !defaultPrevented) { | 616 if (!decisionMade && !defaultPrevented) { |
| 617 decisionMade = true; | 617 decisionMade = true; |
| 618 browserPluginNode['-internal-setPermission'](requestId, false); | 618 browserPluginNode['-internal-setPermission'](requestId, false, ''); |
| 619 } | 619 } |
| 620 } | 620 } |
| 621 }); | 621 }); |
| 622 }; | 622 }; |
| 623 | 623 |
| 624 /** | 624 /** |
| 625 * Implemented when the experimental API is available. | 625 * Implemented when the experimental API is available. |
| 626 * @private | 626 * @private |
| 627 */ | 627 */ |
| 628 WebView.prototype.maybeGetExperimentalPermissionTypes_ = function() { | 628 WebView.prototype.maybeGetExperimentalPermissionTypes_ = function() { |
| 629 return []; | 629 return []; |
| 630 }; | 630 }; |
| 631 | 631 |
| 632 /** | 632 /** |
| 633 * Implemented when the experimental API is available. | 633 * Implemented when the experimental API is available. |
| 634 * @private | 634 * @private |
| 635 */ | 635 */ |
| 636 WebView.prototype.maybeSetupExperimentalAPI_ = function() {}; | 636 WebView.prototype.maybeSetupExperimentalAPI_ = function() {}; |
| 637 | 637 |
| 638 exports.WebView = WebView; | 638 exports.WebView = WebView; |
| OLD | NEW |