| 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 messagingNatives = requireNative('messaging_natives'); | 14 var messagingNatives = requireNative('messaging_natives'); |
| 14 var WebRequestEvent = require('webRequestInternal').WebRequestEvent; | 15 var WebRequestEvent = require('webRequestInternal').WebRequestEvent; |
| 15 var webRequestSchema = | 16 var webRequestSchema = |
| 16 requireNative('schema_registry').GetSchema('webRequest'); | 17 requireNative('schema_registry').GetSchema('webRequest'); |
| 17 | 18 |
| 18 // This secret enables hiding <webview> private members from the outside scope. | 19 // This secret enables hiding <webview> private members from the outside scope. |
| 19 // Outside of this file, |secret| is inaccessible. The only way to access the | 20 // Outside of this file, |secret| is inaccessible. The only way to access the |
| 20 // <webview> element's internal members is via the |secret|. Since it's only | 21 // <webview> element's internal members is via the |secret|. Since it's only |
| 21 // accessible by code here (and in web_view_experimental), only <webview>'s | 22 // accessible by code here (and in web_view_experimental), only <webview>'s |
| 22 // API can access it and not external developers. | 23 // API can access it and not external developers. |
| (...skipping 646 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 669 this.webviewNode_, | 670 this.webviewNode_, |
| 670 'request', | 671 'request', |
| 671 { | 672 { |
| 672 value: request, | 673 value: request, |
| 673 enumerable: true, | 674 enumerable: true, |
| 674 writable: false | 675 writable: false |
| 675 } | 676 } |
| 676 ); | 677 ); |
| 677 }; | 678 }; |
| 678 | 679 |
| 679 // Save document.register in a variable in case the developer attempts to | |
| 680 // override it at some point. | |
| 681 var register = document.register; | |
| 682 | |
| 683 // Registers browser plugin <object> custom element. | 680 // Registers browser plugin <object> custom element. |
| 684 function registerBrowserPluginElement() { | 681 function registerBrowserPluginElement() { |
| 685 var proto = Object.create(HTMLObjectElement.prototype); | 682 var proto = Object.create(HTMLObjectElement.prototype); |
| 686 | 683 |
| 687 proto.createdCallback = function() { | 684 proto.createdCallback = function() { |
| 688 this.setAttribute('type', 'application/browser-plugin'); | 685 this.setAttribute('type', 'application/browser-plugin'); |
| 689 // The <object> node fills in the <webview> container. | 686 // The <object> node fills in the <webview> container. |
| 690 this.style.width = '100%'; | 687 this.style.width = '100%'; |
| 691 this.style.height = '100%'; | 688 this.style.height = '100%'; |
| 692 }; | 689 }; |
| 693 | 690 |
| 694 proto.attributeChangedCallback = function(name, oldValue, newValue) { | 691 proto.attributeChangedCallback = function(name, oldValue, newValue) { |
| 695 if (!this.internal_) { | 692 if (!this.internal_) { |
| 696 return; | 693 return; |
| 697 } | 694 } |
| 698 var internal = this.internal_(secret); | 695 var internal = this.internal_(secret); |
| 699 internal.handleBrowserPluginAttributeMutation_(name, oldValue, newValue); | 696 internal.handleBrowserPluginAttributeMutation_(name, oldValue, newValue); |
| 700 }; | 697 }; |
| 701 | 698 |
| 702 WebViewInternal.BrowserPlugin = | 699 WebViewInternal.BrowserPlugin = |
| 703 register.call(document, 'browser-plugin', {prototype: proto}); | 700 DocumentNatives.RegisterElement('browser-plugin', {prototype: proto}); |
| 704 | 701 |
| 705 delete proto.createdCallback; | 702 delete proto.createdCallback; |
| 706 delete proto.enteredDocumentCallback; | 703 delete proto.enteredDocumentCallback; |
| 707 delete proto.leftDocumentCallback; | 704 delete proto.leftDocumentCallback; |
| 708 delete proto.attributeChangedCallback; | 705 delete proto.attributeChangedCallback; |
| 709 } | 706 } |
| 710 | 707 |
| 711 // Registers <webview> custom element. | 708 // Registers <webview> custom element. |
| 712 function registerWebViewElement() { | 709 function registerWebViewElement() { |
| 713 var proto = Object.create(HTMLElement.prototype); | 710 var proto = Object.create(HTMLElement.prototype); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 760 proto.executeScript = function(var_args) { | 757 proto.executeScript = function(var_args) { |
| 761 var internal = this.internal_(secret); | 758 var internal = this.internal_(secret); |
| 762 $Function.apply(internal.executeScript_, internal, arguments); | 759 $Function.apply(internal.executeScript_, internal, arguments); |
| 763 }; | 760 }; |
| 764 | 761 |
| 765 proto.insertCSS = function(var_args) { | 762 proto.insertCSS = function(var_args) { |
| 766 var internal = this.internal_(secret); | 763 var internal = this.internal_(secret); |
| 767 $Function.apply(internal.insertCSS_, internal, arguments); | 764 $Function.apply(internal.insertCSS_, internal, arguments); |
| 768 }; | 765 }; |
| 769 | 766 |
| 770 window.WebView = register.call(document, 'webview', {prototype: proto}); | 767 window.WebView = |
| 768 DocumentNatives.RegisterElement('webview', {prototype: proto}); |
| 771 | 769 |
| 772 // Delete the callbacks so developers cannot call them and produce unexpected | 770 // Delete the callbacks so developers cannot call them and produce unexpected |
| 773 // behavior. | 771 // behavior. |
| 774 delete proto.createdCallback; | 772 delete proto.createdCallback; |
| 775 delete proto.enteredDocumentCallback; | 773 delete proto.enteredDocumentCallback; |
| 776 delete proto.leftDocumentCallback; | 774 delete proto.leftDocumentCallback; |
| 777 delete proto.attributeChangedCallback; | 775 delete proto.attributeChangedCallback; |
| 778 } | 776 } |
| 779 | 777 |
| 780 var useCapture = true; | 778 var useCapture = true; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 800 WebViewInternal.prototype.maybeGetWebviewExperimentalExtEvents_ = function() {}; | 798 WebViewInternal.prototype.maybeGetWebviewExperimentalExtEvents_ = function() {}; |
| 801 | 799 |
| 802 /** | 800 /** |
| 803 * Implemented when the experimental API is available. | 801 * Implemented when the experimental API is available. |
| 804 * @private | 802 * @private |
| 805 */ | 803 */ |
| 806 WebViewInternal.prototype.maybeAttachWebRequestEventToWebview_ = function() {}; | 804 WebViewInternal.prototype.maybeAttachWebRequestEventToWebview_ = function() {}; |
| 807 | 805 |
| 808 exports.WebViewInternal = WebViewInternal; | 806 exports.WebViewInternal = WebViewInternal; |
| 809 exports.CreateEvent = createEvent; | 807 exports.CreateEvent = createEvent; |
| OLD | NEW |