- add sources.
[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 }
16
17 bool FirstRunHandler::IsInitialized() {
18   return is_initialized_;
19 }
20
21 void FirstRunHandler::AddBackgroundHole(int x, int y, int width, int height) {
22   web_ui()->CallJavascriptFunction("cr.FirstRun.addHole",
23                                    base::FundamentalValue(x),
24                                    base::FundamentalValue(y),
25                                    base::FundamentalValue(width),
26                                    base::FundamentalValue(height));
27 }
28
29 void FirstRunHandler::RemoveBackgroundHoles() {
30   web_ui()->CallJavascriptFunction("cr.FirstRun.removeHoles");
31 }
32
33 void FirstRunHandler::ShowStep(const std::string& name,
34                                const StepPosition& position) {
35   web_ui()->CallJavascriptFunction("cr.FirstRun.showStep",
36                                    base::StringValue(name),
37                                    *position.AsValue());
38 }
39
40 void FirstRunHandler::RegisterMessages() {
41   web_ui()->RegisterMessageCallback("initialized",
42       base::Bind(&FirstRunHandler::HandleInitialized, base::Unretained(this)));
43   web_ui()->RegisterMessageCallback("nextButtonClicked",
44       base::Bind(&FirstRunHandler::HandleNextButtonClicked,
45                  base::Unretained(this)));
46 }
47
48 void FirstRunHandler::HandleInitialized(const base::ListValue* args) {
49   is_initialized_ = true;
50   if (delegate())
51     delegate()->OnActorInitialized();
52 }
53
54 void FirstRunHandler::HandleNextButtonClicked(const base::ListValue* args) {
55   std::string step_name;
56   CHECK(args->GetString(0, &step_name));
57   if (delegate())
58     delegate()->OnNextButtonClicked(step_name);
59 }
60
61 }  // namespace chromeos
62