From 50fedb607a82b11b33cd23bd99094ec6525589c7 Mon Sep 17 00:00:00 2001 From: Mikael Kindborg Date: Wed, 19 Dec 2012 15:18:48 +0100 Subject: [PATCH] Workhole: Fixed bug that causes Wormhole apps that are using WebAppMoblet to crash when using the File API. --- .../JSNativeUI/ResourceMessageHandler.cpp | 3 ++ .../Libs/PhoneGap/PhoneGapMessageHandler.cpp | 3 ++ libs/Wormhole/MessageHandler.cpp | 30 +++++++++++++++++-- 3 files changed, 33 insertions(+), 3 deletions(-) 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()); + } + } } /**