Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(59)

Side by Side Diff: chrome/renderer/resources/extensions/web_view.js

Issue 250063002: Browser Plugin: Simplified guest attachment (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed New Window API test Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | content/renderer/browser_plugin/browser_plugin.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 158
159 // Implemented when the experimental API is available. 159 // Implemented when the experimental API is available.
160 WebViewInternal.maybeRegisterExperimentalAPIs = function(proto) {} 160 WebViewInternal.maybeRegisterExperimentalAPIs = function(proto) {}
161 161
162 /** 162 /**
163 * @constructor 163 * @constructor
164 */ 164 */
165 function WebViewInternal(webviewNode) { 165 function WebViewInternal(webviewNode) {
166 privates(webviewNode).internal = this; 166 privates(webviewNode).internal = this;
167 this.webviewNode = webviewNode; 167 this.webviewNode = webviewNode;
168 this.attached = false;
168 this.browserPluginNode = this.createBrowserPluginNode(); 169 this.browserPluginNode = this.createBrowserPluginNode();
169 var shadowRoot = this.webviewNode.createShadowRoot(); 170 var shadowRoot = this.webviewNode.createShadowRoot();
170 shadowRoot.appendChild(this.browserPluginNode); 171 shadowRoot.appendChild(this.browserPluginNode);
171 172
172 this.setupWebviewNodeAttributes(); 173 this.setupWebviewNodeAttributes();
173 this.setupFocusPropagation(); 174 this.setupFocusPropagation();
174 this.setupWebviewNodeProperties(); 175 this.setupWebviewNodeProperties();
175 this.setupWebviewNodeEvents(); 176 this.setupWebviewNodeEvents();
176 } 177 }
177 178
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after
562 }; 563 };
563 564
564 /** 565 /**
565 * @private 566 * @private
566 */ 567 */
567 WebViewInternal.prototype.setupWebviewNodeEvents = function() { 568 WebViewInternal.prototype.setupWebviewNodeEvents = function() {
568 var self = this; 569 var self = this;
569 this.viewInstanceId = IdGenerator.GetNextId(); 570 this.viewInstanceId = IdGenerator.GetNextId();
570 var onInstanceIdAllocated = function(e) { 571 var onInstanceIdAllocated = function(e) {
571 var detail = e.detail ? JSON.parse(e.detail) : {}; 572 var detail = e.detail ? JSON.parse(e.detail) : {};
572 self.instanceId = detail.windowId; 573 self.attachWindowAndSetUpEvents(detail.windowId);
573 var params = {
574 'api': 'webview',
575 'instanceId': self.viewInstanceId
576 };
577 if (self.userAgentOverride) {
578 params['userAgentOverride'] = self.userAgentOverride;
579 }
580 self.browserPluginNode['-internal-attach'](params);
581
582 var events = self.getEvents();
583 for (var eventName in events) {
584 self.setupEvent(eventName, events[eventName]);
585 }
586 }; 574 };
587 this.browserPluginNode.addEventListener('-internal-instanceid-allocated', 575 this.browserPluginNode.addEventListener('-internal-instanceid-allocated',
588 onInstanceIdAllocated); 576 onInstanceIdAllocated);
589 this.setupWebRequestEvents(); 577 this.setupWebRequestEvents();
590 this.setupExperimentalContextMenus_(); 578 this.setupExperimentalContextMenus_();
591 579
592 this.on = {}; 580 this.on = {};
593 var events = self.getEvents(); 581 var events = self.getEvents();
594 for (var eventName in events) { 582 for (var eventName in events) {
595 this.setupEventProperty(eventName); 583 this.setupEventProperty(eventName);
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
794 var validateCall = function () { 782 var validateCall = function () {
795 if (actionTaken) { 783 if (actionTaken) {
796 throw new Error(ERROR_MSG_NEWWINDOW_ACTION_ALREADY_TAKEN); 784 throw new Error(ERROR_MSG_NEWWINDOW_ACTION_ALREADY_TAKEN);
797 } 785 }
798 actionTaken = true; 786 actionTaken = true;
799 }; 787 };
800 788
801 var windowObj = { 789 var windowObj = {
802 attach: function(webview) { 790 attach: function(webview) {
803 validateCall(); 791 validateCall();
804 if (!webview) 792 if (!webview || !webview.tagName || webview.tagName != 'WEBVIEW')
805 throw new Error(ERROR_MSG_WEBVIEW_EXPECTED); 793 throw new Error(ERROR_MSG_WEBVIEW_EXPECTED);
806 // Attach happens asynchronously to give the tagWatcher an opportunity 794 // Attach happens asynchronously to give the tagWatcher an opportunity
807 // to pick up the new webview before attach operates on it, if it hasn't 795 // to pick up the new webview before attach operates on it, if it hasn't
808 // been attached to the DOM already. 796 // been attached to the DOM already.
809 // Note: Any subsequent errors cannot be exceptions because they happen 797 // Note: Any subsequent errors cannot be exceptions because they happen
810 // asynchronously. 798 // asynchronously.
811 setTimeout(function() { 799 setTimeout(function() {
800 var webViewInternal = privates(webview).internal;
812 var attached = 801 var attached =
813 browserPluginNode['-internal-attachWindowTo'](webview, 802 webViewInternal.attachWindowAndSetUpEvents(event.windowId);
814 event.windowId); 803
815 if (!attached) { 804 if (!attached) {
816 window.console.error(ERROR_MSG_NEWWINDOW_UNABLE_TO_ATTACH); 805 window.console.error(ERROR_MSG_NEWWINDOW_UNABLE_TO_ATTACH);
817 } 806 }
818 // If the object being passed into attach is not a valid <webview> 807 // If the object being passed into attach is not a valid <webview>
819 // then we will fail and it will be treated as if the new window 808 // then we will fail and it will be treated as if the new window
820 // was rejected. The permission API plumbing is used here to clean 809 // was rejected. The permission API plumbing is used here to clean
821 // up the state created for the new window if attaching fails. 810 // up the state created for the new window if attaching fails.
822 WebView.setPermission( 811 WebView.setPermission(
823 self.instanceId, requestId, attached ? 'allow' : 'deny'); 812 self.instanceId, requestId, attached ? 'allow' : 'deny');
824 }, 0); 813 }, 0);
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
1015 WebViewInternal.prototype.setUserAgentOverride = function(userAgentOverride) { 1004 WebViewInternal.prototype.setUserAgentOverride = function(userAgentOverride) {
1016 this.userAgentOverride = userAgentOverride; 1005 this.userAgentOverride = userAgentOverride;
1017 if (!this.instanceId) { 1006 if (!this.instanceId) {
1018 // If we are not attached yet, then we will pick up the user agent on 1007 // If we are not attached yet, then we will pick up the user agent on
1019 // attachment. 1008 // attachment.
1020 return; 1009 return;
1021 } 1010 }
1022 WebView.overrideUserAgent(this.instanceId, userAgentOverride); 1011 WebView.overrideUserAgent(this.instanceId, userAgentOverride);
1023 }; 1012 };
1024 1013
1014 /** @private */
1015 WebViewInternal.prototype.attachWindowAndSetUpEvents = function(instanceId) {
1016 this.instanceId = instanceId;
1017 var params = {
1018 'api': 'webview',
1019 'instanceId': this.viewInstanceId
1020 };
1021 if (this.userAgentOverride) {
1022 params['userAgentOverride'] = this.userAgentOverride;
1023 }
1024 this.browserPluginNode['-internal-attach'](this.instanceId, params);
1025
1026 var events = this.getEvents();
1027 for (var eventName in events) {
1028 this.setupEvent(eventName, events[eventName]);
1029 }
1030 return true;
1031 };
1032
1025 // Registers browser plugin <object> custom element. 1033 // Registers browser plugin <object> custom element.
1026 function registerBrowserPluginElement() { 1034 function registerBrowserPluginElement() {
1027 var proto = Object.create(HTMLObjectElement.prototype); 1035 var proto = Object.create(HTMLObjectElement.prototype);
1028 1036
1029 proto.createdCallback = function() { 1037 proto.createdCallback = function() {
1030 this.setAttribute('type', 'application/browser-plugin'); 1038 this.setAttribute('type', 'application/browser-plugin');
1031 // The <object> node fills in the <webview> container. 1039 // The <object> node fills in the <webview> container.
1032 this.style.width = '100%'; 1040 this.style.width = '100%';
1033 this.style.height = '100%'; 1041 this.style.height = '100%';
1034 }; 1042 };
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
1179 1187
1180 /** 1188 /**
1181 * Implemented when the experimental API is available. 1189 * Implemented when the experimental API is available.
1182 * @private 1190 * @private
1183 */ 1191 */
1184 WebViewInternal.prototype.setupExperimentalContextMenus_ = function() {}; 1192 WebViewInternal.prototype.setupExperimentalContextMenus_ = function() {};
1185 1193
1186 exports.WebView = WebView; 1194 exports.WebView = WebView;
1187 exports.WebViewInternal = WebViewInternal; 1195 exports.WebViewInternal = WebViewInternal;
1188 exports.CreateEvent = CreateEvent; 1196 exports.CreateEvent = CreateEvent;
OLDNEW
« no previous file with comments | « no previous file | content/renderer/browser_plugin/browser_plugin.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698