diff options
Diffstat (limited to 'athena/main')
-rw-r--r-- | athena/main/DEPS | 5 | ||||
-rw-r--r-- | athena/main/athena_content_client.cc | 52 | ||||
-rw-r--r-- | athena/main/athena_content_client.h | 27 | ||||
-rw-r--r-- | athena/main/athena_main.cc | 35 | ||||
-rw-r--r-- | athena/main/athena_main.gyp | 8 | ||||
-rw-r--r-- | athena/main/athena_renderer_pdf_helper.cc | 73 | ||||
-rw-r--r-- | athena/main/athena_renderer_pdf_helper.h | 27 |
7 files changed, 226 insertions, 1 deletions
diff --git a/athena/main/DEPS b/athena/main/DEPS index ee2c60e..9942b76 100644 --- a/athena/main/DEPS +++ b/athena/main/DEPS @@ -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", diff --git a/athena/main/athena_content_client.cc b/athena/main/athena_content_client.cc new file mode 100644 index 0000000..f24574f --- /dev/null +++ b/athena/main/athena_content_client.cc @@ -0,0 +1,52 @@ +// 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 diff --git a/athena/main/athena_content_client.h b/athena/main/athena_content_client.h new file mode 100644 index 0000000..ec94f19 --- /dev/null +++ b/athena/main/athena_content_client.h @@ -0,0 +1,27 @@ +// 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_ diff --git a/athena/main/athena_main.cc b/athena/main/athena_main.cc index f003ba5..e19d7f4 100644 --- a/athena/main/athena_main.cc +++ b/athena/main/athena_main.cc @@ -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); diff --git a/athena/main/athena_main.gyp b/athena/main/athena_main.gyp index 4e86d2b..4e8c3766 100644 --- a/athena/main/athena_main.gyp +++ b/athena/main/athena_main.gyp @@ -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', ], diff --git a/athena/main/athena_renderer_pdf_helper.cc b/athena/main/athena_renderer_pdf_helper.cc new file mode 100644 index 0000000..85bc003 --- /dev/null +++ b/athena/main/athena_renderer_pdf_helper.cc @@ -0,0 +1,73 @@ +// 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 diff --git a/athena/main/athena_renderer_pdf_helper.h b/athena/main/athena_renderer_pdf_helper.h new file mode 100644 index 0000000..2521985 --- /dev/null +++ b/athena/main/athena_renderer_pdf_helper.h @@ -0,0 +1,27 @@ +// 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_ |