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 // This module implements Webview (<webview>) as a custom element that wraps a | 5 // This module implements Webview (<webview>) as a custom element that wraps a |
6 // BrowserPlugin object element. The object element is hidden within | 6 // BrowserPlugin object element. The object element is hidden within |
7 // the shadow DOM of the Webview element. | 7 // the shadow DOM of the Webview element. |
8 | 8 |
9 var DocumentNatives = requireNative('document_natives'); | 9 var DocumentNatives = requireNative('document_natives'); |
10 var EventBindings = require('event_bindings'); | 10 var EventBindings = require('event_bindings'); |
(...skipping 688 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
699 var showWarningMessage = function(dialogType) { | 699 var showWarningMessage = function(dialogType) { |
700 var VOWELS = ['a', 'e', 'i', 'o', 'u']; | 700 var VOWELS = ['a', 'e', 'i', 'o', 'u']; |
701 var WARNING_MSG_DIALOG_BLOCKED = '<webview>: %1 %2 dialog was blocked.'; | 701 var WARNING_MSG_DIALOG_BLOCKED = '<webview>: %1 %2 dialog was blocked.'; |
702 var article = (VOWELS.indexOf(dialogType.charAt(0)) >= 0) ? 'An' : 'A'; | 702 var article = (VOWELS.indexOf(dialogType.charAt(0)) >= 0) ? 'An' : 'A'; |
703 var output = WARNING_MSG_DIALOG_BLOCKED.replace('%1', article); | 703 var output = WARNING_MSG_DIALOG_BLOCKED.replace('%1', article); |
704 output = output.replace('%2', dialogType); | 704 output = output.replace('%2', dialogType); |
705 window.console.warn(output); | 705 window.console.warn(output); |
706 }; | 706 }; |
707 | 707 |
708 var self = this; | 708 var self = this; |
709 var browserPluginNode = this.browserPluginNode; | |
710 var webviewNode = this.webviewNode; | 709 var webviewNode = this.webviewNode; |
711 | |
712 var requestId = event.requestId; | 710 var requestId = event.requestId; |
713 var actionTaken = false; | 711 var actionTaken = false; |
714 | 712 |
715 var validateCall = function() { | 713 var validateCall = function() { |
716 var ERROR_MSG_DIALOG_ACTION_ALREADY_TAKEN = '<webview>: ' + | 714 var ERROR_MSG_DIALOG_ACTION_ALREADY_TAKEN = '<webview>: ' + |
717 'An action has already been taken for this "dialog" event.'; | 715 'An action has already been taken for this "dialog" event.'; |
718 | 716 |
719 if (actionTaken) { | 717 if (actionTaken) { |
720 throw new Error(ERROR_MSG_DIALOG_ACTION_ALREADY_TAKEN); | 718 throw new Error(ERROR_MSG_DIALOG_ACTION_ALREADY_TAKEN); |
721 } | 719 } |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
816 'Unable to attach the new window to the provided webview.'; | 814 'Unable to attach the new window to the provided webview.'; |
817 | 815 |
818 var ERROR_MSG_WEBVIEW_EXPECTED = '<webview> element expected.'; | 816 var ERROR_MSG_WEBVIEW_EXPECTED = '<webview> element expected.'; |
819 | 817 |
820 var showWarningMessage = function() { | 818 var showWarningMessage = function() { |
821 var WARNING_MSG_NEWWINDOW_BLOCKED = '<webview>: A new window was blocked.'; | 819 var WARNING_MSG_NEWWINDOW_BLOCKED = '<webview>: A new window was blocked.'; |
822 window.console.warn(WARNING_MSG_NEWWINDOW_BLOCKED); | 820 window.console.warn(WARNING_MSG_NEWWINDOW_BLOCKED); |
823 }; | 821 }; |
824 | 822 |
825 var self = this; | 823 var self = this; |
826 var browserPluginNode = this.browserPluginNode; | |
827 var webviewNode = this.webviewNode; | 824 var webviewNode = this.webviewNode; |
828 | 825 |
829 var requestId = event.requestId; | 826 var requestId = event.requestId; |
830 var actionTaken = false; | 827 var actionTaken = false; |
831 | 828 |
832 var validateCall = function () { | 829 var validateCall = function () { |
833 if (actionTaken) { | 830 if (actionTaken) { |
834 throw new Error(ERROR_MSG_NEWWINDOW_ACTION_ALREADY_TAKEN); | 831 throw new Error(ERROR_MSG_NEWWINDOW_ACTION_ALREADY_TAKEN); |
835 } | 832 } |
836 actionTaken = true; | 833 actionTaken = true; |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
922 WebView.setPermission( | 919 WebView.setPermission( |
923 self.instanceId, requestId, 'default', '', function(allowed) { | 920 self.instanceId, requestId, 'default', '', function(allowed) { |
924 if (allowed) { | 921 if (allowed) { |
925 return; | 922 return; |
926 } | 923 } |
927 showWarningMessage(event.permission); | 924 showWarningMessage(event.permission); |
928 }); | 925 }); |
929 return; | 926 return; |
930 } | 927 } |
931 | 928 |
932 var browserPluginNode = this.browserPluginNode; | |
933 var webviewNode = this.webviewNode; | 929 var webviewNode = this.webviewNode; |
934 | |
935 var decisionMade = false; | 930 var decisionMade = false; |
936 | 931 |
937 var validateCall = function() { | 932 var validateCall = function() { |
938 if (decisionMade) { | 933 if (decisionMade) { |
939 throw new Error(ERROR_MSG_PERMISSION_ALREADY_DECIDED); | 934 throw new Error(ERROR_MSG_PERMISSION_ALREADY_DECIDED); |
940 } | 935 } |
941 decisionMade = true; | 936 decisionMade = true; |
942 }; | 937 }; |
943 | 938 |
944 // Construct the event.request object. | 939 // Construct the event.request object. |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1071 }; | 1066 }; |
1072 if (this.userAgentOverride) { | 1067 if (this.userAgentOverride) { |
1073 params['userAgentOverride'] = this.userAgentOverride; | 1068 params['userAgentOverride'] = this.userAgentOverride; |
1074 } | 1069 } |
1075 this.setupNameAttribute(); | 1070 this.setupNameAttribute(); |
1076 var events = this.getEvents(); | 1071 var events = this.getEvents(); |
1077 for (var eventName in events) { | 1072 for (var eventName in events) { |
1078 this.setupEvent(eventName, events[eventName]); | 1073 this.setupEvent(eventName, events[eventName]); |
1079 } | 1074 } |
1080 | 1075 |
1081 this.browserPluginNode['-internal-attach'](this.instanceId, params); | 1076 return this.browserPluginNode['-internal-attach'](this.instanceId, params); |
1082 | |
1083 return true; | |
1084 }; | 1077 }; |
1085 | 1078 |
1086 // Registers browser plugin <object> custom element. | 1079 // Registers browser plugin <object> custom element. |
1087 function registerBrowserPluginElement() { | 1080 function registerBrowserPluginElement() { |
1088 var proto = Object.create(HTMLObjectElement.prototype); | 1081 var proto = Object.create(HTMLObjectElement.prototype); |
1089 | 1082 |
1090 proto.createdCallback = function() { | 1083 proto.createdCallback = function() { |
1091 this.setAttribute('type', 'application/browser-plugin'); | 1084 this.setAttribute('type', 'application/browser-plugin'); |
1092 // The <object> node fills in the <webview> container. | 1085 // The <object> node fills in the <webview> container. |
1093 this.style.width = '100%'; | 1086 this.style.width = '100%'; |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1255 | 1248 |
1256 /** | 1249 /** |
1257 * Implemented when the experimental API is available. | 1250 * Implemented when the experimental API is available. |
1258 * @private | 1251 * @private |
1259 */ | 1252 */ |
1260 WebViewInternal.prototype.setupExperimentalContextMenus_ = function() {}; | 1253 WebViewInternal.prototype.setupExperimentalContextMenus_ = function() {}; |
1261 | 1254 |
1262 exports.WebView = WebView; | 1255 exports.WebView = WebView; |
1263 exports.WebViewInternal = WebViewInternal; | 1256 exports.WebViewInternal = WebViewInternal; |
1264 exports.CreateEvent = CreateEvent; | 1257 exports.CreateEvent = CreateEvent; |
OLD | NEW |