1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/webui/chromeos/first_run/first_run_handler.h"
8 #include "base/values.h"
9 #include "content/public/browser/web_ui.h"
13 FirstRunHandler::FirstRunHandler()
14 : is_initialized_(false),
15 is_finalizing_(false) {
18 bool FirstRunHandler::IsInitialized() {
19 return is_initialized_
;
22 void FirstRunHandler::SetBackgroundVisible(bool visible
) {
23 web_ui()->CallJavascriptFunction("cr.FirstRun.setBackgroundVisible",
24 base::FundamentalValue(visible
));
27 void FirstRunHandler::AddRectangularHole(int x
, int y
, int width
, int height
) {
28 web_ui()->CallJavascriptFunction("cr.FirstRun.addRectangularHole",
29 base::FundamentalValue(x
),
30 base::FundamentalValue(y
),
31 base::FundamentalValue(width
),
32 base::FundamentalValue(height
));
35 void FirstRunHandler::AddRoundHole(int x
, int y
, float radius
) {
36 web_ui()->CallJavascriptFunction("cr.FirstRun.addRoundHole",
37 base::FundamentalValue(x
),
38 base::FundamentalValue(y
),
39 base::FundamentalValue(radius
));
42 void FirstRunHandler::RemoveBackgroundHoles() {
43 web_ui()->CallJavascriptFunction("cr.FirstRun.removeHoles");
46 void FirstRunHandler::ShowStepPositioned(const std::string
& name
,
47 const StepPosition
& position
) {
48 web_ui()->CallJavascriptFunction("cr.FirstRun.showStep",
49 base::StringValue(name
),
53 void FirstRunHandler::ShowStepPointingTo(const std::string
& name
,
57 scoped_ptr
<base::Value
> null
= base::Value::CreateNullValue();
58 base::ListValue point_with_offset
;
59 point_with_offset
.AppendInteger(x
);
60 point_with_offset
.AppendInteger(y
);
61 point_with_offset
.AppendInteger(offset
);
62 web_ui()->CallJavascriptFunction("cr.FirstRun.showStep",
63 base::StringValue(name
),
68 void FirstRunHandler::HideCurrentStep() {
69 web_ui()->CallJavascriptFunction("cr.FirstRun.hideCurrentStep");
72 void FirstRunHandler::Finalize() {
73 is_finalizing_
= true;
74 web_ui()->CallJavascriptFunction("cr.FirstRun.finalize");
77 bool FirstRunHandler::IsFinalizing() {
78 return is_finalizing_
;
81 void FirstRunHandler::RegisterMessages() {
82 web_ui()->RegisterMessageCallback("initialized",
83 base::Bind(&FirstRunHandler::HandleInitialized
, base::Unretained(this)));
84 web_ui()->RegisterMessageCallback("nextButtonClicked",
85 base::Bind(&FirstRunHandler::HandleNextButtonClicked
,
86 base::Unretained(this)));
87 web_ui()->RegisterMessageCallback("helpButtonClicked",
88 base::Bind(&FirstRunHandler::HandleHelpButtonClicked
,
89 base::Unretained(this)));
90 web_ui()->RegisterMessageCallback("stepShown",
91 base::Bind(&FirstRunHandler::HandleStepShown
,
92 base::Unretained(this)));
93 web_ui()->RegisterMessageCallback("stepHidden",
94 base::Bind(&FirstRunHandler::HandleStepHidden
,
95 base::Unretained(this)));
96 web_ui()->RegisterMessageCallback("finalized",
97 base::Bind(&FirstRunHandler::HandleFinalized
,
98 base::Unretained(this)));
101 void FirstRunHandler::HandleInitialized(const base::ListValue
* args
) {
102 is_initialized_
= true;
104 delegate()->OnActorInitialized();
107 void FirstRunHandler::HandleNextButtonClicked(const base::ListValue
* args
) {
108 std::string step_name
;
109 CHECK(args
->GetString(0, &step_name
));
111 delegate()->OnNextButtonClicked(step_name
);
114 void FirstRunHandler::HandleHelpButtonClicked(const base::ListValue
* args
) {
116 delegate()->OnHelpButtonClicked();
119 void FirstRunHandler::HandleStepShown(const base::ListValue
* args
) {
120 std::string step_name
;
121 CHECK(args
->GetString(0, &step_name
));
123 delegate()->OnStepShown(step_name
);
126 void FirstRunHandler::HandleStepHidden(const base::ListValue
* args
) {
127 std::string step_name
;
128 CHECK(args
->GetString(0, &step_name
));
130 delegate()->OnStepHidden(step_name
);
133 void FirstRunHandler::HandleFinalized(const base::ListValue
* args
) {
134 is_finalizing_
= false;
136 delegate()->OnActorFinalized();
139 } // namespace chromeos