@@ -24,24 +24,8 @@ var remoting = remoting || {};
24
24
* @constructor
25
25
*/
26
26
remoting . ClientPlugin = function ( container , onExtensionMessage ) {
27
- this . plugin_ = /** @type {remoting.ViewerPlugin } */
28
- document . createElement ( 'embed' ) ;
29
-
27
+ this . plugin_ = remoting . ClientPlugin . createPluginElement_ ( ) ;
30
28
this . plugin_ . id = 'session-client-plugin' ;
31
- if ( remoting . settings . CLIENT_PLUGIN_TYPE == 'pnacl' ) {
32
- this . plugin_ . src = 'remoting_client_pnacl.nmf' ;
33
- this . plugin_ . type = 'application/x-pnacl' ;
34
- } else if ( remoting . settings . CLIENT_PLUGIN_TYPE == 'nacl' ) {
35
- this . plugin_ . src = 'remoting_client_nacl.nmf' ;
36
- this . plugin_ . type = 'application/x-nacl' ;
37
- } else {
38
- this . plugin_ . src = 'about://none' ;
39
- this . plugin_ . type = 'application/vnd.chromium.remoting-viewer' ;
40
- }
41
-
42
- this . plugin_ . width = 0 ;
43
- this . plugin_ . height = 0 ;
44
- this . plugin_ . tabIndex = 0 ; // Required, otherwise focus() doesn't work.
45
29
container . appendChild ( this . plugin_ ) ;
46
30
47
31
this . onExtensionMessage_ = onExtensionMessage ;
@@ -115,6 +99,45 @@ remoting.ClientPlugin = function(container, onExtensionMessage) {
115
99
}
116
100
} ;
117
101
102
+ /**
103
+ * Creates plugin element without adding it to a container.
104
+ *
105
+ * @return {remoting.ViewerPlugin } Plugin element
106
+ */
107
+ remoting . ClientPlugin . createPluginElement_ = function ( ) {
108
+ var plugin = /** @type {remoting.ViewerPlugin } */
109
+ document . createElement ( 'embed' ) ;
110
+ if ( remoting . settings . CLIENT_PLUGIN_TYPE == 'pnacl' ) {
111
+ plugin . src = 'remoting_client_pnacl.nmf' ;
112
+ plugin . type = 'application/x-pnacl' ;
113
+ } else if ( remoting . settings . CLIENT_PLUGIN_TYPE == 'nacl' ) {
114
+ plugin . src = 'remoting_client_nacl.nmf' ;
115
+ plugin . type = 'application/x-nacl' ;
116
+ } else {
117
+ plugin . src = 'about://none' ;
118
+ plugin . type = 'application/vnd.chromium.remoting-viewer' ;
119
+ }
120
+ plugin . width = 0 ;
121
+ plugin . height = 0 ;
122
+ plugin . tabIndex = 0 ; // Required, otherwise focus() doesn't work.
123
+ return plugin ;
124
+ }
125
+
126
+ /**
127
+ * Preloads the plugin to make instantiation faster when the user tries
128
+ * to connect.
129
+ */
130
+ remoting . ClientPlugin . preload = function ( ) {
131
+ if ( remoting . settings . CLIENT_PLUGIN_TYPE != 'pnacl' ) {
132
+ return ;
133
+ }
134
+
135
+ var plugin = remoting . ClientPlugin . createPluginElement_ ( ) ;
136
+ plugin . addEventListener (
137
+ 'loadend' , function ( ) { document . body . removeChild ( plugin ) ; } , false ) ;
138
+ document . body . appendChild ( plugin ) ;
139
+ }
140
+
118
141
/**
119
142
* Set of features for which hasFeature() can be used to test.
120
143
*
0 commit comments