diff options
author | esprehn <esprehn@chromium.org> | 2015-11-17 09:21:49 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-11-17 17:22:54 +0000 |
commit | 3bc8afec55e9cd046b110729f08e7605e6ffbb61 (patch) | |
tree | 33cdc74cf2c7d8442f6ec0070fbfcd3301d39dee /components/nacl/renderer | |
parent | b719a217a59368264de9e4a471eb906435df4611 (diff) | |
download | chromium_src-3bc8afec55e9cd046b110729f08e7605e6ffbb61.zip chromium_src-3bc8afec55e9cd046b110729f08e7605e6ffbb61.tar.gz chromium_src-3bc8afec55e9cd046b110729f08e7605e6ffbb61.tar.bz2 |
Simplify PPAPI progress event logic and move it into Blink.
There's no reason to put a v8::Context on the stack to dispatch an event, this
seems to date way back to when this code was first added because the early patches
(which were never landed) added an expando "url" property [1] [2] to the JS
ProgressEvent object. That code was never landed though, and instead the
DOMResourceProgresssEvent object was added, but the v8 logic was left behind.
This patch removes this unnecessary code and moves the logic for deciding which
event should be dispatched into the WebPluginContainer object. This allows
removing the non-standard WebDOMResourceProgressEvent interface from the public
API and generally simplifying the code.
[1] https://codereview.chromium.org/14588009/diff/2001/chrome/renderer/nacl/ppb_nacl_private_impl.cc
[2] https://chromiumcodereview.appspot.com/14773025
Review URL: https://codereview.chromium.org/1447853002
Cr-Commit-Position: refs/heads/master@{#360101}
Diffstat (limited to 'components/nacl/renderer')
-rw-r--r-- | components/nacl/renderer/progress_event.cc | 69 |
1 files changed, 22 insertions, 47 deletions
diff --git a/components/nacl/renderer/progress_event.cc b/components/nacl/renderer/progress_event.cc index ae30755..6bd5571 100644 --- a/components/nacl/renderer/progress_event.cc +++ b/components/nacl/renderer/progress_event.cc @@ -6,88 +6,63 @@ #include "base/bind.h" #include "base/location.h" -#include "base/logging.h" #include "components/nacl/renderer/ppb_nacl_private.h" #include "content/public/renderer/pepper_plugin_instance.h" #include "ppapi/shared_impl/ppapi_globals.h" #include "third_party/WebKit/public/platform/WebString.h" -#include "third_party/WebKit/public/web/WebDOMResourceProgressEvent.h" -#include "third_party/WebKit/public/web/WebDocument.h" -#include "third_party/WebKit/public/web/WebElement.h" -#include "third_party/WebKit/public/web/WebLocalFrame.h" #include "third_party/WebKit/public/web/WebPluginContainer.h" -#include "v8/include/v8.h" + +using blink::WebString; +using blink::WebPluginContainer; namespace nacl { namespace { -blink::WebString EventTypeToString(PP_NaClEventType event_type) { +const char* EventTypeToName(PP_NaClEventType event_type) { switch (event_type) { case PP_NACL_EVENT_LOADSTART: - return blink::WebString::fromUTF8("loadstart"); + return "loadstart"; case PP_NACL_EVENT_PROGRESS: - return blink::WebString::fromUTF8("progress"); + return "progress"; case PP_NACL_EVENT_ERROR: - return blink::WebString::fromUTF8("error"); + return "error"; case PP_NACL_EVENT_ABORT: - return blink::WebString::fromUTF8("abort"); + return "abort"; case PP_NACL_EVENT_LOAD: - return blink::WebString::fromUTF8("load"); + return "load"; case PP_NACL_EVENT_LOADEND: - return blink::WebString::fromUTF8("loadend"); + return "loadend"; case PP_NACL_EVENT_CRASH: - return blink::WebString::fromUTF8("crash"); + return "crash"; } - NOTIMPLEMENTED(); - return blink::WebString(); + NOTREACHED(); + return ""; } void DispatchProgressEventOnMainThread(PP_Instance instance, - const ProgressEvent &event) { + const ProgressEvent& event) { content::PepperPluginInstance* plugin_instance = content::PepperPluginInstance::Get(instance); if (!plugin_instance) return; - blink::WebPluginContainer* container = plugin_instance->GetContainer(); + WebPluginContainer* container = plugin_instance->GetContainer(); // It's possible that container() is NULL if the plugin has been removed from // the DOM (but the PluginInstance is not destroyed yet). if (!container) return; - blink::WebLocalFrame* frame = container->element().document().frame(); - if (!frame) - return; - v8::HandleScope handle_scope(plugin_instance->GetIsolate()); - v8::Local<v8::Context> context( - plugin_instance->GetIsolate()->GetCurrentContext()); - if (context.IsEmpty()) { - // If there's no JavaScript on the stack, we have to make a new Context. - context = v8::Context::New(plugin_instance->GetIsolate()); - } - v8::Context::Scope context_scope(context); - if (!event.resource_url.empty()) { - blink::WebString url_string = blink::WebString::fromUTF8( - event.resource_url.data(), event.resource_url.size()); - blink::WebDOMResourceProgressEvent blink_event( - EventTypeToString(event.event_type), - event.length_is_computable, - event.loaded_bytes, - event.total_bytes, - url_string); - container->element().dispatchEvent(blink_event); - } else { - blink::WebDOMProgressEvent blink_event(EventTypeToString(event.event_type), - event.length_is_computable, - event.loaded_bytes, - event.total_bytes); - container->element().dispatchEvent(blink_event); - } + container->dispatchProgressEvent( + WebString::fromUTF8(EventTypeToName(event.event_type)), + event.length_is_computable, + event.loaded_bytes, + event.total_bytes, + WebString::fromUTF8(event.resource_url)); } } // namespace -void DispatchProgressEvent(PP_Instance instance, const ProgressEvent &event) { +void DispatchProgressEvent(PP_Instance instance, const ProgressEvent& event) { ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask( FROM_HERE, base::Bind(&DispatchProgressEventOnMainThread, instance, event)); |