Cast: Stop logging kVideoFrameSentToEncoder and rename a couple events.
[chromium-blink-merge.git] / content / renderer / accessibility / blink_ax_tree_source.cc
blob2ba5be4e99daa2686deab061c830f81a78f781e1
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/renderer/accessibility/blink_ax_tree_source.h"
7 #include <set>
9 #include "base/strings/string_number_conversions.h"
10 #include "base/strings/string_util.h"
11 #include "base/strings/utf_string_conversions.h"
12 #include "content/renderer/accessibility/blink_ax_enum_conversion.h"
13 #include "content/renderer/render_view_impl.h"
14 #include "third_party/WebKit/public/platform/WebRect.h"
15 #include "third_party/WebKit/public/platform/WebSize.h"
16 #include "third_party/WebKit/public/platform/WebString.h"
17 #include "third_party/WebKit/public/platform/WebVector.h"
18 #include "third_party/WebKit/public/web/WebAXEnums.h"
19 #include "third_party/WebKit/public/web/WebAXObject.h"
20 #include "third_party/WebKit/public/web/WebDocument.h"
21 #include "third_party/WebKit/public/web/WebDocumentType.h"
22 #include "third_party/WebKit/public/web/WebElement.h"
23 #include "third_party/WebKit/public/web/WebFormControlElement.h"
24 #include "third_party/WebKit/public/web/WebInputElement.h"
25 #include "third_party/WebKit/public/web/WebLocalFrame.h"
26 #include "third_party/WebKit/public/web/WebNode.h"
27 #include "third_party/WebKit/public/web/WebView.h"
29 using base::ASCIIToUTF16;
30 using base::UTF16ToUTF8;
31 using blink::WebAXObject;
32 using blink::WebDocument;
33 using blink::WebDocumentType;
34 using blink::WebElement;
35 using blink::WebLocalFrame;
36 using blink::WebNode;
37 using blink::WebVector;
38 using blink::WebView;
40 namespace content {
42 namespace {
44 // Returns true if |ancestor| is the first unignored parent of |child|,
45 // which means that when walking up the parent chain from |child|,
46 // |ancestor| is the *first* ancestor that isn't marked as
47 // accessibilityIsIgnored().
48 bool IsParentUnignoredOf(WebAXObject ancestor,
49 WebAXObject child) {
50 WebAXObject parent = child.parentObject();
51 while (!parent.isDetached() && parent.accessibilityIsIgnored())
52 parent = parent.parentObject();
53 return parent.equals(ancestor);
56 bool IsTrue(std::string html_value) {
57 return LowerCaseEqualsASCII(html_value, "true");
60 std::string GetEquivalentAriaRoleString(const ui::AXRole role) {
61 switch (role) {
62 case ui::AX_ROLE_ARTICLE:
63 return "article";
64 case ui::AX_ROLE_BANNER:
65 return "banner";
66 case ui::AX_ROLE_COMPLEMENTARY:
67 return "complementary";
68 case ui::AX_ROLE_CONTENT_INFO:
69 case ui::AX_ROLE_FOOTER:
70 return "contentinfo";
71 case ui::AX_ROLE_MAIN:
72 return "main";
73 case ui::AX_ROLE_NAVIGATION:
74 return "navigation";
75 case ui::AX_ROLE_REGION:
76 return "region";
77 default:
78 break;
81 return std::string();
84 void AddIntListAttributeFromWebObjects(ui::AXIntListAttribute attr,
85 WebVector<WebAXObject> objects,
86 ui::AXNodeData* dst) {
87 std::vector<int32> ids;
88 for(size_t i = 0; i < objects.size(); i++)
89 ids.push_back(objects[i].axID());
90 if (ids.size() > 0)
91 dst->AddIntListAttribute(attr, ids);
94 } // Anonymous namespace
96 BlinkAXTreeSource::BlinkAXTreeSource(RenderViewImpl* render_view)
97 : render_view_(render_view) {
100 BlinkAXTreeSource::~BlinkAXTreeSource() {
103 blink::WebAXObject BlinkAXTreeSource::GetRoot() const {
104 return GetMainDocument().accessibilityObject();
107 blink::WebAXObject BlinkAXTreeSource::GetFromId(int32 id) const {
108 return GetMainDocument().accessibilityObjectFromID(id);
111 int32 BlinkAXTreeSource::GetId(blink::WebAXObject node) const {
112 return node.axID();
115 void BlinkAXTreeSource::GetChildren(
116 blink::WebAXObject parent,
117 std::vector<blink::WebAXObject>* out_children) const {
118 bool is_iframe = false;
119 WebNode node = parent.node();
120 if (!node.isNull() && node.isElementNode()) {
121 WebElement element = node.to<WebElement>();
122 is_iframe = (element.tagName() == ASCIIToUTF16("IFRAME"));
125 for (unsigned i = 0; i < parent.childCount(); i++) {
126 blink::WebAXObject child = parent.childAt(i);
128 // The child may be invalid due to issues in blink accessibility code.
129 if (child.isDetached())
130 continue;
132 // Skip children whose parent isn't |parent|.
133 // As an exception, include children of an iframe element.
134 if (!is_iframe && !IsParentUnignoredOf(parent, child))
135 continue;
137 out_children->push_back(child);
141 blink::WebAXObject BlinkAXTreeSource::GetParent(
142 blink::WebAXObject node) const {
143 // Blink returns ignored objects when walking up the parent chain,
144 // we have to skip those here. Also, stop when we get to the root
145 // element.
146 blink::WebAXObject root = GetRoot();
147 do {
148 if (node.equals(root))
149 return blink::WebAXObject();
150 node = node.parentObject();
151 } while (!node.isDetached() && node.accessibilityIsIgnored());
153 return node;
156 bool BlinkAXTreeSource::IsValid(blink::WebAXObject node) const {
157 return !node.isDetached(); // This also checks if it's null.
160 bool BlinkAXTreeSource::IsEqual(blink::WebAXObject node1,
161 blink::WebAXObject node2) const {
162 return node1.equals(node2);
165 blink::WebAXObject BlinkAXTreeSource::GetNull() const {
166 return blink::WebAXObject();
169 void BlinkAXTreeSource::SerializeNode(blink::WebAXObject src,
170 ui::AXNodeData* dst) const {
171 dst->role = AXRoleFromBlink(src.role());
172 dst->state = AXStateFromBlink(src);
173 dst->location = src.boundingBoxRect();
174 dst->id = src.axID();
175 std::string name = UTF16ToUTF8(src.title());
177 std::string value;
178 if (src.valueDescription().length()) {
179 dst->AddStringAttribute(ui::AX_ATTR_VALUE,
180 UTF16ToUTF8(src.valueDescription()));
181 } else {
182 dst->AddStringAttribute(ui::AX_ATTR_VALUE, UTF16ToUTF8(src.stringValue()));
185 if (dst->role == ui::AX_ROLE_COLOR_WELL) {
186 int r, g, b;
187 src.colorValue(r, g, b);
188 dst->AddIntAttribute(ui::AX_ATTR_COLOR_VALUE_RED, r);
189 dst->AddIntAttribute(ui::AX_ATTR_COLOR_VALUE_GREEN, g);
190 dst->AddIntAttribute(ui::AX_ATTR_COLOR_VALUE_BLUE, b);
193 if (dst->role == ui::AX_ROLE_INLINE_TEXT_BOX) {
194 dst->AddIntAttribute(ui::AX_ATTR_TEXT_DIRECTION,
195 AXTextDirectionFromBlink(src.textDirection()));
197 WebVector<int> src_character_offsets;
198 src.characterOffsets(src_character_offsets);
199 std::vector<int32> character_offsets;
200 character_offsets.reserve(src_character_offsets.size());
201 for (size_t i = 0; i < src_character_offsets.size(); ++i)
202 character_offsets.push_back(src_character_offsets[i]);
203 dst->AddIntListAttribute(ui::AX_ATTR_CHARACTER_OFFSETS, character_offsets);
205 WebVector<int> src_word_starts;
206 WebVector<int> src_word_ends;
207 src.wordBoundaries(src_word_starts, src_word_ends);
208 std::vector<int32> word_starts;
209 std::vector<int32> word_ends;
210 word_starts.reserve(src_word_starts.size());
211 word_ends.reserve(src_word_starts.size());
212 for (size_t i = 0; i < src_word_starts.size(); ++i) {
213 word_starts.push_back(src_word_starts[i]);
214 word_ends.push_back(src_word_ends[i]);
216 dst->AddIntListAttribute(ui::AX_ATTR_WORD_STARTS, word_starts);
217 dst->AddIntListAttribute(ui::AX_ATTR_WORD_ENDS, word_ends);
220 if (src.accessKey().length()) {
221 dst->AddStringAttribute(ui::AX_ATTR_ACCESS_KEY,
222 UTF16ToUTF8(src.accessKey()));
224 if (src.actionVerb().length())
225 dst->AddStringAttribute(ui::AX_ATTR_ACTION, UTF16ToUTF8(src.actionVerb()));
226 if (src.isAriaReadOnly())
227 dst->AddBoolAttribute(ui::AX_ATTR_ARIA_READONLY, true);
228 if (src.isButtonStateMixed())
229 dst->AddBoolAttribute(ui::AX_ATTR_BUTTON_MIXED, true);
230 if (src.canSetValueAttribute())
231 dst->AddBoolAttribute(ui::AX_ATTR_CAN_SET_VALUE, true);
232 if (src.accessibilityDescription().length()) {
233 dst->AddStringAttribute(ui::AX_ATTR_DESCRIPTION,
234 UTF16ToUTF8(src.accessibilityDescription()));
236 if (src.hasComputedStyle()) {
237 dst->AddStringAttribute(ui::AX_ATTR_DISPLAY,
238 UTF16ToUTF8(src.computedStyleDisplay()));
240 if (src.helpText().length())
241 dst->AddStringAttribute(ui::AX_ATTR_HELP, UTF16ToUTF8(src.helpText()));
242 if (src.keyboardShortcut().length()) {
243 dst->AddStringAttribute(ui::AX_ATTR_SHORTCUT,
244 UTF16ToUTF8(src.keyboardShortcut()));
246 if (!src.titleUIElement().isDetached()) {
247 dst->AddIntAttribute(ui::AX_ATTR_TITLE_UI_ELEMENT,
248 src.titleUIElement().axID());
250 if (!src.ariaActiveDescendant().isDetached()) {
251 dst->AddIntAttribute(ui::AX_ATTR_ACTIVEDESCENDANT_ID,
252 src.ariaActiveDescendant().axID());
255 if (!src.url().isEmpty())
256 dst->AddStringAttribute(ui::AX_ATTR_URL, src.url().spec());
258 if (dst->role == ui::AX_ROLE_HEADING)
259 dst->AddIntAttribute(ui::AX_ATTR_HIERARCHICAL_LEVEL, src.headingLevel());
260 else if ((dst->role == ui::AX_ROLE_TREE_ITEM ||
261 dst->role == ui::AX_ROLE_ROW) &&
262 src.hierarchicalLevel() > 0) {
263 dst->AddIntAttribute(ui::AX_ATTR_HIERARCHICAL_LEVEL,
264 src.hierarchicalLevel());
267 // Treat the active list box item as focused.
268 if (dst->role == ui::AX_ROLE_LIST_BOX_OPTION &&
269 src.isSelectedOptionActive()) {
270 dst->state |= (1 << ui::AX_STATE_FOCUSED);
273 if (src.canvasHasFallbackContent())
274 dst->AddBoolAttribute(ui::AX_ATTR_CANVAS_HAS_FALLBACK, true);
276 WebNode node = src.node();
277 bool is_iframe = false;
278 std::string live_atomic;
279 std::string live_busy;
280 std::string live_status;
281 std::string live_relevant;
283 if (!node.isNull() && node.isElementNode()) {
284 WebElement element = node.to<WebElement>();
285 is_iframe = (element.tagName() == ASCIIToUTF16("IFRAME"));
287 if (LowerCaseEqualsASCII(element.getAttribute("aria-expanded"), "true"))
288 dst->state |= (1 << ui::AX_STATE_EXPANDED);
290 // TODO(ctguil): The tagName in WebKit is lower cased but
291 // HTMLElement::nodeName calls localNameUpper. Consider adding
292 // a WebElement method that returns the original lower cased tagName.
293 dst->AddStringAttribute(
294 ui::AX_ATTR_HTML_TAG,
295 StringToLowerASCII(UTF16ToUTF8(element.tagName())));
296 for (unsigned i = 0; i < element.attributeCount(); ++i) {
297 std::string name = StringToLowerASCII(UTF16ToUTF8(
298 element.attributeLocalName(i)));
299 std::string value = UTF16ToUTF8(element.attributeValue(i));
300 dst->html_attributes.push_back(std::make_pair(name, value));
303 if (dst->role == ui::AX_ROLE_EDITABLE_TEXT ||
304 dst->role == ui::AX_ROLE_TEXT_AREA ||
305 dst->role == ui::AX_ROLE_TEXT_FIELD) {
306 dst->AddIntAttribute(ui::AX_ATTR_TEXT_SEL_START, src.selectionStart());
307 dst->AddIntAttribute(ui::AX_ATTR_TEXT_SEL_END, src.selectionEnd());
309 WebVector<int> src_line_breaks;
310 src.lineBreaks(src_line_breaks);
311 if (src_line_breaks.size() > 0) {
312 std::vector<int32> line_breaks;
313 line_breaks.reserve(src_line_breaks.size());
314 for (size_t i = 0; i < src_line_breaks.size(); ++i)
315 line_breaks.push_back(src_line_breaks[i]);
316 dst->AddIntListAttribute(ui::AX_ATTR_LINE_BREAKS, line_breaks);
320 // ARIA role.
321 if (element.hasAttribute("role")) {
322 dst->AddStringAttribute(ui::AX_ATTR_ROLE,
323 UTF16ToUTF8(element.getAttribute("role")));
324 } else {
325 std::string role = GetEquivalentAriaRoleString(dst->role);
326 if (!role.empty())
327 dst->AddStringAttribute(ui::AX_ATTR_ROLE, role);
330 // Live region attributes
331 live_atomic = UTF16ToUTF8(element.getAttribute("aria-atomic"));
332 live_busy = UTF16ToUTF8(element.getAttribute("aria-busy"));
333 live_status = UTF16ToUTF8(element.getAttribute("aria-live"));
334 live_relevant = UTF16ToUTF8(element.getAttribute("aria-relevant"));
337 // Walk up the parent chain to set live region attributes of containers
338 std::string container_live_atomic;
339 std::string container_live_busy;
340 std::string container_live_status;
341 std::string container_live_relevant;
342 WebAXObject container_accessible = src;
343 while (!container_accessible.isDetached()) {
344 WebNode container_node = container_accessible.node();
345 if (!container_node.isNull() && container_node.isElementNode()) {
346 WebElement container_elem = container_node.to<WebElement>();
347 if (container_elem.hasAttribute("aria-atomic") &&
348 container_live_atomic.empty()) {
349 container_live_atomic =
350 UTF16ToUTF8(container_elem.getAttribute("aria-atomic"));
352 if (container_elem.hasAttribute("aria-busy") &&
353 container_live_busy.empty()) {
354 container_live_busy =
355 UTF16ToUTF8(container_elem.getAttribute("aria-busy"));
357 if (container_elem.hasAttribute("aria-live") &&
358 container_live_status.empty()) {
359 container_live_status =
360 UTF16ToUTF8(container_elem.getAttribute("aria-live"));
362 if (container_elem.hasAttribute("aria-relevant") &&
363 container_live_relevant.empty()) {
364 container_live_relevant =
365 UTF16ToUTF8(container_elem.getAttribute("aria-relevant"));
368 container_accessible = container_accessible.parentObject();
371 if (!live_atomic.empty())
372 dst->AddBoolAttribute(ui::AX_ATTR_LIVE_ATOMIC, IsTrue(live_atomic));
373 if (!live_busy.empty())
374 dst->AddBoolAttribute(ui::AX_ATTR_LIVE_BUSY, IsTrue(live_busy));
375 if (!live_status.empty())
376 dst->AddStringAttribute(ui::AX_ATTR_LIVE_STATUS, live_status);
377 if (!live_relevant.empty())
378 dst->AddStringAttribute(ui::AX_ATTR_LIVE_RELEVANT, live_relevant);
380 if (!container_live_atomic.empty()) {
381 dst->AddBoolAttribute(ui::AX_ATTR_CONTAINER_LIVE_ATOMIC,
382 IsTrue(container_live_atomic));
384 if (!container_live_busy.empty()) {
385 dst->AddBoolAttribute(ui::AX_ATTR_CONTAINER_LIVE_BUSY,
386 IsTrue(container_live_busy));
388 if (!container_live_status.empty()) {
389 dst->AddStringAttribute(ui::AX_ATTR_CONTAINER_LIVE_STATUS,
390 container_live_status);
392 if (!container_live_relevant.empty()) {
393 dst->AddStringAttribute(ui::AX_ATTR_CONTAINER_LIVE_RELEVANT,
394 container_live_relevant);
397 if (dst->role == ui::AX_ROLE_PROGRESS_INDICATOR ||
398 dst->role == ui::AX_ROLE_SCROLL_BAR ||
399 dst->role == ui::AX_ROLE_SLIDER ||
400 dst->role == ui::AX_ROLE_SPIN_BUTTON) {
401 dst->AddFloatAttribute(ui::AX_ATTR_VALUE_FOR_RANGE, src.valueForRange());
402 dst->AddFloatAttribute(ui::AX_ATTR_MAX_VALUE_FOR_RANGE,
403 src.maxValueForRange());
404 dst->AddFloatAttribute(ui::AX_ATTR_MIN_VALUE_FOR_RANGE,
405 src.minValueForRange());
408 if (dst->role == ui::AX_ROLE_DOCUMENT ||
409 dst->role == ui::AX_ROLE_WEB_AREA) {
410 dst->AddStringAttribute(ui::AX_ATTR_HTML_TAG, "#document");
411 const WebDocument& document = src.document();
412 if (name.empty())
413 name = UTF16ToUTF8(document.title());
414 dst->AddStringAttribute(ui::AX_ATTR_DOC_TITLE,
415 UTF16ToUTF8(document.title()));
416 dst->AddStringAttribute(ui::AX_ATTR_DOC_URL, document.url().spec());
417 dst->AddStringAttribute(
418 ui::AX_ATTR_DOC_MIMETYPE,
419 document.isXHTMLDocument() ? "text/xhtml" : "text/html");
420 dst->AddBoolAttribute(ui::AX_ATTR_DOC_LOADED, src.isLoaded());
421 dst->AddFloatAttribute(ui::AX_ATTR_DOC_LOADING_PROGRESS,
422 src.estimatedLoadingProgress());
424 const WebDocumentType& doctype = document.doctype();
425 if (!doctype.isNull()) {
426 dst->AddStringAttribute(ui::AX_ATTR_DOC_DOCTYPE,
427 UTF16ToUTF8(doctype.name()));
430 const gfx::Size& scroll_offset = document.frame()->scrollOffset();
431 dst->AddIntAttribute(ui::AX_ATTR_SCROLL_X, scroll_offset.width());
432 dst->AddIntAttribute(ui::AX_ATTR_SCROLL_Y, scroll_offset.height());
434 const gfx::Size& min_offset = document.frame()->minimumScrollOffset();
435 dst->AddIntAttribute(ui::AX_ATTR_SCROLL_X_MIN, min_offset.width());
436 dst->AddIntAttribute(ui::AX_ATTR_SCROLL_Y_MIN, min_offset.height());
438 const gfx::Size& max_offset = document.frame()->maximumScrollOffset();
439 dst->AddIntAttribute(ui::AX_ATTR_SCROLL_X_MAX, max_offset.width());
440 dst->AddIntAttribute(ui::AX_ATTR_SCROLL_Y_MAX, max_offset.height());
443 if (dst->role == ui::AX_ROLE_TABLE) {
444 int column_count = src.columnCount();
445 int row_count = src.rowCount();
446 if (column_count > 0 && row_count > 0) {
447 std::set<int32> unique_cell_id_set;
448 std::vector<int32> cell_ids;
449 std::vector<int32> unique_cell_ids;
450 dst->AddIntAttribute(ui::AX_ATTR_TABLE_COLUMN_COUNT, column_count);
451 dst->AddIntAttribute(ui::AX_ATTR_TABLE_ROW_COUNT, row_count);
452 WebAXObject header = src.headerContainerObject();
453 if (!header.isDetached())
454 dst->AddIntAttribute(ui::AX_ATTR_TABLE_HEADER_ID, header.axID());
455 for (int i = 0; i < column_count * row_count; ++i) {
456 WebAXObject cell = src.cellForColumnAndRow(
457 i % column_count, i / column_count);
458 int cell_id = -1;
459 if (!cell.isDetached()) {
460 cell_id = cell.axID();
461 if (unique_cell_id_set.find(cell_id) == unique_cell_id_set.end()) {
462 unique_cell_id_set.insert(cell_id);
463 unique_cell_ids.push_back(cell_id);
466 cell_ids.push_back(cell_id);
468 dst->AddIntListAttribute(ui::AX_ATTR_CELL_IDS, cell_ids);
469 dst->AddIntListAttribute(ui::AX_ATTR_UNIQUE_CELL_IDS, unique_cell_ids);
473 if (dst->role == ui::AX_ROLE_ROW) {
474 dst->AddIntAttribute(ui::AX_ATTR_TABLE_ROW_INDEX, src.rowIndex());
475 WebAXObject header = src.rowHeader();
476 if (!header.isDetached())
477 dst->AddIntAttribute(ui::AX_ATTR_TABLE_ROW_HEADER_ID, header.axID());
480 if (dst->role == ui::AX_ROLE_COLUMN) {
481 dst->AddIntAttribute(ui::AX_ATTR_TABLE_COLUMN_INDEX, src.columnIndex());
482 WebAXObject header = src.columnHeader();
483 if (!header.isDetached())
484 dst->AddIntAttribute(ui::AX_ATTR_TABLE_COLUMN_HEADER_ID, header.axID());
487 if (dst->role == ui::AX_ROLE_CELL ||
488 dst->role == ui::AX_ROLE_ROW_HEADER ||
489 dst->role == ui::AX_ROLE_COLUMN_HEADER) {
490 dst->AddIntAttribute(ui::AX_ATTR_TABLE_CELL_COLUMN_INDEX,
491 src.cellColumnIndex());
492 dst->AddIntAttribute(ui::AX_ATTR_TABLE_CELL_COLUMN_SPAN,
493 src.cellColumnSpan());
494 dst->AddIntAttribute(ui::AX_ATTR_TABLE_CELL_ROW_INDEX, src.cellRowIndex());
495 dst->AddIntAttribute(ui::AX_ATTR_TABLE_CELL_ROW_SPAN, src.cellRowSpan());
498 dst->AddStringAttribute(ui::AX_ATTR_NAME, name);
500 // Add the ids of *indirect* children - those who are children of this node,
501 // but whose parent is *not* this node. One example is a table
502 // cell, which is a child of both a row and a column. Because the cell's
503 // parent is the row, the row adds it as a child, and the column adds it
504 // as an indirect child.
505 int child_count = src.childCount();
506 for (int i = 0; i < child_count; ++i) {
507 WebAXObject child = src.childAt(i);
508 std::vector<int32> indirect_child_ids;
509 if (!is_iframe && !child.isDetached() && !IsParentUnignoredOf(src, child))
510 indirect_child_ids.push_back(child.axID());
511 if (indirect_child_ids.size() > 0) {
512 dst->AddIntListAttribute(
513 ui::AX_ATTR_INDIRECT_CHILD_IDS, indirect_child_ids);
517 WebVector<WebAXObject> controls;
518 if (src.ariaControls(controls))
519 AddIntListAttributeFromWebObjects(ui::AX_ATTR_CONTROLS_IDS, controls, dst);
521 WebVector<WebAXObject> describedby;
522 if (src.ariaDescribedby(describedby)) {
523 AddIntListAttributeFromWebObjects(
524 ui::AX_ATTR_DESCRIBEDBY_IDS, describedby, dst);
527 WebVector<WebAXObject> flowTo;
528 if (src.ariaFlowTo(flowTo))
529 AddIntListAttributeFromWebObjects(ui::AX_ATTR_FLOWTO_IDS, flowTo, dst);
531 WebVector<WebAXObject> labelledby;
532 if (src.ariaLabelledby(labelledby)) {
533 AddIntListAttributeFromWebObjects(
534 ui::AX_ATTR_LABELLEDBY_IDS, labelledby, dst);
537 WebVector<WebAXObject> owns;
538 if (src.ariaOwns(owns))
539 AddIntListAttributeFromWebObjects(ui::AX_ATTR_OWNS_IDS, owns, dst);
542 blink::WebDocument BlinkAXTreeSource::GetMainDocument() const {
543 WebView* view = render_view_->GetWebView();
544 WebLocalFrame* main_frame =
545 view ? view->mainFrame()->toWebLocalFrame() : NULL;
547 if (main_frame)
548 return main_frame->document();
550 return WebDocument();
553 } // namespace content