Commit 665f35f5 authored by John Chen's avatar John Chen Committed by Commit Bot

[ChromeDriver] Lock parent WebView with child in use

When a WebView is in use, lock all its parents, to avoid dangling WebView.

Bug: chromedriver:3383
Change-Id: I3503e35922c45d7d9b1b244877486512d16124bd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2099583Reviewed-by: default avatarCaleb Rouleau <crouleau@chromium.org>
Commit-Queue: John Chen <johnchen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#749429}
parent 5a7d3fed
......@@ -1200,16 +1200,32 @@ std::unique_ptr<base::Value> WebViewImpl::GetCastIssueMessage() {
return std::unique_ptr<base::Value>(cast_tracker_->issue().DeepCopy());
}
WebViewImplHolder::WebViewImplHolder(WebViewImpl* web_view)
: web_view_(web_view), was_locked_(web_view && web_view->Lock()) {}
WebViewImplHolder::WebViewImplHolder(WebViewImpl* web_view) {
// Lock input web view and all its parents, to prevent them from being
// deleted while still in use. Inside |items_|, each web view must appear
// before its parent. This ensures the destructor unlocks the web views in
// the right order.
while (web_view != nullptr) {
Item item;
item.web_view = web_view;
item.was_locked = web_view->Lock();
items_.push_back(item);
web_view = const_cast<WebViewImpl*>(web_view->GetParent());
}
}
WebViewImplHolder::~WebViewImplHolder() {
if (web_view_ != nullptr && !was_locked_) {
if (!web_view_->IsDetached())
web_view_->Unlock();
else if (web_view_->GetParent() != nullptr)
web_view_->GetParent()->GetFrameTracker()->DeleteTargetForFrame(
web_view_->GetId());
for (Item& item : items_) {
// Once we find a web view that is still locked, then all its parents must
// also be locked.
if (item.was_locked)
break;
WebViewImpl* web_view = item.web_view;
if (!web_view->IsDetached())
web_view->Unlock();
else if (web_view->GetParent() != nullptr)
web_view->GetParent()->GetFrameTracker()->DeleteTargetForFrame(
web_view->GetId());
}
}
......
......@@ -226,8 +226,11 @@ class WebViewImplHolder {
~WebViewImplHolder();
private:
WebViewImpl* web_view_;
bool was_locked_;
struct Item {
WebViewImpl* web_view;
bool was_locked;
};
std::vector<Item> items_;
DISALLOW_COPY_AND_ASSIGN(WebViewImplHolder);
};
......
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