1 // Copyright 2014 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/extensions/api/launcher_page/launcher_page_api.h"
7 #include "base/lazy_instance.h"
8 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/ui/app_list/app_list_service.h"
10 #include "chrome/browser/ui/app_list/app_list_syncable_service.h"
11 #include "chrome/browser/ui/app_list/app_list_syncable_service_factory.h"
12 #include "chrome/common/extensions/api/launcher_page.h"
13 #include "content/public/browser/web_contents.h"
14 #include "ui/app_list/app_list_model.h"
16 namespace extensions
{
18 static base::LazyInstance
<BrowserContextKeyedAPIFactory
<LauncherPageAPI
>>
19 g_factory
= LAZY_INSTANCE_INITIALIZER
;
22 BrowserContextKeyedAPIFactory
<LauncherPageAPI
>*
23 LauncherPageAPI::GetFactoryInstance() {
24 return g_factory
.Pointer();
27 LauncherPageAPI::LauncherPageAPI(content::BrowserContext
* context
)
28 : service_(app_list::AppListSyncableServiceFactory::GetForProfile(
29 Profile::FromBrowserContext(context
))) {
32 LauncherPageAPI::~LauncherPageAPI() {
35 app_list::AppListSyncableService
* LauncherPageAPI::GetService() const {
39 LauncherPagePushSubpageFunction::LauncherPagePushSubpageFunction() {
42 ExtensionFunction::ResponseAction
LauncherPagePushSubpageFunction::Run() {
43 app_list::AppListSyncableService
* service
=
44 LauncherPageAPI::GetFactoryInstance()
45 ->Get(browser_context())
47 app_list::AppListModel
* model
= service
->GetModel();
48 model
->PushCustomLauncherPageSubpage();
50 return RespondNow(NoArguments());
53 LauncherPageShowFunction::LauncherPageShowFunction() {
56 ExtensionFunction::ResponseAction
LauncherPageShowFunction::Run() {
57 chrome::HostDesktopType host_desktop
=
58 chrome::GetHostDesktopTypeForNativeWindow(
59 GetAssociatedWebContents()->GetTopLevelNativeWindow());
61 AppListService::Get(host_desktop
)
62 ->ShowForCustomLauncherPage(
63 Profile::FromBrowserContext(browser_context()));
65 return RespondNow(NoArguments());
68 LauncherPageHideFunction::LauncherPageHideFunction() {
71 ExtensionFunction::ResponseAction
LauncherPageHideFunction::Run() {
72 chrome::HostDesktopType host_desktop
=
73 chrome::GetHostDesktopTypeForNativeWindow(
74 GetAssociatedWebContents()->GetTopLevelNativeWindow());
76 AppListService::Get(host_desktop
)->HideCustomLauncherPage();
78 return RespondNow(NoArguments());
81 LauncherPageSetEnabledFunction::LauncherPageSetEnabledFunction() {
84 ExtensionFunction::ResponseAction
LauncherPageSetEnabledFunction::Run() {
85 scoped_ptr
<api::launcher_page::SetEnabled::Params
> params(
86 api::launcher_page::SetEnabled::Params::Create(*args_
));
87 EXTENSION_FUNCTION_VALIDATE(params
.get());
89 app_list::AppListSyncableService
* service
=
90 LauncherPageAPI::GetFactoryInstance()
91 ->Get(browser_context())
93 app_list::AppListModel
* model
= service
->GetModel();
94 model
->SetCustomLauncherPageEnabled(params
->enabled
);
96 return RespondNow(NoArguments());
99 } // namespace extensions