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

Side by Side Diff: chrome/browser/ui/webui/ntp/app_launcher_handler.cc

Issue 11953021: Don't show the apps page on the NTP if the app launcher is installed. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: pref -> app_launcher Created 7 years, 11 months 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/ntp/app_launcher_handler.h" 5 #include "chrome/browser/ui/webui/ntp/app_launcher_handler.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/auto_reset.h" 9 #include "base/auto_reset.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/bind_helpers.h" 11 #include "base/bind_helpers.h"
12 #include "base/i18n/rtl.h" 12 #include "base/i18n/rtl.h"
13 #include "base/metrics/field_trial.h" 13 #include "base/metrics/field_trial.h"
14 #include "base/metrics/histogram.h" 14 #include "base/metrics/histogram.h"
15 #include "base/utf_string_conversions.h" 15 #include "base/utf_string_conversions.h"
16 #include "base/values.h" 16 #include "base/values.h"
17 #include "chrome/browser/extensions/app_launcher.h"
17 #include "chrome/browser/extensions/app_notification.h" 18 #include "chrome/browser/extensions/app_notification.h"
18 #include "chrome/browser/extensions/app_notification_manager.h" 19 #include "chrome/browser/extensions/app_notification_manager.h"
19 #include "chrome/browser/extensions/crx_installer.h" 20 #include "chrome/browser/extensions/crx_installer.h"
20 #include "chrome/browser/extensions/extension_prefs.h" 21 #include "chrome/browser/extensions/extension_prefs.h"
21 #include "chrome/browser/extensions/extension_service.h" 22 #include "chrome/browser/extensions/extension_service.h"
22 #include "chrome/browser/extensions/extension_sorting.h" 23 #include "chrome/browser/extensions/extension_sorting.h"
23 #include "chrome/browser/extensions/extension_system.h" 24 #include "chrome/browser/extensions/extension_system.h"
24 #include "chrome/browser/extensions/management_policy.h" 25 #include "chrome/browser/extensions/management_policy.h"
25 #include "chrome/browser/favicon/favicon_service_factory.h" 26 #include "chrome/browser/favicon/favicon_service_factory.h"
26 #include "chrome/browser/prefs/pref_service.h" 27 #include "chrome/browser/prefs/pref_service.h"
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 sorting->CreateNextAppLaunchOrdinal(page_ordinal); 172 sorting->CreateNextAppLaunchOrdinal(page_ordinal);
172 sorting->SetAppLaunchOrdinal(extension->id(), app_launch_ordinal); 173 sorting->SetAppLaunchOrdinal(extension->id(), app_launch_ordinal);
173 } 174 }
174 value->SetString("app_launch_ordinal", app_launch_ordinal.ToInternalValue()); 175 value->SetString("app_launch_ordinal", app_launch_ordinal.ToInternalValue());
175 } 176 }
176 177
177 void AppLauncherHandler::RegisterMessages() { 178 void AppLauncherHandler::RegisterMessages() {
178 registrar_.Add(this, chrome::NOTIFICATION_APP_INSTALLED_TO_NTP, 179 registrar_.Add(this, chrome::NOTIFICATION_APP_INSTALLED_TO_NTP,
179 content::Source<WebContents>(web_ui()->GetWebContents())); 180 content::Source<WebContents>(web_ui()->GetWebContents()));
180 181
182 web_ui()->RegisterMessageCallback("getShouldShowApps",
183 base::Bind(&AppLauncherHandler::HandleGetShouldShowApps,
184 base::Unretained(this)));
181 web_ui()->RegisterMessageCallback("getApps", 185 web_ui()->RegisterMessageCallback("getApps",
182 base::Bind(&AppLauncherHandler::HandleGetApps, 186 base::Bind(&AppLauncherHandler::HandleGetApps,
183 base::Unretained(this))); 187 base::Unretained(this)));
184 web_ui()->RegisterMessageCallback("launchApp", 188 web_ui()->RegisterMessageCallback("launchApp",
185 base::Bind(&AppLauncherHandler::HandleLaunchApp, 189 base::Bind(&AppLauncherHandler::HandleLaunchApp,
186 base::Unretained(this))); 190 base::Unretained(this)));
187 web_ui()->RegisterMessageCallback("setLaunchType", 191 web_ui()->RegisterMessageCallback("setLaunchType",
188 base::Bind(&AppLauncherHandler::HandleSetLaunchType, 192 base::Bind(&AppLauncherHandler::HandleSetLaunchType,
189 base::Unretained(this))); 193 base::Unretained(this)));
190 web_ui()->RegisterMessageCallback("uninstallApp", 194 web_ui()->RegisterMessageCallback("uninstallApp",
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 *content::Details<const std::string>(details).ptr(); 239 *content::Details<const std::string>(details).ptr();
236 const extensions::AppNotification* notification = 240 const extensions::AppNotification* notification =
237 extension_service_->app_notification_manager()->GetLast(id); 241 extension_service_->app_notification_manager()->GetLast(id);
238 base::StringValue id_value(id); 242 base::StringValue id_value(id);
239 if (notification) { 243 if (notification) {
240 scoped_ptr<DictionaryValue> notification_value( 244 scoped_ptr<DictionaryValue> notification_value(
241 SerializeNotification(*notification)); 245 SerializeNotification(*notification));
242 web_ui()->CallJavascriptFunction("ntp.appNotificationChanged", 246 web_ui()->CallJavascriptFunction("ntp.appNotificationChanged",
243 id_value, *notification_value.get()); 247 id_value, *notification_value.get());
244 } else { 248 } else {
245 web_ui()->CallJavascriptFunction("ntp.appNotificationChanged", 249 web_ui()->CallJavascriptFunction("ntp.appNotificationChanged",
Evan Stade 2013/01/24 18:40:17 now that you're always including the app launcher
jeremya 2013/01/25 00:06:19 Good catch. Moved to new_tab_page_handler.
246 id_value); 250 id_value);
247 } 251 }
248 break; 252 break;
249 } 253 }
250 254
251 case chrome::NOTIFICATION_EXTENSION_LOADED: { 255 case chrome::NOTIFICATION_EXTENSION_LOADED: {
252 const Extension* extension = 256 const Extension* extension =
253 content::Details<const Extension>(details).ptr(); 257 content::Details<const Extension>(details).ptr();
254 if (!extension->is_app()) 258 if (!extension->is_app())
255 return; 259 return;
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 DictionaryValue* app_info = new DictionaryValue(); 387 DictionaryValue* app_info = new DictionaryValue();
384 // CreateAppInfo can change the extension prefs. 388 // CreateAppInfo can change the extension prefs.
385 base::AutoReset<bool> auto_reset(&ignore_changes_, true); 389 base::AutoReset<bool> auto_reset(&ignore_changes_, true);
386 CreateAppInfo(extension, 390 CreateAppInfo(extension,
387 notification_manager->GetLast(extension->id()), 391 notification_manager->GetLast(extension->id()),
388 extension_service_, 392 extension_service_,
389 app_info); 393 app_info);
390 return app_info; 394 return app_info;
391 } 395 }
392 396
397 void AppLauncherHandler::HandleGetShouldShowApps(const ListValue* args) {
398 extensions::UpdateIsAppLauncherEnabled(
399 base::Bind(&AppLauncherHandler::GotIsAppLauncherEnabled,
400 base::Unretained(this)));
Evan Stade 2013/01/24 18:40:17 this doesn't seem right. You need to pass a weak p
jeremya 2013/01/25 00:06:19 Done.
401 }
402
403 void AppLauncherHandler::GotIsAppLauncherEnabled(bool is_enabled) {
404 base::FundamentalValue should_show_apps(!is_enabled);
405 web_ui()->CallJavascriptFunction("ntp.gotShouldShowApps", should_show_apps);
406 }
407
393 void AppLauncherHandler::HandleGetApps(const ListValue* args) { 408 void AppLauncherHandler::HandleGetApps(const ListValue* args) {
394 DictionaryValue dictionary; 409 DictionaryValue dictionary;
395 410
396 // Tell the client whether to show the promo for this view. We don't do this 411 // Tell the client whether to show the promo for this view. We don't do this
397 // in the case of PREF_CHANGED because: 412 // in the case of PREF_CHANGED because:
398 // 413 //
399 // a) At that point in time, depending on the pref that changed, it can look 414 // a) At that point in time, depending on the pref that changed, it can look
400 // like the set of apps installed has changed, and we will mark the promo 415 // like the set of apps installed has changed, and we will mark the promo
401 // expired. 416 // expired.
402 // b) Conceptually, it doesn't really make sense to count a 417 // b) Conceptually, it doesn't really make sense to count a
(...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after
883 898
884 ExtensionUninstallDialog* AppLauncherHandler::GetExtensionUninstallDialog() { 899 ExtensionUninstallDialog* AppLauncherHandler::GetExtensionUninstallDialog() {
885 if (!extension_uninstall_dialog_.get()) { 900 if (!extension_uninstall_dialog_.get()) {
886 Browser* browser = chrome::FindBrowserWithWebContents( 901 Browser* browser = chrome::FindBrowserWithWebContents(
887 web_ui()->GetWebContents()); 902 web_ui()->GetWebContents());
888 extension_uninstall_dialog_.reset( 903 extension_uninstall_dialog_.reset(
889 ExtensionUninstallDialog::Create(browser, this)); 904 ExtensionUninstallDialog::Create(browser, this));
890 } 905 }
891 return extension_uninstall_dialog_.get(); 906 return extension_uninstall_dialog_.get();
892 } 907 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698