2018-10-19 13:50:30 +00:00
|
|
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
|
|
|
// Copyright (c) 2013 Adam Roben <adam@roben.org>. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE-CHROMIUM file.
|
|
|
|
|
2021-11-22 07:34:31 +00:00
|
|
|
#ifndef ELECTRON_SHELL_BROWSER_UI_INSPECTABLE_WEB_CONTENTS_H_
|
|
|
|
#define ELECTRON_SHELL_BROWSER_UI_INSPECTABLE_WEB_CONTENTS_H_
|
2013-03-14 13:03:50 +00:00
|
|
|
|
2020-07-15 18:27:42 +00:00
|
|
|
#include <list>
|
|
|
|
#include <map>
|
|
|
|
#include <memory>
|
|
|
|
#include <set>
|
2017-05-18 22:06:57 +00:00
|
|
|
#include <string>
|
2020-07-15 18:27:42 +00:00
|
|
|
#include <vector>
|
2017-05-18 22:06:57 +00:00
|
|
|
|
2020-07-15 18:27:42 +00:00
|
|
|
#include "base/containers/span.h"
|
|
|
|
#include "base/containers/unique_ptr_adapters.h"
|
2023-05-11 20:07:39 +00:00
|
|
|
#include "base/memory/raw_ptr.h"
|
2020-07-15 18:27:42 +00:00
|
|
|
#include "base/memory/weak_ptr.h"
|
|
|
|
#include "chrome/browser/devtools/devtools_contents_resizing_strategy.h"
|
|
|
|
#include "chrome/browser/devtools/devtools_embedder_message_dispatcher.h"
|
2021-10-21 18:51:36 +00:00
|
|
|
#include "chrome/browser/devtools/devtools_settings.h"
|
2020-07-15 18:27:42 +00:00
|
|
|
#include "content/public/browser/devtools_agent_host.h"
|
|
|
|
#include "content/public/browser/devtools_frontend_host.h"
|
|
|
|
#include "content/public/browser/web_contents_delegate.h"
|
|
|
|
#include "content/public/browser/web_contents_observer.h"
|
|
|
|
#include "electron/buildflags/buildflags.h"
|
|
|
|
#include "ui/gfx/geometry/rect.h"
|
2015-05-18 13:56:03 +00:00
|
|
|
|
2018-10-04 18:08:56 +00:00
|
|
|
class PrefService;
|
2020-07-15 18:27:42 +00:00
|
|
|
class PrefRegistrySimple;
|
2021-10-21 18:51:36 +00:00
|
|
|
struct RegisterOptions;
|
2018-10-04 18:08:56 +00:00
|
|
|
|
2018-10-19 13:50:30 +00:00
|
|
|
namespace electron {
|
2013-03-14 13:03:50 +00:00
|
|
|
|
2014-03-04 08:12:02 +00:00
|
|
|
class InspectableWebContentsDelegate;
|
2013-03-14 13:03:50 +00:00
|
|
|
class InspectableWebContentsView;
|
|
|
|
|
2020-07-15 18:27:42 +00:00
|
|
|
class InspectableWebContents
|
|
|
|
: public content::DevToolsAgentHostClient,
|
|
|
|
public content::WebContentsObserver,
|
|
|
|
public content::WebContentsDelegate,
|
|
|
|
public DevToolsEmbedderMessageDispatcher::Delegate {
|
2013-11-17 23:20:54 +00:00
|
|
|
public:
|
2020-07-15 18:27:42 +00:00
|
|
|
using List = std::list<InspectableWebContents*>;
|
|
|
|
|
|
|
|
static const List& GetAll();
|
|
|
|
static void RegisterPrefs(PrefRegistrySimple* pref_registry);
|
|
|
|
|
2021-09-20 00:34:11 +00:00
|
|
|
InspectableWebContents(std::unique_ptr<content::WebContents> web_contents,
|
2020-07-15 18:27:42 +00:00
|
|
|
PrefService* pref_service,
|
|
|
|
bool is_guest);
|
|
|
|
~InspectableWebContents() override;
|
|
|
|
|
2021-11-03 11:41:45 +00:00
|
|
|
// disable copy
|
|
|
|
InspectableWebContents(const InspectableWebContents&) = delete;
|
|
|
|
InspectableWebContents& operator=(const InspectableWebContents&) = delete;
|
|
|
|
|
2020-07-15 18:27:42 +00:00
|
|
|
InspectableWebContentsView* GetView() const;
|
|
|
|
content::WebContents* GetWebContents() const;
|
|
|
|
content::WebContents* GetDevToolsWebContents() const;
|
|
|
|
|
|
|
|
void SetDelegate(InspectableWebContentsDelegate* delegate);
|
|
|
|
InspectableWebContentsDelegate* GetDelegate() const;
|
|
|
|
bool IsGuest() const;
|
|
|
|
void ReleaseWebContents();
|
|
|
|
void SetDevToolsWebContents(content::WebContents* devtools);
|
|
|
|
void SetDockState(const std::string& state);
|
|
|
|
void ShowDevTools(bool activate);
|
|
|
|
void CloseDevTools();
|
|
|
|
bool IsDevToolsViewShowing();
|
|
|
|
void AttachTo(scoped_refptr<content::DevToolsAgentHost>);
|
|
|
|
void Detach();
|
2022-06-29 16:39:48 +00:00
|
|
|
void CallClientFunction(
|
|
|
|
const std::string& object_name,
|
|
|
|
const std::string& method_name,
|
|
|
|
const base::Value arg1 = {},
|
|
|
|
const base::Value arg2 = {},
|
|
|
|
const base::Value arg3 = {},
|
|
|
|
base::OnceCallback<void(base::Value)> cb = base::NullCallback());
|
2020-07-15 18:27:42 +00:00
|
|
|
void InspectElement(int x, int y);
|
|
|
|
|
|
|
|
// Return the last position and size of devtools window.
|
|
|
|
gfx::Rect GetDevToolsBounds() const;
|
|
|
|
void SaveDevToolsBounds(const gfx::Rect& bounds);
|
|
|
|
|
|
|
|
// Return the last set zoom level of devtools window.
|
|
|
|
double GetDevToolsZoomLevel() const;
|
|
|
|
void UpdateDevToolsZoomLevel(double level);
|
|
|
|
|
|
|
|
private:
|
2022-06-16 07:46:11 +00:00
|
|
|
// DevToolsEmbedderMessageDispatcher::Delegate
|
2020-07-15 18:27:42 +00:00
|
|
|
void ActivateWindow() override;
|
|
|
|
void CloseWindow() override;
|
|
|
|
void LoadCompleted() override;
|
|
|
|
void SetInspectedPageBounds(const gfx::Rect& rect) override;
|
|
|
|
void InspectElementCompleted() override;
|
|
|
|
void InspectedURLChanged(const std::string& url) override;
|
2021-01-12 23:31:23 +00:00
|
|
|
void LoadNetworkResource(DispatchCallback callback,
|
2020-07-15 18:27:42 +00:00
|
|
|
const std::string& url,
|
|
|
|
const std::string& headers,
|
|
|
|
int stream_id) override;
|
2021-01-12 23:31:23 +00:00
|
|
|
void SetIsDocked(DispatchCallback callback, bool is_docked) override;
|
2020-07-15 18:27:42 +00:00
|
|
|
void OpenInNewTab(const std::string& url) override;
|
|
|
|
void ShowItemInFolder(const std::string& file_system_path) override;
|
|
|
|
void SaveToFile(const std::string& url,
|
|
|
|
const std::string& content,
|
|
|
|
bool save_as) override;
|
|
|
|
void AppendToFile(const std::string& url,
|
|
|
|
const std::string& content) override;
|
|
|
|
void RequestFileSystems() override;
|
|
|
|
void AddFileSystem(const std::string& type) override;
|
|
|
|
void RemoveFileSystem(const std::string& file_system_path) override;
|
|
|
|
void UpgradeDraggedFileSystemPermissions(
|
|
|
|
const std::string& file_system_url) override;
|
|
|
|
void IndexPath(int index_request_id,
|
|
|
|
const std::string& file_system_path,
|
|
|
|
const std::string& excluded_folders) override;
|
|
|
|
void StopIndexing(int index_request_id) override;
|
|
|
|
void SearchInPath(int search_request_id,
|
|
|
|
const std::string& file_system_path,
|
|
|
|
const std::string& query) override;
|
|
|
|
void SetWhitelistedShortcuts(const std::string& message) override;
|
|
|
|
void SetEyeDropperActive(bool active) override;
|
|
|
|
void ShowCertificateViewer(const std::string& cert_chain) override;
|
|
|
|
void ZoomIn() override;
|
|
|
|
void ZoomOut() override;
|
|
|
|
void ResetZoom() override;
|
|
|
|
void SetDevicesDiscoveryConfig(
|
|
|
|
bool discover_usb_devices,
|
|
|
|
bool port_forwarding_enabled,
|
|
|
|
const std::string& port_forwarding_config,
|
|
|
|
bool network_discovery_enabled,
|
|
|
|
const std::string& network_discovery_config) override;
|
|
|
|
void SetDevicesUpdatesEnabled(bool enabled) override;
|
|
|
|
void PerformActionOnRemotePage(const std::string& page_id,
|
|
|
|
const std::string& action) override;
|
|
|
|
void OpenRemotePage(const std::string& browser_id,
|
|
|
|
const std::string& url) override;
|
|
|
|
void OpenNodeFrontend() override;
|
|
|
|
void DispatchProtocolMessageFromDevToolsFrontend(
|
|
|
|
const std::string& message) override;
|
2021-01-12 23:31:23 +00:00
|
|
|
void SendJsonRequest(DispatchCallback callback,
|
2020-07-15 18:27:42 +00:00
|
|
|
const std::string& browser_id,
|
|
|
|
const std::string& url) override;
|
2021-10-21 18:51:36 +00:00
|
|
|
void RegisterPreference(const std::string& name,
|
2022-03-09 01:17:43 +00:00
|
|
|
const RegisterOptions& options) override {}
|
2021-01-12 23:31:23 +00:00
|
|
|
void GetPreferences(DispatchCallback callback) override;
|
2022-01-10 22:31:39 +00:00
|
|
|
void GetPreference(DispatchCallback callback,
|
|
|
|
const std::string& name) override;
|
2020-07-15 18:27:42 +00:00
|
|
|
void SetPreference(const std::string& name,
|
|
|
|
const std::string& value) override;
|
|
|
|
void RemovePreference(const std::string& name) override;
|
|
|
|
void ClearPreferences() override;
|
2021-11-24 08:45:59 +00:00
|
|
|
void GetSyncInformation(DispatchCallback callback) override;
|
2020-07-15 18:27:42 +00:00
|
|
|
void ConnectionReady() override;
|
|
|
|
void RegisterExtensionsAPI(const std::string& origin,
|
|
|
|
const std::string& script) override;
|
2021-01-12 23:31:23 +00:00
|
|
|
void Reattach(DispatchCallback callback) override;
|
2020-07-15 18:27:42 +00:00
|
|
|
void RecordEnumeratedHistogram(const std::string& name,
|
|
|
|
int sample,
|
|
|
|
int boundary_value) override {}
|
|
|
|
void ReadyForTest() override {}
|
|
|
|
void SetOpenNewWindowForPopups(bool value) override {}
|
|
|
|
void RecordPerformanceHistogram(const std::string& name,
|
|
|
|
double duration) override {}
|
|
|
|
void RecordUserMetricsAction(const std::string& name) override {}
|
2021-01-12 23:31:23 +00:00
|
|
|
void ShowSurvey(DispatchCallback callback,
|
2020-11-14 00:16:56 +00:00
|
|
|
const std::string& trigger) override {}
|
2021-01-12 23:31:23 +00:00
|
|
|
void CanShowSurvey(DispatchCallback callback,
|
2020-11-14 00:16:56 +00:00
|
|
|
const std::string& trigger) override {}
|
2020-07-15 18:27:42 +00:00
|
|
|
|
|
|
|
// content::DevToolsFrontendHostDelegate:
|
2022-07-13 21:26:16 +00:00
|
|
|
void HandleMessageFromDevToolsFrontend(base::Value::Dict message);
|
2020-07-15 18:27:42 +00:00
|
|
|
|
|
|
|
// content::DevToolsAgentHostClient:
|
|
|
|
void DispatchProtocolMessage(content::DevToolsAgentHost* agent_host,
|
|
|
|
base::span<const uint8_t> message) override;
|
|
|
|
void AgentHostClosed(content::DevToolsAgentHost* agent_host) override;
|
|
|
|
|
|
|
|
// content::WebContentsObserver:
|
|
|
|
void RenderFrameHostChanged(content::RenderFrameHost* old_host,
|
|
|
|
content::RenderFrameHost* new_host) override;
|
|
|
|
void WebContentsDestroyed() override;
|
|
|
|
void OnWebContentsFocused(
|
|
|
|
content::RenderWidgetHost* render_widget_host) override;
|
|
|
|
void ReadyToCommitNavigation(
|
|
|
|
content::NavigationHandle* navigation_handle) override;
|
|
|
|
void DidFinishNavigation(
|
|
|
|
content::NavigationHandle* navigation_handle) override;
|
|
|
|
|
|
|
|
// content::WebContentsDelegate:
|
|
|
|
bool HandleKeyboardEvent(content::WebContents*,
|
|
|
|
const content::NativeWebKeyboardEvent&) override;
|
|
|
|
void CloseContents(content::WebContents* source) override;
|
|
|
|
void RunFileChooser(content::RenderFrameHost* render_frame_host,
|
|
|
|
scoped_refptr<content::FileSelectListener> listener,
|
|
|
|
const blink::mojom::FileChooserParams& params) override;
|
|
|
|
void EnumerateDirectory(content::WebContents* source,
|
|
|
|
scoped_refptr<content::FileSelectListener> listener,
|
|
|
|
const base::FilePath& path) override;
|
|
|
|
|
|
|
|
void SendMessageAck(int request_id, const base::Value* arg1);
|
|
|
|
|
|
|
|
#if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
|
|
|
|
void AddDevToolsExtensionsToClient();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
DevToolsContentsResizingStrategy contents_resizing_strategy_;
|
|
|
|
gfx::Rect devtools_bounds_;
|
2021-01-26 18:16:21 +00:00
|
|
|
bool can_dock_ = true;
|
2020-07-15 18:27:42 +00:00
|
|
|
std::string dock_state_;
|
|
|
|
bool activate_ = true;
|
|
|
|
|
2023-05-11 20:07:39 +00:00
|
|
|
raw_ptr<InspectableWebContentsDelegate> delegate_ =
|
|
|
|
nullptr; // weak references.
|
2020-07-15 18:27:42 +00:00
|
|
|
|
2023-05-11 20:07:39 +00:00
|
|
|
raw_ptr<PrefService> pref_service_; // weak reference.
|
2020-07-15 18:27:42 +00:00
|
|
|
|
|
|
|
std::unique_ptr<content::WebContents> web_contents_;
|
|
|
|
|
|
|
|
// The default devtools created by this class when we don't have an external
|
|
|
|
// one assigned by SetDevToolsWebContents.
|
|
|
|
std::unique_ptr<content::WebContents> managed_devtools_web_contents_;
|
|
|
|
// The external devtools assigned by SetDevToolsWebContents.
|
2023-05-11 20:07:39 +00:00
|
|
|
raw_ptr<content::WebContents> external_devtools_web_contents_ = nullptr;
|
2020-07-15 18:27:42 +00:00
|
|
|
|
|
|
|
bool is_guest_;
|
|
|
|
std::unique_ptr<InspectableWebContentsView> view_;
|
|
|
|
|
2021-03-22 01:56:30 +00:00
|
|
|
bool frontend_loaded_ = false;
|
|
|
|
scoped_refptr<content::DevToolsAgentHost> agent_host_;
|
|
|
|
std::unique_ptr<content::DevToolsFrontendHost> frontend_host_;
|
|
|
|
std::unique_ptr<DevToolsEmbedderMessageDispatcher>
|
|
|
|
embedder_message_dispatcher_;
|
|
|
|
|
2020-07-15 18:27:42 +00:00
|
|
|
class NetworkResourceLoader;
|
|
|
|
std::set<std::unique_ptr<NetworkResourceLoader>, base::UniquePtrComparator>
|
|
|
|
loaders_;
|
|
|
|
|
|
|
|
using ExtensionsAPIs = std::map<std::string, std::string>;
|
|
|
|
ExtensionsAPIs extensions_api_;
|
|
|
|
|
2021-10-21 18:51:36 +00:00
|
|
|
// Contains the set of synced settings.
|
|
|
|
// The DevTools frontend *must* call `Register` for each setting prior to
|
|
|
|
// use, which guarantees that this set must not be persisted.
|
|
|
|
base::flat_set<std::string> synced_setting_names_;
|
|
|
|
|
2021-01-26 18:16:21 +00:00
|
|
|
base::WeakPtrFactory<InspectableWebContents> weak_factory_{this};
|
2013-03-14 13:03:50 +00:00
|
|
|
};
|
|
|
|
|
2018-10-19 13:50:30 +00:00
|
|
|
} // namespace electron
|
2013-03-14 13:03:50 +00:00
|
|
|
|
2021-11-22 07:34:31 +00:00
|
|
|
#endif // ELECTRON_SHELL_BROWSER_UI_INSPECTABLE_WEB_CONTENTS_H_
|