2020-12-14 18:57:36 +00:00
|
|
|
// Copyright (c) 2019 Slack Technologies, Inc.
|
|
|
|
// Use of this source code is governed by the MIT license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#ifndef SHELL_BROWSER_ELECTRON_BROWSER_HANDLER_IMPL_H_
|
|
|
|
#define SHELL_BROWSER_ELECTRON_BROWSER_HANDLER_IMPL_H_
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include "base/memory/weak_ptr.h"
|
|
|
|
#include "content/public/browser/web_contents_observer.h"
|
|
|
|
#include "electron/shell/common/api/api.mojom.h"
|
|
|
|
#include "shell/browser/api/electron_api_web_contents.h"
|
|
|
|
|
|
|
|
namespace content {
|
|
|
|
class RenderFrameHost;
|
2021-07-02 00:51:37 +00:00
|
|
|
}
|
2020-12-14 18:57:36 +00:00
|
|
|
|
|
|
|
namespace electron {
|
|
|
|
class ElectronBrowserHandlerImpl : public mojom::ElectronBrowser,
|
|
|
|
public content::WebContentsObserver {
|
|
|
|
public:
|
|
|
|
explicit ElectronBrowserHandlerImpl(
|
|
|
|
content::RenderFrameHost* render_frame_host,
|
|
|
|
mojo::PendingReceiver<mojom::ElectronBrowser> receiver);
|
|
|
|
|
|
|
|
static void Create(content::RenderFrameHost* frame_host,
|
|
|
|
mojo::PendingReceiver<mojom::ElectronBrowser> receiver);
|
|
|
|
|
2021-11-03 11:41:45 +00:00
|
|
|
// disable copy
|
|
|
|
ElectronBrowserHandlerImpl(const ElectronBrowserHandlerImpl&) = delete;
|
|
|
|
ElectronBrowserHandlerImpl& operator=(const ElectronBrowserHandlerImpl&) =
|
|
|
|
delete;
|
|
|
|
|
2020-12-14 18:57:36 +00:00
|
|
|
// mojom::ElectronBrowser:
|
|
|
|
void Message(bool internal,
|
|
|
|
const std::string& channel,
|
|
|
|
blink::CloneableMessage arguments) override;
|
|
|
|
void Invoke(bool internal,
|
|
|
|
const std::string& channel,
|
|
|
|
blink::CloneableMessage arguments,
|
|
|
|
InvokeCallback callback) override;
|
|
|
|
void OnFirstNonEmptyLayout() override;
|
|
|
|
void ReceivePostMessage(const std::string& channel,
|
|
|
|
blink::TransferableMessage message) override;
|
|
|
|
void MessageSync(bool internal,
|
|
|
|
const std::string& channel,
|
|
|
|
blink::CloneableMessage arguments,
|
|
|
|
MessageSyncCallback callback) override;
|
2021-06-18 04:26:18 +00:00
|
|
|
void MessageTo(int32_t web_contents_id,
|
2020-12-14 18:57:36 +00:00
|
|
|
const std::string& channel,
|
|
|
|
blink::CloneableMessage arguments) override;
|
|
|
|
void MessageHost(const std::string& channel,
|
|
|
|
blink::CloneableMessage arguments) override;
|
|
|
|
void UpdateDraggableRegions(
|
|
|
|
std::vector<mojom::DraggableRegionPtr> regions) override;
|
|
|
|
void SetTemporaryZoomLevel(double level) override;
|
|
|
|
void DoGetZoomLevel(DoGetZoomLevelCallback callback) override;
|
|
|
|
|
|
|
|
base::WeakPtr<ElectronBrowserHandlerImpl> GetWeakPtr() {
|
|
|
|
return weak_factory_.GetWeakPtr();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
~ElectronBrowserHandlerImpl() override;
|
|
|
|
|
|
|
|
// content::WebContentsObserver:
|
|
|
|
void WebContentsDestroyed() override;
|
|
|
|
|
|
|
|
void OnConnectionError();
|
|
|
|
|
|
|
|
content::RenderFrameHost* GetRenderFrameHost();
|
|
|
|
|
|
|
|
const int render_process_id_;
|
|
|
|
const int render_frame_id_;
|
|
|
|
|
|
|
|
mojo::Receiver<mojom::ElectronBrowser> receiver_{this};
|
|
|
|
|
2021-01-26 18:16:21 +00:00
|
|
|
base::WeakPtrFactory<ElectronBrowserHandlerImpl> weak_factory_{this};
|
2020-12-14 18:57:36 +00:00
|
|
|
};
|
|
|
|
} // namespace electron
|
|
|
|
#endif // SHELL_BROWSER_ELECTRON_BROWSER_HANDLER_IMPL_H_
|