Index: chrome/browser/ui/webui/app_list/start_page_ui.cc |
diff --git a/chrome/browser/ui/webui/app_list/start_page_ui.cc b/chrome/browser/ui/webui/app_list/start_page_ui.cc |
index 5a88ec33e6096f0672da613912d60e5e1a4e38c2..018fafd74f39b7792054ca96bcab4fc3b6d4797c 100644 |
--- a/chrome/browser/ui/webui/app_list/start_page_ui.cc |
+++ b/chrome/browser/ui/webui/app_list/start_page_ui.cc |
@@ -4,15 +4,66 @@ |
#include "chrome/browser/ui/webui/app_list/start_page_ui.h" |
+#include "base/file_util.h" |
+#include "base/files/file_path.h" |
+#include "base/memory/ref_counted_memory.h" |
#include "base/memory/scoped_ptr.h" |
+#include "base/sys_info.h" |
#include "chrome/browser/profiles/profile.h" |
#include "chrome/browser/ui/webui/app_list/start_page_handler.h" |
#include "chrome/common/url_constants.h" |
+#include "content/public/browser/browser_thread.h" |
#include "content/public/browser/web_ui.h" |
#include "content/public/browser/web_ui_data_source.h" |
#include "grit/browser_resources.h" |
namespace app_list { |
+namespace { |
+#if defined(OS_CHROMEOS) |
+const char* kHotwordFilenames[] = { |
+ "dnn", |
+ "ep_acoustic_model", |
+ "hclg_shotword", |
+ "hotword_arm.nexe", |
+ "hotword_classifier", |
+ "hotword_normalizer", |
+ "hotword_word_symbols", |
+ "hotword_x86_32.nexe", |
+ "hotword_x86_64.nexe", |
+ "okgoogle_hotword.config", |
+ "phonelist", |
+ "phone_state_map", |
+}; |
+ |
+const char kHotwordFilesDir[] = "/opt/google/hotword"; |
+ |
+void LoadModelData(const std::string& path, |
+ const content::WebUIDataSource::GotDataCallback& callback) { |
+ DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); |
+ // Will be owned by |callback|. |
+ scoped_refptr<base::RefCountedString> data(new base::RefCountedString()); |
+ base::FilePath base_dir(kHotwordFilesDir); |
+ base::ReadFileToString(base_dir.AppendASCII(path), &(data->data())); |
+ callback.Run(data.get()); |
+} |
+ |
+bool HandleHotwordFilesResourceFilter( |
+ const std::string& path, |
+ const content::WebUIDataSource::GotDataCallback& callback) { |
+ for (size_t i = 0; i < arraysize(kHotwordFilenames); ++i) { |
+ if (path == kHotwordFilenames[i]) { |
+ content::BrowserThread::PostTask( |
+ content::BrowserThread::FILE, |
+ FROM_HERE, |
+ base::Bind(&LoadModelData, path, callback)); |
+ return true; |
+ } |
+ } |
+ |
+ return false; |
+} |
+#endif // OS_CHROMEOS |
+} // namespace |
StartPageUI::StartPageUI(content::WebUI* web_ui) |
: content::WebUIController(web_ui) { |
@@ -33,6 +84,12 @@ void StartPageUI::InitDataSource() { |
source->AddResourcePath("start_page.js", IDR_APP_LIST_START_PAGE_JS); |
source->SetDefaultResource(IDR_APP_LIST_START_PAGE_HTML); |
+#if defined(OS_CHROMEOS) |
+ source->OverrideContentSecurityPolicyObjectSrc("object-src 'self' data:;"); |
+ if (base::SysInfo::IsRunningOnChromeOS()) |
+ source->SetRequestFilter(base::Bind(&HandleHotwordFilesResourceFilter)); |
+#endif |
+ |
content::WebUIDataSource::Add(Profile::FromWebUI(web_ui()), source.release()); |
} |