11package ru.mail.communication
22{
33import flash.external.ExternalInterface ;
4+ import flash.utils.ByteArray ;
45
56import ru.mail.data.vo.ErrorVO ;
67import ru.mail.data.vo.FileVO ;
@@ -67,7 +68,6 @@ package ru.mail.communication
6768_call (_callback , data , data2);
6869}
6970catch (e: Error ) {
70- trace ("callJS caused an exception" , e);
7171}
7272}
7373
@@ -82,12 +82,10 @@ package ru.mail.communication
8282var isReady: Boolean = false ;
8383try {
8484var r:* = _call (callback, {type : "ready" , flashId: flashId});
85- trace ( "JSCaller.notifyJSAboutAppReady() " , triesCount );
8685
8786isReady = ( r != null );
8887}
8988catch ( e: Error ) {
90- trace ("notifyJSAboutAppReady error" , e);
9189}
9290
9391return isReady;
@@ -111,7 +109,6 @@ package ru.mail.communication
111109_call (callback, { type : eventType , flashId: flashId });
112110}
113111catch (e: Error ) {
114- trace ("notifyJSMouseEvents error" , e);
115112}
116113}
117114
@@ -126,8 +123,6 @@ package ru.mail.communication
126123 */
127124public function notifyJSFilesEvents (eventType :String , filesVector :Vector .<FileVO> = null ):void
128125{
129- trace ("{JSCaller} - notifyJSFilesEvents, eventType" , eventType )
130-
131126var details: Object = new Object ();
132127details. type = eventType ;
133128
@@ -164,7 +159,6 @@ package ru.mail.communication
164159_call (callback, details);
165160}
166161catch (e: Error ) {
167- trace ("notifyJSFilesEvents error" ,e);
168162}
169163}
170164
@@ -189,7 +183,6 @@ package ru.mail.communication
189183_call (callback, details);
190184}
191185catch (e: Error ) {
192- trace ("notifyJSErrors error" ,e);
193186}
194187}
195188
@@ -204,7 +197,6 @@ package ru.mail.communication
204197_call (callback, { type : 'camera' , error : error , flashId: flashId });
205198}
206199catch (e: Error ) {
207- trace ("notifyCameraStatus error" , e);
208200}
209201}
210202
@@ -222,13 +214,34 @@ package ru.mail.communication
222214_call (callback, {type : "error" , message : errorVO. getError(), flashId: flashId});
223215}
224216catch (e: Error ) {
225- trace ("notifyJSErrors error" ,e);
226217}
227218}
228-
219+
220+ private function clone (source :Object ):* {
221+ var myBA: ByteArray = new ByteArray ();
222+ myBA. writeObject (source );
223+ myBA. position = 0 ;
224+ return (myBA. readObject ());
225+ }
226+
227+ private function _escape (data :* ):* {
228+ if (typeof data === 'string' ) {
229+ return data . replace (/ \\ / g , '\\\\ ' );
230+ } else if (typeof data === 'object' ) {
231+ var ret:* = clone (data );
232+ for (var i: String in data ) {
233+ ret[ i] = _escape (data [ i] );
234+ }
235+ return ret;
236+ }
237+ return data ;
238+ }
239+
229240private function _call (callback :String , data :Object , data2 :Object = null ):* {
241+ data = _escape (data );
230242if ( callback. match (/ ^FileAPI\. Flash\. (onEvent|_fn\. fileapi\d +)$/ ) ) {
231243if (data2) {
244+ data2 = _escape (data2);
232245return ExternalInterface . call (callback, data , data2);
233246}
234247else {
@@ -240,4 +253,4 @@ package ru.mail.communication
240253}
241254}
242255}
243- }
256+ }
0 commit comments