OLD | NEW |
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 "apps/metrics_names.h" | 9 #include "apps/metrics_names.h" |
10 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
13 #include "base/i18n/rtl.h" | 13 #include "base/i18n/rtl.h" |
14 #include "base/metrics/field_trial.h" | 14 #include "base/metrics/field_trial.h" |
15 #include "base/metrics/histogram.h" | 15 #include "base/metrics/histogram.h" |
16 #include "base/prefs/pref_service.h" | 16 #include "base/prefs/pref_service.h" |
17 #include "base/prefs/scoped_user_pref_update.h" | 17 #include "base/prefs/scoped_user_pref_update.h" |
18 #include "base/strings/utf_string_conversions.h" | 18 #include "base/strings/utf_string_conversions.h" |
19 #include "base/values.h" | 19 #include "base/values.h" |
20 #include "chrome/browser/browser_process.h" | 20 #include "chrome/browser/browser_process.h" |
21 #include "chrome/browser/chrome_notification_types.h" | 21 #include "chrome/browser/chrome_notification_types.h" |
22 #include "chrome/browser/extensions/crx_installer.h" | 22 #include "chrome/browser/extensions/crx_installer.h" |
23 #include "chrome/browser/extensions/extension_service.h" | 23 #include "chrome/browser/extensions/extension_service.h" |
| 24 #include "chrome/browser/extensions/extension_ui_util.h" |
24 #include "chrome/browser/extensions/launch_util.h" | 25 #include "chrome/browser/extensions/launch_util.h" |
25 #include "chrome/browser/favicon/favicon_service_factory.h" | 26 #include "chrome/browser/favicon/favicon_service_factory.h" |
26 #include "chrome/browser/profiles/profile.h" | 27 #include "chrome/browser/profiles/profile.h" |
27 #include "chrome/browser/ui/app_list/app_list_util.h" | 28 #include "chrome/browser/ui/app_list/app_list_util.h" |
28 #include "chrome/browser/ui/browser_dialogs.h" | 29 #include "chrome/browser/ui/browser_dialogs.h" |
29 #include "chrome/browser/ui/browser_finder.h" | 30 #include "chrome/browser/ui/browser_finder.h" |
30 #include "chrome/browser/ui/browser_tabstrip.h" | 31 #include "chrome/browser/ui/browser_tabstrip.h" |
31 #include "chrome/browser/ui/browser_window.h" | 32 #include "chrome/browser/ui/browser_window.h" |
32 #include "chrome/browser/ui/extensions/application_launch.h" | 33 #include "chrome/browser/ui/extensions/application_launch.h" |
33 #include "chrome/browser/ui/extensions/extension_enable_flow.h" | 34 #include "chrome/browser/ui/extensions/extension_enable_flow.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 using extensions::AppSorting; | 66 using extensions::AppSorting; |
66 using extensions::CrxInstaller; | 67 using extensions::CrxInstaller; |
67 using extensions::Extension; | 68 using extensions::Extension; |
68 using extensions::ExtensionPrefs; | 69 using extensions::ExtensionPrefs; |
69 using extensions::ExtensionRegistry; | 70 using extensions::ExtensionRegistry; |
70 using extensions::ExtensionSet; | 71 using extensions::ExtensionSet; |
71 using extensions::UnloadedExtensionInfo; | 72 using extensions::UnloadedExtensionInfo; |
72 | 73 |
73 namespace { | 74 namespace { |
74 | 75 |
75 bool ShouldDisplayInNewTabPage(const Extension* app, PrefService* prefs) { | |
76 bool blocked_by_policy = | |
77 (app->id() == extension_misc::kWebStoreAppId || | |
78 app->id() == extension_misc::kEnterpriseWebStoreAppId) && | |
79 prefs->GetBoolean(prefs::kHideWebStoreIcon); | |
80 return app->ShouldDisplayInNewTabPage() && !blocked_by_policy; | |
81 } | |
82 | |
83 void RecordAppLauncherPromoHistogram( | 76 void RecordAppLauncherPromoHistogram( |
84 apps::AppLauncherPromoHistogramValues value) { | 77 apps::AppLauncherPromoHistogramValues value) { |
85 DCHECK_LT(value, apps::APP_LAUNCHER_PROMO_MAX); | 78 DCHECK_LT(value, apps::APP_LAUNCHER_PROMO_MAX); |
86 UMA_HISTOGRAM_ENUMERATION( | 79 UMA_HISTOGRAM_ENUMERATION( |
87 "Apps.AppLauncherPromo", value, apps::APP_LAUNCHER_PROMO_MAX); | 80 "Apps.AppLauncherPromo", value, apps::APP_LAUNCHER_PROMO_MAX); |
88 } | 81 } |
89 | 82 |
90 // This is used to avoid a DCHECK due to an unhandled WebUI callback. The | 83 // This is used to avoid a DCHECK due to an unhandled WebUI callback. The |
91 // JavaScript used to switch between pages sends "pageSelected" which is used | 84 // JavaScript used to switch between pages sends "pageSelected" which is used |
92 // in the context of the NTP for recording metrics we don't need here. | 85 // in the context of the NTP for recording metrics we don't need here. |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 if (ignore_changes_ || !has_loaded_apps_) | 252 if (ignore_changes_ || !has_loaded_apps_) |
260 return; | 253 return; |
261 | 254 |
262 switch (type) { | 255 switch (type) { |
263 case chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED: { | 256 case chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED: { |
264 const Extension* extension = | 257 const Extension* extension = |
265 content::Details<const Extension>(details).ptr(); | 258 content::Details<const Extension>(details).ptr(); |
266 if (!extension->is_app()) | 259 if (!extension->is_app()) |
267 return; | 260 return; |
268 | 261 |
269 PrefService* prefs = Profile::FromWebUI(web_ui())->GetPrefs(); | 262 if (!extensions::ui_util::ShouldDisplayInNewTabPage( |
270 if (!ShouldDisplayInNewTabPage(extension, prefs)) | 263 extension, Profile::FromWebUI(web_ui()))) { |
271 return; | 264 return; |
| 265 } |
272 | 266 |
273 scoped_ptr<base::DictionaryValue> app_info(GetAppInfo(extension)); | 267 scoped_ptr<base::DictionaryValue> app_info(GetAppInfo(extension)); |
274 if (app_info.get()) { | 268 if (app_info.get()) { |
275 visible_apps_.insert(extension->id()); | 269 visible_apps_.insert(extension->id()); |
276 | 270 |
277 ExtensionPrefs* prefs = | 271 ExtensionPrefs* prefs = |
278 ExtensionPrefs::Get(extension_service_->profile()); | 272 ExtensionPrefs::Get(extension_service_->profile()); |
279 scoped_ptr<base::FundamentalValue> highlight( | 273 scoped_ptr<base::FundamentalValue> highlight( |
280 base::Value::CreateBooleanValue( | 274 base::Value::CreateBooleanValue( |
281 prefs->IsFromBookmark(extension->id()) && | 275 prefs->IsFromBookmark(extension->id()) && |
(...skipping 18 matching lines...) Expand all Loading... |
300 // Uninstalls are tracked by NOTIFICATION_EXTENSION_UNINSTALLED. | 294 // Uninstalls are tracked by NOTIFICATION_EXTENSION_UNINSTALLED. |
301 return; | 295 return; |
302 } | 296 } |
303 extension = content::Details<extensions::UnloadedExtensionInfo>( | 297 extension = content::Details<extensions::UnloadedExtensionInfo>( |
304 details)->extension; | 298 details)->extension; |
305 uninstalled = false; | 299 uninstalled = false; |
306 } | 300 } |
307 if (!extension->is_app()) | 301 if (!extension->is_app()) |
308 return; | 302 return; |
309 | 303 |
310 PrefService* prefs = Profile::FromWebUI(web_ui())->GetPrefs(); | 304 if (!extensions::ui_util::ShouldDisplayInNewTabPage( |
311 if (!ShouldDisplayInNewTabPage(extension, prefs)) | 305 extension, Profile::FromWebUI(web_ui()))) { |
312 return; | 306 return; |
| 307 } |
313 | 308 |
314 scoped_ptr<base::DictionaryValue> app_info(GetAppInfo(extension)); | 309 scoped_ptr<base::DictionaryValue> app_info(GetAppInfo(extension)); |
315 if (app_info.get()) { | 310 if (app_info.get()) { |
316 if (uninstalled) | 311 if (uninstalled) |
317 visible_apps_.erase(extension->id()); | 312 visible_apps_.erase(extension->id()); |
318 | 313 |
319 scoped_ptr<base::FundamentalValue> uninstall_value( | 314 scoped_ptr<base::FundamentalValue> uninstall_value( |
320 base::Value::CreateBooleanValue(uninstalled)); | 315 base::Value::CreateBooleanValue(uninstalled)); |
321 scoped_ptr<base::FundamentalValue> from_page( | 316 scoped_ptr<base::FundamentalValue> from_page( |
322 base::Value::CreateBooleanValue(!extension_id_prompting_.empty())); | 317 base::Value::CreateBooleanValue(!extension_id_prompting_.empty())); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
361 default: | 356 default: |
362 NOTREACHED(); | 357 NOTREACHED(); |
363 } | 358 } |
364 } | 359 } |
365 | 360 |
366 void AppLauncherHandler::FillAppDictionary(base::DictionaryValue* dictionary) { | 361 void AppLauncherHandler::FillAppDictionary(base::DictionaryValue* dictionary) { |
367 // CreateAppInfo and ClearOrdinals can change the extension prefs. | 362 // CreateAppInfo and ClearOrdinals can change the extension prefs. |
368 base::AutoReset<bool> auto_reset(&ignore_changes_, true); | 363 base::AutoReset<bool> auto_reset(&ignore_changes_, true); |
369 | 364 |
370 base::ListValue* list = new base::ListValue(); | 365 base::ListValue* list = new base::ListValue(); |
371 PrefService* prefs = Profile::FromWebUI(web_ui())->GetPrefs(); | 366 Profile* profile = Profile::FromWebUI(web_ui()); |
| 367 PrefService* prefs = profile->GetPrefs(); |
372 | 368 |
373 for (std::set<std::string>::iterator it = visible_apps_.begin(); | 369 for (std::set<std::string>::iterator it = visible_apps_.begin(); |
374 it != visible_apps_.end(); ++it) { | 370 it != visible_apps_.end(); ++it) { |
375 const Extension* extension = extension_service_->GetInstalledExtension(*it); | 371 const Extension* extension = extension_service_->GetInstalledExtension(*it); |
376 if (extension && ShouldDisplayInNewTabPage(extension, prefs)) { | 372 if (extension && extensions::ui_util::ShouldDisplayInNewTabPage( |
| 373 extension, profile)) { |
377 base::DictionaryValue* app_info = GetAppInfo(extension); | 374 base::DictionaryValue* app_info = GetAppInfo(extension); |
378 list->Append(app_info); | 375 list->Append(app_info); |
379 } | 376 } |
380 } | 377 } |
381 | 378 |
382 dictionary->Set("apps", list); | 379 dictionary->Set("apps", list); |
383 | 380 |
384 // TODO(estade): remove these settings when the old NTP is removed. The new | 381 // TODO(estade): remove these settings when the old NTP is removed. The new |
385 // NTP does it in js. | 382 // NTP does it in js. |
386 #if defined(OS_MACOSX) | 383 #if defined(OS_MACOSX) |
(...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
851 ExtensionUninstallDialog* AppLauncherHandler::GetExtensionUninstallDialog() { | 848 ExtensionUninstallDialog* AppLauncherHandler::GetExtensionUninstallDialog() { |
852 if (!extension_uninstall_dialog_.get()) { | 849 if (!extension_uninstall_dialog_.get()) { |
853 Browser* browser = chrome::FindBrowserWithWebContents( | 850 Browser* browser = chrome::FindBrowserWithWebContents( |
854 web_ui()->GetWebContents()); | 851 web_ui()->GetWebContents()); |
855 extension_uninstall_dialog_.reset( | 852 extension_uninstall_dialog_.reset( |
856 ExtensionUninstallDialog::Create(extension_service_->profile(), | 853 ExtensionUninstallDialog::Create(extension_service_->profile(), |
857 browser, this)); | 854 browser, this)); |
858 } | 855 } |
859 return extension_uninstall_dialog_.get(); | 856 return extension_uninstall_dialog_.get(); |
860 } | 857 } |
OLD | NEW |