Commit 9faa4c61 authored by garykac@chromium.org's avatar garykac@chromium.org

Fix SetShape (SetAlphaShape) to allow Null regions (+ tests).

SetAlphaShape uses a filter to enforce min/max transparency on the window shape specified by the user. This transparency clamping is required by security to ship the SetShape feature.

We added the call to SetAlphaShape earlier, but we needed to temporarily remove it because of bugs with HiDPI devices and NULL shapes.

The issue with HiDPI devices has been fixed in crrev.com/394193003.
This cl fixes Null shape and re-adds the call to SetAlphaShape so that we can enable this feature on Stable.

BUG=324071

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

Cr-Commit-Position: refs/heads/master@{#288889}
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@288889 0039d316-1c4b-4281-b951-d872f2087c98
parent 7a3b60af
...@@ -110,4 +110,9 @@ IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, WindowsApiGet) { ...@@ -110,4 +110,9 @@ IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, WindowsApiGet) {
<< message_; << message_;
} }
IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, WindowsApiSetShape) {
EXPECT_TRUE(RunPlatformAppTest("platform_apps/windows_api_shape"))
<< message_;
}
} // namespace extensions } // namespace extensions
// Copyright 2014 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.
function testWindowShape(testId, region) {
var createOptions = { id: testId, frame: 'none' };
chrome.app.window.create('index.html',
createOptions,
chrome.test.callbackPass(function(win) {
win.setShape(region)
}));
}
chrome.app.runtime.onLaunched.addListener(function() {
chrome.test.runTests([
// Window shape is a single rect.
function testWindowShapeSingleRect() {
testWindowShape('testWindowShapeSingleRect',
{rects: [{left:100, top:50, width:50, height:100}]});
},
// Window shape is multiple rects.
function testWindowShapeMultipleRects() {
testWindowShape('testWindowShapeMultipleRects',
{rects: [{left:100, top:50, width:50, height:100},
{left:200, top:100, width:50, height:50}]});
},
// Window shape is null.
function testWindowShapeNull() {
testWindowShape('testWindowShapeNull', {});
},
// Window shape is empty.
function testWindowShapeEmpty() {
testWindowShape('testWindowShapeEmpty', {rects: []});
},
]);
});
\ No newline at end of file
{
"name": "Windows API - setShape",
"version": "1",
"manifest_version": 2,
"app": {
"background": {
"scripts": ["background.js"]
}
},
"permissions": ["app.window.shape"]
}
...@@ -496,10 +496,15 @@ gfx::Rect DesktopWindowTreeHostX11::GetWorkAreaBoundsInScreen() const { ...@@ -496,10 +496,15 @@ gfx::Rect DesktopWindowTreeHostX11::GetWorkAreaBoundsInScreen() const {
void DesktopWindowTreeHostX11::SetShape(gfx::NativeRegion native_region) { void DesktopWindowTreeHostX11::SetShape(gfx::NativeRegion native_region) {
if (window_shape_) if (window_shape_)
XDestroyRegion(window_shape_); XDestroyRegion(window_shape_);
custom_window_shape_ = true; custom_window_shape_ = false;
window_shape_ = gfx::CreateRegionFromSkRegion(*native_region); window_shape_ = NULL;
if (native_region) {
custom_window_shape_ = true;
window_shape_ = gfx::CreateRegionFromSkRegion(*native_region);
delete native_region;
}
ResetWindowRegion(); ResetWindowRegion();
delete native_region;
} }
void DesktopWindowTreeHostX11::Activate() { void DesktopWindowTreeHostX11::Activate() {
......
...@@ -307,6 +307,17 @@ TEST_F(DesktopWindowTreeHostX11Test, Shape) { ...@@ -307,6 +307,17 @@ TEST_F(DesktopWindowTreeHostX11Test, Shape) {
EXPECT_TRUE(ShapeRectContainsPoint(shape_rects, 15, 5)); EXPECT_TRUE(ShapeRectContainsPoint(shape_rects, 15, 5));
EXPECT_TRUE(ShapeRectContainsPoint(shape_rects, 95, 15)); EXPECT_TRUE(ShapeRectContainsPoint(shape_rects, 95, 15));
EXPECT_FALSE(ShapeRectContainsPoint(shape_rects, 105, 15)); EXPECT_FALSE(ShapeRectContainsPoint(shape_rects, 105, 15));
// Setting the shape to NULL resets the shape back to the entire
// window bounds.
widget2->SetShape(NULL);
shape_rects = GetShapeRects(xid2);
ASSERT_FALSE(shape_rects.empty());
EXPECT_TRUE(ShapeRectContainsPoint(shape_rects, 5, 5));
EXPECT_TRUE(ShapeRectContainsPoint(shape_rects, 15, 5));
EXPECT_TRUE(ShapeRectContainsPoint(shape_rects, 95, 15));
EXPECT_TRUE(ShapeRectContainsPoint(shape_rects, 105, 15));
EXPECT_FALSE(ShapeRectContainsPoint(shape_rects, 500, 500));
} }
// Test that the widget ignores changes in fullscreen state initiated by the // Test that the widget ignores changes in fullscreen state initiated by the
......
...@@ -438,8 +438,10 @@ void NativeWidgetAura::StackBelow(gfx::NativeView native_view) { ...@@ -438,8 +438,10 @@ void NativeWidgetAura::StackBelow(gfx::NativeView native_view) {
} }
void NativeWidgetAura::SetShape(gfx::NativeRegion region) { void NativeWidgetAura::SetShape(gfx::NativeRegion region) {
// No need for this. Just delete and ignore. if (window_)
delete region; window_->layer()->SetAlphaShape(make_scoped_ptr(region));
else
delete region;
} }
void NativeWidgetAura::Close() { void NativeWidgetAura::Close() {
......
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