2014-07-01 00:30:29 +02:00
|
|
|
// Copyright (c) 2014 The Chromium Embedded Framework Authors.
|
|
|
|
// Portions copyright (c) 2012 The Chromium Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2015-11-17 19:20:13 +01:00
|
|
|
#include "libcef/browser/osr/web_contents_view_osr.h"
|
|
|
|
|
2014-07-01 00:30:29 +02:00
|
|
|
#include "libcef/browser/browser_host_impl.h"
|
2015-11-17 19:20:13 +01:00
|
|
|
#include "libcef/browser/osr/render_widget_host_view_osr.h"
|
2014-07-01 00:30:29 +02:00
|
|
|
#include "libcef/common/drag_data_impl.h"
|
|
|
|
|
2015-07-16 23:40:01 +02:00
|
|
|
#include "content/browser/browser_plugin/browser_plugin_embedder.h"
|
|
|
|
#include "content/browser/browser_plugin/browser_plugin_guest.h"
|
|
|
|
#include "content/browser/frame_host/render_widget_host_view_guest.h"
|
|
|
|
#include "content/browser/web_contents/web_contents_impl.h"
|
2014-07-01 00:30:29 +02:00
|
|
|
#include "content/public/browser/render_widget_host.h"
|
2015-07-16 23:40:01 +02:00
|
|
|
#include "content/public/browser/user_metrics.h"
|
2014-07-01 00:30:29 +02:00
|
|
|
|
2015-11-17 19:20:13 +01:00
|
|
|
CefWebContentsViewOSR::CefWebContentsViewOSR(bool transparent)
|
|
|
|
: transparent_(transparent),
|
|
|
|
web_contents_(NULL),
|
2015-07-16 23:40:01 +02:00
|
|
|
view_(NULL),
|
|
|
|
guest_(NULL) {
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CefWebContentsViewOSR::~CefWebContentsViewOSR() {
|
|
|
|
}
|
|
|
|
|
2014-09-30 20:52:26 +02:00
|
|
|
void CefWebContentsViewOSR::set_web_contents(
|
|
|
|
content::WebContents* web_contents) {
|
|
|
|
DCHECK(!web_contents_);
|
|
|
|
web_contents_ = web_contents;
|
|
|
|
}
|
|
|
|
|
2015-07-16 23:40:01 +02:00
|
|
|
void CefWebContentsViewOSR::set_guest(content::BrowserPluginGuest* guest) {
|
|
|
|
DCHECK(!guest_);
|
|
|
|
guest_ = guest;
|
|
|
|
}
|
|
|
|
|
2014-07-01 00:30:29 +02:00
|
|
|
gfx::NativeView CefWebContentsViewOSR::GetNativeView() const {
|
|
|
|
return gfx::NativeView();
|
|
|
|
}
|
|
|
|
|
|
|
|
gfx::NativeView CefWebContentsViewOSR::GetContentNativeView() const {
|
|
|
|
return gfx::NativeView();
|
|
|
|
}
|
|
|
|
|
|
|
|
gfx::NativeWindow CefWebContentsViewOSR::GetTopLevelNativeWindow() const {
|
|
|
|
return gfx::NativeWindow();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefWebContentsViewOSR::GetContainerBounds(gfx::Rect* out) const {
|
2015-07-16 23:40:01 +02:00
|
|
|
if (guest_) {
|
|
|
|
// Based on WebContentsViewGuest::GetContainerBounds.
|
|
|
|
if (guest_->embedder_web_contents()) {
|
|
|
|
// We need embedder container's bounds to calculate our bounds.
|
|
|
|
guest_->embedder_web_contents()->GetView()->GetContainerBounds(out);
|
|
|
|
gfx::Point guest_coordinates = guest_->GetScreenCoordinates(gfx::Point());
|
|
|
|
out->Offset(guest_coordinates.x(), guest_coordinates.y());
|
|
|
|
} else {
|
|
|
|
out->set_origin(gfx::Point());
|
|
|
|
}
|
|
|
|
out->set_size(size_);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-07-01 00:30:29 +02:00
|
|
|
*out = GetViewBounds();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefWebContentsViewOSR::SizeContents(const gfx::Size& size) {
|
2015-07-16 23:40:01 +02:00
|
|
|
if (guest_) {
|
|
|
|
// Based on WebContentsViewGuest::SizeContents.
|
|
|
|
size_ = size;
|
|
|
|
content::RenderWidgetHostView* rwhv =
|
|
|
|
web_contents_->GetRenderWidgetHostView();
|
|
|
|
if (rwhv)
|
|
|
|
rwhv->SetSize(size);
|
|
|
|
}
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefWebContentsViewOSR::Focus() {
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefWebContentsViewOSR::SetInitialFocus() {
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefWebContentsViewOSR::StoreFocus() {
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefWebContentsViewOSR::RestoreFocus() {
|
|
|
|
}
|
|
|
|
|
|
|
|
content::DropData* CefWebContentsViewOSR::GetDropData() const {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
gfx::Rect CefWebContentsViewOSR::GetViewBounds() const {
|
2015-07-16 23:40:01 +02:00
|
|
|
if (guest_) {
|
|
|
|
// Based on WebContentsViewGuest::GetViewBounds.
|
|
|
|
return gfx::Rect(size_);
|
|
|
|
}
|
|
|
|
|
2014-07-01 00:30:29 +02:00
|
|
|
return view_ ? view_->GetViewBounds() : gfx::Rect();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefWebContentsViewOSR::CreateView(const gfx::Size& initial_size,
|
|
|
|
gfx::NativeView context) {
|
2015-07-16 23:40:01 +02:00
|
|
|
if (guest_) {
|
|
|
|
// Based on WebContentsViewGuest::CreateView.
|
|
|
|
size_ = initial_size;
|
|
|
|
}
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
content::RenderWidgetHostViewBase* CefWebContentsViewOSR::CreateViewForWidget(
|
2014-11-12 20:25:15 +01:00
|
|
|
content::RenderWidgetHost* render_widget_host,
|
|
|
|
bool is_guest_view_hack) {
|
2014-07-01 00:30:29 +02:00
|
|
|
if (render_widget_host->GetView()) {
|
|
|
|
return static_cast<content::RenderWidgetHostViewBase*>(
|
|
|
|
render_widget_host->GetView());
|
|
|
|
}
|
|
|
|
|
2015-07-16 23:40:01 +02:00
|
|
|
if (guest_) {
|
|
|
|
// Based on WebContentsViewGuest::CreateViewForWidget.
|
2015-08-17 21:48:57 +02:00
|
|
|
content::WebContents* embedder_web_contents =
|
|
|
|
guest_->embedder_web_contents();
|
|
|
|
CefRenderWidgetHostViewOSR* embedder_host_view =
|
|
|
|
static_cast<CefRenderWidgetHostViewOSR*>(
|
2015-11-10 21:18:16 +01:00
|
|
|
embedder_web_contents->GetRenderViewHost()->GetWidget()->GetView());
|
2015-08-17 21:48:57 +02:00
|
|
|
|
2015-07-16 23:40:01 +02:00
|
|
|
CefRenderWidgetHostViewOSR* platform_widget =
|
2015-11-17 19:20:13 +01:00
|
|
|
new CefRenderWidgetHostViewOSR(transparent_, render_widget_host,
|
|
|
|
embedder_host_view);
|
2015-08-17 21:48:57 +02:00
|
|
|
embedder_host_view->AddGuestHostView(platform_widget);
|
|
|
|
|
2015-07-16 23:40:01 +02:00
|
|
|
return new content::RenderWidgetHostViewGuest(
|
|
|
|
render_widget_host,
|
|
|
|
guest_,
|
|
|
|
platform_widget->GetWeakPtr());
|
|
|
|
}
|
|
|
|
|
2015-11-17 19:20:13 +01:00
|
|
|
view_ = new CefRenderWidgetHostViewOSR(transparent_, render_widget_host,
|
|
|
|
NULL);
|
2014-07-01 00:30:29 +02:00
|
|
|
return view_;
|
|
|
|
}
|
|
|
|
|
2015-06-11 17:00:05 +02:00
|
|
|
// Called for popup and fullscreen widgets.
|
2014-07-01 00:30:29 +02:00
|
|
|
content::RenderWidgetHostViewBase*
|
|
|
|
CefWebContentsViewOSR::CreateViewForPopupWidget(
|
|
|
|
content::RenderWidgetHost* render_widget_host) {
|
2015-11-17 19:20:13 +01:00
|
|
|
return new CefRenderWidgetHostViewOSR(transparent_, render_widget_host,
|
|
|
|
view_);
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefWebContentsViewOSR::SetPageTitle(const base::string16& title) {
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefWebContentsViewOSR::RenderViewCreated(content::RenderViewHost* host) {
|
|
|
|
if (view_)
|
|
|
|
view_->InstallTransparency();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefWebContentsViewOSR::RenderViewSwappedIn(
|
|
|
|
content::RenderViewHost* host) {
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefWebContentsViewOSR::SetOverscrollControllerEnabled(bool enabled) {
|
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(OS_MACOSX)
|
2014-09-04 19:53:40 +02:00
|
|
|
void CefWebContentsViewOSR::SetAllowOtherViews(bool allow) {
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
2014-09-04 19:53:40 +02:00
|
|
|
bool CefWebContentsViewOSR::GetAllowOtherViews() const {
|
2014-07-01 00:30:29 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefWebContentsViewOSR::IsEventTracking() const {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefWebContentsViewOSR::CloseTabAfterEventTracking() {
|
|
|
|
}
|
|
|
|
#endif // defined(OS_MACOSX)
|
|
|
|
|
|
|
|
void CefWebContentsViewOSR::StartDragging(
|
|
|
|
const content::DropData& drop_data,
|
|
|
|
blink::WebDragOperationsMask allowed_ops,
|
|
|
|
const gfx::ImageSkia& image,
|
|
|
|
const gfx::Vector2d& image_offset,
|
|
|
|
const content::DragEventSourceInfo& event_info) {
|
2015-07-16 23:40:01 +02:00
|
|
|
if (guest_) {
|
|
|
|
// Based on WebContentsViewGuest::StartDragging.
|
|
|
|
content::WebContentsImpl* embedder_web_contents =
|
|
|
|
guest_->embedder_web_contents();
|
|
|
|
embedder_web_contents->GetBrowserPluginEmbedder()->StartDrag(guest_);
|
|
|
|
content::RenderViewHostImpl* embedder_render_view_host =
|
|
|
|
static_cast<content::RenderViewHostImpl*>(
|
|
|
|
embedder_web_contents->GetRenderViewHost());
|
|
|
|
CHECK(embedder_render_view_host);
|
|
|
|
content::RenderViewHostDelegateView* view =
|
|
|
|
embedder_render_view_host->GetDelegate()->GetDelegateView();
|
|
|
|
if (view) {
|
|
|
|
content::RecordAction(
|
|
|
|
base::UserMetricsAction("BrowserPlugin.Guest.StartDrag"));
|
|
|
|
view->StartDragging(drop_data, allowed_ops, image, image_offset,
|
|
|
|
event_info);
|
|
|
|
} else {
|
|
|
|
embedder_web_contents->SystemDragEnded();
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-07-01 00:30:29 +02:00
|
|
|
CefRefPtr<CefBrowserHostImpl> browser;
|
|
|
|
CefRefPtr<CefRenderHandler> handler;
|
|
|
|
bool handled = false;
|
|
|
|
CefRenderWidgetHostViewOSR* view =
|
|
|
|
static_cast<CefRenderWidgetHostViewOSR*>(view_);
|
|
|
|
if (view)
|
|
|
|
browser = view->browser_impl();
|
|
|
|
if (browser.get())
|
|
|
|
handler = browser->GetClient()->GetRenderHandler();
|
|
|
|
if (handler.get()) {
|
|
|
|
CefRefPtr<CefDragDataImpl> drag_data(new CefDragDataImpl(drop_data));
|
|
|
|
drag_data->SetReadOnly(true);
|
|
|
|
base::MessageLoop::ScopedNestableTaskAllower allow(
|
|
|
|
base::MessageLoop::current());
|
2015-01-26 01:57:01 +01:00
|
|
|
handled = handler->StartDragging(
|
|
|
|
browser.get(),
|
2014-07-01 00:30:29 +02:00
|
|
|
drag_data.get(),
|
|
|
|
static_cast<CefRenderHandler::DragOperationsMask>(allowed_ops),
|
|
|
|
event_info.event_location.x(),
|
|
|
|
event_info.event_location.y());
|
|
|
|
}
|
|
|
|
if (!handled && web_contents_)
|
|
|
|
web_contents_->SystemDragEnded();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefWebContentsViewOSR::UpdateDragCursor(
|
|
|
|
blink::WebDragOperation operation) {
|
2015-07-16 23:40:01 +02:00
|
|
|
if (guest_) {
|
|
|
|
// Based on WebContentsViewGuest::UpdateDragCursor.
|
|
|
|
content::RenderViewHostImpl* embedder_render_view_host =
|
|
|
|
static_cast<content::RenderViewHostImpl*>(
|
|
|
|
guest_->embedder_web_contents()->GetRenderViewHost());
|
|
|
|
CHECK(embedder_render_view_host);
|
|
|
|
content::RenderViewHostDelegateView* view =
|
|
|
|
embedder_render_view_host->GetDelegate()->GetDelegateView();
|
|
|
|
if (view)
|
|
|
|
view->UpdateDragCursor(operation);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-07-01 00:30:29 +02:00
|
|
|
CefRefPtr<CefBrowserHostImpl> browser;
|
|
|
|
CefRefPtr<CefRenderHandler> handler;
|
|
|
|
CefRenderWidgetHostViewOSR* view =
|
|
|
|
static_cast<CefRenderWidgetHostViewOSR*>(view_);
|
|
|
|
if (view)
|
|
|
|
browser = view->browser_impl();
|
|
|
|
if (browser.get())
|
|
|
|
handler = browser->GetClient()->GetRenderHandler();
|
|
|
|
if (handler.get()) {
|
2015-01-26 01:57:01 +01:00
|
|
|
handler->UpdateDragCursor(
|
|
|
|
browser.get(),
|
2014-07-01 00:30:29 +02:00
|
|
|
static_cast<CefRenderHandler::DragOperation>(operation));
|
|
|
|
}
|
|
|
|
}
|