athena: Add support for PDF.

Advertise support for PDF plugins, and use the implementations from the
pdf component (in //components/pdf) for adding the necessary support for
showing PDF files in athena.

BUG=401242
R=jamescook@chromium.org, oshima@chromium.org, raymes@chromium.org

Review URL: https://codereview.chromium.org/484873004

Cr-Commit-Position: refs/heads/master@{#292684}
parent 176ca8f5
......@@ -14,9 +14,11 @@ include_rules = [
"+athena/wm/public",
"+components/metrics/proto",
"+components/omnibox",
"+components/pdf",
"+components/search_engines",
"+content/public",
"+net",
"+ppapi",
"+ui/aura",
"+ui/app_list",
"+ui/base",
......@@ -40,6 +42,9 @@ specific_include_rules = {
"athena_app_window_controller\.*": [
"+extensions/shell/browser",
],
"athena_content_client\.h": [
"+extensions/shell/common",
],
# TODO(oshima): Remove this.
"placeholder\.*": [
"+third_party/skia",
......
// Copyright 2014 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 "athena/main/athena_content_client.h"
#include "base/files/file_path.h"
#include "base/path_service.h"
#include "content/public/common/pepper_plugin_info.h"
#include "ppapi/shared_impl/ppapi_permissions.h"
namespace athena {
AthenaContentClient::AthenaContentClient() {}
AthenaContentClient::~AthenaContentClient() {}
void AthenaContentClient::AddPepperPlugins(
std::vector<content::PepperPluginInfo>* plugins) {
const char kPDFPluginMimeType[] = "application/pdf";
const char kPDFPluginExtension[] = "pdf";
const char kPDFPluginDescription[] = "Portable Document Format";
const char kPDFPluginPrintPreviewMimeType[] =
"application/x-google-chrome-print-preview-pdf";
const uint32 kPDFPluginPermissions =
ppapi::PERMISSION_PRIVATE | ppapi::PERMISSION_DEV;
const char kPDFPluginName[] = "Chrome PDF Viewer";
const base::FilePath::CharType kPDFPluginFileName[] =
FILE_PATH_LITERAL("libpdf.so");
base::FilePath module;
if (!PathService::Get(base::DIR_MODULE, &module))
return;
content::PepperPluginInfo pdf;
pdf.path = base::FilePath(module.Append(kPDFPluginFileName));
pdf.name = kPDFPluginName;
content::WebPluginMimeType pdf_mime_type(
kPDFPluginMimeType, kPDFPluginExtension, kPDFPluginDescription);
content::WebPluginMimeType print_preview_pdf_mime_type(
kPDFPluginPrintPreviewMimeType,
kPDFPluginExtension,
kPDFPluginDescription);
pdf.mime_types.push_back(pdf_mime_type);
pdf.mime_types.push_back(print_preview_pdf_mime_type);
pdf.permissions = kPDFPluginPermissions;
plugins->push_back(pdf);
ShellContentClient::AddPepperPlugins(plugins);
}
} // namespace athena
// Copyright 2014 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 ATHENA_MAIN_ATHENA_CONTENT_CLIENT_H_
#define ATHENA_MAIN_ATHENA_CONTENT_CLIENT_H_
#include "extensions/shell/common/shell_content_client.h"
namespace athena {
class AthenaContentClient : public extensions::ShellContentClient {
public:
AthenaContentClient();
virtual ~AthenaContentClient();
private:
// extensions::ShellContentClient:
virtual void AddPepperPlugins(
std::vector<content::PepperPluginInfo>* plugins) OVERRIDE;
DISALLOW_COPY_AND_ASSIGN(AthenaContentClient);
};
} // namespace athena
#endif // ATHENA_MAIN_ATHENA_CONTENT_CLIENT_H_
......@@ -7,11 +7,14 @@
#include "athena/content/public/web_contents_view_delegate_creator.h"
#include "athena/env/public/athena_env.h"
#include "athena/extensions/public/extensions_delegate.h"
#include "athena/main/athena_content_client.h"
#include "athena/main/athena_launcher.h"
#include "athena/main/athena_renderer_pdf_helper.h"
#include "athena/screen/public/screen_manager.h"
#include "base/command_line.h"
#include "base/file_util.h"
#include "base/path_service.h"
#include "components/pdf/renderer/ppb_pdf_impl.h"
#include "content/public/app/content_main.h"
#include "content/public/browser/browser_thread.h"
#include "extensions/shell/app/shell_main_delegate.h"
......@@ -20,7 +23,10 @@
#include "extensions/shell/browser/shell_browser_main_delegate.h"
#include "extensions/shell/browser/shell_content_browser_client.h"
#include "extensions/shell/browser/shell_extension_system.h"
#include "extensions/shell/common/shell_content_client.h"
#include "extensions/shell/common/switches.h"
#include "extensions/shell/renderer/shell_content_renderer_client.h"
#include "ppapi/c/private/ppb_pdf.h"
#include "ui/aura/window_tree_host.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/wm/core/visibility_controller.h"
......@@ -123,6 +129,27 @@ class AthenaContentBrowserClient
DISALLOW_COPY_AND_ASSIGN(AthenaContentBrowserClient);
};
class AthenaContentRendererClient
: public extensions::ShellContentRendererClient {
public:
AthenaContentRendererClient() {}
virtual ~AthenaContentRendererClient() {}
// content::ContentRendererClient:
virtual void RenderFrameCreated(content::RenderFrame* render_frame) OVERRIDE {
new athena::AthenaRendererPDFHelper(render_frame);
extensions::ShellContentRendererClient::RenderFrameCreated(render_frame);
}
virtual const void* CreatePPAPIInterface(
const std::string& interface_name) OVERRIDE {
if (interface_name == PPB_PDF_INTERFACE)
return pdf::PPB_PDF_Impl::GetInterface();
return extensions::ShellContentRendererClient::CreatePPAPIInterface(
interface_name);
}
};
class AthenaMainDelegate : public extensions::ShellMainDelegate {
public:
AthenaMainDelegate() {}
......@@ -130,11 +157,19 @@ class AthenaMainDelegate : public extensions::ShellMainDelegate {
private:
// extensions::ShellMainDelegate:
virtual content::ContentClient* CreateContentClient() OVERRIDE {
return new athena::AthenaContentClient();
}
virtual content::ContentBrowserClient* CreateShellContentBrowserClient()
OVERRIDE {
return new AthenaContentBrowserClient();
}
virtual content::ContentRendererClient* CreateShellContentRendererClient()
OVERRIDE {
return new AthenaContentRendererClient();
}
virtual void InitializeResourceBundle() OVERRIDE {
base::FilePath pak_dir;
PathService::Get(base::DIR_MODULE, &pak_dir);
......
......@@ -25,7 +25,9 @@
# TODO(mukai): declare those symbols for Athena.
'../../components/components.gyp:infobars_test_support',
'../../components/components.gyp:omnibox',
'../../components/components.gyp:pdf_renderer',
'../../components/components.gyp:search_engines',
'../../pdf/pdf.gyp:pdf',
'../../skia/skia.gyp:skia',
'../../ui/app_list/app_list.gyp:app_list',
'../../ui/chromeos/ui_chromeos.gyp:ui_chromeos',
......@@ -37,8 +39,12 @@
'../..',
],
'sources': [
'athena_content_client.cc',
'athena_content_client.h',
'athena_launcher.cc',
'athena_launcher.h',
'athena_renderer_pdf_helper.cc',
'athena_renderer_pdf_helper.h',
'debug/debug_window.cc',
'debug/debug_window.h',
'debug/network_selector.cc',
......@@ -54,7 +60,7 @@
'type': 'executable',
'dependencies': [
'../../ui/accessibility/accessibility.gyp:ax_gen',
'../athena.gyp:athena_app_shell_lib',
'../athena.gyp:athena_app_shell_lib',
'../resources/athena_resources.gyp:athena_pak',
'athena_main_lib',
],
......
// Copyright 2014 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 "athena/main/athena_renderer_pdf_helper.h"
#include "components/pdf/renderer/pepper_pdf_host.h"
#include "content/public/renderer/renderer_ppapi_host.h"
#include "ppapi/host/host_factory.h"
#include "ppapi/host/ppapi_host.h"
#include "ppapi/host/resource_host.h"
#include "ppapi/proxy/ppapi_messages.h"
namespace athena {
namespace {
class PDFRendererHostFactory : public ppapi::host::HostFactory {
public:
explicit PDFRendererHostFactory(content::RendererPpapiHost* host)
: host_(host) {}
virtual ~PDFRendererHostFactory() {}
private:
// ppapi::host::HostFactory:
virtual scoped_ptr<ppapi::host::ResourceHost> CreateResourceHost(
ppapi::host::PpapiHost* host,
const ppapi::proxy::ResourceMessageCallParams& params,
PP_Instance instance,
const IPC::Message& message) OVERRIDE {
DCHECK_EQ(host_->GetPpapiHost(), host);
// Make sure the plugin is giving us a valid instance for this resource.
if (!host_->IsValidInstance(instance))
return scoped_ptr<ppapi::host::ResourceHost>();
if (host_->GetPpapiHost()->permissions().HasPermission(
ppapi::PERMISSION_PRIVATE)) {
switch (message.type()) {
case PpapiHostMsg_PDF_Create::ID:
return scoped_ptr<ppapi::host::ResourceHost>(
new pdf::PepperPDFHost(host_, instance, params.pp_resource()));
case PpapiHostMsg_FlashFontFile_Create::ID:
return scoped_ptr<ppapi::host::ResourceHost>(
new ppapi::host::ResourceHost(host_->GetPpapiHost(),
instance,
params.pp_resource()));
}
}
return scoped_ptr<ppapi::host::ResourceHost>();
}
// Not owned by this object.
content::RendererPpapiHost* host_;
DISALLOW_COPY_AND_ASSIGN(PDFRendererHostFactory);
};
} // namespace
AthenaRendererPDFHelper::AthenaRendererPDFHelper(content::RenderFrame* frame)
: content::RenderFrameObserver(frame) {}
AthenaRendererPDFHelper::~AthenaRendererPDFHelper() {}
void AthenaRendererPDFHelper::DidCreatePepperPlugin(
content::RendererPpapiHost* host) {
host->GetPpapiHost()->AddHostFactoryFilter(
scoped_ptr<ppapi::host::HostFactory>(new PDFRendererHostFactory(host)));
}
} // namespace athena
// Copyright 2014 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 ATHENA_MAIN_ATHENA_RENDERER_PDF_HELPER_H_
#define ATHENA_MAIN_ATHENA_RENDERER_PDF_HELPER_H_
#include "content/public/renderer/render_frame_observer.h"
namespace athena {
class AthenaRendererPDFHelper : public content::RenderFrameObserver {
public:
explicit AthenaRendererPDFHelper(content::RenderFrame* frame);
virtual ~AthenaRendererPDFHelper();
private:
// RenderFrameObserver:
virtual void DidCreatePepperPlugin(
content::RendererPpapiHost* host) OVERRIDE;
DISALLOW_COPY_AND_ASSIGN(AthenaRendererPDFHelper);
};
} // namespace athena
#endif // ATHENA_MAIN_ATHENA_RENDERER_PDF_HELPER_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment