Commit 1f870d56 authored by jam@chromium.org's avatar jam@chromium.org

Fix windowed plugins not appearing if opened in the background until the browser resizes.

BUG=335900
R=ben@chromium.org

Review URL: https://codereview.chromium.org/150073002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@247881 0039d316-1c4b-4281-b951-d872f2087c98
parent b2a556b9
......@@ -10,17 +10,21 @@
#include "base/file_util.h"
#include "base/memory/ref_counted.h"
#include "base/path_service.h"
#include "base/prefs/pref_service.h"
#include "base/process/kill.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/plugins/plugin_prefs.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
#include "content/public/browser/browser_child_process_host_iterator.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/child_process_data.h"
#include "content/public/browser/plugin_service.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/content_constants.h"
#include "content/public/common/content_paths.h"
#include "content/public/common/process_type.h"
......@@ -29,6 +33,12 @@
#include "content/public/test/test_utils.h"
#include "net/base/net_util.h"
#if defined(OS_WIN)
#include "content/public/browser/web_contents_view.h"
#include "ui/aura/root_window.h"
#include "ui/aura/window.h"
#endif
using content::BrowserThread;
namespace {
......@@ -263,3 +273,67 @@ IN_PROC_BROWSER_TEST_F(ChromePluginTest, InstalledPlugins) {
ASSERT_TRUE(j != plugins.size()) << "Didn't find " << expected[i];
}
}
#if defined(OS_WIN)
namespace {
BOOL CALLBACK EnumerateChildren(HWND hwnd, LPARAM l_param) {
HWND* child = reinterpret_cast<HWND*>(l_param);
*child = hwnd;
// The first child window is the plugin, then its children. So stop
// enumerating after the first callback.
return FALSE;
}
}
// Test that if a background tab loads an NPAPI plugin, they are displayed after
// switching to that page. http://crbug.com/335900
IN_PROC_BROWSER_TEST_F(ChromePluginTest, WindowedNPAPIPluginHidden) {
browser()->profile()->GetPrefs()->SetBoolean(prefs::kPluginsAlwaysAuthorize,
true);
// First load the page in the background and wait for the NPAPI plugin's
// window to be created.
GURL url = ui_test_utils::GetTestUrl(
base::FilePath(),
base::FilePath().AppendASCII("windowed_npapi_plugin.html"));
ui_test_utils::NavigateToURLWithDisposition(
browser(), url, NEW_BACKGROUND_TAB,
ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
// We create a third window just to trigger the second one to update its
// constrained window list. Normally this would be triggered by the status bar
// animation closing after the user middle clicked a link.
ui_test_utils::NavigateToURLWithDisposition(
browser(), GURL("about:blank"), NEW_BACKGROUND_TAB,
ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB);
base::string16 expected_title(base::ASCIIToUTF16("created"));
content::WebContents* tab =
browser()->tab_strip_model()->GetWebContentsAt(1);
if (tab->GetTitle() != expected_title) {
content::TitleWatcher title_watcher(tab, expected_title);
EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle());
}
// Now activate the tab and verify that the plugin painted.
browser()->tab_strip_model()->ActivateTabAt(1, true);
base::string16 expected_title2(base::ASCIIToUTF16("shown"));
content::TitleWatcher title_watcher2(tab, expected_title2);
EXPECT_EQ(expected_title2, title_watcher2.WaitAndGetTitle());
HWND child = NULL;
HWND hwnd = tab->GetView()->GetNativeView()->GetDispatcher()->host()->
GetAcceleratedWidget();
EnumChildWindows(hwnd, EnumerateChildren,reinterpret_cast<LPARAM>(&child));
RECT region;
int result = GetWindowRgnBox(child, &region);
ASSERT_NE(result, NULLREGION);
}
#endif
<hmtl>
<body>
<embed type="application/vnd.npapi-test"
height="300"
width="100%"
name="set_title_in_set_window_and_paint"
id="1"
mode="np_embed"/>
</body>
<script>
function PluginCreated() {
window.document.title = "created";
return;
}
function PluginShown() {
window.document.title = "shown";
return;
}
</script>
</hmtl>
......@@ -1362,15 +1362,16 @@ void RenderWidgetHostViewAura::DidReceiveFrameFromRenderer() {
#if defined(OS_WIN)
void RenderWidgetHostViewAura::UpdateConstrainedWindowRects(
const std::vector<gfx::Rect>& rects) {
// Check this before setting constrained_rects_, so that next time they're set
// and we have a root window we don't early return.
if (!window_->GetDispatcher())
return;
if (rects == constrained_rects_)
return;
constrained_rects_ = rects;
UpdateCutoutRects();
}
void RenderWidgetHostViewAura::UpdateCutoutRects() {
if (!window_->GetRootWindow())
return;
HWND parent = window_->GetDispatcher()->host()->GetAcceleratedWidget();
CutoutRectsParams params;
params.widget = this;
......
......@@ -588,12 +588,6 @@ class CONTENT_EXPORT RenderWidgetHostViewAura
// Helper function to set keyboard focus to the main window.
void SetKeyboardFocus();
#if defined(OS_WIN)
// Updates the total list of cutout rects, which is the union of transient
// windows and constrained windows.
void UpdateCutoutRects();
#endif
// The model object.
RenderWidgetHostImpl* host_;
......
......@@ -792,10 +792,8 @@ class WebContentsViewAura::WindowObserver
virtual void OnWindowVisibilityChanged(aura::Window* window,
bool visible) OVERRIDE {
if (window == view_->window_)
return;
if (window->parent() == parent_ ||
if (window == view_->window_ ||
window->parent() == parent_ ||
window->parent() == view_->window_->GetRootWindow()) {
UpdateConstrainedWindows(NULL);
}
......
......@@ -99,7 +99,8 @@ PluginTest* CreatePluginTest(const std::string& test_name,
test_name == "create_instance_in_paint" ||
test_name == "alert_in_window_message" ||
test_name == "ensure_scripting_works_in_destroy" ||
test_name == "set_title_in_paint") {
test_name == "set_title_in_paint" ||
test_name == "set_title_in_set_window_and_paint") {
new_test = new WindowedPluginTest(instance, host_functions);
#endif
} else if (test_name == "setup") {
......
......@@ -39,7 +39,8 @@ NPError WindowedPluginTest::SetWindow(NPWindow* pNPWindow) {
if ((test_name() == "create_instance_in_paint" && test_id() == "1") ||
test_name() == "alert_in_window_message" ||
test_name() == "set_title_in_paint") {
test_name() == "set_title_in_paint" ||
test_name() == "set_title_in_set_window_and_paint") {
static ATOM window_class = 0;
if (!window_class) {
WNDCLASSEX wcex;
......@@ -68,6 +69,9 @@ NPError WindowedPluginTest::SetWindow(NPWindow* pNPWindow) {
::SetProp(window_, L"Plugin_Instance", this);
}
if (test_name() == "set_title_in_set_window_and_paint")
CallJSFunction(this, "PluginCreated");
return NPERR_NO_ERROR;
}
......@@ -122,6 +126,18 @@ LRESULT CALLBACK WindowedPluginTest::WindowProc(
reinterpret_cast<WindowedPluginTest*>
(::GetProp(window, L"Plugin_Instance"));
if (message == WM_PAINT) {
PAINTSTRUCT ps;
HDC hdc = BeginPaint(window, &ps);
HBRUSH brush = CreateSolidBrush(RGB(255, 0, 0));
SelectObject(hdc, brush);
RECT r;
GetClientRect(window, &r);
Rectangle(hdc, 0, 0, r.right, r.bottom);
DeleteObject(brush);
EndPaint(window, &ps);
}
if (this_ptr && !this_ptr->done_) {
if (this_ptr->test_name() == "create_instance_in_paint" &&
message == WM_PAINT) {
......@@ -138,6 +154,10 @@ LRESULT CALLBACK WindowedPluginTest::WindowProc(
message == WM_PAINT) {
this_ptr->done_ = true;
CallJSFunction(this_ptr, "SetTitle");
} else if (this_ptr->test_name() == "set_title_in_set_window_and_paint" &&
message == WM_PAINT) {
this_ptr->done_ = true;
CallJSFunction(this_ptr, "PluginShown");
}
if (this_ptr->done_) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment