| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/printing/cloud_print/cloud_print_setup_flow.h" | 5 #include "chrome/browser/printing/cloud_print/cloud_print_setup_flow.h" |
| 6 | 6 |
| 7 #include "app/gfx/font_util.h" | |
| 8 #include "base/json/json_writer.h" | 7 #include "base/json/json_writer.h" |
| 9 #include "base/singleton.h" | 8 #include "base/singleton.h" |
| 10 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 11 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| 12 #include "base/values.h" | 11 #include "base/values.h" |
| 13 #include "chrome/browser/browser_list.h" | 12 #include "chrome/browser/browser_list.h" |
| 14 #include "chrome/browser/browser_thread.h" | 13 #include "chrome/browser/browser_thread.h" |
| 15 #include "chrome/browser/dom_ui/chrome_url_data_manager.h" | 14 #include "chrome/browser/dom_ui/chrome_url_data_manager.h" |
| 16 #include "chrome/browser/dom_ui/dom_ui_util.h" | 15 #include "chrome/browser/dom_ui/dom_ui_util.h" |
| 17 #if defined(TOOLKIT_GTK) | |
| 18 #include "chrome/browser/gtk/html_dialog_gtk.h" | |
| 19 #endif // defined(TOOLKIT_GTK) | |
| 20 #include "chrome/browser/platform_util.h" | 16 #include "chrome/browser/platform_util.h" |
| 21 #include "chrome/browser/prefs/pref_service.h" | 17 #include "chrome/browser/prefs/pref_service.h" |
| 22 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service.h" | 18 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service.h" |
| 23 #include "chrome/browser/printing/cloud_print/cloud_print_setup_message_handler.
h" | 19 #include "chrome/browser/printing/cloud_print/cloud_print_setup_message_handler.
h" |
| 24 #include "chrome/browser/printing/cloud_print/cloud_print_setup_source.h" | 20 #include "chrome/browser/printing/cloud_print/cloud_print_setup_source.h" |
| 25 #include "chrome/browser/printing/cloud_print/cloud_print_url.h" | 21 #include "chrome/browser/printing/cloud_print/cloud_print_url.h" |
| 26 #include "chrome/browser/profiles/profile.h" | 22 #include "chrome/browser/profiles/profile.h" |
| 27 #include "chrome/browser/renderer_host/render_view_host.h" | 23 #include "chrome/browser/renderer_host/render_view_host.h" |
| 28 #include "chrome/browser/service/service_process_control.h" | 24 #include "chrome/browser/service/service_process_control.h" |
| 29 #include "chrome/browser/service/service_process_control_manager.h" | 25 #include "chrome/browser/service/service_process_control_manager.h" |
| 30 #include "chrome/browser/tab_contents/tab_contents.h" | 26 #include "chrome/browser/tab_contents/tab_contents.h" |
| 31 #include "chrome/browser/ui/browser.h" | 27 #include "chrome/browser/ui/browser.h" |
| 32 #include "chrome/browser/ui/browser_window.h" | 28 #include "chrome/browser/ui/browser_window.h" |
| 33 #if defined(TOOLKIT_VIEWS) | |
| 34 #include "chrome/browser/ui/views/browser_dialogs.h" | |
| 35 #endif // defined(TOOLKIT_GTK) | |
| 36 #include "chrome/common/net/gaia/gaia_auth_fetcher.h" | 29 #include "chrome/common/net/gaia/gaia_auth_fetcher.h" |
| 37 #include "chrome/common/net/gaia/gaia_constants.h" | 30 #include "chrome/common/net/gaia/gaia_constants.h" |
| 38 #include "chrome/common/net/gaia/google_service_auth_error.h" | 31 #include "chrome/common/net/gaia/google_service_auth_error.h" |
| 39 #include "chrome/common/pref_names.h" | 32 #include "chrome/common/pref_names.h" |
| 40 #include "chrome/common/service_messages.h" | 33 #include "chrome/common/service_messages.h" |
| 41 #include "gfx/font.h" | 34 #include "gfx/font.h" |
| 42 | |
| 43 #include "grit/chromium_strings.h" | 35 #include "grit/chromium_strings.h" |
| 44 #include "grit/locale_settings.h" | 36 #include "grit/locale_settings.h" |
| 37 #include "ui/base/l10n/l10n_font_util.h" |
| 38 |
| 39 #if defined(TOOLKIT_GTK) |
| 40 #include "chrome/browser/gtk/html_dialog_gtk.h" |
| 41 #endif // defined(TOOLKIT_GTK) |
| 42 |
| 43 #if defined(TOOLKIT_VIEWS) |
| 44 #include "chrome/browser/ui/views/browser_dialogs.h" |
| 45 #endif // defined(TOOLKIT_GTK) |
| 45 | 46 |
| 46 static const wchar_t kGaiaLoginIFrameXPath[] = L"//iframe[@id='gaialogin']"; | 47 static const wchar_t kGaiaLoginIFrameXPath[] = L"//iframe[@id='gaialogin']"; |
| 47 static const wchar_t kDoneIframeXPath[] = L"//iframe[@id='setupdone']"; | 48 static const wchar_t kDoneIframeXPath[] = L"//iframe[@id='setupdone']"; |
| 48 | 49 |
| 49 //////////////////////////////////////////////////////////////////////////////// | 50 //////////////////////////////////////////////////////////////////////////////// |
| 50 // CloudPrintSetupFlow implementation. | 51 // CloudPrintSetupFlow implementation. |
| 51 | 52 |
| 52 // static | 53 // static |
| 53 CloudPrintSetupFlow* CloudPrintSetupFlow::OpenDialog( | 54 CloudPrintSetupFlow* CloudPrintSetupFlow::OpenDialog( |
| 54 Profile* profile, Delegate* delegate, gfx::NativeWindow parent_window) { | 55 Profile* profile, Delegate* delegate, gfx::NativeWindow parent_window) { |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 const_cast<CloudPrintSetupFlow*>(this))); | 131 const_cast<CloudPrintSetupFlow*>(this))); |
| 131 } | 132 } |
| 132 | 133 |
| 133 void CloudPrintSetupFlow::GetDialogSize(gfx::Size* size) const { | 134 void CloudPrintSetupFlow::GetDialogSize(gfx::Size* size) const { |
| 134 PrefService* prefs = profile_->GetPrefs(); | 135 PrefService* prefs = profile_->GetPrefs(); |
| 135 gfx::Font approximate_web_font( | 136 gfx::Font approximate_web_font( |
| 136 UTF8ToUTF16(prefs->GetString(prefs::kWebKitSansSerifFontFamily)), | 137 UTF8ToUTF16(prefs->GetString(prefs::kWebKitSansSerifFontFamily)), |
| 137 prefs->GetInteger(prefs::kWebKitDefaultFontSize)); | 138 prefs->GetInteger(prefs::kWebKitDefaultFontSize)); |
| 138 | 139 |
| 139 if (setup_done_) { | 140 if (setup_done_) { |
| 140 *size = gfx::GetLocalizedContentsSizeForFont( | 141 *size = ui::GetLocalizedContentsSizeForFont( |
| 141 IDS_CLOUD_PRINT_SETUP_WIZARD_DONE_WIDTH_CHARS, | 142 IDS_CLOUD_PRINT_SETUP_WIZARD_DONE_WIDTH_CHARS, |
| 142 IDS_CLOUD_PRINT_SETUP_WIZARD_DONE_HEIGHT_LINES, | 143 IDS_CLOUD_PRINT_SETUP_WIZARD_DONE_HEIGHT_LINES, |
| 143 approximate_web_font); | 144 approximate_web_font); |
| 144 } else { | 145 } else { |
| 145 *size = gfx::GetLocalizedContentsSizeForFont( | 146 *size = ui::GetLocalizedContentsSizeForFont( |
| 146 IDS_CLOUD_PRINT_SETUP_WIZARD_WIDTH_CHARS, | 147 IDS_CLOUD_PRINT_SETUP_WIZARD_WIDTH_CHARS, |
| 147 IDS_CLOUD_PRINT_SETUP_WIZARD_HEIGHT_LINES, | 148 IDS_CLOUD_PRINT_SETUP_WIZARD_HEIGHT_LINES, |
| 148 approximate_web_font); | 149 approximate_web_font); |
| 149 } | 150 } |
| 150 } | 151 } |
| 151 | 152 |
| 152 // A callback to notify the delegate that the dialog closed. | 153 // A callback to notify the delegate that the dialog closed. |
| 153 void CloudPrintSetupFlow::OnDialogClosed(const std::string& json_retval) { | 154 void CloudPrintSetupFlow::OnDialogClosed(const std::string& json_retval) { |
| 154 // If we are fetching the token then cancel the request. | 155 // If we are fetching the token then cancel the request. |
| 155 if (authenticator_.get()) | 156 if (authenticator_.get()) |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 product_name, | 278 product_name, |
| 278 UTF8ToUTF16(login_))); | 279 UTF8ToUTF16(login_))); |
| 279 std::wstring javascript = L"cloudprint.setMessage('" + message + L"');"; | 280 std::wstring javascript = L"cloudprint.setMessage('" + message + L"');"; |
| 280 ExecuteJavascriptInIFrame(kDoneIframeXPath, javascript); | 281 ExecuteJavascriptInIFrame(kDoneIframeXPath, javascript); |
| 281 | 282 |
| 282 if (dom_ui_) { | 283 if (dom_ui_) { |
| 283 PrefService* prefs = profile_->GetPrefs(); | 284 PrefService* prefs = profile_->GetPrefs(); |
| 284 gfx::Font approximate_web_font( | 285 gfx::Font approximate_web_font( |
| 285 UTF8ToUTF16(prefs->GetString(prefs::kWebKitSansSerifFontFamily)), | 286 UTF8ToUTF16(prefs->GetString(prefs::kWebKitSansSerifFontFamily)), |
| 286 prefs->GetInteger(prefs::kWebKitDefaultFontSize)); | 287 prefs->GetInteger(prefs::kWebKitDefaultFontSize)); |
| 287 gfx::Size done_size = gfx::GetLocalizedContentsSizeForFont( | 288 gfx::Size done_size = ui::GetLocalizedContentsSizeForFont( |
| 288 IDS_CLOUD_PRINT_SETUP_WIZARD_DONE_WIDTH_CHARS, | 289 IDS_CLOUD_PRINT_SETUP_WIZARD_DONE_WIDTH_CHARS, |
| 289 IDS_CLOUD_PRINT_SETUP_WIZARD_DONE_HEIGHT_LINES, | 290 IDS_CLOUD_PRINT_SETUP_WIZARD_DONE_HEIGHT_LINES, |
| 290 approximate_web_font); | 291 approximate_web_font); |
| 291 | 292 |
| 292 FundamentalValue new_width(done_size.width()); | 293 FundamentalValue new_width(done_size.width()); |
| 293 FundamentalValue new_height(done_size.height()); | 294 FundamentalValue new_height(done_size.height()); |
| 294 dom_ui_->CallJavascriptFunction(L"cloudprint.showSetupDone", | 295 dom_ui_->CallJavascriptFunction(L"cloudprint.showSetupDone", |
| 295 new_width, new_height); | 296 new_width, new_height); |
| 296 } | 297 } |
| 297 | 298 |
| 298 ExecuteJavascriptInIFrame(kDoneIframeXPath, L"cloudprint.onPageShown();"); | 299 ExecuteJavascriptInIFrame(kDoneIframeXPath, L"cloudprint.onPageShown();"); |
| 299 } | 300 } |
| 300 | 301 |
| 301 void CloudPrintSetupFlow::ExecuteJavascriptInIFrame( | 302 void CloudPrintSetupFlow::ExecuteJavascriptInIFrame( |
| 302 const std::wstring& iframe_xpath, | 303 const std::wstring& iframe_xpath, |
| 303 const std::wstring& js) { | 304 const std::wstring& js) { |
| 304 if (dom_ui_) { | 305 if (dom_ui_) { |
| 305 RenderViewHost* rvh = dom_ui_->tab_contents()->render_view_host(); | 306 RenderViewHost* rvh = dom_ui_->tab_contents()->render_view_host(); |
| 306 rvh->ExecuteJavascriptInWebFrame(iframe_xpath, js); | 307 rvh->ExecuteJavascriptInWebFrame(iframe_xpath, js); |
| 307 } | 308 } |
| 308 } | 309 } |
| OLD | NEW |