OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/app_list/start_page_ui.h" | 5 #include "chrome/browser/ui/webui/app_list/start_page_ui.h" |
6 | 6 |
7 #include "base/file_util.h" | |
8 #include "base/files/file_path.h" | |
9 #include "base/memory/ref_counted_memory.h" | |
7 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "base/sys_info.h" | |
8 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
9 #include "chrome/browser/ui/webui/app_list/start_page_handler.h" | 13 #include "chrome/browser/ui/webui/app_list/start_page_handler.h" |
10 #include "chrome/common/url_constants.h" | 14 #include "chrome/common/url_constants.h" |
15 #include "content/public/browser/browser_thread.h" | |
11 #include "content/public/browser/web_ui.h" | 16 #include "content/public/browser/web_ui.h" |
12 #include "content/public/browser/web_ui_data_source.h" | 17 #include "content/public/browser/web_ui_data_source.h" |
13 #include "grit/browser_resources.h" | 18 #include "grit/browser_resources.h" |
14 | 19 |
15 namespace app_list { | 20 namespace app_list { |
21 namespace { | |
22 #if defined(OS_CHROMEOS) | |
23 const char* kHotwordFilenames[] = { | |
24 "dnn", | |
25 "ep_acoustic_model", | |
26 "hclg_shotword", | |
27 "hotword_arm.nexe", | |
28 "hotword_classifier", | |
29 "hotword_normalizer", | |
30 "hotword_word_symbols", | |
31 "hotword_x86_32.nexe", | |
32 "hotword_x86_64.nexe", | |
33 "okgoogle_hotword.config", | |
34 "phonelist", | |
35 "phone_state_map", | |
36 }; | |
37 | |
38 const char kHotwordFilesDir[] = "/opt/google/hotword"; | |
39 | |
40 void LoadModelData(const std::string& path, | |
41 const content::WebUIDataSource::GotDataCallback& callback) { | |
42 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); | |
43 // Will be owned by |callback|. | |
44 base::RefCountedString* data = new base::RefCountedString(); | |
xiyuan
2013/10/29 18:10:07
nit: use scoped_refptr<base::RefCountedString>
Jun Mukai
2013/10/30 01:01:32
Done.
| |
45 base::FilePath base_dir(kHotwordFilesDir); | |
46 base::ReadFileToString(base_dir.AppendASCII(path), &(data->data())); | |
47 callback.Run(data); | |
48 } | |
49 | |
50 bool HandleHotwordFilesResourceFilter( | |
51 const std::string& path, | |
52 const content::WebUIDataSource::GotDataCallback& callback) { | |
53 for (size_t i = 0; i < arraysize(kHotwordFilenames); ++i) { | |
54 if (path == kHotwordFilenames[i]) { | |
55 content::BrowserThread::PostTask( | |
56 content::BrowserThread::FILE, | |
57 FROM_HERE, | |
58 base::Bind(&LoadModelData, path, callback)); | |
59 return true; | |
60 } | |
61 } | |
62 | |
63 return false; | |
64 } | |
65 #endif // OS_CHROMEOS | |
66 } // namespace | |
16 | 67 |
17 StartPageUI::StartPageUI(content::WebUI* web_ui) | 68 StartPageUI::StartPageUI(content::WebUI* web_ui) |
18 : content::WebUIController(web_ui) { | 69 : content::WebUIController(web_ui) { |
19 web_ui->AddMessageHandler(new StartPageHandler); | 70 web_ui->AddMessageHandler(new StartPageHandler); |
20 InitDataSource(); | 71 InitDataSource(); |
21 } | 72 } |
22 | 73 |
23 StartPageUI::~StartPageUI() {} | 74 StartPageUI::~StartPageUI() {} |
24 | 75 |
25 void StartPageUI::InitDataSource() { | 76 void StartPageUI::InitDataSource() { |
26 scoped_ptr<content::WebUIDataSource> source( | 77 scoped_ptr<content::WebUIDataSource> source( |
27 content::WebUIDataSource::Create(chrome::kChromeUIAppListStartPageHost)); | 78 content::WebUIDataSource::Create(chrome::kChromeUIAppListStartPageHost)); |
28 | 79 |
29 source->SetUseJsonJSFormatV2(); | 80 source->SetUseJsonJSFormatV2(); |
30 source->SetJsonPath("strings.js"); | 81 source->SetJsonPath("strings.js"); |
31 | 82 |
32 source->AddResourcePath("start_page.css", IDR_APP_LIST_START_PAGE_CSS); | 83 source->AddResourcePath("start_page.css", IDR_APP_LIST_START_PAGE_CSS); |
33 source->AddResourcePath("start_page.js", IDR_APP_LIST_START_PAGE_JS); | 84 source->AddResourcePath("start_page.js", IDR_APP_LIST_START_PAGE_JS); |
34 source->SetDefaultResource(IDR_APP_LIST_START_PAGE_HTML); | 85 source->SetDefaultResource(IDR_APP_LIST_START_PAGE_HTML); |
35 | 86 |
87 #if defined(OS_CHROMEOS) | |
88 source->OverrideContentSecurityPolicyObjectSrc("object-src 'self' data:;"); | |
89 if (base::SysInfo::IsRunningOnChromeOS()) | |
90 source->SetRequestFilter(base::Bind(&HandleHotwordFilesResourceFilter)); | |
91 #endif | |
92 | |
36 content::WebUIDataSource::Add(Profile::FromWebUI(web_ui()), source.release()); | 93 content::WebUIDataSource::Add(Profile::FromWebUI(web_ui()), source.release()); |
37 } | 94 } |
38 | 95 |
39 } // namespace app_list | 96 } // namespace app_list |
OLD | NEW |