2015-10-02 09:50:10 +00:00
|
|
|
// Copyright (c) 2015 GitHub, Inc.
|
|
|
|
// Use of this source code is governed by the MIT license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#include "atom/browser/api/atom_api_desktop_capturer.h"
|
|
|
|
|
2017-04-04 04:50:44 +00:00
|
|
|
using base::PlatformThreadRef;
|
|
|
|
|
2015-10-02 09:50:10 +00:00
|
|
|
#include "atom/common/api/atom_api_native_image.h"
|
2015-10-06 06:34:54 +00:00
|
|
|
#include "atom/common/native_mate_converters/gfx_converter.h"
|
2015-10-02 09:50:10 +00:00
|
|
|
#include "base/strings/utf_string_conversions.h"
|
|
|
|
#include "chrome/browser/media/desktop_media_list.h"
|
2018-01-18 01:04:57 +00:00
|
|
|
#include "content/public/browser/desktop_capture.h"
|
2015-10-02 09:50:10 +00:00
|
|
|
#include "native_mate/dictionary.h"
|
|
|
|
#include "third_party/webrtc/modules/desktop_capture/desktop_capture_options.h"
|
2017-01-23 09:47:30 +00:00
|
|
|
#include "third_party/webrtc/modules/desktop_capture/desktop_capturer.h"
|
2015-10-02 09:50:10 +00:00
|
|
|
|
2016-03-08 14:28:53 +00:00
|
|
|
#include "atom/common/node_includes.h"
|
|
|
|
|
2015-10-06 06:34:54 +00:00
|
|
|
namespace mate {
|
|
|
|
|
|
|
|
template<>
|
|
|
|
struct Converter<DesktopMediaList::Source> {
|
|
|
|
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
|
|
|
|
const DesktopMediaList::Source& source) {
|
|
|
|
mate::Dictionary dict(isolate, v8::Object::New(isolate));
|
|
|
|
content::DesktopMediaID id = source.id;
|
|
|
|
dict.Set("name", base::UTF16ToUTF8(source.name));
|
|
|
|
dict.Set("id", id.ToString());
|
|
|
|
dict.Set(
|
|
|
|
"thumbnail",
|
|
|
|
atom::api::NativeImage::Create(isolate, gfx::Image(source.thumbnail)));
|
|
|
|
return ConvertToV8(isolate, dict);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace mate
|
|
|
|
|
2015-10-02 09:50:10 +00:00
|
|
|
namespace atom {
|
|
|
|
|
|
|
|
namespace api {
|
|
|
|
|
2016-04-25 01:17:54 +00:00
|
|
|
DesktopCapturer::DesktopCapturer(v8::Isolate* isolate) {
|
|
|
|
Init(isolate);
|
2015-10-04 01:35:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DesktopCapturer::~DesktopCapturer() {
|
|
|
|
}
|
|
|
|
|
2015-12-08 05:49:26 +00:00
|
|
|
void DesktopCapturer::StartHandling(bool capture_window,
|
|
|
|
bool capture_screen,
|
|
|
|
const gfx::Size& thumbnail_size) {
|
2018-01-18 01:04:57 +00:00
|
|
|
webrtc::DesktopCaptureOptions options =
|
|
|
|
content::CreateDesktopCaptureOptions();
|
2015-10-03 02:41:08 +00:00
|
|
|
|
2017-01-23 09:47:30 +00:00
|
|
|
std::unique_ptr<webrtc::DesktopCapturer> screen_capturer(
|
|
|
|
capture_screen ? webrtc::DesktopCapturer::CreateScreenCapturer(options)
|
|
|
|
: nullptr);
|
|
|
|
std::unique_ptr<webrtc::DesktopCapturer> window_capturer(
|
|
|
|
capture_window ? webrtc::DesktopCapturer::CreateWindowCapturer(options)
|
|
|
|
: nullptr);
|
2016-03-08 14:28:53 +00:00
|
|
|
media_list_.reset(new NativeDesktopMediaList(
|
|
|
|
std::move(screen_capturer), std::move(window_capturer)));
|
2015-10-05 03:32:12 +00:00
|
|
|
|
2015-10-06 06:34:54 +00:00
|
|
|
media_list_->SetThumbnailSize(thumbnail_size);
|
2015-10-02 09:50:10 +00:00
|
|
|
media_list_->StartUpdating(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DesktopCapturer::OnSourceAdded(int index) {
|
|
|
|
}
|
|
|
|
|
|
|
|
void DesktopCapturer::OnSourceRemoved(int index) {
|
|
|
|
}
|
|
|
|
|
|
|
|
void DesktopCapturer::OnSourceMoved(int old_index, int new_index) {
|
|
|
|
}
|
|
|
|
|
|
|
|
void DesktopCapturer::OnSourceNameChanged(int index) {
|
|
|
|
}
|
|
|
|
|
|
|
|
void DesktopCapturer::OnSourceThumbnailChanged(int index) {
|
2015-10-05 03:32:12 +00:00
|
|
|
}
|
|
|
|
|
2015-10-06 06:34:54 +00:00
|
|
|
bool DesktopCapturer::OnRefreshFinished() {
|
2015-12-08 05:49:26 +00:00
|
|
|
Emit("finished", media_list_->GetSources());
|
2015-10-06 06:34:54 +00:00
|
|
|
return false;
|
2015-10-02 09:50:10 +00:00
|
|
|
}
|
|
|
|
|
2016-04-25 01:17:54 +00:00
|
|
|
// static
|
|
|
|
mate::Handle<DesktopCapturer> DesktopCapturer::Create(v8::Isolate* isolate) {
|
|
|
|
return mate::CreateHandle(isolate, new DesktopCapturer(isolate));
|
2015-10-02 09:50:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
2016-04-25 01:17:54 +00:00
|
|
|
void DesktopCapturer::BuildPrototype(
|
2016-08-02 09:08:12 +00:00
|
|
|
v8::Isolate* isolate, v8::Local<v8::FunctionTemplate> prototype) {
|
2016-08-02 10:28:12 +00:00
|
|
|
prototype->SetClassName(mate::StringToV8(isolate, "DesktopCapturer"));
|
2016-08-02 09:08:12 +00:00
|
|
|
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
|
2016-04-25 01:17:54 +00:00
|
|
|
.SetMethod("startHandling", &DesktopCapturer::StartHandling);
|
2015-10-02 09:50:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace api
|
|
|
|
|
|
|
|
} // namespace atom
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused,
|
|
|
|
v8::Local<v8::Context> context, void* priv) {
|
|
|
|
v8::Isolate* isolate = context->GetIsolate();
|
|
|
|
mate::Dictionary dict(isolate, exports);
|
2015-10-04 01:35:00 +00:00
|
|
|
dict.Set("desktopCapturer", atom::api::DesktopCapturer::Create(isolate));
|
2015-10-02 09:50:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2018-01-06 15:58:24 +00:00
|
|
|
NODE_BUILTIN_MODULE_CONTEXT_AWARE(atom_browser_desktop_capturer, Initialize);
|