Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(137)

Side by Side Diff: chrome/browser/ui/webui/welcome_win10_handler.cc

Issue 2449853008: Determine the Win10-specific Welcome page variant to display (Closed)
Patch Set: comments #2 Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <string>
8
9 #include "base/bind.h" 7 #include "base/bind.h"
10 #include "chrome/browser/shell_integration.h" 8 #include "chrome/browser/shell_integration.h"
11 #include "chrome/common/url_constants.h" 9 #include "chrome/common/url_constants.h"
10 #include "chrome/grit/generated_resources.h"
11 #include "content/public/browser/browser_thread.h"
12 #include "content/public/browser/web_contents.h" 12 #include "content/public/browser/web_contents.h"
13 #include "ui/base/l10n/l10n_util.h"
14 #include "url/gurl.h"
13 15
14 WelcomeWin10Handler::WelcomeWin10Handler() = default; 16 WelcomeWin10Handler::WelcomeWin10Handler() {
17 // The check is started as early as possible because waiting for the page to
18 // be fully loaded is unnecessarily wasting time.
19 StartIsPinnedToTaskbarCheck();
20 }
15 21
16 WelcomeWin10Handler::~WelcomeWin10Handler() = default; 22 WelcomeWin10Handler::~WelcomeWin10Handler() = default;
17 23
18 // Override from WebUIMessageHandler.
19 void WelcomeWin10Handler::RegisterMessages() { 24 void WelcomeWin10Handler::RegisterMessages() {
20 web_ui()->RegisterMessageCallback( 25 web_ui()->RegisterMessageCallback(
21 "handleSetDefaultBrowser", 26 "handleSetDefaultBrowser",
22 base::Bind(&WelcomeWin10Handler::HandleSetDefaultBrowser, 27 base::Bind(&WelcomeWin10Handler::HandleSetDefaultBrowser,
23 base::Unretained(this))); 28 base::Unretained(this)));
24 web_ui()->RegisterMessageCallback( 29 web_ui()->RegisterMessageCallback(
25 "handleContinue", 30 "handleContinue",
26 base::Bind(&WelcomeWin10Handler::HandleContinue, base::Unretained(this))); 31 base::Bind(&WelcomeWin10Handler::HandleContinue, base::Unretained(this)));
32 web_ui()->RegisterMessageCallback(
33 "getPinnedToTaskbarState",
34 base::Bind(&WelcomeWin10Handler::HandleGetPinnedToTaskbarState,
35 base::Unretained(this)));
36 }
37
38 void WelcomeWin10Handler::HandleGetPinnedToTaskbarState(
39 const base::ListValue* args) {
40 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
41 AllowJavascript();
42
43 CHECK_EQ(1U, args->GetSize());
44 // Save the callback id so that the result can be sent back when it is
45 // available.
46 CHECK(args->GetString(0, &pinned_state_callback_id_));
47
48 // Send back the result if it is already available.
49 if (pinned_state_result_) {
50 SendPinnedToTaskbarStateResult();
51 return;
52 }
53
54 // Only wait for a small amount of time for the result. If the timer fires,
55 // it will be assumed that Chrome is pinned to the taskbar.
56 static constexpr base::TimeDelta kPinnedToTaskbarTimeout =
michaelpg 2016/10/31 21:04:59 so it seems this is allowed because it's |constexp
Patrick Monette 2016/10/31 22:33:49 Removed static.
57 base::TimeDelta::FromMilliseconds(200);
58 timer_.Start(FROM_HERE, kPinnedToTaskbarTimeout,
59 base::Bind(&WelcomeWin10Handler::OnIsPinnedToTaskbarDetermined,
60 base::Unretained(this), true));
27 } 61 }
28 62
29 void WelcomeWin10Handler::HandleSetDefaultBrowser(const base::ListValue* args) { 63 void WelcomeWin10Handler::HandleSetDefaultBrowser(const base::ListValue* args) {
30 // The worker owns itself. 64 // The worker owns itself.
31 (new shell_integration::DefaultBrowserWorker( 65 (new shell_integration::DefaultBrowserWorker(
32 shell_integration::DefaultWebClientWorkerCallback())) 66 shell_integration::DefaultWebClientWorkerCallback()))
33 ->StartSetAsDefault(); 67 ->StartSetAsDefault();
34 } 68 }
35 69
36 void WelcomeWin10Handler::HandleContinue(const base::ListValue* args) { 70 void WelcomeWin10Handler::HandleContinue(const base::ListValue* args) {
37 web_ui()->GetWebContents()->GetController().LoadURL( 71 web_ui()->GetWebContents()->GetController().LoadURL(
38 GURL(chrome::kChromeUINewTabURL), content::Referrer(), 72 GURL(chrome::kChromeUINewTabURL), content::Referrer(),
39 ui::PageTransition::PAGE_TRANSITION_LINK, std::string()); 73 ui::PageTransition::PAGE_TRANSITION_LINK, std::string());
40 } 74 }
75
76 void WelcomeWin10Handler::StartIsPinnedToTaskbarCheck() {
77 // Start the utility process that will handle the IsPinnedToTaskbar() call.
78 client_.reset(new content::UtilityProcessMojoClient<mojom::ShellHandler>(
79 l10n_util::GetStringUTF16(IDS_UTILITY_PROCESS_SHELL_HANDLER_NAME)));
80
81 // Assume that Chrome is pinned to the taskbar if an error occurs.
82 client_->set_error_callback(
83 base::Bind(&WelcomeWin10Handler::OnIsPinnedToTaskbarDetermined,
84 base::Unretained(this), true));
85 client_->set_disable_sandbox();
86 client_->Start();
87
88 client_->service()->IsPinnedToTaskbar(base::Bind(
89 &WelcomeWin10Handler::OnIsPinnedToTaskbarResult, base::Unretained(this)));
90 }
91
92 void WelcomeWin10Handler::OnIsPinnedToTaskbarResult(bool succeeded,
93 bool is_pinned_to_taskbar) {
94 OnIsPinnedToTaskbarDetermined(succeeded && is_pinned_to_taskbar);
95 }
96
97 void WelcomeWin10Handler::OnIsPinnedToTaskbarDetermined(
98 bool is_pinned_to_taskbar) {
99 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
100
101 // Reset the client and the timer to make sure this function only gets called
102 // once.
103 client_.reset();
104 timer_.Stop();
105
106 pinned_state_result_ = is_pinned_to_taskbar;
107
108 // If the page already called getPinnedToTaskbarState(), the result can be
109 // sent back.
110 if (!pinned_state_callback_id_.empty())
111 SendPinnedToTaskbarStateResult();
112 }
113
114 void WelcomeWin10Handler::SendPinnedToTaskbarStateResult() {
115 ResolveJavascriptCallback(
116 base::StringValue(pinned_state_callback_id_),
117 base::FundamentalValue(pinned_state_result_.value()));
118 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/welcome_win10_handler.h ('k') | chrome/browser/ui/webui/welcome_win10_ui.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698