c3036d4557
* chore: bump chromium in DEPS to 117.0.5929.0 * chore: bump chromium in DEPS to 117.0.5931.0 * chore: bump chromium in DEPS to 117.0.5932.0 * chore: update patches * 4728317: Prevent PrintRenderFrameHelper from printing when already printing | https://chromium-review.googlesource.com/c/chromium/src/+/4728317 * 4739501: Use base::SequenceBound to manage SerialPortManagerImpl | https://chromium-review.googlesource.com/c/chromium/src/+/4739501 * 4702051: Allow overriding source in install-sysroot.py | https://chromium-review.googlesource.com/c/chromium/src/+/4702051 * chore: update filenames.libcxx.gni * 4727002: Rename "enable_arc2" to "enable_arc" | https://chromium-review.googlesource.com/c/chromium/src/+/4727002 * chore: bump chromium in DEPS to 117.0.5934.0 * 4736873: Rename ColorSpaces methods on display::Display | https://chromium-review.googlesource.com/c/chromium/src/+/4736873 * 4727203: Replace bool with an enum in as suggested in DevtoolsManagerDelegate. | https://chromium-review.googlesource.com/c/chromium/src/+/4727203 * 4744479: [DevTools] Add 'generateTaggedPDF' option to DevTools Page.printToPDF | https://chromium-review.googlesource.com/c/chromium/src/+/4744479 * 4735893: Don't share WebUSB permissions with webviews | https://chromium-review.googlesource.com/c/chromium/src/+/4735893 * revert: update filenames.libcxx.gni * chore: bump chromium in DEPS to 117.0.5936.0 * chore: update patches * 4746465: SAA: Query for embargoed StorageAccess permissions | https://chromium-review.googlesource.com/c/chromium/src/+/4746465 * 4666325: Move buildtools/third_party/lib*/trunk source paths to third_party/lib*/src. | https://chromium-review.googlesource.com/c/chromium/src/+/4666325 * chore: bump chromium in DEPS to 117.0.5938.0 * chore: bump chromium in DEPS to 118.0.5939.0 * chore: update patches * Send line bounds through CursorAnchorInfo on requestCursorUpdate https://chromium-review.googlesource.com/c/chromium/src/+/4394588 * Fixup lint for Move buildtools/third_party/lib*/trunk source paths to third_party/lib*/src * 4700305: [mac] Fix override of CHILD_PROCESS_EXE https://chromium-review.googlesource.com/c/chromium/src/+/4700305 Needed because of 4729689: Reland "Remove redundant existence check in PathService" | https://chromium-review.googlesource.com/c/chromium/src/+/4729689 * 4753759: More consistent icon handling for menus. https://chromium-review.googlesource.com/c/chromium/src/+/4753759 * chore: bump chromium in DEPS to 118.0.5941.0 * chore: update patches * chore: bump chromium in DEPS to 117.0.5938.0 * test: update nan-spec-runner cflags * build: fix isystem include path in nan-spec-runner * fixup! 4666325: Move buildtools/third_party/lib*/trunk source paths to third_party/lib*/src. | https://chromium-review.googlesource.com/c/chromium/src/+/4666325 fix a few more instances of the old path libc++.a and libc++abi.a are still in buildtools/ --------- Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com> Co-authored-by: VerteDinde <vertedinde@electronjs.org> Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com> Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org> Co-authored-by: Charles Kerr <charles@charleskerr.com>
142 lines
5 KiB
C++
142 lines
5 KiB
C++
// Copyright (c) 2014 The Chromium Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE-CHROMIUM file.
|
|
|
|
#include "shell/browser/ui/devtools_manager_delegate.h"
|
|
|
|
#include <memory>
|
|
#include <utility>
|
|
|
|
#include "base/command_line.h"
|
|
#include "base/files/file_path.h"
|
|
#include "base/functional/bind.h"
|
|
#include "base/path_service.h"
|
|
#include "base/strings/string_number_conversions.h"
|
|
#include "base/strings/stringprintf.h"
|
|
#include "base/strings/utf_string_conversions.h"
|
|
#include "chrome/common/chrome_paths.h"
|
|
#include "content/public/browser/devtools_agent_host.h"
|
|
#include "content/public/browser/devtools_frontend_host.h"
|
|
#include "content/public/browser/devtools_socket_factory.h"
|
|
#include "content/public/browser/favicon_status.h"
|
|
#include "content/public/browser/navigation_entry.h"
|
|
#include "content/public/common/content_switches.h"
|
|
#include "content/public/common/url_constants.h"
|
|
#include "content/public/common/user_agent.h"
|
|
#include "electron/grit/electron_resources.h"
|
|
#include "net/base/net_errors.h"
|
|
#include "net/socket/stream_socket.h"
|
|
#include "net/socket/tcp_server_socket.h"
|
|
#include "shell/browser/browser.h"
|
|
#include "shell/common/electron_paths.h"
|
|
#include "third_party/inspector_protocol/crdtp/dispatch.h"
|
|
#include "ui/base/resource/resource_bundle.h"
|
|
|
|
namespace electron {
|
|
|
|
namespace {
|
|
|
|
class TCPServerSocketFactory : public content::DevToolsSocketFactory {
|
|
public:
|
|
TCPServerSocketFactory(const std::string& address, int port)
|
|
: address_(address), port_(port) {}
|
|
|
|
// disable copy
|
|
TCPServerSocketFactory(const TCPServerSocketFactory&) = delete;
|
|
TCPServerSocketFactory& operator=(const TCPServerSocketFactory&) = delete;
|
|
|
|
private:
|
|
// content::ServerSocketFactory.
|
|
std::unique_ptr<net::ServerSocket> CreateForHttpServer() override {
|
|
auto socket =
|
|
std::make_unique<net::TCPServerSocket>(nullptr, net::NetLogSource());
|
|
if (socket->ListenWithAddressAndPort(address_, port_, 10) != net::OK)
|
|
return std::unique_ptr<net::ServerSocket>();
|
|
|
|
return socket;
|
|
}
|
|
std::unique_ptr<net::ServerSocket> CreateForTethering(
|
|
std::string* name) override {
|
|
return std::unique_ptr<net::ServerSocket>();
|
|
}
|
|
|
|
std::string address_;
|
|
uint16_t port_;
|
|
};
|
|
|
|
std::unique_ptr<content::DevToolsSocketFactory> CreateSocketFactory() {
|
|
auto& command_line = *base::CommandLine::ForCurrentProcess();
|
|
// See if the user specified a port on the command line (useful for
|
|
// automation). If not, use an ephemeral port by specifying 0.
|
|
int port = 0;
|
|
if (command_line.HasSwitch(switches::kRemoteDebuggingPort)) {
|
|
int temp_port;
|
|
std::string port_str =
|
|
command_line.GetSwitchValueASCII(switches::kRemoteDebuggingPort);
|
|
if (base::StringToInt(port_str, &temp_port) && temp_port >= 0 &&
|
|
temp_port < 65535) {
|
|
port = temp_port;
|
|
} else {
|
|
DLOG(WARNING) << "Invalid http debugger port number " << temp_port;
|
|
}
|
|
}
|
|
return std::make_unique<TCPServerSocketFactory>("127.0.0.1", port);
|
|
}
|
|
|
|
const char kBrowserCloseMethod[] = "Browser.close";
|
|
|
|
} // namespace
|
|
|
|
// DevToolsManagerDelegate ---------------------------------------------------
|
|
|
|
// static
|
|
void DevToolsManagerDelegate::StartHttpHandler() {
|
|
base::FilePath session_data;
|
|
base::PathService::Get(DIR_SESSION_DATA, &session_data);
|
|
content::DevToolsAgentHost::StartRemoteDebuggingServer(
|
|
CreateSocketFactory(), session_data, base::FilePath());
|
|
}
|
|
|
|
DevToolsManagerDelegate::DevToolsManagerDelegate() = default;
|
|
|
|
DevToolsManagerDelegate::~DevToolsManagerDelegate() = default;
|
|
|
|
void DevToolsManagerDelegate::Inspect(content::DevToolsAgentHost* agent_host) {}
|
|
|
|
void DevToolsManagerDelegate::HandleCommand(
|
|
content::DevToolsAgentHostClientChannel* channel,
|
|
base::span<const uint8_t> message,
|
|
NotHandledCallback callback) {
|
|
crdtp::Dispatchable dispatchable(crdtp::SpanFrom(message));
|
|
DCHECK(dispatchable.ok());
|
|
if (crdtp::SpanEquals(crdtp::SpanFrom(kBrowserCloseMethod),
|
|
dispatchable.Method())) {
|
|
// In theory, we should respond over the protocol saying that the
|
|
// Browser.close was handled. But doing so requires instantiating the
|
|
// protocol UberDispatcher and generating proper protocol handlers.
|
|
// Since we only have one method and it is supposed to close Electron,
|
|
// we don't need to add this complexity. Should we decide to support
|
|
// methods like Browser.setWindowBounds, we'll need to do it though.
|
|
content::GetUIThreadTaskRunner({})->PostTask(
|
|
FROM_HERE, base::BindOnce([]() { Browser::Get()->Quit(); }));
|
|
return;
|
|
}
|
|
std::move(callback).Run(message);
|
|
}
|
|
|
|
scoped_refptr<content::DevToolsAgentHost>
|
|
DevToolsManagerDelegate::CreateNewTarget(const GURL& url,
|
|
TargetType target_type) {
|
|
return nullptr;
|
|
}
|
|
|
|
std::string DevToolsManagerDelegate::GetDiscoveryPageHTML() {
|
|
return ui::ResourceBundle::GetSharedInstance().LoadDataResourceString(
|
|
IDR_CONTENT_SHELL_DEVTOOLS_DISCOVERY_PAGE);
|
|
}
|
|
|
|
bool DevToolsManagerDelegate::HasBundledFrontendResources() {
|
|
return true;
|
|
}
|
|
|
|
} // namespace electron
|