OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/chromeos/accessibility/accessibility_util.h" | 5 #include "chrome/browser/chromeos/accessibility/accessibility_util.h" |
6 | 6 |
7 #include <queue> | 7 #include <queue> |
8 | 8 |
9 #include "ash/high_contrast/high_contrast_controller.h" | 9 #include "ash/high_contrast/high_contrast_controller.h" |
10 #include "ash/magnifier/magnification_controller.h" | 10 #include "ash/magnifier/magnification_controller.h" |
11 #include "ash/magnifier/partial_magnification_controller.h" | 11 #include "ash/magnifier/partial_magnification_controller.h" |
12 #include "ash/shell.h" | 12 #include "ash/shell.h" |
13 #include "ash/shell_delegate.h" | 13 #include "ash/shell_delegate.h" |
14 #include "base/bind.h" | 14 #include "base/bind.h" |
15 #include "base/bind_helpers.h" | 15 #include "base/bind_helpers.h" |
16 #include "base/logging.h" | 16 #include "base/logging.h" |
17 #include "base/metrics/histogram.h" | 17 #include "base/metrics/histogram.h" |
18 #include "base/prefs/pref_service.h" | 18 #include "base/prefs/pref_service.h" |
19 #include "chrome/browser/accessibility/accessibility_extension_api.h" | 19 #include "chrome/browser/accessibility/accessibility_extension_api.h" |
20 #include "chrome/browser/browser_process.h" | 20 #include "chrome/browser/browser_process.h" |
21 #include "chrome/browser/chromeos/accessibility/magnification_manager.h" | 21 #include "chrome/browser/chromeos/accessibility/magnification_manager.h" |
22 #include "chrome/browser/extensions/component_loader.h" | 22 #include "chrome/browser/extensions/component_loader.h" |
23 #include "chrome/browser/extensions/extension_service.h" | 23 #include "chrome/browser/extensions/extension_service.h" |
24 #include "chrome/browser/extensions/extension_system.h" | 24 #include "chrome/browser/extensions/extension_system.h" |
25 #include "chrome/browser/extensions/file_reader.h" | |
26 #include "chrome/browser/profiles/profile.h" | 25 #include "chrome/browser/profiles/profile.h" |
27 #include "chrome/browser/profiles/profile_manager.h" | 26 #include "chrome/browser/profiles/profile_manager.h" |
28 #include "chrome/browser/speech/tts_controller.h" | 27 #include "chrome/browser/speech/tts_controller.h" |
29 #include "chrome/browser/ui/singleton_tabs.h" | 28 #include "chrome/browser/ui/singleton_tabs.h" |
30 #include "chrome/common/extensions/extension.h" | 29 #include "chrome/common/extensions/extension.h" |
31 #include "chrome/common/extensions/extension_messages.h" | 30 #include "chrome/common/extensions/extension_messages.h" |
32 #include "chrome/common/extensions/extension_resource.h" | |
33 #include "chrome/common/extensions/user_script.h" | 31 #include "chrome/common/extensions/user_script.h" |
34 #include "chrome/common/pref_names.h" | 32 #include "chrome/common/pref_names.h" |
35 #include "chrome/common/url_constants.h" | 33 #include "chrome/common/url_constants.h" |
36 #include "content/public/browser/browser_accessibility_state.h" | 34 #include "content/public/browser/browser_accessibility_state.h" |
37 #include "content/public/browser/notification_service.h" | 35 #include "content/public/browser/notification_service.h" |
38 #include "content/public/browser/render_process_host.h" | 36 #include "content/public/browser/render_process_host.h" |
39 #include "content/public/browser/render_view_host.h" | 37 #include "content/public/browser/render_view_host.h" |
40 #include "content/public/browser/web_contents.h" | 38 #include "content/public/browser/web_contents.h" |
41 #include "content/public/browser/web_ui.h" | 39 #include "content/public/browser/web_ui.h" |
| 40 #include "extensions/browser/file_reader.h" |
| 41 #include "extensions/common/extension_resource.h" |
42 #include "googleurl/src/gurl.h" | 42 #include "googleurl/src/gurl.h" |
43 #include "grit/browser_resources.h" | 43 #include "grit/browser_resources.h" |
44 #include "grit/generated_resources.h" | 44 #include "grit/generated_resources.h" |
45 #include "ui/base/l10n/l10n_util.h" | 45 #include "ui/base/l10n/l10n_util.h" |
46 #include "ui/base/resource/resource_bundle.h" | 46 #include "ui/base/resource/resource_bundle.h" |
47 | 47 |
48 using content::RenderViewHost; | 48 using content::RenderViewHost; |
49 | 49 |
50 namespace chromeos { | 50 namespace chromeos { |
51 namespace accessibility { | 51 namespace accessibility { |
52 | 52 |
53 // Helper class that directly loads an extension's content scripts into | 53 // Helper class that directly loads an extension's content scripts into |
54 // all of the frames corresponding to a given RenderViewHost. | 54 // all of the frames corresponding to a given RenderViewHost. |
55 class ContentScriptLoader { | 55 class ContentScriptLoader { |
56 public: | 56 public: |
57 // Initialize the ContentScriptLoader with the ID of the extension | 57 // Initialize the ContentScriptLoader with the ID of the extension |
58 // and the RenderViewHost where the scripts should be loaded. | 58 // and the RenderViewHost where the scripts should be loaded. |
59 ContentScriptLoader(const std::string& extension_id, | 59 ContentScriptLoader(const std::string& extension_id, |
60 int render_process_id, | 60 int render_process_id, |
61 int render_view_id) | 61 int render_view_id) |
62 : extension_id_(extension_id), | 62 : extension_id_(extension_id), |
63 render_process_id_(render_process_id), | 63 render_process_id_(render_process_id), |
64 render_view_id_(render_view_id) {} | 64 render_view_id_(render_view_id) {} |
65 | 65 |
66 // Call this once with the ExtensionResource corresponding to each | 66 // Call this once with the ExtensionResource corresponding to each |
67 // content script to be loaded. | 67 // content script to be loaded. |
68 void AppendScript(ExtensionResource resource) { | 68 void AppendScript(extensions::ExtensionResource resource) { |
69 resources_.push(resource); | 69 resources_.push(resource); |
70 } | 70 } |
71 | 71 |
72 // Fianlly, call this method once to fetch all of the resources and | 72 // Fianlly, call this method once to fetch all of the resources and |
73 // load them. This method will delete this object when done. | 73 // load them. This method will delete this object when done. |
74 void Run() { | 74 void Run() { |
75 if (resources_.empty()) { | 75 if (resources_.empty()) { |
76 delete this; | 76 delete this; |
77 return; | 77 return; |
78 } | 78 } |
79 | 79 |
80 ExtensionResource resource = resources_.front(); | 80 extensions::ExtensionResource resource = resources_.front(); |
81 resources_.pop(); | 81 resources_.pop(); |
82 scoped_refptr<FileReader> reader(new FileReader(resource, base::Bind( | 82 scoped_refptr<FileReader> reader(new FileReader(resource, base::Bind( |
83 &ContentScriptLoader::OnFileLoaded, base::Unretained(this)))); | 83 &ContentScriptLoader::OnFileLoaded, base::Unretained(this)))); |
84 reader->Start(); | 84 reader->Start(); |
85 } | 85 } |
86 | 86 |
87 private: | 87 private: |
88 void OnFileLoaded(bool success, const std::string& data) { | 88 void OnFileLoaded(bool success, const std::string& data) { |
89 if (success) { | 89 if (success) { |
90 ExtensionMsg_ExecuteCode_Params params; | 90 ExtensionMsg_ExecuteCode_Params params; |
(...skipping 11 matching lines...) Expand all Loading... |
102 render_view_host->Send(new ExtensionMsg_ExecuteCode( | 102 render_view_host->Send(new ExtensionMsg_ExecuteCode( |
103 render_view_host->GetRoutingID(), params)); | 103 render_view_host->GetRoutingID(), params)); |
104 } | 104 } |
105 } | 105 } |
106 Run(); | 106 Run(); |
107 } | 107 } |
108 | 108 |
109 std::string extension_id_; | 109 std::string extension_id_; |
110 int render_process_id_; | 110 int render_process_id_; |
111 int render_view_id_; | 111 int render_view_id_; |
112 std::queue<ExtensionResource> resources_; | 112 std::queue<extensions::ExtensionResource> resources_; |
113 }; | 113 }; |
114 | 114 |
115 void UpdateChromeOSAccessibilityHistograms() { | 115 void UpdateChromeOSAccessibilityHistograms() { |
116 UMA_HISTOGRAM_BOOLEAN("Accessibility.CrosSpokenFeedback", | 116 UMA_HISTOGRAM_BOOLEAN("Accessibility.CrosSpokenFeedback", |
117 IsSpokenFeedbackEnabled()); | 117 IsSpokenFeedbackEnabled()); |
118 UMA_HISTOGRAM_BOOLEAN("Accessibility.CrosHighContrast", | 118 UMA_HISTOGRAM_BOOLEAN("Accessibility.CrosHighContrast", |
119 IsHighContrastEnabled()); | 119 IsHighContrastEnabled()); |
120 UMA_HISTOGRAM_BOOLEAN("Accessibility.CrosVirtualKeyboard", | 120 UMA_HISTOGRAM_BOOLEAN("Accessibility.CrosVirtualKeyboard", |
121 IsVirtualKeyboardEnabled()); | 121 IsVirtualKeyboardEnabled()); |
122 if (MagnificationManager::Get()) { | 122 if (MagnificationManager::Get()) { |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 | 194 |
195 // Inject ChromeVox' content scripts. | 195 // Inject ChromeVox' content scripts. |
196 ContentScriptLoader* loader = new ContentScriptLoader( | 196 ContentScriptLoader* loader = new ContentScriptLoader( |
197 extension->id(), render_view_host->GetProcess()->GetID(), | 197 extension->id(), render_view_host->GetProcess()->GetID(), |
198 render_view_host->GetRoutingID()); | 198 render_view_host->GetRoutingID()); |
199 | 199 |
200 for (size_t i = 0; i < extension->content_scripts().size(); i++) { | 200 for (size_t i = 0; i < extension->content_scripts().size(); i++) { |
201 const extensions::UserScript& script = extension->content_scripts()[i]; | 201 const extensions::UserScript& script = extension->content_scripts()[i]; |
202 for (size_t j = 0; j < script.js_scripts().size(); ++j) { | 202 for (size_t j = 0; j < script.js_scripts().size(); ++j) { |
203 const extensions::UserScript::File &file = script.js_scripts()[j]; | 203 const extensions::UserScript::File &file = script.js_scripts()[j]; |
204 ExtensionResource resource = extension->GetResource( | 204 extensions::ExtensionResource resource = extension->GetResource( |
205 file.relative_path()); | 205 file.relative_path()); |
206 loader->AppendScript(resource); | 206 loader->AppendScript(resource); |
207 } | 207 } |
208 } | 208 } |
209 loader->Run(); // It cleans itself up when done. | 209 loader->Run(); // It cleans itself up when done. |
210 } | 210 } |
211 | 211 |
212 DLOG(INFO) << "ChromeVox was Loaded."; | 212 DLOG(INFO) << "ChromeVox was Loaded."; |
213 } else { // Unload ChromeVox | 213 } else { // Unload ChromeVox |
214 extension_service->component_loader()->Remove(path); | 214 extension_service->component_loader()->Remove(path); |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 if (IsSpokenFeedbackEnabled()) | 296 if (IsSpokenFeedbackEnabled()) |
297 Speak(utterance); | 297 Speak(utterance); |
298 } | 298 } |
299 | 299 |
300 void ShowAccessibilityHelp(Browser* browser) { | 300 void ShowAccessibilityHelp(Browser* browser) { |
301 chrome::ShowSingletonTab(browser, GURL(chrome::kChromeAccessibilityHelpURL)); | 301 chrome::ShowSingletonTab(browser, GURL(chrome::kChromeAccessibilityHelpURL)); |
302 } | 302 } |
303 | 303 |
304 } // namespace accessibility | 304 } // namespace accessibility |
305 } // namespace chromeos | 305 } // namespace chromeos |
OLD | NEW |