Commit 15ce5fef authored by tbarzic's avatar tbarzic Committed by Commit bot

Remove unused chrome.screenlockPrivate methods

TEST=Tested that easy unlock still works
BUG=None

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

Cr-Commit-Position: refs/heads/master@{#295216}
parent caf87444
......@@ -4,16 +4,11 @@
#include "chrome/browser/extensions/api/screenlock_private/screenlock_private_api.h"
#include <vector>
#include "base/lazy_instance.h"
#include "base/strings/utf_string_conversions.h"
#include "base/values.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/extensions/api/screenlock_private.h"
#include "extensions/browser/event_router.h"
#include "extensions/browser/image_loader.h"
#include "ui/gfx/image/image.h"
namespace screenlock = extensions::api::screenlock_private;
......@@ -22,23 +17,6 @@ namespace extensions {
namespace {
const char kNotLockedError[] = "Screen is not currently locked.";
const char kInvalidIconError[] = "Invalid custom icon data.";
ScreenlockBridge::LockHandler::AuthType ToLockHandlerAuthType(
screenlock::AuthType auth_type) {
switch (auth_type) {
case screenlock::AUTH_TYPE_OFFLINEPASSWORD:
return ScreenlockBridge::LockHandler::OFFLINE_PASSWORD;
case screenlock::AUTH_TYPE_NUMERICPIN:
return ScreenlockBridge::LockHandler::NUMERIC_PIN;
case screenlock::AUTH_TYPE_USERCLICK:
return ScreenlockBridge::LockHandler::USER_CLICK;
case screenlock::AUTH_TYPE_NONE:
break;
}
NOTREACHED();
return ScreenlockBridge::LockHandler::OFFLINE_PASSWORD;
}
screenlock::AuthType FromLockHandlerAuthType(
ScreenlockBridge::LockHandler::AuthType auth_type) {
......@@ -92,165 +70,6 @@ bool ScreenlockPrivateSetLockedFunction::RunAsync() {
return true;
}
ScreenlockPrivateShowMessageFunction::ScreenlockPrivateShowMessageFunction() {}
ScreenlockPrivateShowMessageFunction::~ScreenlockPrivateShowMessageFunction() {}
bool ScreenlockPrivateShowMessageFunction::RunAsync() {
scoped_ptr<screenlock::ShowMessage::Params> params(
screenlock::ShowMessage::Params::Create(*args_));
EXTENSION_FUNCTION_VALIDATE(params.get());
ScreenlockBridge::LockHandler* locker =
ScreenlockBridge::Get()->lock_handler();
if (locker)
locker->ShowBannerMessage(base::UTF8ToUTF16(params->message));
SendResponse(error_.empty());
return true;
}
ScreenlockPrivateShowCustomIconFunction::
ScreenlockPrivateShowCustomIconFunction() {}
ScreenlockPrivateShowCustomIconFunction::
~ScreenlockPrivateShowCustomIconFunction() {}
bool ScreenlockPrivateShowCustomIconFunction::RunAsync() {
scoped_ptr<screenlock::ShowCustomIcon::Params> params(
screenlock::ShowCustomIcon::Params::Create(*args_));
EXTENSION_FUNCTION_VALIDATE(params.get());
ScreenlockBridge::LockHandler* locker =
ScreenlockBridge::Get()->lock_handler();
if (!locker) {
SetError(kNotLockedError);
return false;
}
const int kMaxButtonIconSize = 40;
bool has_scale_100P = false;
std::vector<extensions::ImageLoader::ImageRepresentation> icon_info;
for (size_t i = 0; i < params->icon.size(); ++i) {
ui::ScaleFactor scale_factor;
if (params->icon[i]->scale_factor == 1.) {
scale_factor = ui::SCALE_FACTOR_100P;
} else if (params->icon[i]->scale_factor == 2.) {
scale_factor = ui::SCALE_FACTOR_200P;
} else {
continue;
}
ExtensionResource resource = extension()->GetResource(params->icon[i]->url);
if (resource.empty())
continue;
icon_info.push_back(
ImageLoader::ImageRepresentation(
resource,
ImageLoader::ImageRepresentation::RESIZE_WHEN_LARGER,
gfx::Size(kMaxButtonIconSize * params->icon[i]->scale_factor,
kMaxButtonIconSize * params->icon[i]->scale_factor),
scale_factor));
if (scale_factor == ui::SCALE_FACTOR_100P)
has_scale_100P = true;
}
if (!has_scale_100P) {
SetError(kInvalidIconError);
return false;
}
extensions::ImageLoader* loader = extensions::ImageLoader::Get(GetProfile());
loader->LoadImagesAsync(
extension(),
icon_info,
base::Bind(&ScreenlockPrivateShowCustomIconFunction::OnImageLoaded,
this));
return true;
}
void ScreenlockPrivateShowCustomIconFunction::OnImageLoaded(
const gfx::Image& image) {
ScreenlockBridge::LockHandler* locker =
ScreenlockBridge::Get()->lock_handler();
if (!locker) {
SetError(kNotLockedError);
SendResponse(false);
return;
}
ScreenlockBridge::UserPodCustomIconOptions icon;
icon.SetIconAsImage(image);
locker->ShowUserPodCustomIcon(
ScreenlockBridge::GetAuthenticatedUserEmail(GetProfile()),
icon);
SendResponse(error_.empty());
}
ScreenlockPrivateHideCustomIconFunction::
ScreenlockPrivateHideCustomIconFunction() {
}
ScreenlockPrivateHideCustomIconFunction::
~ScreenlockPrivateHideCustomIconFunction() {
}
bool ScreenlockPrivateHideCustomIconFunction::RunAsync() {
ScreenlockBridge::LockHandler* locker =
ScreenlockBridge::Get()->lock_handler();
if (locker) {
locker->HideUserPodCustomIcon(
ScreenlockBridge::GetAuthenticatedUserEmail(GetProfile()));
} else {
SetError(kNotLockedError);
}
SendResponse(error_.empty());
return true;
}
ScreenlockPrivateSetAuthTypeFunction::ScreenlockPrivateSetAuthTypeFunction() {}
ScreenlockPrivateSetAuthTypeFunction::~ScreenlockPrivateSetAuthTypeFunction() {}
bool ScreenlockPrivateSetAuthTypeFunction::RunAsync() {
scoped_ptr<screenlock::SetAuthType::Params> params(
screenlock::SetAuthType::Params::Create(*args_));
EXTENSION_FUNCTION_VALIDATE(params.get());
ScreenlockBridge::LockHandler* locker =
ScreenlockBridge::Get()->lock_handler();
if (locker) {
std::string initial_value =
params->initial_value.get() ? *(params->initial_value.get()) : "";
locker->SetAuthType(
ScreenlockBridge::GetAuthenticatedUserEmail(GetProfile()),
ToLockHandlerAuthType(params->auth_type),
base::UTF8ToUTF16(initial_value));
} else {
SetError(kNotLockedError);
}
SendResponse(error_.empty());
return true;
}
ScreenlockPrivateGetAuthTypeFunction::ScreenlockPrivateGetAuthTypeFunction() {}
ScreenlockPrivateGetAuthTypeFunction::~ScreenlockPrivateGetAuthTypeFunction() {}
bool ScreenlockPrivateGetAuthTypeFunction::RunAsync() {
ScreenlockBridge::LockHandler* locker =
ScreenlockBridge::Get()->lock_handler();
if (locker) {
ScreenlockBridge::LockHandler::AuthType auth_type = locker->GetAuthType(
ScreenlockBridge::GetAuthenticatedUserEmail(GetProfile()));
std::string auth_type_name =
screenlock::ToString(FromLockHandlerAuthType(auth_type));
SetResult(new base::StringValue(auth_type_name));
} else {
SetError(kNotLockedError);
}
SendResponse(error_.empty());
return true;
}
ScreenlockPrivateAcceptAuthAttemptFunction::
ScreenlockPrivateAcceptAuthAttemptFunction() {}
......
......@@ -11,10 +11,6 @@
#include "chrome/browser/signin/screenlock_bridge.h"
#include "extensions/browser/browser_context_keyed_api_factory.h"
namespace gfx {
class Image;
}
namespace extensions {
class ScreenlockPrivateGetLockedFunction : public ChromeAsyncExtensionFunction {
......@@ -41,73 +37,6 @@ class ScreenlockPrivateSetLockedFunction : public ChromeAsyncExtensionFunction {
DISALLOW_COPY_AND_ASSIGN(ScreenlockPrivateSetLockedFunction);
};
class ScreenlockPrivateShowMessageFunction
: public ChromeAsyncExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("screenlockPrivate.showMessage",
SCREENLOCKPRIVATE_SHOWMESSAGE)
ScreenlockPrivateShowMessageFunction();
virtual bool RunAsync() OVERRIDE;
private:
virtual ~ScreenlockPrivateShowMessageFunction();
DISALLOW_COPY_AND_ASSIGN(ScreenlockPrivateShowMessageFunction);
};
class ScreenlockPrivateShowCustomIconFunction
: public ChromeAsyncExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("screenlockPrivate.showCustomIcon",
SCREENLOCKPRIVATE_SHOWCUSTOMICON)
ScreenlockPrivateShowCustomIconFunction();
virtual bool RunAsync() OVERRIDE;
private:
virtual ~ScreenlockPrivateShowCustomIconFunction();
void OnImageLoaded(const gfx::Image& image);
DISALLOW_COPY_AND_ASSIGN(ScreenlockPrivateShowCustomIconFunction);
};
class ScreenlockPrivateHideCustomIconFunction
: public ChromeAsyncExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("screenlockPrivate.hideCustomIcon",
SCREENLOCKPRIVATE_HIDECUSTOMICON)
ScreenlockPrivateHideCustomIconFunction();
virtual bool RunAsync() OVERRIDE;
private:
virtual ~ScreenlockPrivateHideCustomIconFunction();
void OnImageLoaded(const gfx::Image& image);
DISALLOW_COPY_AND_ASSIGN(ScreenlockPrivateHideCustomIconFunction);
};
class ScreenlockPrivateSetAuthTypeFunction
: public ChromeAsyncExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("screenlockPrivate.setAuthType",
SCREENLOCKPRIVATE_SETAUTHTYPE)
ScreenlockPrivateSetAuthTypeFunction();
virtual bool RunAsync() OVERRIDE;
private:
virtual ~ScreenlockPrivateSetAuthTypeFunction();
DISALLOW_COPY_AND_ASSIGN(ScreenlockPrivateSetAuthTypeFunction);
};
class ScreenlockPrivateGetAuthTypeFunction
: public ChromeAsyncExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("screenlockPrivate.getAuthType",
SCREENLOCKPRIVATE_GETAUTHTYPE)
ScreenlockPrivateGetAuthTypeFunction();
virtual bool RunAsync() OVERRIDE;
private:
virtual ~ScreenlockPrivateGetAuthTypeFunction();
DISALLOW_COPY_AND_ASSIGN(ScreenlockPrivateGetAuthTypeFunction);
};
class ScreenlockPrivateAcceptAuthAttemptFunction
: public ChromeAsyncExtensionFunction {
public:
......
......@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/strings/string16.h"
#include "chrome/browser/extensions/api/screenlock_private/screenlock_private_api.h"
#include "chrome/browser/extensions/extension_apitest.h"
#include "chrome/browser/signin/signin_manager_factory.h"
......@@ -63,6 +64,10 @@ class ScreenlockPrivateApiTest : public ExtensionApiTest,
const content::NotificationDetails& details) OVERRIDE {
const std::string& content = *content::Details<std::string>(details).ptr();
if (content == kAttemptClickAuthMessage) {
ScreenlockBridge::Get()->lock_handler()->SetAuthType(
kTestUser,
ScreenlockBridge::LockHandler::USER_CLICK,
base::string16());
extensions::ScreenlockPrivateEventRouter* router =
extensions::ScreenlockPrivateEventRouter::GetFactoryInstance()->Get(
profile());
......
......@@ -9,9 +9,6 @@
#include "chrome/browser/profiles/profile_window.h"
#include "chrome/browser/signin/signin_manager_factory.h"
#include "components/signin/core/browser/signin_manager.h"
#include "ui/base/webui/web_ui_util.h"
#include "ui/gfx/image/image.h"
#include "ui/gfx/image/image_skia.h"
#if defined(OS_CHROMEOS)
#include "chromeos/dbus/dbus_thread_manager.h"
......@@ -46,24 +43,10 @@ ScreenlockBridge::UserPodCustomIconOptions::~UserPodCustomIconOptions() {}
scoped_ptr<base::DictionaryValue>
ScreenlockBridge::UserPodCustomIconOptions::ToDictionaryValue() const {
scoped_ptr<base::DictionaryValue> result(new base::DictionaryValue());
if (!icon_image_ && icon_resource_url_.empty())
if (icon_resource_url_.empty())
return result.Pass();
if (icon_image_) {
gfx::ImageSkia icon_skia = icon_image_->AsImageSkia();
base::DictionaryValue* icon_representations = new base::DictionaryValue();
icon_representations->SetString(
"scale1x",
webui::GetBitmapDataUrl(
icon_skia.GetRepresentation(1.0f).sk_bitmap()));
icon_representations->SetString(
"scale2x",
webui::GetBitmapDataUrl(
icon_skia.GetRepresentation(2.0f).sk_bitmap()));
result->Set("data", icon_representations);
} else {
result->SetString("resourceUrl", icon_resource_url_);
}
result->SetString("resourceUrl", icon_resource_url_);
if (!tooltip_.empty()) {
base::DictionaryValue* tooltip_options = new base::DictionaryValue();
......@@ -96,18 +79,9 @@ ScreenlockBridge::UserPodCustomIconOptions::ToDictionaryValue() const {
void ScreenlockBridge::UserPodCustomIconOptions::SetIconAsResourceURL(
const std::string& url) {
DCHECK(!icon_image_);
icon_resource_url_ = url;
}
void ScreenlockBridge::UserPodCustomIconOptions::SetIconAsImage(
const gfx::Image& image) {
DCHECK(icon_resource_url_.empty());
icon_image_.reset(new gfx::Image(image));
SetSize(image.Width(), image.Height());
}
void ScreenlockBridge::UserPodCustomIconOptions::SetSize(size_t icon_width,
size_t icon_height) {
......
......@@ -15,9 +15,6 @@
#include "base/strings/string16.h"
#include "base/values.h"
namespace gfx {
class Image;
}
class Profile;
......@@ -50,21 +47,14 @@ class ScreenlockBridge {
// Sets the icon as chrome://theme resource URL.
void SetIconAsResourceURL(const std::string& url);
// Sets the icon as a gfx::Image. The image will be converted to set of data
// URLs for each icon representation. Use |SetIconAsResourceURL| instead of
// this.
// TODO(tbarzic): Remove this one once easy unlock app stops using
// screenlockPrivate.showCustomIcon.
void SetIconAsImage(const gfx::Image& image);
// Sets the icon size. Has to be called if |SetIconAsResourceURL| was used
// to set the icon. For animated icon, this should be set to a single frame
// size, not the animation resource size.
// Sets the icon size. If not called, the icon will not be visible.
// For animated icon, this should be set to a single frame size, not the
// animation resource size.
void SetSize(size_t icon_width, size_t icon_height);
// If the icon is supposed to be animated, sets the animation parameters.
// If set, it expects that the resource set using |SetIcon*| methods
// contains horizontally arranged ordered list of animation frames.
// If set, it expects that the resource set using |SetIconAsResourceURL|
// method contains horizontally arranged ordered list of animation frames.
// Note that the icon size set in |SetSize| should be a single frame size.
// |resource_width|: Total animation resource width.
// |frame_length_ms|: Time for which a single animation frame is shown.
......@@ -84,7 +74,6 @@ class ScreenlockBridge {
private:
std::string icon_resource_url_;
scoped_ptr<gfx::Image> icon_image_;
size_t width_;
size_t height_;
......
......@@ -16,16 +16,7 @@ namespace screenlockPrivate {
// in the password field.
enum AuthType {offlinePassword, numericPin, userClick};
// Extension resource for a icon representation for a scale factor.
dictionary IconRepresentation {
// The scale factor the representation is for.
double scaleFactor;
// The image resource URL.
DOMString url;
};
callback BooleanCallback = void(boolean locked);
callback AuthTypeCallback = void(AuthType authType);
interface Functions {
// Returns true if the screen is currently locked, false otherwise.
......@@ -35,27 +26,6 @@ namespace screenlockPrivate {
// <code>locked=false</code> to unlock it.
static void setLocked(boolean locked);
// Show a message to the user on the unlock UI if the screen is locked.
static void showMessage(DOMString message);
// Show a custom icon beside the input field on the user pod.
// |icon|: Extension resoucres for the icon's multi-scale representations.
// Currently, only scales 1 and 2 are supported. The list must have a
// resource for at least scale 1.
static void showCustomIcon(IconRepresentation[] icon);
// Hides the custom icon added by $(ref:showCustomIcon)().
static void hideCustomIcon();
// Returns the current auth type used for the user pod.
static void getAuthType(AuthTypeCallback callback);
// Set the type of the authentication for the user pod. The input field
// area of the user pod below the user's portrait will be changed.
// |authType|: The type of authentication to use.
// |initialValue|: The initial value to populate the input field.
static void setAuthType(AuthType authType, optional DOMString initialValue);
// Accepts or rejects the current auth attempt.
static void acceptAuthAttempt(boolean accept);
};
......
......@@ -4,17 +4,9 @@
var authAttempted = false;
function setAuthType() {
chrome.screenlockPrivate.setAuthType('userClick');
chrome.screenlockPrivate.getAuthType(function(authType) {
chrome.test.assertEq('userClick', authType);
chrome.test.sendMessage('attemptClickAuth');
});
}
chrome.screenlockPrivate.onChanged.addListener(function(locked) {
if (locked && !authAttempted) {
setAuthType();
chrome.test.sendMessage('attemptClickAuth');
} else if (!locked && authAttempted) {
chrome.test.succeed();
} else {
......
......@@ -303,19 +303,6 @@ cr.define('login', function() {
return this.querySelector('.custom-icon');
},
/**
* Set the icon's background image as image set with different
* representations for available screen scale factors.
* @param {!{scale1x: string, scale2x: string}} icon The icon
* representations.
*/
setIconAsImageSet: function(icon) {
this.iconElement.style.backgroundImage =
'-webkit-image-set(' +
'url(' + icon.scale1x + ') 1x,' +
'url(' + icon.scale2x + ') 2x)';
},
/**
* Sets the icon background image to a chrome://theme URL.
* @param {!string} iconUrl The icon's background image URL.
......@@ -2310,14 +2297,10 @@ cr.define('login', function() {
return;
}
if (icon.resourceUrl) {
pod.customIconElement.setIconAsResourceUrl(icon.resourceUrl);
} else if (icon.data) {
pod.customIconElement.setIconAsImageSet(icon.data);
} else {
if (!icon.resourceUrl)
return;
}
pod.customIconElement.setIconAsResourceUrl(icon.resourceUrl);
pod.customIconElement.setSize(icon.size || {width: 0, height: 0});
pod.customIconElement.setAnimation(icon.animation || null);
pod.customIconElement.setOpacity(icon.opacity || 100);
......
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