Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(793)

Side by Side Diff: chrome/browser/dom_ui/app_launcher_handler.cc

Issue 5273004: Add "create Application Shortcut" to the app menu on NTP. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add support for GTK. Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/metrics/histogram.h" 8 #include "base/metrics/histogram.h"
9 #include "base/string_number_conversions.h" 9 #include "base/string_number_conversions.h"
10 #include "base/string_split.h" 10 #include "base/string_split.h"
11 #include "base/string_util.h" 11 #include "base/string_util.h"
12 #include "base/utf_string_conversions.h" 12 #include "base/utf_string_conversions.h"
13 #include "base/values.h" 13 #include "base/values.h"
14 #include "chrome/browser/app_launched_animation.h" 14 #include "chrome/browser/app_launched_animation.h"
15 #include "chrome/browser/extensions/default_apps.h" 15 #include "chrome/browser/extensions/default_apps.h"
16 #include "chrome/browser/extensions/extension_prefs.h" 16 #include "chrome/browser/extensions/extension_prefs.h"
17 #include "chrome/browser/extensions/extensions_service.h" 17 #include "chrome/browser/extensions/extensions_service.h"
18 #include "chrome/browser/platform_util.h" 18 #include "chrome/browser/platform_util.h"
19 #include "chrome/browser/profile.h" 19 #include "chrome/browser/profile.h"
20 #include "chrome/browser/tab_contents/tab_contents.h" 20 #include "chrome/browser/tab_contents/tab_contents.h"
21 #include "chrome/browser/ui/browser.h" 21 #include "chrome/browser/ui/browser.h"
22 #include "chrome/browser/ui/browser_list.h" 22 #include "chrome/browser/ui/browser_list.h"
23 #include "chrome/browser/ui/browser_window.h"
23 #include "chrome/common/chrome_switches.h" 24 #include "chrome/common/chrome_switches.h"
24 #include "chrome/common/extensions/extension.h" 25 #include "chrome/common/extensions/extension.h"
25 #include "chrome/common/extensions/extension_constants.h" 26 #include "chrome/common/extensions/extension_constants.h"
26 #include "chrome/common/extensions/extension_icon_set.h" 27 #include "chrome/common/extensions/extension_icon_set.h"
27 #include "chrome/common/extensions/extension_resource.h" 28 #include "chrome/common/extensions/extension_resource.h"
28 #include "chrome/common/notification_service.h" 29 #include "chrome/common/notification_service.h"
29 #include "chrome/common/notification_type.h" 30 #include "chrome/common/notification_type.h"
30 #include "chrome/common/url_constants.h" 31 #include "chrome/common/url_constants.h"
31 #include "gfx/rect.h" 32 #include "gfx/rect.h"
32 #include "grit/browser_resources.h" 33 #include "grit/browser_resources.h"
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 value->SetString("launch_url", extension->GetFullLaunchURL().spec()); 91 value->SetString("launch_url", extension->GetFullLaunchURL().spec());
91 value->SetString("options_url", extension->options_url().spec()); 92 value->SetString("options_url", extension->options_url().spec());
92 value->SetString("icon_big", GetIconURL( 93 value->SetString("icon_big", GetIconURL(
93 extension, Extension::EXTENSION_ICON_LARGE, 94 extension, Extension::EXTENSION_ICON_LARGE,
94 "chrome://theme/IDR_APP_DEFAULT_ICON")); 95 "chrome://theme/IDR_APP_DEFAULT_ICON"));
95 value->SetString("icon_small", GetIconURL( 96 value->SetString("icon_small", GetIconURL(
96 extension, Extension::EXTENSION_ICON_BITTY, 97 extension, Extension::EXTENSION_ICON_BITTY,
97 std::string("chrome://favicon/") + extension->GetFullLaunchURL().spec())); 98 std::string("chrome://favicon/") + extension->GetFullLaunchURL().spec()));
98 value->SetInteger("launch_container", extension->launch_container()); 99 value->SetInteger("launch_container", extension->launch_container());
99 value->SetInteger("launch_type", 100 value->SetInteger("launch_type",
100 extension_prefs->GetLaunchType(extension->id())); 101 extension_prefs->GetLaunchType(extension->id(),
102 ExtensionPrefs::LAUNCH_REGULAR));
101 103
102 int app_launch_index = extension_prefs->GetAppLaunchIndex(extension->id()); 104 int app_launch_index = extension_prefs->GetAppLaunchIndex(extension->id());
103 if (app_launch_index == -1) { 105 if (app_launch_index == -1) {
104 // Make sure every app has a launch index (some predate the launch index). 106 // Make sure every app has a launch index (some predate the launch index).
105 app_launch_index = extension_prefs->GetNextAppLaunchIndex(); 107 app_launch_index = extension_prefs->GetNextAppLaunchIndex();
106 extension_prefs->SetAppLaunchIndex(extension->id(), app_launch_index); 108 extension_prefs->SetAppLaunchIndex(extension->id(), app_launch_index);
107 } 109 }
108 value->SetInteger("app_launch_index", app_launch_index); 110 value->SetInteger("app_launch_index", app_launch_index);
109 } 111 }
110 112
(...skipping 19 matching lines...) Expand all
130 dom_ui_->RegisterMessageCallback("getApps", 132 dom_ui_->RegisterMessageCallback("getApps",
131 NewCallback(this, &AppLauncherHandler::HandleGetApps)); 133 NewCallback(this, &AppLauncherHandler::HandleGetApps));
132 dom_ui_->RegisterMessageCallback("launchApp", 134 dom_ui_->RegisterMessageCallback("launchApp",
133 NewCallback(this, &AppLauncherHandler::HandleLaunchApp)); 135 NewCallback(this, &AppLauncherHandler::HandleLaunchApp));
134 dom_ui_->RegisterMessageCallback("setLaunchType", 136 dom_ui_->RegisterMessageCallback("setLaunchType",
135 NewCallback(this, &AppLauncherHandler::HandleSetLaunchType)); 137 NewCallback(this, &AppLauncherHandler::HandleSetLaunchType));
136 dom_ui_->RegisterMessageCallback("uninstallApp", 138 dom_ui_->RegisterMessageCallback("uninstallApp",
137 NewCallback(this, &AppLauncherHandler::HandleUninstallApp)); 139 NewCallback(this, &AppLauncherHandler::HandleUninstallApp));
138 dom_ui_->RegisterMessageCallback("hideAppsPromo", 140 dom_ui_->RegisterMessageCallback("hideAppsPromo",
139 NewCallback(this, &AppLauncherHandler::HandleHideAppsPromo)); 141 NewCallback(this, &AppLauncherHandler::HandleHideAppsPromo));
142 dom_ui_->RegisterMessageCallback("createAppShortcut",
143 NewCallback(this, &AppLauncherHandler::HandleCreateAppShortcut));
140 } 144 }
141 145
142 void AppLauncherHandler::Observe(NotificationType type, 146 void AppLauncherHandler::Observe(NotificationType type,
143 const NotificationSource& source, 147 const NotificationSource& source,
144 const NotificationDetails& details) { 148 const NotificationDetails& details) {
145 switch (type.value) { 149 switch (type.value) {
146 case NotificationType::EXTENSION_LOADED: 150 case NotificationType::EXTENSION_LOADED:
147 case NotificationType::EXTENSION_UNLOADED: 151 case NotificationType::EXTENSION_UNLOADED:
148 if (dom_ui_->tab_contents()) 152 if (dom_ui_->tab_contents())
149 HandleGetApps(NULL); 153 HandleGetApps(NULL);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 dictionary->SetBoolean("showPromo", false); 190 dictionary->SetBoolean("showPromo", false);
187 promo_active_ = false; 191 promo_active_ = false;
188 } 192 }
189 193
190 bool showLauncher = 194 bool showLauncher =
191 CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableAppLauncher); 195 CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableAppLauncher);
192 dictionary->SetBoolean("showLauncher", showLauncher); 196 dictionary->SetBoolean("showLauncher", showLauncher);
193 197
194 #if defined(OS_MACOSX) 198 #if defined(OS_MACOSX)
195 // App windows are not yet implemented on mac. 199 // App windows are not yet implemented on mac.
196 bool disable_app_window_launch = true; 200 dictionary->SetBoolean("disableAppWindowLaunch", true);
197 #else 201 dictionary->SetBoolean("disableCreateAppShortcut", true);
198 bool disable_app_window_launch = false;
199 #endif 202 #endif
200 dictionary->SetBoolean("disableAppWindowLaunch", disable_app_window_launch);
201 } 203 }
202 204
203 void AppLauncherHandler::HandleGetApps(const ListValue* args) { 205 void AppLauncherHandler::HandleGetApps(const ListValue* args) {
204 DictionaryValue dictionary; 206 DictionaryValue dictionary;
205 FillAppDictionary(&dictionary); 207 FillAppDictionary(&dictionary);
206 dom_ui_->CallJavascriptFunction(L"getAppsCallback", dictionary); 208 dom_ui_->CallJavascriptFunction(L"getAppsCallback", dictionary);
207 209
208 // First time we get here we set up the observer so that we can tell update 210 // First time we get here we set up the observer so that we can tell update
209 // the apps as they change. 211 // the apps as they change.
210 if (registrar_.IsEmpty()) { 212 if (registrar_.IsEmpty()) {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 252
251 // To give a more "launchy" experience when using the NTP launcher, we close 253 // To give a more "launchy" experience when using the NTP launcher, we close
252 // it automatically. 254 // it automatically.
253 Browser* browser = BrowserList::GetLastActive(); 255 Browser* browser = BrowserList::GetLastActive();
254 TabContents* old_contents = NULL; 256 TabContents* old_contents = NULL;
255 if (browser) 257 if (browser)
256 old_contents = browser->GetSelectedTabContents(); 258 old_contents = browser->GetSelectedTabContents();
257 259
258 AnimateAppIcon(extension, rect); 260 AnimateAppIcon(extension, rect);
259 261
262 // Look at preference to find the right launch container. If no preference
263 // is set, launch as a regular tab.
260 extension_misc::LaunchContainer launch_container = 264 extension_misc::LaunchContainer launch_container =
261 extension->launch_container(); 265 extensions_service_->extension_prefs()->GetLaunchContainer(
262 ExtensionPrefs::LaunchType prefs_launch_type = 266 extension, ExtensionPrefs::LAUNCH_REGULAR);
263 extensions_service_->extension_prefs()->GetLaunchType(extension_id);
264
265 // If the user chose to open in a window, change the container type.
266 if (prefs_launch_type == ExtensionPrefs::LAUNCH_WINDOW)
267 launch_container = extension_misc::LAUNCH_WINDOW;
268 267
269 TabContents* new_contents = Browser::OpenApplication( 268 TabContents* new_contents = Browser::OpenApplication(
270 profile, extension, launch_container, old_contents); 269 profile, extension, launch_container, old_contents);
271 270
272 if (new_contents != old_contents && browser->tab_count() > 1) 271 if (new_contents != old_contents && browser->tab_count() > 1)
273 browser->CloseTabContents(old_contents); 272 browser->CloseTabContents(old_contents);
274 273
275 if (extension_id != extension_misc::kWebStoreAppId) 274 if (extension_id != extension_misc::kWebStoreAppId)
276 RecordAppLaunch(promo_active_); 275 RecordAppLaunch(promo_active_);
277 } 276 }
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 320
322 for (ExtensionIdSet::const_iterator iter = app_ids->begin(); 321 for (ExtensionIdSet::const_iterator iter = app_ids->begin();
323 iter != app_ids->end(); ++iter) { 322 iter != app_ids->end(); ++iter) {
324 if (extensions_service_->GetExtensionById(*iter, true)) 323 if (extensions_service_->GetExtensionById(*iter, true))
325 extensions_service_->UninstallExtension(*iter, false); 324 extensions_service_->UninstallExtension(*iter, false);
326 } 325 }
327 326
328 extensions_service_->default_apps()->SetPromoHidden(); 327 extensions_service_->default_apps()->SetPromoHidden();
329 } 328 }
330 329
330 void AppLauncherHandler::HandleCreateAppShortcut(const ListValue* args) {
331 std::string extension_id;
332 if (!args->GetString(0, &extension_id)) {
333 NOTREACHED();
334 return;
335 }
336
337 const Extension* extension =
338 extensions_service_->GetExtensionById(extension_id, false);
339 DCHECK(extension);
Aaron Boodman 2010/11/30 00:29:28 My new motto: DCHECK is for wusses. In this case,
Sam Kerner (Chrome) 2010/11/30 01:21:04 Done.
340
341 Browser* browser = BrowserList::GetLastActive();
342 if (!browser)
343 return;
344 browser->window()->ShowCreateChromeAppShortcutsDialog(
345 browser->profile(), extension);
346 }
347
331 // static 348 // static
332 void AppLauncherHandler::RecordWebStoreLaunch(bool promo_active) { 349 void AppLauncherHandler::RecordWebStoreLaunch(bool promo_active) {
333 if (!promo_active) return; 350 if (!promo_active) return;
334 351
335 UMA_HISTOGRAM_ENUMERATION(extension_misc::kAppsPromoHistogram, 352 UMA_HISTOGRAM_ENUMERATION(extension_misc::kAppsPromoHistogram,
336 extension_misc::PROMO_LAUNCH_WEB_STORE, 353 extension_misc::PROMO_LAUNCH_WEB_STORE,
337 extension_misc::PROMO_BUCKET_BOUNDARY); 354 extension_misc::PROMO_BUCKET_BOUNDARY);
338 } 355 }
339 356
340 // static 357 // static
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 // We make this check for the case of minimized windows, unit tests, etc. 396 // We make this check for the case of minimized windows, unit tests, etc.
380 if (platform_util::IsVisible(dom_ui_->tab_contents()->GetNativeView()) && 397 if (platform_util::IsVisible(dom_ui_->tab_contents()->GetNativeView()) &&
381 Animation::ShouldRenderRichAnimation()) { 398 Animation::ShouldRenderRichAnimation()) {
382 #if defined(OS_WIN) 399 #if defined(OS_WIN)
383 AppLaunchedAnimation::Show(extension, rect); 400 AppLaunchedAnimation::Show(extension, rect);
384 #else 401 #else
385 NOTIMPLEMENTED(); 402 NOTIMPLEMENTED();
386 #endif 403 #endif
387 } 404 }
388 } 405 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698