| 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'); | |
| 20 | 19 |
| 21 // This secret enables hiding <webview> private members from the outside scope. | 20 // This secret enables hiding <webview> private members from the outside scope. |
| 22 // Outside of this file, |secret| is inaccessible. The only way to access the | 21 // Outside of this file, |secret| is inaccessible. The only way to access the |
| 23 // <webview> element's internal members is via the |secret|. Since it's only | 22 // <webview> element's internal members is via the |secret|. Since it's only |
| 24 // accessible by code here (and in web_view_experimental), only <webview>'s | 23 // accessible by code here (and in web_view_experimental), only <webview>'s |
| 25 // API can access it and not external developers. | 24 // API can access it and not external developers. |
| 26 var secret = {}; | 25 var secret = {}; |
| 27 | 26 |
| 28 var WEB_VIEW_ATTRIBUTE_MAXHEIGHT = 'maxheight'; | 27 var WEB_VIEW_ATTRIBUTE_MAXHEIGHT = 'maxheight'; |
| 29 var WEB_VIEW_ATTRIBUTE_MAXWIDTH = 'maxwidth'; | 28 var WEB_VIEW_ATTRIBUTE_MAXWIDTH = 'maxwidth'; |
| 30 var WEB_VIEW_ATTRIBUTE_MINHEIGHT = 'minheight'; | 29 var WEB_VIEW_ATTRIBUTE_MINHEIGHT = 'minheight'; |
| 31 var WEB_VIEW_ATTRIBUTE_MINWIDTH = 'minwidth'; | 30 var WEB_VIEW_ATTRIBUTE_MINWIDTH = 'minwidth'; |
| 32 | 31 |
| 33 /** @type {Array.<string>} */ | 32 /** @type {Array.<string>} */ |
| 34 var WEB_VIEW_ATTRIBUTES = [ | 33 var WEB_VIEW_ATTRIBUTES = [ |
| 35 'name', | 34 'name', |
| 36 'partition', | 35 'partition', |
| 37 'autosize', | 36 'autosize', |
| 38 WEB_VIEW_ATTRIBUTE_MINHEIGHT, | 37 WEB_VIEW_ATTRIBUTE_MINHEIGHT, |
| 39 WEB_VIEW_ATTRIBUTE_MINWIDTH, | 38 WEB_VIEW_ATTRIBUTE_MINWIDTH, |
| 40 WEB_VIEW_ATTRIBUTE_MAXHEIGHT, | 39 WEB_VIEW_ATTRIBUTE_MAXHEIGHT, |
| 41 WEB_VIEW_ATTRIBUTE_MAXWIDTH | 40 WEB_VIEW_ATTRIBUTE_MAXWIDTH |
| 42 ]; | 41 ]; |
| 43 | 42 |
| 43 var webViewInstanceIdCounter = 0; |
| 44 |
| 44 var CreateEvent = function(name) { | 45 var CreateEvent = function(name) { |
| 45 var eventOpts = {supportsListeners: true, supportsFilters: true}; | 46 var eventOpts = {supportsListeners: true, supportsFilters: true}; |
| 46 return new EventBindings.Event(name, undefined, eventOpts); | 47 return new EventBindings.Event(name, undefined, eventOpts); |
| 47 }; | 48 }; |
| 48 | 49 |
| 49 var WEB_VIEW_EVENTS = { | 50 var WEB_VIEW_EVENTS = { |
| 50 'close': { | 51 'close': { |
| 51 evt: CreateEvent('webview.onClose'), | 52 evt: CreateEvent('webview.onClose'), |
| 52 fields: [] | 53 fields: [] |
| 53 }, | 54 }, |
| (...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 543 node.style.height = webViewEvent.newHeight + 'px'; | 544 node.style.height = webViewEvent.newHeight + 'px'; |
| 544 } | 545 } |
| 545 node.dispatchEvent(webViewEvent); | 546 node.dispatchEvent(webViewEvent); |
| 546 }; | 547 }; |
| 547 | 548 |
| 548 /** | 549 /** |
| 549 * @private | 550 * @private |
| 550 */ | 551 */ |
| 551 WebViewInternal.prototype.setupWebviewNodeEvents_ = function() { | 552 WebViewInternal.prototype.setupWebviewNodeEvents_ = function() { |
| 552 var self = this; | 553 var self = this; |
| 553 this.viewInstanceId_ = WebViewNatives.GetNextInstanceID(); | 554 this.viewInstanceId_ = ++webViewInstanceIdCounter; |
| 554 var onInstanceIdAllocated = function(e) { | 555 var onInstanceIdAllocated = function(e) { |
| 555 var detail = e.detail ? JSON.parse(e.detail) : {}; | 556 var detail = e.detail ? JSON.parse(e.detail) : {}; |
| 556 self.instanceId_ = detail.windowId; | 557 self.instanceId_ = detail.windowId; |
| 557 var params = { | 558 var params = { |
| 558 'api': 'webview', | 559 'api': 'webview', |
| 559 'instanceId': self.viewInstanceId_ | 560 'instanceId': self.viewInstanceId_ |
| 560 }; | 561 }; |
| 561 self.browserPluginNode_['-internal-attach'](params); | 562 self.browserPluginNode_['-internal-attach'](params); |
| 562 | 563 |
| 563 var events = self.getEvents_(); | 564 var events = self.getEvents_(); |
| (...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 931 | 932 |
| 932 /** | 933 /** |
| 933 * Implemented when the experimental API is available. | 934 * Implemented when the experimental API is available. |
| 934 * @private | 935 * @private |
| 935 */ | 936 */ |
| 936 WebViewInternal.prototype.maybeAttachWebRequestEventToWebview_ = function() {}; | 937 WebViewInternal.prototype.maybeAttachWebRequestEventToWebview_ = function() {}; |
| 937 | 938 |
| 938 exports.WebView = WebView; | 939 exports.WebView = WebView; |
| 939 exports.WebViewInternal = WebViewInternal; | 940 exports.WebViewInternal = WebViewInternal; |
| 940 exports.CreateEvent = CreateEvent; | 941 exports.CreateEvent = CreateEvent; |
| OLD | NEW |