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

Side by Side Diff: chrome/browser/remoting/setup_flow.cc

Issue 5985003: New remoting setup flow. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: - Created 9 years, 11 months 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/remoting/setup_flow.h ('k') | chrome/browser/remoting/setup_flow_login_step.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2010 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/remoting/setup_flow.h"
6
7 #include "app/gfx/font_util.h"
8 #include "app/l10n_util.h"
9 #include "base/json/json_reader.h"
10 #include "base/json/json_writer.h"
11 #include "base/utf_string_conversions.h"
12 #include "base/values.h"
13 #include "chrome/browser/browser_thread.h"
14 #include "chrome/browser/prefs/pref_service.h"
15 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/browser/remoting/remoting_resources_source.h"
17 #include "chrome/browser/remoting/setup_flow_login_step.h"
18 #include "chrome/browser/renderer_host/render_view_host.h"
19 #include "chrome/browser/tab_contents/tab_contents.h"
20 #include "chrome/browser/ui/browser.h"
21 #include "chrome/browser/ui/browser_list.h"
22 #include "chrome/common/pref_names.h"
23 #include "gfx/font.h"
24 #include "grit/generated_resources.h"
25 #include "grit/locale_settings.h"
26
27 namespace remoting {
28
29 static const wchar_t kDoneIframeXPath[] = L"//iframe[@id='done']";
30
31 SetupFlowStep::SetupFlowStep() { }
32 SetupFlowStep::~SetupFlowStep() { }
33
34 SetupFlowStepBase::SetupFlowStepBase()
35 : flow_(NULL) {
36 }
37
38 SetupFlowStepBase::~SetupFlowStepBase() { }
39
40 void SetupFlowStepBase::Start(SetupFlow* flow, DoneCallback* done_callback) {
41 done_callback_.reset(done_callback);
42 flow_ = flow;
43 DoStart();
44 }
45
46 SetupFlowStep* SetupFlowStepBase::GetNextStep() {
47 DCHECK(done_);
48 return next_step_;
49 }
50
51 void SetupFlowStepBase::ExecuteJavascriptInIFrame(
52 const std::wstring& iframe_xpath, const std::wstring& js) {
53 DOMUI* dom_ui = flow()->dom_ui();
54 DCHECK(dom_ui);
55
56 RenderViewHost* rvh = dom_ui->tab_contents()->render_view_host();
57 rvh->ExecuteJavascriptInWebFrame(iframe_xpath, js);
58 }
59
60 void SetupFlowStepBase::FinishStep(SetupFlowStep* next_step) {
61 next_step_ = next_step;
62 done_ = true;
63 done_callback_->Run();
64 }
65
66 SetupFlowDoneStep::SetupFlowDoneStep() { }
67 SetupFlowDoneStep::~SetupFlowDoneStep() { }
68
69 void SetupFlowDoneStep::HandleMessage(const std::string& message,
70 const ListValue* args) {
71 }
72
73 void SetupFlowDoneStep::Cancel() { }
74
75 void SetupFlowDoneStep::DoStart() {
76 std::wstring javascript = L"setMessage('You are all set!');";
77 ExecuteJavascriptInIFrame(kDoneIframeXPath, javascript);
78
79 flow()->dom_ui()->CallJavascriptFunction(L"showSetupDone");
80
81 ExecuteJavascriptInIFrame(kDoneIframeXPath, L"onPageShown();");
82 }
83
84 SetupFlow::SetupFlow(const std::string& args, Profile* profile,
85 SetupFlowStep* first_step)
86 : dom_ui_(NULL),
87 dialog_start_args_(args),
88 profile_(profile),
89 current_step_(first_step) {
90 // TODO(hclam): The data source should be added once.
91 BrowserThread::PostTask(
92 BrowserThread::IO, FROM_HERE,
93 NewRunnableMethod(ChromeURLDataManager::GetInstance(),
94 &ChromeURLDataManager::AddDataSource,
95 make_scoped_refptr(new RemotingResourcesSource())));
96 }
97
98 SetupFlow::~SetupFlow() { }
99
100 // static
101 SetupFlow* SetupFlow::OpenSetupDialog(Profile* profile) {
102 // Set the arguments for showing the gaia login page.
103 DictionaryValue args;
104 args.SetString("iframeToShow", "login");
105 args.SetString("user", "");
106 args.SetInteger("error", 0);
107 args.SetBoolean("editable_user", true);
108
109 std::string json_args;
110 base::JSONWriter::Write(&args, false, &json_args);
111
112 Browser* b = BrowserList::GetLastActive();
113 if (!b)
114 return NULL;
115
116 SetupFlow *flow = new SetupFlow(json_args, profile, new SetupFlowLoginStep());
117 b->BrowserShowHtmlDialog(flow, NULL);
118 return flow;
119 }
120
121 GURL SetupFlow::GetDialogContentURL() const {
122 return GURL("chrome://remotingresources/setup");
123 }
124
125 void SetupFlow::GetDOMMessageHandlers(
126 std::vector<DOMMessageHandler*>* handlers) const {
127 // The called will be responsible for deleting this object.
128 handlers->push_back(const_cast<SetupFlow*>(this));
129 }
130
131 void SetupFlow::GetDialogSize(gfx::Size* size) const {
132 PrefService* prefs = profile_->GetPrefs();
133 gfx::Font approximate_web_font(
134 UTF8ToWide(prefs->GetString(prefs::kWebKitSansSerifFontFamily)),
135 prefs->GetInteger(prefs::kWebKitDefaultFontSize));
136
137 // TODO(pranavk) Replace the following SYNC resources with REMOTING Resources.
138 *size = gfx::GetLocalizedContentsSizeForFont(
139 IDS_SYNC_SETUP_WIZARD_WIDTH_CHARS,
140 IDS_SYNC_SETUP_WIZARD_HEIGHT_LINES,
141 approximate_web_font);
142 }
143
144 // A callback to notify the delegate that the dialog closed.
145 void SetupFlow::OnDialogClosed(const std::string& json_retval) {
146 if (current_step_ != NULL)
147 current_step_->Cancel();
148 }
149
150 std::string SetupFlow::GetDialogArgs() const {
151 return dialog_start_args_;
152 }
153
154 void SetupFlow::OnCloseContents(TabContents* source,
155 bool* out_close_dialog) {
156 }
157
158 std::wstring SetupFlow::GetDialogTitle() const {
159 return l10n_util::GetString(IDS_REMOTING_SETUP_DIALOG_TITLE);
160 }
161
162 bool SetupFlow::IsDialogModal() const {
163 return false;
164 }
165
166 bool SetupFlow::ShouldShowDialogTitle() const {
167 return true;
168 }
169
170 DOMMessageHandler* SetupFlow::Attach(DOMUI* dom_ui) {
171 dom_ui_ = dom_ui;
172 StartCurrentStep();
173 return DOMMessageHandler::Attach(dom_ui);
174 }
175
176 void SetupFlow::RegisterMessages() {
177 dom_ui_->RegisterMessageCallback("SubmitAuth",
178 NewCallback(this, &SetupFlow::HandleSubmitAuth));
179 }
180
181 void SetupFlow::HandleSubmitAuth(const ListValue* args) {
182 current_step_->HandleMessage("SubmitAuth", args);
183 }
184
185 void SetupFlow::StartCurrentStep() {
186 current_step_->Start(this, NewCallback(this, &SetupFlow::OnStepDone));
187 }
188
189 void SetupFlow::OnStepDone() {
190 current_step_.reset(current_step_->GetNextStep());
191 StartCurrentStep();
192 }
193
194 } // namespace remoting
OLDNEW
« no previous file with comments | « chrome/browser/remoting/setup_flow.h ('k') | chrome/browser/remoting/setup_flow_login_step.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698