| 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 489 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 544 node.style.height = webViewEvent.newHeight + 'px'; | 543 node.style.height = webViewEvent.newHeight + 'px'; |
| 545 } | 544 } |
| 546 node.dispatchEvent(webViewEvent); | 545 node.dispatchEvent(webViewEvent); |
| 547 }; | 546 }; |
| 548 | 547 |
| 549 /** | 548 /** |
| 550 * @private | 549 * @private |
| 551 */ | 550 */ |
| 552 WebViewInternal.prototype.setupWebviewNodeEvents_ = function() { | 551 WebViewInternal.prototype.setupWebviewNodeEvents_ = function() { |
| 553 var self = this; | 552 var self = this; |
| 554 this.viewInstanceId_ = ++webViewInstanceIdCounter; | 553 this.viewInstanceId_ = WebViewNatives.GetNextInstanceID(); |
| 555 var onInstanceIdAllocated = function(e) { | 554 var onInstanceIdAllocated = function(e) { |
| 556 var detail = e.detail ? JSON.parse(e.detail) : {}; | 555 var detail = e.detail ? JSON.parse(e.detail) : {}; |
| 557 self.instanceId_ = detail.windowId; | 556 self.instanceId_ = detail.windowId; |
| 558 var params = { | 557 var params = { |
| 559 'api': 'webview', | 558 'api': 'webview', |
| 560 'instanceId': self.viewInstanceId_ | 559 'instanceId': self.viewInstanceId_ |
| 561 }; | 560 }; |
| 562 self.browserPluginNode_['-internal-attach'](params); | 561 self.browserPluginNode_['-internal-attach'](params); |
| 563 | 562 |
| 564 var events = self.getEvents_(); | 563 var events = self.getEvents_(); |
| (...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 932 | 931 |
| 933 /** | 932 /** |
| 934 * Implemented when the experimental API is available. | 933 * Implemented when the experimental API is available. |
| 935 * @private | 934 * @private |
| 936 */ | 935 */ |
| 937 WebViewInternal.prototype.maybeAttachWebRequestEventToWebview_ = function() {}; | 936 WebViewInternal.prototype.maybeAttachWebRequestEventToWebview_ = function() {}; |
| 938 | 937 |
| 939 exports.WebView = WebView; | 938 exports.WebView = WebView; |
| 940 exports.WebViewInternal = WebViewInternal; | 939 exports.WebViewInternal = WebViewInternal; |
| 941 exports.CreateEvent = CreateEvent; | 940 exports.CreateEvent = CreateEvent; |
| OLD | NEW |