Commit 2e19ce1c authored by dougt's avatar dougt Committed by Commit Bot

Better handle null delegates by returning instead of CHECK()

BUG=741764

Review-Url: https://codereview.chromium.org/2976913002
Cr-Commit-Position: refs/heads/master@{#486221}
parent 558367a7
...@@ -3050,30 +3050,36 @@ HRESULT WINAPI BrowserAccessibilityComWin::InternalQueryInterface( ...@@ -3050,30 +3050,36 @@ HRESULT WINAPI BrowserAccessibilityComWin::InternalQueryInterface(
void** object) { void** object) {
BrowserAccessibilityComWin* accessibility = BrowserAccessibilityComWin* accessibility =
reinterpret_cast<BrowserAccessibilityComWin*>(this_ptr); reinterpret_cast<BrowserAccessibilityComWin*>(this_ptr);
if (!accessibility->owner()) {
*object = nullptr;
return E_NOINTERFACE;
}
int32_t ia_role = accessibility->MSAARole(); int32_t ia_role = accessibility->MSAARole();
if (iid == IID_IAccessibleImage) { if (iid == IID_IAccessibleImage) {
if (ia_role != ROLE_SYSTEM_GRAPHIC) { if (ia_role != ROLE_SYSTEM_GRAPHIC) {
*object = NULL; *object = nullptr;
return E_NOINTERFACE; return E_NOINTERFACE;
} }
} else if (iid == IID_IAccessibleTable || iid == IID_IAccessibleTable2) { } else if (iid == IID_IAccessibleTable || iid == IID_IAccessibleTable2) {
if (ia_role != ROLE_SYSTEM_TABLE) { if (ia_role != ROLE_SYSTEM_TABLE) {
*object = NULL; *object = nullptr;
return E_NOINTERFACE; return E_NOINTERFACE;
} }
} else if (iid == IID_IAccessibleTableCell) { } else if (iid == IID_IAccessibleTableCell) {
if (!ui::IsCellOrTableHeaderRole(accessibility->owner()->GetRole())) { if (!ui::IsCellOrTableHeaderRole(accessibility->owner()->GetRole())) {
*object = NULL; *object = nullptr;
return E_NOINTERFACE; return E_NOINTERFACE;
} }
} else if (iid == IID_IAccessibleValue) { } else if (iid == IID_IAccessibleValue) {
if (!accessibility->IsRangeValueSupported()) { if (!accessibility->IsRangeValueSupported()) {
*object = NULL; *object = nullptr;
return E_NOINTERFACE; return E_NOINTERFACE;
} }
} else if (iid == IID_ISimpleDOMDocument) { } else if (iid == IID_ISimpleDOMDocument) {
if (ia_role != ROLE_SYSTEM_DOCUMENT) { if (ia_role != ROLE_SYSTEM_DOCUMENT) {
*object = NULL; *object = nullptr;
return E_NOINTERFACE; return E_NOINTERFACE;
} }
} else if (iid == IID_IAccessibleHyperlink) { } else if (iid == IID_IAccessibleHyperlink) {
......
...@@ -18,28 +18,34 @@ void AXPlatformNodeBase::Init(AXPlatformNodeDelegate* delegate) { ...@@ -18,28 +18,34 @@ void AXPlatformNodeBase::Init(AXPlatformNodeDelegate* delegate) {
} }
const AXNodeData& AXPlatformNodeBase::GetData() const { const AXNodeData& AXPlatformNodeBase::GetData() const {
CHECK(delegate_); CR_DEFINE_STATIC_LOCAL(ui::AXNodeData, empty_data, ());
return delegate_->GetData(); if (delegate_)
return delegate_->GetData();
return empty_data;
} }
gfx::Rect AXPlatformNodeBase::GetBoundsInScreen() const { gfx::Rect AXPlatformNodeBase::GetBoundsInScreen() const {
CHECK(delegate_); if (delegate_)
return delegate_->GetScreenBoundsRect(); return delegate_->GetScreenBoundsRect();
return gfx::Rect();
} }
gfx::NativeViewAccessible AXPlatformNodeBase::GetParent() { gfx::NativeViewAccessible AXPlatformNodeBase::GetParent() {
CHECK(delegate_); if (delegate_)
return delegate_->GetParent(); return delegate_->GetParent();
return nullptr;
} }
int AXPlatformNodeBase::GetChildCount() { int AXPlatformNodeBase::GetChildCount() {
CHECK(delegate_); if (delegate_)
return delegate_->GetChildCount(); return delegate_->GetChildCount();
return 0;
} }
gfx::NativeViewAccessible AXPlatformNodeBase::ChildAtIndex(int index) { gfx::NativeViewAccessible AXPlatformNodeBase::ChildAtIndex(int index) {
CHECK(delegate_); if (delegate_)
return delegate_->ChildAtIndex(index); return delegate_->ChildAtIndex(index);
return nullptr;
} }
// AXPlatformNode overrides. // AXPlatformNode overrides.
...@@ -65,7 +71,8 @@ AXPlatformNodeDelegate* AXPlatformNodeBase::GetDelegate() const { ...@@ -65,7 +71,8 @@ AXPlatformNodeDelegate* AXPlatformNodeBase::GetDelegate() const {
// Helpers. // Helpers.
AXPlatformNodeBase* AXPlatformNodeBase::GetPreviousSibling() { AXPlatformNodeBase* AXPlatformNodeBase::GetPreviousSibling() {
CHECK(delegate_); if (!delegate_)
return nullptr;
gfx::NativeViewAccessible parent_accessible = GetParent(); gfx::NativeViewAccessible parent_accessible = GetParent();
AXPlatformNodeBase* parent = FromNativeViewAccessible(parent_accessible); AXPlatformNodeBase* parent = FromNativeViewAccessible(parent_accessible);
if (!parent) if (!parent)
...@@ -80,7 +87,8 @@ AXPlatformNodeBase* AXPlatformNodeBase::GetPreviousSibling() { ...@@ -80,7 +87,8 @@ AXPlatformNodeBase* AXPlatformNodeBase::GetPreviousSibling() {
} }
AXPlatformNodeBase* AXPlatformNodeBase::GetNextSibling() { AXPlatformNodeBase* AXPlatformNodeBase::GetNextSibling() {
CHECK(delegate_); if (!delegate_)
return nullptr;
gfx::NativeViewAccessible parent_accessible = GetParent(); gfx::NativeViewAccessible parent_accessible = GetParent();
AXPlatformNodeBase* parent = FromNativeViewAccessible(parent_accessible); AXPlatformNodeBase* parent = FromNativeViewAccessible(parent_accessible);
if (!parent) if (!parent)
...@@ -93,7 +101,8 @@ AXPlatformNodeBase* AXPlatformNodeBase::GetNextSibling() { ...@@ -93,7 +101,8 @@ AXPlatformNodeBase* AXPlatformNodeBase::GetNextSibling() {
} }
bool AXPlatformNodeBase::IsDescendant(AXPlatformNodeBase* node) { bool AXPlatformNodeBase::IsDescendant(AXPlatformNodeBase* node) {
CHECK(delegate_); if (!delegate_)
return false;
if (!node) if (!node)
return false; return false;
if (node == this) if (node == this)
...@@ -107,102 +116,124 @@ bool AXPlatformNodeBase::IsDescendant(AXPlatformNodeBase* node) { ...@@ -107,102 +116,124 @@ bool AXPlatformNodeBase::IsDescendant(AXPlatformNodeBase* node) {
bool AXPlatformNodeBase::HasBoolAttribute( bool AXPlatformNodeBase::HasBoolAttribute(
ui::AXBoolAttribute attribute) const { ui::AXBoolAttribute attribute) const {
CHECK(delegate_); if (!delegate_)
return false;
return GetData().HasBoolAttribute(attribute); return GetData().HasBoolAttribute(attribute);
} }
bool AXPlatformNodeBase::GetBoolAttribute( bool AXPlatformNodeBase::GetBoolAttribute(
ui::AXBoolAttribute attribute) const { ui::AXBoolAttribute attribute) const {
CHECK(delegate_); if (!delegate_)
return false;
return GetData().GetBoolAttribute(attribute); return GetData().GetBoolAttribute(attribute);
} }
bool AXPlatformNodeBase::GetBoolAttribute( bool AXPlatformNodeBase::GetBoolAttribute(
ui::AXBoolAttribute attribute, bool* value) const { ui::AXBoolAttribute attribute, bool* value) const {
CHECK(delegate_); if (!delegate_)
return false;
return GetData().GetBoolAttribute(attribute, value); return GetData().GetBoolAttribute(attribute, value);
} }
bool AXPlatformNodeBase::HasFloatAttribute( bool AXPlatformNodeBase::HasFloatAttribute(
ui::AXFloatAttribute attribute) const { ui::AXFloatAttribute attribute) const {
CHECK(delegate_); if (!delegate_)
return false;
return GetData().HasFloatAttribute(attribute); return GetData().HasFloatAttribute(attribute);
} }
float AXPlatformNodeBase::GetFloatAttribute( float AXPlatformNodeBase::GetFloatAttribute(
ui::AXFloatAttribute attribute) const { ui::AXFloatAttribute attribute) const {
CHECK(delegate_); if (!delegate_)
return false;
return GetData().GetFloatAttribute(attribute); return GetData().GetFloatAttribute(attribute);
} }
bool AXPlatformNodeBase::GetFloatAttribute( bool AXPlatformNodeBase::GetFloatAttribute(
ui::AXFloatAttribute attribute, float* value) const { ui::AXFloatAttribute attribute, float* value) const {
CHECK(delegate_); if (!delegate_)
return false;
return GetData().GetFloatAttribute(attribute, value); return GetData().GetFloatAttribute(attribute, value);
} }
bool AXPlatformNodeBase::HasIntAttribute( bool AXPlatformNodeBase::HasIntAttribute(
ui::AXIntAttribute attribute) const { ui::AXIntAttribute attribute) const {
CHECK(delegate_); if (!delegate_)
return false;
return GetData().HasIntAttribute(attribute); return GetData().HasIntAttribute(attribute);
} }
int AXPlatformNodeBase::GetIntAttribute( int AXPlatformNodeBase::GetIntAttribute(
ui::AXIntAttribute attribute) const { ui::AXIntAttribute attribute) const {
CHECK(delegate_); if (!delegate_)
return false;
return GetData().GetIntAttribute(attribute); return GetData().GetIntAttribute(attribute);
} }
bool AXPlatformNodeBase::GetIntAttribute( bool AXPlatformNodeBase::GetIntAttribute(
ui::AXIntAttribute attribute, int* value) const { ui::AXIntAttribute attribute, int* value) const {
CHECK(delegate_); if (!delegate_)
return false;
return GetData().GetIntAttribute(attribute, value); return GetData().GetIntAttribute(attribute, value);
} }
bool AXPlatformNodeBase::HasStringAttribute( bool AXPlatformNodeBase::HasStringAttribute(
ui::AXStringAttribute attribute) const { ui::AXStringAttribute attribute) const {
CHECK(delegate_); if (!delegate_)
return false;
return GetData().HasStringAttribute(attribute); return GetData().HasStringAttribute(attribute);
} }
const std::string& AXPlatformNodeBase::GetStringAttribute( const std::string& AXPlatformNodeBase::GetStringAttribute(
ui::AXStringAttribute attribute) const { ui::AXStringAttribute attribute) const {
CHECK(delegate_); CR_DEFINE_STATIC_LOCAL(std::string, empty_data, ());
if (!delegate_)
return empty_data;
return GetData().GetStringAttribute(attribute); return GetData().GetStringAttribute(attribute);
} }
bool AXPlatformNodeBase::GetStringAttribute( bool AXPlatformNodeBase::GetStringAttribute(
ui::AXStringAttribute attribute, std::string* value) const { ui::AXStringAttribute attribute, std::string* value) const {
CHECK(delegate_); if (!delegate_)
return false;
return GetData().GetStringAttribute(attribute, value); return GetData().GetStringAttribute(attribute, value);
} }
base::string16 AXPlatformNodeBase::GetString16Attribute( base::string16 AXPlatformNodeBase::GetString16Attribute(
ui::AXStringAttribute attribute) const { ui::AXStringAttribute attribute) const {
CHECK(delegate_); if (!delegate_)
return base::string16();
return GetData().GetString16Attribute(attribute); return GetData().GetString16Attribute(attribute);
} }
bool AXPlatformNodeBase::GetString16Attribute( bool AXPlatformNodeBase::GetString16Attribute(
ui::AXStringAttribute attribute, ui::AXStringAttribute attribute,
base::string16* value) const { base::string16* value) const {
CHECK(delegate_); if (!delegate_)
return false;
return GetData().GetString16Attribute(attribute, value); return GetData().GetString16Attribute(attribute, value);
} }
bool AXPlatformNodeBase::HasIntListAttribute( bool AXPlatformNodeBase::HasIntListAttribute(
ui::AXIntListAttribute attribute) const { ui::AXIntListAttribute attribute) const {
if (!delegate_)
return false;
return GetData().HasIntListAttribute(attribute); return GetData().HasIntListAttribute(attribute);
} }
const std::vector<int32_t>& AXPlatformNodeBase::GetIntListAttribute( const std::vector<int32_t>& AXPlatformNodeBase::GetIntListAttribute(
ui::AXIntListAttribute attribute) const { ui::AXIntListAttribute attribute) const {
CR_DEFINE_STATIC_LOCAL(std::vector<int32_t>, empty_data, ());
if (!delegate_)
return empty_data;
return GetData().GetIntListAttribute(attribute); return GetData().GetIntListAttribute(attribute);
} }
bool AXPlatformNodeBase::GetIntListAttribute( bool AXPlatformNodeBase::GetIntListAttribute(
ui::AXIntListAttribute attribute, ui::AXIntListAttribute attribute,
std::vector<int32_t>* value) const { std::vector<int32_t>* value) const {
if (!delegate_)
return false;
return GetData().GetIntListAttribute(attribute, value); return GetData().GetIntListAttribute(attribute, value);
} }
...@@ -210,7 +241,6 @@ AXPlatformNodeBase::AXPlatformNodeBase() { ...@@ -210,7 +241,6 @@ AXPlatformNodeBase::AXPlatformNodeBase() {
} }
AXPlatformNodeBase::~AXPlatformNodeBase() { AXPlatformNodeBase::~AXPlatformNodeBase() {
CHECK(!delegate_);
} }
// static // static
...@@ -226,7 +256,9 @@ bool AXPlatformNodeBase::SetTextSelection(int start_offset, int end_offset) { ...@@ -226,7 +256,9 @@ bool AXPlatformNodeBase::SetTextSelection(int start_offset, int end_offset) {
action_data.anchor_node_id = action_data.focus_node_id = GetData().id; action_data.anchor_node_id = action_data.focus_node_id = GetData().id;
action_data.anchor_offset = start_offset; action_data.anchor_offset = start_offset;
action_data.focus_offset = end_offset; action_data.focus_offset = end_offset;
DCHECK(delegate_); if (!delegate_)
return false;
return delegate_->AccessibilityPerformAction(action_data); return delegate_->AccessibilityPerformAction(action_data);
} }
...@@ -306,6 +338,8 @@ bool AXPlatformNodeBase::IsRangeValueSupported() const { ...@@ -306,6 +338,8 @@ bool AXPlatformNodeBase::IsRangeValueSupported() const {
} }
AXPlatformNodeBase* AXPlatformNodeBase::GetTable() const { AXPlatformNodeBase* AXPlatformNodeBase::GetTable() const {
if (!delegate_)
return nullptr;
AXPlatformNodeBase* table = const_cast<AXPlatformNodeBase*>(this); AXPlatformNodeBase* table = const_cast<AXPlatformNodeBase*>(this);
while (table && !ui::IsTableLikeRole(table->GetData().role)) { while (table && !ui::IsTableLikeRole(table->GetData().role)) {
gfx::NativeViewAccessible parent_accessible = table->GetParent(); gfx::NativeViewAccessible parent_accessible = table->GetParent();
...@@ -317,8 +351,8 @@ AXPlatformNodeBase* AXPlatformNodeBase::GetTable() const { ...@@ -317,8 +351,8 @@ AXPlatformNodeBase* AXPlatformNodeBase::GetTable() const {
} }
AXPlatformNodeBase* AXPlatformNodeBase::GetTableCell(int index) const { AXPlatformNodeBase* AXPlatformNodeBase::GetTableCell(int index) const {
DCHECK(delegate_); if (!delegate_)
return nullptr;
if (!ui::IsTableLikeRole(GetData().role) && if (!ui::IsTableLikeRole(GetData().role) &&
!ui::IsCellOrTableHeaderRole(GetData().role)) !ui::IsCellOrTableHeaderRole(GetData().role))
return nullptr; return nullptr;
......
...@@ -1381,7 +1381,6 @@ STDMETHODIMP AXPlatformNodeWin::get_columnHeaderCells( ...@@ -1381,7 +1381,6 @@ STDMETHODIMP AXPlatformNodeWin::get_columnHeaderCells(
*n_column_header_cells = 0; *n_column_header_cells = 0;
auto* table = GetTable(); auto* table = GetTable();
if (!table) { if (!table) {
NOTREACHED();
return S_FALSE; return S_FALSE;
} }
...@@ -1438,7 +1437,6 @@ STDMETHODIMP AXPlatformNodeWin::get_rowHeaderCells(IUnknown*** cell_accessibles, ...@@ -1438,7 +1437,6 @@ STDMETHODIMP AXPlatformNodeWin::get_rowHeaderCells(IUnknown*** cell_accessibles,
*n_row_header_cells = 0; *n_row_header_cells = 0;
auto* table = GetTable(); auto* table = GetTable();
if (!table) { if (!table) {
NOTREACHED();
return S_FALSE; return S_FALSE;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment