electron/atom/renderer/guest_view_container.cc

65 lines
1.8 KiB
C++
Raw Normal View History

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>
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"
2015-09-02 07:16:49 +00:00
#include "base/message_loop/message_loop.h"
#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*>;
static base::LazyInstance<GuestViewContainerMap> g_guest_view_container_map =
LAZY_INSTANCE_INITIALIZER;
} // namespace
GuestViewContainer::GuestViewContainer(content::RenderFrame* render_frame)
2016-09-06 08:24:37 +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));
}
void GuestViewContainer::DidResizeElement(const gfx::Size& new_size) {
2015-05-29 05:47:09 +00:00
if (element_resize_callback_.is_null())
return;
base::MessageLoop::current()->PostTask(
FROM_HERE, base::Bind(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