Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / ui / webui / chromeos / login / screenlock_icon_source.cc
blob71c2f0b2cf1e1aeac04db67351100ab79fa2bdfd
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/webui/chromeos/login/screenlock_icon_source.h"
7 #include "chrome/browser/chromeos/login/screen_locker.h"
8 #include "chrome/browser/ui/webui/chromeos/login/screenlock_icon_provider.h"
9 #include "chrome/common/url_constants.h"
10 #include "net/base/escape.h"
12 namespace {
14 gfx::Image GetDefaultIcon() {
15 return gfx::Image();
18 } // namespace
20 namespace chromeos {
22 ////////////////////////////////////////////////////////////////////////////////
23 // ScreenlockIconSource
25 ScreenlockIconSource::ScreenlockIconSource(
26 base::WeakPtr<ScreenlockIconProvider> icon_provider)
27 : icon_provider_(icon_provider) {
30 ScreenlockIconSource::~ScreenlockIconSource() {}
32 std::string ScreenlockIconSource::GetSource() const {
33 return std::string(chrome::kChromeUIScreenlockIconHost);
36 void ScreenlockIconSource::StartDataRequest(
37 const std::string& path,
38 int render_process_id,
39 int render_frame_id,
40 const content::URLDataSource::GotDataCallback& callback) {
41 if (!icon_provider_) {
42 callback.Run(GetDefaultIcon().As1xPNGBytes());
43 return;
46 std::string username = net::UnescapeURLComponent(
47 path,
48 net::UnescapeRule::URL_SPECIAL_CHARS | net::UnescapeRule::SPACES);
50 gfx::Image image = icon_provider_->GetIcon(username);
51 if (image.IsEmpty()) {
52 callback.Run(GetDefaultIcon().As1xPNGBytes());
53 return;
56 callback.Run(image.As1xPNGBytes().get());
59 std::string ScreenlockIconSource::GetMimeType(const std::string&) const {
60 return "image/png";
63 // static.
64 std::string ScreenlockIconSource::GetIconURLForUser(
65 const std::string& username) {
66 return std::string(chrome::kChromeUIScreenlockIconURL) +
67 net::EscapePath(username);
70 } // namespace chromeos