build: move pepper flash behind feature flag
This commit is contained in:
parent
8ccb5cc6eb
commit
5e2406081e
33 changed files with 39 additions and 2695 deletions
|
@ -1,99 +0,0 @@
|
|||
// 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.
|
||||
|
||||
#include "chrome/renderer/pepper/chrome_renderer_pepper_host_factory.h"
|
||||
|
||||
#include "base/logging.h"
|
||||
#include "chrome/renderer/pepper/pepper_flash_font_file_host.h"
|
||||
#include "chrome/renderer/pepper/pepper_flash_fullscreen_host.h"
|
||||
#include "chrome/renderer/pepper/pepper_flash_menu_host.h"
|
||||
#include "chrome/renderer/pepper/pepper_flash_renderer_host.h"
|
||||
#include "content/public/renderer/renderer_ppapi_host.h"
|
||||
#include "ppapi/host/ppapi_host.h"
|
||||
#include "ppapi/host/resource_host.h"
|
||||
#include "ppapi/proxy/ppapi_message_utils.h"
|
||||
#include "ppapi/proxy/ppapi_messages.h"
|
||||
#include "ppapi/shared_impl/ppapi_permissions.h"
|
||||
|
||||
#if defined(ENABLE_PDF_VIEWER)
|
||||
#include "components/pdf/renderer/pepper_pdf_host.h"
|
||||
#endif // defined(ENABLE_PDF_VIEWER)
|
||||
|
||||
using ppapi::host::ResourceHost;
|
||||
|
||||
ChromeRendererPepperHostFactory::ChromeRendererPepperHostFactory(
|
||||
content::RendererPpapiHost* host)
|
||||
: host_(host) {}
|
||||
|
||||
ChromeRendererPepperHostFactory::~ChromeRendererPepperHostFactory() {}
|
||||
|
||||
std::unique_ptr<ResourceHost>
|
||||
ChromeRendererPepperHostFactory::CreateResourceHost(
|
||||
ppapi::host::PpapiHost* host,
|
||||
PP_Resource resource,
|
||||
PP_Instance instance,
|
||||
const IPC::Message& message) {
|
||||
DCHECK_EQ(host_->GetPpapiHost(), host);
|
||||
|
||||
// Make sure the plugin is giving us a valid instance for this resource.
|
||||
if (!host_->IsValidInstance(instance))
|
||||
return std::unique_ptr<ResourceHost>();
|
||||
|
||||
if (host_->GetPpapiHost()->permissions().HasPermission(
|
||||
ppapi::PERMISSION_FLASH)) {
|
||||
switch (message.type()) {
|
||||
case PpapiHostMsg_Flash_Create::ID: {
|
||||
return std::unique_ptr<ResourceHost>(
|
||||
new PepperFlashRendererHost(host_, instance, resource));
|
||||
}
|
||||
case PpapiHostMsg_FlashFullscreen_Create::ID: {
|
||||
return std::unique_ptr<ResourceHost>(
|
||||
new PepperFlashFullscreenHost(host_, instance, resource));
|
||||
}
|
||||
case PpapiHostMsg_FlashMenu_Create::ID: {
|
||||
ppapi::proxy::SerializedFlashMenu serialized_menu;
|
||||
if (ppapi::UnpackMessage<PpapiHostMsg_FlashMenu_Create>(
|
||||
message, &serialized_menu)) {
|
||||
return std::unique_ptr<ResourceHost>(new PepperFlashMenuHost(
|
||||
host_, instance, resource, serialized_menu));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO(raymes): PDF also needs access to the FlashFontFileHost currently.
|
||||
// We should either rename PPB_FlashFont_File to PPB_FontFile_Private or get
|
||||
// rid of its use in PDF if possible.
|
||||
if (host_->GetPpapiHost()->permissions().HasPermission(
|
||||
ppapi::PERMISSION_FLASH) ||
|
||||
host_->GetPpapiHost()->permissions().HasPermission(
|
||||
ppapi::PERMISSION_PRIVATE)) {
|
||||
switch (message.type()) {
|
||||
case PpapiHostMsg_FlashFontFile_Create::ID: {
|
||||
ppapi::proxy::SerializedFontDescription description;
|
||||
PP_PrivateFontCharset charset;
|
||||
if (ppapi::UnpackMessage<PpapiHostMsg_FlashFontFile_Create>(
|
||||
message, &description, &charset)) {
|
||||
return std::unique_ptr<ResourceHost>(new PepperFlashFontFileHost(
|
||||
host_, instance, resource, description, charset));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(ENABLE_PDF_VIEWER)
|
||||
if (host_->GetPpapiHost()->permissions().HasPermission(
|
||||
ppapi::PERMISSION_PRIVATE)) {
|
||||
switch (message.type()) {
|
||||
case PpapiHostMsg_PDF_Create::ID: {
|
||||
return std::make_unique<pdf::PepperPDFHost>(host_, instance, resource);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif // defined(ENABLE_PDF_VIEWER)
|
||||
|
||||
return std::unique_ptr<ResourceHost>();
|
||||
}
|
|
@ -1,34 +0,0 @@
|
|||
// 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.
|
||||
|
||||
#ifndef CHROME_RENDERER_PEPPER_CHROME_RENDERER_PEPPER_HOST_FACTORY_H_
|
||||
#define CHROME_RENDERER_PEPPER_CHROME_RENDERER_PEPPER_HOST_FACTORY_H_
|
||||
|
||||
#include "base/macros.h"
|
||||
#include "ppapi/host/host_factory.h"
|
||||
|
||||
namespace content {
|
||||
class RendererPpapiHost;
|
||||
}
|
||||
|
||||
class ChromeRendererPepperHostFactory : public ppapi::host::HostFactory {
|
||||
public:
|
||||
explicit ChromeRendererPepperHostFactory(content::RendererPpapiHost* host);
|
||||
~ChromeRendererPepperHostFactory() override;
|
||||
|
||||
// HostFactory.
|
||||
std::unique_ptr<ppapi::host::ResourceHost> CreateResourceHost(
|
||||
ppapi::host::PpapiHost* host,
|
||||
PP_Resource resource,
|
||||
PP_Instance instance,
|
||||
const IPC::Message& message) override;
|
||||
|
||||
private:
|
||||
// Not owned by this object.
|
||||
content::RendererPpapiHost* host_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(ChromeRendererPepperHostFactory);
|
||||
};
|
||||
|
||||
#endif // CHROME_RENDERER_PEPPER_CHROME_RENDERER_PEPPER_HOST_FACTORY_H_
|
|
@ -1,105 +0,0 @@
|
|||
// 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.
|
||||
|
||||
#include "chrome/renderer/pepper/pepper_flash_font_file_host.h"
|
||||
|
||||
#include "base/sys_byteorder.h"
|
||||
#include "build/build_config.h"
|
||||
#include "content/public/renderer/renderer_ppapi_host.h"
|
||||
#include "ppapi/c/pp_errors.h"
|
||||
#include "ppapi/host/dispatch_host_message.h"
|
||||
#include "ppapi/host/host_message_context.h"
|
||||
#include "ppapi/host/ppapi_host.h"
|
||||
#include "ppapi/proxy/ppapi_messages.h"
|
||||
#include "ppapi/proxy/serialized_structs.h"
|
||||
|
||||
#if defined(OS_LINUX) || defined(OS_OPENBSD)
|
||||
#include "content/public/child/child_process_sandbox_support_linux.h"
|
||||
#include "content/public/common/common_sandbox_support_linux.h"
|
||||
#elif defined(OS_WIN)
|
||||
#include "third_party/skia/include/ports/SkFontMgr.h"
|
||||
#endif
|
||||
|
||||
PepperFlashFontFileHost::PepperFlashFontFileHost(
|
||||
content::RendererPpapiHost* host,
|
||||
PP_Instance instance,
|
||||
PP_Resource resource,
|
||||
const ppapi::proxy::SerializedFontDescription& description,
|
||||
PP_PrivateFontCharset charset)
|
||||
: ResourceHost(host->GetPpapiHost(), instance, resource) {
|
||||
#if defined(OS_LINUX) || defined(OS_OPENBSD)
|
||||
fd_.reset(content::MatchFontWithFallback(
|
||||
description.face.c_str(),
|
||||
description.weight >= PP_BROWSERFONT_TRUSTED_WEIGHT_BOLD,
|
||||
description.italic, charset, PP_BROWSERFONT_TRUSTED_FAMILY_DEFAULT));
|
||||
#elif defined(OS_WIN) // defined(OS_LINUX) || defined(OS_OPENBSD)
|
||||
int weight = description.weight;
|
||||
if (weight == FW_DONTCARE)
|
||||
weight = SkFontStyle::kNormal_Weight;
|
||||
SkFontStyle style(weight, SkFontStyle::kNormal_Width,
|
||||
description.italic ? SkFontStyle::kItalic_Slant
|
||||
: SkFontStyle::kUpright_Slant);
|
||||
sk_sp<SkFontMgr> font_mgr(SkFontMgr::RefDefault());
|
||||
typeface_ = sk_sp<SkTypeface>(
|
||||
font_mgr->matchFamilyStyle(description.face.c_str(), style));
|
||||
#endif // defined(OS_WIN)
|
||||
}
|
||||
|
||||
PepperFlashFontFileHost::~PepperFlashFontFileHost() {}
|
||||
|
||||
int32_t PepperFlashFontFileHost::OnResourceMessageReceived(
|
||||
const IPC::Message& msg,
|
||||
ppapi::host::HostMessageContext* context) {
|
||||
PPAPI_BEGIN_MESSAGE_MAP(PepperFlashFontFileHost, msg)
|
||||
PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_FlashFontFile_GetFontTable,
|
||||
OnGetFontTable)
|
||||
PPAPI_END_MESSAGE_MAP()
|
||||
return PP_ERROR_FAILED;
|
||||
}
|
||||
bool PepperFlashFontFileHost::GetFontData(uint32_t table,
|
||||
void* buffer,
|
||||
size_t* length) {
|
||||
bool result = false;
|
||||
#if defined(OS_LINUX) || defined(OS_OPENBSD)
|
||||
int fd = fd_.get();
|
||||
if (fd != -1)
|
||||
result = content::GetFontTable(fd, table, 0 /* offset */,
|
||||
reinterpret_cast<uint8_t*>(buffer), length);
|
||||
#elif defined(OS_WIN)
|
||||
if (typeface_) {
|
||||
table = base::ByteSwap(table);
|
||||
if (buffer == NULL) {
|
||||
*length = typeface_->getTableSize(table);
|
||||
if (*length > 0)
|
||||
result = true;
|
||||
} else {
|
||||
size_t new_length = typeface_->getTableData(table, 0, *length, buffer);
|
||||
if (new_length == *length)
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return result;
|
||||
}
|
||||
|
||||
int32_t PepperFlashFontFileHost::OnGetFontTable(
|
||||
ppapi::host::HostMessageContext* context,
|
||||
uint32_t table) {
|
||||
std::string contents;
|
||||
int32_t result = PP_ERROR_FAILED;
|
||||
size_t length = 0;
|
||||
if (GetFontData(table, NULL, &length)) {
|
||||
contents.resize(length);
|
||||
uint8_t* contents_ptr =
|
||||
reinterpret_cast<uint8_t*>(const_cast<char*>(contents.c_str()));
|
||||
if (GetFontData(table, contents_ptr, &length)) {
|
||||
result = PP_OK;
|
||||
} else {
|
||||
contents.clear();
|
||||
}
|
||||
}
|
||||
|
||||
context->reply_msg = PpapiPluginMsg_FlashFontFile_GetFontTableReply(contents);
|
||||
return result;
|
||||
}
|
|
@ -1,56 +0,0 @@
|
|||
// 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.
|
||||
|
||||
#ifndef CHROME_RENDERER_PEPPER_PEPPER_FLASH_FONT_FILE_HOST_H_
|
||||
#define CHROME_RENDERER_PEPPER_PEPPER_FLASH_FONT_FILE_HOST_H_
|
||||
|
||||
#include "ppapi/c/private/pp_private_font_charset.h"
|
||||
#include "ppapi/host/resource_host.h"
|
||||
|
||||
#if defined(OS_LINUX) || defined(OS_OPENBSD)
|
||||
#include "base/files/scoped_file.h"
|
||||
#elif defined(OS_WIN)
|
||||
#include "third_party/skia/include/core/SkRefCnt.h"
|
||||
#include "third_party/skia/include/core/SkTypeface.h"
|
||||
#endif
|
||||
|
||||
namespace content {
|
||||
class RendererPpapiHost;
|
||||
}
|
||||
|
||||
namespace ppapi {
|
||||
namespace proxy {
|
||||
struct SerializedFontDescription;
|
||||
}
|
||||
} // namespace ppapi
|
||||
|
||||
class PepperFlashFontFileHost : public ppapi::host::ResourceHost {
|
||||
public:
|
||||
PepperFlashFontFileHost(
|
||||
content::RendererPpapiHost* host,
|
||||
PP_Instance instance,
|
||||
PP_Resource resource,
|
||||
const ppapi::proxy::SerializedFontDescription& description,
|
||||
PP_PrivateFontCharset charset);
|
||||
~PepperFlashFontFileHost() override;
|
||||
|
||||
int32_t OnResourceMessageReceived(
|
||||
const IPC::Message& msg,
|
||||
ppapi::host::HostMessageContext* context) override;
|
||||
|
||||
private:
|
||||
int32_t OnGetFontTable(ppapi::host::HostMessageContext* context,
|
||||
uint32_t table);
|
||||
bool GetFontData(uint32_t table, void* buffer, size_t* length);
|
||||
|
||||
#if defined(OS_LINUX) || defined(OS_OPENBSD)
|
||||
base::ScopedFD fd_;
|
||||
#elif defined(OS_WIN)
|
||||
sk_sp<SkTypeface> typeface_;
|
||||
#endif
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(PepperFlashFontFileHost);
|
||||
};
|
||||
|
||||
#endif // CHROME_RENDERER_PEPPER_PEPPER_FLASH_FONT_FILE_HOST_H_
|
|
@ -1,42 +0,0 @@
|
|||
// 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.
|
||||
|
||||
#include "chrome/renderer/pepper/pepper_flash_fullscreen_host.h"
|
||||
|
||||
#include "content/public/renderer/pepper_plugin_instance.h"
|
||||
#include "content/public/renderer/renderer_ppapi_host.h"
|
||||
#include "ppapi/c/pp_errors.h"
|
||||
#include "ppapi/host/dispatch_host_message.h"
|
||||
#include "ppapi/host/host_message_context.h"
|
||||
#include "ppapi/host/ppapi_host.h"
|
||||
#include "ppapi/proxy/ppapi_messages.h"
|
||||
|
||||
PepperFlashFullscreenHost::PepperFlashFullscreenHost(
|
||||
content::RendererPpapiHost* host,
|
||||
PP_Instance instance,
|
||||
PP_Resource resource)
|
||||
: ResourceHost(host->GetPpapiHost(), instance, resource),
|
||||
renderer_ppapi_host_(host) {}
|
||||
|
||||
PepperFlashFullscreenHost::~PepperFlashFullscreenHost() {}
|
||||
|
||||
int32_t PepperFlashFullscreenHost::OnResourceMessageReceived(
|
||||
const IPC::Message& msg,
|
||||
ppapi::host::HostMessageContext* context) {
|
||||
PPAPI_BEGIN_MESSAGE_MAP(PepperFlashFullscreenHost, msg)
|
||||
PPAPI_DISPATCH_HOST_RESOURCE_CALL(
|
||||
PpapiHostMsg_FlashFullscreen_SetFullscreen, OnSetFullscreen)
|
||||
PPAPI_END_MESSAGE_MAP()
|
||||
return PP_ERROR_FAILED;
|
||||
}
|
||||
|
||||
int32_t PepperFlashFullscreenHost::OnSetFullscreen(
|
||||
ppapi::host::HostMessageContext* context,
|
||||
bool fullscreen) {
|
||||
content::PepperPluginInstance* plugin_instance =
|
||||
renderer_ppapi_host_->GetPluginInstance(pp_instance());
|
||||
if (plugin_instance && plugin_instance->FlashSetFullscreen(fullscreen, true))
|
||||
return PP_OK;
|
||||
return PP_ERROR_FAILED;
|
||||
}
|
|
@ -1,35 +0,0 @@
|
|||
// 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.
|
||||
|
||||
#ifndef CHROME_RENDERER_PEPPER_PEPPER_FLASH_FULLSCREEN_HOST_H_
|
||||
#define CHROME_RENDERER_PEPPER_PEPPER_FLASH_FULLSCREEN_HOST_H_
|
||||
|
||||
#include "ppapi/host/resource_host.h"
|
||||
|
||||
namespace content {
|
||||
class RendererPpapiHost;
|
||||
}
|
||||
|
||||
class PepperFlashFullscreenHost : public ppapi::host::ResourceHost {
|
||||
public:
|
||||
PepperFlashFullscreenHost(content::RendererPpapiHost* host,
|
||||
PP_Instance instance,
|
||||
PP_Resource resource);
|
||||
~PepperFlashFullscreenHost() override;
|
||||
|
||||
int32_t OnResourceMessageReceived(
|
||||
const IPC::Message& msg,
|
||||
ppapi::host::HostMessageContext* context) override;
|
||||
|
||||
private:
|
||||
int32_t OnSetFullscreen(ppapi::host::HostMessageContext* context,
|
||||
bool fullscreen);
|
||||
|
||||
// Non-owning pointer.
|
||||
content::RendererPpapiHost* renderer_ppapi_host_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(PepperFlashFullscreenHost);
|
||||
};
|
||||
|
||||
#endif // CHROME_RENDERER_PEPPER_PEPPER_FLASH_FULLSCREEN_HOST_H_
|
|
@ -1,201 +0,0 @@
|
|||
// 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.
|
||||
|
||||
#include "chrome/renderer/pepper/pepper_flash_menu_host.h"
|
||||
|
||||
#include "base/strings/utf_string_conversions.h"
|
||||
#include "content/public/common/context_menu_params.h"
|
||||
#include "content/public/renderer/render_frame.h"
|
||||
#include "content/public/renderer/renderer_ppapi_host.h"
|
||||
#include "ipc/ipc_message.h"
|
||||
#include "ppapi/c/private/ppb_flash_menu.h"
|
||||
#include "ppapi/host/dispatch_host_message.h"
|
||||
#include "ppapi/host/ppapi_host.h"
|
||||
#include "ppapi/proxy/ppapi_messages.h"
|
||||
#include "ppapi/proxy/serialized_flash_menu.h"
|
||||
#include "ui/gfx/geometry/point.h"
|
||||
|
||||
namespace {
|
||||
|
||||
// Maximum depth of submenus allowed (e.g., 1 indicates that submenus are
|
||||
// allowed, but not sub-submenus).
|
||||
const size_t kMaxMenuDepth = 2;
|
||||
|
||||
// Maximum number of entries in any single menu (including separators).
|
||||
const size_t kMaxMenuEntries = 50;
|
||||
|
||||
// Maximum total number of entries in the |menu_id_map| (see below).
|
||||
// (Limit to 500 real entries; reserve the 0 action as an invalid entry.)
|
||||
const size_t kMaxMenuIdMapEntries = 501;
|
||||
|
||||
// Converts menu data from one form to another.
|
||||
// - |depth| is the current nested depth (call it starting with 0).
|
||||
// - |menu_id_map| is such that |menu_id_map[output_item.action] ==
|
||||
// input_item.id| (where |action| is what a |MenuItem| has, |id| is what a
|
||||
// |PP_Flash_MenuItem| has).
|
||||
bool ConvertMenuData(const PP_Flash_Menu* in_menu,
|
||||
size_t depth,
|
||||
std::vector<content::MenuItem>* out_menu,
|
||||
std::vector<int32_t>* menu_id_map) {
|
||||
if (depth > kMaxMenuDepth || !in_menu)
|
||||
return false;
|
||||
|
||||
// Clear the output, just in case.
|
||||
out_menu->clear();
|
||||
|
||||
if (!in_menu->count)
|
||||
return true; // Nothing else to do.
|
||||
|
||||
if (!in_menu->items || in_menu->count > kMaxMenuEntries)
|
||||
return false;
|
||||
for (uint32_t i = 0; i < in_menu->count; i++) {
|
||||
content::MenuItem item;
|
||||
|
||||
PP_Flash_MenuItem_Type type = in_menu->items[i].type;
|
||||
switch (type) {
|
||||
case PP_FLASH_MENUITEM_TYPE_NORMAL:
|
||||
item.type = content::MenuItem::OPTION;
|
||||
break;
|
||||
case PP_FLASH_MENUITEM_TYPE_CHECKBOX:
|
||||
item.type = content::MenuItem::CHECKABLE_OPTION;
|
||||
break;
|
||||
case PP_FLASH_MENUITEM_TYPE_SEPARATOR:
|
||||
item.type = content::MenuItem::SEPARATOR;
|
||||
break;
|
||||
case PP_FLASH_MENUITEM_TYPE_SUBMENU:
|
||||
item.type = content::MenuItem::SUBMENU;
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
if (in_menu->items[i].name)
|
||||
item.label = base::UTF8ToUTF16(in_menu->items[i].name);
|
||||
if (menu_id_map->size() >= kMaxMenuIdMapEntries)
|
||||
return false;
|
||||
item.action = static_cast<unsigned>(menu_id_map->size());
|
||||
// This sets |(*menu_id_map)[item.action] = in_menu->items[i].id|.
|
||||
menu_id_map->push_back(in_menu->items[i].id);
|
||||
item.enabled = PP_ToBool(in_menu->items[i].enabled);
|
||||
item.checked = PP_ToBool(in_menu->items[i].checked);
|
||||
if (type == PP_FLASH_MENUITEM_TYPE_SUBMENU) {
|
||||
if (!ConvertMenuData(in_menu->items[i].submenu, depth + 1, &item.submenu,
|
||||
menu_id_map))
|
||||
return false;
|
||||
}
|
||||
|
||||
out_menu->push_back(item);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
PepperFlashMenuHost::PepperFlashMenuHost(
|
||||
content::RendererPpapiHost* host,
|
||||
PP_Instance instance,
|
||||
PP_Resource resource,
|
||||
const ppapi::proxy::SerializedFlashMenu& serial_menu)
|
||||
: ppapi::host::ResourceHost(host->GetPpapiHost(), instance, resource),
|
||||
renderer_ppapi_host_(host),
|
||||
showing_context_menu_(false),
|
||||
context_menu_request_id_(0),
|
||||
has_saved_context_menu_action_(false),
|
||||
saved_context_menu_action_(0) {
|
||||
menu_id_map_.push_back(0); // Reserve |menu_id_map_[0]|.
|
||||
if (!ConvertMenuData(serial_menu.pp_menu(), 0, &menu_data_, &menu_id_map_)) {
|
||||
menu_data_.clear();
|
||||
menu_id_map_.clear();
|
||||
}
|
||||
}
|
||||
|
||||
PepperFlashMenuHost::~PepperFlashMenuHost() {
|
||||
if (showing_context_menu_) {
|
||||
content::RenderFrame* render_frame =
|
||||
renderer_ppapi_host_->GetRenderFrameForInstance(pp_instance());
|
||||
if (render_frame)
|
||||
render_frame->CancelContextMenu(context_menu_request_id_);
|
||||
}
|
||||
}
|
||||
|
||||
int32_t PepperFlashMenuHost::OnResourceMessageReceived(
|
||||
const IPC::Message& msg,
|
||||
ppapi::host::HostMessageContext* context) {
|
||||
PPAPI_BEGIN_MESSAGE_MAP(PepperFlashMenuHost, msg)
|
||||
PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_FlashMenu_Show,
|
||||
OnHostMsgShow)
|
||||
PPAPI_END_MESSAGE_MAP()
|
||||
return PP_ERROR_FAILED;
|
||||
}
|
||||
|
||||
int32_t PepperFlashMenuHost::OnHostMsgShow(
|
||||
ppapi::host::HostMessageContext* context,
|
||||
const PP_Point& location) {
|
||||
// Note that all early returns must do a SendMenuReply. The sync result for
|
||||
// this message isn't used, so to forward the error to the plugin, we need to
|
||||
// additionally call SendMenuReply explicitly.
|
||||
if (menu_data_.empty()) {
|
||||
SendMenuReply(PP_ERROR_FAILED, -1);
|
||||
return PP_ERROR_FAILED;
|
||||
}
|
||||
if (showing_context_menu_) {
|
||||
SendMenuReply(PP_ERROR_INPROGRESS, -1);
|
||||
return PP_ERROR_INPROGRESS;
|
||||
}
|
||||
|
||||
content::RenderFrame* render_frame =
|
||||
renderer_ppapi_host_->GetRenderFrameForInstance(pp_instance());
|
||||
|
||||
content::ContextMenuParams params;
|
||||
params.x = location.x;
|
||||
params.y = location.y;
|
||||
params.custom_context.is_pepper_menu = true;
|
||||
params.custom_context.render_widget_id =
|
||||
renderer_ppapi_host_->GetRoutingIDForWidget(pp_instance());
|
||||
params.custom_items = menu_data_;
|
||||
|
||||
// Transform the position to be in render frame's coordinates.
|
||||
gfx::Point render_frame_pt = renderer_ppapi_host_->PluginPointToRenderFrame(
|
||||
pp_instance(), gfx::Point(location.x, location.y));
|
||||
params.x = render_frame_pt.x();
|
||||
params.y = render_frame_pt.y();
|
||||
|
||||
showing_context_menu_ = true;
|
||||
context_menu_request_id_ = render_frame->ShowContextMenu(this, params);
|
||||
|
||||
// Note: the show message is sync so this OK is for the sync reply which we
|
||||
// don't actually use (see the comment in the resource file for this). The
|
||||
// async message containing the context menu action will be sent in the
|
||||
// future.
|
||||
return PP_OK;
|
||||
}
|
||||
|
||||
void PepperFlashMenuHost::OnMenuAction(int request_id, unsigned action) {
|
||||
// Just save the action.
|
||||
DCHECK(!has_saved_context_menu_action_);
|
||||
has_saved_context_menu_action_ = true;
|
||||
saved_context_menu_action_ = action;
|
||||
}
|
||||
|
||||
void PepperFlashMenuHost::OnMenuClosed(int request_id) {
|
||||
if (has_saved_context_menu_action_ &&
|
||||
saved_context_menu_action_ < menu_id_map_.size()) {
|
||||
SendMenuReply(PP_OK, menu_id_map_[saved_context_menu_action_]);
|
||||
has_saved_context_menu_action_ = false;
|
||||
saved_context_menu_action_ = 0;
|
||||
} else {
|
||||
SendMenuReply(PP_ERROR_USERCANCEL, -1);
|
||||
}
|
||||
|
||||
showing_context_menu_ = false;
|
||||
context_menu_request_id_ = 0;
|
||||
}
|
||||
|
||||
void PepperFlashMenuHost::SendMenuReply(int32_t result, int action) {
|
||||
ppapi::host::ReplyMessageContext reply_context(
|
||||
ppapi::proxy::ResourceMessageReplyParams(pp_resource(), 0), NULL,
|
||||
MSG_ROUTING_NONE);
|
||||
reply_context.params.set_result(result);
|
||||
host()->SendReply(reply_context, PpapiPluginMsg_FlashMenu_ShowReply(action));
|
||||
}
|
|
@ -1,69 +0,0 @@
|
|||
// 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.
|
||||
|
||||
#ifndef CHROME_RENDERER_PEPPER_PEPPER_FLASH_MENU_HOST_H_
|
||||
#define CHROME_RENDERER_PEPPER_PEPPER_FLASH_MENU_HOST_H_
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "base/compiler_specific.h"
|
||||
#include "content/public/renderer/context_menu_client.h"
|
||||
#include "ppapi/c/pp_point.h"
|
||||
#include "ppapi/host/host_message_context.h"
|
||||
#include "ppapi/host/resource_host.h"
|
||||
|
||||
namespace content {
|
||||
class RendererPpapiHost;
|
||||
struct MenuItem;
|
||||
} // namespace content
|
||||
|
||||
namespace ppapi {
|
||||
namespace proxy {
|
||||
class SerializedFlashMenu;
|
||||
}
|
||||
} // namespace ppapi
|
||||
|
||||
class PepperFlashMenuHost : public ppapi::host::ResourceHost,
|
||||
public content::ContextMenuClient {
|
||||
public:
|
||||
PepperFlashMenuHost(content::RendererPpapiHost* host,
|
||||
PP_Instance instance,
|
||||
PP_Resource resource,
|
||||
const ppapi::proxy::SerializedFlashMenu& serial_menu);
|
||||
~PepperFlashMenuHost() override;
|
||||
|
||||
int32_t OnResourceMessageReceived(
|
||||
const IPC::Message& msg,
|
||||
ppapi::host::HostMessageContext* context) override;
|
||||
|
||||
private:
|
||||
int32_t OnHostMsgShow(ppapi::host::HostMessageContext* context,
|
||||
const PP_Point& location);
|
||||
|
||||
// ContextMenuClient implementation.
|
||||
void OnMenuAction(int request_id, unsigned action) override;
|
||||
void OnMenuClosed(int request_id) override;
|
||||
|
||||
void SendMenuReply(int32_t result, int action);
|
||||
|
||||
content::RendererPpapiHost* renderer_ppapi_host_;
|
||||
|
||||
bool showing_context_menu_;
|
||||
int context_menu_request_id_;
|
||||
|
||||
std::vector<content::MenuItem> menu_data_;
|
||||
|
||||
// We send |MenuItem|s, which have an |unsigned| "action" field instead of
|
||||
// an |int32_t| ID. (CONTENT also limits the range of valid values for
|
||||
// actions.) This maps actions to IDs.
|
||||
std::vector<int32_t> menu_id_map_;
|
||||
|
||||
// Used to send a single context menu "completion" upon menu close.
|
||||
bool has_saved_context_menu_action_;
|
||||
unsigned saved_context_menu_action_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(PepperFlashMenuHost);
|
||||
};
|
||||
|
||||
#endif // CHROME_RENDERER_PEPPER_PEPPER_FLASH_MENU_HOST_H_
|
|
@ -1,370 +0,0 @@
|
|||
// 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.
|
||||
|
||||
#include "chrome/renderer/pepper/pepper_flash_renderer_host.h"
|
||||
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
#include "base/lazy_instance.h"
|
||||
#include "base/macros.h"
|
||||
#include "base/metrics/histogram_macros.h"
|
||||
#include "base/strings/string_util.h"
|
||||
#include "content/public/renderer/pepper_plugin_instance.h"
|
||||
#include "content/public/renderer/render_thread.h"
|
||||
#include "content/public/renderer/renderer_ppapi_host.h"
|
||||
#include "ipc/ipc_message_macros.h"
|
||||
#include "net/http/http_util.h"
|
||||
#include "ppapi/c/pp_errors.h"
|
||||
#include "ppapi/c/trusted/ppb_browser_font_trusted.h"
|
||||
#include "ppapi/host/dispatch_host_message.h"
|
||||
#include "ppapi/proxy/host_dispatcher.h"
|
||||
#include "ppapi/proxy/ppapi_messages.h"
|
||||
#include "ppapi/proxy/resource_message_params.h"
|
||||
#include "ppapi/proxy/serialized_structs.h"
|
||||
#include "ppapi/thunk/enter.h"
|
||||
#include "ppapi/thunk/ppb_image_data_api.h"
|
||||
#include "skia/ext/platform_canvas.h"
|
||||
#include "third_party/skia/include/core/SkCanvas.h"
|
||||
#include "third_party/skia/include/core/SkFontStyle.h"
|
||||
#include "third_party/skia/include/core/SkMatrix.h"
|
||||
#include "third_party/skia/include/core/SkPaint.h"
|
||||
#include "third_party/skia/include/core/SkPoint.h"
|
||||
#include "third_party/skia/include/core/SkTypeface.h"
|
||||
#include "ui/gfx/geometry/rect.h"
|
||||
#include "url/gurl.h"
|
||||
|
||||
using ppapi::thunk::EnterResourceNoLock;
|
||||
using ppapi::thunk::PPB_ImageData_API;
|
||||
|
||||
namespace {
|
||||
|
||||
// Some non-simple HTTP request headers that Flash may set.
|
||||
// (Please see http://www.w3.org/TR/cors/#simple-header for the definition of
|
||||
// simple headers.)
|
||||
//
|
||||
// The list and the enum defined below are used to collect data about request
|
||||
// headers used in PPB_Flash.Navigate() calls, in order to understand the impact
|
||||
// of rejecting PPB_Flash.Navigate() requests with non-simple headers.
|
||||
//
|
||||
// TODO(yzshen): We should be able to remove the histogram recording code once
|
||||
// we get the answer.
|
||||
const char* const kRejectedHttpRequestHeaders[] = {
|
||||
"authorization", //
|
||||
"cache-control", //
|
||||
"content-encoding", //
|
||||
"content-md5", //
|
||||
"content-type", // If the media type is not one of those covered by the
|
||||
// simple header definition.
|
||||
"expires", //
|
||||
"from", //
|
||||
"if-match", //
|
||||
"if-none-match", //
|
||||
"if-range", //
|
||||
"if-unmodified-since", //
|
||||
"pragma", //
|
||||
"referer" //
|
||||
};
|
||||
|
||||
// Please note that new entries should be added right above
|
||||
// FLASH_NAVIGATE_USAGE_ENUM_COUNT, and existing entries shouldn't be re-ordered
|
||||
// or removed, since this ordering is used in a histogram.
|
||||
enum FlashNavigateUsage {
|
||||
// This section must be in the same order as kRejectedHttpRequestHeaders.
|
||||
REJECT_AUTHORIZATION = 0,
|
||||
REJECT_CACHE_CONTROL,
|
||||
REJECT_CONTENT_ENCODING,
|
||||
REJECT_CONTENT_MD5,
|
||||
REJECT_CONTENT_TYPE,
|
||||
REJECT_EXPIRES,
|
||||
REJECT_FROM,
|
||||
REJECT_IF_MATCH,
|
||||
REJECT_IF_NONE_MATCH,
|
||||
REJECT_IF_RANGE,
|
||||
REJECT_IF_UNMODIFIED_SINCE,
|
||||
REJECT_PRAGMA,
|
||||
REJECT_REFERER,
|
||||
|
||||
// The navigate request is rejected because of headers not listed above
|
||||
// (e.g., custom headers).
|
||||
REJECT_OTHER_HEADERS,
|
||||
|
||||
// Total number of rejected navigate requests.
|
||||
TOTAL_REJECTED_NAVIGATE_REQUESTS,
|
||||
|
||||
// Total number of navigate requests.
|
||||
TOTAL_NAVIGATE_REQUESTS,
|
||||
FLASH_NAVIGATE_USAGE_ENUM_COUNT
|
||||
};
|
||||
|
||||
static base::LazyInstance<std::map<std::string, FlashNavigateUsage>>::
|
||||
DestructorAtExit g_rejected_headers = LAZY_INSTANCE_INITIALIZER;
|
||||
|
||||
bool IsSimpleHeader(const std::string& lower_case_header_name,
|
||||
const std::string& header_value) {
|
||||
if (lower_case_header_name == "accept" ||
|
||||
lower_case_header_name == "accept-language" ||
|
||||
lower_case_header_name == "content-language") {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (lower_case_header_name == "content-type") {
|
||||
std::string lower_case_mime_type;
|
||||
std::string lower_case_charset;
|
||||
bool had_charset = false;
|
||||
net::HttpUtil::ParseContentType(header_value, &lower_case_mime_type,
|
||||
&lower_case_charset, &had_charset, NULL);
|
||||
return lower_case_mime_type == "application/x-www-form-urlencoded" ||
|
||||
lower_case_mime_type == "multipart/form-data" ||
|
||||
lower_case_mime_type == "text/plain";
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void RecordFlashNavigateUsage(FlashNavigateUsage usage) {
|
||||
DCHECK_NE(FLASH_NAVIGATE_USAGE_ENUM_COUNT, usage);
|
||||
UMA_HISTOGRAM_ENUMERATION("Plugin.FlashNavigateUsage", usage,
|
||||
FLASH_NAVIGATE_USAGE_ENUM_COUNT);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
PepperFlashRendererHost::PepperFlashRendererHost(
|
||||
content::RendererPpapiHost* host,
|
||||
PP_Instance instance,
|
||||
PP_Resource resource)
|
||||
: ResourceHost(host->GetPpapiHost(), instance, resource),
|
||||
host_(host),
|
||||
weak_factory_(this) {}
|
||||
|
||||
PepperFlashRendererHost::~PepperFlashRendererHost() {
|
||||
// This object may be destroyed in the middle of a sync message. If that is
|
||||
// the case, make sure we respond to all the pending navigate calls.
|
||||
std::vector<ppapi::host::ReplyMessageContext>::reverse_iterator it;
|
||||
for (it = navigate_replies_.rbegin(); it != navigate_replies_.rend(); ++it)
|
||||
SendReply(*it, IPC::Message());
|
||||
}
|
||||
|
||||
int32_t PepperFlashRendererHost::OnResourceMessageReceived(
|
||||
const IPC::Message& msg,
|
||||
ppapi::host::HostMessageContext* context) {
|
||||
PPAPI_BEGIN_MESSAGE_MAP(PepperFlashRendererHost, msg)
|
||||
PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_Flash_GetProxyForURL,
|
||||
OnGetProxyForURL)
|
||||
PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_Flash_SetInstanceAlwaysOnTop,
|
||||
OnSetInstanceAlwaysOnTop)
|
||||
PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_Flash_DrawGlyphs,
|
||||
OnDrawGlyphs)
|
||||
PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_Flash_Navigate, OnNavigate)
|
||||
PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_Flash_IsRectTopmost,
|
||||
OnIsRectTopmost)
|
||||
PPAPI_END_MESSAGE_MAP()
|
||||
return PP_ERROR_FAILED;
|
||||
}
|
||||
|
||||
int32_t PepperFlashRendererHost::OnGetProxyForURL(
|
||||
ppapi::host::HostMessageContext* host_context,
|
||||
const std::string& url) {
|
||||
GURL gurl(url);
|
||||
if (!gurl.is_valid())
|
||||
return PP_ERROR_FAILED;
|
||||
std::string proxy;
|
||||
bool result = content::RenderThread::Get()->ResolveProxy(gurl, &proxy);
|
||||
if (!result)
|
||||
return PP_ERROR_FAILED;
|
||||
host_context->reply_msg = PpapiPluginMsg_Flash_GetProxyForURLReply(proxy);
|
||||
return PP_OK;
|
||||
}
|
||||
|
||||
int32_t PepperFlashRendererHost::OnSetInstanceAlwaysOnTop(
|
||||
ppapi::host::HostMessageContext* host_context,
|
||||
bool on_top) {
|
||||
content::PepperPluginInstance* plugin_instance =
|
||||
host_->GetPluginInstance(pp_instance());
|
||||
if (plugin_instance)
|
||||
plugin_instance->SetAlwaysOnTop(on_top);
|
||||
// Since no reply is sent for this message, it doesn't make sense to return an
|
||||
// error.
|
||||
return PP_OK;
|
||||
}
|
||||
|
||||
int32_t PepperFlashRendererHost::OnDrawGlyphs(
|
||||
ppapi::host::HostMessageContext* host_context,
|
||||
ppapi::proxy::PPBFlash_DrawGlyphs_Params params) {
|
||||
return PP_ERROR_FAILED;
|
||||
// if (params.glyph_indices.size() != params.glyph_advances.size() ||
|
||||
// params.glyph_indices.empty())
|
||||
// return PP_ERROR_FAILED;
|
||||
//
|
||||
// // Set up the typeface.
|
||||
// int weight = (params.font_desc.weight + 1) * 100;
|
||||
// SkFontStyle::Slant slant = SkFontStyle::kUpright_Slant;
|
||||
// if (params.font_desc.italic)
|
||||
// slant = SkFontStyle::kItalic_Slant;
|
||||
// SkFontStyle style(weight, SkFontStyle::kNormal_Width, slant);
|
||||
// sk_sp<SkTypeface> typeface(
|
||||
// SkTypeface::MakeFromName(params.font_desc.face.c_str(), style));
|
||||
// if (!typeface)
|
||||
// return PP_ERROR_FAILED;
|
||||
//
|
||||
// EnterResourceNoLock<PPB_ImageData_API> enter(
|
||||
// params.image_data.host_resource(), true);
|
||||
// if (enter.failed())
|
||||
// return PP_ERROR_FAILED;
|
||||
//
|
||||
// // Set up the canvas.
|
||||
// PPB_ImageData_API* image = static_cast<PPB_ImageData_API*>(enter.object());
|
||||
// SkCanvas* canvas = image->GetCanvas();
|
||||
// bool needs_unmapping = false;
|
||||
// if (!canvas) {
|
||||
// needs_unmapping = true;
|
||||
// image->Map();
|
||||
// canvas = image->GetCanvas();
|
||||
// if (!canvas)
|
||||
// return PP_ERROR_FAILED; // Failure mapping.
|
||||
// }
|
||||
//
|
||||
// SkAutoCanvasRestore acr(canvas, true);
|
||||
//
|
||||
// // Clip is applied in pixels before the transform.
|
||||
// SkRect clip_rect = {
|
||||
// SkIntToScalar(params.clip.point.x), SkIntToScalar(params.clip.point.y),
|
||||
// SkIntToScalar(params.clip.point.x + params.clip.size.width),
|
||||
// SkIntToScalar(params.clip.point.y + params.clip.size.height)};
|
||||
// canvas->clipRect(clip_rect);
|
||||
//
|
||||
// // Convert & set the matrix.
|
||||
// SkMatrix matrix;
|
||||
// matrix.set(SkMatrix::kMScaleX, SkFloatToScalar(params.transformation[0][0]));
|
||||
// matrix.set(SkMatrix::kMSkewX, SkFloatToScalar(params.transformation[0][1]));
|
||||
// matrix.set(SkMatrix::kMTransX, SkFloatToScalar(params.transformation[0][2]));
|
||||
// matrix.set(SkMatrix::kMSkewY, SkFloatToScalar(params.transformation[1][0]));
|
||||
// matrix.set(SkMatrix::kMScaleY, SkFloatToScalar(params.transformation[1][1]));
|
||||
// matrix.set(SkMatrix::kMTransY, SkFloatToScalar(params.transformation[1][2]));
|
||||
// matrix.set(SkMatrix::kMPersp0, SkFloatToScalar(params.transformation[2][0]));
|
||||
// matrix.set(SkMatrix::kMPersp1, SkFloatToScalar(params.transformation[2][1]));
|
||||
// matrix.set(SkMatrix::kMPersp2, SkFloatToScalar(params.transformation[2][2]));
|
||||
// canvas->concat(matrix);
|
||||
//
|
||||
// SkPaint paint;
|
||||
// paint.setColor(params.color);
|
||||
// paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
|
||||
// paint.setAntiAlias(true);
|
||||
// paint.setHinting(SkPaint::kFull_Hinting);
|
||||
// paint.setTextSize(SkIntToScalar(params.font_desc.size));
|
||||
// paint.setTypeface(std::move(typeface));
|
||||
// if (params.allow_subpixel_aa) {
|
||||
// paint.setSubpixelText(true);
|
||||
// paint.setLCDRenderText(true);
|
||||
// }
|
||||
//
|
||||
// SkScalar x = SkIntToScalar(params.position.x);
|
||||
// SkScalar y = SkIntToScalar(params.position.y);
|
||||
//
|
||||
// // Build up the skia advances.
|
||||
// size_t glyph_count = params.glyph_indices.size();
|
||||
// if (glyph_count) {
|
||||
// std::vector<SkPoint> storage;
|
||||
// storage.resize(glyph_count);
|
||||
// SkPoint* sk_positions = &storage[0];
|
||||
// for (uint32_t i = 0; i < glyph_count; i++) {
|
||||
// sk_positions[i].set(x, y);
|
||||
// x += SkFloatToScalar(params.glyph_advances[i].x);
|
||||
// y += SkFloatToScalar(params.glyph_advances[i].y);
|
||||
// }
|
||||
//
|
||||
// canvas->drawPosText(¶ms.glyph_indices[0], glyph_count * 2, sk_positions,
|
||||
// paint);
|
||||
// }
|
||||
//
|
||||
// if (needs_unmapping)
|
||||
// image->Unmap();
|
||||
//
|
||||
// return PP_OK;
|
||||
}
|
||||
|
||||
// CAUTION: This code is subtle because Navigate is a sync call which may
|
||||
// cause re-entrancy or cause the instance to be destroyed. If the instance
|
||||
// is destroyed we need to ensure that we respond to all outstanding sync
|
||||
// messages so that the plugin process does not remain blocked.
|
||||
int32_t PepperFlashRendererHost::OnNavigate(
|
||||
ppapi::host::HostMessageContext* host_context,
|
||||
const ppapi::URLRequestInfoData& data,
|
||||
const std::string& target,
|
||||
bool from_user_action) {
|
||||
// If our PepperPluginInstance is already destroyed, just return a failure.
|
||||
content::PepperPluginInstance* plugin_instance =
|
||||
host_->GetPluginInstance(pp_instance());
|
||||
if (!plugin_instance)
|
||||
return PP_ERROR_FAILED;
|
||||
|
||||
std::map<std::string, FlashNavigateUsage>& rejected_headers =
|
||||
g_rejected_headers.Get();
|
||||
if (rejected_headers.empty()) {
|
||||
for (size_t i = 0; i < arraysize(kRejectedHttpRequestHeaders); ++i)
|
||||
rejected_headers[kRejectedHttpRequestHeaders[i]] =
|
||||
static_cast<FlashNavigateUsage>(i);
|
||||
}
|
||||
|
||||
net::HttpUtil::HeadersIterator header_iter(data.headers.begin(),
|
||||
data.headers.end(), "\n\r");
|
||||
bool rejected = false;
|
||||
while (header_iter.GetNext()) {
|
||||
std::string lower_case_header_name = base::ToLowerASCII(header_iter.name());
|
||||
if (!IsSimpleHeader(lower_case_header_name, header_iter.values())) {
|
||||
rejected = true;
|
||||
|
||||
std::map<std::string, FlashNavigateUsage>::const_iterator iter =
|
||||
rejected_headers.find(lower_case_header_name);
|
||||
FlashNavigateUsage usage =
|
||||
iter != rejected_headers.end() ? iter->second : REJECT_OTHER_HEADERS;
|
||||
RecordFlashNavigateUsage(usage);
|
||||
}
|
||||
}
|
||||
|
||||
RecordFlashNavigateUsage(TOTAL_NAVIGATE_REQUESTS);
|
||||
if (rejected) {
|
||||
RecordFlashNavigateUsage(TOTAL_REJECTED_NAVIGATE_REQUESTS);
|
||||
return PP_ERROR_NOACCESS;
|
||||
}
|
||||
|
||||
// Navigate may call into Javascript (e.g. with a "javascript:" URL),
|
||||
// or do things like navigate away from the page, either one of which will
|
||||
// need to re-enter into the plugin. It is safe, because it is essentially
|
||||
// equivalent to NPN_GetURL, where Flash would expect re-entrancy.
|
||||
ppapi::proxy::HostDispatcher* host_dispatcher =
|
||||
ppapi::proxy::HostDispatcher::GetForInstance(pp_instance());
|
||||
host_dispatcher->set_allow_plugin_reentrancy();
|
||||
|
||||
// Grab a weak pointer to ourselves on the stack so we can check if we are
|
||||
// still alive.
|
||||
base::WeakPtr<PepperFlashRendererHost> weak_ptr = weak_factory_.GetWeakPtr();
|
||||
// Keep track of reply contexts in case we are destroyed during a Navigate
|
||||
// call. Even if we are destroyed, we still need to send these replies to
|
||||
// unblock the plugin process.
|
||||
navigate_replies_.push_back(host_context->MakeReplyMessageContext());
|
||||
plugin_instance->Navigate(data, target.c_str(), from_user_action);
|
||||
// This object might have been destroyed by this point. If it is destroyed
|
||||
// the reply will be sent in the destructor. Otherwise send the reply here.
|
||||
if (weak_ptr.get()) {
|
||||
SendReply(navigate_replies_.back(), IPC::Message());
|
||||
navigate_replies_.pop_back();
|
||||
}
|
||||
|
||||
// Return PP_OK_COMPLETIONPENDING so that no reply is automatically sent.
|
||||
return PP_OK_COMPLETIONPENDING;
|
||||
}
|
||||
|
||||
int32_t PepperFlashRendererHost::OnIsRectTopmost(
|
||||
ppapi::host::HostMessageContext* host_context,
|
||||
const PP_Rect& rect) {
|
||||
content::PepperPluginInstance* plugin_instance =
|
||||
host_->GetPluginInstance(pp_instance());
|
||||
if (plugin_instance &&
|
||||
plugin_instance->IsRectTopmost(gfx::Rect(
|
||||
rect.point.x, rect.point.y, rect.size.width, rect.size.height)))
|
||||
return PP_OK;
|
||||
return PP_ERROR_FAILED;
|
||||
}
|
|
@ -1,68 +0,0 @@
|
|||
// 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.
|
||||
|
||||
#ifndef CHROME_RENDERER_PEPPER_PEPPER_FLASH_RENDERER_HOST_H_
|
||||
#define CHROME_RENDERER_PEPPER_PEPPER_FLASH_RENDERER_HOST_H_
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "base/memory/weak_ptr.h"
|
||||
#include "ppapi/host/host_message_context.h"
|
||||
#include "ppapi/host/resource_host.h"
|
||||
|
||||
struct PP_Rect;
|
||||
|
||||
namespace ppapi {
|
||||
struct URLRequestInfoData;
|
||||
}
|
||||
|
||||
namespace ppapi {
|
||||
namespace proxy {
|
||||
struct PPBFlash_DrawGlyphs_Params;
|
||||
}
|
||||
} // namespace ppapi
|
||||
|
||||
namespace content {
|
||||
class RendererPpapiHost;
|
||||
}
|
||||
|
||||
class PepperFlashRendererHost : public ppapi::host::ResourceHost {
|
||||
public:
|
||||
PepperFlashRendererHost(content::RendererPpapiHost* host,
|
||||
PP_Instance instance,
|
||||
PP_Resource resource);
|
||||
~PepperFlashRendererHost() override;
|
||||
|
||||
// ppapi::host::ResourceHost override.
|
||||
int32_t OnResourceMessageReceived(
|
||||
const IPC::Message& msg,
|
||||
ppapi::host::HostMessageContext* context) override;
|
||||
|
||||
private:
|
||||
int32_t OnGetProxyForURL(ppapi::host::HostMessageContext* host_context,
|
||||
const std::string& url);
|
||||
int32_t OnSetInstanceAlwaysOnTop(
|
||||
ppapi::host::HostMessageContext* host_context,
|
||||
bool on_top);
|
||||
int32_t OnDrawGlyphs(ppapi::host::HostMessageContext* host_context,
|
||||
ppapi::proxy::PPBFlash_DrawGlyphs_Params params);
|
||||
int32_t OnNavigate(ppapi::host::HostMessageContext* host_context,
|
||||
const ppapi::URLRequestInfoData& data,
|
||||
const std::string& target,
|
||||
bool from_user_action);
|
||||
int32_t OnIsRectTopmost(ppapi::host::HostMessageContext* host_context,
|
||||
const PP_Rect& rect);
|
||||
|
||||
// A stack of ReplyMessageContexts to track Navigate() calls which have not
|
||||
// yet been replied to.
|
||||
std::vector<ppapi::host::ReplyMessageContext> navigate_replies_;
|
||||
|
||||
content::RendererPpapiHost* host_;
|
||||
base::WeakPtrFactory<PepperFlashRendererHost> weak_factory_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(PepperFlashRendererHost);
|
||||
};
|
||||
|
||||
#endif // CHROME_RENDERER_PEPPER_PEPPER_FLASH_RENDERER_HOST_H_
|
|
@ -1,30 +0,0 @@
|
|||
// 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.
|
||||
|
||||
#include "chrome/renderer/pepper/pepper_helper.h"
|
||||
|
||||
#include "chrome/renderer/pepper/chrome_renderer_pepper_host_factory.h"
|
||||
#include "chrome/renderer/pepper/pepper_shared_memory_message_filter.h"
|
||||
#include "content/public/renderer/renderer_ppapi_host.h"
|
||||
#include "ppapi/host/ppapi_host.h"
|
||||
|
||||
PepperHelper::PepperHelper(content::RenderFrame* render_frame)
|
||||
: RenderFrameObserver(render_frame) {}
|
||||
|
||||
PepperHelper::~PepperHelper() {}
|
||||
|
||||
void PepperHelper::DidCreatePepperPlugin(content::RendererPpapiHost* host) {
|
||||
// TODO(brettw) figure out how to hook up the host factory. It needs some
|
||||
// kind of filter-like system to allow dynamic additions.
|
||||
host->GetPpapiHost()->AddHostFactoryFilter(
|
||||
std::unique_ptr<ppapi::host::HostFactory>(
|
||||
new ChromeRendererPepperHostFactory(host)));
|
||||
host->GetPpapiHost()->AddInstanceMessageFilter(
|
||||
std::unique_ptr<ppapi::host::InstanceMessageFilter>(
|
||||
new PepperSharedMemoryMessageFilter(host)));
|
||||
}
|
||||
|
||||
void PepperHelper::OnDestruct() {
|
||||
delete this;
|
||||
}
|
|
@ -1,26 +0,0 @@
|
|||
// 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.
|
||||
|
||||
#ifndef CHROME_RENDERER_PEPPER_PEPPER_HELPER_H_
|
||||
#define CHROME_RENDERER_PEPPER_PEPPER_HELPER_H_
|
||||
|
||||
#include "base/compiler_specific.h"
|
||||
#include "content/public/renderer/render_frame_observer.h"
|
||||
|
||||
// This class listens for Pepper creation events from the RenderFrame and
|
||||
// attaches the parts required for Chrome-specific plugin support.
|
||||
class PepperHelper : public content::RenderFrameObserver {
|
||||
public:
|
||||
explicit PepperHelper(content::RenderFrame* render_frame);
|
||||
~PepperHelper() override;
|
||||
|
||||
// RenderFrameObserver.
|
||||
void DidCreatePepperPlugin(content::RendererPpapiHost* host) override;
|
||||
void OnDestruct() override;
|
||||
|
||||
private:
|
||||
DISALLOW_COPY_AND_ASSIGN(PepperHelper);
|
||||
};
|
||||
|
||||
#endif // CHROME_RENDERER_PEPPER_PEPPER_HELPER_H_
|
|
@ -1,63 +0,0 @@
|
|||
// Copyright (c) 2013 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.
|
||||
|
||||
#include "chrome/renderer/pepper/pepper_shared_memory_message_filter.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "base/memory/shared_memory.h"
|
||||
#include "base/process/process_handle.h"
|
||||
#include "content/public/common/content_client.h"
|
||||
#include "content/public/renderer/pepper_plugin_instance.h"
|
||||
#include "content/public/renderer/render_thread.h"
|
||||
#include "content/public/renderer/renderer_ppapi_host.h"
|
||||
#include "ppapi/host/ppapi_host.h"
|
||||
#include "ppapi/proxy/ppapi_messages.h"
|
||||
#include "ppapi/shared_impl/var_tracker.h"
|
||||
|
||||
PepperSharedMemoryMessageFilter::PepperSharedMemoryMessageFilter(
|
||||
content::RendererPpapiHost* host)
|
||||
: InstanceMessageFilter(host->GetPpapiHost()), host_(host) {}
|
||||
|
||||
PepperSharedMemoryMessageFilter::~PepperSharedMemoryMessageFilter() {}
|
||||
|
||||
bool PepperSharedMemoryMessageFilter::OnInstanceMessageReceived(
|
||||
const IPC::Message& msg) {
|
||||
bool handled = true;
|
||||
IPC_BEGIN_MESSAGE_MAP(PepperSharedMemoryMessageFilter, msg)
|
||||
IPC_MESSAGE_HANDLER(PpapiHostMsg_SharedMemory_CreateSharedMemory,
|
||||
OnHostMsgCreateSharedMemory)
|
||||
IPC_MESSAGE_UNHANDLED(handled = false)
|
||||
IPC_END_MESSAGE_MAP()
|
||||
return handled;
|
||||
}
|
||||
|
||||
bool PepperSharedMemoryMessageFilter::Send(IPC::Message* msg) {
|
||||
return host_->GetPpapiHost()->Send(msg);
|
||||
}
|
||||
|
||||
void PepperSharedMemoryMessageFilter::OnHostMsgCreateSharedMemory(
|
||||
PP_Instance instance,
|
||||
uint32_t size,
|
||||
int* host_handle_id,
|
||||
ppapi::proxy::SerializedHandle* plugin_handle) {
|
||||
plugin_handle->set_null_shmem();
|
||||
*host_handle_id = -1;
|
||||
std::unique_ptr<base::SharedMemory> shm(
|
||||
content::RenderThread::Get()->HostAllocateSharedMemoryBuffer(size));
|
||||
if (!shm.get())
|
||||
return;
|
||||
|
||||
base::SharedMemoryHandle host_shm_handle = shm->handle().Duplicate();
|
||||
*host_handle_id =
|
||||
content::PepperPluginInstance::Get(instance)
|
||||
->GetVarTracker()
|
||||
->TrackSharedMemoryHandle(instance, host_shm_handle, size);
|
||||
|
||||
// We set auto_close to false since we need our file descriptor to
|
||||
// actually be duplicated on linux. The shared memory destructor will
|
||||
// close the original handle for us.
|
||||
plugin_handle->set_shmem(
|
||||
host_->ShareSharedMemoryHandleWithRemote(host_shm_handle), size);
|
||||
}
|
|
@ -1,46 +0,0 @@
|
|||
// Copyright (c) 2013 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.
|
||||
|
||||
#ifndef CHROME_RENDERER_PEPPER_PEPPER_SHARED_MEMORY_MESSAGE_FILTER_H_
|
||||
#define CHROME_RENDERER_PEPPER_PEPPER_SHARED_MEMORY_MESSAGE_FILTER_H_
|
||||
|
||||
#include "ppapi/c/pp_instance.h"
|
||||
#include "ppapi/host/instance_message_filter.h"
|
||||
|
||||
namespace content {
|
||||
class RendererPpapiHost;
|
||||
}
|
||||
|
||||
namespace ppapi {
|
||||
namespace proxy {
|
||||
class SerializedHandle;
|
||||
}
|
||||
} // namespace ppapi
|
||||
|
||||
// Implements the backend for shared memory messages from a plugin process.
|
||||
class PepperSharedMemoryMessageFilter
|
||||
: public ppapi::host::InstanceMessageFilter {
|
||||
public:
|
||||
explicit PepperSharedMemoryMessageFilter(content::RendererPpapiHost* host);
|
||||
~PepperSharedMemoryMessageFilter() override;
|
||||
|
||||
// InstanceMessageFilter:
|
||||
bool OnInstanceMessageReceived(const IPC::Message& msg) override;
|
||||
|
||||
bool Send(IPC::Message* msg);
|
||||
|
||||
private:
|
||||
// Message handlers.
|
||||
void OnHostMsgCreateSharedMemory(
|
||||
PP_Instance instance,
|
||||
uint32_t size,
|
||||
int* host_shm_handle_id,
|
||||
ppapi::proxy::SerializedHandle* plugin_shm_handle);
|
||||
|
||||
content::RendererPpapiHost* host_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(PepperSharedMemoryMessageFilter);
|
||||
};
|
||||
|
||||
#endif // CHROME_RENDERER_PEPPER_PEPPER_SHARED_MEMORY_MESSAGE_FILTER_H_
|
Loading…
Add table
Add a link
Reference in a new issue