Chromium Code Reviews| Index: chrome/browser/ui/webui/welcome_win10_handler.cc |
| diff --git a/chrome/browser/ui/webui/welcome_win10_handler.cc b/chrome/browser/ui/webui/welcome_win10_handler.cc |
| index de4167ad0b359e2850c9f2c8e7544b8e42322247..02df7c892607c3575f4d20cf470b5fc3dd61f781 100644 |
| --- a/chrome/browser/ui/webui/welcome_win10_handler.cc |
| +++ b/chrome/browser/ui/webui/welcome_win10_handler.cc |
| @@ -9,13 +9,15 @@ |
| #include "base/bind.h" |
| #include "chrome/browser/shell_integration.h" |
| #include "chrome/common/url_constants.h" |
| +#include "chrome/grit/generated_resources.h" |
| #include "content/public/browser/web_contents.h" |
| +#include "ui/base/l10n/l10n_util.h" |
| +#include "url/gurl.h" |
| WelcomeWin10Handler::WelcomeWin10Handler() = default; |
| WelcomeWin10Handler::~WelcomeWin10Handler() = default; |
| -// Override from WebUIMessageHandler. |
| void WelcomeWin10Handler::RegisterMessages() { |
| web_ui()->RegisterMessageCallback( |
| "handleSetDefaultBrowser", |
| @@ -24,6 +26,41 @@ void WelcomeWin10Handler::RegisterMessages() { |
| web_ui()->RegisterMessageCallback( |
| "handleContinue", |
| base::Bind(&WelcomeWin10Handler::HandleContinue, base::Unretained(this))); |
| + web_ui()->RegisterMessageCallback( |
| + "handleIsPinnedToTaskbar", |
| + base::Bind(&WelcomeWin10Handler::HandleIsPinnedToTaskbar, |
| + base::Unretained(this))); |
| +} |
| + |
| +void WelcomeWin10Handler::HandleIsPinnedToTaskbar(const base::ListValue* args) { |
| + AllowJavascript(); |
| + |
| + CHECK_EQ(1U, args->GetSize()); |
| + std::string callback_id; |
| + CHECK(args->GetString(0, &callback_id)); |
| + |
| + // Assume that Chrome is pinned to the taskbar if an error occured while |
| + // checking or if the timeout is hit. |
| + base::Closure on_error_callback = |
| + base::Bind(&WelcomeWin10Handler::OnIsPinnedToTaskbarDetermined, |
| + base::Unretained(this), callback_id, true); |
| + |
| + constexpr base::TimeDelta kPinnedToTaskbarTimeout = |
| + base::TimeDelta::FromMilliseconds(2000); |
|
tmartino
2016/10/28 15:18:04
2s seems quite high.
Patrick Monette
2016/10/28 21:21:37
I've put 200ms. On my debug version of Chrome, the
|
| + // Set a timeout. |
| + timer_.Start(FROM_HERE, kPinnedToTaskbarTimeout, on_error_callback); |
| + |
| + // Start the utility process that will handle the IsPinnedToTaskbar() call. |
|
tmartino
2016/10/28 15:18:04
Would it be possible to start the check in the cto
Patrick Monette
2016/10/28 21:21:37
Seems reasonable. Done.
|
| + client_.reset(new content::UtilityProcessMojoClient<mojom::ShellHandler>( |
| + l10n_util::GetStringUTF16(IDS_UTILITY_PROCESS_SHELL_HANDLER_NAME))); |
| + |
| + client_->set_error_callback(on_error_callback); |
| + client_->set_disable_sandbox(); |
| + client_->Start(); |
| + |
| + client_->service()->IsPinnedToTaskbar( |
| + base::Bind(&WelcomeWin10Handler::OnIsPinnedToTaskbarResult, |
| + base::Unretained(this), callback_id)); |
| } |
| void WelcomeWin10Handler::HandleSetDefaultBrowser(const base::ListValue* args) { |
| @@ -38,3 +75,22 @@ void WelcomeWin10Handler::HandleContinue(const base::ListValue* args) { |
| GURL(chrome::kChromeUINewTabURL), content::Referrer(), |
| ui::PageTransition::PAGE_TRANSITION_LINK, std::string()); |
| } |
| + |
| +void WelcomeWin10Handler::OnIsPinnedToTaskbarResult( |
| + const std::string& callback_id, |
| + bool succeeded, |
| + bool is_pinned_to_taskbar) { |
| + OnIsPinnedToTaskbarDetermined(callback_id, succeeded && is_pinned_to_taskbar); |
| +} |
| + |
| +void WelcomeWin10Handler::OnIsPinnedToTaskbarDetermined( |
| + const std::string& callback_id, |
| + bool is_pinned_to_taskbar) { |
| + // Reset the client and the timer to make sure this function only gets called |
| + // once. |
| + client_.reset(); |
| + timer_.Stop(); |
| + |
| + ResolveJavascriptCallback(base::StringValue(callback_id), |
| + base::FundamentalValue(is_pinned_to_taskbar)); |
| +} |