Chromium Code Reviews| OLD | NEW |
|---|---|
| (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::Done(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 BrowserThread::PostTask( | |
|
Alpha Left Google
2010/12/21 21:52:04
This should only be done once.
Sergey Ulanov
2010/12/21 22:26:49
All other code I could find that calls AddDataSour
Alpha Left Google
2010/12/24 06:33:07
This is in fact a bug and they shouldn't be adding
Sergey Ulanov
2010/12/28 19:07:53
Done.
| |
| 91 BrowserThread::IO, FROM_HERE, | |
| 92 NewRunnableMethod(ChromeURLDataManager::GetInstance(), | |
| 93 &ChromeURLDataManager::AddDataSource, | |
| 94 make_scoped_refptr(new RemotingResourcesSource()))); | |
| 95 } | |
| 96 | |
| 97 SetupFlow::~SetupFlow() { } | |
| 98 | |
| 99 // static | |
| 100 SetupFlow* SetupFlow::OpenSetupDialog(Profile* profile) { | |
| 101 // Set the arguments for showing the gaia login page. | |
| 102 DictionaryValue args; | |
| 103 args.SetString("iframeToShow", "login"); | |
| 104 args.SetString("user", ""); | |
| 105 args.SetInteger("error", 0); | |
| 106 args.SetBoolean("editable_user", true); | |
| 107 | |
| 108 std::string json_args; | |
| 109 base::JSONWriter::Write(&args, false, &json_args); | |
| 110 | |
| 111 Browser* b = BrowserList::GetLastActive(); | |
| 112 if (!b) | |
| 113 return NULL; | |
| 114 | |
| 115 SetupFlow *flow = new SetupFlow(json_args, profile, new SetupFlowLoginStep()); | |
| 116 b->BrowserShowHtmlDialog(flow, NULL); | |
| 117 return flow; | |
| 118 } | |
| 119 | |
| 120 GURL SetupFlow::GetDialogContentURL() const { | |
| 121 return GURL("chrome://remotingresources/setup"); | |
| 122 } | |
| 123 | |
| 124 void SetupFlow::GetDOMMessageHandlers( | |
| 125 std::vector<DOMMessageHandler*>* handlers) const { | |
| 126 // The called will be responsible for deleting this object. | |
| 127 handlers->push_back(const_cast<SetupFlow*>(this)); | |
|
Alpha Left Google
2010/12/21 21:52:04
Give the list of SetupFlowStep as handlers. This w
Sergey Ulanov
2010/12/21 22:26:49
SetupFlow doesn't know about all steps of the flow
| |
| 128 } | |
| 129 | |
| 130 void SetupFlow::GetDialogSize(gfx::Size* size) const { | |
| 131 PrefService* prefs = profile_->GetPrefs(); | |
| 132 gfx::Font approximate_web_font( | |
| 133 UTF8ToWide(prefs->GetString(prefs::kWebKitSansSerifFontFamily)), | |
| 134 prefs->GetInteger(prefs::kWebKitDefaultFontSize)); | |
| 135 | |
| 136 // TODO(pranavk) Replace the following SYNC resources with REMOTING Resources. | |
| 137 *size = gfx::GetLocalizedContentsSizeForFont( | |
| 138 IDS_SYNC_SETUP_WIZARD_WIDTH_CHARS, | |
| 139 IDS_SYNC_SETUP_WIZARD_HEIGHT_LINES, | |
| 140 approximate_web_font); | |
| 141 } | |
| 142 | |
| 143 // A callback to notify the delegate that the dialog closed. | |
| 144 void SetupFlow::OnDialogClosed(const std::string& json_retval) { | |
| 145 if (current_step_ != NULL) | |
| 146 current_step_->Cancel(); | |
| 147 } | |
| 148 | |
| 149 std::string SetupFlow::GetDialogArgs() const { | |
| 150 return dialog_start_args_; | |
| 151 } | |
| 152 | |
| 153 void SetupFlow::OnCloseContents(TabContents* source, | |
| 154 bool* out_close_dialog) { | |
| 155 } | |
| 156 | |
| 157 std::wstring SetupFlow::GetDialogTitle() const { | |
| 158 return l10n_util::GetString(IDS_REMOTING_SETUP_DIALOG_TITLE); | |
| 159 } | |
| 160 | |
| 161 bool SetupFlow::IsDialogModal() const { | |
| 162 return false; | |
| 163 } | |
| 164 | |
| 165 bool SetupFlow::ShouldShowDialogTitle() const { | |
| 166 return true; | |
| 167 } | |
| 168 | |
| 169 DOMMessageHandler* SetupFlow::Attach(DOMUI* dom_ui) { | |
| 170 dom_ui_ = dom_ui; | |
| 171 StartCurrentStep(); | |
| 172 return DOMMessageHandler::Attach(dom_ui); | |
| 173 } | |
| 174 | |
| 175 void SetupFlow::RegisterMessages() { | |
| 176 dom_ui_->RegisterMessageCallback("SubmitAuth", | |
|
Alpha Left Google
2010/12/21 21:52:04
Should let SetupFlowStep to register their own mes
Sergey Ulanov
2010/12/21 22:26:49
That would be possible if DOMUI allowed unregister
| |
| 177 NewCallback(this, &SetupFlow::HandleSubmitAuth)); | |
| 178 } | |
| 179 | |
| 180 void SetupFlow::HandleSubmitAuth(const ListValue* args) { | |
| 181 current_step_->HandleMessage("SubmitAuth", args); | |
| 182 } | |
| 183 | |
| 184 void SetupFlow::StartCurrentStep() { | |
| 185 current_step_->Start(this, NewCallback(this, &SetupFlow::OnStepDone)); | |
| 186 } | |
| 187 | |
| 188 void SetupFlow::OnStepDone() { | |
| 189 current_step_.reset(current_step_->GetNextStep()); | |
| 190 StartCurrentStep(); | |
| 191 } | |
| 192 | |
| 193 } // namespace remoting | |
| OLD | NEW |