| 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 addTagWatcher = require('tagWatcher').addTagWatcher; | 10 var addTagWatcher = require('tagWatcher').addTagWatcher; |
| (...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 416 ]; | 416 ]; |
| 417 | 417 |
| 418 var self = this; | 418 var self = this; |
| 419 var node = this.webviewNode_; | 419 var node = this.webviewNode_; |
| 420 var browserPluginNode = this.browserPluginNode_; | 420 var browserPluginNode = this.browserPluginNode_; |
| 421 | 421 |
| 422 var onTrackedObjectGone = function(requestId, e) { | 422 var onTrackedObjectGone = function(requestId, e) { |
| 423 var detail = e.detail ? JSON.parse(e.detail) : {}; | 423 var detail = e.detail ? JSON.parse(e.detail) : {}; |
| 424 if (detail.id != requestId) | 424 if (detail.id != requestId) |
| 425 return; | 425 return; |
| 426 browserPluginNode['-internal-setPermission'](requestId, false); | 426 browserPluginNode['-internal-setPermission'](requestId, false, ''); |
| 427 } | 427 } |
| 428 | 428 |
| 429 browserPluginNode.addEventListener('-internal-newwindow', function(e) { | 429 browserPluginNode.addEventListener('-internal-newwindow', function(e) { |
| 430 var evt = new Event('newwindow', { bubbles: true, cancelable: true }); | 430 var evt = new Event('newwindow', { bubbles: true, cancelable: true }); |
| 431 var detail = e.detail ? JSON.parse(e.detail) : {}; | 431 var detail = e.detail ? JSON.parse(e.detail) : {}; |
| 432 | 432 |
| 433 $Array.forEach(NEW_WINDOW_EVENT_ATTRIBUTES, function(attribName) { | 433 $Array.forEach(NEW_WINDOW_EVENT_ATTRIBUTES, function(attribName) { |
| 434 evt[attribName] = detail[attribName]; | 434 evt[attribName] = detail[attribName]; |
| 435 }); | 435 }); |
| 436 var requestId = detail.requestId; | 436 var requestId = detail.requestId; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 456 var attached = | 456 var attached = |
| 457 browserPluginNode['-internal-attachWindowTo'](webview, | 457 browserPluginNode['-internal-attachWindowTo'](webview, |
| 458 detail.windowId); | 458 detail.windowId); |
| 459 if (!attached) { | 459 if (!attached) { |
| 460 console.error(ERROR_MSG_NEWWINDOW_UNABLE_TO_ATTACH); | 460 console.error(ERROR_MSG_NEWWINDOW_UNABLE_TO_ATTACH); |
| 461 } | 461 } |
| 462 // If the object being passed into attach is not a valid <webview> | 462 // If the object being passed into attach is not a valid <webview> |
| 463 // then we will fail and it will be treated as if the new window | 463 // then we will fail and it will be treated as if the new window |
| 464 // was rejected. The permission API plumbing is used here to clean | 464 // was rejected. The permission API plumbing is used here to clean |
| 465 // up the state created for the new window if attaching fails. | 465 // up the state created for the new window if attaching fails. |
| 466 browserPluginNode['-internal-setPermission'](requestId, attached); | 466 browserPluginNode['-internal-setPermission'](requestId, attached, ''); |
| 467 }, 0); | 467 }, 0); |
| 468 }, | 468 }, |
| 469 discard: function() { | 469 discard: function() { |
| 470 validateCall(); | 470 validateCall(); |
| 471 browserPluginNode['-internal-setPermission'](requestId, false); | 471 browserPluginNode['-internal-setPermission'](requestId, false, ''); |
| 472 } | 472 } |
| 473 }; | 473 }; |
| 474 evt.window = window; | 474 evt.window = window; |
| 475 // Make browser plugin track lifetime of |window|. | 475 // Make browser plugin track lifetime of |window|. |
| 476 var onTrackedObjectGoneWithRequestId = | 476 var onTrackedObjectGoneWithRequestId = |
| 477 $Function.bind(onTrackedObjectGone, self, requestId); | 477 $Function.bind(onTrackedObjectGone, self, requestId); |
| 478 browserPluginNode.addEventListener('-internal-trackedobjectgone', | 478 browserPluginNode.addEventListener('-internal-trackedobjectgone', |
| 479 onTrackedObjectGoneWithRequestId); | 479 onTrackedObjectGoneWithRequestId); |
| 480 browserPluginNode['-internal-trackObjectLifetime'](window, requestId); | 480 browserPluginNode['-internal-trackObjectLifetime'](window, requestId); |
| 481 | 481 |
| 482 var defaultPrevented = !node.dispatchEvent(evt); | 482 var defaultPrevented = !node.dispatchEvent(evt); |
| 483 if (!actionTaken && !defaultPrevented) { | 483 if (!actionTaken && !defaultPrevented) { |
| 484 actionTaken = true; | 484 actionTaken = true; |
| 485 // The default action is to discard the window. | 485 // The default action is to discard the window. |
| 486 browserPluginNode['-internal-setPermission'](requestId, false); | 486 browserPluginNode['-internal-setPermission'](requestId, false, ''); |
| 487 console.warn(WARNING_MSG_NEWWINDOW_BLOCKED); | 487 console.warn(WARNING_MSG_NEWWINDOW_BLOCKED); |
| 488 } | 488 } |
| 489 }); | 489 }); |
| 490 }; | 490 }; |
| 491 | 491 |
| 492 /** | 492 /** |
| 493 * @private | 493 * @private |
| 494 */ | 494 */ |
| 495 WebView.prototype.setupExecuteCodeAPI_ = function() { | 495 WebView.prototype.setupExecuteCodeAPI_ = function() { |
| 496 var ERROR_MSG_CANNOT_INJECT_SCRIPT = '<webview>: ' + | 496 var ERROR_MSG_CANNOT_INJECT_SCRIPT = '<webview>: ' + |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 545 | 545 |
| 546 var self = this; | 546 var self = this; |
| 547 var node = this.webviewNode_; | 547 var node = this.webviewNode_; |
| 548 var browserPluginNode = this.browserPluginNode_; | 548 var browserPluginNode = this.browserPluginNode_; |
| 549 var internalevent = '-internal-permissionrequest'; | 549 var internalevent = '-internal-permissionrequest'; |
| 550 | 550 |
| 551 var onTrackedObjectGone = function(requestId, e) { | 551 var onTrackedObjectGone = function(requestId, e) { |
| 552 var detail = e.detail ? JSON.parse(e.detail) : {}; | 552 var detail = e.detail ? JSON.parse(e.detail) : {}; |
| 553 if (detail.id != requestId) | 553 if (detail.id != requestId) |
| 554 return; | 554 return; |
| 555 browserPluginNode['-internal-setPermission'](requestId, false); | 555 browserPluginNode['-internal-setPermission'](requestId, false, ''); |
| 556 } | 556 } |
| 557 | 557 |
| 558 browserPluginNode.addEventListener(internalevent, function(e) { | 558 browserPluginNode.addEventListener(internalevent, function(e) { |
| 559 var evt = new Event('permissionrequest', {bubbles: true, cancelable: true}); | 559 var evt = new Event('permissionrequest', {bubbles: true, cancelable: true}); |
| 560 var detail = e.detail ? JSON.parse(e.detail) : {}; | 560 var detail = e.detail ? JSON.parse(e.detail) : {}; |
| 561 $Array.forEach(EXPOSED_PERMISSION_EVENT_ATTRIBS, function(attribName) { | 561 $Array.forEach(EXPOSED_PERMISSION_EVENT_ATTRIBS, function(attribName) { |
| 562 if (detail[attribName] !== undefined) | 562 if (detail[attribName] !== undefined) |
| 563 evt[attribName] = detail[attribName]; | 563 evt[attribName] = detail[attribName]; |
| 564 }); | 564 }); |
| 565 var requestId = detail.requestId; | 565 var requestId = detail.requestId; |
| 566 | 566 |
| 567 if (detail.requestId !== undefined && | 567 if (detail.requestId !== undefined && |
| 568 PERMISSION_TYPES.indexOf(detail.permission) >= 0) { | 568 PERMISSION_TYPES.indexOf(detail.permission) >= 0) { |
| 569 // TODO(lazyboy): Also fill in evt.details (see webview specs). | 569 // TODO(lazyboy): Also fill in evt.details (see webview specs). |
| 570 // http://crbug.com/141197. | 570 // http://crbug.com/141197. |
| 571 var decisionMade = false; | 571 var decisionMade = false; |
| 572 // Construct the event.request object. | 572 // Construct the event.request object. |
| 573 var request = { | 573 var request = { |
| 574 allow: function() { | 574 allow: function() { |
| 575 if (decisionMade) { | 575 if (decisionMade) { |
| 576 throw new Error(ERROR_MSG_PERMISSION_ALREADY_DECIDED); | 576 throw new Error(ERROR_MSG_PERMISSION_ALREADY_DECIDED); |
| 577 } else { | 577 } else { |
| 578 browserPluginNode['-internal-setPermission'](requestId, true); | 578 browserPluginNode['-internal-setPermission'](requestId, true, ''); |
| 579 decisionMade = true; | 579 decisionMade = true; |
| 580 } | 580 } |
| 581 }, | 581 }, |
| 582 deny: function() { | 582 deny: function() { |
| 583 if (decisionMade) { | 583 if (decisionMade) { |
| 584 throw new Error(ERROR_MSG_PERMISSION_ALREADY_DECIDED); | 584 throw new Error(ERROR_MSG_PERMISSION_ALREADY_DECIDED); |
| 585 } else { | 585 } else { |
| 586 browserPluginNode['-internal-setPermission'](requestId, false); | 586 browserPluginNode['-internal-setPermission'](requestId, false, ''); |
| 587 decisionMade = true; | 587 decisionMade = true; |
| 588 } | 588 } |
| 589 } | 589 } |
| 590 }; | 590 }; |
| 591 evt.request = request; | 591 evt.request = request; |
| 592 | 592 |
| 593 // Make browser plugin track lifetime of |request|. | 593 // Make browser plugin track lifetime of |request|. |
| 594 var onTrackedObjectGoneWithRequestId = | 594 var onTrackedObjectGoneWithRequestId = |
| 595 $Function.bind(onTrackedObjectGone, self, requestId); | 595 $Function.bind(onTrackedObjectGone, self, requestId); |
| 596 browserPluginNode.addEventListener('-internal-trackedobjectgone', | 596 browserPluginNode.addEventListener('-internal-trackedobjectgone', |
| 597 onTrackedObjectGoneWithRequestId); | 597 onTrackedObjectGoneWithRequestId); |
| 598 browserPluginNode['-internal-trackObjectLifetime'](request, requestId); | 598 browserPluginNode['-internal-trackObjectLifetime'](request, requestId); |
| 599 | 599 |
| 600 var defaultPrevented = !node.dispatchEvent(evt); | 600 var defaultPrevented = !node.dispatchEvent(evt); |
| 601 if (!decisionMade && !defaultPrevented) { | 601 if (!decisionMade && !defaultPrevented) { |
| 602 decisionMade = true; | 602 decisionMade = true; |
| 603 browserPluginNode['-internal-setPermission'](requestId, false); | 603 browserPluginNode['-internal-setPermission'](requestId, false, ''); |
| 604 } | 604 } |
| 605 } | 605 } |
| 606 }); | 606 }); |
| 607 }; | 607 }; |
| 608 | 608 |
| 609 /** | 609 /** |
| 610 * Implemented when the experimental API is available. | 610 * Implemented when the experimental API is available. |
| 611 * @private | 611 * @private |
| 612 */ | 612 */ |
| 613 WebView.prototype.maybeGetExperimentalPermissionTypes_ = function() { | 613 WebView.prototype.maybeGetExperimentalPermissionTypes_ = function() { |
| 614 return []; | 614 return []; |
| 615 }; | 615 }; |
| 616 | 616 |
| 617 /** | 617 /** |
| 618 * Implemented when the experimental API is available. | 618 * Implemented when the experimental API is available. |
| 619 * @private | 619 * @private |
| 620 */ | 620 */ |
| 621 WebView.prototype.maybeSetupExperimentalAPI_ = function() {}; | 621 WebView.prototype.maybeSetupExperimentalAPI_ = function() {}; |
| 622 | 622 |
| 623 exports.WebView = WebView; | 623 exports.WebView = WebView; |
| OLD | NEW |