Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / ppapi / thunk / enter.cc
index 03937c9..a98a3ec 100644 (file)
@@ -23,6 +23,12 @@ bool IsMainThread() {
       PpapiGlobals::Get()->GetMainThreadMessageLoop()->BelongsToCurrentThread();
 }
 
+bool CurrentThreadHandlingBlockingMessage() {
+  ppapi::MessageLoopShared* current =
+      PpapiGlobals::Get()->GetCurrentMessageLoop();
+  return current && current->CurrentlyHandlingBlockingMessage();
+}
+
 }  // namespace
 
 namespace thunk {
@@ -141,6 +147,18 @@ void EnterBase::SetStateForCallbackError(bool report_error) {
         PpapiGlobals::Get()->BroadcastLogWithSource(0, PP_LOGLEVEL_ERROR,
                                                     std::string(), message);
       }
+    } else if (callback_->is_blocking() &&
+               CurrentThreadHandlingBlockingMessage()) {
+      // Blocking callbacks are not allowed while handling a blocking message.
+      callback_->MarkAsCompleted();
+      callback_ = NULL;
+      retval_ = PP_ERROR_WOULD_BLOCK_THREAD;
+      if (report_error) {
+        std::string message("Blocking callbacks are not allowed while handling "
+                            "a blocking message from JavaScript.");
+        PpapiGlobals::Get()->BroadcastLogWithSource(0, PP_LOGLEVEL_ERROR,
+                                                    std::string(), message);
+      }
     } else if (!IsMainThread() &&
                callback_->has_null_target_loop() &&
                !callback_->is_blocking()) {