OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "content/browser/accessibility/accessibility_ui.h" | 5 #include "content/browser/accessibility/accessibility_ui.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 namespace content { | 42 namespace content { |
43 | 43 |
44 namespace { | 44 namespace { |
45 | 45 |
46 base::DictionaryValue* BuildTargetDescriptor( | 46 base::DictionaryValue* BuildTargetDescriptor( |
47 const GURL& url, | 47 const GURL& url, |
48 const std::string& name, | 48 const std::string& name, |
49 const GURL& favicon_url, | 49 const GURL& favicon_url, |
50 int process_id, | 50 int process_id, |
51 int route_id, | 51 int route_id, |
52 AccessibilityMode accessibility_mode, | 52 unsigned int accessibility_mode, |
53 base::ProcessHandle handle = base::kNullProcessHandle) { | 53 base::ProcessHandle handle = base::kNullProcessHandle) { |
54 base::DictionaryValue* target_data = new base::DictionaryValue(); | 54 base::DictionaryValue* target_data = new base::DictionaryValue(); |
55 target_data->SetInteger(kProcessIdField, process_id); | 55 target_data->SetInteger(kProcessIdField, process_id); |
56 target_data->SetInteger(kRouteIdField, route_id); | 56 target_data->SetInteger(kRouteIdField, route_id); |
57 target_data->SetString(kUrlField, url.spec()); | 57 target_data->SetString(kUrlField, url.spec()); |
58 target_data->SetString(kNameField, net::EscapeForHTML(name)); | 58 target_data->SetString(kNameField, net::EscapeForHTML(name)); |
59 target_data->SetInteger(kPidField, base::GetProcId(handle)); | 59 target_data->SetInteger(kPidField, base::GetProcId(handle)); |
60 target_data->SetString(kFaviconUrlField, favicon_url.spec()); | 60 target_data->SetString(kFaviconUrlField, favicon_url.spec()); |
61 target_data->SetInteger(kAccessibilityModeField, | 61 target_data->SetInteger(kAccessibilityModeField, |
62 accessibility_mode); | 62 accessibility_mode); |
63 return target_data; | 63 return target_data; |
64 } | 64 } |
65 | 65 |
66 base::DictionaryValue* BuildTargetDescriptor(RenderViewHost* rvh) { | 66 base::DictionaryValue* BuildTargetDescriptor(RenderViewHost* rvh) { |
67 WebContents* web_contents = WebContents::FromRenderViewHost(rvh); | 67 WebContents* web_contents = WebContents::FromRenderViewHost(rvh); |
68 std::string title; | 68 std::string title; |
69 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(rvh); | 69 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(rvh); |
70 AccessibilityMode accessibility_mode = rwhi->accessibility_mode(); | 70 unsigned int accessibility_mode = rwhi->accessibility_mode(); |
71 | 71 |
72 GURL url; | 72 GURL url; |
73 GURL favicon_url; | 73 GURL favicon_url; |
74 if (web_contents) { | 74 if (web_contents) { |
75 // TODO(nasko): Fix the following code to use a consistent set of data | 75 // TODO(nasko): Fix the following code to use a consistent set of data |
76 // across the URL, title, and favicon. | 76 // across the URL, title, and favicon. |
77 url = web_contents->GetURL(); | 77 url = web_contents->GetURL(); |
78 title = base::UTF16ToUTF8(web_contents->GetTitle()); | 78 title = base::UTF16ToUTF8(web_contents->GetTitle()); |
79 NavigationController& controller = web_contents->GetController(); | 79 NavigationController& controller = web_contents->GetController(); |
80 NavigationEntry* entry = controller.GetVisibleEntry(); | 80 NavigationEntry* entry = controller.GetVisibleEntry(); |
(...skipping 21 matching lines...) Expand all Loading... |
102 continue; | 102 continue; |
103 if (!widget->IsRenderView()) | 103 if (!widget->IsRenderView()) |
104 continue; | 104 continue; |
105 | 105 |
106 RenderViewHost* rvh = RenderViewHost::From(widget); | 106 RenderViewHost* rvh = RenderViewHost::From(widget); |
107 rvh_list->Append(BuildTargetDescriptor(rvh)); | 107 rvh_list->Append(BuildTargetDescriptor(rvh)); |
108 } | 108 } |
109 | 109 |
110 scoped_ptr<base::DictionaryValue> data(new base::DictionaryValue()); | 110 scoped_ptr<base::DictionaryValue> data(new base::DictionaryValue()); |
111 data->Set("list", rvh_list.release()); | 111 data->Set("list", rvh_list.release()); |
112 scoped_ptr<base::FundamentalValue> a11y_mode(new base::FundamentalValue( | 112 scoped_ptr<base::FundamentalValue> a11y_mode(base::Value::CreateIntegerValue( |
113 BrowserAccessibilityStateImpl::GetInstance()->accessibility_mode())); | 113 BrowserAccessibilityStateImpl::GetInstance()->accessibility_mode())); |
114 data->Set("global_a11y_mode", a11y_mode.release()); | 114 data->Set("global_a11y_mode", a11y_mode.release()); |
115 | 115 |
116 std::string json_string; | 116 std::string json_string; |
117 base::JSONWriter::Write(data.get(), &json_string); | 117 base::JSONWriter::Write(data.get(), &json_string); |
118 | 118 |
119 callback.Run(base::RefCountedString::TakeString(&json_string)); | 119 callback.Run(base::RefCountedString::TakeString(&json_string)); |
120 } | 120 } |
121 | 121 |
122 bool HandleRequestCallback( | 122 bool HandleRequestCallback( |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 CHECK(base::StringToInt(process_id_str, | 177 CHECK(base::StringToInt(process_id_str, |
178 &process_id)); | 178 &process_id)); |
179 CHECK(base::StringToInt(route_id_str, &route_id)); | 179 CHECK(base::StringToInt(route_id_str, &route_id)); |
180 | 180 |
181 RenderViewHost* rvh = RenderViewHost::FromID(process_id, route_id); | 181 RenderViewHost* rvh = RenderViewHost::FromID(process_id, route_id); |
182 if (!rvh) | 182 if (!rvh) |
183 return; | 183 return; |
184 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(rvh); | 184 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(rvh); |
185 if (!rwhi) | 185 if (!rwhi) |
186 return; | 186 return; |
187 AccessibilityMode mode = rwhi->accessibility_mode(); | 187 unsigned int mode = rwhi->accessibility_mode(); |
188 if (mode == AccessibilityModeOff) | 188 if (mode > 0) |
189 rwhi->SetAccessibilityMode(AccessibilityModeComplete); | 189 rwhi->RemoveAccessibilityMode(AccessibilityModeAll); |
190 else | 190 else |
191 rwhi->SetAccessibilityMode(AccessibilityModeOff); | 191 rwhi->AddAccessibilityMode(AccessibilityModeComplete); |
192 } | 192 } |
193 | 193 |
194 void AccessibilityUI::ToggleGlobalAccessibility(const base::ListValue* args) { | 194 void AccessibilityUI::ToggleGlobalAccessibility(const base::ListValue* args) { |
195 BrowserAccessibilityStateImpl* state = | 195 BrowserAccessibilityStateImpl* state = |
196 BrowserAccessibilityStateImpl::GetInstance(); | 196 BrowserAccessibilityStateImpl::GetInstance(); |
197 AccessibilityMode mode = state->accessibility_mode(); | 197 unsigned int mode = state->accessibility_mode(); |
198 AccessibilityMode new_mode = (mode == AccessibilityModeOff | 198 if (mode > 0) |
199 ? AccessibilityModeComplete | 199 state->RemoveAccessibilityMode(AccessibilityModeAll); |
200 : AccessibilityModeOff); | 200 else |
201 state->SetAccessibilityMode(new_mode); | 201 state->AddAccessibilityMode(AccessibilityModeComplete); |
202 } | 202 } |
203 | 203 |
204 void AccessibilityUI::RequestAccessibilityTree(const base::ListValue* args) { | 204 void AccessibilityUI::RequestAccessibilityTree(const base::ListValue* args) { |
205 std::string process_id_str; | 205 std::string process_id_str; |
206 std::string route_id_str; | 206 std::string route_id_str; |
207 int process_id; | 207 int process_id; |
208 int route_id; | 208 int route_id; |
209 CHECK(args->GetSize() == 2); | 209 CHECK(args->GetSize() == 2); |
210 CHECK(args->GetString(0, &process_id_str)); | 210 CHECK(args->GetString(0, &process_id_str)); |
211 CHECK(args->GetString(1, &route_id_str)); | 211 CHECK(args->GetString(1, &route_id_str)); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 formatter->SetFilters(filters); | 249 formatter->SetFilters(filters); |
250 formatter->FormatAccessibilityTree(&accessibility_contents_utf16); | 250 formatter->FormatAccessibilityTree(&accessibility_contents_utf16); |
251 | 251 |
252 result->Set("tree", | 252 result->Set("tree", |
253 new base::StringValue( | 253 new base::StringValue( |
254 base::UTF16ToUTF8(accessibility_contents_utf16))); | 254 base::UTF16ToUTF8(accessibility_contents_utf16))); |
255 web_ui()->CallJavascriptFunction("accessibility.showTree", *(result.get())); | 255 web_ui()->CallJavascriptFunction("accessibility.showTree", *(result.get())); |
256 } | 256 } |
257 | 257 |
258 } // namespace content | 258 } // namespace content |
OLD | NEW |