Chromium Code Reviews| 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/ui/webui/chromeos/imageburner/imageburner_ui.h" | 5 #include "chrome/browser/ui/webui/chromeos/imageburner/imageburner_ui.h" |
| 6 #include "chrome/browser/ui/webui/chromeos/imageburner/webui_handler.h" | 6 #include "chrome/browser/ui/webui/chromeos/imageburner/webui_handler.h" |
| 7 | 7 |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
| 10 #include "base/i18n/rtl.h" | 10 #include "base/i18n/rtl.h" |
| 11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
| 12 #include "base/task.h" | 12 #include "base/task.h" |
| 13 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
| 14 #include "base/values.h" | 14 #include "base/values.h" |
| 15 #include "chrome/browser/chromeos/system/statistics_provider.h" | 15 #include "chrome/browser/chromeos/system/statistics_provider.h" |
| 16 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
| 17 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" | |
| 17 #include "chrome/common/jstemplate_builder.h" | 18 #include "chrome/common/jstemplate_builder.h" |
| 18 #include "chrome/common/time_format.h" | 19 #include "chrome/common/time_format.h" |
| 19 #include "chrome/common/url_constants.h" | 20 #include "chrome/common/url_constants.h" |
| 20 #include "content/browser/browser_thread.h" | 21 #include "content/browser/browser_thread.h" |
| 21 #include "grit/browser_resources.h" | 22 #include "grit/browser_resources.h" |
| 22 #include "grit/generated_resources.h" | 23 #include "grit/generated_resources.h" |
| 23 #include "grit/locale_settings.h" | 24 #include "grit/locale_settings.h" |
| 24 #include "ui/base/l10n/l10n_util.h" | 25 #include "ui/base/l10n/l10n_util.h" |
| 25 #include "ui/base/resource/resource_bundle.h" | 26 #include "ui/base/resource/resource_bundle.h" |
| 26 #include "ui/base/text/bytes_formatting.h" | 27 #include "ui/base/text/bytes_formatting.h" |
| 27 | 28 |
| 28 namespace imageburner { | 29 namespace { |
| 29 | 30 |
| 30 static const char kPropertyDevicePath[] = "devicePath"; | 31 static const char kPropertyDevicePath[] = "devicePath"; |
|
Evan Stade
2011/10/11 21:35:23
do not need static for things in unnamed namespace
| |
| 31 static const char kPropertyFilePath[] = "filePath"; | 32 static const char kPropertyFilePath[] = "filePath"; |
| 32 static const char kPropertyLabel[] = "label"; | 33 static const char kPropertyLabel[] = "label"; |
| 33 static const char kPropertyPath[] = "path"; | 34 static const char kPropertyPath[] = "path"; |
| 34 | 35 |
| 35 // Name for hwid in machine statistics. | 36 // Name for hwid in machine statistics. |
| 36 const std::string kHwidStatistic = "hardware_class"; | 37 static const std::string kHwidStatistic = "hardware_class"; |
| 37 | |
| 38 | 38 |
| 39 static const char kImageZipFileName[] = "chromeos_image.bin.zip"; | 39 static const char kImageZipFileName[] = "chromeos_image.bin.zip"; |
| 40 | 40 |
| 41 // 3.9GB. It is less than 4GB because true device size ussually varies a little. | 41 // 3.9GB. It is less than 4GB because true device size ussually varies a little. |
| 42 static const uint64 kMinDeviceSize = | 42 static const uint64 kMinDeviceSize = |
| 43 static_cast<uint64>(3.9) * 1000 * 1000 * 1000; | 43 static_cast<uint64>(3.9) * 1000 * 1000 * 1000; |
| 44 | 44 |
| 45 // Link displayed on imageburner ui. | 45 // Link displayed on imageburner ui. |
| 46 static const std::string kMoreInfoLink = | 46 static const std::string kMoreInfoLink = |
| 47 "http://www.chromium.org/chromium-os/chromiumos-design-docs/recovery-mode"; | 47 "http://www.chromium.org/chromium-os/chromiumos-design-docs/recovery-mode"; |
| 48 | 48 |
| 49 //////////////////////////////////////////////////////////////////////////////// | 49 ChromeWebUIDataSource *CreateImageburnerUIHTMLSource() { |
| 50 // | 50 ChromeWebUIDataSource *source = |
| 51 // UIHTMLSource | 51 new ChromeWebUIDataSource(chrome::kChromeUIImageBurnerHost); |
| 52 // | |
| 53 //////////////////////////////////////////////////////////////////////////////// | |
| 54 | 52 |
| 55 class UIHTMLSource : public ChromeURLDataManager::DataSource { | 53 source->AddLocalizedString("headerTitle", IDS_IMAGEBURN_HEADER_TITLE); |
| 56 public: | 54 source->AddLocalizedString("headerDescription", |
| 57 UIHTMLSource() | 55 IDS_IMAGEBURN_HEADER_DESCRIPTION); |
| 58 : DataSource(chrome::kChromeUIImageBurnerHost, MessageLoop::current()) { | 56 source->AddLocalizedString("headerLink", IDS_IMAGEBURN_HEADER_LINK); |
| 59 } | 57 source->AddLocalizedString("statusDevicesNone", |
| 58 IDS_IMAGEBURN_NO_DEVICES_STATUS); | |
| 59 source->AddLocalizedString("warningDevicesNone", | |
| 60 IDS_IMAGEBURN_NO_DEVICES_WARNING); | |
| 61 source->AddLocalizedString("statusDevicesMultiple", | |
| 62 IDS_IMAGEBURN_MUL_DEVICES_STATUS); | |
| 63 source->AddLocalizedString("statusDeviceUSB", | |
| 64 IDS_IMAGEBURN_USB_DEVICE_STATUS); | |
| 65 source->AddLocalizedString("statusDeviceSD", | |
| 66 IDS_IMAGEBURN_SD_DEVICE_STATUS); | |
| 67 source->AddLocalizedString("warningDevices", | |
| 68 IDS_IMAGEBURN_DEVICES_WARNING); | |
| 69 source->AddLocalizedString("statusNoConnection", | |
| 70 IDS_IMAGEBURN_NO_CONNECTION_STATUS); | |
| 71 source->AddLocalizedString("warningNoConnection", | |
| 72 IDS_IMAGEBURN_NO_CONNECTION_WARNING); | |
| 73 source->AddLocalizedString("statusNoSpace", | |
| 74 IDS_IMAGEBURN_INSUFFICIENT_SPACE_STATUS); | |
| 75 source->AddLocalizedString("warningNoSpace", | |
| 76 IDS_IMAGEBURN_INSUFFICIENT_SPACE_WARNING); | |
| 77 source->AddLocalizedString("statusDownloading", | |
| 78 IDS_IMAGEBURN_DOWNLOADING_STATUS); | |
| 79 source->AddLocalizedString("statusUnzip", IDS_IMAGEBURN_UNZIP_STATUS); | |
| 80 source->AddLocalizedString("statusBurn", IDS_IMAGEBURN_BURN_STATUS); | |
| 81 source->AddLocalizedString("statusError", IDS_IMAGEBURN_ERROR_STATUS); | |
| 82 source->AddLocalizedString("statusSuccess", IDS_IMAGEBURN_SUCCESS_STATUS); | |
| 83 source->AddLocalizedString("warningSuccess", IDS_IMAGEBURN_SUCCESS_DESC); | |
| 84 source->AddLocalizedString("title", IDS_IMAGEBURN_PAGE_TITLE); | |
| 85 source->AddLocalizedString("confirmButton", IDS_IMAGEBURN_CONFIRM_BUTTON); | |
| 86 source->AddLocalizedString("cancelButton", IDS_IMAGEBURN_CANCEL_BUTTON); | |
| 87 source->AddLocalizedString("retryButton", IDS_IMAGEBURN_RETRY_BUTTON); | |
| 88 source->AddString("moreInfoLink", ASCIIToUTF16(kMoreInfoLink)); | |
| 60 | 89 |
| 61 // Called when the network layer has requested a resource underneath | 90 source->set_json_path("strings.js"); |
| 62 // the path we registered. | 91 source->add_resource_path("image_burner.js", IDR_IMAGEBURNER_JS); |
| 63 virtual void StartDataRequest(const std::string& path, | 92 source->set_default_resource(IDR_IMAGEBURNER_HTML); |
| 64 bool is_incognito, | 93 return source; |
| 65 int request_id) { | 94 } |
| 66 DictionaryValue localized_strings; | |
| 67 localized_strings.SetString("headerTitle", | |
| 68 l10n_util::GetStringUTF16(IDS_IMAGEBURN_HEADER_TITLE)); | |
| 69 localized_strings.SetString("headerDescription", | |
| 70 l10n_util::GetStringUTF16(IDS_IMAGEBURN_HEADER_DESCRIPTION)); | |
| 71 localized_strings.SetString("headerLink", | |
| 72 l10n_util::GetStringUTF16(IDS_IMAGEBURN_HEADER_LINK)); | |
| 73 localized_strings.SetString("statusDevicesNone", | |
| 74 l10n_util::GetStringUTF16(IDS_IMAGEBURN_NO_DEVICES_STATUS)); | |
| 75 localized_strings.SetString("warningDevicesNone", | |
| 76 l10n_util::GetStringUTF16(IDS_IMAGEBURN_NO_DEVICES_WARNING)); | |
| 77 localized_strings.SetString("statusDevicesMultiple", | |
| 78 l10n_util::GetStringUTF16(IDS_IMAGEBURN_MUL_DEVICES_STATUS)); | |
| 79 localized_strings.SetString("statusDeviceUSB", | |
| 80 l10n_util::GetStringUTF16(IDS_IMAGEBURN_USB_DEVICE_STATUS)); | |
| 81 localized_strings.SetString("statusDeviceSD", | |
| 82 l10n_util::GetStringUTF16(IDS_IMAGEBURN_SD_DEVICE_STATUS)); | |
| 83 localized_strings.SetString("warningDevices", | |
| 84 l10n_util::GetStringUTF16(IDS_IMAGEBURN_DEVICES_WARNING)); | |
| 85 localized_strings.SetString("statusNoConnection", | |
| 86 l10n_util::GetStringUTF16(IDS_IMAGEBURN_NO_CONNECTION_STATUS)); | |
| 87 localized_strings.SetString("warningNoConnection", | |
| 88 l10n_util::GetStringUTF16(IDS_IMAGEBURN_NO_CONNECTION_WARNING)); | |
| 89 localized_strings.SetString("statusNoSpace", | |
| 90 l10n_util::GetStringUTF16(IDS_IMAGEBURN_INSUFFICIENT_SPACE_STATUS)); | |
| 91 localized_strings.SetString("warningNoSpace", | |
| 92 l10n_util::GetStringUTF16(IDS_IMAGEBURN_INSUFFICIENT_SPACE_WARNING)); | |
| 93 localized_strings.SetString("statusDownloading", | |
| 94 l10n_util::GetStringUTF16(IDS_IMAGEBURN_DOWNLOADING_STATUS)); | |
| 95 localized_strings.SetString("statusUnzip", | |
| 96 l10n_util::GetStringUTF16(IDS_IMAGEBURN_UNZIP_STATUS)); | |
| 97 localized_strings.SetString("statusBurn", | |
| 98 l10n_util::GetStringUTF16(IDS_IMAGEBURN_BURN_STATUS)); | |
| 99 localized_strings.SetString("statusError", | |
| 100 l10n_util::GetStringUTF16(IDS_IMAGEBURN_ERROR_STATUS)); | |
| 101 localized_strings.SetString("statusSuccess", | |
| 102 l10n_util::GetStringUTF16(IDS_IMAGEBURN_SUCCESS_STATUS)); | |
| 103 localized_strings.SetString("warningSuccess", | |
| 104 l10n_util::GetStringUTF16(IDS_IMAGEBURN_SUCCESS_DESC)); | |
| 105 localized_strings.SetString("title", | |
| 106 l10n_util::GetStringUTF16(IDS_IMAGEBURN_PAGE_TITLE)); | |
| 107 localized_strings.SetString("confirmButton", | |
| 108 l10n_util::GetStringUTF16(IDS_IMAGEBURN_CONFIRM_BUTTON)); | |
| 109 localized_strings.SetString("cancelButton", | |
| 110 l10n_util::GetStringUTF16(IDS_IMAGEBURN_CANCEL_BUTTON)); | |
| 111 localized_strings.SetString("retryButton", | |
| 112 l10n_util::GetStringUTF16(IDS_IMAGEBURN_RETRY_BUTTON)); | |
| 113 | 95 |
| 114 localized_strings.SetString("moreInfoLink", kMoreInfoLink); | 96 } // namespace |
| 115 | 97 |
| 116 SetFontAndTextDirection(&localized_strings); | 98 namespace imageburner { |
| 117 | |
| 118 static const base::StringPiece imageburn_html( | |
| 119 ResourceBundle::GetSharedInstance().GetRawDataResource( | |
| 120 IDR_IMAGEBURNER_HTML)); | |
| 121 std::string full_html = jstemplate_builder::GetTemplatesHtml( | |
| 122 imageburn_html, &localized_strings, "more-info-link"); | |
| 123 | |
| 124 SendResponse(request_id, base::RefCountedString::TakeString(&full_html)); | |
| 125 } | |
| 126 | |
| 127 virtual std::string GetMimeType(const std::string&) const { | |
| 128 return "text/html"; | |
| 129 } | |
| 130 | |
| 131 private: | |
| 132 virtual ~UIHTMLSource() {} | |
| 133 | |
| 134 DISALLOW_COPY_AND_ASSIGN(UIHTMLSource); | |
| 135 }; | |
| 136 | 99 |
| 137 //////////////////////////////////////////////////////////////////////////////// | 100 //////////////////////////////////////////////////////////////////////////////// |
| 138 // | 101 // |
| 139 // WebUIHandlerTaskProxy | 102 // WebUIHandlerTaskProxy |
| 140 // | 103 // |
| 141 //////////////////////////////////////////////////////////////////////////////// | 104 //////////////////////////////////////////////////////////////////////////////// |
| 142 | 105 |
| 143 WebUIHandlerTaskProxy::WebUIHandlerTaskProxy(Delegate* delegate) { | 106 WebUIHandlerTaskProxy::WebUIHandlerTaskProxy(Delegate* delegate) { |
| 144 delegate_ = delegate->AsWeakPtr(); | 107 delegate_ = delegate->AsWeakPtr(); |
| 145 delegate_->DetachFromThread(); | 108 delegate_->DetachFromThread(); |
| (...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 663 | 626 |
| 664 //////////////////////////////////////////////////////////////////////////////// | 627 //////////////////////////////////////////////////////////////////////////////// |
| 665 // | 628 // |
| 666 // ImageBurnUI | 629 // ImageBurnUI |
| 667 // | 630 // |
| 668 //////////////////////////////////////////////////////////////////////////////// | 631 //////////////////////////////////////////////////////////////////////////////// |
| 669 | 632 |
| 670 ImageBurnUI::ImageBurnUI(TabContents* contents) : ChromeWebUI(contents) { | 633 ImageBurnUI::ImageBurnUI(TabContents* contents) : ChromeWebUI(contents) { |
| 671 imageburner::WebUIHandler* handler = new imageburner::WebUIHandler(contents); | 634 imageburner::WebUIHandler* handler = new imageburner::WebUIHandler(contents); |
| 672 AddMessageHandler((handler)->Attach(this)); | 635 AddMessageHandler((handler)->Attach(this)); |
| 673 imageburner::UIHTMLSource* html_source = new imageburner::UIHTMLSource(); | 636 |
| 674 Profile* profile = Profile::FromBrowserContext(contents->browser_context()); | 637 Profile* profile = Profile::FromBrowserContext(contents->browser_context()); |
| 675 profile->GetChromeURLDataManager()->AddDataSource(html_source); | 638 profile->GetChromeURLDataManager()->AddDataSource( |
| 639 CreateImageburnerUIHTMLSource()); | |
| 676 } | 640 } |
| OLD | NEW |