diff options
author | dmichael <dmichael@chromium.org> | 2014-09-24 08:41:14 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-09-24 15:41:34 +0000 |
commit | 44b96754c1e11929fd7d1dc8ed36880d80476372 (patch) | |
tree | e44776e6ca178c3b5f37dbcc24998dad9a193559 /ppapi/proxy | |
parent | 7bf0d74a828bed0730daa361fd25603535136c0d (diff) | |
download | chromium_src-44b96754c1e11929fd7d1dc8ed36880d80476372.zip chromium_src-44b96754c1e11929fd7d1dc8ed36880d80476372.tar.gz chromium_src-44b96754c1e11929fd7d1dc8ed36880d80476372.tar.bz2 |
PPAPI: Disallow blocking callbacks while handling a blocking message
This makes it so that the plugin can not use blocking completion callbacks while servicing HandleBlockingMessage. This is to discourage leaving JavaScript hung while doing long-running things (e.g. file IO).
(Of course, the plugin can get around this by bouncing to another thread; but I think this adds a useful guideline/deterrent.)
BUG=415351
Review URL: https://codereview.chromium.org/600553002
Cr-Commit-Position: refs/heads/master@{#296422}
Diffstat (limited to 'ppapi/proxy')
-rw-r--r-- | ppapi/proxy/message_handler.cc | 8 | ||||
-rw-r--r-- | ppapi/proxy/ppb_message_loop_proxy.cc | 10 | ||||
-rw-r--r-- | ppapi/proxy/ppb_message_loop_proxy.h | 10 |
3 files changed, 25 insertions, 3 deletions
diff --git a/ppapi/proxy/message_handler.cc b/ppapi/proxy/message_handler.cc index e095dd7..a0f5ccc 100644 --- a/ppapi/proxy/message_handler.cc +++ b/ppapi/proxy/message_handler.cc @@ -39,8 +39,12 @@ void HandleBlockingMessageWrapper(HandleBlockingMessageFunc function, if (!dispatcher) return; PP_Var result = PP_MakeUndefined(); + MessageLoopResource::GetCurrent()-> + set_currently_handling_blocking_message(true); CallWhileUnlocked( function, instance, user_data, &message_data.get(), &result); + MessageLoopResource::GetCurrent()-> + set_currently_handling_blocking_message(false); PpapiMsg_PPPMessageHandler_HandleBlockingMessage::WriteReplyParams( reply_msg.get(), SerializedVarReturnValue::Convert(dispatcher, result), @@ -64,10 +68,14 @@ void HandleBlockingMessageWrapper_0_1(HandleBlockingMessageFunc_0_1 function, PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); if (!dispatcher) return; + MessageLoopResource::GetCurrent()-> + set_currently_handling_blocking_message(true); PP_Var return_value = CallWhileUnlocked(function, instance, user_data, message_data.get()); + MessageLoopResource::GetCurrent()-> + set_currently_handling_blocking_message(false); PpapiMsg_PPPMessageHandler_HandleBlockingMessage::WriteReplyParams( reply_msg.get(), SerializedVarReturnValue::Convert(dispatcher, return_value), diff --git a/ppapi/proxy/ppb_message_loop_proxy.cc b/ppapi/proxy/ppb_message_loop_proxy.cc index 2bc9694..555c008 100644 --- a/ppapi/proxy/ppb_message_loop_proxy.cc +++ b/ppapi/proxy/ppb_message_loop_proxy.cc @@ -31,7 +31,8 @@ MessageLoopResource::MessageLoopResource(PP_Instance instance) nested_invocations_(0), destroyed_(false), should_destroy_(false), - is_main_thread_loop_(false) { + is_main_thread_loop_(false), + currently_handling_blocking_message_(false) { } MessageLoopResource::MessageLoopResource(ForMainThread for_main_thread) @@ -39,7 +40,8 @@ MessageLoopResource::MessageLoopResource(ForMainThread for_main_thread) nested_invocations_(0), destroyed_(false), should_destroy_(false), - is_main_thread_loop_(true) { + is_main_thread_loop_(true), + currently_handling_blocking_message_(false) { // We attach the main thread immediately. We can't use AttachToCurrentThread, // because the MessageLoop already exists. @@ -193,6 +195,10 @@ base::MessageLoopProxy* MessageLoopResource::GetMessageLoopProxy() { return loop_proxy_.get(); } +bool MessageLoopResource::CurrentlyHandlingBlockingMessage() { + return currently_handling_blocking_message_; +} + // static void MessageLoopResource::ReleaseMessageLoop(void* value) { static_cast<MessageLoopResource*>(value)->DetachFromThread(); diff --git a/ppapi/proxy/ppb_message_loop_proxy.h b/ppapi/proxy/ppb_message_loop_proxy.h index f6cc252..20569f7 100644 --- a/ppapi/proxy/ppb_message_loop_proxy.h +++ b/ppapi/proxy/ppb_message_loop_proxy.h @@ -48,6 +48,10 @@ class PPAPI_PROXY_EXPORT MessageLoopResource : public MessageLoopShared { return loop_proxy_; } + void set_currently_handling_blocking_message(bool handling_blocking_message) { + currently_handling_blocking_message_ = handling_blocking_message; + } + private: struct TaskInfo { tracked_objects::Location from_here; @@ -58,6 +62,8 @@ class PPAPI_PROXY_EXPORT MessageLoopResource : public MessageLoopShared { // Returns true if the object is associated with the current thread. bool IsCurrent() const; + // MessageLoopShared implementation. + // // Handles posting to the message loop if there is one, or the pending queue // if there isn't. // NOTE: The given closure will be run *WITHOUT* acquiring the Proxy lock. @@ -66,8 +72,8 @@ class PPAPI_PROXY_EXPORT MessageLoopResource : public MessageLoopShared { virtual void PostClosure(const tracked_objects::Location& from_here, const base::Closure& closure, int64 delay_ms) OVERRIDE; - virtual base::MessageLoopProxy* GetMessageLoopProxy() OVERRIDE; + virtual bool CurrentlyHandlingBlockingMessage() OVERRIDE; // TLS destructor function. static void ReleaseMessageLoop(void* value); @@ -92,6 +98,8 @@ class PPAPI_PROXY_EXPORT MessageLoopResource : public MessageLoopShared { bool is_main_thread_loop_; + bool currently_handling_blocking_message_; + // Since we allow tasks to be posted before the message loop is actually // created (when it's associated with a thread), we keep tasks posted here // until that happens. Once the loop_ is created, this is unused. |