1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
|
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/extensions/api/launcher_page/launcher_page_api.h"
#include "base/lazy_instance.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/app_list/app_list_service.h"
#include "chrome/browser/ui/app_list/app_list_syncable_service.h"
#include "chrome/browser/ui/app_list/app_list_syncable_service_factory.h"
#include "chrome/common/extensions/api/launcher_page.h"
#include "content/public/browser/web_contents.h"
#include "ui/app_list/app_list_model.h"
namespace extensions {
static base::LazyInstance<BrowserContextKeyedAPIFactory<LauncherPageAPI>>
g_factory = LAZY_INSTANCE_INITIALIZER;
// static
BrowserContextKeyedAPIFactory<LauncherPageAPI>*
LauncherPageAPI::GetFactoryInstance() {
return g_factory.Pointer();
}
LauncherPageAPI::LauncherPageAPI(content::BrowserContext* context)
: service_(app_list::AppListSyncableServiceFactory::GetForProfile(
Profile::FromBrowserContext(context))) {
}
LauncherPageAPI::~LauncherPageAPI() {
}
app_list::AppListSyncableService* LauncherPageAPI::GetService() const {
return service_;
}
LauncherPagePushSubpageFunction::LauncherPagePushSubpageFunction() {
}
ExtensionFunction::ResponseAction LauncherPagePushSubpageFunction::Run() {
app_list::AppListSyncableService* service =
LauncherPageAPI::GetFactoryInstance()
->Get(browser_context())
->GetService();
app_list::AppListModel* model = service->model();
model->PushCustomLauncherPageSubpage();
return RespondNow(NoArguments());
}
LauncherPageShowFunction::LauncherPageShowFunction() {
}
ExtensionFunction::ResponseAction LauncherPageShowFunction::Run() {
chrome::HostDesktopType host_desktop =
chrome::GetHostDesktopTypeForNativeWindow(
GetAssociatedWebContents()->GetTopLevelNativeWindow());
AppListService::Get(host_desktop)
->ShowForCustomLauncherPage(
Profile::FromBrowserContext(browser_context()));
return RespondNow(NoArguments());
}
LauncherPageSetEnabledFunction::LauncherPageSetEnabledFunction() {
}
ExtensionFunction::ResponseAction LauncherPageSetEnabledFunction::Run() {
scoped_ptr<api::launcher_page::SetEnabled::Params> params(
api::launcher_page::SetEnabled::Params::Create(*args_));
EXTENSION_FUNCTION_VALIDATE(params.get());
app_list::AppListSyncableService* service =
LauncherPageAPI::GetFactoryInstance()
->Get(browser_context())
->GetService();
app_list::AppListModel* model = service->model();
model->SetCustomLauncherPageEnabled(params->enabled);
return RespondNow(NoArguments());
}
} // namespace extensions
|