diff options
author | ananta@chromium.org <ananta@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-27 16:21:25 +0000 |
---|---|---|
committer | ananta@chromium.org <ananta@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-27 16:21:25 +0000 |
commit | 24e863243cc6e12da33425f8401f0920170d7062 (patch) | |
tree | 670fc34a9eb817605eb6bca3fda7f46fc811f43d /webkit/glue/plugins/test/plugin_windowless_test.cc | |
parent | 014664d1a84c416cc67a91a9338ad08e3179050d (diff) | |
download | chromium_src-24e863243cc6e12da33425f8401f0920170d7062.zip chromium_src-24e863243cc6e12da33425f8401f0920170d7062.tar.gz chromium_src-24e863243cc6e12da33425f8401f0920170d7062.tar.bz2 |
We need to set the clipping region of the HDC passed in to a windowless flash plugin instance in NPP_HandleEvent for WM_PAINT. The windowless flash plugin instance queries the clipping region of the DC and on not finding it proceeds
to paint the plugin window rect, which causes unnecessary CPU spikes.
This fixes bug http://code.google.com/p/chromium/issues/detail?id=8835, where the plugin process would consume CPU even when we scrolled down to the static video images.
With this fix the CPU usage for windowless flash plugins is on par with Firefox.
Added a uitest which validates whether the hdc passed in to HandleEvent for WM_PAINT has a valid clipping region.
Bug=8835
Review URL: http://codereview.chromium.org/53106
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@12651 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/glue/plugins/test/plugin_windowless_test.cc')
-rw-r--r-- | webkit/glue/plugins/test/plugin_windowless_test.cc | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/webkit/glue/plugins/test/plugin_windowless_test.cc b/webkit/glue/plugins/test/plugin_windowless_test.cc new file mode 100644 index 0000000..131102c --- /dev/null +++ b/webkit/glue/plugins/test/plugin_windowless_test.cc @@ -0,0 +1,75 @@ +// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#define STRSAFE_NO_DEPRECATE +#include "webkit/glue/plugins/test/plugin_windowless_test.h" +#include "webkit/glue/plugins/test/plugin_client.h" + +namespace NPAPIClient { + +WindowlessPluginTest::WindowlessPluginTest( + NPP id, NPNetscapeFuncs *host_functions, const std::string& test_name) + : PluginTest(id, host_functions), + test_name_(test_name) { +} + +int16 WindowlessPluginTest::HandleEvent(void* event) { + + NPNetscapeFuncs* browser = NPAPIClient::PluginClient::HostFunctions(); + + NPBool supports_windowless = 0; + NPError result = browser->getvalue(id(), NPNVSupportsWindowless, + &supports_windowless); + if ((result != NPERR_NO_ERROR) || (supports_windowless != TRUE)) { + SetError("Failed to read NPNVSupportsWindowless value"); + SignalTestCompleted(); + return PluginTest::HandleEvent(event); + } + + NPEvent* np_event = reinterpret_cast<NPEvent*>(event); + if (WM_PAINT == np_event->event && + base::strcasecmp(test_name_.c_str(), + "execute_script_delete_in_paint") == 0) { + HDC paint_dc = reinterpret_cast<HDC>(np_event->wParam); + if (paint_dc == NULL) { + SetError("Invalid Window DC passed to HandleEvent for WM_PAINT"); + SignalTestCompleted(); + return NPERR_GENERIC_ERROR; + } + + HRGN clipping_region = CreateRectRgn(0, 0, 0, 0); + if (!GetClipRgn(paint_dc, clipping_region)) { + SetError("No clipping region set in window DC"); + DeleteObject(clipping_region); + SignalTestCompleted(); + return NPERR_GENERIC_ERROR; + } + + DeleteObject(clipping_region); + + NPUTF8* urlString = "javascript:DeletePluginWithinScript()"; + NPUTF8* targetString = NULL; + browser->geturl(id(), urlString, targetString); + SignalTestCompleted(); + } else if (WM_MOUSEMOVE == np_event->event && + base::strcasecmp(test_name_.c_str(), + "execute_script_delete_in_mouse_move") == 0) { + std::string script = "javascript:DeletePluginWithinScript()"; + NPString script_string; + script_string.UTF8Characters = script.c_str(); + script_string.UTF8Length = + static_cast<unsigned int>(script.length()); + + NPObject *window_obj = NULL; + browser->getvalue(id(), NPNVWindowNPObject, &window_obj); + NPVariant result_var; + NPError result = browser->evaluate(id(), window_obj, + &script_string, &result_var); + SignalTestCompleted(); + } + // If this test failed, then we'd have crashed by now. + return PluginTest::HandleEvent(event); +} + +} // namespace NPAPIClient |