summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authornkostylev@chromium.org <nkostylev@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-23 11:15:36 +0000
committernkostylev@chromium.org <nkostylev@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-23 11:15:36 +0000
commit9b78cfd2818651c50f76990771fdaae1d85c3c3d (patch)
tree78fb51629371b48675769b535a5e019a06550af7 /chrome/browser
parentadf5f63b6300d9336a0b5a7c23634cb36254c5a0 (diff)
downloadchromium_src-9b78cfd2818651c50f76990771fdaae1d85c3c3d.zip
chromium_src-9b78cfd2818651c50f76990771fdaae1d85c3c3d.tar.gz
chromium_src-9b78cfd2818651c50f76990771fdaae1d85c3c3d.tar.bz2
[cros] Initial CL for SIM card unlock support.
BUG=chromium-os:12007 TEST=Manual. Open chrome:sim-unlock. Review URL: http://codereview.chromium.org/6708087 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@79112 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/browser_resources.grd1
-rw-r--r--chrome/browser/chromeos/webui/sim_unlock_ui.cc181
-rw-r--r--chrome/browser/chromeos/webui/sim_unlock_ui.h27
-rw-r--r--chrome/browser/resources/chromeos/sim_unlock.html11
-rw-r--r--chrome/browser/resources/chromeos/sim_unlock.js11
5 files changed, 231 insertions, 0 deletions
diff --git a/chrome/browser/browser_resources.grd b/chrome/browser/browser_resources.grd
index d4be682..b2fee28 100644
--- a/chrome/browser/browser_resources.grd
+++ b/chrome/browser/browser_resources.grd
@@ -109,6 +109,7 @@ without changes to the corresponding grd file. etaa -->
<include name="IDR_OS_CREDITS_HTML" file="resources\about_os_credits.html" flattenhtml="true" type="BINDATA" />
<include name="IDR_PROXY_SETTINGS_HTML" file="resources\chromeos\proxy_settings.html" flattenhtml="true" type="BINDATA" />
<include name="IDR_SLIDESHOW_HTML" file="resources\slideshow.html" flattenhtml="true" type="BINDATA" />
+ <include name="IDR_SIM_UNLOCK_HTML" file="resources\chromeos\sim_unlock.html" flattenhtml="true" type="BINDATA" />
<include name="IDR_MENU_HTML" file="resources\menu.html" flattenhtml="true" type="BINDATA" />
<include name="IDR_NETWORK_MENU_CSS" file="resources\network_menu.css" flattenhtml="true" type="BINDATA" />
<include name="IDR_NETWORK_MENU_JS" file="resources\network_menu.js" flattenhtml="true" type="BINDATA" />
diff --git a/chrome/browser/chromeos/webui/sim_unlock_ui.cc b/chrome/browser/chromeos/webui/sim_unlock_ui.cc
new file mode 100644
index 0000000..e9f13818
--- /dev/null
+++ b/chrome/browser/chromeos/webui/sim_unlock_ui.cc
@@ -0,0 +1,181 @@
+// Copyright (c) 2011 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/webui/sim_unlock_ui.h"
+
+#include <string>
+
+#include "base/string_piece.h"
+#include "base/values.h"
+#include "base/weak_ptr.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/ui/webui/chrome_url_data_manager.h"
+#include "chrome/common/jstemplate_builder.h"
+#include "chrome/common/url_constants.h"
+#include "content/browser/tab_contents/tab_contents.h"
+#include "grit/browser_resources.h"
+#include "grit/generated_resources.h"
+#include "ui/base/l10n/l10n_util.h"
+#include "ui/base/resource/resource_bundle.h"
+
+namespace {
+
+// Host page JS API function names.
+const char kJsApiEnterPinCode[] = "enterPinCode";
+const char kJsApiEnterPukCode[] = "enterPukCode";
+
+} // namespace
+
+namespace chromeos {
+
+class SimUnlockUIHTMLSource : public ChromeURLDataManager::DataSource {
+ public:
+ SimUnlockUIHTMLSource();
+
+ // Called when the network layer has requested a resource underneath
+ // the path we registered.
+ virtual void StartDataRequest(const std::string& path,
+ bool is_incognito,
+ int request_id);
+ virtual std::string GetMimeType(const std::string&) const {
+ return "text/html";
+ }
+
+ private:
+ virtual ~SimUnlockUIHTMLSource() {}
+
+ std::string service_path_;
+ DISALLOW_COPY_AND_ASSIGN(SimUnlockUIHTMLSource);
+};
+
+// The handler for Javascript messages related to the "sim-unlock" view.
+class SimUnlockHandler : public WebUIMessageHandler,
+ public base::SupportsWeakPtr<SimUnlockHandler> {
+ public:
+ SimUnlockHandler();
+ virtual ~SimUnlockHandler();
+
+ // Init work after Attach.
+ void Init(TabContents* contents);
+
+ // WebUIMessageHandler implementation.
+ virtual WebUIMessageHandler* Attach(WebUI* web_ui);
+ virtual void RegisterMessages();
+
+ private:
+ // Handlers for JS WebUI messages.
+ void HandleEnterPinCode(const ListValue* args);
+ void HandleEnterPukCode(const ListValue* args);
+
+ TabContents* tab_contents_;
+
+ DISALLOW_COPY_AND_ASSIGN(SimUnlockHandler);
+};
+
+// SimUnlockUIHTMLSource -------------------------------------------------------
+
+SimUnlockUIHTMLSource::SimUnlockUIHTMLSource()
+ : DataSource(chrome::kChromeUISimUnlockHost, MessageLoop::current()) {
+}
+
+void SimUnlockUIHTMLSource::StartDataRequest(const std::string& path,
+ bool is_incognito,
+ int request_id) {
+ DictionaryValue strings;
+ strings.SetString("title",
+ l10n_util::GetStringUTF16(IDS_SIM_UNLOCK_ENTER_PIN_TITLE));
+ strings.SetString("enterPinTitle",
+ l10n_util::GetStringUTF16(IDS_SIM_UNLOCK_ENTER_PIN_TITLE));
+ strings.SetString("incorrectPinMessage",
+ l10n_util::GetStringUTF16(IDS_SIM_UNLOCK_INCORRECT_PIN_MESSAGE));
+ // TODO(nkostylev): Initialize string with number of PIN tries left.
+ strings.SetString("pinTriesLeft",
+ l10n_util::GetStringFUTF16(IDS_SIM_UNLOCK_PIN_TRIES_LEFT_MESSAGE,
+ string16()));
+ strings.SetString("incorrectPinTitle",
+ l10n_util::GetStringUTF16(IDS_SIM_UNLOCK_INCORRECT_PIN_TITLE));
+ // TODO(nkostylev): Pass carrier name if we know that.
+ strings.SetString("noPinTriesLeft", l10n_util::GetStringFUTF16(
+ IDS_SIM_UNLOCK_NO_PIN_TRIES_LEFT_MESSAGE,
+ l10n_util::GetStringUTF16(IDS_SIM_UNLOCK_DEFAULT_CARRIER)));
+ strings.SetString("enterPukButton",
+ l10n_util::GetStringUTF16(IDS_SIM_UNLOCK_ENTER_PUK_BUTTON));
+ strings.SetString("enterPukTitle",
+ l10n_util::GetStringUTF16(IDS_SIM_UNLOCK_ENTER_PUK_TITLE));
+ // TODO(nkostylev): Initialize string with number of PIN tries left.
+ strings.SetString("pukTriesLeft",
+ l10n_util::GetStringFUTF16(IDS_SIM_UNLOCK_PUK_TRIES_LEFT_MESSAGE,
+ string16()));
+ // TODO(nkostylev): Pass carrier name if we know that.
+ strings.SetString("enterPukMessage", l10n_util::GetStringFUTF16(
+ IDS_SIM_UNLOCK_ENTER_PUK_MESSAGE,
+ l10n_util::GetStringUTF16(IDS_SIM_UNLOCK_DEFAULT_CARRIER)));
+ strings.SetString("noPukTriesLeft",
+ l10n_util::GetStringUTF16(IDS_SIM_UNLOCK_NO_PUK_TRIES_LEFT_MESSAGE));
+ strings.SetString("simBlockedTitle",
+ l10n_util::GetStringUTF16(IDS_SIM_UNLOCK_SIM_BLOCKED_TITLE));
+ strings.SetString("simBlockedMessage",
+ l10n_util::GetStringUTF16(IDS_SIM_UNLOCK_SIM_BLOCKED_MESSAGE));
+ SetFontAndTextDirection(&strings);
+
+ static const base::StringPiece html(
+ ResourceBundle::GetSharedInstance().GetRawDataResource(
+ IDR_SIM_UNLOCK_HTML));
+
+ const std::string& full_html = jstemplate_builder::GetI18nTemplateHtml(
+ html, &strings);
+
+ scoped_refptr<RefCountedBytes> html_bytes(new RefCountedBytes());
+ html_bytes->data.resize(full_html.size());
+ std::copy(full_html.begin(), full_html.end(), html_bytes->data.begin());
+
+ SendResponse(request_id, html_bytes);
+}
+
+// SimUnlockHandler ------------------------------------------------------------
+
+SimUnlockHandler::SimUnlockHandler()
+ : tab_contents_(NULL) {
+}
+
+SimUnlockHandler::~SimUnlockHandler() {
+}
+
+WebUIMessageHandler* SimUnlockHandler::Attach(WebUI* web_ui) {
+ return WebUIMessageHandler::Attach(web_ui);
+}
+
+void SimUnlockHandler::Init(TabContents* contents) {
+ tab_contents_ = contents;
+ // TODO(nkostylev): Init SIM lock/unlock state.
+}
+
+void SimUnlockHandler::RegisterMessages() {
+ web_ui_->RegisterMessageCallback(kJsApiEnterPinCode,
+ NewCallback(this, &SimUnlockHandler::HandleEnterPinCode));
+ web_ui_->RegisterMessageCallback(kJsApiEnterPukCode,
+ NewCallback(this, &SimUnlockHandler::HandleEnterPukCode));
+}
+
+void SimUnlockHandler::HandleEnterPinCode(const ListValue* args) {
+ // TODO(nkostylev): Pass PIN code to flimflam.
+}
+
+void SimUnlockHandler::HandleEnterPukCode(const ListValue* args) {
+ // TODO(nkostylev): Pass PUK code to flimflam.
+}
+
+// SimUnlockUI -----------------------------------------------------------------
+
+SimUnlockUI::SimUnlockUI(TabContents* contents) : WebUI(contents) {
+ SimUnlockHandler* handler = new SimUnlockHandler();
+ AddMessageHandler((handler)->Attach(this));
+ handler->Init(contents);
+ SimUnlockUIHTMLSource* html_source = new SimUnlockUIHTMLSource();
+
+ // Set up the chrome://sim-unlock/ source.
+ contents->profile()->GetChromeURLDataManager()->AddDataSource(html_source);
+}
+
+} // namespace chromeos
diff --git a/chrome/browser/chromeos/webui/sim_unlock_ui.h b/chrome/browser/chromeos/webui/sim_unlock_ui.h
new file mode 100644
index 0000000..4f39ad5
--- /dev/null
+++ b/chrome/browser/chromeos/webui/sim_unlock_ui.h
@@ -0,0 +1,27 @@
+// Copyright (c) 2011 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_WEBUI_SIM_UNLOCK_UI_H_
+#define CHROME_BROWSER_CHROMEOS_WEBUI_SIM_UNLOCK_UI_H_
+#pragma once
+
+#include "content/browser/webui/web_ui.h"
+
+namespace chromeos {
+
+// A custom WebUI that defines datasource for SIM unlock dialog that is used
+// in Chrome OS for specific tasks:
+// - Unlock SIM card (enter PIN/PUK codes).
+// - Display "SIM card is blocked" message when there're no PUK tries left.
+class SimUnlockUI : public WebUI {
+ public:
+ explicit SimUnlockUI(TabContents* contents);
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(SimUnlockUI);
+};
+
+} // namespace chromeos
+
+#endif // CHROME_BROWSER_CHROMEOS_WEBUI_SIM_UNLOCK_UI_H_
diff --git a/chrome/browser/resources/chromeos/sim_unlock.html b/chrome/browser/resources/chromeos/sim_unlock.html
new file mode 100644
index 0000000..a7c214e4
--- /dev/null
+++ b/chrome/browser/resources/chromeos/sim_unlock.html
@@ -0,0 +1,11 @@
+<!DOCTYPE HTML>
+<html i18n-values="dir:textdirection">
+<head>
+<title i18n-content="title"></title>
+<script src="chrome://resources/js/cr/event_target.js"></script>
+<script src="chrome://resources/js/util.js"></script>
+<script src="sim_unlock.js"></script>
+</head>
+<body i18n-values=".style.fontFamily:fontfamily;">
+</body>
+</html>
diff --git a/chrome/browser/resources/chromeos/sim_unlock.js b/chrome/browser/resources/chromeos/sim_unlock.js
new file mode 100644
index 0000000..e80fe8d
--- /dev/null
+++ b/chrome/browser/resources/chromeos/sim_unlock.js
@@ -0,0 +1,11 @@
+// Copyright (c) 2011 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.
+
+/**
+ * DOMContentLoaded handler, initializes the page.
+ */
+function load() {
+}
+
+document.addEventListener('DOMContentLoaded', load);