1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/webui/app_list/start_page_handler.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/metrics/histogram_macros.h"
12 #include "base/values.h"
13 #include "base/version.h"
14 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/ui/app_list/app_list_controller_delegate.h"
16 #include "chrome/browser/ui/app_list/app_list_service.h"
17 #include "chrome/browser/ui/app_list/start_page_service.h"
18 #include "chrome/browser/ui/host_desktop.h"
19 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h"
20 #include "chrome/common/pref_names.h"
21 #include "components/update_client/update_query_params.h"
22 #include "content/public/browser/web_ui.h"
23 #include "extensions/browser/extension_registry.h"
24 #include "extensions/browser/extension_system.h"
25 #include "extensions/common/constants.h"
26 #include "extensions/common/extension.h"
27 #include "extensions/common/extension_icon_set.h"
28 #include "ui/app_list/app_list_switches.h"
29 #include "ui/events/event_constants.h"
35 const char kAppListDoodleActionHistogram
[] = "Apps.AppListDoodleAction";
37 // Interactions a user has with the app list doodle. This enum must not have its
38 // order altered as it is used in histograms.
49 StartPageHandler::StartPageHandler() {
52 StartPageHandler::~StartPageHandler() {
55 void StartPageHandler::RegisterMessages() {
56 web_ui()->RegisterMessageCallback(
57 "appListShown", base::Bind(&StartPageHandler::HandleAppListShown
,
58 base::Unretained(this)));
59 web_ui()->RegisterMessageCallback(
60 "doodleClicked", base::Bind(&StartPageHandler::HandleDoodleClicked
,
61 base::Unretained(this)));
62 web_ui()->RegisterMessageCallback(
64 base::Bind(&StartPageHandler::HandleInitialize
, base::Unretained(this)));
65 web_ui()->RegisterMessageCallback(
67 base::Bind(&StartPageHandler::HandleLaunchApp
, base::Unretained(this)));
70 void StartPageHandler::HandleAppListShown(const base::ListValue
* args
) {
71 bool doodle_shown
= false;
72 if (args
->GetBoolean(0, &doodle_shown
) && doodle_shown
) {
73 UMA_HISTOGRAM_ENUMERATION(kAppListDoodleActionHistogram
, DOODLE_SHOWN
,
78 void StartPageHandler::HandleDoodleClicked(const base::ListValue
* args
) {
79 UMA_HISTOGRAM_ENUMERATION(kAppListDoodleActionHistogram
, DOODLE_CLICKED
,
83 void StartPageHandler::HandleInitialize(const base::ListValue
* args
) {
84 Profile
* profile
= Profile::FromWebUI(web_ui());
85 StartPageService
* service
= StartPageService::Get(profile
);
89 service
->WebUILoaded();
92 void StartPageHandler::HandleLaunchApp(const base::ListValue
* args
) {
94 CHECK(args
->GetString(0, &app_id
));
96 Profile
* profile
= Profile::FromWebUI(web_ui());
97 const extensions::Extension
* app
=
98 extensions::ExtensionRegistry::Get(profile
)
99 ->GetExtensionById(app_id
, extensions::ExtensionRegistry::EVERYTHING
);
105 AppListControllerDelegate
* controller
= AppListService::Get(
106 chrome::GetHostDesktopTypeForNativeView(
107 web_ui()->GetWebContents()->GetNativeView()))->
108 GetControllerDelegate();
109 controller
->ActivateApp(profile
,
111 AppListControllerDelegate::LAUNCH_FROM_APP_LIST
,
115 } // namespace app_list