| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/webui/extensions/chromeos/kiosk_apps_handler.h" | 5 #include "chrome/browser/ui/webui/extensions/chromeos/kiosk_apps_handler.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
| 16 #include "base/sys_info.h" | 16 #include "base/sys_info.h" |
| 17 #include "base/values.h" | 17 #include "base/values.h" |
| 18 #include "chrome/browser/chromeos/settings/cros_settings.h" | 18 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 19 #include "chrome/common/extensions/extension_constants.h" | 19 #include "chrome/common/extensions/extension_constants.h" |
| 20 #include "chromeos/chromeos_switches.h" | 20 #include "chromeos/chromeos_switches.h" |
| 21 #include "chromeos/settings/cros_settings_names.h" | 21 #include "chromeos/settings/cros_settings_names.h" |
| 22 #include "components/crx_file/id_util.h" |
| 22 #include "components/user_manager/user_manager.h" | 23 #include "components/user_manager/user_manager.h" |
| 23 #include "content/public/browser/web_ui.h" | 24 #include "content/public/browser/web_ui.h" |
| 24 #include "content/public/browser/web_ui_data_source.h" | 25 #include "content/public/browser/web_ui_data_source.h" |
| 25 #include "extensions/common/extension.h" | |
| 26 #include "grit/chromium_strings.h" | 26 #include "grit/chromium_strings.h" |
| 27 #include "grit/generated_resources.h" | 27 #include "grit/generated_resources.h" |
| 28 #include "ui/base/l10n/l10n_util.h" | 28 #include "ui/base/l10n/l10n_util.h" |
| 29 #include "ui/base/webui/web_ui_util.h" | 29 #include "ui/base/webui/web_ui_util.h" |
| 30 #include "url/gurl.h" | 30 #include "url/gurl.h" |
| 31 | 31 |
| 32 namespace chromeos { | 32 namespace chromeos { |
| 33 | 33 |
| 34 namespace { | 34 namespace { |
| 35 | 35 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 50 KioskAppManager::Get()->GetAutoLaunchApp() == app_data.app_id && | 50 KioskAppManager::Get()->GetAutoLaunchApp() == app_data.app_id && |
| 51 (KioskAppManager::Get()->IsAutoLaunchEnabled() || | 51 (KioskAppManager::Get()->IsAutoLaunchEnabled() || |
| 52 KioskAppManager::Get()->IsAutoLaunchRequested())); | 52 KioskAppManager::Get()->IsAutoLaunchRequested())); |
| 53 app_dict->SetBoolean("isLoading", app_data.is_loading); | 53 app_dict->SetBoolean("isLoading", app_data.is_loading); |
| 54 } | 54 } |
| 55 | 55 |
| 56 // Sanitize app id input value and extracts app id out of it. | 56 // Sanitize app id input value and extracts app id out of it. |
| 57 // Returns false if an app id could not be derived out of the input. | 57 // Returns false if an app id could not be derived out of the input. |
| 58 bool ExtractsAppIdFromInput(const std::string& input, | 58 bool ExtractsAppIdFromInput(const std::string& input, |
| 59 std::string* app_id) { | 59 std::string* app_id) { |
| 60 if (extensions::Extension::IdIsValid(input)) { | 60 if (crx_file::id_util::IdIsValid(input)) { |
| 61 *app_id = input; | 61 *app_id = input; |
| 62 return true; | 62 return true; |
| 63 } | 63 } |
| 64 | 64 |
| 65 GURL webstore_url = GURL(input); | 65 GURL webstore_url = GURL(input); |
| 66 if (!webstore_url.is_valid()) | 66 if (!webstore_url.is_valid()) |
| 67 return false; | 67 return false; |
| 68 | 68 |
| 69 GURL webstore_base_url = | 69 GURL webstore_base_url = |
| 70 GURL(extension_urls::GetWebstoreItemDetailURLPrefix()); | 70 GURL(extension_urls::GetWebstoreItemDetailURLPrefix()); |
| 71 | 71 |
| 72 if (webstore_url.scheme() != webstore_base_url.scheme() || | 72 if (webstore_url.scheme() != webstore_base_url.scheme() || |
| 73 webstore_url.host() != webstore_base_url.host() || | 73 webstore_url.host() != webstore_base_url.host() || |
| 74 !StartsWithASCII( | 74 !StartsWithASCII( |
| 75 webstore_url.path(), webstore_base_url.path(), true)) { | 75 webstore_url.path(), webstore_base_url.path(), true)) { |
| 76 return false; | 76 return false; |
| 77 } | 77 } |
| 78 | 78 |
| 79 const std::string path = webstore_url.path(); | 79 const std::string path = webstore_url.path(); |
| 80 const size_t last_slash = path.rfind('/'); | 80 const size_t last_slash = path.rfind('/'); |
| 81 if (last_slash == std::string::npos) | 81 if (last_slash == std::string::npos) |
| 82 return false; | 82 return false; |
| 83 | 83 |
| 84 const std::string candidate_id = path.substr(last_slash + 1); | 84 const std::string candidate_id = path.substr(last_slash + 1); |
| 85 if (!extensions::Extension::IdIsValid(candidate_id)) | 85 if (!crx_file::id_util::IdIsValid(candidate_id)) |
| 86 return false; | 86 return false; |
| 87 | 87 |
| 88 *app_id = candidate_id; | 88 *app_id = candidate_id; |
| 89 return true; | 89 return true; |
| 90 } | 90 } |
| 91 | 91 |
| 92 } // namespace | 92 } // namespace |
| 93 | 93 |
| 94 KioskAppsHandler::KioskAppsHandler() | 94 KioskAppsHandler::KioskAppsHandler() |
| 95 : kiosk_app_manager_(KioskAppManager::Get()), | 95 : kiosk_app_manager_(KioskAppManager::Get()), |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 344 | 344 |
| 345 void KioskAppsHandler::ShowError(const std::string& app_id) { | 345 void KioskAppsHandler::ShowError(const std::string& app_id) { |
| 346 base::StringValue app_id_value(app_id); | 346 base::StringValue app_id_value(app_id); |
| 347 web_ui()->CallJavascriptFunction("extensions.KioskAppsOverlay.showError", | 347 web_ui()->CallJavascriptFunction("extensions.KioskAppsOverlay.showError", |
| 348 app_id_value); | 348 app_id_value); |
| 349 | 349 |
| 350 kiosk_app_manager_->RemoveApp(app_id); | 350 kiosk_app_manager_->RemoveApp(app_id); |
| 351 } | 351 } |
| 352 | 352 |
| 353 } // namespace chromeos | 353 } // namespace chromeos |
| OLD | NEW |