Commit a43eb717 authored by calamity's avatar calamity Committed by Commit bot

Add launcherPage.hide() API.

This CL adds a launcherPage.hide() API which can be used by custom
launcher pages to implement custom hiding behavior. The API only works
if the custom launcher page is showing and does nothing otherwise.

BUG=481712

Review URL: https://codereview.chromium.org/1137503005

Cr-Commit-Position: refs/heads/master@{#330065}
parent 1edc0b3f
......@@ -315,10 +315,11 @@ IN_PROC_BROWSER_TEST_F(CustomLauncherPageBrowserTest, LauncherPageSubpages) {
contents_view->IsStateActive(app_list::AppListModel::STATE_START));
}
IN_PROC_BROWSER_TEST_F(CustomLauncherPageBrowserTest,
LauncherPageShow) {
IN_PROC_BROWSER_TEST_F(CustomLauncherPageBrowserTest, LauncherPageShowAndHide) {
const base::string16 kLauncherPageShowScript =
base::ASCIIToUTF16("chrome.launcherPage.show();");
const base::string16 kLauncherPageHideScript =
base::ASCIIToUTF16("hideCustomLauncherPage()");
LoadAndLaunchPlatformApp(kCustomLauncherPagePath, "Launched");
app_list::AppListView* app_list_view = GetAppListView();
......@@ -362,6 +363,29 @@ IN_PROC_BROWSER_TEST_F(CustomLauncherPageBrowserTest,
EXPECT_TRUE(contents_view->IsStateActive(
app_list::AppListModel::STATE_CUSTOM_LAUNCHER_PAGE));
}
// Ensure launcherPage.hide() hides the launcher page when it's showing.
{
ExtensionTestMessageListener listener("onPageProgressAt0", false);
custom_page_frame->ExecuteJavaScript(kLauncherPageHideScript);
listener.WaitUntilSatisfied();
EXPECT_TRUE(
contents_view->IsStateActive(app_list::AppListModel::STATE_START));
}
// Nothing should happen if hide() is called from the apps page.
{
contents_view->SetActiveState(app_list::AppListModel::STATE_APPS, false);
ExtensionTestMessageListener listener("launcherPageHidden", false);
custom_page_frame->ExecuteJavaScript(kLauncherPageHideScript);
listener.WaitUntilSatisfied();
EXPECT_TRUE(
contents_view->IsStateActive(app_list::AppListModel::STATE_APPS));
}
}
IN_PROC_BROWSER_TEST_F(CustomLauncherPageBrowserTest, LauncherPageSetEnabled) {
......
......@@ -65,6 +65,19 @@ ExtensionFunction::ResponseAction LauncherPageShowFunction::Run() {
return RespondNow(NoArguments());
}
LauncherPageHideFunction::LauncherPageHideFunction() {
}
ExtensionFunction::ResponseAction LauncherPageHideFunction::Run() {
chrome::HostDesktopType host_desktop =
chrome::GetHostDesktopTypeForNativeWindow(
GetAssociatedWebContents()->GetTopLevelNativeWindow());
AppListService::Get(host_desktop)->HideCustomLauncherPage();
return RespondNow(NoArguments());
}
LauncherPageSetEnabledFunction::LauncherPageSetEnabledFunction() {
}
......
......@@ -65,6 +65,21 @@ class LauncherPageShowFunction : public UIThreadExtensionFunction {
DISALLOW_COPY_AND_ASSIGN(LauncherPageShowFunction);
};
class LauncherPageHideFunction : public UIThreadExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("launcherPage.hide", LAUNCHERPAGE_HIDE);
LauncherPageHideFunction();
protected:
~LauncherPageHideFunction() override {}
ResponseAction Run() override;
private:
DISALLOW_COPY_AND_ASSIGN(LauncherPageHideFunction);
};
class LauncherPageSetEnabledFunction : public UIThreadExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("launcherPage.setEnabled",
......
......@@ -100,6 +100,10 @@ class AppListService {
// Shows the app list, and switches to the custom launcher page.
virtual void ShowForCustomLauncherPage(Profile* profile) = 0;
// Hides the custom launcher page if it is currently being shown. Does nothing
// otherwise.
virtual void HideCustomLauncherPage() = 0;
// Dismiss the app list.
virtual void DismissAppList() = 0;
......
......@@ -35,6 +35,7 @@ class AppListServiceDisabled : public AppListService {
Profile* profile,
const scoped_refptr<content::SpeechRecognitionSessionPreamble>& preamble)
override {}
void HideCustomLauncherPage() override {}
void ShowForAppInstall(Profile* profile,
const std::string& extension_id,
bool start_discovery_tracking) override {}
......
......@@ -51,6 +51,7 @@ class AppListServiceMac : public AppListServiceImpl,
void Init(Profile* initial_profile) override;
void DismissAppList() override;
void ShowForCustomLauncherPage(Profile* profile) override;
void HideCustomLauncherPage() override;
bool IsAppListVisible() const override;
void EnableAppList(Profile* initial_profile,
AppListEnableSource enable_source) override;
......
......@@ -425,6 +425,10 @@ void AppListServiceMac::ShowForCustomLauncherPage(Profile* profile) {
NOTIMPLEMENTED();
}
void AppListServiceMac::HideCustomLauncherPage() {
NOTIMPLEMENTED();
}
bool AppListServiceMac::IsAppListVisible() const {
return [GetNativeWindow() isVisible] &&
![animation_controller_ isClosing];
......
......@@ -56,6 +56,7 @@ class TestingAppListServiceImpl : public AppListServiceImpl {
}
void ShowForCustomLauncherPage(Profile* profile) override {}
void HideCustomLauncherPage() override {}
void DismissAppList() override { showing_for_profile_ = NULL; }
......
......@@ -49,6 +49,19 @@ void AppListServiceViews::ShowForCustomLauncherPage(Profile* profile) {
app_list::AppListModel::STATE_CUSTOM_LAUNCHER_PAGE);
}
void AppListServiceViews::HideCustomLauncherPage() {
if (!shower_.IsAppListVisible())
return;
app_list::ContentsView* contents_view =
shower_.app_list()->app_list_main_view()->contents_view();
if (contents_view->IsStateActive(
app_list::AppListModel::STATE_CUSTOM_LAUNCHER_PAGE)) {
contents_view->SetActiveState(app_list::AppListModel::STATE_START, true);
}
}
void AppListServiceViews::DismissAppList() {
if (!can_dismiss_)
return;
......
......@@ -38,6 +38,7 @@ class AppListServiceViews : public AppListServiceImpl,
const std::string& extension_id,
bool start_discovery_tracking) override;
void ShowForCustomLauncherPage(Profile* profile) override;
void HideCustomLauncherPage() override;
void DismissAppList() override;
bool IsAppListVisible() const override;
gfx::NativeWindow GetAppListWindow() override;
......
......@@ -91,6 +91,20 @@ void AppListServiceAsh::ShowForCustomLauncherPage(Profile* /*profile*/) {
ShowAndSwitchToState(app_list::AppListModel::STATE_CUSTOM_LAUNCHER_PAGE);
}
void AppListServiceAsh::HideCustomLauncherPage() {
app_list::AppListView* app_list_view =
ash::Shell::GetInstance()->GetAppListView();
if (!app_list_view)
return;
app_list::ContentsView* contents_view =
app_list_view->app_list_main_view()->contents_view();
if (contents_view->IsStateActive(
app_list::AppListModel::STATE_CUSTOM_LAUNCHER_PAGE)) {
contents_view->SetActiveState(app_list::AppListModel::STATE_START, true);
}
}
bool AppListServiceAsh::IsAppListVisible() const {
return ash::Shell::GetInstance()->GetAppListTargetVisibility();
}
......
......@@ -44,6 +44,7 @@ class AppListServiceAsh : public AppListServiceImpl {
const std::string& extension_id,
bool start_discovery_tracking) override;
void ShowForCustomLauncherPage(Profile* profile) override;
void HideCustomLauncherPage() override;
bool IsAppListVisible() const override;
void DismissAppList() override;
void EnableAppList(Profile* initial_profile,
......
......@@ -7,6 +7,7 @@
namespace launcherPage {
callback PushSubpageCallback = void();
callback ShowCallback = void();
callback HideCallback = void();
callback SetEnabledCallback = void();
interface Functions {
......@@ -24,6 +25,9 @@ namespace launcherPage {
// page.
static void show(optional ShowCallback callback);
// Returns the launcher to the start page if the launcher page is showing.
static void hide(optional HideCallback callback);
// Sets whether the launcher page is enabled in the launcher. If disabled,
// the launcher page will not be shown when the area at the bottom of the
// launcher is pressed.
......
......@@ -31,6 +31,12 @@ function enableCustomLauncherPage() {
});
}
function hideCustomLauncherPage() {
chrome.launcherPage.hide(function() {
chrome.test.sendMessage('launcherPageHidden');
});
}
document.addEventListener('DOMContentLoaded', function() {
chrome.test.sendMessage('Launched');
});
......
......@@ -1098,6 +1098,7 @@ enum HistogramValue {
PASSWORDSPRIVATE_REMOVESAVEDPASSWORD,
PASSWORDSPRIVATE_REMOVEPASSWORDEXCEPTION,
PASSWORDSPRIVATE_GETPLAINTEXTPASSWORD,
LAUNCHERPAGE_HIDE,
// Last entry: Add new entries above and ensure to update
// tools/metrics/histograms/histograms.xml.
ENUM_BOUNDARY
......
......@@ -52345,6 +52345,7 @@ Therefore, the affected-histogram name has to have at least one dot in it.
<int value="1037" label="PASSWORDSPRIVATE_REMOVESAVEDPASSWORD"/>
<int value="1038" label="PASSWORDSPRIVATE_REMOVEPASSWORDEXCEPTION"/>
<int value="1039" label="PASSWORDSPRIVATE_GETPLAINTEXTPASSWORD"/>
<int value="1040" label="LAUNCHERPAGE_HIDE"/>
</enum>
<enum name="ExtensionInstallCause" type="int">
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment