| 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" | 7 #include "base/file_util.h" |
| 8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 9 #include "base/memory/ref_counted_memory.h" | 9 #include "base/memory/ref_counted_memory.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/sys_info.h" | 11 #include "base/sys_info.h" |
| 12 #include "chrome/browser/extensions/extension_service.h" | 12 #include "chrome/browser/extensions/extension_service.h" |
| 13 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 14 #include "chrome/browser/ui/webui/app_list/start_page_handler.h" | 14 #include "chrome/browser/ui/webui/app_list/start_page_handler.h" |
| 15 #include "chrome/common/extensions/extension_constants.h" | 15 #include "chrome/common/extensions/extension_constants.h" |
| 16 #include "chrome/common/url_constants.h" | 16 #include "chrome/common/url_constants.h" |
| 17 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
| 18 #include "content/public/browser/web_ui.h" | 18 #include "content/public/browser/web_ui.h" |
| 19 #include "content/public/browser/web_ui_data_source.h" | 19 #include "content/public/browser/web_ui_data_source.h" |
| 20 #include "extensions/browser/extension_system.h" | 20 #include "extensions/browser/extension_system.h" |
| 21 #include "extensions/common/extension.h" | 21 #include "extensions/common/extension.h" |
| 22 #include "grit/browser_resources.h" | 22 #include "grit/browser_resources.h" |
| 23 | 23 |
| 24 namespace app_list { | 24 namespace app_list { |
| 25 namespace { | 25 namespace { |
| 26 #if defined(OS_CHROMEOS) | 26 #if defined(OS_CHROMEOS) |
| 27 const char* kHotwordFilenames[] = { | 27 const char* kHotwordFilePrefixes[] = { |
| 28 "greconacl.nmf", | 28 "hotword_", |
| 29 "hotword.data", | 29 "_platform_specific/", |
| 30 "_platform_specific/arm/hotword_arm.nexe", | |
| 31 "_platform_specific/x86-32/hotword_x86_32.nexe", | |
| 32 "_platform_specific/x86-64/hotword_x86_64.nexe", | |
| 33 }; | 30 }; |
| 34 | 31 |
| 35 void LoadModelData(const base::FilePath& base_dir, | 32 void LoadModelData(const base::FilePath& base_dir, |
| 36 const std::string& path, | 33 const std::string& path, |
| 37 const content::WebUIDataSource::GotDataCallback& callback) { | 34 const content::WebUIDataSource::GotDataCallback& callback) { |
| 38 DCHECK_CURRENTLY_ON(content::BrowserThread::FILE); | 35 DCHECK_CURRENTLY_ON(content::BrowserThread::FILE); |
| 39 // Will be owned by |callback|. | 36 // Will be owned by |callback|. |
| 40 scoped_refptr<base::RefCountedString> data(new base::RefCountedString()); | 37 scoped_refptr<base::RefCountedString> data(new base::RefCountedString()); |
| 41 base::ReadFileToString(base_dir.AppendASCII(path), &(data->data())); | 38 base::ReadFileToString(base_dir.AppendASCII(path), &(data->data())); |
| 42 callback.Run(data.get()); | 39 callback.Run(data.get()); |
| 43 } | 40 } |
| 44 | 41 |
| 45 bool HandleHotwordFilesResourceFilter( | 42 bool HandleHotwordFilesResourceFilter( |
| 46 Profile* profile, | 43 Profile* profile, |
| 47 const std::string& path, | 44 const std::string& path, |
| 48 const content::WebUIDataSource::GotDataCallback& callback) { | 45 const content::WebUIDataSource::GotDataCallback& callback) { |
| 49 ExtensionService* service = | 46 ExtensionService* service = |
| 50 extensions::ExtensionSystem::Get(profile)->extension_service(); | 47 extensions::ExtensionSystem::Get(profile)->extension_service(); |
| 51 const extensions::Extension* extension = | 48 const extensions::Extension* extension = |
| 52 service->GetExtensionById(extension_misc::kHotwordExtensionId, false); | 49 service->GetExtensionById(extension_misc::kHotwordExtensionId, false); |
| 53 if (!extension) | 50 if (!extension) |
| 54 return false; | 51 return false; |
| 55 | 52 |
| 56 for (size_t i = 0; i < arraysize(kHotwordFilenames); ++i) { | 53 for (size_t i = 0; i < arraysize(kHotwordFilePrefixes); ++i) { |
| 57 if (path == kHotwordFilenames[i]) { | 54 if (path.find(kHotwordFilePrefixes[i]) == 0) { |
| 58 content::BrowserThread::PostTask( | 55 content::BrowserThread::PostTask( |
| 59 content::BrowserThread::FILE, | 56 content::BrowserThread::FILE, |
| 60 FROM_HERE, | 57 FROM_HERE, |
| 61 base::Bind(&LoadModelData, extension->path(), path, callback)); | 58 base::Bind(&LoadModelData, extension->path(), path, callback)); |
| 62 return true; | 59 return true; |
| 63 } | 60 } |
| 64 } | 61 } |
| 65 | 62 |
| 66 return false; | 63 return false; |
| 67 } | 64 } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 92 source->OverrideContentSecurityPolicyObjectSrc("object-src 'self' data:;"); | 89 source->OverrideContentSecurityPolicyObjectSrc("object-src 'self' data:;"); |
| 93 if (base::SysInfo::IsRunningOnChromeOS()) | 90 if (base::SysInfo::IsRunningOnChromeOS()) |
| 94 source->SetRequestFilter(base::Bind(&HandleHotwordFilesResourceFilter, | 91 source->SetRequestFilter(base::Bind(&HandleHotwordFilesResourceFilter, |
| 95 Profile::FromWebUI(web_ui()))); | 92 Profile::FromWebUI(web_ui()))); |
| 96 #endif | 93 #endif |
| 97 | 94 |
| 98 content::WebUIDataSource::Add(Profile::FromWebUI(web_ui()), source.release()); | 95 content::WebUIDataSource::Add(Profile::FromWebUI(web_ui()), source.release()); |
| 99 } | 96 } |
| 100 | 97 |
| 101 } // namespace app_list | 98 } // namespace app_list |
| OLD | NEW |