summaryrefslogtreecommitdiff
path: root/chromium/chrome/browser/ui/webui/about_ui.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/chrome/browser/ui/webui/about_ui.cc')
-rw-r--r--chromium/chrome/browser/ui/webui/about_ui.cc76
1 files changed, 75 insertions, 1 deletions
diff --git a/chromium/chrome/browser/ui/webui/about_ui.cc b/chromium/chrome/browser/ui/webui/about_ui.cc
index 9ca0978f164..6153c0f51c9 100644
--- a/chromium/chrome/browser/ui/webui/about_ui.cc
+++ b/chromium/chrome/browser/ui/webui/about_ui.cc
@@ -259,6 +259,75 @@ class ChromeOSCreditsHandler
DISALLOW_COPY_AND_ASSIGN(ChromeOSCreditsHandler);
};
+
+class LinuxCreditsHandler
+ : public base::RefCountedThreadSafe<LinuxCreditsHandler> {
+ public:
+ static void Start(const std::string& path,
+ const content::URLDataSource::GotDataCallback& callback) {
+ scoped_refptr<LinuxCreditsHandler> handler(
+ new LinuxCreditsHandler(path, callback));
+ handler->StartOnUIThread();
+ }
+
+ private:
+ friend class base::RefCountedThreadSafe<LinuxCreditsHandler>;
+
+ LinuxCreditsHandler(const std::string& path,
+ const content::URLDataSource::GotDataCallback& callback)
+ : path_(path), callback_(callback) {}
+
+ virtual ~LinuxCreditsHandler() {}
+
+ void StartOnUIThread() {
+ DCHECK_CURRENTLY_ON(BrowserThread::UI);
+ if (path_ == kKeyboardUtilsPath) {
+ contents_ = ui::ResourceBundle::GetSharedInstance()
+ .GetRawDataResource(IDR_KEYBOARD_UTILS_JS)
+ .as_string();
+ ResponseOnUIThread();
+ return;
+ }
+ // Load local Linux credits from the disk.
+ base::PostTaskWithTraitsAndReply(
+ FROM_HERE, {base::MayBlock(), base::TaskPriority::BEST_EFFORT},
+ base::Bind(&LinuxCreditsHandler::LoadLinuxCreditsFileAsync, this),
+ base::Bind(&LinuxCreditsHandler::ResponseOnUIThread, this));
+ }
+
+ void LoadLinuxCreditsFileAsync() {
+ base::FilePath credits_file_path(chrome::kLinuxCreditsPath);
+ if (!base::ReadFileToString(credits_file_path, &contents_)) {
+ // File with credits not found, ResponseOnUIThread will load credits
+ // from resources if contents_ is empty.
+ contents_.clear();
+ }
+ }
+
+ void ResponseOnUIThread() {
+ DCHECK_CURRENTLY_ON(BrowserThread::UI);
+ // If we fail to load Linux credits from disk, load the placeholder from
+ // resources.
+ // TODO(rjwright): Add a linux-specific placeholder in resources.
+ if (contents_.empty() && path_ != kKeyboardUtilsPath) {
+ contents_ = ui::ResourceBundle::GetSharedInstance()
+ .GetRawDataResource(IDR_OS_CREDITS_HTML)
+ .as_string();
+ }
+ callback_.Run(base::RefCountedString::TakeString(&contents_));
+ }
+
+ // Path in the URL.
+ const std::string path_;
+
+ // Callback to run with the response.
+ content::URLDataSource::GotDataCallback callback_;
+
+ // Linux credits contents that was loaded from file.
+ std::string contents_;
+
+ DISALLOW_COPY_AND_ASSIGN(LinuxCreditsHandler);
+};
#endif
} // namespace
@@ -385,6 +454,9 @@ void AboutUIHTMLSource::StartDataRequest(
} else if (source_name_ == chrome::kChromeUIOSCreditsHost) {
ChromeOSCreditsHandler::Start(path, callback);
return;
+ } else if (source_name_ == chrome::kChromeUILinuxCreditsHost) {
+ LinuxCreditsHandler::Start(path, callback);
+ return;
#endif
#if !defined(OS_ANDROID)
} else if (source_name_ == chrome::kChromeUITermsHost) {
@@ -421,8 +493,10 @@ std::string AboutUIHTMLSource::GetMimeType(const std::string& path) const {
bool AboutUIHTMLSource::ShouldAddContentSecurityPolicy() const {
#if defined(OS_CHROMEOS)
- if (source_name_ == chrome::kChromeUIOSCreditsHost)
+ if (source_name_ == chrome::kChromeUIOSCreditsHost ||
+ source_name_ == chrome::kChromeUILinuxCreditsHost) {
return false;
+ }
#endif
return content::URLDataSource::ShouldAddContentSecurityPolicy();
}