Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / ui / webui / app_list / start_page_handler.cc
blob72b10e67110a66be65b57e080d80c920d8be9b0a
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"
7 #include <string>
9 #include "base/bind.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"
31 namespace app_list {
33 namespace {
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.
39 enum DoodleAction {
40 DOODLE_SHOWN = 0,
41 DOODLE_CLICKED,
42 // Add values here.
44 DOODLE_ACTION_LAST,
47 } // namespace
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(
63 "initialize",
64 base::Bind(&StartPageHandler::HandleInitialize, base::Unretained(this)));
65 web_ui()->RegisterMessageCallback(
66 "launchApp",
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,
74 DOODLE_ACTION_LAST);
78 void StartPageHandler::HandleDoodleClicked(const base::ListValue* args) {
79 UMA_HISTOGRAM_ENUMERATION(kAppListDoodleActionHistogram, DOODLE_CLICKED,
80 DOODLE_ACTION_LAST);
83 void StartPageHandler::HandleInitialize(const base::ListValue* args) {
84 Profile* profile = Profile::FromWebUI(web_ui());
85 StartPageService* service = StartPageService::Get(profile);
86 if (!service)
87 return;
89 service->WebUILoaded();
92 void StartPageHandler::HandleLaunchApp(const base::ListValue* args) {
93 std::string app_id;
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);
100 if (!app) {
101 NOTREACHED();
102 return;
105 AppListControllerDelegate* controller = AppListService::Get(
106 chrome::GetHostDesktopTypeForNativeView(
107 web_ui()->GetWebContents()->GetNativeView()))->
108 GetControllerDelegate();
109 controller->ActivateApp(profile,
110 app,
111 AppListControllerDelegate::LAUNCH_FROM_APP_LIST,
112 ui::EF_NONE);
115 } // namespace app_list