Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: ensure ElectronBrowser mojo service is only bound to appropriate…
… render frames (#33367) * Make ElectronBrowser mojo interface frame associated. (#32815) Co-authored-by: Marek Haranczyk <marek@openfin.co> * fix: ensure ElectronBrowser mojo service is only bound to appropriate render frames (#33323) (#33350) * fix: ensure ElectronBrowser mojo service is only bound to authorized render frames Notes: no-notes * refactor: extract electron API IPC to its own mojo interface * fix: just check main frame not primary main frame Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Marek Haranczyk <marek@openfin.co>
- Loading branch information
1 parent
a203965
commit d5dd3fb
Showing
16 changed files
with
399 additions
and
240 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
// Copyright (c) 2022 Slack Technologies, Inc. | ||
// Use of this source code is governed by the MIT license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "shell/browser/electron_api_ipc_handler_impl.h" | ||
|
||
#include <utility> | ||
|
||
#include "content/public/browser/render_frame_host.h" | ||
#include "content/public/browser/render_process_host.h" | ||
#include "mojo/public/cpp/bindings/self_owned_receiver.h" | ||
|
||
namespace electron { | ||
ElectronApiIPCHandlerImpl::ElectronApiIPCHandlerImpl( | ||
content::RenderFrameHost* frame_host, | ||
mojo::PendingAssociatedReceiver<mojom::ElectronApiIPC> receiver) | ||
: render_process_id_(frame_host->GetProcess()->GetID()), | ||
render_frame_id_(frame_host->GetRoutingID()) { | ||
content::WebContents* web_contents = | ||
content::WebContents::FromRenderFrameHost(frame_host); | ||
DCHECK(web_contents); | ||
content::WebContentsObserver::Observe(web_contents); | ||
|
||
receiver_.Bind(std::move(receiver)); | ||
receiver_.set_disconnect_handler(base::BindOnce( | ||
&ElectronApiIPCHandlerImpl::OnConnectionError, GetWeakPtr())); | ||
} | ||
|
||
ElectronApiIPCHandlerImpl::~ElectronApiIPCHandlerImpl() = default; | ||
|
||
void ElectronApiIPCHandlerImpl::WebContentsDestroyed() { | ||
delete this; | ||
} | ||
|
||
void ElectronApiIPCHandlerImpl::OnConnectionError() { | ||
delete this; | ||
} | ||
|
||
void ElectronApiIPCHandlerImpl::Message(bool internal, | ||
const std::string& channel, | ||
blink::CloneableMessage arguments) { | ||
api::WebContents* api_web_contents = api::WebContents::From(web_contents()); | ||
if (api_web_contents) { | ||
api_web_contents->Message(internal, channel, std::move(arguments), | ||
GetRenderFrameHost()); | ||
} | ||
} | ||
void ElectronApiIPCHandlerImpl::Invoke(bool internal, | ||
const std::string& channel, | ||
blink::CloneableMessage arguments, | ||
InvokeCallback callback) { | ||
api::WebContents* api_web_contents = api::WebContents::From(web_contents()); | ||
if (api_web_contents) { | ||
api_web_contents->Invoke(internal, channel, std::move(arguments), | ||
std::move(callback), GetRenderFrameHost()); | ||
} | ||
} | ||
|
||
void ElectronApiIPCHandlerImpl::ReceivePostMessage( | ||
const std::string& channel, | ||
blink::TransferableMessage message) { | ||
api::WebContents* api_web_contents = api::WebContents::From(web_contents()); | ||
if (api_web_contents) { | ||
api_web_contents->ReceivePostMessage(channel, std::move(message), | ||
GetRenderFrameHost()); | ||
} | ||
} | ||
|
||
void ElectronApiIPCHandlerImpl::MessageSync(bool internal, | ||
const std::string& channel, | ||
blink::CloneableMessage arguments, | ||
MessageSyncCallback callback) { | ||
api::WebContents* api_web_contents = api::WebContents::From(web_contents()); | ||
if (api_web_contents) { | ||
api_web_contents->MessageSync(internal, channel, std::move(arguments), | ||
std::move(callback), GetRenderFrameHost()); | ||
} | ||
} | ||
|
||
void ElectronApiIPCHandlerImpl::MessageTo(int32_t web_contents_id, | ||
const std::string& channel, | ||
blink::CloneableMessage arguments) { | ||
api::WebContents* api_web_contents = api::WebContents::From(web_contents()); | ||
if (api_web_contents) { | ||
api_web_contents->MessageTo(web_contents_id, channel, std::move(arguments)); | ||
} | ||
} | ||
|
||
void ElectronApiIPCHandlerImpl::MessageHost(const std::string& channel, | ||
blink::CloneableMessage arguments) { | ||
api::WebContents* api_web_contents = api::WebContents::From(web_contents()); | ||
if (api_web_contents) { | ||
api_web_contents->MessageHost(channel, std::move(arguments), | ||
GetRenderFrameHost()); | ||
} | ||
} | ||
|
||
content::RenderFrameHost* ElectronApiIPCHandlerImpl::GetRenderFrameHost() { | ||
return content::RenderFrameHost::FromID(render_process_id_, render_frame_id_); | ||
} | ||
|
||
// static | ||
void ElectronApiIPCHandlerImpl::Create( | ||
content::RenderFrameHost* frame_host, | ||
mojo::PendingAssociatedReceiver<mojom::ElectronApiIPC> receiver) { | ||
new ElectronApiIPCHandlerImpl(frame_host, std::move(receiver)); | ||
} | ||
} // namespace electron |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.