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. 4 5#include "chrome/browser/ui/webui/chromeos/login/screenlock_icon_source.h" 6 7#include "chrome/browser/chromeos/login/lock/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" 11 12namespace { 13 14gfx::Image GetDefaultIcon() { 15 return gfx::Image(); 16} 17 18} // namespace 19 20namespace chromeos { 21 22//////////////////////////////////////////////////////////////////////////////// 23// ScreenlockIconSource 24 25ScreenlockIconSource::ScreenlockIconSource( 26 base::WeakPtr<ScreenlockIconProvider> icon_provider) 27 : icon_provider_(icon_provider) { 28} 29 30ScreenlockIconSource::~ScreenlockIconSource() {} 31 32std::string ScreenlockIconSource::GetSource() const { 33 return std::string(chrome::kChromeUIScreenlockIconHost); 34} 35 36void 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().get()); 43 return; 44 } 45 46 GURL url(chrome::kChromeUIScreenlockIconURL + path); 47 std::string username = net::UnescapeURLComponent( 48 url.path().substr(1), 49 net::UnescapeRule::URL_SPECIAL_CHARS | net::UnescapeRule::SPACES); 50 51 gfx::Image image = icon_provider_->GetIcon(username); 52 if (image.IsEmpty()) { 53 callback.Run(GetDefaultIcon().As1xPNGBytes().get()); 54 return; 55 } 56 57 callback.Run(image.As1xPNGBytes().get()); 58} 59 60std::string ScreenlockIconSource::GetMimeType(const std::string&) const { 61 return "image/png"; 62} 63 64// static. 65std::string ScreenlockIconSource::GetIconURLForUser( 66 const std::string& username) { 67 return std::string(chrome::kChromeUIScreenlockIconURL) + 68 net::EscapePath(username); 69} 70 71} // namespace chromeos 72