diff --git a/libs/Wormhole/Libs/JSNativeUI/ResourceMessageHandler.cpp b/libs/Wormhole/Libs/JSNativeUI/ResourceMessageHandler.cpp index 8908878d0..5ffb2753b 100644 --- a/libs/Wormhole/Libs/JSNativeUI/ResourceMessageHandler.cpp +++ b/libs/Wormhole/Libs/JSNativeUI/ResourceMessageHandler.cpp @@ -46,6 +46,9 @@ namespace Wormhole // A new instance of ImageDownloader is created. mImageDownloader = new ImageDownloader(); mImageDownloader->addDownloadListener(this); + + // Set default FileUtil object. + setFileUtil(new FileUtil()); } /** diff --git a/libs/Wormhole/Libs/PhoneGap/PhoneGapMessageHandler.cpp b/libs/Wormhole/Libs/PhoneGap/PhoneGapMessageHandler.cpp index b61ac2da5..3ccbc7e3d 100644 --- a/libs/Wormhole/Libs/PhoneGap/PhoneGapMessageHandler.cpp +++ b/libs/Wormhole/Libs/PhoneGap/PhoneGapMessageHandler.cpp @@ -54,6 +54,9 @@ namespace Wormhole { mSensorEventToManager[i] = false; } + + // Set default FileUtil object. + setFileUtil(new FileUtil()); } /** diff --git a/libs/Wormhole/MessageHandler.cpp b/libs/Wormhole/MessageHandler.cpp index bd822e42d..1e0880c8f 100644 --- a/libs/Wormhole/MessageHandler.cpp +++ b/libs/Wormhole/MessageHandler.cpp @@ -72,9 +72,33 @@ void MessageHandler::initialize(Wormhole::HybridMoblet* moblet) mNativeUIMessageHandler = new NativeUIMessageHandler(webView); mResourceMessageHandler = new ResourceMessageHandler(webView); - // Set the FileUtil object to use. - mPhoneGapMessageHandler->setFileUtil(moblet->getFileUtil()); - mResourceMessageHandler->setFileUtil(moblet->getFileUtil()); + // Set the FileUtil object to use... + + // For the PhoneGapMessageHandler. + FileUtil* fileUtilPhoneGapHandler = mPhoneGapMessageHandler->getFileUtil(); + if (fileUtilPhoneGapHandler != moblet->getFileUtil()) + { + if (NULL != fileUtilPhoneGapHandler) + { + delete fileUtilPhoneGapHandler; + } + mPhoneGapMessageHandler->setFileUtil(moblet->getFileUtil()); + } + + // For the ResourceMessageHandler. + FileUtil* fileUtilResourceHandler = mResourceMessageHandler->getFileUtil(); + if (fileUtilResourceHandler != moblet->getFileUtil()) + { + if (NULL != fileUtilResourceHandler) + { + // Make sure it is not the same as the PhoneGapMessageHandler has. + if (fileUtilResourceHandler != fileUtilPhoneGapHandler) + { + delete fileUtilResourceHandler; + } + mResourceMessageHandler->setFileUtil(moblet->getFileUtil()); + } + } } /**