Commit aa9775ec authored by Anatoliy Potapchuk's avatar Anatoliy Potapchuk Committed by Commit Bot

Don't allow extensions create new tabs in locked fullscreen mode

Previously, you were able to do an escape via tabs.create api. Now it
is not possible.

Bug: 1024244
Change-Id: Ic81c202891cd504f08678db3bbf42b4a5ae1a28d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1914360
Commit-Queue: Anatoliy Potapchuk <apotapchuk@chromium.org>
Reviewed-by: default avatarDevlin <rdevlin.cronin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#719863}
parent a3a8726a
......@@ -27,6 +27,11 @@
#include "ui/display/test/scoped_screen_override.h"
#include "ui/display/test/test_screen.h"
#if defined(OS_CHROMEOS)
#include "ash/public/cpp/window_pin_type.h"
#include "ash/public/cpp/window_properties.h"
#endif
namespace extensions {
using display::test::ScopedScreenOverride;
......@@ -77,6 +82,7 @@ class TabsApiUnitTest : public ExtensionServiceTestBase {
~TabsApiUnitTest() override {}
Browser* browser() { return browser_.get(); }
TestBrowserWindow* browser_window() { return browser_window_.get(); }
TabStripModel* GetTabStripModel() { return browser_->tab_strip_model(); }
......@@ -538,4 +544,25 @@ TEST_F(TabsApiUnitTest, TabsGoForwardAndBackWithoutTabId) {
base::RunLoop().RunUntilIdle();
}
#if defined(OS_CHROMEOS)
TEST_F(TabsApiUnitTest, DontCreateTabsInLockedFullscreenMode) {
scoped_refptr<const Extension> extension_with_tabs_permission =
CreateTabsExtension();
browser_window()->SetNativeWindow(new aura::Window(nullptr));
auto function = base::MakeRefCounted<TabsCreateFunction>();
function->set_extension(extension_with_tabs_permission.get());
// In locked fullscreen mode we should not be able to create any tabs.
browser_window()->GetNativeWindow()->SetProperty(
ash::kWindowPinTypeKey, ash::WindowPinType::kTrustedPinned);
EXPECT_EQ(tabs_constants::kLockedFullscreenModeNewTabError,
extension_function_test_utils::RunFunctionAndReturnError(
function.get(), "[{}]", browser(), api_test_utils::NONE));
}
#endif // defined(OS_CHROMEOS)
} // namespace extensions
......@@ -118,6 +118,8 @@ const char kJavaScriptUrlsNotAllowedInTabsUpdate[] =
"JavaScript URLs are not allowed in chrome.tabs.update. Use "
"chrome.tabs.executeScript instead.";
const char kBrowserWindowNotAllowed[] = "Browser windows not allowed.";
const char kLockedFullscreenModeNewTabError[] =
"You cannot create new tabs while in locked fullscreen mode.";
} // namespace tabs_constants
} // namespace extensions
......@@ -108,6 +108,7 @@ extern const char kCannotDetermineLanguageOfUnloadedTab[];
extern const char kMissingLockWindowFullscreenPrivatePermission[];
extern const char kJavaScriptUrlsNotAllowedInTabsUpdate[];
extern const char kBrowserWindowNotAllowed[];
extern const char kLockedFullscreenModeNewTabError[];
} // namespace tabs_constants
} // namespace extensions
......
......@@ -300,6 +300,14 @@ base::DictionaryValue* ExtensionTabUtil::OpenTab(ExtensionFunction* function,
navigate_params.tabstrip_add_types = add_types;
Navigate(&navigate_params);
// This happens in locked fullscreen mode.
if (!navigate_params.navigated_or_inserted_contents) {
if (error) {
*error = tabs_constants::kLockedFullscreenModeNewTabError;
}
return nullptr;
}
// The tab may have been created in a different window, so make sure we look
// at the right tab strip.
TabStripModel* tab_strip = navigate_params.browser->tab_strip_model();
......
......@@ -70,7 +70,7 @@ ui::ZOrderLevel TestBrowserWindow::GetZOrderLevel() const {
}
gfx::NativeWindow TestBrowserWindow::GetNativeWindow() const {
return NULL;
return native_window_;
}
bool TestBrowserWindow::IsOnCurrentWorkspace() const {
......@@ -251,6 +251,10 @@ bool TestBrowserWindow::IsVisibleOnAllWorkspaces() const {
return false;
}
void TestBrowserWindow::SetNativeWindow(gfx::NativeWindow window) {
native_window_ = window;
}
// TestBrowserWindowOwner -----------------------------------------------------
TestBrowserWindowOwner::TestBrowserWindowOwner(TestBrowserWindow* window)
......
......@@ -42,6 +42,7 @@ class SendTabToSelfBubbleView;
// An implementation of BrowserWindow used for testing. TestBrowserWindow only
// contains a valid LocationBar, all other getters return NULL.
// However, some of them can be preset to a specific value.
// See BrowserWithTestWindowTest for an example of using this class.
class TestBrowserWindow : public BrowserWindow {
public:
......@@ -195,6 +196,8 @@ class TestBrowserWindow : public BrowserWindow {
void ShowInProductHelpPromo(InProductHelpFeature iph_feature) override {}
void SetNativeWindow(gfx::NativeWindow window);
protected:
void DestroyBrowser() override {}
......@@ -227,6 +230,7 @@ class TestBrowserWindow : public BrowserWindow {
autofill::TestAutofillBubbleHandler autofill_bubble_handler_;
TestDownloadShelf download_shelf_;
TestLocationBar location_bar_;
gfx::NativeWindow native_window_ = nullptr;
DISALLOW_COPY_AND_ASSIGN(TestBrowserWindow);
};
......
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