| 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 DocumentNatives = requireNative('document_natives'); | 12 var DocumentNatives = requireNative('document_natives'); |
| 13 var EventBindings = require('event_bindings'); | 13 var EventBindings = require('event_bindings'); |
| 14 var MessagingNatives = requireNative('messaging_natives'); | 14 var MessagingNatives = requireNative('messaging_natives'); |
| 15 var WebRequestEvent = require('webRequestInternal').WebRequestEvent; | 15 var WebRequestEvent = require('webRequestInternal').WebRequestEvent; |
| 16 var WebRequestSchema = | 16 var WebRequestSchema = |
| 17 requireNative('schema_registry').GetSchema('webRequest'); | 17 requireNative('schema_registry').GetSchema('webRequest'); |
| 18 var WebView = require('binding').Binding.create('webview').generate(); | 18 var WebView = require('binding').Binding.create('webview').generate(); |
| 19 var WebViewNatives = requireNative('webview_natives'); |
| 19 | 20 |
| 20 // This secret enables hiding <webview> private members from the outside scope. | 21 // This secret enables hiding <webview> private members from the outside scope. |
| 21 // Outside of this file, |secret| is inaccessible. The only way to access the | 22 // Outside of this file, |secret| is inaccessible. The only way to access the |
| 22 // <webview> element's internal members is via the |secret|. Since it's only | 23 // <webview> element's internal members is via the |secret|. Since it's only |
| 23 // accessible by code here (and in web_view_experimental), only <webview>'s | 24 // accessible by code here (and in web_view_experimental), only <webview>'s |
| 24 // API can access it and not external developers. | 25 // API can access it and not external developers. |
| 25 var secret = {}; | 26 var secret = {}; |
| 26 | 27 |
| 27 var WEB_VIEW_ATTRIBUTE_MAXHEIGHT = 'maxheight'; | 28 var WEB_VIEW_ATTRIBUTE_MAXHEIGHT = 'maxheight'; |
| 28 var WEB_VIEW_ATTRIBUTE_MAXWIDTH = 'maxwidth'; | 29 var WEB_VIEW_ATTRIBUTE_MAXWIDTH = 'maxwidth'; |
| 29 var WEB_VIEW_ATTRIBUTE_MINHEIGHT = 'minheight'; | 30 var WEB_VIEW_ATTRIBUTE_MINHEIGHT = 'minheight'; |
| 30 var WEB_VIEW_ATTRIBUTE_MINWIDTH = 'minwidth'; | 31 var WEB_VIEW_ATTRIBUTE_MINWIDTH = 'minwidth'; |
| 31 | 32 |
| 32 /** @type {Array.<string>} */ | 33 /** @type {Array.<string>} */ |
| 33 var WEB_VIEW_ATTRIBUTES = [ | 34 var WEB_VIEW_ATTRIBUTES = [ |
| 34 'name', | 35 'name', |
| 35 'partition', | 36 'partition', |
| 36 'autosize', | 37 'autosize', |
| 37 WEB_VIEW_ATTRIBUTE_MINHEIGHT, | 38 WEB_VIEW_ATTRIBUTE_MINHEIGHT, |
| 38 WEB_VIEW_ATTRIBUTE_MINWIDTH, | 39 WEB_VIEW_ATTRIBUTE_MINWIDTH, |
| 39 WEB_VIEW_ATTRIBUTE_MAXHEIGHT, | 40 WEB_VIEW_ATTRIBUTE_MAXHEIGHT, |
| 40 WEB_VIEW_ATTRIBUTE_MAXWIDTH | 41 WEB_VIEW_ATTRIBUTE_MAXWIDTH |
| 41 ]; | 42 ]; |
| 42 | 43 |
| 43 var webViewInstanceIdCounter = 0; | |
| 44 | |
| 45 var CreateEvent = function(name) { | 44 var CreateEvent = function(name) { |
| 46 var eventOpts = {supportsListeners: true, supportsFilters: true}; | 45 var eventOpts = {supportsListeners: true, supportsFilters: true}; |
| 47 return new EventBindings.Event(name, undefined, eventOpts); | 46 return new EventBindings.Event(name, undefined, eventOpts); |
| 48 }; | 47 }; |
| 49 | 48 |
| 50 var WEB_VIEW_EVENTS = { | 49 var WEB_VIEW_EVENTS = { |
| 51 'close': { | 50 'close': { |
| 52 evt: CreateEvent('webview.onClose'), | 51 evt: CreateEvent('webview.onClose'), |
| 53 fields: [] | 52 fields: [] |
| 54 }, | 53 }, |
| (...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 532 node.style.height = webViewEvent.newHeight + 'px'; | 531 node.style.height = webViewEvent.newHeight + 'px'; |
| 533 } | 532 } |
| 534 node.dispatchEvent(webViewEvent); | 533 node.dispatchEvent(webViewEvent); |
| 535 }; | 534 }; |
| 536 | 535 |
| 537 /** | 536 /** |
| 538 * @private | 537 * @private |
| 539 */ | 538 */ |
| 540 WebViewInternal.prototype.setupWebviewNodeEvents_ = function() { | 539 WebViewInternal.prototype.setupWebviewNodeEvents_ = function() { |
| 541 var self = this; | 540 var self = this; |
| 542 this.viewInstanceId_ = ++webViewInstanceIdCounter; | 541 this.viewInstanceId_ = WebViewNatives.GetNextInstanceID(); |
| 543 var onInstanceIdAllocated = function(e) { | 542 var onInstanceIdAllocated = function(e) { |
| 544 var detail = e.detail ? JSON.parse(e.detail) : {}; | 543 var detail = e.detail ? JSON.parse(e.detail) : {}; |
| 545 self.instanceId_ = detail.windowId; | 544 self.instanceId_ = detail.windowId; |
| 546 var params = { | 545 var params = { |
| 547 'api': 'webview', | 546 'api': 'webview', |
| 548 'instanceId': self.viewInstanceId_ | 547 'instanceId': self.viewInstanceId_ |
| 549 }; | 548 }; |
| 550 self.browserPluginNode_['-internal-attach'](params); | 549 self.browserPluginNode_['-internal-attach'](params); |
| 551 | 550 |
| 552 var events = self.getEvents_(); | 551 var events = self.getEvents_(); |
| (...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 920 | 919 |
| 921 /** | 920 /** |
| 922 * Implemented when the experimental API is available. | 921 * Implemented when the experimental API is available. |
| 923 * @private | 922 * @private |
| 924 */ | 923 */ |
| 925 WebViewInternal.prototype.maybeAttachWebRequestEventToWebview_ = function() {}; | 924 WebViewInternal.prototype.maybeAttachWebRequestEventToWebview_ = function() {}; |
| 926 | 925 |
| 927 exports.WebView = WebView; | 926 exports.WebView = WebView; |
| 928 exports.WebViewInternal = WebViewInternal; | 927 exports.WebViewInternal = WebViewInternal; |
| 929 exports.CreateEvent = CreateEvent; | 928 exports.CreateEvent = CreateEvent; |
| OLD | NEW |