Upstream version 11.40.277.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / webui / chromeos / first_run / first_run_handler.cc
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.
4
5 #include "chrome/browser/ui/webui/chromeos/first_run/first_run_handler.h"
6
7 #include "base/bind.h"
8 #include "base/values.h"
9 #include "content/public/browser/web_ui.h"
10
11 namespace chromeos {
12
13 FirstRunHandler::FirstRunHandler()
14     : is_initialized_(false),
15       is_finalizing_(false) {
16 }
17
18 bool FirstRunHandler::IsInitialized() {
19   return is_initialized_;
20 }
21
22 void FirstRunHandler::SetBackgroundVisible(bool visible) {
23   web_ui()->CallJavascriptFunction("cr.FirstRun.setBackgroundVisible",
24                                    base::FundamentalValue(visible));
25 }
26
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));
33 }
34
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));
40 }
41
42 void FirstRunHandler::RemoveBackgroundHoles() {
43   web_ui()->CallJavascriptFunction("cr.FirstRun.removeHoles");
44 }
45
46 void FirstRunHandler::ShowStepPositioned(const std::string& name,
47                                          const StepPosition& position) {
48   web_ui()->CallJavascriptFunction("cr.FirstRun.showStep",
49                                    base::StringValue(name),
50                                    *position.AsValue());
51 }
52
53 void FirstRunHandler::ShowStepPointingTo(const std::string& name,
54                                          int x,
55                                          int y,
56                                          int offset) {
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),
64                                    *null,
65                                    point_with_offset);
66 }
67
68 void FirstRunHandler::HideCurrentStep() {
69   web_ui()->CallJavascriptFunction("cr.FirstRun.hideCurrentStep");
70 }
71
72 void FirstRunHandler::Finalize() {
73   is_finalizing_ = true;
74   web_ui()->CallJavascriptFunction("cr.FirstRun.finalize");
75 }
76
77 bool FirstRunHandler::IsFinalizing() {
78   return is_finalizing_;
79 }
80
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)));
99 }
100
101 void FirstRunHandler::HandleInitialized(const base::ListValue* args) {
102   is_initialized_ = true;
103   if (delegate())
104     delegate()->OnActorInitialized();
105 }
106
107 void FirstRunHandler::HandleNextButtonClicked(const base::ListValue* args) {
108   std::string step_name;
109   CHECK(args->GetString(0, &step_name));
110   if (delegate())
111     delegate()->OnNextButtonClicked(step_name);
112 }
113
114 void FirstRunHandler::HandleHelpButtonClicked(const base::ListValue* args) {
115   if (delegate())
116     delegate()->OnHelpButtonClicked();
117 }
118
119 void FirstRunHandler::HandleStepShown(const base::ListValue* args) {
120   std::string step_name;
121   CHECK(args->GetString(0, &step_name));
122   if (delegate())
123     delegate()->OnStepShown(step_name);
124 }
125
126 void FirstRunHandler::HandleStepHidden(const base::ListValue* args) {
127   std::string step_name;
128   CHECK(args->GetString(0, &step_name));
129   if (delegate())
130     delegate()->OnStepHidden(step_name);
131 }
132
133 void FirstRunHandler::HandleFinalized(const base::ListValue* args) {
134   is_finalizing_ = false;
135   if (delegate())
136     delegate()->OnActorFinalized();
137 }
138
139 }  // namespace chromeos