2016-04-26 07:10:27 +00:00
|
|
|
// Copyright (c) 2016 GitHub, Inc.
|
|
|
|
// Use of this source code is governed by the MIT license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2019-09-18 16:52:06 +00:00
|
|
|
#include "shell/common/api/remote/remote_callback_freer.h"
|
2016-04-26 07:10:27 +00:00
|
|
|
|
|
|
|
#include "base/strings/utf_string_conversions.h"
|
|
|
|
#include "base/values.h"
|
2018-03-09 09:31:09 +00:00
|
|
|
#include "content/public/browser/render_frame_host.h"
|
|
|
|
#include "content/public/browser/web_contents.h"
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "electron/shell/common/api/api.mojom.h"
|
2019-10-28 22:12:35 +00:00
|
|
|
#include "mojo/public/cpp/bindings/associated_remote.h"
|
2019-04-02 22:38:16 +00:00
|
|
|
#include "third_party/blink/public/common/associated_interfaces/associated_interface_provider.h"
|
2016-04-26 07:10:27 +00:00
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
namespace electron {
|
2016-04-26 07:10:27 +00:00
|
|
|
|
|
|
|
// static
|
|
|
|
void RemoteCallbackFreer::BindTo(v8::Isolate* isolate,
|
|
|
|
v8::Local<v8::Object> target,
|
2019-10-29 06:40:09 +00:00
|
|
|
int frame_id,
|
2018-07-10 08:15:40 +00:00
|
|
|
const std::string& context_id,
|
2016-04-26 07:10:27 +00:00
|
|
|
int object_id,
|
|
|
|
content::WebContents* web_contents) {
|
2019-10-29 06:40:09 +00:00
|
|
|
new RemoteCallbackFreer(isolate, target, frame_id, context_id, object_id,
|
|
|
|
web_contents);
|
2016-04-26 07:10:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
RemoteCallbackFreer::RemoteCallbackFreer(v8::Isolate* isolate,
|
|
|
|
v8::Local<v8::Object> target,
|
2019-10-29 06:40:09 +00:00
|
|
|
int frame_id,
|
2018-07-10 08:15:40 +00:00
|
|
|
const std::string& context_id,
|
2016-04-26 07:10:27 +00:00
|
|
|
int object_id,
|
|
|
|
content::WebContents* web_contents)
|
|
|
|
: ObjectLifeMonitor(isolate, target),
|
|
|
|
content::WebContentsObserver(web_contents),
|
2019-10-29 06:40:09 +00:00
|
|
|
frame_id_(frame_id),
|
2018-07-10 08:15:40 +00:00
|
|
|
context_id_(context_id),
|
2018-04-18 01:55:30 +00:00
|
|
|
object_id_(object_id) {}
|
2016-04-26 07:10:27 +00:00
|
|
|
|
2019-09-16 22:12:00 +00:00
|
|
|
RemoteCallbackFreer::~RemoteCallbackFreer() = default;
|
2016-04-26 07:10:27 +00:00
|
|
|
|
|
|
|
void RemoteCallbackFreer::RunDestructor() {
|
2019-10-29 06:40:09 +00:00
|
|
|
auto frames = web_contents()->GetAllFrames();
|
|
|
|
auto iter = std::find_if(frames.begin(), frames.end(), [this](auto* f) {
|
|
|
|
return f->GetRoutingID() == frame_id_;
|
|
|
|
});
|
|
|
|
|
|
|
|
if (iter != frames.end() && (*iter)->IsRenderFrameLive()) {
|
2019-10-28 22:12:35 +00:00
|
|
|
mojo::AssociatedRemote<mojom::ElectronRenderer> electron_renderer;
|
2019-10-29 06:40:09 +00:00
|
|
|
(*iter)->GetRemoteAssociatedInterfaces()->GetInterface(&electron_renderer);
|
2019-10-28 22:12:35 +00:00
|
|
|
electron_renderer->DereferenceRemoteJSCallback(context_id_, object_id_);
|
2018-03-09 09:31:09 +00:00
|
|
|
}
|
2016-04-26 07:10:27 +00:00
|
|
|
|
2016-04-26 07:37:46 +00:00
|
|
|
Observe(nullptr);
|
2016-04-26 07:10:27 +00:00
|
|
|
}
|
|
|
|
|
2016-04-26 07:30:26 +00:00
|
|
|
void RemoteCallbackFreer::RenderViewDeleted(content::RenderViewHost*) {
|
2016-04-26 07:10:27 +00:00
|
|
|
delete this;
|
|
|
|
}
|
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
} // namespace electron
|