45aafe113c38fad59434820146ad95b76a769b10
[platform/framework/web/crosswalk.git] / src / chrome / browser / chromeos / login / helper.cc
1 // Copyright (c) 2012 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/chromeos/login/helper.h"
6
7 #include "ash/shell.h"
8 #include "base/command_line.h"
9 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/grit/generated_resources.h"
11 #include "chrome/grit/theme_resources.h"
12 #include "chromeos/chromeos_switches.h"
13 #include "chromeos/network/network_handler.h"
14 #include "chromeos/network/network_state.h"
15 #include "chromeos/network/network_state_handler.h"
16 #include "third_party/cros_system_api/dbus/service_constants.h"
17 #include "ui/base/l10n/l10n_util.h"
18 #include "ui/gfx/image/image_skia.h"
19 #include "ui/gfx/screen.h"
20
21 namespace chromeos {
22
23 gfx::Rect CalculateScreenBounds(const gfx::Size& size) {
24   gfx::Rect bounds(ash::Shell::GetScreen()->GetPrimaryDisplay().bounds());
25   if (!size.IsEmpty()) {
26     int horizontal_diff = bounds.width() - size.width();
27     int vertical_diff = bounds.height() - size.height();
28     bounds.Inset(horizontal_diff / 2, vertical_diff / 2);
29   }
30   return bounds;
31 }
32
33 int GetCurrentUserImageSize() {
34   // The biggest size that the profile picture is displayed at is currently
35   // 220px, used for the big preview on OOBE and Change Picture options page.
36   static const int kBaseUserImageSize = 220;
37   float scale_factor = gfx::Display::GetForcedDeviceScaleFactor();
38   if (scale_factor > 1.0f)
39     return static_cast<int>(scale_factor * kBaseUserImageSize);
40   return kBaseUserImageSize * gfx::ImageSkia::GetMaxSupportedScale();
41 }
42
43 namespace login {
44
45 bool LoginScrollIntoViewEnabled() {
46   return !CommandLine::ForCurrentProcess()->HasSwitch(
47       chromeos::switches::kDisableLoginScrollIntoView);
48 }
49
50 NetworkStateHelper::NetworkStateHelper() {}
51 NetworkStateHelper::~NetworkStateHelper() {}
52
53 base::string16 NetworkStateHelper::GetCurrentNetworkName() const {
54   NetworkStateHandler* nsh = NetworkHandler::Get()->network_state_handler();
55   const NetworkState* network =
56       nsh->ConnectedNetworkByType(NetworkTypePattern::NonVirtual());
57   if (network) {
58     if (network->Matches(NetworkTypePattern::Ethernet()))
59       return l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_DEVICE_ETHERNET);
60     return base::UTF8ToUTF16(network->name());
61   }
62
63   network = nsh->ConnectingNetworkByType(NetworkTypePattern::NonVirtual());
64   if (network) {
65     if (network->Matches(NetworkTypePattern::Ethernet()))
66       return l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_DEVICE_ETHERNET);
67     return base::UTF8ToUTF16(network->name());
68   }
69   return base::string16();
70 }
71
72 bool NetworkStateHelper::IsConnected() const {
73   chromeos::NetworkStateHandler* nsh =
74       chromeos::NetworkHandler::Get()->network_state_handler();
75   return nsh->ConnectedNetworkByType(chromeos::NetworkTypePattern::Default()) !=
76          NULL;
77 }
78
79 bool NetworkStateHelper::IsConnecting() const {
80   chromeos::NetworkStateHandler* nsh =
81       chromeos::NetworkHandler::Get()->network_state_handler();
82   return nsh->ConnectingNetworkByType(
83       chromeos::NetworkTypePattern::Default()) != NULL;
84 }
85
86 }  // namespace login
87
88 }  // namespace chromeos