Commit 52d81474 authored by Felix Ekblom's avatar Felix Ekblom Committed by Commit Bot

Actually check whether extension is in kiosk mode

Add the missing check for actually being in kiosk mode, but keep the
autotest bail to simplify testing of the feature.

BUG=chromium:826568
TEST=Ran autotest, verified that extension can't access edid.

Change-Id: I8f93e29d8d977b0977b3eb597ce2aae263b4e9b9
Reviewed-on: https://chromium-review.googlesource.com/982619Reviewed-by: default avatarSteven Bennetts <stevenjb@chromium.org>
Commit-Queue: Felix Ekblom <felixe@chromium.org>
Cr-Commit-Position: refs/heads/master@{#548147}
parent f24199ed
...@@ -25,9 +25,9 @@ namespace extensions { ...@@ -25,9 +25,9 @@ namespace extensions {
namespace display = api::system_display; namespace display = api::system_display;
const char SystemDisplayFunction::kCrosOnlyError[] = const char SystemDisplayCrOSRestrictedFunction::kCrosOnlyError[] =
"Function available only on ChromeOS."; "Function available only on ChromeOS.";
const char SystemDisplayFunction::kKioskOnlyError[] = const char SystemDisplayCrOSRestrictedFunction::kKioskOnlyError[] =
"Only kiosk enabled extensions are allowed to use this function."; "Only kiosk enabled extensions are allowed to use this function.";
namespace { namespace {
...@@ -148,9 +148,23 @@ bool OverscanTracker::RemoveObserverImpl(content::WebContents* web_contents) { ...@@ -148,9 +148,23 @@ bool OverscanTracker::RemoveObserverImpl(content::WebContents* web_contents) {
return observers_.empty(); return observers_.empty();
} }
bool HasAutotestPrivate(const UIThreadExtensionFunction& function) {
return function.extension() &&
function.extension()->permissions_data()->HasAPIPermission(
APIPermission::kAutoTestPrivate);
}
#if defined(OS_CHROMEOS)
// |edid| is available only to Chrome OS kiosk mode applications.
bool ShouldRestrictEdidInformation(const UIThreadExtensionFunction& function) {
return !HasAutotestPrivate(function) &&
!KioskModeInfo::IsKioskEnabled(function.extension());
}
#endif
} // namespace } // namespace
bool SystemDisplayFunction::PreRunValidation(std::string* error) { bool SystemDisplayCrOSRestrictedFunction::PreRunValidation(std::string* error) {
if (!UIThreadExtensionFunction::PreRunValidation(error)) if (!UIThreadExtensionFunction::PreRunValidation(error))
return false; return false;
...@@ -170,20 +184,8 @@ bool SystemDisplayFunction::PreRunValidation(std::string* error) { ...@@ -170,20 +184,8 @@ bool SystemDisplayFunction::PreRunValidation(std::string* error) {
#endif #endif
} }
bool SystemDisplayFunction::ShouldRestrictToKioskAndWebUI() { bool SystemDisplayCrOSRestrictedFunction::ShouldRestrictToKioskAndWebUI() {
// Allow autotest extension to access for Chrome OS testing. return !HasAutotestPrivate(*this);
if (extension() && extension()->permissions_data()->HasAPIPermission(
APIPermission::kAutoTestPrivate)) {
return false;
}
return true;
}
bool SystemDisplayGetInfoFunction::PreRunValidation(std::string* error) {
// Returns true to not block the method completely when in non-kiosk mode.
// Only the |edid| property is conditional to kiosk mode.
return true;
} }
ExtensionFunction::ResponseAction SystemDisplayGetInfoFunction::Run() { ExtensionFunction::ResponseAction SystemDisplayGetInfoFunction::Run() {
...@@ -199,11 +201,12 @@ ExtensionFunction::ResponseAction SystemDisplayGetInfoFunction::Run() { ...@@ -199,11 +201,12 @@ ExtensionFunction::ResponseAction SystemDisplayGetInfoFunction::Run() {
void SystemDisplayGetInfoFunction::Response( void SystemDisplayGetInfoFunction::Response(
DisplayInfoProvider::DisplayUnitInfoList all_displays_info) { DisplayInfoProvider::DisplayUnitInfoList all_displays_info) {
// |edid| is restricted to kiosk mode. #if defined(OS_CHROMEOS)
if (ShouldRestrictToKioskAndWebUI()) { if (ShouldRestrictEdidInformation(*this)) {
for (auto& display_info : all_displays_info) for (auto& display_info : all_displays_info)
display_info.edid.release(); display_info.edid.release();
} }
#endif
Respond(ArgumentList(display::GetInfo::Results::Create(all_displays_info))); Respond(ArgumentList(display::GetInfo::Results::Create(all_displays_info)));
} }
......
...@@ -12,13 +12,13 @@ ...@@ -12,13 +12,13 @@
namespace extensions { namespace extensions {
class SystemDisplayFunction : public UIThreadExtensionFunction { class SystemDisplayCrOSRestrictedFunction : public UIThreadExtensionFunction {
public: public:
static const char kCrosOnlyError[]; static const char kCrosOnlyError[];
static const char kKioskOnlyError[]; static const char kKioskOnlyError[];
protected: protected:
~SystemDisplayFunction() override {} ~SystemDisplayCrOSRestrictedFunction() override {}
bool PreRunValidation(std::string* error) override; bool PreRunValidation(std::string* error) override;
// Returns true if this function should be restricted to kiosk-mode apps and // Returns true if this function should be restricted to kiosk-mode apps and
...@@ -26,22 +26,22 @@ class SystemDisplayFunction : public UIThreadExtensionFunction { ...@@ -26,22 +26,22 @@ class SystemDisplayFunction : public UIThreadExtensionFunction {
virtual bool ShouldRestrictToKioskAndWebUI(); virtual bool ShouldRestrictToKioskAndWebUI();
}; };
// GetInfo is a SystemDisplayFunction to limit some of the fields to kiosk mode // This function inherits from UIThreadExtensionFunction because, unlike the
// and web UI. The method itself is not kiosk-mode only. // rest of this API, it's available on all platforms.
class SystemDisplayGetInfoFunction : public SystemDisplayFunction { class SystemDisplayGetInfoFunction : public UIThreadExtensionFunction {
public: public:
DECLARE_EXTENSION_FUNCTION("system.display.getInfo", SYSTEM_DISPLAY_GETINFO); DECLARE_EXTENSION_FUNCTION("system.display.getInfo", SYSTEM_DISPLAY_GETINFO);
protected: protected:
~SystemDisplayGetInfoFunction() override {} ~SystemDisplayGetInfoFunction() override {}
bool PreRunValidation(std::string* error) override;
ResponseAction Run() override; ResponseAction Run() override;
void Response(DisplayInfoProvider::DisplayUnitInfoList all_displays_info); void Response(DisplayInfoProvider::DisplayUnitInfoList all_displays_info);
}; };
class SystemDisplayGetDisplayLayoutFunction : public SystemDisplayFunction { class SystemDisplayGetDisplayLayoutFunction
: public SystemDisplayCrOSRestrictedFunction {
public: public:
DECLARE_EXTENSION_FUNCTION("system.display.getDisplayLayout", DECLARE_EXTENSION_FUNCTION("system.display.getDisplayLayout",
SYSTEM_DISPLAY_GETDISPLAYLAYOUT); SYSTEM_DISPLAY_GETDISPLAYLAYOUT);
...@@ -54,7 +54,8 @@ class SystemDisplayGetDisplayLayoutFunction : public SystemDisplayFunction { ...@@ -54,7 +54,8 @@ class SystemDisplayGetDisplayLayoutFunction : public SystemDisplayFunction {
void Response(DisplayInfoProvider::DisplayLayoutList display_layout); void Response(DisplayInfoProvider::DisplayLayoutList display_layout);
}; };
class SystemDisplaySetDisplayPropertiesFunction : public SystemDisplayFunction { class SystemDisplaySetDisplayPropertiesFunction
: public SystemDisplayCrOSRestrictedFunction {
public: public:
DECLARE_EXTENSION_FUNCTION("system.display.setDisplayProperties", DECLARE_EXTENSION_FUNCTION("system.display.setDisplayProperties",
SYSTEM_DISPLAY_SETDISPLAYPROPERTIES); SYSTEM_DISPLAY_SETDISPLAYPROPERTIES);
...@@ -66,7 +67,8 @@ class SystemDisplaySetDisplayPropertiesFunction : public SystemDisplayFunction { ...@@ -66,7 +67,8 @@ class SystemDisplaySetDisplayPropertiesFunction : public SystemDisplayFunction {
void Response(base::Optional<std::string> error); void Response(base::Optional<std::string> error);
}; };
class SystemDisplaySetDisplayLayoutFunction : public SystemDisplayFunction { class SystemDisplaySetDisplayLayoutFunction
: public SystemDisplayCrOSRestrictedFunction {
public: public:
DECLARE_EXTENSION_FUNCTION("system.display.setDisplayLayout", DECLARE_EXTENSION_FUNCTION("system.display.setDisplayLayout",
SYSTEM_DISPLAY_SETDISPLAYLAYOUT); SYSTEM_DISPLAY_SETDISPLAYLAYOUT);
...@@ -78,7 +80,8 @@ class SystemDisplaySetDisplayLayoutFunction : public SystemDisplayFunction { ...@@ -78,7 +80,8 @@ class SystemDisplaySetDisplayLayoutFunction : public SystemDisplayFunction {
void Response(base::Optional<std::string> error); void Response(base::Optional<std::string> error);
}; };
class SystemDisplayEnableUnifiedDesktopFunction : public SystemDisplayFunction { class SystemDisplayEnableUnifiedDesktopFunction
: public SystemDisplayCrOSRestrictedFunction {
public: public:
DECLARE_EXTENSION_FUNCTION("system.display.enableUnifiedDesktop", DECLARE_EXTENSION_FUNCTION("system.display.enableUnifiedDesktop",
SYSTEM_DISPLAY_ENABLEUNIFIEDDESKTOP); SYSTEM_DISPLAY_ENABLEUNIFIEDDESKTOP);
...@@ -89,7 +92,7 @@ class SystemDisplayEnableUnifiedDesktopFunction : public SystemDisplayFunction { ...@@ -89,7 +92,7 @@ class SystemDisplayEnableUnifiedDesktopFunction : public SystemDisplayFunction {
}; };
class SystemDisplayOverscanCalibrationStartFunction class SystemDisplayOverscanCalibrationStartFunction
: public SystemDisplayFunction { : public SystemDisplayCrOSRestrictedFunction {
public: public:
DECLARE_EXTENSION_FUNCTION("system.display.overscanCalibrationStart", DECLARE_EXTENSION_FUNCTION("system.display.overscanCalibrationStart",
SYSTEM_DISPLAY_OVERSCANCALIBRATIONSTART); SYSTEM_DISPLAY_OVERSCANCALIBRATIONSTART);
...@@ -100,7 +103,7 @@ class SystemDisplayOverscanCalibrationStartFunction ...@@ -100,7 +103,7 @@ class SystemDisplayOverscanCalibrationStartFunction
}; };
class SystemDisplayOverscanCalibrationAdjustFunction class SystemDisplayOverscanCalibrationAdjustFunction
: public SystemDisplayFunction { : public SystemDisplayCrOSRestrictedFunction {
public: public:
DECLARE_EXTENSION_FUNCTION("system.display.overscanCalibrationAdjust", DECLARE_EXTENSION_FUNCTION("system.display.overscanCalibrationAdjust",
SYSTEM_DISPLAY_OVERSCANCALIBRATIONADJUST); SYSTEM_DISPLAY_OVERSCANCALIBRATIONADJUST);
...@@ -111,7 +114,7 @@ class SystemDisplayOverscanCalibrationAdjustFunction ...@@ -111,7 +114,7 @@ class SystemDisplayOverscanCalibrationAdjustFunction
}; };
class SystemDisplayOverscanCalibrationResetFunction class SystemDisplayOverscanCalibrationResetFunction
: public SystemDisplayFunction { : public SystemDisplayCrOSRestrictedFunction {
public: public:
DECLARE_EXTENSION_FUNCTION("system.display.overscanCalibrationReset", DECLARE_EXTENSION_FUNCTION("system.display.overscanCalibrationReset",
SYSTEM_DISPLAY_OVERSCANCALIBRATIONRESET); SYSTEM_DISPLAY_OVERSCANCALIBRATIONRESET);
...@@ -122,7 +125,7 @@ class SystemDisplayOverscanCalibrationResetFunction ...@@ -122,7 +125,7 @@ class SystemDisplayOverscanCalibrationResetFunction
}; };
class SystemDisplayOverscanCalibrationCompleteFunction class SystemDisplayOverscanCalibrationCompleteFunction
: public SystemDisplayFunction { : public SystemDisplayCrOSRestrictedFunction {
public: public:
DECLARE_EXTENSION_FUNCTION("system.display.overscanCalibrationComplete", DECLARE_EXTENSION_FUNCTION("system.display.overscanCalibrationComplete",
SYSTEM_DISPLAY_OVERSCANCALIBRATIONCOMPLETE); SYSTEM_DISPLAY_OVERSCANCALIBRATIONCOMPLETE);
...@@ -133,7 +136,7 @@ class SystemDisplayOverscanCalibrationCompleteFunction ...@@ -133,7 +136,7 @@ class SystemDisplayOverscanCalibrationCompleteFunction
}; };
class SystemDisplayShowNativeTouchCalibrationFunction class SystemDisplayShowNativeTouchCalibrationFunction
: public SystemDisplayFunction { : public SystemDisplayCrOSRestrictedFunction {
public: public:
DECLARE_EXTENSION_FUNCTION("system.display.showNativeTouchCalibration", DECLARE_EXTENSION_FUNCTION("system.display.showNativeTouchCalibration",
SYSTEM_DISPLAY_SHOWNATIVETOUCHCALIBRATION); SYSTEM_DISPLAY_SHOWNATIVETOUCHCALIBRATION);
...@@ -146,7 +149,7 @@ class SystemDisplayShowNativeTouchCalibrationFunction ...@@ -146,7 +149,7 @@ class SystemDisplayShowNativeTouchCalibrationFunction
}; };
class SystemDisplayStartCustomTouchCalibrationFunction class SystemDisplayStartCustomTouchCalibrationFunction
: public SystemDisplayFunction { : public SystemDisplayCrOSRestrictedFunction {
public: public:
DECLARE_EXTENSION_FUNCTION("system.display.startCustomTouchCalibration", DECLARE_EXTENSION_FUNCTION("system.display.startCustomTouchCalibration",
SYSTEM_DISPLAY_STARTCUSTOMTOUCHCALIBRATION); SYSTEM_DISPLAY_STARTCUSTOMTOUCHCALIBRATION);
...@@ -157,7 +160,7 @@ class SystemDisplayStartCustomTouchCalibrationFunction ...@@ -157,7 +160,7 @@ class SystemDisplayStartCustomTouchCalibrationFunction
}; };
class SystemDisplayCompleteCustomTouchCalibrationFunction class SystemDisplayCompleteCustomTouchCalibrationFunction
: public SystemDisplayFunction { : public SystemDisplayCrOSRestrictedFunction {
public: public:
DECLARE_EXTENSION_FUNCTION("system.display.completeCustomTouchCalibration", DECLARE_EXTENSION_FUNCTION("system.display.completeCustomTouchCalibration",
SYSTEM_DISPLAY_COMPLETECUSTOMTOUCHCALIBRATION); SYSTEM_DISPLAY_COMPLETECUSTOMTOUCHCALIBRATION);
...@@ -168,7 +171,7 @@ class SystemDisplayCompleteCustomTouchCalibrationFunction ...@@ -168,7 +171,7 @@ class SystemDisplayCompleteCustomTouchCalibrationFunction
}; };
class SystemDisplayClearTouchCalibrationFunction class SystemDisplayClearTouchCalibrationFunction
: public SystemDisplayFunction { : public SystemDisplayCrOSRestrictedFunction {
public: public:
DECLARE_EXTENSION_FUNCTION("system.display.clearTouchCalibration", DECLARE_EXTENSION_FUNCTION("system.display.clearTouchCalibration",
SYSTEM_DISPLAY_CLEARTOUCHCALIBRATION); SYSTEM_DISPLAY_CLEARTOUCHCALIBRATION);
...@@ -178,7 +181,8 @@ class SystemDisplayClearTouchCalibrationFunction ...@@ -178,7 +181,8 @@ class SystemDisplayClearTouchCalibrationFunction
ResponseAction Run() override; ResponseAction Run() override;
}; };
class SystemDisplaySetMirrorModeFunction : public SystemDisplayFunction { class SystemDisplaySetMirrorModeFunction
: public SystemDisplayCrOSRestrictedFunction {
public: public:
DECLARE_EXTENSION_FUNCTION("system.display.setMirrorMode", DECLARE_EXTENSION_FUNCTION("system.display.setMirrorMode",
SYSTEM_DISPLAY_SETMIRRORMODE); SYSTEM_DISPLAY_SETMIRRORMODE);
......
...@@ -247,7 +247,7 @@ IN_PROC_BROWSER_TEST_F(SystemDisplayApiTest, SetDisplay) { ...@@ -247,7 +247,7 @@ IN_PROC_BROWSER_TEST_F(SystemDisplayApiTest, SetDisplay) {
set_info_function->set_has_callback(true); set_info_function->set_has_callback(true);
EXPECT_EQ( EXPECT_EQ(
SystemDisplayFunction::kCrosOnlyError, SystemDisplayCrOSRestrictedFunction::kCrosOnlyError,
api_test_utils::RunFunctionAndReturnError( api_test_utils::RunFunctionAndReturnError(
set_info_function.get(), "[\"display_id\", {}]", browser_context())); set_info_function.get(), "[\"display_id\", {}]", browser_context()));
...@@ -297,7 +297,7 @@ IN_PROC_BROWSER_TEST_F(SystemDisplayApiTest, SetDisplayNotKioskEnabled) { ...@@ -297,7 +297,7 @@ IN_PROC_BROWSER_TEST_F(SystemDisplayApiTest, SetDisplayNotKioskEnabled) {
set_info_function->set_has_callback(true); set_info_function->set_has_callback(true);
EXPECT_EQ( EXPECT_EQ(
SystemDisplayFunction::kKioskOnlyError, SystemDisplayCrOSRestrictedFunction::kKioskOnlyError,
api_test_utils::RunFunctionAndReturnError( api_test_utils::RunFunctionAndReturnError(
set_info_function.get(), "[\"display_id\", {}]", browser_context())); set_info_function.get(), "[\"display_id\", {}]", browser_context()));
......
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