summaryrefslogtreecommitdiffstats
path: root/chrome/browser/chromeos/dom_ui
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser/chromeos/dom_ui')
-rw-r--r--chrome/browser/chromeos/dom_ui/accounts_options_handler.cc10
-rw-r--r--chrome/browser/chromeos/dom_ui/core_chromeos_options_handler.cc5
-rw-r--r--chrome/browser/chromeos/dom_ui/imageburner_ui.cc16
-rw-r--r--chrome/browser/chromeos/dom_ui/imageburner_ui.h14
-rw-r--r--chrome/browser/chromeos/dom_ui/internet_options_handler.cc372
-rw-r--r--chrome/browser/chromeos/dom_ui/internet_options_handler.h69
-rw-r--r--chrome/browser/chromeos/dom_ui/keyboard_overlay_ui.cc4
-rw-r--r--chrome/browser/chromeos/dom_ui/language_customize_modifier_keys_handler.cc2
-rw-r--r--chrome/browser/chromeos/dom_ui/language_options_handler.cc2
-rw-r--r--chrome/browser/chromeos/dom_ui/language_options_handler_unittest.cc14
-rw-r--r--chrome/browser/chromeos/dom_ui/login/authenticator_facade.h63
-rw-r--r--chrome/browser/chromeos/dom_ui/login/authenticator_facade_cros.cc35
-rw-r--r--chrome/browser/chromeos/dom_ui/login/authenticator_facade_cros.h45
-rw-r--r--chrome/browser/chromeos/dom_ui/login/authenticator_facade_cros_helpers.cc43
-rw-r--r--chrome/browser/chromeos/dom_ui/login/authenticator_facade_cros_helpers.h35
-rw-r--r--chrome/browser/chromeos/dom_ui/login/authenticator_facade_cros_unittest.cc132
-rw-r--r--chrome/browser/chromeos/dom_ui/login/authenticator_facade_stub.cc28
-rw-r--r--chrome/browser/chromeos/dom_ui/login/authenticator_facade_stub.h48
-rw-r--r--chrome/browser/chromeos/dom_ui/login/authenticator_facade_stub_unittest.cc163
-rw-r--r--chrome/browser/chromeos/dom_ui/login/login_ui.cc160
-rw-r--r--chrome/browser/chromeos/dom_ui/login/login_ui.h96
-rw-r--r--chrome/browser/chromeos/dom_ui/login/login_ui_helpers.cc94
-rw-r--r--chrome/browser/chromeos/dom_ui/login/login_ui_helpers.h78
-rw-r--r--chrome/browser/chromeos/dom_ui/login/login_ui_unittest.cc154
-rw-r--r--chrome/browser/chromeos/dom_ui/login/login_ui_unittest.h78
-rw-r--r--chrome/browser/chromeos/dom_ui/login/mock_authenticator_facade_cros.h49
-rw-r--r--chrome/browser/chromeos/dom_ui/login/mock_authenticator_facade_cros_helpers.h36
-rw-r--r--chrome/browser/chromeos/dom_ui/login/mock_authenticator_facade_stub.h44
-rw-r--r--chrome/browser/chromeos/dom_ui/login/mock_login_ui_handler.h36
-rw-r--r--chrome/browser/chromeos/dom_ui/login/mock_login_ui_helpers.h63
-rw-r--r--chrome/browser/chromeos/dom_ui/menu_ui.cc10
-rw-r--r--chrome/browser/chromeos/dom_ui/mobile_setup_ui.cc5
-rw-r--r--chrome/browser/chromeos/dom_ui/network_menu_ui.cc2
-rw-r--r--chrome/browser/chromeos/dom_ui/proxy_handler.cc3
-rw-r--r--chrome/browser/chromeos/dom_ui/register_page_ui.cc2
-rw-r--r--chrome/browser/chromeos/dom_ui/stats_options_handler.cc3
-rw-r--r--chrome/browser/chromeos/dom_ui/system_info_ui.cc2
-rw-r--r--chrome/browser/chromeos/dom_ui/system_options_handler.cc1
-rw-r--r--chrome/browser/chromeos/dom_ui/system_settings_provider.cc17
-rw-r--r--chrome/browser/chromeos/dom_ui/system_settings_provider.h9
40 files changed, 1804 insertions, 238 deletions
diff --git a/chrome/browser/chromeos/dom_ui/accounts_options_handler.cc b/chrome/browser/chromeos/dom_ui/accounts_options_handler.cc
index e461989..9d9be53 100644
--- a/chrome/browser/chromeos/dom_ui/accounts_options_handler.cc
+++ b/chrome/browser/chromeos/dom_ui/accounts_options_handler.cc
@@ -17,7 +17,7 @@
namespace chromeos {
AccountsOptionsHandler::AccountsOptionsHandler()
- : CrosOptionsPageUIHandler(new UserCrosSettingsProvider()) {
+ : CrosOptionsPageUIHandler(new UserCrosSettingsProvider) {
}
AccountsOptionsHandler::~AccountsOptionsHandler() {
@@ -43,8 +43,8 @@ void AccountsOptionsHandler::GetLocalizedValues(
localized_strings->SetString("allow_BWSI", l10n_util::GetStringUTF16(
IDS_OPTIONS_ACCOUNTS_ALLOW_BWSI_DESCRIPTION));
- localized_strings->SetString("allow_guest",l10n_util::GetStringUTF16(
- IDS_OPTIONS_ACCOUNTS_ALLOW_GUEST_DESCRIPTION));
+ localized_strings->SetString("use_whitelist",l10n_util::GetStringUTF16(
+ IDS_OPTIONS_ACCOUNTS_USE_WHITELIST_DESCRIPTION));
localized_strings->SetString("show_user_on_signin",l10n_util::GetStringUTF16(
IDS_OPTIONS_ACCOUNTS_SHOW_USER_NAMES_ON_SINGIN_DESCRIPTION));
localized_strings->SetString("username_edit_hint",l10n_util::GetStringUTF16(
@@ -53,6 +53,10 @@ void AccountsOptionsHandler::GetLocalizedValues(
IDS_OPTIONS_ACCOUNTS_USERNAME_FORMAT));
localized_strings->SetString("add_users",l10n_util::GetStringUTF16(
IDS_OPTIONS_ACCOUNTS_ADD_USERS));
+ localized_strings->SetString("owner_only", l10n_util::GetStringUTF16(
+ IDS_OPTIONS_ACCOUNTS_OWNER_ONLY));
+ localized_strings->SetString("owner_user_id", UTF8ToUTF16(
+ UserCrosSettingsProvider::cached_owner()));
localized_strings->SetString("current_user_is_owner",
UserManager::Get()->current_user_is_owner() ?
diff --git a/chrome/browser/chromeos/dom_ui/core_chromeos_options_handler.cc b/chrome/browser/chromeos/dom_ui/core_chromeos_options_handler.cc
index d76e33d..43d1148 100644
--- a/chrome/browser/chromeos/dom_ui/core_chromeos_options_handler.cc
+++ b/chrome/browser/chromeos/dom_ui/core_chromeos_options_handler.cc
@@ -4,11 +4,14 @@
#include "chrome/browser/chromeos/dom_ui/core_chromeos_options_handler.h"
+#include <string>
+
#include "base/json/json_reader.h"
#include "base/string_number_conversions.h"
#include "chrome/browser/chromeos/cros_settings.h"
#include "chrome/browser/metrics/user_metrics.h"
-#include "chrome/common/notification_service.h"
+#include "chrome/common/notification_details.h"
+#include "chrome/common/notification_source.h"
namespace chromeos {
diff --git a/chrome/browser/chromeos/dom_ui/imageburner_ui.cc b/chrome/browser/chromeos/dom_ui/imageburner_ui.cc
index b827c93..24fc64a 100644
--- a/chrome/browser/chromeos/dom_ui/imageburner_ui.cc
+++ b/chrome/browser/chromeos/dom_ui/imageburner_ui.cc
@@ -4,6 +4,8 @@
#include "chrome/browser/chromeos/dom_ui/imageburner_ui.h"
+#include <algorithm>
+
#include "app/l10n_util.h"
#include "app/resource_bundle.h"
#include "base/i18n/rtl.h"
@@ -17,7 +19,8 @@
#include "chrome/browser/browser_thread.h"
#include "chrome/browser/download/download_types.h"
#include "chrome/browser/download/download_util.h"
-#include "chrome/browser/profile.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/tab_contents/tab_contents.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/jstemplate_builder.h"
#include "chrome/common/url_constants.h"
@@ -105,7 +108,7 @@ ImageBurnHandler::ImageBurnHandler(TabContents* contents)
chromeos::CrosLibrary::Get()->GetBurnLibrary();
burn_lib->AddObserver(this);
local_image_file_path_.clear();
- burn_resource_manager_ = Singleton<ImageBurnResourceManager>::get();
+ burn_resource_manager_ = ImageBurnResourceManager::GetInstance();
}
ImageBurnHandler::~ImageBurnHandler() {
@@ -398,7 +401,7 @@ void ImageBurnHandler::CreateLocalImagePath() {
ImageBurnTaskProxy::ImageBurnTaskProxy(
const base::WeakPtr<ImageBurnHandler>& handler)
: handler_(handler) {
- resource_manager_ = Singleton<ImageBurnResourceManager>::get();
+ resource_manager_ = ImageBurnResourceManager::GetInstance();
}
bool ImageBurnTaskProxy::ReportDownloadInitialized() {
@@ -464,6 +467,11 @@ ImageBurnResourceManager::~ImageBurnResourceManager() {
download_manager_->RemoveObserver(this);
}
+// static
+ImageBurnResourceManager* ImageBurnResourceManager::GetInstance() {
+ return Singleton<ImageBurnResourceManager>::get();
+}
+
void ImageBurnResourceManager::OnDownloadUpdated(DownloadItem* download) {
if (download->state() == DownloadItem::CANCELLED) {
image_url_.reset();
@@ -610,7 +618,7 @@ ImageBurnUI::ImageBurnUI(TabContents* contents) : DOMUI(contents) {
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
NewRunnableMethod(
- Singleton<ChromeURLDataManager>::get(),
+ ChromeURLDataManager::GetInstance(),
&ChromeURLDataManager::AddDataSource,
make_scoped_refptr(html_source)));
}
diff --git a/chrome/browser/chromeos/dom_ui/imageburner_ui.h b/chrome/browser/chromeos/dom_ui/imageburner_ui.h
index 0f2560a..44041e5 100644
--- a/chrome/browser/chromeos/dom_ui/imageburner_ui.h
+++ b/chrome/browser/chromeos/dom_ui/imageburner_ui.h
@@ -22,10 +22,11 @@
#include "chrome/browser/download/download_item.h"
#include "chrome/browser/download/download_manager.h"
#include "chrome/browser/download/download_util.h"
-#include "chrome/browser/tab_contents/tab_contents.h"
#include "googleurl/src/gurl.h"
#include "net/base/file_stream.h"
+template <typename T> struct DefaultSingletonTraits;
+
static const std::string kPropertyPath = "path";
static const std::string kPropertyTitle = "title";
static const std::string kPropertyDirectory = "isDirectory";
@@ -36,6 +37,7 @@ static const std::string kImageFileName = "chromeos_image.bin.gz";
static const std::string kTempImageFolderName = "chromeos_image";
class ImageBurnResourceManager;
+class TabContents;
class ImageBurnUIHTMLSource : public ChromeURLDataManager::DataSource {
public:
@@ -158,8 +160,8 @@ class ImageBurnTaskProxy
class ImageBurnResourceManager : public DownloadManager::Observer,
public DownloadItem::Observer {
public:
- ImageBurnResourceManager();
- ~ImageBurnResourceManager();
+ // Returns the singleton instance.
+ static ImageBurnResourceManager* GetInstance();
// DownloadItem::Observer interface
virtual void OnDownloadUpdated(DownloadItem* download);
@@ -190,6 +192,11 @@ class ImageBurnResourceManager : public DownloadManager::Observer,
net::FileStream* CreateFileStream(FilePath* file_path);
private:
+ friend struct DefaultSingletonTraits<ImageBurnResourceManager>;
+
+ ImageBurnResourceManager();
+ ~ImageBurnResourceManager();
+
FilePath local_image_dir_file_path_;
FilePath image_fecher_local_path_;
bool image_download_started_;
@@ -216,4 +223,3 @@ class ImageBurnUI : public DOMUI {
DISALLOW_COPY_AND_ASSIGN(ImageBurnUI);
};
#endif // CHROME_BROWSER_CHROMEOS_DOM_UI_IMAGEBURNER_UI_H_
-
diff --git a/chrome/browser/chromeos/dom_ui/internet_options_handler.cc b/chrome/browser/chromeos/dom_ui/internet_options_handler.cc
index 5f1e772..1b37cea 100644
--- a/chrome/browser/chromeos/dom_ui/internet_options_handler.cc
+++ b/chrome/browser/chromeos/dom_ui/internet_options_handler.cc
@@ -26,11 +26,8 @@
#include "chrome/browser/chromeos/login/ownership_service.h"
#include "chrome/browser/chromeos/status/network_menu.h"
#include "chrome/browser/dom_ui/dom_ui_util.h"
-#include "chrome/browser/tab_contents/tab_contents.h"
-#include "chrome/browser/tab_contents/tab_contents_view.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/views/window.h"
-#include "chrome/common/notification_service.h"
#include "chrome/common/time_format.h"
#include "grit/browser_resources.h"
#include "grit/chromium_strings.h"
@@ -296,23 +293,12 @@ void InternetOptionsHandler::GetLocalizedValues(
localized_strings->SetString("generalNetworkingTitle",
l10n_util::GetStringUTF16(
IDS_OPTIONS_SETTINGS_INTERNET_CONTROL_TITLE));
-
- localized_strings->SetString("detailsInternetOk",
- l10n_util::GetStringUTF16(IDS_OK));
localized_strings->SetString("detailsInternetDismiss",
- l10n_util::GetStringUTF16(IDS_CANCEL));
-
- localized_strings->Set("wiredList", GetWiredList());
- localized_strings->Set("wirelessList", GetWirelessList());
- localized_strings->Set("rememberedList", GetRememberedList());
+ l10n_util::GetStringUTF16(IDS_CLOSE));
chromeos::NetworkLibrary* cros =
chromeos::CrosLibrary::Get()->GetNetworkLibrary();
- localized_strings->SetBoolean("wifiAvailable", cros->wifi_available());
- localized_strings->SetBoolean("wifiEnabled", cros->wifi_enabled());
- localized_strings->SetBoolean("cellularAvailable",
- cros->cellular_available());
- localized_strings->SetBoolean("cellularEnabled", cros->cellular_enabled());
+ FillNetworkInfo(localized_strings, cros);
localized_strings->SetBoolean("networkUseSettingsUI", use_settings_ui_);
}
@@ -328,10 +314,10 @@ void InternetOptionsHandler::RegisterMessages() {
NewCallback(this, &InternetOptionsHandler::LoginCallback));
dom_ui_->RegisterMessageCallback("loginToCertNetwork",
NewCallback(this, &InternetOptionsHandler::LoginCertCallback));
- dom_ui_->RegisterMessageCallback("setDetails",
- NewCallback(this, &InternetOptionsHandler::SetDetailsCallback));
dom_ui_->RegisterMessageCallback("loginToOtherNetwork",
NewCallback(this, &InternetOptionsHandler::LoginToOtherCallback));
+ dom_ui_->RegisterMessageCallback("setDetails",
+ NewCallback(this, &InternetOptionsHandler::SetDetailsCallback));
dom_ui_->RegisterMessageCallback("enableWifi",
NewCallback(this, &InternetOptionsHandler::EnableWifiCallback));
dom_ui_->RegisterMessageCallback("disableWifi",
@@ -382,13 +368,7 @@ void InternetOptionsHandler::BuyDataPlanCallback(const ListValue* args) {
void InternetOptionsHandler::RefreshNetworkData(
chromeos::NetworkLibrary* cros) {
DictionaryValue dictionary;
- dictionary.Set("wiredList", GetWiredList());
- dictionary.Set("wirelessList", GetWirelessList());
- dictionary.Set("rememberedList", GetRememberedList());
- dictionary.SetBoolean("wifiAvailable", cros->wifi_available());
- dictionary.SetBoolean("wifiEnabled", cros->wifi_enabled());
- dictionary.SetBoolean("cellularAvailable", cros->cellular_available());
- dictionary.SetBoolean("cellularEnabled", cros->cellular_enabled());
+ FillNetworkInfo(&dictionary, cros);
dom_ui_->CallJavascriptFunction(
L"options.InternetOptions.refreshNetworkData", dictionary);
}
@@ -408,9 +388,6 @@ void InternetOptionsHandler::OnNetworkChanged(
RefreshNetworkData(cros);
}
-// Add an observer for the active network, if any, so
-// that we can dynamically display the correct icon for
-// that network's signal strength.
// TODO(ers) Ideally, on this page we'd monitor all networks for
// signal strength changes, not just the active network.
void InternetOptionsHandler::MonitorActiveNetwork(
@@ -435,7 +412,7 @@ void InternetOptionsHandler::OnCellularDataPlanChanged(
chromeos::NetworkLibrary* obj) {
if (!dom_ui_)
return;
- chromeos::CellularNetwork* cellular = obj->cellular_network();
+ const chromeos::CellularNetwork* cellular = obj->cellular_network();
if (!cellular)
return;
const chromeos::CellularDataPlanVector& plans = cellular->GetDataPlans();
@@ -448,6 +425,8 @@ void InternetOptionsHandler::OnCellularDataPlanChanged(
}
connection_plans.SetString("servicePath", cellular->service_path());
connection_plans.SetBoolean("needsPlan", cellular->needs_new_plan());
+ connection_plans.SetBoolean("activated",
+ cellular->activation_state() == chromeos::ACTIVATION_STATE_ACTIVATED);
connection_plans.Set("plans", plan_list);
dom_ui_->CallJavascriptFunction(
L"options.InternetOptions.updateCellularPlans", connection_plans);
@@ -499,7 +478,7 @@ void InternetOptionsHandler::SetDetailsCallback(const ListValue* args) {
network->set_identity(ident);
changed = true;
}
- if (!is_certificate_in_pkcs11(network->cert_path())) {
+ if (!IsCertificateInPkcs11(network->cert_path())) {
std::string certpath;
if (!args->GetString(3, &certpath)) {
NOTREACHED();
@@ -523,11 +502,7 @@ void InternetOptionsHandler::SetDetailsCallback(const ListValue* args) {
cros->SaveWifiNetwork(network);
}
-// Parse 'path' to determine if the certificate is stored in a pkcs#11 device.
-// flimflam recognizes the string "SETTINGS:" to specify authentication
-// parameters. 'key_id=' indicates that the certificate is stored in a pkcs#11
-// device. See src/third_party/flimflam/files/doc/service-api.txt.
-bool InternetOptionsHandler::is_certificate_in_pkcs11(const std::string& path) {
+bool InternetOptionsHandler::IsCertificateInPkcs11(const std::string& path) {
static const std::string settings_string("SETTINGS:");
static const std::string pkcs11_key("key_id");
if (path.find(settings_string) == 0) {
@@ -544,10 +519,13 @@ void InternetOptionsHandler::PopulateDictionaryDetails(
const chromeos::Network* net, chromeos::NetworkLibrary* cros) {
DCHECK(net);
DictionaryValue dictionary;
- chromeos::ConnectionType type = net->type();
std::string hardware_address;
chromeos::NetworkIPConfigVector ipconfigs =
cros->GetIPConfigs(net->device_path(), &hardware_address);
+ if (!hardware_address.empty()) {
+ dictionary.SetString("hardwareAddress",
+ FormatHardwareAddress(hardware_address));
+ }
scoped_ptr<ListValue> ipconfig_list(new ListValue());
for (chromeos::NetworkIPConfigVector::const_iterator it = ipconfigs.begin();
it != ipconfigs.end(); ++it) {
@@ -560,39 +538,21 @@ void InternetOptionsHandler::PopulateDictionaryDetails(
ipconfig_list->Append(ipconfig_dict.release());
}
dictionary.Set("ipconfigs", ipconfig_list.release());
+
+ chromeos::ConnectionType type = net->type();
dictionary.SetInteger("type", type);
dictionary.SetString("servicePath", net->service_path());
dictionary.SetBoolean("connecting", net->connecting());
dictionary.SetBoolean("connected", net->connected());
dictionary.SetString("connectionState", net->GetStateString());
+
if (type == chromeos::TYPE_WIFI) {
- chromeos::WifiNetwork* wireless =
+ chromeos::WifiNetwork* wifi =
cros->FindWifiNetworkByPath(net->service_path());
- if (!wireless) {
+ if (!wifi) {
LOG(WARNING) << "Cannot find network " << net->service_path();
} else {
- dictionary.SetString("ssid", wireless->name());
- dictionary.SetBoolean("autoConnect", wireless->auto_connect());
- if (wireless->encrypted()) {
- dictionary.SetBoolean("encrypted", true);
- if (wireless->encryption() == chromeos::SECURITY_8021X) {
- bool certificate_in_pkcs11 =
- is_certificate_in_pkcs11(wireless->cert_path());
- if (certificate_in_pkcs11) {
- dictionary.SetBoolean("certInPkcs", true);
- } else {
- dictionary.SetBoolean("certInPkcs", false);
- }
- dictionary.SetString("certPath", wireless->cert_path());
- dictionary.SetString("ident", wireless->identity());
- dictionary.SetBoolean("certNeeded", true);
- dictionary.SetString("certPass", wireless->passphrase());
- } else {
- dictionary.SetBoolean("certNeeded", false);
- }
- } else {
- dictionary.SetBoolean("encrypted", false);
- }
+ PopulateWifiDetails(&dictionary, wifi);
}
} else if (type == chromeos::TYPE_CELLULAR) {
chromeos::CellularNetwork* cellular =
@@ -600,50 +560,81 @@ void InternetOptionsHandler::PopulateDictionaryDetails(
if (!cellular) {
LOG(WARNING) << "Cannot find network " << net->service_path();
} else {
- // Cellular network / connection settings.
- dictionary.SetString("serviceName", cellular->service_name());
- dictionary.SetString("networkTechnology",
- cellular->GetNetworkTechnologyString());
- dictionary.SetString("operatorName", cellular->operator_name());
- dictionary.SetString("operatorCode", cellular->operator_code());
- dictionary.SetString("activationState",
- cellular->GetActivationStateString());
- dictionary.SetString("roamingState",
- cellular->GetRoamingStateString());
- dictionary.SetString("restrictedPool",
- cellular->restricted_pool() ?
- l10n_util::GetStringUTF8(IDS_CONFIRM_MESSAGEBOX_YES_BUTTON_LABEL) :
- l10n_util::GetStringUTF8(IDS_CONFIRM_MESSAGEBOX_NO_BUTTON_LABEL));
- dictionary.SetString("errorState", cellular->GetErrorString());
- dictionary.SetString("supportUrl",
- cellular->payment_url());
- // Device settings.
- dictionary.SetString("manufacturer", cellular->manufacturer());
- dictionary.SetString("modelId", cellular->model_id());
- dictionary.SetString("firmwareRevision", cellular->firmware_revision());
- dictionary.SetString("hardwareRevision", cellular->hardware_revision());
- dictionary.SetString("lastUpdate", cellular->last_update());
- dictionary.SetString("prlVersion", StringPrintf("%u",
- cellular->prl_version()));
- dictionary.SetString("meid", cellular->meid());
- dictionary.SetString("imei", cellular->imei());
- dictionary.SetString("mdn", cellular->mdn());
- dictionary.SetString("imsi", cellular->imsi());
- dictionary.SetString("esn", cellular->esn());
- dictionary.SetString("min", cellular->min());
-
- dictionary.SetBoolean("gsm", cellular->is_gsm());
+ PopulateCellularDetails(&dictionary, cellular);
}
}
- if (!hardware_address.empty()) {
- dictionary.SetString("hardwareAddress",
- FormatHardwareAddress(hardware_address));
- }
dom_ui_->CallJavascriptFunction(
L"options.InternetOptions.showDetailedInfo", dictionary);
}
+void InternetOptionsHandler::PopulateWifiDetails(
+ DictionaryValue* dictionary,
+ const chromeos::WifiNetwork* wifi) {
+ dictionary->SetString("ssid", wifi->name());
+ dictionary->SetBoolean("autoConnect", wifi->auto_connect());
+ if (wifi->encrypted()) {
+ dictionary->SetBoolean("encrypted", true);
+ if (wifi->encryption() == chromeos::SECURITY_8021X) {
+ bool certificate_in_pkcs11 =
+ IsCertificateInPkcs11(wifi->cert_path());
+ if (certificate_in_pkcs11) {
+ dictionary->SetBoolean("certInPkcs", true);
+ } else {
+ dictionary->SetBoolean("certInPkcs", false);
+ }
+ dictionary->SetString("certPath", wifi->cert_path());
+ dictionary->SetString("ident", wifi->identity());
+ dictionary->SetBoolean("certNeeded", true);
+ dictionary->SetString("certPass", wifi->passphrase());
+ } else {
+ dictionary->SetBoolean("certNeeded", false);
+ }
+ } else {
+ dictionary->SetBoolean("encrypted", false);
+ }
+}
+
+void InternetOptionsHandler::PopulateCellularDetails(
+ DictionaryValue* dictionary,
+ const chromeos::CellularNetwork* cellular) {
+ // Cellular network / connection settings.
+ dictionary->SetString("serviceName", cellular->service_name());
+ dictionary->SetString("networkTechnology",
+ cellular->GetNetworkTechnologyString());
+ dictionary->SetString("operatorName", cellular->operator_name());
+ dictionary->SetString("operatorCode", cellular->operator_code());
+ dictionary->SetString("activationState",
+ cellular->GetActivationStateString());
+ dictionary->SetString("roamingState",
+ cellular->GetRoamingStateString());
+ dictionary->SetString("restrictedPool",
+ cellular->restricted_pool() ?
+ l10n_util::GetStringUTF8(
+ IDS_CONFIRM_MESSAGEBOX_YES_BUTTON_LABEL) :
+ l10n_util::GetStringUTF8(
+ IDS_CONFIRM_MESSAGEBOX_NO_BUTTON_LABEL));
+ dictionary->SetString("errorState", cellular->GetErrorString());
+ dictionary->SetString("supportUrl", cellular->payment_url());
+
+ // Device settings.
+ dictionary->SetString("manufacturer", cellular->manufacturer());
+ dictionary->SetString("modelId", cellular->model_id());
+ dictionary->SetString("firmwareRevision", cellular->firmware_revision());
+ dictionary->SetString("hardwareRevision", cellular->hardware_revision());
+ dictionary->SetString("lastUpdate", cellular->last_update());
+ dictionary->SetString("prlVersion", StringPrintf("%u",
+ cellular->prl_version()));
+ dictionary->SetString("meid", cellular->meid());
+ dictionary->SetString("imei", cellular->imei());
+ dictionary->SetString("mdn", cellular->mdn());
+ dictionary->SetString("imsi", cellular->imsi());
+ dictionary->SetString("esn", cellular->esn());
+ dictionary->SetString("min", cellular->min());
+
+ dictionary->SetBoolean("gsm", cellular->is_gsm());
+}
+
void InternetOptionsHandler::LoginCallback(const ListValue* args) {
std::string service_path;
std::string password;
@@ -749,78 +740,84 @@ void InternetOptionsHandler::ButtonClickCallback(const ListValue* args) {
return;
}
- bool is_owner =
- chromeos::OwnershipService::GetSharedInstance()->CurrentUserIsOwner();
-
int type = atoi(str_type.c_str());
- chromeos::NetworkLibrary* cros =
- chromeos::CrosLibrary::Get()->GetNetworkLibrary();
-
if (type == chromeos::TYPE_ETHERNET) {
- chromeos::EthernetNetwork* ether = cros->ethernet_network();
+ chromeos::NetworkLibrary* cros =
+ chromeos::CrosLibrary::Get()->GetNetworkLibrary();
+ const chromeos::EthernetNetwork* ether = cros->ethernet_network();
PopulateDictionaryDetails(ether, cros);
} else if (type == chromeos::TYPE_WIFI) {
- chromeos::WifiNetwork* network;
- if (command == "forget") {
- if (!is_owner) {
- LOG(WARNING) << "Non-owner tried to forget a network.";
- return;
- }
- cros->ForgetWifiNetwork(service_path);
- } else if (!use_settings_ui_ &&
- service_path == kOtherNetworksFakePath) {
- // Other wifi networks.
- chromeos::NetworkConfigView* view =
- new chromeos::NetworkConfigView();
- CreateModalPopup(view);
- view->SetLoginTextfieldFocus();
- } else if ((network = cros->FindWifiNetworkByPath(service_path))) {
- if (command == "connect") {
- // Connect to wifi here. Open password page if appropriate.
- if (network->encrypted() && !network->auto_connect()) {
- if (use_settings_ui_) {
- if (network->encryption() == chromeos::SECURITY_8021X) {
- PopulateDictionaryDetails(network, cros);
- } else {
- DictionaryValue dictionary;
- dictionary.SetString("servicePath", network->service_path());
- dom_ui_->CallJavascriptFunction(
- L"options.InternetOptions.showPasswordEntry", dictionary);
- }
+ HandleWifiButtonClick(service_path, command);
+ } else if (type == chromeos::TYPE_CELLULAR) {
+ HandleCellularButtonClick(service_path, command);
+ } else {
+ NOTREACHED();
+ }
+}
+
+void InternetOptionsHandler::HandleWifiButtonClick(
+ const std::string& service_path,
+ const std::string& command) {
+ chromeos::NetworkLibrary* cros =
+ chromeos::CrosLibrary::Get()->GetNetworkLibrary();
+ chromeos::WifiNetwork* network;
+ if (command == "forget") {
+ if (!chromeos::OwnershipService::GetSharedInstance()->
+ CurrentUserIsOwner()) {
+ LOG(WARNING) << "Non-owner tried to forget a network.";
+ return;
+ }
+ cros->ForgetWifiNetwork(service_path);
+ } else if (!use_settings_ui_ && service_path == kOtherNetworksFakePath) {
+ // Other wifi networks.
+ CreateModalPopup(new chromeos::NetworkConfigView());
+ } else if ((network = cros->FindWifiNetworkByPath(service_path))) {
+ if (command == "connect") {
+ // Connect to wifi here. Open password page if appropriate.
+ if (network->IsPassphraseRequired()) {
+ if (use_settings_ui_) {
+ if (network->encryption() == chromeos::SECURITY_8021X) {
+ PopulateDictionaryDetails(network, cros);
} else {
- chromeos::NetworkConfigView* view =
- new chromeos::NetworkConfigView(network, true);
- CreateModalPopup(view);
- view->SetLoginTextfieldFocus();
+ DictionaryValue dictionary;
+ dictionary.SetString("servicePath", network->service_path());
+ dom_ui_->CallJavascriptFunction(
+ L"options.InternetOptions.showPasswordEntry", dictionary);
}
} else {
- cros->ConnectToWifiNetwork(
- network, std::string(), std::string(), std::string());
+ CreateModalPopup(new chromeos::NetworkConfigView(network));
}
- } else if (command == "disconnect") {
- cros->DisconnectFromWirelessNetwork(network);
- } else if (command == "options") {
- PopulateDictionaryDetails(network, cros);
+ } else {
+ cros->ConnectToWifiNetwork(
+ network, std::string(), std::string(), std::string());
}
+ } else if (command == "disconnect") {
+ cros->DisconnectFromWirelessNetwork(network);
+ } else if (command == "options") {
+ PopulateDictionaryDetails(network, cros);
}
- } else if (type == chromeos::TYPE_CELLULAR) {
- chromeos::CellularNetwork* cellular =
- cros->FindCellularNetworkByPath(service_path);
- if (cellular) {
- if (command == "connect") {
- cros->ConnectToCellularNetwork(cellular);
- } else if (command == "disconnect") {
- cros->DisconnectFromWirelessNetwork(cellular);
- } else if (command == "activate") {
- Browser* browser = BrowserList::GetLastActive();
- if (browser)
- browser->OpenMobilePlanTabAndActivate();
- } else if (command == "options") {
- PopulateDictionaryDetails(cellular, cros);
- }
+ }
+}
+
+void InternetOptionsHandler::HandleCellularButtonClick(
+ const std::string& service_path,
+ const std::string& command) {
+ chromeos::NetworkLibrary* cros =
+ chromeos::CrosLibrary::Get()->GetNetworkLibrary();
+ chromeos::CellularNetwork* cellular =
+ cros->FindCellularNetworkByPath(service_path);
+ if (cellular) {
+ if (command == "connect") {
+ cros->ConnectToCellularNetwork(cellular);
+ } else if (command == "disconnect") {
+ cros->DisconnectFromWirelessNetwork(cellular);
+ } else if (command == "activate") {
+ Browser* browser = BrowserList::GetLastActive();
+ if (browser)
+ browser->OpenMobilePlanTabAndActivate();
+ } else if (command == "options") {
+ PopulateDictionaryDetails(cellular, cros);
}
- } else {
- NOTREACHED();
}
}
@@ -840,10 +837,16 @@ void InternetOptionsHandler::RefreshCellularPlanCallback(
cros->RefreshCellularDataPlans(cellular);
}
-ListValue* InternetOptionsHandler::GetNetwork(const std::string& service_path,
- const SkBitmap& icon, const std::string& name, bool connecting,
- bool connected, bool connectable, chromeos::ConnectionType connection_type,
- bool remembered, chromeos::ActivationState activation_state,
+ListValue* InternetOptionsHandler::GetNetwork(
+ const std::string& service_path,
+ const SkBitmap& icon,
+ const std::string& name,
+ bool connecting,
+ bool connected,
+ bool connectable,
+ chromeos::ConnectionType connection_type,
+ bool remembered,
+ chromeos::ActivationState activation_state,
bool needs_new_plan) {
ListValue* network = new ListValue();
@@ -864,29 +867,33 @@ ListValue* InternetOptionsHandler::GetNetwork(const std::string& service_path,
chromeos::CellularNetwork::ActivationStateToString(activation_state));
}
}
- // service path
+
+ // To keep the consistency with JS implementation, do not change the order
+ // locally.
+ // TODO(kochi): Use dictionaly for future maintainability.
+ // 0) service path
network->Append(Value::CreateStringValue(service_path));
- // name
+ // 1) name
network->Append(Value::CreateStringValue(name));
- // status
+ // 2) status
network->Append(Value::CreateStringValue(status));
- // type
+ // 3) type
network->Append(Value::CreateIntegerValue(static_cast<int>(connection_type)));
- // connected
+ // 4) connected
network->Append(Value::CreateBooleanValue(connected));
- // connecting
+ // 5) connecting
network->Append(Value::CreateBooleanValue(connecting));
- // icon data url
+ // 6) icon data url
network->Append(Value::CreateStringValue(icon.isNull() ? "" :
dom_ui_util::GetImageDataUrl(icon)));
- // remembered
+ // 7) remembered
network->Append(Value::CreateBooleanValue(remembered));
- // activation_state
+ // 8) activation state
network->Append(Value::CreateIntegerValue(
static_cast<int>(activation_state)));
- // needs_new_plan
+ // 9) needs new plan
network->Append(Value::CreateBooleanValue(needs_new_plan));
- // connectable
+ // 10) connectable
network->Append(Value::CreateBooleanValue(connectable));
return network;
}
@@ -899,7 +906,7 @@ ListValue* InternetOptionsHandler::GetWiredList() {
// If ethernet is not enabled, then don't add anything.
if (cros->ethernet_enabled()) {
- chromeos::EthernetNetwork* ethernet_network =
+ const chromeos::EthernetNetwork* ethernet_network =
cros->ethernet_network();
SkBitmap icon = *rb.GetBitmapNamed(IDR_STATUSBAR_WIRED_BLACK);
if (!ethernet_network || (!ethernet_network->connecting() &&
@@ -933,8 +940,7 @@ ListValue* InternetOptionsHandler::GetWirelessList() {
const chromeos::WifiNetworkVector& wifi_networks = cros->wifi_networks();
for (chromeos::WifiNetworkVector::const_iterator it =
wifi_networks.begin(); it != wifi_networks.end(); ++it) {
- SkBitmap icon = chromeos::NetworkMenu::IconForNetworkStrength(
- (*it)->strength(), true);
+ SkBitmap icon = chromeos::NetworkMenu::IconForNetworkStrength(*it, true);
if ((*it)->encrypted()) {
icon = chromeos::NetworkMenu::IconForDisplay(icon,
*rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_SECURE));
@@ -956,8 +962,7 @@ ListValue* InternetOptionsHandler::GetWirelessList() {
cros->cellular_networks();
for (chromeos::CellularNetworkVector::const_iterator it =
cellular_networks.begin(); it != cellular_networks.end(); ++it) {
- SkBitmap icon = chromeos::NetworkMenu::IconForNetworkStrength(
- (*it)->strength(), true);
+ SkBitmap icon = chromeos::NetworkMenu::IconForNetworkStrength(*it, true);
SkBitmap badge = chromeos::NetworkMenu::BadgeForNetworkTechnology(*it);
icon = chromeos::NetworkMenu::IconForDisplay(icon, badge);
list->Append(GetNetwork(
@@ -1020,3 +1025,14 @@ ListValue* InternetOptionsHandler::GetRememberedList() {
}
return list;
}
+
+void InternetOptionsHandler::FillNetworkInfo(
+ DictionaryValue* dictionary, chromeos::NetworkLibrary* cros) {
+ dictionary->Set("wiredList", GetWiredList());
+ dictionary->Set("wirelessList", GetWirelessList());
+ dictionary->Set("rememberedList", GetRememberedList());
+ dictionary->SetBoolean("wifiAvailable", cros->wifi_available());
+ dictionary->SetBoolean("wifiEnabled", cros->wifi_enabled());
+ dictionary->SetBoolean("cellularAvailable", cros->cellular_available());
+ dictionary->SetBoolean("cellularEnabled", cros->cellular_enabled());
+}
diff --git a/chrome/browser/chromeos/dom_ui/internet_options_handler.h b/chrome/browser/chromeos/dom_ui/internet_options_handler.h
index b44263c..7b857ff 100644
--- a/chrome/browser/chromeos/dom_ui/internet_options_handler.h
+++ b/chrome/browser/chromeos/dom_ui/internet_options_handler.h
@@ -40,15 +40,23 @@ class InternetOptionsHandler
virtual void OnCellularDataPlanChanged(chromeos::NetworkLibrary* network_lib);
private:
- // Open a modal popup dialog.
+ // Opens a modal popup dialog.
void CreateModalPopup(views::WindowDelegate* view);
// Passes data needed to show details overlay for network.
// |args| will be [ network_type, service_path, command ]
- // And command is one of 'options', 'connect', disconnect', or 'forget'
+ // And command is one of 'options', 'connect', disconnect', 'activate' or
+ // 'forget'
+ // Handle{Wifi,Cellular}ButtonClick handles button click on a wireless
+ // network item and a cellular network item respectively.
void ButtonClickCallback(const ListValue* args);
- // Initiates cellular plan data refresh. The results from libcros will
- // be passed through CellularDataPlanChanged() callback method.
+ void HandleWifiButtonClick(const std::string& service_path,
+ const std::string& command);
+ void HandleCellularButtonClick(const std::string& service_path,
+ const std::string& command);
+
+ // Initiates cellular plan data refresh. The results from libcros will be
+ // passed through CellularDataPlanChanged() callback method.
// |args| will be [ service_path ]
void RefreshCellularPlanCallback(const ListValue* args);
@@ -62,36 +70,55 @@ class InternetOptionsHandler
void DisableCellularCallback(const ListValue* args);
void BuyDataPlanCallback(const ListValue* args);
- bool is_certificate_in_pkcs11(const std::string& path);
+ // Parses 'path' to determine if the certificate is stored in a pkcs#11
+ // device. flimflam recognizes the string "SETTINGS:" to specify
+ // authentication parameters. 'key_id=' indicates that the certificate is
+ // stored in a pkcs#11 device.
+ // See src/third_party/flimflam/files/doc/service-api.txt.
+ bool IsCertificateInPkcs11(const std::string& path);
// Populates the ui with the details of the given device path. This forces
// an overlay to be displayed in the UI.
void PopulateDictionaryDetails(const chromeos::Network* net,
chromeos::NetworkLibrary* cros);
-
- // Converts CellularDataPlan structure into dictionary for JS. Formats
- // plan settings into human readable texts.
+ void PopulateWifiDetails(DictionaryValue* dictionary,
+ const chromeos::WifiNetwork* wifi);
+ void PopulateCellularDetails(DictionaryValue* dictionary,
+ const chromeos::CellularNetwork*
+ cellular);
+
+ // Converts CellularDataPlan structure into dictionary for JS. Formats plan
+ // settings into human readable texts.
DictionaryValue* CellularDataPlanToDictionary(
const chromeos::CellularDataPlan* plan);
- // Creates the map of a network
- ListValue* GetNetwork(const std::string& service_path, const SkBitmap& icon,
- const std::string& name, bool connecting, bool connected,
- bool connectable, chromeos::ConnectionType connection_type,
- bool remembered, chromeos::ActivationState activation_state,
- bool restricted_ip);
-
- // Creates the map of wired networks
+ // Creates the map of a network.
+ ListValue* GetNetwork(const std::string& service_path,
+ const SkBitmap& icon,
+ const std::string& name,
+ bool connecting,
+ bool connected,
+ bool connectable,
+ chromeos::ConnectionType connection_type,
+ bool remembered,
+ chromeos::ActivationState activation_state,
+ bool restricted_ip);
+
+ // Creates the map of wired networks.
ListValue* GetWiredList();
- // Creates the map of wireless networks
+ // Creates the map of wireless networks.
ListValue* GetWirelessList();
- // Creates the map of remembered networks
+ // Creates the map of remembered networks.
ListValue* GetRememberedList();
- // Refresh the display of network information
+ // Fills network information into JS dictionary for displaying network lists.
+ void FillNetworkInfo(DictionaryValue* dictionary,
+ chromeos::NetworkLibrary* cros);
+ // Refreshes the display of network information.
void RefreshNetworkData(chromeos::NetworkLibrary* cros);
- // Monitor the active network, if any
+ // Adds an observer for the active network, if any, so that we can dynamically
+ // display the correct icon for that network's signal strength.
void MonitorActiveNetwork(chromeos::NetworkLibrary* cros);
- // If any network is currently active, this is its service path
+ // If any network is currently active, this is its service path.
std::string active_network_;
// A boolean flag of whether to use DOMUI for connect UI. True to use DOMUI
diff --git a/chrome/browser/chromeos/dom_ui/keyboard_overlay_ui.cc b/chrome/browser/chromeos/dom_ui/keyboard_overlay_ui.cc
index e2477aa..9a2c0ce 100644
--- a/chrome/browser/chromeos/dom_ui/keyboard_overlay_ui.cc
+++ b/chrome/browser/chromeos/dom_ui/keyboard_overlay_ui.cc
@@ -16,9 +16,9 @@
#include "chrome/browser/dom_ui/chrome_url_data_manager.h"
#include "chrome/common/jstemplate_builder.h"
#include "chrome/common/url_constants.h"
-#include "cros/chromeos_input_method.h"
#include "grit/browser_resources.h"
#include "grit/generated_resources.h"
+#include "third_party/cros/chromeos_input_method.h"
class KeyboardOverlayUIHTMLSource : public ChromeURLDataManager::DataSource {
@@ -295,7 +295,7 @@ KeyboardOverlayUI::KeyboardOverlayUI(TabContents* contents)
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
NewRunnableMethod(
- Singleton<ChromeURLDataManager>::get(),
+ ChromeURLDataManager::GetInstance(),
&ChromeURLDataManager::AddDataSource,
make_scoped_refptr(html_source)));
}
diff --git a/chrome/browser/chromeos/dom_ui/language_customize_modifier_keys_handler.cc b/chrome/browser/chromeos/dom_ui/language_customize_modifier_keys_handler.cc
index 954b971..56e4448 100644
--- a/chrome/browser/chromeos/dom_ui/language_customize_modifier_keys_handler.cc
+++ b/chrome/browser/chromeos/dom_ui/language_customize_modifier_keys_handler.cc
@@ -6,8 +6,8 @@
#include "app/l10n_util.h"
#include "base/values.h"
-#include "cros/chromeos_keyboard.h"
#include "grit/generated_resources.h"
+#include "third_party/cros/chromeos_keyboard.h"
namespace {
const struct ModifierKeysSelectItem {
diff --git a/chrome/browser/chromeos/dom_ui/language_options_handler.cc b/chrome/browser/chromeos/dom_ui/language_options_handler.cc
index 413eecc..cd81ada 100644
--- a/chrome/browser/chromeos/dom_ui/language_options_handler.cc
+++ b/chrome/browser/chromeos/dom_ui/language_options_handler.cc
@@ -20,7 +20,7 @@
#include "chrome/browser/chromeos/input_method/input_method_util.h"
#include "chrome/browser/metrics/user_metrics.h"
#include "chrome/browser/prefs/pref_service.h"
-#include "chrome/browser/profile.h"
+#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/tab_contents/tab_contents.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/common/pref_names.h"
diff --git a/chrome/browser/chromeos/dom_ui/language_options_handler_unittest.cc b/chrome/browser/chromeos/dom_ui/language_options_handler_unittest.cc
index 4c940ef..ddf58b7 100644
--- a/chrome/browser/chromeos/dom_ui/language_options_handler_unittest.cc
+++ b/chrome/browser/chromeos/dom_ui/language_options_handler_unittest.cc
@@ -27,12 +27,14 @@ static InputMethodDescriptors CreateInputMethodDescriptors() {
return descriptors;
}
-// TODO: Fix this test. See http://crosbug.com/6269
-TEST(LanguageOptionsHandlerTest, DISABLED_GetInputMethodList) {
- // Use the stub libcros. The change is global (i.e. affects other unti
- // tests), but it should be ok. Unit tests should not require the real
- // libcros.
- CrosLibrary::Get()->GetTestApi()->SetUseStubImpl();
+TEST(LanguageOptionsHandlerTest, GetInputMethodList) {
+ // Use the stub libcros. The object will take care of the cleanup.
+ ScopedStubCrosEnabler stub_cros_enabler;
+
+ // Reset the library implementation so it will be initialized
+ // again. Otherwise, non-stub implementation can be reused, if it's
+ // already initialized elsewhere, which results in a crash.
+ CrosLibrary::Get()->GetTestApi()->SetInputMethodLibrary(NULL, false);
InputMethodDescriptors descriptors = CreateInputMethodDescriptors();
scoped_ptr<ListValue> list(
diff --git a/chrome/browser/chromeos/dom_ui/login/authenticator_facade.h b/chrome/browser/chromeos/dom_ui/login/authenticator_facade.h
new file mode 100644
index 0000000..0c6af1c
--- /dev/null
+++ b/chrome/browser/chromeos/dom_ui/login/authenticator_facade.h
@@ -0,0 +1,63 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_CHROMEOS_DOM_UI_LOGIN_AUTHENTICATOR_FACADE_H_
+#define CHROME_BROWSER_CHROMEOS_DOM_UI_LOGIN_AUTHENTICATOR_FACADE_H_
+#pragma once
+
+#include <string>
+
+#include "chrome/browser/chromeos/login/authenticator.h"
+#include "chrome/browser/chromeos/login/login_utils.h"
+#include "chrome/common/net/gaia/google_service_auth_error.h"
+
+class Profile;
+
+namespace chromeos {
+
+class LoginStatusConsumer;
+
+// AuthenticatorFacade operates as an interface between the DOMui login handling
+// layer and the authentication layer. This allows for using a stubbed version
+// of authentication during testing if needed. Also this allows for a clear
+// seperation between the DOMui login handling code and the code that deals with
+// authentication.
+// What code will be compiled with what DEPS flags:
+// touchui == 0
+// AuthenticatorFacade is not compiled
+// touchui == 1 && chromeos == 0
+// AuthenticatorFacade is compiled in using the stubbed authentication code
+// touchui == 1 && chromes == 1
+// AuthenticatorFacade is compiled in using the functional authentication code
+// TODO(rharrison): Implement the real authentication code.
+class AuthenticatorFacade {
+ public:
+ explicit AuthenticatorFacade(LoginStatusConsumer* consumer) :
+ consumer_(consumer) {}
+ virtual ~AuthenticatorFacade() {}
+ virtual void Setup() {}
+ virtual void AuthenticateToLogin(Profile* profile,
+ const std::string& username,
+ const std::string& password,
+ const std::string& login_token,
+ const std::string& login_captcha) = 0;
+ void AuthenticateToUnlock(const std::string& username,
+ const std::string& password) {
+ AuthenticateToLogin(NULL /* not used */,
+ username,
+ password,
+ std::string(),
+ std::string());
+ }
+
+ protected:
+ LoginStatusConsumer* consumer_;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(AuthenticatorFacade);
+};
+
+} // namespace chromeos
+
+#endif // CHROME_BROWSER_CHROMEOS_DOM_UI_LOGIN_AUTHENTICATOR_FACADE_H_
diff --git a/chrome/browser/chromeos/dom_ui/login/authenticator_facade_cros.cc b/chrome/browser/chromeos/dom_ui/login/authenticator_facade_cros.cc
new file mode 100644
index 0000000..051c875
--- /dev/null
+++ b/chrome/browser/chromeos/dom_ui/login/authenticator_facade_cros.cc
@@ -0,0 +1,35 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/chromeos/dom_ui/login/authenticator_facade_cros.h"
+#include "chrome/browser/chromeos/dom_ui/login/authenticator_facade_cros_helpers.h"
+
+#include <string>
+
+namespace chromeos {
+
+AuthenticatorFacadeCros::AuthenticatorFacadeCros(
+ LoginStatusConsumer* consumer)
+ : AuthenticatorFacade(consumer),
+ authenticator_(NULL),
+ helpers_(new AuthenticatorFacadeCrosHelpers()) {
+}
+
+void AuthenticatorFacadeCros::Setup() {
+ authenticator_ = helpers_->CreateAuthenticator(consumer_);
+}
+
+void AuthenticatorFacadeCros::AuthenticateToLogin(
+ Profile* profile,
+ const std::string& username,
+ const std::string& password,
+ const std::string& login_token,
+ const std::string& login_captcha) {
+ helpers_->PostAuthenticateToLogin(authenticator_.get(),
+ profile,
+ username,
+ password);
+}
+
+} // namespace chromeos
diff --git a/chrome/browser/chromeos/dom_ui/login/authenticator_facade_cros.h b/chrome/browser/chromeos/dom_ui/login/authenticator_facade_cros.h
new file mode 100644
index 0000000..4135f07
--- /dev/null
+++ b/chrome/browser/chromeos/dom_ui/login/authenticator_facade_cros.h
@@ -0,0 +1,45 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_CHROMEOS_DOM_UI_LOGIN_AUTHENTICATOR_FACADE_CROS_H_
+#define CHROME_BROWSER_CHROMEOS_DOM_UI_LOGIN_AUTHENTICATOR_FACADE_CROS_H_
+#pragma once
+
+#include <string>
+
+#include "base/scoped_ptr.h"
+#include "chrome/browser/chromeos/login/authenticator.h"
+#include "chrome/browser/chromeos/dom_ui/login/authenticator_facade.h"
+#include "chrome/browser/chromeos/dom_ui/login/authenticator_facade_cros_helpers.h"
+
+namespace chromeos {
+
+class AuthenticatorFacadeCrosHelpers;
+
+// This class provides authentication services to the DOM login screen through
+// libcros. It is only compiled and used when TOUCH_UI and OS_CHROMEOS are
+// defined.
+class AuthenticatorFacadeCros : public AuthenticatorFacade {
+ public:
+ explicit AuthenticatorFacadeCros(LoginStatusConsumer* consumer);
+ virtual ~AuthenticatorFacadeCros() {}
+
+ void Setup();
+ virtual void AuthenticateToLogin(Profile* profile,
+ const std::string& username,
+ const std::string& password,
+ const std::string& login_token,
+ const std::string& login_captcha);
+
+ protected:
+ scoped_refptr<Authenticator> authenticator_;
+ scoped_ptr<AuthenticatorFacadeCrosHelpers> helpers_;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(AuthenticatorFacadeCros);
+};
+
+} // namespace chromeos
+
+#endif // CHROME_BROWSER_CHROMEOS_DOM_UI_LOGIN_AUTHENTICATOR_FACADE_CROS_H_
diff --git a/chrome/browser/chromeos/dom_ui/login/authenticator_facade_cros_helpers.cc b/chrome/browser/chromeos/dom_ui/login/authenticator_facade_cros_helpers.cc
new file mode 100644
index 0000000..3337c2e
--- /dev/null
+++ b/chrome/browser/chromeos/dom_ui/login/authenticator_facade_cros_helpers.cc
@@ -0,0 +1,43 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <string>
+
+#include "chrome/browser/browser_thread.h"
+#include "chrome/browser/chromeos/cros/cros_library.h"
+#include "chrome/browser/chromeos/dom_ui/login/authenticator_facade_cros_helpers.h"
+#include "chrome/browser/chromeos/login/authenticator.h"
+#include "chrome/browser/chromeos/login/login_utils.h"
+
+namespace chromeos {
+
+AuthenticatorFacadeCrosHelpers::AuthenticatorFacadeCrosHelpers() {
+}
+
+Authenticator* AuthenticatorFacadeCrosHelpers::CreateAuthenticator(
+ LoginStatusConsumer* consumer) {
+
+ return CrosLibrary::Get()->EnsureLoaded() ?
+ LoginUtils::Get()->CreateAuthenticator(consumer) :
+ NULL;
+}
+
+void AuthenticatorFacadeCrosHelpers::PostAuthenticateToLogin(
+ Authenticator* authenticator,
+ Profile* profile,
+ const std::string& username,
+ const std::string& password) {
+
+ BrowserThread::PostTask(
+ BrowserThread::UI, FROM_HERE,
+ NewRunnableMethod(authenticator,
+ &Authenticator::AuthenticateToLogin,
+ profile,
+ username,
+ password,
+ std::string(),
+ std::string()));
+}
+
+} // namespace chromeos
diff --git a/chrome/browser/chromeos/dom_ui/login/authenticator_facade_cros_helpers.h b/chrome/browser/chromeos/dom_ui/login/authenticator_facade_cros_helpers.h
new file mode 100644
index 0000000..ddac0c5
--- /dev/null
+++ b/chrome/browser/chromeos/dom_ui/login/authenticator_facade_cros_helpers.h
@@ -0,0 +1,35 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_CHROMEOS_DOM_UI_LOGIN_AUTHENTICATOR_FACADE_CROS_HELPERS_H_
+#define CHROME_BROWSER_CHROMEOS_DOM_UI_LOGIN_AUTHENTICATOR_FACADE_CROS_HELPERS_H_
+#pragma once
+
+#include <string>
+
+class Profile;
+
+namespace chromeos {
+
+class Authenticator;
+class LoginStatusConsumer;
+
+class AuthenticatorFacadeCrosHelpers {
+ public:
+ AuthenticatorFacadeCrosHelpers();
+ virtual ~AuthenticatorFacadeCrosHelpers() {}
+
+ virtual Authenticator* CreateAuthenticator(LoginStatusConsumer* consumer);
+ virtual void PostAuthenticateToLogin(Authenticator* authenticator,
+ Profile* profile,
+ const std::string& username,
+ const std::string& password);
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(AuthenticatorFacadeCrosHelpers);
+};
+
+} // namespace chromeos
+
+#endif // CHROME_BROWSER_CHROMEOS_DOM_UI_LOGIN_AUTHENTICATOR_FACADE_CROS_HELPERS_H_
diff --git a/chrome/browser/chromeos/dom_ui/login/authenticator_facade_cros_unittest.cc b/chrome/browser/chromeos/dom_ui/login/authenticator_facade_cros_unittest.cc
new file mode 100644
index 0000000..a3df5a7
--- /dev/null
+++ b/chrome/browser/chromeos/dom_ui/login/authenticator_facade_cros_unittest.cc
@@ -0,0 +1,132 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <string>
+
+#include "base/scoped_ptr.h"
+#include "chrome/browser/chromeos/dom_ui/login/authenticator_facade_cros.h"
+#include "chrome/browser/chromeos/dom_ui/login/mock_authenticator_facade_cros_helpers.h"
+#include "chrome/browser/chromeos/dom_ui/login/mock_login_ui_handler.h"
+#include "chrome/browser/chromeos/login/mock_authenticator.h"
+#include "chrome/test/testing_profile.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+using ::testing::_;
+using ::testing::Return;
+
+namespace {
+
+class AuthenticatorFacadeCrosHarness
+ : public chromeos::AuthenticatorFacadeCros {
+ public:
+ AuthenticatorFacadeCrosHarness(
+ chromeos::LoginStatusConsumer* consumer)
+ : chromeos::AuthenticatorFacadeCros(consumer) {
+ }
+
+ chromeos::LoginStatusConsumer* GetConsumer() const {
+ return consumer_;
+ }
+ chromeos::MockAuthenticatorFacadeCrosHelpers* GetHelpers() const {
+ return static_cast<chromeos::MockAuthenticatorFacadeCrosHelpers*>(
+ helpers_.get());
+ }
+ void SetHelpers(chromeos::MockAuthenticatorFacadeCrosHelpers* helpers) {
+ helpers_.reset(helpers);
+ }
+ chromeos::MockAuthenticator* GetAuthenticator() const {
+ return static_cast<chromeos::MockAuthenticator*>(
+ authenticator_.get());
+ }
+ void SetAuthenticator(chromeos::MockAuthenticator* authenticator) {
+ authenticator_ = authenticator;
+ }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(AuthenticatorFacadeCrosHarness);
+};
+
+} // namespace
+
+namespace chromeos {
+
+// Setup Tests
+TEST(AuthenticatorFacadeCrosTest, Setup) {
+ MockLoginUIHandler consumer;
+ MockAuthenticatorFacadeCrosHelpers* helpers =
+ new chromeos::MockAuthenticatorFacadeCrosHelpers();
+ scoped_refptr<chromeos::MockAuthenticator> authenticator =
+ new chromeos::MockAuthenticator(&consumer,
+ std::string(),
+ std::string());
+ TestingProfile mock_profile;
+ AuthenticatorFacadeCrosHarness facade(&consumer);
+
+ facade.SetHelpers(helpers);
+ EXPECT_CALL(*helpers, CreateAuthenticator(&consumer))
+ .Times(1)
+ .WillRepeatedly(Return(authenticator.get()));
+
+ facade.Setup();
+
+ ASSERT_EQ(&consumer, facade.GetConsumer());
+ ASSERT_EQ(authenticator.get(), facade.GetAuthenticator());
+}
+
+// AuthenticateToLogin Tests
+TEST(AuthenticatorFacadeCrosTest, AuthenticateToLogin) {
+ MockLoginUIHandler consumer;
+ MockAuthenticatorFacadeCrosHelpers* helpers =
+ new chromeos::MockAuthenticatorFacadeCrosHelpers();
+ scoped_refptr<chromeos::MockAuthenticator> authenticator =
+ new chromeos::MockAuthenticator(&consumer,
+ std::string(),
+ std::string());
+ TestingProfile mock_profile;
+ std::string test_username("Test_User");
+ std::string test_password("Test_Password");
+ std::string test_token("Test_Token");
+ std::string test_captcha("Test_Captcha");
+ AuthenticatorFacadeCrosHarness facade(&consumer);
+
+ facade.SetHelpers(helpers);
+ facade.SetAuthenticator(authenticator.get());
+ EXPECT_CALL(*helpers, PostAuthenticateToLogin(authenticator.get(),
+ &mock_profile,
+ test_username,
+ test_password))
+ .Times(1);
+
+ facade.AuthenticateToLogin(&mock_profile,
+ test_username,
+ test_password,
+ test_token,
+ test_captcha);
+}
+
+// AuthenticateToUnlock
+TEST(AuthenticatorFacadeCrosTest, AuthenticateToUnlock) {
+ MockLoginUIHandler consumer;
+ MockAuthenticatorFacadeCrosHelpers* helpers =
+ new chromeos::MockAuthenticatorFacadeCrosHelpers();
+ scoped_refptr<chromeos::MockAuthenticator> authenticator =
+ new chromeos::MockAuthenticator(&consumer,
+ std::string(),
+ std::string());
+ std::string test_username("Test_User");
+ std::string test_password("Test_Password");
+ AuthenticatorFacadeCrosHarness facade(&consumer);
+
+ facade.SetHelpers(helpers);
+ facade.SetAuthenticator(authenticator.get());
+ EXPECT_CALL(*helpers, PostAuthenticateToLogin(authenticator.get(),
+ NULL,
+ test_username,
+ test_password))
+ .Times(1);
+
+ facade.AuthenticateToUnlock(test_username, test_password);
+}
+
+} // namespace chromeos
diff --git a/chrome/browser/chromeos/dom_ui/login/authenticator_facade_stub.cc b/chrome/browser/chromeos/dom_ui/login/authenticator_facade_stub.cc
new file mode 100644
index 0000000..93b138b
--- /dev/null
+++ b/chrome/browser/chromeos/dom_ui/login/authenticator_facade_stub.cc
@@ -0,0 +1,28 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/chromeos/dom_ui/login/authenticator_facade_stub.h"
+
+namespace chromeos {
+
+void AuthenticatorFacadeStub::AuthenticateToLogin(
+ Profile* profile,
+ const std::string& username,
+ const std::string& password,
+ const std::string& login_token,
+ const std::string& login_captcha) {
+ if (!expected_username_.compare(username) &&
+ !expected_password_.compare(password)) {
+ consumer_->OnLoginSuccess(username,
+ password,
+ credentials_,
+ false);
+ } else {
+ GoogleServiceAuthError error(
+ GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS);
+ consumer_->OnLoginFailure(LoginFailure::FromNetworkAuthFailure(error));
+ }
+}
+
+} // namespace chromeos
diff --git a/chrome/browser/chromeos/dom_ui/login/authenticator_facade_stub.h b/chrome/browser/chromeos/dom_ui/login/authenticator_facade_stub.h
new file mode 100644
index 0000000..b773dbb
--- /dev/null
+++ b/chrome/browser/chromeos/dom_ui/login/authenticator_facade_stub.h
@@ -0,0 +1,48 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_CHROMEOS_DOM_UI_LOGIN_AUTHENTICATOR_FACADE_STUB_H_
+#define CHROME_BROWSER_CHROMEOS_DOM_UI_LOGIN_AUTHENTICATOR_FACADE_STUB_H_
+#pragma once
+
+#include <string>
+
+#include "chrome/browser/chromeos/dom_ui/login/authenticator_facade.h"
+
+namespace chromeos {
+
+// This class is a stubbed out version of the authentication that is used for
+// functional testing of the LoginUI code. It takes in an expected user/pass
+// pair during construction, which is used for authentication. Any pair that
+// isn't the expected pair will fail authentication and the pair will pass.
+// TODO(rharrison): Once the functional authentication code is completed make
+// sure that this code isn't used in chromeos builds.
+class AuthenticatorFacadeStub : public AuthenticatorFacade {
+ public:
+ AuthenticatorFacadeStub(LoginStatusConsumer* consumer,
+ const std::string& expected_username,
+ const std::string& expected_password) :
+ AuthenticatorFacade(consumer),
+ expected_username_(expected_username),
+ expected_password_(expected_password) {}
+ virtual ~AuthenticatorFacadeStub() {}
+
+ virtual void AuthenticateToLogin(Profile* profile,
+ const std::string& username,
+ const std::string& password,
+ const std::string& login_token,
+ const std::string& login_captcha);
+
+ protected:
+ const std::string expected_username_;
+ const std::string expected_password_;
+ GaiaAuthConsumer::ClientLoginResult credentials_;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(AuthenticatorFacadeStub);
+};
+
+} // namespace chromeos
+
+#endif // CHROME_BROWSER_CHROMEOS_DOM_UI_LOGIN_AUTHENTICATOR_FACADE_STUB_H_
diff --git a/chrome/browser/chromeos/dom_ui/login/authenticator_facade_stub_unittest.cc b/chrome/browser/chromeos/dom_ui/login/authenticator_facade_stub_unittest.cc
new file mode 100644
index 0000000..4c8252a
--- /dev/null
+++ b/chrome/browser/chromeos/dom_ui/login/authenticator_facade_stub_unittest.cc
@@ -0,0 +1,163 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+#include <string>
+
+#include "base/scoped_ptr.h"
+#include "chrome/browser/chromeos/dom_ui/login/authenticator_facade_stub.h"
+#include "chrome/browser/chromeos/dom_ui/login/mock_login_ui_handler.h"
+
+#include "testing/gtest/include/gtest/gtest.h"
+
+using ::testing::_;
+
+class LoginStatusConsumer;
+
+namespace {
+
+class AuthenticatorFacadeStubHarness
+ : public chromeos::AuthenticatorFacadeStub {
+ public:
+ AuthenticatorFacadeStubHarness(chromeos::LoginStatusConsumer* consumer,
+ const std::string& username,
+ const std::string& password) :
+ chromeos::AuthenticatorFacadeStub(consumer,
+ username,
+ password) {}
+ const std::string GetUsername() const { return expected_username_; }
+ const std::string GetPassword() const { return expected_password_; }
+ chromeos::LoginStatusConsumer* GetConsumer() const { return consumer_; }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(AuthenticatorFacadeStubHarness);
+};
+
+} // namespace
+
+namespace chromeos {
+
+// Setup Tests
+TEST(AuthenticatorFacadeStubTest, SetupSuccess) {
+ MockLoginUIHandler consumer;
+ std::string test_username("Test_User");
+ std::string test_password("Test_Password");
+ scoped_ptr<AuthenticatorFacadeStubHarness>
+ facade(new AuthenticatorFacadeStubHarness(&consumer,
+ test_username,
+ test_password));
+ ASSERT_EQ(&consumer, facade->GetConsumer());
+ ASSERT_EQ(test_username, facade->GetUsername());
+ ASSERT_EQ(test_password, facade->GetPassword());
+}
+
+// AuthenticateToLogin Tests
+TEST(AuthenticatorFacadeStubTest, AuthenticateToLoginSuccess) {
+ MockLoginUIHandler consumer;
+ std::string test_username("Test_User");
+ std::string test_password("Test_Password");
+ std::string test_token("Test_Token");
+ std::string test_captcha("Test_Captcha");
+ scoped_ptr<AuthenticatorFacadeStubHarness>
+ facade(new AuthenticatorFacadeStubHarness(&consumer,
+ test_username,
+ test_password));
+
+ EXPECT_CALL(consumer, OnLoginSuccess(test_username,
+ _,
+ _,
+ false))
+ .Times(1);
+
+ facade->AuthenticateToLogin(NULL,
+ test_username,
+ test_password,
+ test_token,
+ test_captcha);
+}
+
+TEST(AuthenticatorFacadeStubTest, AuthenticateToLoginFailure) {
+ MockLoginUIHandler consumer;
+ std::string test_username("Test_User");
+ std::string test_password("Test_Password");
+ std::string bad_username("Bad_User");
+ std::string bad_password("Bad_Password");
+ std::string test_token("Test_Token");
+ std::string test_captcha("Test_Captcha");
+ scoped_ptr<AuthenticatorFacadeStubHarness>
+ facade(new AuthenticatorFacadeStubHarness(&consumer,
+ test_username,
+ test_password));
+ EXPECT_CALL(consumer, OnLoginFailure(_))
+ .Times(1);
+
+ facade->AuthenticateToLogin(NULL,
+ bad_username,
+ test_password,
+ test_token,
+ test_captcha);
+
+ EXPECT_CALL(consumer, OnLoginFailure(_))
+ .Times(1);
+
+ facade->AuthenticateToLogin(NULL,
+ test_username,
+ bad_password,
+ test_token,
+ test_captcha);
+
+ EXPECT_CALL(consumer, OnLoginFailure(_))
+ .Times(1);
+
+ facade->AuthenticateToLogin(NULL,
+ bad_username,
+ bad_password,
+ test_token,
+ test_captcha);
+}
+
+// AuthenticateToUnlock
+TEST(AuthenticatorFacadeStubTest, AuthenticateToUnlockSuccess) {
+ MockLoginUIHandler consumer;
+ std::string test_username("Test_User");
+ std::string test_password("Test_Password");
+ scoped_ptr<AuthenticatorFacadeStubHarness>
+ facade(new AuthenticatorFacadeStubHarness(&consumer,
+ test_username,
+ test_password));
+
+ EXPECT_CALL(consumer, OnLoginSuccess(test_username,
+ _,
+ _,
+ false))
+ .Times(1);
+
+ facade->AuthenticateToUnlock(test_username, test_password);
+}
+
+TEST(AuthenticatorFacadeStubTest, AuthenticateToUnlockFailure) {
+ MockLoginUIHandler consumer;
+ std::string test_username("Test_User");
+ std::string test_password("Test_Password");
+ std::string bad_username("Bad_User");
+ std::string bad_password("Bad_Password");
+ scoped_ptr<AuthenticatorFacadeStubHarness>
+ facade(new AuthenticatorFacadeStubHarness(&consumer,
+ test_username,
+ test_password));
+ EXPECT_CALL(consumer, OnLoginFailure(_))
+ .Times(1);
+
+ facade->AuthenticateToUnlock(bad_username, test_password);
+
+ EXPECT_CALL(consumer, OnLoginFailure(_))
+ .Times(1);
+
+ facade->AuthenticateToUnlock(test_username, bad_password);
+
+ EXPECT_CALL(consumer, OnLoginFailure(_))
+ .Times(1);
+
+ facade->AuthenticateToUnlock(bad_username, bad_password);
+}
+
+} // namespace chromeos
diff --git a/chrome/browser/chromeos/dom_ui/login/login_ui.cc b/chrome/browser/chromeos/dom_ui/login/login_ui.cc
new file mode 100644
index 0000000..cf9d3f5
--- /dev/null
+++ b/chrome/browser/chromeos/dom_ui/login/login_ui.cc
@@ -0,0 +1,160 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/ref_counted_memory.h"
+#include "base/singleton.h"
+#include "base/string_piece.h"
+#include "base/values.h"
+#include "chrome/browser/browser_thread.h"
+#include "chrome/browser/chromeos/dom_ui/login/authenticator_facade.h"
+#include "chrome/browser/chromeos/dom_ui/login/login_ui.h"
+#include "chrome/browser/chromeos/dom_ui/login/login_ui_helpers.h"
+#include "chrome/browser/ui/browser.h"
+#include "chrome/browser/ui/browser_window.h"
+#include "chrome/common/url_constants.h"
+
+#if defined(OS_CHROMEOS)
+#include "chrome/browser/chromeos/dom_ui/login/authenticator_facade_cros.h"
+#else
+#include "chrome/browser/chromeos/dom_ui/login/authenticator_facade_stub.h"
+#endif
+
+namespace chromeos {
+
+////////////////////////////////////////////////////////////////////////////////
+//
+// LoginUIHTMLSource
+//
+////////////////////////////////////////////////////////////////////////////////
+
+LoginUIHTMLSource::LoginUIHTMLSource(MessageLoop* message_loop)
+ : DataSource(chrome::kChromeUILoginHost, message_loop),
+ html_operations_(new HTMLOperationsInterface()) {
+}
+
+void LoginUIHTMLSource::StartDataRequest(const std::string& path,
+ bool is_off_the_record,
+ int request_id) {
+ DictionaryValue localized_strings;
+ SetFontAndTextDirection(&localized_strings);
+
+ base::StringPiece login_html = html_operations_->GetLoginHTML();
+ std::string full_html = html_operations_->GetFullHTML(login_html,
+ &localized_strings);
+ scoped_refptr<RefCountedBytes> html_bytes(
+ html_operations_->CreateHTMLBytes(full_html));
+ SendResponse(request_id,
+ (html_bytes.get()));
+}
+
+////////////////////////////////////////////////////////////////////////////////
+//
+// LoginUIHandler
+//
+////////////////////////////////////////////////////////////////////////////////
+
+LoginUIHandler::LoginUIHandler()
+ : facade_(NULL),
+ profile_operations_(NULL),
+ browser_operations_(NULL) {
+#if defined(OS_CHROMEOS)
+ facade_.reset(new chromeos::AuthenticatorFacadeCros(this));
+#else
+ facade_.reset(new chromeos::AuthenticatorFacadeStub(this,
+ "chronos",
+ "chronos"));
+#endif
+ facade_->Setup();
+ profile_operations_.reset(new ProfileOperationsInterface());
+ browser_operations_.reset(new BrowserOperationsInterface());
+}
+
+DOMMessageHandler* LoginUIHandler::Attach(DOMUI* dom_ui) {
+ return DOMMessageHandler::Attach(dom_ui);
+}
+
+void LoginUIHandler::RegisterMessages() {
+ dom_ui_->RegisterMessageCallback(
+ "LaunchIncognito",
+ NewCallback(this,
+ &LoginUIHandler::HandleLaunchIncognito));
+ dom_ui_->RegisterMessageCallback(
+ "AuthenticateUser",
+ NewCallback(this,
+ &LoginUIHandler::HandleAuthenticateUser));
+}
+
+void LoginUIHandler::HandleAuthenticateUser(const ListValue* args) {
+ std::string username;
+ std::string password;
+ size_t expected_size = 2;
+ CHECK_EQ(args->GetSize(), expected_size);
+ args->GetString(0, &username);
+ args->GetString(1, &password);
+
+ Profile* profile = profile_operations_->GetDefaultProfile();
+ // For AuthenticateToLogin we are currently not using/supporting tokens and
+ // captchas, but the function signature that we inherit from
+ // LoginStatusConsumer has two fields for them. We are currently passing in an
+ // empty string for these fields by calling the default constructor for the
+ // string class.
+ facade_->AuthenticateToLogin(profile,
+ username,
+ password,
+ std::string(),
+ std::string());
+}
+
+void LoginUIHandler::HandleLaunchIncognito(const ListValue* args) {
+ Profile* profile = profile_operations_->GetDefaultProfileByPath();
+ Browser* login_browser = browser_operations_->GetLoginBrowser(profile);
+ Browser* logged_in = browser_operations_->CreateBrowser(profile);
+ logged_in->NewTab();
+ logged_in->window()->Show();
+ login_browser->CloseWindow();
+}
+
+void LoginUIHandler::OnLoginFailure(const LoginFailure& failure) {
+ Profile* profile = profile_operations_->GetDefaultProfileByPath();
+ Browser* login_browser = browser_operations_->GetLoginBrowser(profile);
+ login_browser->OpenCurrentURL();
+}
+
+void LoginUIHandler::OnLoginSuccess(
+ const std::string& username,
+ const std::string& password,
+ const GaiaAuthConsumer::ClientLoginResult& credentials,
+ bool pending_requests) {
+ Profile* profile = profile_operations_->GetDefaultProfileByPath();
+ Browser* login_browser = browser_operations_->GetLoginBrowser(profile);
+ Browser* logged_in = browser_operations_->CreateBrowser(profile);
+ logged_in->NewTab();
+ logged_in->window()->Show();
+ login_browser->CloseWindow();
+}
+
+void LoginUIHandler::OnOffTheRecordLoginSuccess() {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+//
+// LoginUI
+//
+////////////////////////////////////////////////////////////////////////////////
+LoginUI::LoginUI(TabContents* contents)
+ : DOMUI(contents) {
+ LoginUIHandler* handler = new LoginUIHandler();
+ AddMessageHandler(handler->Attach(this));
+ LoginUIHTMLSource* html_source =
+ new LoginUIHTMLSource(MessageLoop::current());
+
+ BrowserThread::PostTask(
+ BrowserThread::IO, FROM_HERE,
+ NewRunnableMethod(
+ ChromeURLDataManager::GetInstance(),
+ &ChromeURLDataManager::AddDataSource,
+ make_scoped_refptr(html_source)));
+}
+
+} // namespace chromeos
diff --git a/chrome/browser/chromeos/dom_ui/login/login_ui.h b/chrome/browser/chromeos/dom_ui/login/login_ui.h
new file mode 100644
index 0000000..b19699e
--- /dev/null
+++ b/chrome/browser/chromeos/dom_ui/login/login_ui.h
@@ -0,0 +1,96 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_CHROMEOS_DOM_UI_LOGIN_LOGIN_UI_H_
+#define CHROME_BROWSER_CHROMEOS_DOM_UI_LOGIN_LOGIN_UI_H_
+#pragma once
+
+#include <string>
+
+#include "base/scoped_ptr.h"
+#include "chrome/browser/chromeos/login/login_status_consumer.h"
+#include "chrome/browser/dom_ui/chrome_url_data_manager.h"
+#include "chrome/browser/dom_ui/dom_ui.h"
+
+class Profile;
+
+namespace chromeos {
+
+class AuthenticatorFacade;
+class BrowserOperationsInterface;
+class HTMLOperationsInterface;
+class ProfileOperationsInterface;
+
+// Boilerplate class that is used to associate the LoginUI code with the URL
+// "chrome://login"
+class LoginUIHTMLSource : public ChromeURLDataManager::DataSource {
+ public:
+ explicit LoginUIHTMLSource(MessageLoop* message_loop);
+
+ virtual void StartDataRequest(const std::string& path,
+ bool is_off_the_record,
+ int request_id);
+ virtual std::string GetMimeType(const std::string&) const {
+ return "text/html";
+ }
+
+ private:
+ scoped_ptr<HTMLOperationsInterface> html_operations_;
+
+ DISALLOW_COPY_AND_ASSIGN(LoginUIHTMLSource);
+};
+
+// Main LoginUI handling function. It handles the DOMui hooks that are supplied
+// for the login page to use for authentication. It passes the key pair form the
+// login page to the AuthenticatorFacade. The facade then will call back into
+// this class with the result, which will then be used to determine the browser
+// behaviour.
+class LoginUIHandler : public DOMMessageHandler,
+ public chromeos::LoginStatusConsumer {
+ public:
+ LoginUIHandler();
+
+ // DOMMessageHandler implementation.
+ virtual DOMMessageHandler* Attach(DOMUI* dom_ui);
+ virtual void RegisterMessages();
+
+ void HandleAuthenticateUser(const ListValue* args);
+ void HandleLaunchIncognito(const ListValue* args);
+
+ // Overridden from LoginStatusConsumer.
+ virtual void OnLoginFailure(const chromeos::LoginFailure& failure);
+ virtual void OnLoginSuccess(
+ const std::string& username,
+ const std::string& password,
+ const GaiaAuthConsumer::ClientLoginResult& credentials,
+ bool pending_requests);
+ virtual void OnOffTheRecordLoginSuccess();
+
+ protected:
+ scoped_ptr<AuthenticatorFacade> facade_;
+ scoped_ptr<ProfileOperationsInterface> profile_operations_;
+ scoped_ptr<BrowserOperationsInterface> browser_operations_;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(LoginUIHandler);
+};
+
+// Boilerplate class that is used to associate the LoginUI code with the DOMui
+// code.
+class LoginUI : public DOMUI {
+ public:
+ explicit LoginUI(TabContents* contents);
+
+ // Return the URL for a given search term.
+ static const GURL GetLoginURLWithSearchText(const string16& text);
+
+ static RefCountedMemory* GetFaviconResourceBytes();
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(LoginUI);
+};
+
+} // namespace chromeos
+
+#endif // CHROME_BROWSER_CHROMEOS_DOM_UI_LOGIN_LOGIN_UI_H_
diff --git a/chrome/browser/chromeos/dom_ui/login/login_ui_helpers.cc b/chrome/browser/chromeos/dom_ui/login/login_ui_helpers.cc
new file mode 100644
index 0000000..c0d05d0
--- /dev/null
+++ b/chrome/browser/chromeos/dom_ui/login/login_ui_helpers.cc
@@ -0,0 +1,94 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+// #include <algorithm>
+
+#include <algorithm>
+
+#include "app/resource_bundle.h"
+#include "base/file_path.h"
+#include "base/path_service.h"
+#include "base/values.h"
+#include "chrome/browser/browser_list.h"
+#include "chrome/browser/browser_process.h"
+#include "chrome/browser/chromeos/dom_ui/login/login_ui_helpers.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/profiles/profile_manager.h"
+#include "chrome/browser/ui/browser.h"
+#include "chrome/common/chrome_paths.h"
+#include "chrome/common/jstemplate_builder.h"
+#include "grit/browser_resources.h"
+
+namespace chromeos {
+
+////////////////////////////////////////////////////////////////////////////////
+//
+// ProfileOperationsInterface
+//
+////////////////////////////////////////////////////////////////////////////////
+Profile* ProfileOperationsInterface::GetDefaultProfile() {
+ ProfileManager* profile_manager = g_browser_process->profile_manager();
+ return profile_manager->GetDefaultProfile();
+}
+
+Profile* ProfileOperationsInterface::GetDefaultProfileByPath() {
+ return GetDefaultProfile(GetUserDataPath());
+}
+
+Profile* ProfileOperationsInterface::GetDefaultProfile(FilePath user_data_dir) {
+ ProfileManager* profile_manager = g_browser_process->profile_manager();
+ return profile_manager->GetDefaultProfile(user_data_dir);
+}
+
+FilePath ProfileOperationsInterface::GetUserDataPath() {
+ FilePath user_data_dir;
+ PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
+ return user_data_dir;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+//
+// BrowserOperationsInterface
+//
+////////////////////////////////////////////////////////////////////////////////
+Browser* BrowserOperationsInterface::CreateBrowser(Profile* profile) {
+ return Browser::Create(profile);
+}
+
+Browser* BrowserOperationsInterface::GetLoginBrowser(Profile* profile) {
+ return BrowserList::FindBrowserWithType(profile,
+ Browser::TYPE_ANY,
+ true);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+//
+// HTMLOperationsInterface
+//
+////////////////////////////////////////////////////////////////////////////////
+base::StringPiece HTMLOperationsInterface::GetLoginHTML() {
+ base::StringPiece login_html(
+ ResourceBundle::GetSharedInstance().GetRawDataResource(
+ IDR_LOGIN_HTML));
+ return login_html;
+}
+
+std::string HTMLOperationsInterface::GetFullHTML(
+ base::StringPiece login_html,
+ DictionaryValue* localized_strings) {
+ return jstemplate_builder::GetI18nTemplateHtml(
+ login_html,
+ localized_strings);
+}
+
+RefCountedBytes* HTMLOperationsInterface::CreateHTMLBytes(
+ std::string full_html) {
+ RefCountedBytes* html_bytes = new RefCountedBytes();
+ html_bytes->data.resize(full_html.size());
+ std::copy(full_html.begin(),
+ full_html.end(),
+ html_bytes->data.begin());
+ return html_bytes;
+}
+
+} // namespace chromeos
diff --git a/chrome/browser/chromeos/dom_ui/login/login_ui_helpers.h b/chrome/browser/chromeos/dom_ui/login/login_ui_helpers.h
new file mode 100644
index 0000000..93e73c5
--- /dev/null
+++ b/chrome/browser/chromeos/dom_ui/login/login_ui_helpers.h
@@ -0,0 +1,78 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_CHROMEOS_DOM_UI_LOGIN_LOGIN_UI_HELPERS_H_
+#define CHROME_BROWSER_CHROMEOS_DOM_UI_LOGIN_LOGIN_UI_HELPERS_H_
+#pragma once
+
+#include <string>
+
+class Browser;
+class DictionaryValue;
+class FilePath;
+class Profile;
+class RefCountedBytes;
+
+namespace base {
+class StringPiece;
+}; // namespace base
+
+namespace chromeos {
+
+// This class is used for encapsulating the statics and other other messy
+// external calls that are required for getting the needed profile objects. This
+// allows for easier mocking of this code and allows for modularity.
+class ProfileOperationsInterface {
+ public:
+ ProfileOperationsInterface() {}
+ virtual ~ProfileOperationsInterface() {}
+
+ virtual Profile* GetDefaultProfile();
+ virtual Profile* GetDefaultProfileByPath();
+
+ private:
+ Profile* GetDefaultProfile(FilePath user_data_dir);
+ FilePath GetUserDataPath();
+
+ DISALLOW_COPY_AND_ASSIGN(ProfileOperationsInterface);
+};
+
+// This class is used for encapsulating the statics and other other messy
+// external calls that are required for creating and getting the needed browser
+// objects. This allows for easier mocking of this code and allows for
+// modularity.
+class BrowserOperationsInterface {
+ public:
+ BrowserOperationsInterface() {}
+ virtual ~BrowserOperationsInterface() {}
+
+ virtual Browser* CreateBrowser(Profile* profile);
+ virtual Browser* GetLoginBrowser(Profile* profile);
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(BrowserOperationsInterface);
+};
+
+// This class is used for encapsulating the statics and other other messy
+// external calls that are required for creating and getting the needed HTML
+// objects. This allows for easier mocking of this code and allows for
+// modularity. Since we don't currently unit the class that this code is related
+// to, there is a case for refactoring it back into LoginUIHTMLSource.
+class HTMLOperationsInterface {
+ public:
+ HTMLOperationsInterface() {}
+ virtual ~HTMLOperationsInterface() {}
+
+ virtual base::StringPiece GetLoginHTML();
+ virtual std::string GetFullHTML(base::StringPiece login_html,
+ DictionaryValue* localized_strings);
+ virtual RefCountedBytes* CreateHTMLBytes(std::string full_html);
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(HTMLOperationsInterface);
+};
+
+} // namespace chromeos
+
+#endif // CHROME_BROWSER_CHROMEOS_DOM_UI_LOGIN_LOGIN_UI_HELPERS_H_
diff --git a/chrome/browser/chromeos/dom_ui/login/login_ui_unittest.cc b/chrome/browser/chromeos/dom_ui/login/login_ui_unittest.cc
new file mode 100644
index 0000000..e3e60b3
--- /dev/null
+++ b/chrome/browser/chromeos/dom_ui/login/login_ui_unittest.cc
@@ -0,0 +1,154 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <string>
+
+#include "base/scoped_ptr.h"
+#include "base/string_piece.h"
+#include "base/values.h"
+#include "chrome/browser/chromeos/dom_ui/login/login_ui.h"
+#include "chrome/browser/chromeos/dom_ui/login/login_ui_unittest.h"
+#include "chrome/test/testing_profile.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+using ::testing::_;
+using ::testing::Return;
+using ::testing::StrEq;
+
+// Listing of untested functions:
+//
+// LoginUI::*
+// LoginUIHTML::*
+//
+// The objects LoginUI and LoginUIHTMLSource do not have any testing,
+// since there are rather trivial/boilerplatey. They are used for hooking the
+// LoginUI code into the greater system and depend extensively on calling
+// external functions. The external functions should be unit tested, but the
+// these objects are better tested in a functional manner.
+//
+//
+// LoginUIHandler::RegisterMessage
+//
+// There is currently no test for LoginUIHandler::RegisterMessage, b/c the
+// function DOMUI::RegisterMesssageCallback is not declared virtual. This means
+// that it cannot be mocked easily and it is non-trivial to resolve, since just
+// making the function virtual causes other problems. Either this class or that
+// class needs to be refactored to deal with this before one can write this
+// test. Realistically there isn't much to fail in this function, so testing
+// should not be needed in this class.
+//
+//
+// LoginUIHandler::HandleLaunchIncognito
+// LoginUIHandler::OnLoginFailure
+// LoginUIHandler::OnLoginSuccess
+// LoginUIHandler::OnOffTheRecordLoginSuccess
+//
+// There no tests for these functions since all of them are pretty straight
+// forward assuming that the called functions perform as expected and it is
+// non-trivial to mock the Browser class.
+namespace chromeos {
+
+// LoginUIHandler::Attach
+TEST(LoginUIHandlerTest, Attach) {
+ // Don't care about the expected in this test
+ LoginUIHandlerHarness handler_harness("", "");
+ MockDOMUI dom_ui;
+
+ EXPECT_EQ(&handler_harness, handler_harness.Attach(&dom_ui));
+ EXPECT_EQ(&dom_ui, handler_harness.GetDOMUI());
+}
+
+// Helper for LoginUIHandler::HandleAuthenticateUser
+void RunHandleAuthenticateUserTest(const std::string& expected_username,
+ const std::string& expected_password,
+ const std::string& supplied_username,
+ const std::string& supplied_password) {
+ ListValue arg_list;
+ StringValue* username_value = new StringValue(supplied_username);
+ StringValue* password_value = new StringValue(supplied_password);
+ TestingProfile mock_profile;
+ LoginUIHandlerHarness handler(expected_username,
+ expected_password);
+
+ EXPECT_EQ(expected_username, handler.GetMockFacade()->GetUsername());
+ EXPECT_EQ(expected_password, handler.GetMockFacade()->GetPassword());
+
+ arg_list.Append(username_value);
+ arg_list.Append(password_value);
+ EXPECT_CALL(*(handler.GetMockProfileOperations()),
+ GetDefaultProfile())
+ .Times(1)
+ .WillRepeatedly(Return(&mock_profile));
+
+ EXPECT_CALL(*(handler.GetMockFacade()),
+ AuthenticateToLogin(&mock_profile,
+ StrEq(supplied_username),
+ StrEq(supplied_password),
+ StrEq(std::string()),
+ StrEq(std::string())))
+ .Times(1);
+
+ handler.HandleAuthenticateUser(&arg_list);
+ // This code does not simulate the callback that occurs in the
+ // AuthenticatorFacade, since that would be a) a functional test and b)
+ // require a working mock of Browser.
+}
+
+// LoginUIHandler::HandleAuthenticateUser on success
+TEST(LoginUIHandlerTest, HandleAuthenticateUserSuccess) {
+ RunHandleAuthenticateUserTest("chronos",
+ "chronos",
+ "chronos",
+ "chronos");
+
+ RunHandleAuthenticateUserTest("bob",
+ "mumistheword",
+ "bob",
+ "mumistheword");
+}
+
+// LoginUIHandler::HandleAuthenticateUser on failure
+TEST(LoginUIHandlerTest, HandleAuthenticateUserFailure) {
+ RunHandleAuthenticateUserTest("chronos",
+ "chronos",
+ std::string(),
+ "chronos");
+
+ RunHandleAuthenticateUserTest("chronos",
+ "chronos",
+ std::string(),
+ std::string());
+
+ RunHandleAuthenticateUserTest("chronos",
+ "chronos",
+ "chronos",
+ std::string());
+
+ RunHandleAuthenticateUserTest("chronos",
+ "chronos",
+ "bob",
+ "mumistheword");
+
+ RunHandleAuthenticateUserTest("bob",
+ "mumistheword",
+ "bob",
+ std::string());
+
+ RunHandleAuthenticateUserTest("bob",
+ "mumistheword",
+ std::string(),
+ std::string());
+
+ RunHandleAuthenticateUserTest("bob",
+ "mumistheword",
+ std::string(),
+ "mumistheword");
+
+ RunHandleAuthenticateUserTest("bob",
+ "mumistheword",
+ "chronos",
+ "chronos");
+}
+
+} // namespace chromeos
diff --git a/chrome/browser/chromeos/dom_ui/login/login_ui_unittest.h b/chrome/browser/chromeos/dom_ui/login/login_ui_unittest.h
new file mode 100644
index 0000000..cb143cc
--- /dev/null
+++ b/chrome/browser/chromeos/dom_ui/login/login_ui_unittest.h
@@ -0,0 +1,78 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_CHROMEOS_DOM_UI_LOGIN_LOGIN_UI_UNITTEST_H_
+#define CHROME_BROWSER_CHROMEOS_DOM_UI_LOGIN_LOGIN_UI_UNITTEST_H_
+#pragma once
+
+#include <string>
+
+#if defined(OS_CHROMEOS)
+#include "chrome/browser/chromeos/dom_ui/login/mock_authenticator_facade_cros.h"
+#else
+#include "chrome/browser/chromeos/dom_ui/login/mock_authenticator_facade_stub.h"
+#endif
+#include "chrome/browser/chromeos/dom_ui/login/mock_login_ui_helpers.h"
+#include "chrome/test/testing_profile.h"
+#include "testing/gmock/include/gmock/gmock.h"
+
+namespace chromeos {
+
+class MockDOMUI : public DOMUI {
+ public:
+ MockDOMUI() : DOMUI(NULL) {}
+ MOCK_METHOD2(RegisterMessageCallback,
+ void(const std::string& message,
+ MessageCallback* callback));
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(MockDOMUI);
+};
+
+class LoginUIHandlerHarness : public LoginUIHandler {
+ public:
+ explicit LoginUIHandlerHarness(const std::string& expected_username,
+ const std::string& expected_password)
+ : LoginUIHandler() {
+#if defined(OS_CHROMEOS)
+ facade_.reset(new MockAuthenticatorFacadeCros(this,
+ expected_username,
+ expected_password));
+#else
+ facade_.reset(new MockAuthenticatorFacadeStub(this,
+ expected_username,
+ expected_password));
+#endif
+ profile_operations_.reset(new MockProfileOperationsInterface());
+ browser_operations_.reset(new MockBrowserOperationsInterface());
+ }
+
+ DOMUI* GetDOMUI() const { return dom_ui_;}
+#if defined(OS_CHROMEOS)
+ MockAuthenticatorFacadeCros* GetMockFacade() const {
+ return static_cast<MockAuthenticatorFacadeCros*>
+ (facade_.get());
+ }
+#else
+ MockAuthenticatorFacadeStub* GetMockFacade() const {
+ return static_cast<MockAuthenticatorFacadeStub*>
+ (facade_.get());
+ }
+#endif
+ MockProfileOperationsInterface* GetMockProfileOperations() const {
+ return static_cast<MockProfileOperationsInterface*>
+ (profile_operations_.get());
+ }
+ MockBrowserOperationsInterface* GetMockBrowserOperations() const {
+ return static_cast<MockBrowserOperationsInterface*>
+ (browser_operations_.get());
+ }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(LoginUIHandlerHarness);
+};
+
+} // namespace chromeos
+
+#endif // CHROME_BROWSER_CHROMEOS_DOM_UI_LOGIN_LOGIN_UI_UNITTEST_H_
diff --git a/chrome/browser/chromeos/dom_ui/login/mock_authenticator_facade_cros.h b/chrome/browser/chromeos/dom_ui/login/mock_authenticator_facade_cros.h
new file mode 100644
index 0000000..a7dc25f
--- /dev/null
+++ b/chrome/browser/chromeos/dom_ui/login/mock_authenticator_facade_cros.h
@@ -0,0 +1,49 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_CHROMEOS_DOM_UI_LOGIN_MOCK_AUTHENTICATOR_FACADE_CROS_H_
+#define CHROME_BROWSER_CHROMEOS_DOM_UI_LOGIN_MOCK_AUTHENTICATOR_FACADE_CROS_H_
+#pragma once
+
+#include <string>
+
+#include "chrome/browser/chromeos/dom_ui/login/authenticator_facade_cros.h"
+#include "testing/gmock/include/gmock/gmock.h"
+
+namespace chromeos {
+
+class MockAuthenticatorFacadeCros : public AuthenticatorFacadeCros {
+ public:
+ explicit MockAuthenticatorFacadeCros(LoginStatusConsumer* consumer,
+ const std::string& expected_username,
+ const std::string& expected_password)
+ : chromeos::AuthenticatorFacadeCros(consumer),
+ expected_username_(expected_username),
+ expected_password_(expected_password) {}
+
+ MOCK_METHOD0(Setup,
+ void());
+ MOCK_METHOD5(AuthenticateToLogin,
+ void(Profile* profile,
+ const std::string& username,
+ const std::string& password,
+ const std::string& login_token,
+ const std::string& login_captcha));
+ MOCK_METHOD2(AuthenticateToUnlock,
+ void(const std::string& username,
+ const std::string& password));
+ const std::string& GetUsername() { return expected_username_; }
+ const std::string& GetPassword() { return expected_password_; }
+
+ protected:
+ std::string expected_username_;
+ std::string expected_password_;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(MockAuthenticatorFacadeCros);
+};
+
+} // namespace chromeos
+
+#endif // CHROME_BROWSER_CHROMEOS_DOM_UI_LOGIN_MOCK_AUTHENTICATOR_FACADE_CROS_H_
diff --git a/chrome/browser/chromeos/dom_ui/login/mock_authenticator_facade_cros_helpers.h b/chrome/browser/chromeos/dom_ui/login/mock_authenticator_facade_cros_helpers.h
new file mode 100644
index 0000000..fc54459
--- /dev/null
+++ b/chrome/browser/chromeos/dom_ui/login/mock_authenticator_facade_cros_helpers.h
@@ -0,0 +1,36 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_CHROMEOS_DOM_UI_LOGIN_MOCK_AUTHENTICATOR_FACADE_CROS_HELPERS_H_
+#define CHROME_BROWSER_CHROMEOS_DOM_UI_LOGIN_MOCK_AUTHENTICATOR_FACADE_CROS_HELPERS_H_
+#pragma once
+
+#include <string>
+
+#include "chrome/browser/chromeos/dom_ui/login/authenticator_facade_cros_helpers.h"
+#include "testing/gmock/include/gmock/gmock.h"
+
+namespace chromeos {
+
+class MockAuthenticatorFacadeCrosHelpers
+ : public AuthenticatorFacadeCrosHelpers {
+ public:
+ MockAuthenticatorFacadeCrosHelpers()
+ : AuthenticatorFacadeCrosHelpers() {}
+
+ MOCK_METHOD1(CreateAuthenticator,
+ Authenticator*(LoginStatusConsumer* consumer));
+ MOCK_METHOD4(PostAuthenticateToLogin,
+ void(Authenticator* authenticator,
+ Profile* profile,
+ const std::string& username,
+ const std::string& password));
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(MockAuthenticatorFacadeCrosHelpers);
+};
+
+} // namespace chromeos
+
+#endif // CHROME_BROWSER_CHROMEOS_DOM_UI_LOGIN_MOCK_AUTHENTICATOR_FACADE_CROS_HELPERS_H_
diff --git a/chrome/browser/chromeos/dom_ui/login/mock_authenticator_facade_stub.h b/chrome/browser/chromeos/dom_ui/login/mock_authenticator_facade_stub.h
new file mode 100644
index 0000000..d1b1389
--- /dev/null
+++ b/chrome/browser/chromeos/dom_ui/login/mock_authenticator_facade_stub.h
@@ -0,0 +1,44 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_CHROMEOS_DOM_UI_LOGIN_MOCK_AUTHENTICATOR_FACADE_STUB_H_
+#define CHROME_BROWSER_CHROMEOS_DOM_UI_LOGIN_MOCK_AUTHENTICATOR_FACADE_STUB_H_
+#pragma once
+
+#include <string>
+
+#include "chrome/browser/chromeos/dom_ui/login/authenticator_facade_stub.h"
+#include "testing/gmock/include/gmock/gmock.h"
+
+namespace chromeos {
+
+class MockAuthenticatorFacadeStub : public AuthenticatorFacadeStub {
+ public:
+ explicit MockAuthenticatorFacadeStub(LoginStatusConsumer* consumer,
+ const std::string& expected_username,
+ const std::string& expected_password)
+ : chromeos::AuthenticatorFacadeStub(consumer,
+ expected_username,
+ expected_password) {}
+ MOCK_METHOD0(Setup,
+ void());
+ MOCK_METHOD5(AuthenticateToLogin,
+ void(Profile* profile,
+ const std::string& username,
+ const std::string& password,
+ const std::string& login_token,
+ const std::string& login_captcha));
+ MOCK_METHOD2(AuthenticateToUnlock,
+ void(const std::string& username,
+ const std::string& password));
+ const std::string& GetUsername() { return expected_username_; }
+ const std::string& GetPassword() { return expected_password_; }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(MockAuthenticatorFacadeStub);
+};
+
+} // namespace chromeos
+
+#endif // CHROME_BROWSER_CHROMEOS_DOM_UI_LOGIN_MOCK_AUTHENTICATOR_FACADE_STUB_H_
diff --git a/chrome/browser/chromeos/dom_ui/login/mock_login_ui_handler.h b/chrome/browser/chromeos/dom_ui/login/mock_login_ui_handler.h
new file mode 100644
index 0000000..236f5c6
--- /dev/null
+++ b/chrome/browser/chromeos/dom_ui/login/mock_login_ui_handler.h
@@ -0,0 +1,36 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_CHROMEOS_DOM_UI_LOGIN_MOCK_LOGIN_UI_HANDLER_H_
+#define CHROME_BROWSER_CHROMEOS_DOM_UI_LOGIN_MOCK_LOGIN_UI_HANDLER_H_
+#pragma once
+
+#include <string>
+
+#include "chrome/browser/chromeos/dom_ui/login/login_ui.h"
+#include "chrome/browser/chromeos/dom_ui/login/login_ui_helpers.h"
+#include "testing/gmock/include/gmock/gmock.h"
+
+namespace chromeos {
+
+class MockLoginUIHandler : public chromeos::LoginUIHandler {
+ public:
+ MOCK_METHOD1(Attach,
+ DOMMessageHandler*(DOMUI* dom_ui));
+ MOCK_METHOD0(RegisterMessages,
+ void());
+ MOCK_METHOD1(OnLoginFailure,
+ void(const chromeos::LoginFailure& failure));
+ MOCK_METHOD4(OnLoginSuccess,
+ void(const std::string& username,
+ const std::string& password,
+ const GaiaAuthConsumer::ClientLoginResult& credentials,
+ bool pending_requests));
+ MOCK_METHOD0(OnOffTheRecordLoginSuccess,
+ void());
+};
+
+} // namespace chromeos
+
+#endif // CHROME_BROWSER_CHROMEOS_DOM_UI_LOGIN_MOCK_LOGIN_UI_HANDLER_H_
diff --git a/chrome/browser/chromeos/dom_ui/login/mock_login_ui_helpers.h b/chrome/browser/chromeos/dom_ui/login/mock_login_ui_helpers.h
new file mode 100644
index 0000000..0217abd
--- /dev/null
+++ b/chrome/browser/chromeos/dom_ui/login/mock_login_ui_helpers.h
@@ -0,0 +1,63 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_CHROMEOS_DOM_UI_LOGIN_MOCK_LOGIN_UI_HELPERS_H_
+#define CHROME_BROWSER_CHROMEOS_DOM_UI_LOGIN_MOCK_LOGIN_UI_HELPERS_H_
+#pragma once
+
+#include <string>
+
+#include "chrome/browser/chromeos/dom_ui/login/login_ui_helpers.h"
+#include "testing/gmock/include/gmock/gmock.h"
+
+namespace chromeos {
+
+class MockProfileOperationsInterface
+ : public chromeos::ProfileOperationsInterface {
+ public:
+ MockProfileOperationsInterface() {}
+
+ MOCK_METHOD0(GetDefaultProfile,
+ Profile*());
+ MOCK_METHOD0(GetDefaultProfileByPath,
+ Profile*());
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(MockProfileOperationsInterface);
+};
+
+class MockBrowserOperationsInterface
+ : public chromeos::BrowserOperationsInterface {
+ public:
+ MockBrowserOperationsInterface() {}
+
+ MOCK_METHOD1(CreateBrowser,
+ Browser*(Profile* profile));
+ MOCK_METHOD1(GetLoginBrowser,
+ Browser*(Profile* profile));
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(MockBrowserOperationsInterface);
+};
+
+class MockHTMLOperationsInterface
+ : public chromeos::HTMLOperationsInterface {
+ public:
+ MockHTMLOperationsInterface() {}
+
+ MOCK_METHOD0(GetLoginHTML,
+ base::StringPiece());
+ MOCK_METHOD2(GetFullHTML,
+ std::string(base::StringPiece login_html,
+ DictionaryValue* localized_strings));
+ MOCK_METHOD1(CreateHTMLBytes,
+ RefCountedBytes*(std::string full_html));
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(MockHTMLOperationsInterface);
+};
+
+} // namespace chromeos
+
+#endif // CHROME_BROWSER_CHROMEOS_DOM_UI_LOGIN_MOCK_LOGIN_UI_HELPERS_H_
diff --git a/chrome/browser/chromeos/dom_ui/menu_ui.cc b/chrome/browser/chromeos/dom_ui/menu_ui.cc
index 8ffd2a8..1bbc2b4 100644
--- a/chrome/browser/chromeos/dom_ui/menu_ui.cc
+++ b/chrome/browser/chromeos/dom_ui/menu_ui.cc
@@ -4,6 +4,8 @@
#include "chrome/browser/chromeos/dom_ui/menu_ui.h"
+#include <algorithm>
+
#include "app/menus/menu_model.h"
#include "app/resource_bundle.h"
#include "base/callback.h"
@@ -20,7 +22,6 @@
#include "chrome/browser/chromeos/views/domui_menu_widget.h"
#include "chrome/browser/chromeos/views/native_menu_domui.h"
#include "chrome/browser/dom_ui/dom_ui_util.h"
-#include "chrome/browser/profile.h"
#include "chrome/browser/tab_contents/tab_contents.h"
#include "chrome/browser/tab_contents/tab_contents_delegate.h"
#include "chrome/common/url_constants.h"
@@ -314,8 +315,7 @@ MenuUIHTMLSource::MenuUIHTMLSource(const chromeos::MenuSourceDelegate* delegate,
delegate_(delegate),
menu_class_(menu_class),
menu_source_id_(menu_source_id),
- menu_css_id_(menu_css_id)
-{
+ menu_css_id_(menu_css_id) {
}
void MenuUIHTMLSource::StartDataRequest(const std::string& path,
@@ -535,7 +535,7 @@ MenuUI::MenuUI(TabContents* contents) : DOMUI(contents) {
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
NewRunnableMethod(
- Singleton<ChromeURLDataManager>::get(),
+ ChromeURLDataManager::GetInstance(),
&ChromeURLDataManager::AddDataSource,
make_scoped_refptr(CreateDataSource())));
}
@@ -548,7 +548,7 @@ MenuUI::MenuUI(TabContents* contents, ChromeURLDataManager::DataSource* source)
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
NewRunnableMethod(
- Singleton<ChromeURLDataManager>::get(),
+ ChromeURLDataManager::GetInstance(),
&ChromeURLDataManager::AddDataSource,
make_scoped_refptr(source)));
}
diff --git a/chrome/browser/chromeos/dom_ui/mobile_setup_ui.cc b/chrome/browser/chromeos/dom_ui/mobile_setup_ui.cc
index d254d90..f1e980d 100644
--- a/chrome/browser/chromeos/dom_ui/mobile_setup_ui.cc
+++ b/chrome/browser/chromeos/dom_ui/mobile_setup_ui.cc
@@ -22,14 +22,13 @@
#include "base/values.h"
#include "base/weak_ptr.h"
#include "chrome/browser/browser_list.h"
-#include "chrome/browser/browser_process.h"
#include "chrome/browser/browser_thread.h"
#include "chrome/browser/chromeos/cros/cros_library.h"
#include "chrome/browser/chromeos/cros/network_library.h"
#include "chrome/browser/chromeos/cros/system_library.h"
#include "chrome/browser/dom_ui/chrome_url_data_manager.h"
#include "chrome/browser/prefs/pref_service.h"
-#include "chrome/browser/profile.h"
+#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/tab_contents/tab_contents.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/common/jstemplate_builder.h"
@@ -1036,7 +1035,7 @@ MobileSetupUI::MobileSetupUI(TabContents* contents) : DOMUI(contents) {
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
NewRunnableMethod(
- Singleton<ChromeURLDataManager>::get(),
+ ChromeURLDataManager::GetInstance(),
&ChromeURLDataManager::AddDataSource,
make_scoped_refptr(html_source)));
}
diff --git a/chrome/browser/chromeos/dom_ui/network_menu_ui.cc b/chrome/browser/chromeos/dom_ui/network_menu_ui.cc
index a9aa9c4..2973432 100644
--- a/chrome/browser/chromeos/dom_ui/network_menu_ui.cc
+++ b/chrome/browser/chromeos/dom_ui/network_menu_ui.cc
@@ -121,7 +121,7 @@ NetworkMenuUI::NetworkMenuUI(TabContents* contents)
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
NewRunnableMethod(
- Singleton<ChromeURLDataManager>::get(),
+ ChromeURLDataManager::GetInstance(),
&ChromeURLDataManager::AddDataSource,
make_scoped_refptr(theme)));
}
diff --git a/chrome/browser/chromeos/dom_ui/proxy_handler.cc b/chrome/browser/chromeos/dom_ui/proxy_handler.cc
index 7a196f8..759d8bd 100644
--- a/chrome/browser/chromeos/dom_ui/proxy_handler.cc
+++ b/chrome/browser/chromeos/dom_ui/proxy_handler.cc
@@ -13,7 +13,6 @@
#include "base/utf_string_conversions.h"
#include "base/values.h"
#include "chrome/browser/chromeos/proxy_cros_settings_provider.h"
-#include "chrome/common/notification_service.h"
#include "grit/browser_resources.h"
#include "grit/chromium_strings.h"
#include "grit/generated_resources.h"
@@ -69,4 +68,4 @@ void ProxyHandler::GetLocalizedValues(
l10n_util::GetStringUTF16(IDS_PROXY_BYPASS));
}
-} // namespace chromeos
+} // namespace chromeos
diff --git a/chrome/browser/chromeos/dom_ui/register_page_ui.cc b/chrome/browser/chromeos/dom_ui/register_page_ui.cc
index 8357fbc..1778490 100644
--- a/chrome/browser/chromeos/dom_ui/register_page_ui.cc
+++ b/chrome/browser/chromeos/dom_ui/register_page_ui.cc
@@ -326,7 +326,7 @@ RegisterPageUI::RegisterPageUI(TabContents* contents) : DOMUI(contents){
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
NewRunnableMethod(
- Singleton<ChromeURLDataManager>::get(),
+ ChromeURLDataManager::GetInstance(),
&ChromeURLDataManager::AddDataSource,
make_scoped_refptr(html_source)));
}
diff --git a/chrome/browser/chromeos/dom_ui/stats_options_handler.cc b/chrome/browser/chromeos/dom_ui/stats_options_handler.cc
index c228946..38ed546 100644
--- a/chrome/browser/chromeos/dom_ui/stats_options_handler.cc
+++ b/chrome/browser/chromeos/dom_ui/stats_options_handler.cc
@@ -9,6 +9,7 @@
#include "base/utf_string_conversions.h"
#include "base/values.h"
#include "chrome/browser/chromeos/cros_settings_names.h"
+#include "chrome/browser/chromeos/login/user_manager.h"
#include "chrome/browser/chromeos/metrics_cros_settings_provider.h"
#include "chrome/browser/metrics/user_metrics.h"
@@ -54,7 +55,7 @@ void StatsOptionsHandler::HandleMetricsReportingCheckbox(
void StatsOptionsHandler::SetupMetricsReportingCheckbox(bool user_changed) {
#if defined(GOOGLE_CHROME_BUILD)
FundamentalValue checked(MetricsCrosSettingsProvider::GetMetricsStatus());
- FundamentalValue disabled(false);
+ FundamentalValue disabled(!UserManager::Get()->current_user_is_owner());
FundamentalValue user_has_changed(user_changed);
dom_ui_->CallJavascriptFunction(
L"options.AdvancedOptions.SetMetricsReportingCheckboxState", checked,
diff --git a/chrome/browser/chromeos/dom_ui/system_info_ui.cc b/chrome/browser/chromeos/dom_ui/system_info_ui.cc
index d9a70da..857c560 100644
--- a/chrome/browser/chromeos/dom_ui/system_info_ui.cc
+++ b/chrome/browser/chromeos/dom_ui/system_info_ui.cc
@@ -182,7 +182,7 @@ SystemInfoUI::SystemInfoUI(TabContents* contents) : DOMUI(contents) {
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
NewRunnableMethod(
- Singleton<ChromeURLDataManager>::get(),
+ ChromeURLDataManager::GetInstance(),
&ChromeURLDataManager::AddDataSource,
make_scoped_refptr(html_source)));
}
diff --git a/chrome/browser/chromeos/dom_ui/system_options_handler.cc b/chrome/browser/chromeos/dom_ui/system_options_handler.cc
index d47c82c..d543871 100644
--- a/chrome/browser/chromeos/dom_ui/system_options_handler.cc
+++ b/chrome/browser/chromeos/dom_ui/system_options_handler.cc
@@ -14,7 +14,6 @@
#include "base/values.h"
#include "chrome/browser/chromeos/dom_ui/system_settings_provider.h"
#include "chrome/browser/chromeos/language_preferences.h"
-#include "chrome/common/notification_service.h"
#include "grit/browser_resources.h"
#include "grit/chromium_strings.h"
#include "grit/generated_resources.h"
diff --git a/chrome/browser/chromeos/dom_ui/system_settings_provider.cc b/chrome/browser/chromeos/dom_ui/system_settings_provider.cc
index d8b0c10..fcfa7dc 100644
--- a/chrome/browser/chromeos/dom_ui/system_settings_provider.cc
+++ b/chrome/browser/chromeos/dom_ui/system_settings_provider.cc
@@ -214,8 +214,8 @@ void SystemSettingsProvider::DoSet(const std::string& path, Value* in_value) {
bool SystemSettingsProvider::Get(const std::string& path,
Value** out_value) const {
if (path == kSystemTimezone) {
- *out_value = Value::CreateStringValue(
- GetTimezoneID(CrosLibrary::Get()->GetSystemLibrary()->GetTimezone()));
+ *out_value = Value::CreateStringValue(GetKnownTimezoneID(
+ CrosLibrary::Get()->GetSystemLibrary()->GetTimezone()));
return true;
}
return false;
@@ -300,4 +300,17 @@ const icu::TimeZone* SystemSettingsProvider::GetTimezone(
return NULL;
}
+string16 SystemSettingsProvider::GetKnownTimezoneID(
+ const icu::TimeZone& timezone) const {
+ for (std::vector<icu::TimeZone*>::const_iterator iter = timezones_.begin();
+ iter != timezones_.end(); ++iter) {
+ const icu::TimeZone* known_timezone = *iter;
+ if (known_timezone->hasSameRules(timezone))
+ return GetTimezoneID(*known_timezone);
+ }
+
+ // Not able to find a matching timezone in our list.
+ return string16();
+}
+
} // namespace chromeos
diff --git a/chrome/browser/chromeos/dom_ui/system_settings_provider.h b/chrome/browser/chromeos/dom_ui/system_settings_provider.h
index 816ea2c..a355df6 100644
--- a/chrome/browser/chromeos/dom_ui/system_settings_provider.h
+++ b/chrome/browser/chromeos/dom_ui/system_settings_provider.h
@@ -46,6 +46,15 @@ class SystemSettingsProvider : public CrosSettingsProvider,
// Gets timezone object from its id.
const icu::TimeZone* GetTimezone(const string16& timezone_id);
+ // Gets a timezone id from a timezone in |timezones_| that has the same
+ // rule of given |timezone|.
+ // One timezone could have multiple timezones,
+ // e.g.
+ // US/Pacific == America/Los_Angeles
+ // We should always use the known timezone id when passing back as
+ // pref values.
+ string16 GetKnownTimezoneID(const icu::TimeZone& timezone) const;
+
// Timezones.
std::vector<icu::TimeZone*> timezones_;