diff options
20 files changed, 252 insertions, 26 deletions
diff --git a/chrome/browser/apps/app_window_interactive_uitest.cc b/chrome/browser/apps/app_window_interactive_uitest.cc index 5b79947..0c90e44 100644 --- a/chrome/browser/apps/app_window_interactive_uitest.cc +++ b/chrome/browser/apps/app_window_interactive_uitest.cc @@ -275,6 +275,58 @@ IN_PROC_BROWSER_TEST_F(AppWindowInteractiveTest, EXPECT_TRUE(GetFirstAppWindow()->GetBaseWindow()->IsFullscreen()); } +// This test is duplicated from ESCDoesNotLeaveFullscreenWindow. +// It runs the same test, but uses the old permission names: 'fullscreen' +// and 'overrideEscFullscreen'. +IN_PROC_BROWSER_TEST_F(AppWindowInteractiveTest, + ESCDoesNotLeaveFullscreenOldPermission) { +// This test is flaky on MacOS 10.6. +#if defined(OS_MACOSX) && !defined(OS_IOS) + if (base::mac::IsOSSnowLeopard()) + return; +#endif + + ExtensionTestMessageListener launched_listener("Launched", true); + LoadAndLaunchPlatformApp("prevent_leave_fullscreen_old"); + ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); + + // We start by making sure the window is actually focused. + ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow( + GetFirstAppWindow()->GetNativeWindow())); + + // When receiving the reply, the application will try to go fullscreen using + // the Window API but there is no synchronous way to know if that actually + // succeeded. Also, failure will not be notified. A failure case will only be + // known with a timeout. + { + FullscreenChangeWaiter fs_changed(GetFirstAppWindow()->GetBaseWindow()); + + launched_listener.Reply("window"); + + fs_changed.Wait(); + } + + // Depending on the platform, going fullscreen might create an animation. + // We want to make sure that the ESC key we will send next is actually going + // to be received and the application might not receive key events during the + // animation so we should wait for the key focus to be back. + WaitUntilKeyFocus(); + + ASSERT_TRUE(SimulateKeyPress(ui::VKEY_ESCAPE)); + + ExtensionTestMessageListener second_key_listener("B_KEY_RECEIVED", false); + + ASSERT_TRUE(SimulateKeyPress(ui::VKEY_B)); + + ASSERT_TRUE(second_key_listener.WaitUntilSatisfied()); + + // We assume that at that point, if we had to leave fullscreen, we should be. + // However, by nature, we can not guarantee that and given that we do test + // that nothing happens, we might end up with random-success when the feature + // is broken. + EXPECT_TRUE(GetFirstAppWindow()->GetBaseWindow()->IsFullscreen()); +} + // This test does not work on Linux Aura because ShowInactive() is not // implemented. See http://crbug.com/325142 // It also does not work on Windows because of the document being focused even diff --git a/chrome/browser/extensions/api/app_current_window_internal/app_current_window_internal_api.cc b/chrome/browser/extensions/api/app_current_window_internal/app_current_window_internal_api.cc index 0cf6ef0..2277942 100644 --- a/chrome/browser/extensions/api/app_current_window_internal/app_current_window_internal_api.cc +++ b/chrome/browser/extensions/api/app_current_window_internal/app_current_window_internal_api.cc @@ -49,7 +49,7 @@ const char kRequiresFramelessWindow[] = "This function requires a frameless window (frame:none)."; const char kAlwaysOnTopPermission[] = - "The \"alwaysOnTopWindows\" permission is required."; + "The \"app.window.alwaysOnTop\" permission is required."; const char kInvalidParameters[] = "Invalid parameters."; diff --git a/chrome/browser/extensions/api/app_window/app_window_apitest.cc b/chrome/browser/extensions/api/app_window/app_window_apitest.cc index 99a5c02..5866c19 100644 --- a/chrome/browser/extensions/api/app_window/app_window_apitest.cc +++ b/chrome/browser/extensions/api/app_window/app_window_apitest.cc @@ -142,6 +142,13 @@ IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, } IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, + WindowsApiAlwaysOnTopWithOldPermissions) { + EXPECT_TRUE(RunPlatformAppTest( + "platform_apps/windows_api_always_on_top/has_old_permissions")) + << message_; +} + +IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, WindowsApiAlwaysOnTopNoPermissions) { EXPECT_TRUE(RunPlatformAppTest( "platform_apps/windows_api_always_on_top/no_permissions")) << message_; diff --git a/chrome/common/extensions/api/_api_features.json b/chrome/common/extensions/api/_api_features.json index b3c6edd..6515a26 100644 --- a/chrome/common/extensions/api/_api_features.json +++ b/chrome/common/extensions/api/_api_features.json @@ -53,6 +53,10 @@ "channel": "stable", "contexts": ["blessed_extension", "unblessed_extension", "content_script"] }, + "app.currentWindowInternal.setShape": { + "dependencies": ["permission:app.window.shape"], + "contexts": ["blessed_extension"] + }, "app.getDetails": { "contexts": ["blessed_extension", "unblessed_extension", "content_script"], "matches": [] diff --git a/chrome/common/extensions/api/_permission_features.json b/chrome/common/extensions/api/_permission_features.json index 41aae0d..3ae1b51 100644 --- a/chrome/common/extensions/api/_permission_features.json +++ b/chrome/common/extensions/api/_permission_features.json @@ -40,10 +40,22 @@ "extension_types": ["extension", "legacy_packaged_app", "platform_app"], "min_manifest_version": 2 }, - "alwaysOnTopWindows": { + "app.window.alwaysOnTop": { "channel": "stable", "extension_types": ["platform_app"] }, + "app.window.fullscreen": { + "channel": "stable", + "extension_types": ["platform_app"] + }, + "app.window.fullscreen.overrideEsc": { + "channel": "stable", + "extension_types": ["platform_app"] + }, + "app.window.shape": { + "channel": "dev", + "extension_types": ["platform_app"] + }, "audio": [ { "channel": "dev", @@ -406,10 +418,6 @@ "channel": "stable", "extension_types": ["extension", "legacy_packaged_app"] }, - "fullscreen": { - "channel": "stable", - "extension_types": ["platform_app"] - }, "gcm": { "channel": "dev", "extension_types": ["extension", "platform_app"] @@ -648,10 +656,6 @@ "extension", "legacy_packaged_app", "hosted_app", "platform_app" ] }, - "overrideEscFullscreen": { - "channel": "stable", - "extension_types": ["platform_app"] - }, "echoPrivate": { "channel": "stable", "extension_types": ["extension", "legacy_packaged_app", "platform_app"], diff --git a/chrome/common/extensions/api/app_window.idl b/chrome/common/extensions/api/app_window.idl index 2c4dc58..ec1123a 100644 --- a/chrome/common/extensions/api/app_window.idl +++ b/chrome/common/extensions/api/app_window.idl @@ -231,7 +231,7 @@ namespace app.window { // If true, the window will stay above most other windows. If there are // multiple windows of this kind, the currently focused window will be in - // the foreground. Requires the <code>"alwaysOnTopWindows"</code> + // the foreground. Requires the <code>"app.window.alwaysOnTop"</code> // permission. Defaults to false.<br> // Call <code>setAlwaysOnTop()</code> on the window to change this property // after creation.<br> @@ -258,8 +258,9 @@ namespace app.window { // Fullscreens the window.<br> // The user will be able to restore the window by pressing ESC. An // application can prevent the fullscreen state to be left when ESC is - // pressed by requesting the <b>overrideEscFullscreen</b> permission and - // canceling the event by calling .preventDefault(), like this:<br> + // pressed by requesting the <b>app.window.fullscreen.overrideEsc</b> + // permission and canceling the event by calling .preventDefault(), like + // this:<br> // <code>window.onKeyDown = function(e) { if (e.keyCode == 27 /* ESC */) { // e.preventDefault(); } };</code> static void fullscreen(); @@ -331,7 +332,7 @@ namespace app.window { [nodoc] long frameColor; // Set whether the window should stay above most other windows. Requires the - // <code>"alwaysOnTopWindows"</code> permission. + // <code>"app.window.alwaysOnTop"</code> permission. static void setAlwaysOnTop(boolean alwaysOnTop); // The JavaScript 'window' object for the created child. diff --git a/chrome/common/extensions/docs/templates/articles/permission_warnings.html b/chrome/common/extensions/docs/templates/articles/permission_warnings.html index 2001e843..927cce7 100644 --- a/chrome/common/extensions/docs/templates/articles/permission_warnings.html +++ b/chrome/common/extensions/docs/templates/articles/permission_warnings.html @@ -414,7 +414,10 @@ The following permissions don't result in a warning: <ul> <li>"activeTab"</li> {{?is_apps}} - <li>"alwaysOnTopWindows"</li> + <li>"app.window.alwaysOnTop"</li> + <li>"app.window.fullscreen"</li> + <li>"app.window.fullscreen.overrideEsc"</li> + <li>"app.window.shape"</li> {{/is_apps}} <li>"browsingData"</li> <li>"chrome://favicon/"</li> @@ -422,9 +425,6 @@ The following permissions don't result in a warning: <li>"contextMenus"</li> <li>"cookies"</li> <li>"experimental"</li> -{{?is_apps}} - <li>"fullscreen"</li> -{{/is_apps}} <li>"idle"</li> <li>"notifications"</li> {{?is_apps}} diff --git a/chrome/common/extensions/permissions/chrome_api_permissions.cc b/chrome/common/extensions/permissions/chrome_api_permissions.cc index 5799bd1..f05dc67 100644 --- a/chrome/common/extensions/permissions/chrome_api_permissions.cc +++ b/chrome/common/extensions/permissions/chrome_api_permissions.cc @@ -17,6 +17,9 @@ namespace extensions { namespace { +const char kOldAlwaysOnTopWindowsPermission[] = "alwaysOnTopWindows"; +const char kOldFullscreenPermission[] = "fullscreen"; +const char kOldOverrideEscFullscreenPermission[] = "overrideEscFullscreen"; const char kOldUnlimitedStoragePermission[] = "unlimited_storage"; const char kWindowsPermission[] = "windows"; @@ -290,7 +293,7 @@ std::vector<APIPermissionInfo*> ChromeAPIPermissions::GetAllPermissions() {APIPermission::kSocket, "socket", APIPermissionInfo::kFlagCannotBeOptional, 0, PermissionMessage::kNone, &CreateAPIPermission<SocketPermission>}, - {APIPermission::kAlwaysOnTopWindows, "alwaysOnTopWindows"}, + {APIPermission::kAlwaysOnTopWindows, "app.window.alwaysOnTop"}, {APIPermission::kAudioCapture, "audioCapture", APIPermissionInfo::kFlagNone, IDS_EXTENSION_PROMPT_WARNING_AUDIO_CAPTURE, @@ -349,10 +352,12 @@ std::vector<APIPermissionInfo*> ChromeAPIPermissions::GetAllPermissions() {APIPermission::kSystemDisplay, "system.display"}, {APIPermission::kSystemStorage, "system.storage"}, {APIPermission::kPointerLock, "pointerLock"}, - {APIPermission::kFullscreen, "fullscreen"}, + {APIPermission::kFullscreen, "app.window.fullscreen"}, {APIPermission::kAudio, "audio"}, {APIPermission::kCastStreaming, "cast.streaming"}, - {APIPermission::kOverrideEscFullscreen, "overrideEscFullscreen"}, + {APIPermission::kOverrideEscFullscreen, + "app.window.fullscreen.overrideEsc"}, + {APIPermission::kWindowShape, "app.window.shape"}, // Settings override permissions. {APIPermission::kHomepage, "homepage", @@ -389,6 +394,13 @@ ChromeAPIPermissions::GetAllAliases() const { // Register aliases. std::vector<PermissionsProvider::AliasInfo> aliases; aliases.push_back(PermissionsProvider::AliasInfo( + "app.window.alwaysOnTop", kOldAlwaysOnTopWindowsPermission)); + aliases.push_back(PermissionsProvider::AliasInfo("app.window.fullscreen", + kOldFullscreenPermission)); + aliases.push_back( + PermissionsProvider::AliasInfo("app.window.fullscreen.overrideEsc", + kOldOverrideEscFullscreenPermission)); + aliases.push_back(PermissionsProvider::AliasInfo( "unlimitedStorage", kOldUnlimitedStoragePermission)); aliases.push_back(PermissionsProvider::AliasInfo( "tabs", kWindowsPermission)); diff --git a/chrome/common/extensions/permissions/permission_set_unittest.cc b/chrome/common/extensions/permissions/permission_set_unittest.cc index 03481b7..b42fb5e 100644 --- a/chrome/common/extensions/permissions/permission_set_unittest.cc +++ b/chrome/common/extensions/permissions/permission_set_unittest.cc @@ -653,6 +653,7 @@ TEST(PermissionsTest, PermissionMessages) { skip.insert(APIPermission::kIdltest); skip.insert(APIPermission::kLogPrivate); skip.insert(APIPermission::kNotification); + skip.insert(APIPermission::kOverrideEscFullscreen); skip.insert(APIPermission::kPointerLock); skip.insert(APIPermission::kPower); skip.insert(APIPermission::kPushMessaging); @@ -666,7 +667,7 @@ TEST(PermissionsTest, PermissionMessages) { skip.insert(APIPermission::kTts); skip.insert(APIPermission::kUnlimitedStorage); skip.insert(APIPermission::kWebView); - skip.insert(APIPermission::kOverrideEscFullscreen); + skip.insert(APIPermission::kWindowShape); // TODO(erikkay) add a string for this permission. skip.insert(APIPermission::kBackground); diff --git a/chrome/test/data/extensions/platform_apps/app_window/generic/manifest.json b/chrome/test/data/extensions/platform_apps/app_window/generic/manifest.json index 838ad56..b2b0b89 100644 --- a/chrome/test/data/extensions/platform_apps/app_window/generic/manifest.json +++ b/chrome/test/data/extensions/platform_apps/app_window/generic/manifest.json @@ -8,5 +8,5 @@ "scripts": ["main.js"] } }, - "permissions": ["fullscreen", "alwaysOnTopWindows"] + "permissions": ["app.window.fullscreen", "app.window.alwaysOnTop"] } diff --git a/chrome/test/data/extensions/platform_apps/prevent_leave_fullscreen/manifest.json b/chrome/test/data/extensions/platform_apps/prevent_leave_fullscreen/manifest.json index 8cd9d23..a573389 100644 --- a/chrome/test/data/extensions/platform_apps/prevent_leave_fullscreen/manifest.json +++ b/chrome/test/data/extensions/platform_apps/prevent_leave_fullscreen/manifest.json @@ -7,6 +7,6 @@ } }, "permissions": [ - "fullscreen", "overrideEscFullscreen" + "app.window.fullscreen", "app.window.fullscreen.overrideEsc" ] } diff --git a/chrome/test/data/extensions/platform_apps/prevent_leave_fullscreen_old/main.html b/chrome/test/data/extensions/platform_apps/prevent_leave_fullscreen_old/main.html new file mode 100644 index 0000000..f22cbda --- /dev/null +++ b/chrome/test/data/extensions/platform_apps/prevent_leave_fullscreen_old/main.html @@ -0,0 +1,9 @@ +<!DOCTYPE html> +<html> +<head> + <title>fullscreen (old permission name)</title> +</head> +<body> + foobar +</body> +</html> diff --git a/chrome/test/data/extensions/platform_apps/prevent_leave_fullscreen_old/main.js b/chrome/test/data/extensions/platform_apps/prevent_leave_fullscreen_old/main.js new file mode 100644 index 0000000..2a5bebd --- /dev/null +++ b/chrome/test/data/extensions/platform_apps/prevent_leave_fullscreen_old/main.js @@ -0,0 +1,60 @@ +// Copyright 2013 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. + +chrome.app.runtime.onLaunched.addListener(function() { + chrome.app.window.create('main.html', {}, function(win) { + // The following key events handler will prevent the default behavior for + // the ESC key, thus will prevent the ESC key to leave fullscreen. + win.contentWindow.document.addEventListener('keydown', function(e) { + e.preventDefault(); + }); + win.contentWindow.document.addEventListener('keyup', function(e) { + e.preventDefault(); + }); + + chrome.test.sendMessage('Launched', function(reply) { + var doc = win.contentWindow.document; + doc.addEventListener('keydown', function(e) { + if (e.keyCode != 90) // 'z' + return; + chrome.test.sendMessage('KeyReceived'); + }); + + switch (reply) { + case 'window': + doc.addEventListener('keydown', function(e) { + if (e.keyCode != 66) // 'b' + return; + doc.removeEventListener('keydown', arguments.callee); + // We do one trip to the event loop to increase the chances that + // fullscreen could have been left before the message is received. + setTimeout(function() { + chrome.test.sendMessage('B_KEY_RECEIVED'); + }); + }); + win.fullscreen(); + break; + + case 'dom': + doc.addEventListener('keydown', function() { + doc.removeEventListener('keydown', arguments.callee); + + doc.addEventListener('keydown', function(e) { + if (e.keyCode != 66) // 'b' + return; + doc.removeEventListener('keydown', arguments.callee); + // We do one trip to the event loop to increase the chances that + // fullscreen could have been left before the message is received. + setTimeout(function() { + chrome.test.sendMessage('B_KEY_RECEIVED'); + }); + }); + + doc.body.webkitRequestFullscreen(); + }); + break; + } + }); + }); +}); diff --git a/chrome/test/data/extensions/platform_apps/prevent_leave_fullscreen_old/manifest.json b/chrome/test/data/extensions/platform_apps/prevent_leave_fullscreen_old/manifest.json new file mode 100644 index 0000000..8cd9d23 --- /dev/null +++ b/chrome/test/data/extensions/platform_apps/prevent_leave_fullscreen_old/manifest.json @@ -0,0 +1,12 @@ +{ + "name": "Test app for leaving fullscreen rules", + "version": "1", + "app": { + "background": { + "scripts": ["main.js"] + } + }, + "permissions": [ + "fullscreen", "overrideEscFullscreen" + ] +} diff --git a/chrome/test/data/extensions/platform_apps/windows_api_always_on_top/has_old_permissions/background.js b/chrome/test/data/extensions/platform_apps/windows_api_always_on_top/has_old_permissions/background.js new file mode 100644 index 0000000..03aabe0 --- /dev/null +++ b/chrome/test/data/extensions/platform_apps/windows_api_always_on_top/has_old_permissions/background.js @@ -0,0 +1,51 @@ +// Copyright 2013 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. + +var callbackPass = chrome.test.callbackPass; + +function testAlwaysOnTop(testId, initValue, setOption) { + var options = { id: testId }; + if (setOption) + options.alwaysOnTop = initValue; + + chrome.app.window.create('index.html', + options, + callbackPass(function(win) { + // Check that isAlwaysOnTop() returns the initial value. + chrome.test.assertEq(initValue, win.isAlwaysOnTop()); + + // Toggle the current value. + win.setAlwaysOnTop(!initValue); + + // setAlwaysOnTop is synchronous in the browser, so send an async request to + // ensure we get the updated value of isAlwaysOnTop. + chrome.test.waitForRoundTrip("msg", callbackPass(function(platformInfo) { + // Check that isAlwaysOnTop() returns the new value. + chrome.test.assertEq(!initValue, win.isAlwaysOnTop()); + + win.contentWindow.close(); + })); + })); +} + +chrome.app.runtime.onLaunched.addListener(function() { + chrome.test.runTests([ + + // Window is created with always on top enabled. + function testAlwaysOnTopInitTrue() { + testAlwaysOnTop('testAlwaysOnTopInitTrue', true, true); + }, + + // Window is created with always on top explicitly disabled. + function testAlwaysOnTopInitFalse() { + testAlwaysOnTop('testAlwaysOnTopInitFalse', false, true); + }, + + // Window is created with option not explicitly set. + function testAlwaysOnTopNoInit() { + testAlwaysOnTop('testAlwaysOnTopNoInit', false, false); + } + + ]); +}); diff --git a/chrome/test/data/extensions/platform_apps/windows_api_always_on_top/has_old_permissions/index.html b/chrome/test/data/extensions/platform_apps/windows_api_always_on_top/has_old_permissions/index.html new file mode 100644 index 0000000..c341a40 --- /dev/null +++ b/chrome/test/data/extensions/platform_apps/windows_api_always_on_top/has_old_permissions/index.html @@ -0,0 +1 @@ +<!-- empty --> diff --git a/chrome/test/data/extensions/platform_apps/windows_api_always_on_top/has_old_permissions/manifest.json b/chrome/test/data/extensions/platform_apps/windows_api_always_on_top/has_old_permissions/manifest.json new file mode 100644 index 0000000..e9a4740 --- /dev/null +++ b/chrome/test/data/extensions/platform_apps/windows_api_always_on_top/has_old_permissions/manifest.json @@ -0,0 +1,11 @@ +{ + "name": "Windows API - AlwaysOnTop (old permission)", + "version": "1", + "manifest_version": 2, + "app": { + "background": { + "scripts": ["background.js"] + } + }, + "permissions": ["alwaysOnTopWindows"] +} diff --git a/chrome/test/data/extensions/platform_apps/windows_api_always_on_top/has_permissions/manifest.json b/chrome/test/data/extensions/platform_apps/windows_api_always_on_top/has_permissions/manifest.json index 8a10297..a86b8f3 100644 --- a/chrome/test/data/extensions/platform_apps/windows_api_always_on_top/has_permissions/manifest.json +++ b/chrome/test/data/extensions/platform_apps/windows_api_always_on_top/has_permissions/manifest.json @@ -7,5 +7,5 @@ "scripts": ["background.js"] } }, - "permissions": ["alwaysOnTopWindows"] + "permissions": ["app.window.alwaysOnTop"] } diff --git a/chrome/test/data/extensions/platform_apps/windows_api_always_on_top/no_permissions/background.js b/chrome/test/data/extensions/platform_apps/windows_api_always_on_top/no_permissions/background.js index bd5f0c5..1d49d1c 100644 --- a/chrome/test/data/extensions/platform_apps/windows_api_always_on_top/no_permissions/background.js +++ b/chrome/test/data/extensions/platform_apps/windows_api_always_on_top/no_permissions/background.js @@ -14,7 +14,7 @@ function testAlwaysOnTop(testId, value) { options, callbackPass(function(win) { // Check that isAlwaysOnTop() returns false because the manifest did not - // specify the "alwaysOnTopWindows" permission. + // specify the "app.window.alwaysOnTop" permission. chrome.test.assertEq(false, win.isAlwaysOnTop()); // Attempt to use setAlwaysOnTop() to change the property. But this should diff --git a/extensions/common/permissions/api_permission.h b/extensions/common/permissions/api_permission.h index 5d40f86..b6933c2 100644 --- a/extensions/common/permissions/api_permission.h +++ b/extensions/common/permissions/api_permission.h @@ -163,6 +163,7 @@ class APIPermission { kWebrtcLoggingPrivate, kWebstorePrivate, kWebView, + kWindowShape, kScreenlockPrivate, kSystemCpu, kSystemMemory, |