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

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: More cleanup 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.attachWindow(detail.windowId);
lazyboy 2014/04/23 20:42:07 nit: probably self.attachWindowAndSetUpEvents() is
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 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
802 attach: function(webview) { 790 attach: function(webview) {
803 validateCall(); 791 validateCall();
804 if (!webview) 792 if (!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() {
812 var attached = 800 var attached = false;
813 browserPluginNode['-internal-attachWindowTo'](webview, 801 var webViewInternal = privates(webview).internal;
814 event.windowId); 802 if (webViewInternal instanceof WebViewInternal) {
803 attached = webViewInternal.attachWindow(event.windowId);
804 }
805
815 if (!attached) { 806 if (!attached) {
816 window.console.error(ERROR_MSG_NEWWINDOW_UNABLE_TO_ATTACH); 807 window.console.error(ERROR_MSG_NEWWINDOW_UNABLE_TO_ATTACH);
817 } 808 }
818 // If the object being passed into attach is not a valid <webview> 809 // 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 810 // 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 811 // was rejected. The permission API plumbing is used here to clean
821 // up the state created for the new window if attaching fails. 812 // up the state created for the new window if attaching fails.
822 WebView.setPermission( 813 WebView.setPermission(
823 self.instanceId, requestId, attached ? 'allow' : 'deny'); 814 self.instanceId, requestId, attached ? 'allow' : 'deny');
824 }, 0); 815 }, 0);
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
1015 WebViewInternal.prototype.setUserAgentOverride = function(userAgentOverride) { 1006 WebViewInternal.prototype.setUserAgentOverride = function(userAgentOverride) {
1016 this.userAgentOverride = userAgentOverride; 1007 this.userAgentOverride = userAgentOverride;
1017 if (!this.instanceId) { 1008 if (!this.instanceId) {
1018 // If we are not attached yet, then we will pick up the user agent on 1009 // If we are not attached yet, then we will pick up the user agent on
1019 // attachment. 1010 // attachment.
1020 return; 1011 return;
1021 } 1012 }
1022 WebView.overrideUserAgent(this.instanceId, userAgentOverride); 1013 WebView.overrideUserAgent(this.instanceId, userAgentOverride);
1023 }; 1014 };
1024 1015
1016 /** @private */
1017 WebViewInternal.prototype.attachWindow = function(instanceId) {
1018 if (this.attached) {
1019 return false;
1020 }
1021 this.attached = true;
1022 this.instanceId = instanceId;
1023 var params = {
1024 'api': 'webview',
1025 'instanceId': this.viewInstanceId
1026 };
1027 if (this.userAgentOverride) {
1028 params['userAgentOverride'] = this.userAgentOverride;
1029 }
1030 this.browserPluginNode['-internal-attach'](this.instanceId, params);
1031
1032 var events = this.getEvents();
1033 for (var eventName in events) {
1034 this.setupEvent(eventName, events[eventName]);
1035 }
1036 return true;
1037 };
1038
1025 // Registers browser plugin <object> custom element. 1039 // Registers browser plugin <object> custom element.
1026 function registerBrowserPluginElement() { 1040 function registerBrowserPluginElement() {
1027 var proto = Object.create(HTMLObjectElement.prototype); 1041 var proto = Object.create(HTMLObjectElement.prototype);
1028 1042
1029 proto.createdCallback = function() { 1043 proto.createdCallback = function() {
1030 this.setAttribute('type', 'application/browser-plugin'); 1044 this.setAttribute('type', 'application/browser-plugin');
1031 // The <object> node fills in the <webview> container. 1045 // The <object> node fills in the <webview> container.
1032 this.style.width = '100%'; 1046 this.style.width = '100%';
1033 this.style.height = '100%'; 1047 this.style.height = '100%';
1034 }; 1048 };
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
1179 1193
1180 /** 1194 /**
1181 * Implemented when the experimental API is available. 1195 * Implemented when the experimental API is available.
1182 * @private 1196 * @private
1183 */ 1197 */
1184 WebViewInternal.prototype.setupExperimentalContextMenus_ = function() {}; 1198 WebViewInternal.prototype.setupExperimentalContextMenus_ = function() {};
1185 1199
1186 exports.WebView = WebView; 1200 exports.WebView = WebView;
1187 exports.WebViewInternal = WebViewInternal; 1201 exports.WebViewInternal = WebViewInternal;
1188 exports.CreateEvent = CreateEvent; 1202 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