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 "base/string_number_conversions.h" | 8 #include "base/string_number_conversions.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 if (registrar_.IsEmpty()) { | 131 if (registrar_.IsEmpty()) { |
132 registrar_.Add(this, NotificationType::EXTENSION_LOADED, | 132 registrar_.Add(this, NotificationType::EXTENSION_LOADED, |
133 NotificationService::AllSources()); | 133 NotificationService::AllSources()); |
134 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED, | 134 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED, |
135 NotificationService::AllSources()); | 135 NotificationService::AllSources()); |
136 } | 136 } |
137 } | 137 } |
138 | 138 |
139 void AppLauncherHandler::HandleLaunchApp(const ListValue* args) { | 139 void AppLauncherHandler::HandleLaunchApp(const ListValue* args) { |
140 std::string extension_id; | 140 std::string extension_id; |
141 std::string launch_container; | |
142 int left = 0; | 141 int left = 0; |
143 int top = 0; | 142 int top = 0; |
144 int width = 0; | 143 int width = 0; |
145 int height = 0; | 144 int height = 0; |
146 | 145 |
147 if (!args->GetString(0, &extension_id) || | 146 if (!args->GetString(0, &extension_id) || |
148 !args->GetString(1, &launch_container) || | 147 !ExtractInt(args, 1, &left) || |
149 !ExtractInt(args, 2, &left) || | 148 !ExtractInt(args, 2, &top) || |
150 !ExtractInt(args, 3, &top) || | 149 !ExtractInt(args, 3, &width) || |
151 !ExtractInt(args, 4, &width) || | 150 !ExtractInt(args, 4, &height)) { |
152 !ExtractInt(args, 5, &height)) { | |
153 NOTREACHED(); | 151 NOTREACHED(); |
154 return; | 152 return; |
155 } | 153 } |
156 | 154 |
157 // The rect we get from the client is relative to the browser client viewport. | 155 // The rect we get from the client is relative to the browser client viewport. |
158 // Offset the rect by the tab contents bounds. | 156 // Offset the rect by the tab contents bounds. |
159 gfx::Rect rect(left, top, width, height); | 157 gfx::Rect rect(left, top, width, height); |
160 gfx::Rect tab_contents_bounds; | 158 gfx::Rect tab_contents_bounds; |
161 dom_ui_->tab_contents()->GetContainerBounds(&tab_contents_bounds); | 159 dom_ui_->tab_contents()->GetContainerBounds(&tab_contents_bounds); |
162 rect.Offset(tab_contents_bounds.origin()); | 160 rect.Offset(tab_contents_bounds.origin()); |
163 | 161 |
164 // Override the default launch container. | |
165 Extension* extension = | 162 Extension* extension = |
166 extensions_service_->GetExtensionById(extension_id, false); | 163 extensions_service_->GetExtensionById(extension_id, false); |
167 DCHECK(extension); | 164 DCHECK(extension); |
168 | |
169 Profile* profile = extensions_service_->profile(); | 165 Profile* profile = extensions_service_->profile(); |
170 | |
171 Extension::LaunchContainer container = extension->launch_container(); | 166 Extension::LaunchContainer container = extension->launch_container(); |
172 if (launch_container == "tab") | |
173 container = Extension::LAUNCH_TAB; | |
174 else if (launch_container == "panel") | |
175 container = Extension::LAUNCH_PANEL; | |
176 else if (launch_container == "window") | |
177 container = Extension::LAUNCH_WINDOW; | |
178 else if (!launch_container.empty()) | |
179 NOTREACHED() << "Unexpected launch container: " << launch_container << "."; | |
180 | 167 |
181 // To give a more "launchy" experience when using the NTP launcher, we close | 168 // To give a more "launchy" experience when using the NTP launcher, we close |
182 // it automatically. | 169 // it automatically. |
183 Browser* browser = BrowserList::GetLastActive(); | 170 Browser* browser = BrowserList::GetLastActive(); |
184 TabContents* old_contents = NULL; | 171 TabContents* old_contents = NULL; |
185 if (browser) | 172 if (browser) |
186 old_contents = browser->GetSelectedTabContents(); | 173 old_contents = browser->GetSelectedTabContents(); |
187 | 174 |
188 AnimateAppIcon(extension, rect); | 175 AnimateAppIcon(extension, rect); |
189 Browser::OpenApplication(profile, extension, container); | 176 Browser::OpenApplication(profile, extension, container); |
(...skipping 21 matching lines...) Expand all Loading... |
211 void AppLauncherHandler::HandleUninstallApp(const ListValue* args) { | 198 void AppLauncherHandler::HandleUninstallApp(const ListValue* args) { |
212 std::string extension_id = WideToUTF8(ExtractStringValue(args)); | 199 std::string extension_id = WideToUTF8(ExtractStringValue(args)); |
213 | 200 |
214 // Make sure that the extension exists. | 201 // Make sure that the extension exists. |
215 Extension* extension = | 202 Extension* extension = |
216 extensions_service_->GetExtensionById(extension_id, false); | 203 extensions_service_->GetExtensionById(extension_id, false); |
217 DCHECK(extension); | 204 DCHECK(extension); |
218 | 205 |
219 extensions_service_->UninstallExtension(extension_id, false); | 206 extensions_service_->UninstallExtension(extension_id, false); |
220 } | 207 } |
OLD | NEW |