Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(467)

Side by Side Diff: chrome/browser/ui/webui/app_list/start_page_ui.cc

Issue 992173002: Delete the old hotwording integration. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@hotword-remove-disable-option
Patch Set: Rebase. Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/files/file_path.h" 7 #include "base/files/file_path.h"
8 #include "base/files/file_util.h" 8 #include "base/files/file_util.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 {
26 #if defined(OS_CHROMEOS)
27 const char* kHotwordFilePrefixes[] = {
28 "hotword_",
29 "_platform_specific/",
30 };
31
32 void LoadModelData(const base::FilePath& base_dir,
33 const std::string& path,
34 const content::WebUIDataSource::GotDataCallback& callback) {
35 DCHECK_CURRENTLY_ON(content::BrowserThread::FILE);
36 // Will be owned by |callback|.
37 scoped_refptr<base::RefCountedString> data(new base::RefCountedString());
38 base::ReadFileToString(base_dir.AppendASCII(path), &(data->data()));
39 callback.Run(data.get());
40 }
41
42 bool HandleHotwordFilesResourceFilter(
43 Profile* profile,
44 const std::string& path,
45 const content::WebUIDataSource::GotDataCallback& callback) {
46 ExtensionService* service =
47 extensions::ExtensionSystem::Get(profile)->extension_service();
48 const extensions::Extension* extension =
49 service->GetExtensionById(extension_misc::kHotwordExtensionId, false);
50 if (!extension)
51 return false;
52
53 for (size_t i = 0; i < arraysize(kHotwordFilePrefixes); ++i) {
54 if (path.find(kHotwordFilePrefixes[i]) == 0) {
55 content::BrowserThread::PostTask(
56 content::BrowserThread::FILE,
57 FROM_HERE,
58 base::Bind(&LoadModelData, extension->path(), path, callback));
59 return true;
60 }
61 }
62
63 return false;
64 }
65 #endif // OS_CHROMEOS
66 } // namespace
67 25
68 StartPageUI::StartPageUI(content::WebUI* web_ui) 26 StartPageUI::StartPageUI(content::WebUI* web_ui)
69 : content::WebUIController(web_ui) { 27 : content::WebUIController(web_ui) {
70 web_ui->AddMessageHandler(new StartPageHandler); 28 web_ui->AddMessageHandler(new StartPageHandler);
71 InitDataSource(); 29 InitDataSource();
72 } 30 }
73 31
74 StartPageUI::~StartPageUI() {} 32 StartPageUI::~StartPageUI() {}
75 33
76 void StartPageUI::InitDataSource() { 34 void StartPageUI::InitDataSource() {
77 scoped_ptr<content::WebUIDataSource> source( 35 scoped_ptr<content::WebUIDataSource> source(
78 content::WebUIDataSource::Create(chrome::kChromeUIAppListStartPageHost)); 36 content::WebUIDataSource::Create(chrome::kChromeUIAppListStartPageHost));
79 37
80 source->SetJsonPath("strings.js"); 38 source->SetJsonPath("strings.js");
81 39
82 source->AddResourcePath("start_page.css", IDR_APP_LIST_START_PAGE_CSS); 40 source->AddResourcePath("start_page.css", IDR_APP_LIST_START_PAGE_CSS);
83 source->AddResourcePath("start_page.js", IDR_APP_LIST_START_PAGE_JS); 41 source->AddResourcePath("start_page.js", IDR_APP_LIST_START_PAGE_JS);
84 source->AddResourcePath("hotword_nacl.nmf", IDR_APP_LIST_HOTWORD_NACL_NMF);
85 source->SetDefaultResource(IDR_APP_LIST_START_PAGE_HTML); 42 source->SetDefaultResource(IDR_APP_LIST_START_PAGE_HTML);
86 43
87 #if defined(OS_CHROMEOS)
88 source->OverrideContentSecurityPolicyObjectSrc("object-src 'self' data:;");
89 if (base::SysInfo::IsRunningOnChromeOS())
90 source->SetRequestFilter(base::Bind(&HandleHotwordFilesResourceFilter,
91 Profile::FromWebUI(web_ui())));
92 #endif
93
94 content::WebUIDataSource::Add(Profile::FromWebUI(web_ui()), source.release()); 44 content::WebUIDataSource::Add(Profile::FromWebUI(web_ui()), source.release());
95 } 45 }
96 46
97 } // namespace app_list 47 } // namespace app_list
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/app_list/start_page_handler.cc ('k') | chrome/browser/ui/webui/options/browser_options_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698