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-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,
|
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) {
|
2018-07-10 08:15:40 +00:00
|
|
|
new RemoteCallbackFreer(isolate, target, context_id, object_id, web_contents);
|
2016-04-26 07:10:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
RemoteCallbackFreer::RemoteCallbackFreer(v8::Isolate* isolate,
|
|
|
|
v8::Local<v8::Object> target,
|
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),
|
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() {
|
2018-08-24 15:30:37 +00:00
|
|
|
auto* channel = "ELECTRON_RENDERER_RELEASE_CALLBACK";
|
2016-04-26 07:37:46 +00:00
|
|
|
base::ListValue args;
|
2018-09-01 01:13:51 +00:00
|
|
|
int32_t sender_id = 0;
|
2018-07-10 08:15:40 +00:00
|
|
|
args.AppendString(context_id_);
|
2016-04-26 07:37:46 +00:00
|
|
|
args.AppendInteger(object_id_);
|
2018-04-17 22:41:47 +00:00
|
|
|
auto* frame_host = web_contents()->GetMainFrame();
|
2018-03-09 09:31:09 +00:00
|
|
|
if (frame_host) {
|
2019-04-02 22:38:16 +00:00
|
|
|
mojom::ElectronRendererAssociatedPtr electron_ptr;
|
|
|
|
frame_host->GetRemoteAssociatedInterfaces()->GetInterface(
|
|
|
|
mojo::MakeRequest(&electron_ptr));
|
|
|
|
electron_ptr->Message(true /* internal */, false /* send_to_all */, channel,
|
|
|
|
args.Clone(), sender_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
|