2015-03-13 23:33:06 +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/renderer/guest_view_container.h"
|
|
|
|
|
2015-05-29 05:47:09 +00:00
|
|
|
#include <map>
|
2018-09-13 00:25:56 +00:00
|
|
|
#include <utility>
|
2015-05-29 05:47:09 +00:00
|
|
|
|
2015-09-02 07:16:49 +00:00
|
|
|
#include "base/bind.h"
|
2015-05-29 05:47:09 +00:00
|
|
|
#include "base/lazy_instance.h"
|
2016-11-30 07:30:03 +00:00
|
|
|
#include "base/threading/thread_task_runner_handle.h"
|
2015-08-10 03:56:42 +00:00
|
|
|
#include "ui/gfx/geometry/size.h"
|
2015-05-29 05:47:09 +00:00
|
|
|
|
2015-03-13 23:33:06 +00:00
|
|
|
namespace atom {
|
|
|
|
|
2015-05-29 05:47:09 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
using GuestViewContainerMap = std::map<int, GuestViewContainer*>;
|
2017-06-20 19:14:39 +00:00
|
|
|
static base::LazyInstance<GuestViewContainerMap>::DestructorAtExit
|
|
|
|
g_guest_view_container_map = LAZY_INSTANCE_INITIALIZER;
|
2015-05-29 05:47:09 +00:00
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
GuestViewContainer::GuestViewContainer(content::RenderFrame* render_frame)
|
2018-04-18 01:55:30 +00:00
|
|
|
: weak_ptr_factory_(this) {}
|
2015-03-13 23:33:06 +00:00
|
|
|
|
|
|
|
GuestViewContainer::~GuestViewContainer() {
|
2015-05-29 05:47:09 +00:00
|
|
|
if (element_instance_id_ > 0)
|
|
|
|
g_guest_view_container_map.Get().erase(element_instance_id_);
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
GuestViewContainer* GuestViewContainer::FromID(int element_instance_id) {
|
|
|
|
GuestViewContainerMap* guest_view_containers =
|
|
|
|
g_guest_view_container_map.Pointer();
|
|
|
|
auto it = guest_view_containers->find(element_instance_id);
|
|
|
|
return it == guest_view_containers->end() ? nullptr : it->second;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GuestViewContainer::RegisterElementResizeCallback(
|
|
|
|
const ResizeCallback& callback) {
|
|
|
|
element_resize_callback_ = callback;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GuestViewContainer::SetElementInstanceID(int element_instance_id) {
|
|
|
|
element_instance_id_ = element_instance_id;
|
|
|
|
g_guest_view_container_map.Get().insert(
|
|
|
|
std::make_pair(element_instance_id, this));
|
|
|
|
}
|
|
|
|
|
2015-08-04 09:07:31 +00:00
|
|
|
void GuestViewContainer::DidResizeElement(const gfx::Size& new_size) {
|
2015-05-29 05:47:09 +00:00
|
|
|
if (element_resize_callback_.is_null())
|
|
|
|
return;
|
|
|
|
|
2016-11-30 07:30:03 +00:00
|
|
|
base::ThreadTaskRunnerHandle::Get()->PostTask(
|
2018-04-20 10:55:05 +00:00
|
|
|
FROM_HERE, base::BindOnce(element_resize_callback_, new_size));
|
2015-03-13 23:33:06 +00:00
|
|
|
}
|
|
|
|
|
2015-09-02 07:16:49 +00:00
|
|
|
base::WeakPtr<content::BrowserPluginDelegate> GuestViewContainer::GetWeakPtr() {
|
|
|
|
return weak_ptr_factory_.GetWeakPtr();
|
|
|
|
}
|
|
|
|
|
2015-03-13 23:33:06 +00:00
|
|
|
} // namespace atom
|