Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / webui / chromeos / mobile_setup_ui.cc
index c9bc8d7..8884cb6 100644 (file)
@@ -33,6 +33,7 @@
 #include "chromeos/network/network_state_handler.h"
 #include "chromeos/network/network_state_handler_observer.h"
 #include "content/public/browser/browser_thread.h"
+#include "content/public/browser/render_frame_host.h"
 #include "content/public/browser/url_data_source.h"
 #include "content/public/browser/web_contents.h"
 #include "content/public/browser/web_ui.h"
@@ -85,14 +86,15 @@ void DataRequestFailed(
 }
 
 // Converts the network properties into a JS object.
-void GetDeviceInfo(const DictionaryValue& properties, DictionaryValue* value) {
+void GetDeviceInfo(const base::DictionaryValue& properties,
+                   base::DictionaryValue* value) {
   std::string name;
   properties.GetStringWithoutPathExpansion(shill::kNameProperty, &name);
-  bool activate_over_non_cellular_networks = false;
-  properties.GetBooleanWithoutPathExpansion(
-      shill::kActivateOverNonCellularNetworkProperty,
-      &activate_over_non_cellular_networks);
-  const DictionaryValue* payment_dict;
+  std::string activation_type;
+  properties.GetStringWithoutPathExpansion(
+      shill::kActivationTypeProperty,
+      &activation_type);
+  const base::DictionaryValue* payment_dict;
   std::string payment_url, post_method, post_data;
   if (properties.GetDictionaryWithoutPathExpansion(
           shill::kPaymentPortalProperty, &payment_dict)) {
@@ -104,8 +106,7 @@ void GetDeviceInfo(const DictionaryValue& properties, DictionaryValue* value) {
         shill::kPaymentPortalPostData, &post_data);
   }
 
-  value->SetBoolean("activate_over_non_cellular_network",
-                    activate_over_non_cellular_networks);
+  value->SetString("activation_type", activation_type);
   value->SetString("carrier", name);
   value->SetString("payment_url", payment_url);
   if (LowerCaseEqualsASCII(post_method, "post") && !post_data.empty())
@@ -129,6 +130,14 @@ void GetDeviceInfo(const DictionaryValue& properties, DictionaryValue* value) {
   value->SetString("MDN", device->mdn());
 }
 
+void SetActivationStateAndError(MobileActivator::PlanActivationState state,
+                                const std::string& error_description,
+                                base::DictionaryValue* value) {
+  value->SetInteger("state", state);
+  if (!error_description.empty())
+    value->SetString("error", error_description);
+}
+
 }  // namespace
 
 class MobileSetupUIHTMLSource : public content::URLDataSource {
@@ -140,7 +149,7 @@ class MobileSetupUIHTMLSource : public content::URLDataSource {
   virtual void StartDataRequest(
       const std::string& path,
       int render_process_id,
-      int render_view_id,
+      int render_frame_id,
       const content::URLDataSource::GotDataCallback& callback) OVERRIDE;
   virtual std::string GetMimeType(const std::string&) const OVERRIDE {
     return "text/html";
@@ -215,10 +224,10 @@ class MobileSetupHandler
       scoped_ptr<base::DictionaryValue> error_data);
 
   // Handlers for JS WebUI messages.
-  void HandleSetTransactionStatus(const ListValue* args);
-  void HandleStartActivation(const ListValue* args);
-  void HandlePaymentPortalLoad(const ListValue* args);
-  void HandleGetDeviceInfo(const ListValue* args);
+  void HandleSetTransactionStatus(const base::ListValue* args);
+  void HandleStartActivation(const base::ListValue* args);
+  void HandlePaymentPortalLoad(const base::ListValue* args);
+  void HandleGetDeviceInfo(const base::ListValue* args);
 
   // NetworkStateHandlerObserver implementation.
   virtual void NetworkConnectionStateChanged(
@@ -263,7 +272,7 @@ std::string MobileSetupUIHTMLSource::GetSource() const {
 void MobileSetupUIHTMLSource::StartDataRequest(
     const std::string& path,
     int render_process_id,
-    int render_view_id,
+    int render_frame_id,
     const content::URLDataSource::GotDataCallback& callback) {
   NetworkHandler::Get()->network_configuration_handler()->GetProperties(
       path,
@@ -279,7 +288,7 @@ void MobileSetupUIHTMLSource::GetPropertiesAndStartDataRequest(
     const content::URLDataSource::GotDataCallback& callback,
     const std::string& service_path,
     const base::DictionaryValue& properties) {
-  const DictionaryValue* payment_dict;
+  const base::DictionaryValue* payment_dict;
   std::string name, usage_url, activation_state, payment_url;
   if (!properties.GetStringWithoutPathExpansion(
           shill::kNameProperty, &name) ||
@@ -302,11 +311,11 @@ void MobileSetupUIHTMLSource::GetPropertiesAndStartDataRequest(
   }
 
   NET_LOG_EVENT("Starting mobile setup", service_path);
-  DictionaryValue strings;
+  base::DictionaryValue strings;
 
   strings.SetString("connecting_header",
                     l10n_util::GetStringFUTF16(IDS_MOBILE_CONNECTING_HEADER,
-                                               UTF8ToUTF16(name)));
+                                               base::UTF8ToUTF16(name)));
   strings.SetString("error_header",
                     l10n_util::GetStringUTF16(IDS_MOBILE_ERROR_HEADER));
   strings.SetString("activating_header",
@@ -385,6 +394,15 @@ void MobileSetupHandler::OnActivationStateChanged(
   DCHECK_EQ(TYPE_ACTIVATION, type_);
   if (!web_ui())
     return;
+
+  if (!network) {
+    base::DictionaryValue device_dict;
+    SetActivationStateAndError(state, error_description, &device_dict);
+    web_ui()->CallJavascriptFunction(kJsDeviceStatusChangedCallback,
+                                     device_dict);
+    return;
+  }
+
   NetworkHandler::Get()->network_configuration_handler()->GetProperties(
       network->path(),
       base::Bind(&MobileSetupHandler::GetPropertiesAndCallStatusChanged,
@@ -402,13 +420,10 @@ void MobileSetupHandler::GetPropertiesAndCallStatusChanged(
     const std::string& error_description,
     const std::string& service_path,
     const base::DictionaryValue& properties) {
-  DictionaryValue device_dict;
+  base::DictionaryValue device_dict;
   GetDeviceInfo(properties, &device_dict);
-  device_dict.SetInteger("state", state);
-  if (error_description.length())
-    device_dict.SetString("error", error_description);
-  web_ui()->CallJavascriptFunction(
-      kJsDeviceStatusChangedCallback, device_dict);
+  SetActivationStateAndError(state, error_description, &device_dict);
+  web_ui()->CallJavascriptFunction(kJsDeviceStatusChangedCallback, device_dict);
 }
 
 void MobileSetupHandler::RegisterMessages() {
@@ -426,7 +441,7 @@ void MobileSetupHandler::RegisterMessages() {
                  base::Unretained(this)));
 }
 
-void MobileSetupHandler::HandleStartActivation(const ListValue* args) {
+void MobileSetupHandler::HandleStartActivation(const base::ListValue* args) {
   DCHECK_EQ(TYPE_UNDETERMINED, type_);
 
   if (!web_ui())
@@ -443,7 +458,8 @@ void MobileSetupHandler::HandleStartActivation(const ListValue* args) {
   MobileActivator::GetInstance()->InitiateActivation(path.substr(1));
 }
 
-void MobileSetupHandler::HandleSetTransactionStatus(const ListValue* args) {
+void MobileSetupHandler::HandleSetTransactionStatus(
+    const base::ListValue* args) {
   DCHECK_EQ(TYPE_ACTIVATION, type_);
   if (!web_ui())
     return;
@@ -460,7 +476,7 @@ void MobileSetupHandler::HandleSetTransactionStatus(const ListValue* args) {
       LowerCaseEqualsASCII(status, kJsApiResultOK));
 }
 
-void MobileSetupHandler::HandlePaymentPortalLoad(const ListValue* args) {
+void MobileSetupHandler::HandlePaymentPortalLoad(const base::ListValue* args) {
   // Only activation flow webui is interested in these events.
   if (type_ != TYPE_ACTIVATION || !web_ui())
     return;
@@ -477,7 +493,7 @@ void MobileSetupHandler::HandlePaymentPortalLoad(const ListValue* args) {
       LowerCaseEqualsASCII(result, kJsApiResultOK));
 }
 
-void MobileSetupHandler::HandleGetDeviceInfo(const ListValue* args) {
+void MobileSetupHandler::HandleGetDeviceInfo(const base::ListValue* args) {
   DCHECK_NE(TYPE_ACTIVATION, type_);
   if (!web_ui())
     return;
@@ -530,7 +546,7 @@ void MobileSetupHandler::HandleGetDeviceInfo(const ListValue* args) {
 void MobileSetupHandler::GetPropertiesAndCallGetDeviceInfo(
     const std::string& service_path,
     const base::DictionaryValue& properties) {
-  DictionaryValue device_info;
+  base::DictionaryValue device_info;
   GetDeviceInfo(properties, &device_info);
   web_ui()->CallJavascriptFunction(kJsGetDeviceInfoCallback, device_info);
 }
@@ -543,7 +559,7 @@ void MobileSetupHandler::GetPropertiesFailure(
   NET_LOG_ERROR("MobileActivator GetProperties Failed: " + error_name,
                 service_path);
   // Invoke |callback_name| with an empty dictionary.
-  DictionaryValue device_dict;
+  base::DictionaryValue device_dict;
   web_ui()->CallJavascriptFunction(callback_name, device_dict);
 }
 
@@ -620,13 +636,10 @@ MobileSetupUI::MobileSetupUI(content::WebUI* web_ui)
 }
 
 void MobileSetupUI::DidCommitProvisionalLoadForFrame(
-    int64 frame_id,
-    const string16& frame_unique_name,
-    bool is_main_frame,
+    content::RenderFrameHost* render_frame_host,
     const GURL& url,
-    content::PageTransition transition_type,
-    content::RenderViewHost* render_view_host) {
-  if (frame_unique_name != UTF8ToUTF16("paymentForm"))
+    content::PageTransition transition_type) {
+  if (render_frame_host->GetFrameName() != "paymentForm")
     return;
 
   web_ui()->CallJavascriptFunction(
@@ -634,14 +647,11 @@ void MobileSetupUI::DidCommitProvisionalLoadForFrame(
 }
 
 void MobileSetupUI::DidFailProvisionalLoad(
-    int64 frame_id,
-    const string16& frame_unique_name,
-    bool is_main_frame,
+    content::RenderFrameHost* render_frame_host,
     const GURL& validated_url,
     int error_code,
-    const string16& error_description,
-    content::RenderViewHost* render_view_host) {
-  if (frame_unique_name != UTF8ToUTF16("paymentForm"))
+    const base::string16& error_description) {
+  if (render_frame_host->GetFrameName() != "paymentForm")
     return;
 
   base::FundamentalValue result_value(-error_code);