Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/webui/welcome_win10_handler.h" | 5 #include "chrome/browser/ui/webui/welcome_win10_handler.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/memory/ptr_util.h" | 8 #include "base/values.h" |
| 9 #include "chrome/browser/shell_integration.h" | 9 #include "chrome/browser/shell_integration.h" |
| 10 #include "chrome/browser/shell_integration_win.h" | |
| 10 #include "chrome/common/url_constants.h" | 11 #include "chrome/common/url_constants.h" |
| 11 #include "chrome/grit/generated_resources.h" | |
| 12 #include "content/public/browser/browser_thread.h" | 12 #include "content/public/browser/browser_thread.h" |
| 13 #include "content/public/browser/web_contents.h" | 13 #include "content/public/browser/web_contents.h" |
| 14 #include "ui/base/l10n/l10n_util.h" | |
| 15 #include "url/gurl.h" | 14 #include "url/gurl.h" |
| 16 | 15 |
| 17 WelcomeWin10Handler::WelcomeWin10Handler() { | 16 WelcomeWin10Handler::WelcomeWin10Handler() : weak_ptr_factory_(this) { |
| 18 // The check is started as early as possible because waiting for the page to | 17 // The check is started as early as possible because waiting for the page to |
| 19 // be fully loaded is unnecessarily wasting time. | 18 // be fully loaded is unnecessarily wasting time. |
| 20 StartIsPinnedToTaskbarCheck(); | 19 StartIsPinnedToTaskbarCheck(); |
| 21 } | 20 } |
| 22 | 21 |
| 23 WelcomeWin10Handler::~WelcomeWin10Handler() = default; | 22 WelcomeWin10Handler::~WelcomeWin10Handler() = default; |
| 24 | 23 |
| 25 void WelcomeWin10Handler::RegisterMessages() { | 24 void WelcomeWin10Handler::RegisterMessages() { |
| 26 web_ui()->RegisterMessageCallback( | 25 web_ui()->RegisterMessageCallback( |
| 27 "handleSetDefaultBrowser", | 26 "handleSetDefaultBrowser", |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 68 ->StartSetAsDefault(); | 67 ->StartSetAsDefault(); |
| 69 } | 68 } |
| 70 | 69 |
| 71 void WelcomeWin10Handler::HandleContinue(const base::ListValue* args) { | 70 void WelcomeWin10Handler::HandleContinue(const base::ListValue* args) { |
| 72 web_ui()->GetWebContents()->GetController().LoadURL( | 71 web_ui()->GetWebContents()->GetController().LoadURL( |
| 73 GURL(chrome::kChromeUINewTabURL), content::Referrer(), | 72 GURL(chrome::kChromeUINewTabURL), content::Referrer(), |
| 74 ui::PageTransition::PAGE_TRANSITION_LINK, std::string()); | 73 ui::PageTransition::PAGE_TRANSITION_LINK, std::string()); |
| 75 } | 74 } |
| 76 | 75 |
| 77 void WelcomeWin10Handler::StartIsPinnedToTaskbarCheck() { | 76 void WelcomeWin10Handler::StartIsPinnedToTaskbarCheck() { |
| 78 // Start the utility process that will handle the IsPinnedToTaskbar() call. | 77 // Assume that Chrome is pinned to the taskbar if an error occurs. |
| 79 client_ = | 78 base::Closure error_callback = |
| 80 base::MakeUnique<content::UtilityProcessMojoClient<mojom::ShellHandler>>( | 79 base::Bind(&WelcomeWin10Handler::OnIsPinnedToTaskbarDetermined, |
| 81 l10n_util::GetStringUTF16(IDS_UTILITY_PROCESS_SHELL_HANDLER_NAME)); | 80 weak_ptr_factory_.GetWeakPtr(), true); |
| 82 | 81 |
| 83 // Assume that Chrome is pinned to the taskbar if an error occurs. | 82 shell_integration::win::GetIsPinnedToTaskbarState( |
| 84 client_->set_error_callback( | 83 error_callback, |
| 85 base::Bind(&WelcomeWin10Handler::OnIsPinnedToTaskbarDetermined, | 84 base::Bind(&WelcomeWin10Handler::OnIsPinnedToTaskbarResult, |
| 86 base::Unretained(this), true)); | 85 weak_ptr_factory_.GetWeakPtr())); |
| 87 client_->set_disable_sandbox(); | |
| 88 client_->Start(); | |
| 89 | |
| 90 client_->service()->IsPinnedToTaskbar(base::Bind( | |
| 91 &WelcomeWin10Handler::OnIsPinnedToTaskbarResult, base::Unretained(this))); | |
| 92 } | 86 } |
| 93 | 87 |
| 94 void WelcomeWin10Handler::OnIsPinnedToTaskbarResult(bool succeeded, | 88 void WelcomeWin10Handler::OnIsPinnedToTaskbarResult(bool succeeded, |
| 95 bool is_pinned_to_taskbar) { | 89 bool is_pinned_to_taskbar) { |
| 96 OnIsPinnedToTaskbarDetermined(succeeded && is_pinned_to_taskbar); | 90 OnIsPinnedToTaskbarDetermined(succeeded && is_pinned_to_taskbar); |
|
grt (UTC plus 2)
2016/11/21 10:45:31
should this be !succeeded || is_pinned_to_taskbar
Patrick Monette
2016/11/21 18:48:47
Good catch. Done.
| |
| 97 } | 91 } |
| 98 | 92 |
| 99 void WelcomeWin10Handler::OnIsPinnedToTaskbarDetermined( | 93 void WelcomeWin10Handler::OnIsPinnedToTaskbarDetermined( |
| 100 bool is_pinned_to_taskbar) { | 94 bool is_pinned_to_taskbar) { |
| 101 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 95 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 102 | 96 |
| 103 // Reset the client and the timer to make sure this function only gets called | 97 // Early exit if the pinned_state was already determined. |
| 104 // once. | 98 if (pinned_state_result_) |
| 105 client_.reset(); | 99 return; |
| 100 | |
| 101 // Stop the timer if it's still running. | |
| 106 timer_.Stop(); | 102 timer_.Stop(); |
| 107 | 103 |
| 108 pinned_state_result_ = is_pinned_to_taskbar; | 104 pinned_state_result_ = is_pinned_to_taskbar; |
| 109 | 105 |
| 110 // If the page already called getPinnedToTaskbarState(), the result can be | 106 // If the page already called getPinnedToTaskbarState(), the result can be |
| 111 // sent back. | 107 // sent back. |
| 112 if (!pinned_state_callback_id_.empty()) | 108 if (!pinned_state_callback_id_.empty()) |
| 113 SendPinnedToTaskbarStateResult(); | 109 SendPinnedToTaskbarStateResult(); |
| 114 } | 110 } |
| 115 | 111 |
| 116 void WelcomeWin10Handler::SendPinnedToTaskbarStateResult() { | 112 void WelcomeWin10Handler::SendPinnedToTaskbarStateResult() { |
| 117 ResolveJavascriptCallback( | 113 ResolveJavascriptCallback( |
| 118 base::StringValue(pinned_state_callback_id_), | 114 base::StringValue(pinned_state_callback_id_), |
| 119 base::FundamentalValue(pinned_state_result_.value())); | 115 base::FundamentalValue(pinned_state_result_.value())); |
| 120 } | 116 } |
| OLD | NEW |