| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/dom_ui/app_launcher_handler.h" | 5 #include "chrome/browser/dom_ui/app_launcher_handler.h" |
| 6 | 6 |
| 7 #include "app/animation.h" | 7 #include "app/animation.h" |
| 8 #include "app/resource_bundle.h" | 8 #include "app/resource_bundle.h" |
| 9 #include "base/base64.h" | 9 #include "base/base64.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 DOMMessageHandler* AppLauncherHandler::Attach(DOMUI* dom_ui) { | 48 DOMMessageHandler* AppLauncherHandler::Attach(DOMUI* dom_ui) { |
| 49 // TODO(arv): Add initialization code to the Apps store etc. | 49 // TODO(arv): Add initialization code to the Apps store etc. |
| 50 return DOMMessageHandler::Attach(dom_ui); | 50 return DOMMessageHandler::Attach(dom_ui); |
| 51 } | 51 } |
| 52 | 52 |
| 53 void AppLauncherHandler::RegisterMessages() { | 53 void AppLauncherHandler::RegisterMessages() { |
| 54 dom_ui_->RegisterMessageCallback("getApps", | 54 dom_ui_->RegisterMessageCallback("getApps", |
| 55 NewCallback(this, &AppLauncherHandler::HandleGetApps)); | 55 NewCallback(this, &AppLauncherHandler::HandleGetApps)); |
| 56 dom_ui_->RegisterMessageCallback("launchApp", | 56 dom_ui_->RegisterMessageCallback("launchApp", |
| 57 NewCallback(this, &AppLauncherHandler::HandleLaunchApp)); | 57 NewCallback(this, &AppLauncherHandler::HandleLaunchApp)); |
| 58 dom_ui_->RegisterMessageCallback("uninstallApp", |
| 59 NewCallback(this, &AppLauncherHandler::HandleUninstallApp)); |
| 58 } | 60 } |
| 59 | 61 |
| 60 void AppLauncherHandler::Observe(NotificationType type, | 62 void AppLauncherHandler::Observe(NotificationType type, |
| 61 const NotificationSource& source, | 63 const NotificationSource& source, |
| 62 const NotificationDetails& details) { | 64 const NotificationDetails& details) { |
| 63 switch (type.value) { | 65 switch (type.value) { |
| 64 case NotificationType::EXTENSION_LOADED: | 66 case NotificationType::EXTENSION_LOADED: |
| 65 case NotificationType::EXTENSION_UNLOADED: | 67 case NotificationType::EXTENSION_UNLOADED: |
| 66 if (dom_ui_->tab_contents()) | 68 if (dom_ui_->tab_contents()) |
| 67 HandleGetApps(NULL); | 69 HandleGetApps(NULL); |
| 68 break; | 70 break; |
| 69 | 71 |
| 70 default: | 72 default: |
| 71 NOTREACHED(); | 73 NOTREACHED(); |
| 72 } | 74 } |
| 73 } | 75 } |
| 74 | 76 |
| 75 // static | 77 // static |
| 76 void AppLauncherHandler::CreateAppInfo(Extension* extension, | 78 void AppLauncherHandler::CreateAppInfo(Extension* extension, |
| 77 DictionaryValue* value) { | 79 DictionaryValue* value) { |
| 78 value->Clear(); | 80 value->Clear(); |
| 79 value->SetString(L"id", extension->id()); | 81 value->SetString(L"id", extension->id()); |
| 80 value->SetString(L"name", extension->name()); | 82 value->SetString(L"name", extension->name()); |
| 81 value->SetString(L"description", extension->description()); | 83 value->SetString(L"description", extension->description()); |
| 82 value->SetString(L"launch_url", extension->GetFullLaunchURL().spec()); | 84 value->SetString(L"launch_url", extension->GetFullLaunchURL().spec()); |
| 85 value->SetString(L"options_url", extension->options_url().spec()); |
| 83 | 86 |
| 84 FilePath relative_path = | 87 FilePath relative_path = |
| 85 extension->GetIconPath(Extension::EXTENSION_ICON_LARGE).relative_path(); | 88 extension->GetIconPath(Extension::EXTENSION_ICON_LARGE).relative_path(); |
| 86 | 89 |
| 87 #if defined(OS_POSIX) | 90 #if defined(OS_POSIX) |
| 88 std::string path = relative_path.value(); | 91 std::string path = relative_path.value(); |
| 89 #elif defined(OS_WIN) | 92 #elif defined(OS_WIN) |
| 90 std::string path = WideToUTF8(relative_path.value()); | 93 std::string path = WideToUTF8(relative_path.value()); |
| 91 #endif // OS_WIN | 94 #endif // OS_WIN |
| 92 | 95 |
| 93 GURL icon_url = extension->GetResourceURL(path); | 96 GURL icon_url = extension->GetResourceURL(path); |
| 94 value->SetString(L"icon", icon_url.spec()); | 97 value->SetString(L"icon", icon_url.spec()); |
| 95 } | 98 } |
| 96 | 99 |
| 97 void AppLauncherHandler::HandleGetApps(const Value* value) { | 100 void AppLauncherHandler::HandleGetApps(const Value* value) { |
| 98 std::string gallery_title; | |
| 99 std::string gallery_url; | |
| 100 | |
| 101 // TODO(aa): Decide the final values for these and remove the switches. | |
| 102 gallery_title = CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | |
| 103 switches::kAppsGalleryTitle); | |
| 104 gallery_url = CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | |
| 105 switches::kAppsGalleryURL); | |
| 106 bool show_debug_link = CommandLine::ForCurrentProcess()->HasSwitch( | 101 bool show_debug_link = CommandLine::ForCurrentProcess()->HasSwitch( |
| 107 switches::kAppsDebug); | 102 switches::kAppsDebug); |
| 108 | 103 |
| 109 DictionaryValue dictionary; | 104 DictionaryValue dictionary; |
| 110 dictionary.SetString(L"galleryTitle", gallery_title); | |
| 111 dictionary.SetString(L"galleryURL", gallery_url); | |
| 112 dictionary.SetBoolean(L"showDebugLink", show_debug_link); | 105 dictionary.SetBoolean(L"showDebugLink", show_debug_link); |
| 113 | 106 |
| 114 ListValue* list = new ListValue(); | 107 ListValue* list = new ListValue(); |
| 115 const ExtensionList* extensions = extensions_service_->extensions(); | 108 const ExtensionList* extensions = extensions_service_->extensions(); |
| 116 for (ExtensionList::const_iterator it = extensions->begin(); | 109 for (ExtensionList::const_iterator it = extensions->begin(); |
| 117 it != extensions->end(); ++it) { | 110 it != extensions->end(); ++it) { |
| 118 if ((*it)->IsApp()) { | 111 if ((*it)->IsApp()) { |
| 119 DictionaryValue* app_info = new DictionaryValue(); | 112 DictionaryValue* app_info = new DictionaryValue(); |
| 120 CreateAppInfo(*it, app_info); | 113 CreateAppInfo(*it, app_info); |
| 121 list->Append(app_info); | 114 list->Append(app_info); |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 // We make this check for the case of minimized windows, unit tests, etc. | 203 // We make this check for the case of minimized windows, unit tests, etc. |
| 211 if (platform_util::IsVisible(dom_ui_->tab_contents()->GetNativeView()) && | 204 if (platform_util::IsVisible(dom_ui_->tab_contents()->GetNativeView()) && |
| 212 Animation::ShouldRenderRichAnimation()) { | 205 Animation::ShouldRenderRichAnimation()) { |
| 213 #if defined(OS_WIN) | 206 #if defined(OS_WIN) |
| 214 AppLaunchedAnimation::Show(extension, rect); | 207 AppLaunchedAnimation::Show(extension, rect); |
| 215 #else | 208 #else |
| 216 NOTIMPLEMENTED(); | 209 NOTIMPLEMENTED(); |
| 217 #endif | 210 #endif |
| 218 } | 211 } |
| 219 } | 212 } |
| 213 |
| 214 void AppLauncherHandler::HandleUninstallApp(const Value* value) { |
| 215 if (!value->IsType(Value::TYPE_LIST)) { |
| 216 NOTREACHED(); |
| 217 return; |
| 218 } |
| 219 |
| 220 std::string extension_id; |
| 221 const ListValue* list = static_cast<const ListValue*>(value); |
| 222 if (!list->GetString(0, &extension_id)) { |
| 223 NOTREACHED(); |
| 224 return; |
| 225 } |
| 226 |
| 227 // Make sure that the extension exists. |
| 228 Extension* extension = |
| 229 extensions_service_->GetExtensionById(extension_id, false); |
| 230 DCHECK(extension); |
| 231 |
| 232 extensions_service_->UninstallExtension(extension_id, false); |
| 233 } |
| OLD | NEW |