Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(125)

Side by Side Diff: chrome/browser/signin/screenlock_bridge.cc

Issue 446743003: Hook up new API for easy unlock to update lock screen (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/signin/screenlock_bridge.h" 5 #include "chrome/browser/signin/screenlock_bridge.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/strings/string16.h"
8 #include "chrome/browser/profiles/profile_window.h" 9 #include "chrome/browser/profiles/profile_window.h"
9 #include "chrome/browser/signin/signin_manager_factory.h" 10 #include "chrome/browser/signin/signin_manager_factory.h"
10 #include "components/signin/core/browser/signin_manager.h" 11 #include "components/signin/core/browser/signin_manager.h"
12 #include "ui/base/webui/web_ui_util.h"
13 #include "ui/gfx/image/image.h"
14 #include "ui/gfx/image/image_skia.h"
11 15
12 #if defined(OS_CHROMEOS) 16 #if defined(OS_CHROMEOS)
13 #include "chromeos/dbus/dbus_thread_manager.h" 17 #include "chromeos/dbus/dbus_thread_manager.h"
14 #include "chromeos/dbus/session_manager_client.h" 18 #include "chromeos/dbus/session_manager_client.h"
15 #endif 19 #endif
16 20
17 namespace { 21 namespace {
18 22
19 base::LazyInstance<ScreenlockBridge> g_screenlock_bridge_bridge_instance = 23 base::LazyInstance<ScreenlockBridge> g_screenlock_bridge_bridge_instance =
20 LAZY_INSTANCE_INITIALIZER; 24 LAZY_INSTANCE_INITIALIZER;
21 25
22 } // namespace 26 } // namespace
23 27
24 // static 28 // static
25 ScreenlockBridge* ScreenlockBridge::Get() { 29 ScreenlockBridge* ScreenlockBridge::Get() {
26 return g_screenlock_bridge_bridge_instance.Pointer(); 30 return g_screenlock_bridge_bridge_instance.Pointer();
27 } 31 }
28 32
33 ScreenlockBridge::UserPodCustomIconOptions::UserPodCustomIconOptions()
34 : width_(0u),
35 height_(0u),
36 animation_set_(false),
37 animation_resource_width_(0u),
38 animation_frame_length_ms_(0u),
39 opacity_(100u),
40 autoshow_tooltip_(false) {
41 }
42
43 ScreenlockBridge::UserPodCustomIconOptions::~UserPodCustomIconOptions() {}
44
45 scoped_ptr<base::DictionaryValue>
46 ScreenlockBridge::UserPodCustomIconOptions::ToDictionaryValue() const {
47 scoped_ptr<base::DictionaryValue> result(new base::DictionaryValue());
48 if (!icon_image_ && icon_resource_url_.empty())
49 return result.Pass();
50
51 if (icon_image_) {
52 gfx::ImageSkia icon_skia = icon_image_->AsImageSkia();
53 base::DictionaryValue* icon_representations = new base::DictionaryValue();
54 icon_representations->SetString(
55 "scale1x",
56 webui::GetBitmapDataUrl(
57 icon_skia.GetRepresentation(1.0f).sk_bitmap()));
58 icon_representations->SetString(
59 "scale2x",
60 webui::GetBitmapDataUrl(
61 icon_skia.GetRepresentation(2.0f).sk_bitmap()));
62 result->Set("data", icon_representations);
63 } else {
64 result->SetString("resourceUrl", icon_resource_url_);
65 }
66
67 if (!tooltip_.empty()) {
68 base::DictionaryValue* tooltip_options = new base::DictionaryValue();
69 tooltip_options->SetString("text", tooltip_);
70 tooltip_options->SetBoolean("autoshow", autoshow_tooltip_);
71 result->Set("tooltip", tooltip_options);
72 }
73
74 base::DictionaryValue* size = new base::DictionaryValue();
75 size->SetInteger("height", height_);
76 size->SetInteger("width", width_);
77 result->Set("size", size);
78
79 result->SetInteger("opacity", opacity_);
80
81 if (animation_set_) {
82 base::DictionaryValue* animation = new base::DictionaryValue();
83 animation->SetInteger("resourceWidth",
84 animation_resource_width_);
85 animation->SetInteger("frameLengthMs",
86 animation_frame_length_ms_);
87 result->Set("animation", animation);
88 }
89 return result.Pass();
90 }
91
92 void ScreenlockBridge::UserPodCustomIconOptions::SetIconAsResourceURL(
93 const std::string& url) {
94 DCHECK(!icon_image_);
95
96 icon_resource_url_ = url;
97 }
98
99 void ScreenlockBridge::UserPodCustomIconOptions::SetIconAsImage(
100 const gfx::Image& image) {
101 DCHECK(icon_resource_url_.empty());
102
103 icon_image_.reset(new gfx::Image(image));
104 SetSize(image.Width(), image.Height());
105 }
106
107 void ScreenlockBridge::UserPodCustomIconOptions::SetSize(size_t icon_width,
108 size_t icon_height) {
109 width_ = icon_width;
110 height_ = icon_height;
111 }
112
113 void ScreenlockBridge::UserPodCustomIconOptions::SetAnimation(
114 size_t resource_width,
115 size_t frame_length_ms) {
116 animation_set_ = true;
117 animation_resource_width_ = resource_width;
118 animation_frame_length_ms_ = frame_length_ms;
119 }
120
121 void ScreenlockBridge::UserPodCustomIconOptions::SetOpacity(size_t opacity) {
122 DCHECK_LE(opacity, 100u);
123 opacity_ = opacity;
124 }
125
126 void ScreenlockBridge::UserPodCustomIconOptions::SetTooltip(
127 const base::string16& tooltip,
128 bool autoshow) {
129 tooltip_ = tooltip;
130 autoshow_tooltip_ = autoshow;
131 }
132
29 // static 133 // static
30 std::string ScreenlockBridge::GetAuthenticatedUserEmail(Profile* profile) { 134 std::string ScreenlockBridge::GetAuthenticatedUserEmail(Profile* profile) {
31 // |profile| has to be a signed-in profile with SigninManager already 135 // |profile| has to be a signed-in profile with SigninManager already
32 // created. Otherwise, just crash to collect stack. 136 // created. Otherwise, just crash to collect stack.
33 SigninManagerBase* signin_manager = 137 SigninManagerBase* signin_manager =
34 SigninManagerFactory::GetForProfileIfExists(profile); 138 SigninManagerFactory::GetForProfileIfExists(profile);
35 return signin_manager->GetAuthenticatedUsername(); 139 return signin_manager->GetAuthenticatedUsername();
36 } 140 }
37 141
38 ScreenlockBridge::ScreenlockBridge() : lock_handler_(NULL) { 142 ScreenlockBridge::ScreenlockBridge() : lock_handler_(NULL) {
(...skipping 30 matching lines...) Expand all
69 lock_handler_->Unlock(GetAuthenticatedUserEmail(profile)); 173 lock_handler_->Unlock(GetAuthenticatedUserEmail(profile));
70 } 174 }
71 175
72 void ScreenlockBridge::AddObserver(Observer* observer) { 176 void ScreenlockBridge::AddObserver(Observer* observer) {
73 observers_.AddObserver(observer); 177 observers_.AddObserver(observer);
74 } 178 }
75 179
76 void ScreenlockBridge::RemoveObserver(Observer* observer) { 180 void ScreenlockBridge::RemoveObserver(Observer* observer) {
77 observers_.RemoveObserver(observer); 181 observers_.RemoveObserver(observer);
78 } 182 }
OLDNEW
« no previous file with comments | « chrome/browser/signin/screenlock_bridge.h ('k') | chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698