| OLD | NEW |
| (Empty) |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 var FILES_APP_ORIGIN = 'chrome-extension://hhaomjibdihmijegdhdafkllkbggdgoj'; | |
| 6 | |
| 7 /** | |
| 8 * Polymer element to render an image securely inside webview. | |
| 9 * When tapped, files-safe-img-tap-inside or | |
| 10 * files-safe-img-tap-outside events are fired depending on the position | |
| 11 * of the tap. | |
| 12 */ | |
| 13 var FilesSafeImg = Polymer({ | |
| 14 is: 'files-safe-img', | |
| 15 | |
| 16 properties: { | |
| 17 // URL accessible from webview. | |
| 18 src: { | |
| 19 type: String, | |
| 20 observer: 'onSrcChange_', | |
| 21 reflectToAttribute: true | |
| 22 } | |
| 23 }, | |
| 24 | |
| 25 listeners: {'src-changed': 'onSrcChange_'}, | |
| 26 | |
| 27 onSrcChange_: function() { | |
| 28 if (!this.src && this.webview_) { | |
| 29 // Remove webview to clean up unnecessary processes. | |
| 30 Polymer.dom(this.$.content).removeChild(this.webview_); | |
| 31 this.webview_ = null; | |
| 32 } else if (this.src && !this.webview_) { | |
| 33 // Create webview node only if src exists to save resouces. | |
| 34 var webview = document.createElement('webview'); | |
| 35 this.webview_ = webview; | |
| 36 webview.partition = 'trusted'; | |
| 37 webview.allowtransparency = 'true'; | |
| 38 Polymer.dom(this.$.content).appendChild(webview); | |
| 39 webview.addEventListener( | |
| 40 'contentload', this.onSrcChange_.bind(this)); | |
| 41 webview.src = 'foreground/elements/files_safe_img_webview_content.html'; | |
| 42 } else if (this.src && this.webview_.contentWindow) { | |
| 43 this.webview_.contentWindow.postMessage(this.src, FILES_APP_ORIGIN); | |
| 44 } | |
| 45 }, | |
| 46 | |
| 47 created: function() { | |
| 48 /** | |
| 49 * @type {HTMLElement} | |
| 50 */ | |
| 51 this.webview_ = null; | |
| 52 }, | |
| 53 | |
| 54 ready: function() { | |
| 55 window.addEventListener('message', function(event) { | |
| 56 if (event.origin !== FILES_APP_ORIGIN) { | |
| 57 console.error('Unknown origin.'); | |
| 58 return; | |
| 59 } | |
| 60 if (event.data === 'tap-inside') { | |
| 61 this.fire('files-safe-img-tap-inside'); | |
| 62 } else if (event.data === 'tap-outside') { | |
| 63 this.fire('files-safe-img-tap-outside'); | |
| 64 } | |
| 65 }.bind(this)); | |
| 66 } | |
| 67 }); | |
| OLD | NEW |