Reland "[serial] Implement tab indicator triggered by open()"
This is a reland of 0ca38034e8e6daca423130b7643dae169a60692b
The tests were flaking because the tab indicator is only removed after the
browser process receives the Mojo connection error. To fix this the tests are
now unit tests where we can make sure to run the necessary message loop to make
sure that this event has been delivered before checking.
Original change's description:
> [serial] Implement tab indicator triggered by open()
>
> As long as there is an active connection between a frame in a tab and a
> serial port the tab should display an indicator.
>
> This is accomplished by adding an additional Mojo pipe that is kept open
> between the device service and the browser processes for as long as the
> render process has a connection to the port.
>
> Bug: 917204
> Change-Id: I6441070f3473bd6b4a98dae98844a89ee4eb2329
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1546502
> Reviewed-by: Scott Violet <[email protected]>
> Reviewed-by: Dominick Ng <[email protected]>
> Reviewed-by: Yuri Wiitala <[email protected]>
> Commit-Queue: Reilly Grant <[email protected]>
> Cr-Commit-Position: refs/heads/master@{#647109}
Bug: 917204
Change-Id: I26fbb51845ae6b7ce2fe54bad2cc0a271ce0cbd0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1555508
Reviewed-by: Dominick Ng <[email protected]>
Reviewed-by: Scott Violet <[email protected]>
Commit-Queue: Reilly Grant <[email protected]>
Cr-Commit-Position: refs/heads/master@{#649154}
diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc
index a012751..c319c1a 100644
--- a/content/browser/web_contents/web_contents_impl.cc
+++ b/content/browser/web_contents/web_contents_impl.cc
@@ -583,7 +583,6 @@
GetContentClient()->browser()->GetAXModeForBrowserContext(
browser_context)),
audio_stream_monitor_(this),
- bluetooth_connected_device_count_(0),
media_web_contents_observer_(
std::make_unique<MediaWebContentsObserver>(this)),
media_device_group_id_salt_base_(
@@ -1542,6 +1541,10 @@
return bluetooth_connected_device_count_ > 0;
}
+bool WebContentsImpl::IsConnectedToSerialPort() const {
+ return serial_active_frame_count_ > 0;
+}
+
bool WebContentsImpl::HasPictureInPictureVideo() {
return has_picture_in_picture_video_;
}
@@ -6713,6 +6716,31 @@
}
}
+void WebContentsImpl::IncrementSerialActiveFrameCount() {
+ // Trying to invalidate the tab state while being destroyed could result in a
+ // use after free.
+ if (IsBeingDestroyed())
+ return;
+
+ // Notify for UI updates if the state changes.
+ serial_active_frame_count_++;
+ if (serial_active_frame_count_ == 1)
+ NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
+}
+
+void WebContentsImpl::DecrementSerialActiveFrameCount() {
+ // Trying to invalidate the tab state while being destroyed could result in a
+ // use after free.
+ if (IsBeingDestroyed())
+ return;
+
+ // Notify for UI updates if the state changes.
+ DCHECK_NE(0u, serial_active_frame_count_);
+ serial_active_frame_count_--;
+ if (serial_active_frame_count_ == 0)
+ NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
+}
+
void WebContentsImpl::SetHasPersistentVideo(bool has_persistent_video) {
if (has_persistent_video_ == has_persistent_video)
return;