Repository: electron/electron
File: shell/browser/ui/inspectable_web_contents.cc (C++)

Code before:
  embedder_message_dispatcher_.reset();
  frontend_host_.reset();

  if (view_ && view_->GetDelegate())
    view_->GetDelegate()->DevToolsClosed();
}

bool InspectableWebContents::HandleKeyboardEvent(
    content::WebContents* source,
    const input::NativeWebKeyboardEvent& event) {
  auto* delegate = web_contents_->GetDelegate();
  return !delegate || delegate->HandleKeyboardEvent(source, event);
}

bool InspectableWebContents::DidAddMessageToConsole(
    content::WebContents* source,
    blink::mojom::ConsoleMessageLevel log_level,
    const std::u16string& message,
    int32_t line_no,
    const std::u16string& source_id) {
  // Suppress Chromium's default logging of DevTools frontend console messages
  // into native logs for the managed DevTools WebContents. Can be overridden by
  // enabling verbose logging.
  if (source == managed_devtools_web_contents_.get()) {
    // In testing builds, let logging through.
    if (DCHECK_IS_ON()) {
      return false;
    }

    if (VLOG_IS_ON(1)) {
      // Match Chromium's `content::LogConsoleMessage()` output format, but emit
      // it as a verbose log.
      logging::LogMessage("CONSOLE", line_no, logging::LOGGING_VERBOSE).stream()
          << "\"" << message << "\", source: " << source_id << " (" << line_no
          << ")";
    }

    return true;  // Suppress the default logging.
  }

  return false;  // Allow the default logging.
}

void InspectableWebContents::CloseContents(content::WebContents* source) {
  // This is where the devtools closes itself (by clicking the x button).
  CloseDevTools();
}

std::unique_ptr<content::EyeDropper> InspectableWebContents::OpenEyeDropper(
    content::RenderFrameHost* frame,
    content::EyeDropperListener* listener) {

Review comment (suggestion):
Could be a compile time check instead which can let the compiler remove the unreachable code.

```
#if DCHECK_IS_ON()
```

Code after:
  embedder_message_dispatcher_.reset();
  frontend_host_.reset();

  if (view_ && view_->GetDelegate())
    view_->GetDelegate()->DevToolsClosed();
}

bool InspectableWebContents::HandleKeyboardEvent(
    content::WebContents* source,
    const input::NativeWebKeyboardEvent& event) {
  auto* delegate = web_contents_->GetDelegate();
  return !delegate || delegate->HandleKeyboardEvent(source, event);
}

bool InspectableWebContents::DidAddMessageToConsole(
    content::WebContents* source,
    blink::mojom::ConsoleMessageLevel log_level,
    const std::u16string& message,
    int32_t line_no,
    const std::u16string& source_id) {
  // Suppress Chromium's default logging of DevTools frontend console messages
  // into native logs for the managed DevTools WebContents. Can be overridden by
  // enabling verbose logging.
  if (source == managed_devtools_web_contents_.get()) {
#if DCHECK_IS_ON()
    // In debug/testing builds, let logging through.
    return false;
#endif

    if (VLOG_IS_ON(1)) {
      // Match Chromium's `content::LogConsoleMessage()` output format, but emit
      // it as a verbose log.
      logging::LogMessage("CONSOLE", line_no, logging::LOGGING_VERBOSE).stream()
          << "\"" << message << "\", source: " << source_id << " (" << line_no
          << ")";
    }

    return true;  // Suppress the default logging.
  }

  return false;  // Allow the default logging.
}

void InspectableWebContents::CloseContents(content::WebContents* source) {
  // This is where the devtools closes itself (by clicking the x button).
  CloseDevTools();
}

std::unique_ptr<content::EyeDropper> InspectableWebContents::OpenEyeDropper(
    content::RenderFrameHost* frame,
    content::EyeDropperListener* listener) {