summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorapatrick@chromium.org <apatrick@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-10 00:50:22 +0000
committerapatrick@chromium.org <apatrick@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-10 00:50:22 +0000
commite8f7a187aa77cd3898e9dc7f382a89d0bc6ed359 (patch)
tree193b2c73d4118871f64bed9f2620f0f00ceb83c9
parent60ae33e3b2d15497bb524c923adbcc8f8087494c (diff)
downloadchromium_src-e8f7a187aa77cd3898e9dc7f382a89d0bc6ed359.zip
chromium_src-e8f7a187aa77cd3898e9dc7f382a89d0bc6ed359.tar.gz
chromium_src-e8f7a187aa77cd3898e9dc7f382a89d0bc6ed359.tar.bz2
Deleted WebPluginDelegatePepper and everything dependent on it.
This removes support for pepper v1 trusted plugins. TEST=pepper v2 plugin runs, npapi plugin runs, trybots BUG=none Review URL: http://codereview.chromium.org/6646025 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@77568 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/renderer_host/browser_render_process_host.cc1
-rw-r--r--chrome/chrome_renderer.gypi8
-rw-r--r--chrome/chrome_tests.gypi1
-rw-r--r--chrome/common/chrome_switches.cc3
-rw-r--r--chrome/common/chrome_switches.h1
-rw-r--r--chrome/renderer/pepper_devices.cc304
-rw-r--r--chrome/renderer/pepper_devices.h128
-rw-r--r--chrome/renderer/pepper_devices_browsertest.cc269
-rw-r--r--chrome/renderer/pepper_scrollbar_widget.cc300
-rw-r--r--chrome/renderer/pepper_scrollbar_widget.h62
-rw-r--r--chrome/renderer/pepper_widget.cc146
-rw-r--r--chrome/renderer/pepper_widget.h42
-rw-r--r--chrome/renderer/render_view.cc94
-rw-r--r--chrome/renderer/render_view.h12
-rw-r--r--chrome/renderer/webplugin_delegate_pepper.cc1350
-rw-r--r--chrome/renderer/webplugin_delegate_pepper.h310
-rw-r--r--gpu/demos/demos.gyp148
-rw-r--r--gpu/demos/framework/main_pepper.cc183
18 files changed, 6 insertions, 3356 deletions
diff --git a/chrome/browser/renderer_host/browser_render_process_host.cc b/chrome/browser/renderer_host/browser_render_process_host.cc
index c58eef8..c8dc43a 100644
--- a/chrome/browser/renderer_host/browser_render_process_host.cc
+++ b/chrome/browser/renderer_host/browser_render_process_host.cc
@@ -723,7 +723,6 @@ void BrowserRenderProcessHost::PropagateBrowserCommandLineToRenderer(
switches::kInProcessPlugins,
#endif // GOOGLE_CHROME_BUILD
switches::kInProcessWebGL,
- switches::kInternalPepper,
switches::kJavaScriptFlags,
switches::kLoggingLevel,
switches::kMemoryProfiling,
diff --git a/chrome/chrome_renderer.gypi b/chrome/chrome_renderer.gypi
index daee5a9..149232a 100644
--- a/chrome/chrome_renderer.gypi
+++ b/chrome/chrome_renderer.gypi
@@ -144,16 +144,10 @@
'renderer/page_click_tracker.h',
'renderer/page_load_histograms.cc',
'renderer/page_load_histograms.h',
- 'renderer/pepper_devices.cc',
- 'renderer/pepper_devices.h',
'renderer/pepper_platform_context_3d_impl.cc',
'renderer/pepper_platform_context_3d_impl.h',
'renderer/pepper_plugin_delegate_impl.cc',
'renderer/pepper_plugin_delegate_impl.h',
- 'renderer/pepper_scrollbar_widget.cc',
- 'renderer/pepper_scrollbar_widget.h',
- 'renderer/pepper_widget.cc',
- 'renderer/pepper_widget.h',
'renderer/plugin_channel_host.cc',
'renderer/plugin_channel_host.h',
'renderer/print_web_view_helper.cc',
@@ -264,8 +258,6 @@
'renderer/webgraphicscontext3d_command_buffer_impl.h',
'renderer/webplugin_delegate_proxy.cc',
'renderer/webplugin_delegate_proxy.h',
- 'renderer/webplugin_delegate_pepper.cc',
- 'renderer/webplugin_delegate_pepper.h',
'renderer/websharedworker_proxy.cc',
'renderer/websharedworker_proxy.h',
'renderer/websharedworkerrepository_impl.cc',
diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi
index 0255504..f077ba5 100644
--- a/chrome/chrome_tests.gypi
+++ b/chrome/chrome_tests.gypi
@@ -2294,7 +2294,6 @@
'renderer/autofill/form_manager_browsertest.cc',
'renderer/autofill/password_autofill_manager_unittest.cc',
'renderer/page_click_tracker_browsertest.cc',
- 'renderer/pepper_devices_browsertest.cc',
'renderer/render_view_browsertest.cc',
'renderer/render_view_browsertest_mac.mm',
'renderer/render_widget_browsertest.cc',
diff --git a/chrome/common/chrome_switches.cc b/chrome/common/chrome_switches.cc
index d0df5b6..50cd21d 100644
--- a/chrome/common/chrome_switches.cc
+++ b/chrome/common/chrome_switches.cc
@@ -708,9 +708,6 @@ const char kIncognito[] = "incognito";
// TemplateURL.
const char kInstantURL[] = "instant-url";
-// Runs a trusted Pepper plugin inside the renderer process.
-const char kInternalPepper[] = "internal-pepper";
-
// Specifies the flags passed to JS engine
const char kJavaScriptFlags[] = "js-flags";
diff --git a/chrome/common/chrome_switches.h b/chrome/common/chrome_switches.h
index 2dac7fc..5b3c0cf 100644
--- a/chrome/common/chrome_switches.h
+++ b/chrome/common/chrome_switches.h
@@ -202,7 +202,6 @@ extern const char kInProcessPlugins[];
extern const char kInProcessWebGL[];
extern const char kIncognito[];
extern const char kInstantURL[];
-extern const char kInternalPepper[];
extern const char kJavaScriptFlags[];
extern const char kKeepAliveForTest[];
extern const char kLoadExtension[];
diff --git a/chrome/renderer/pepper_devices.cc b/chrome/renderer/pepper_devices.cc
deleted file mode 100644
index bc99b13..0000000
--- a/chrome/renderer/pepper_devices.cc
+++ /dev/null
@@ -1,304 +0,0 @@
-// Copyright (c) 2010 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_devices.h"
-
-#include "chrome/common/render_messages.h"
-#include "chrome/common/render_messages_params.h"
-#include "chrome/renderer/render_thread.h"
-#include "chrome/renderer/webplugin_delegate_pepper.h"
-#include "skia/ext/platform_canvas.h"
-#include "third_party/skia/include/core/SkBitmap.h"
-#include "webkit/plugins/npapi/plugin_instance.h"
-#include "webkit/plugins/npapi/webplugin.h"
-
-namespace {
-
-const uint32 kBytesPerPixel = 4; // Only 8888 RGBA for now.
-
-} // namespace
-
-int Graphics2DDeviceContext::next_buffer_id_ = 0;
-
-struct Graphics2DDeviceContext::FlushCallbackData {
- FlushCallbackData(NPDeviceFlushContextCallbackPtr f,
- NPP n,
- NPDeviceContext2D* c,
- NPUserData* u)
- : function(f),
- npp(n),
- context(c),
- user_data(u) {
- }
-
- NPDeviceFlushContextCallbackPtr function;
- NPP npp;
- NPDeviceContext2D* context;
- NPUserData* user_data;
-};
-
-Graphics2DDeviceContext::Graphics2DDeviceContext(
- WebPluginDelegatePepper* plugin_delegate)
- : plugin_delegate_(plugin_delegate) {
-}
-
-Graphics2DDeviceContext::~Graphics2DDeviceContext() {}
-
-NPError Graphics2DDeviceContext::Initialize(
- gfx::Rect window_rect, const NPDeviceContext2DConfig* config,
- NPDeviceContext2D* context) {
- int width = window_rect.width();
- int height = window_rect.height();
- uint32 buffer_size = width * height * kBytesPerPixel;
-
- // Allocate the transport DIB and the PlatformCanvas pointing to it.
-#if defined(OS_MACOSX)
- // On the Mac, shared memory has to be created in the browser in order to
- // work in the sandbox. Do this by sending a message to the browser
- // requesting a TransportDIB (see also
- // chrome/renderer/webplugin_delegate_proxy.cc, method
- // WebPluginDelegateProxy::CreateBitmap() for similar code). Note that the
- // TransportDIB is _not_ cached in the browser; this is because this memory
- // gets flushed by the renderer into another TransportDIB that represents the
- // page, which is then in turn flushed to the screen by the browser process.
- // When |transport_dib_| goes out of scope in the dtor, all of its shared
- // memory gets reclaimed.
- TransportDIB::Handle dib_handle;
- IPC::Message* msg = new ViewHostMsg_AllocTransportDIB(buffer_size,
- false,
- &dib_handle);
- if (!RenderThread::current()->Send(msg))
- return NPERR_GENERIC_ERROR;
- if (!TransportDIB::is_valid(dib_handle))
- return NPERR_OUT_OF_MEMORY_ERROR;
- transport_dib_.reset(TransportDIB::Map(dib_handle));
-#else
- transport_dib_.reset(TransportDIB::Create(buffer_size, ++next_buffer_id_));
- if (!transport_dib_.get())
- return NPERR_OUT_OF_MEMORY_ERROR;
-#endif // defined(OS_MACOSX)
- canvas_.reset(transport_dib_->GetPlatformCanvas(width, height));
- if (!canvas_.get())
- return NPERR_OUT_OF_MEMORY_ERROR;
-
- // Note that we need to get the address out of the bitmap rather than
- // using plugin_buffer_->memory(). The memory() is when the bitmap data
- // has had "Map" called on it. For Windows, this is separate than making a
- // bitmap using the shared section.
- const SkBitmap& plugin_bitmap =
- canvas_->getTopPlatformDevice().accessBitmap(true);
- SkAutoLockPixels locker(plugin_bitmap);
-
- // TODO(brettw) this theoretically shouldn't be necessary. But the
- // platform device on Windows will fill itself with green to help you
- // catch areas you didn't paint.
- plugin_bitmap.eraseARGB(0, 0, 0, 0);
-
- // Save the canvas to the output context structure and save the
- // OpenPaintContext for future reference.
- context->region = plugin_bitmap.getAddr32(0, 0);
- context->stride = width * kBytesPerPixel;
- context->dirty.left = 0;
- context->dirty.top = 0;
- context->dirty.right = width;
- context->dirty.bottom = height;
- return NPERR_NO_ERROR;
-}
-
-NPError Graphics2DDeviceContext::Flush(SkBitmap* committed_bitmap,
- NPDeviceContext2D* context,
- NPDeviceFlushContextCallbackPtr callback,
- NPP id, void* user_data) {
- // Draw the bitmap to the backing store.
- //
- // TODO(brettw) we can optimize this in the case where the entire canvas is
- // updated by actually taking ownership of the buffer and not telling the
- // plugin we're done using it. This wat we can avoid the copy when the entire
- // canvas has been updated.
- SkIRect src_rect = { context->dirty.left,
- context->dirty.top,
- context->dirty.right,
- context->dirty.bottom };
- SkRect dest_rect = { SkIntToScalar(context->dirty.left),
- SkIntToScalar(context->dirty.top),
- SkIntToScalar(context->dirty.right),
- SkIntToScalar(context->dirty.bottom) };
- SkCanvas committed_canvas(*committed_bitmap);
-
- // We want to replace the contents of the bitmap rather than blend.
- SkPaint paint;
- paint.setXfermodeMode(SkXfermode::kSrc_Mode);
- committed_canvas.drawBitmapRect(
- canvas_->getTopPlatformDevice().accessBitmap(false),
- &src_rect, dest_rect, &paint);
-
- committed_bitmap->setIsOpaque(false);
-
- // Cause the updated part of the screen to be repainted. This will happen
- // asynchronously.
- // TODO(brettw) is this the coorect coordinate system?
- gfx::Rect dest_gfx_rect(context->dirty.left, context->dirty.top,
- context->dirty.right - context->dirty.left,
- context->dirty.bottom - context->dirty.top);
-
- plugin_delegate_->instance()->webplugin()->InvalidateRect(dest_gfx_rect);
-
- // Save the callback to execute later. See |unpainted_flush_callbacks_| in
- // the header file.
- if (callback) {
- unpainted_flush_callbacks_.push_back(
- FlushCallbackData(callback, id, context, user_data));
- }
-
- return NPERR_NO_ERROR;
-}
-
-void Graphics2DDeviceContext::RenderViewInitiatedPaint() {
- // Move all "unpainted" callbacks to the painted state. See
- // |unpainted_flush_callbacks_| in the header for more.
- std::copy(unpainted_flush_callbacks_.begin(),
- unpainted_flush_callbacks_.end(),
- std::back_inserter(painted_flush_callbacks_));
- unpainted_flush_callbacks_.clear();
-}
-
-void Graphics2DDeviceContext::RenderViewFlushedPaint() {
- // Notify all "painted" callbacks. See |unpainted_flush_callbacks_| in the
- // header for more.
- for (size_t i = 0; i < painted_flush_callbacks_.size(); i++) {
- const FlushCallbackData& data = painted_flush_callbacks_[i];
- data.function(data.npp, data.context, NPERR_NO_ERROR, data.user_data);
- }
- painted_flush_callbacks_.clear();
-}
-
-AudioDeviceContext::AudioDeviceContext()
- : context_(NULL),
- stream_id_(0),
- shared_memory_size_(0) {
-}
-
-AudioDeviceContext::~AudioDeviceContext() {
- if (stream_id_) {
- OnDestroy();
- }
-}
-
-NPError AudioDeviceContext::Initialize(AudioMessageFilter* filter,
- const NPDeviceContextAudioConfig* config,
- NPDeviceContextAudio* context) {
- DCHECK(filter);
- // Make sure we don't call init more than once.
- DCHECK_EQ(0, stream_id_);
-
- if (!config || !context) {
- return NPERR_INVALID_PARAM;
- }
- filter_ = filter;
- context_= context;
-
- ViewHostMsg_Audio_CreateStream_Params params;
- params.params.format = AudioParameters::AUDIO_PCM_LINEAR;
- params.params.channels = config->outputChannelMap;
- params.params.sample_rate = config->sampleRate;
- switch (config->sampleType) {
- case NPAudioSampleTypeInt16:
- params.params.bits_per_sample = 16;
- break;
- case NPAudioSampleTypeFloat32:
- params.params.bits_per_sample = 32;
- break;
- default:
- return NPERR_INVALID_PARAM;
- }
-
- context->config = *config;
- params.params.samples_per_packet = config->sampleFrameCount;
-
- stream_id_ = filter_->AddDelegate(this);
- filter->Send(new ViewHostMsg_CreateAudioStream(0, stream_id_, params, true));
- return NPERR_NO_ERROR;
-}
-
-void AudioDeviceContext::OnDestroy() {
- // Make sure we don't call destroy more than once.
- DCHECK_NE(0, stream_id_);
- filter_->RemoveDelegate(stream_id_);
- filter_->Send(new ViewHostMsg_CloseAudioStream(0, stream_id_));
- stream_id_ = 0;
- if (audio_thread_.get()) {
- socket_->Close();
- audio_thread_->Join();
- }
-}
-
-void AudioDeviceContext::OnRequestPacket(AudioBuffersState buffers_state) {
- FireAudioCallback();
- filter_->Send(new ViewHostMsg_NotifyAudioPacketReady(0, stream_id_,
- shared_memory_size_));
-}
-
-void AudioDeviceContext::OnStateChanged(
- const ViewMsg_AudioStreamState_Params& state) {
-}
-
-void AudioDeviceContext::OnCreated(
- base::SharedMemoryHandle handle, uint32 length) {
-#if defined(OS_WIN)
- DCHECK(handle);
-#else
- DCHECK_NE(-1, handle.fd);
-#endif
- DCHECK(length);
- DCHECK(context_);
-
- shared_memory_.reset(new base::SharedMemory(handle, false));
- shared_memory_->Map(length);
- shared_memory_size_ = length;
-
- context_->outBuffer = shared_memory_->memory();
- FireAudioCallback();
- filter_->Send(new ViewHostMsg_PlayAudioStream(0, stream_id_));
-}
-
-void AudioDeviceContext::OnLowLatencyCreated(
- base::SharedMemoryHandle handle, base::SyncSocket::Handle socket_handle,
- uint32 length) {
-#if defined(OS_WIN)
- DCHECK(handle);
- DCHECK(socket_handle);
-#else
- DCHECK_NE(-1, handle.fd);
- DCHECK_NE(-1, socket_handle);
-#endif
- DCHECK(length);
- DCHECK(context_);
- DCHECK(!audio_thread_.get());
- shared_memory_.reset(new base::SharedMemory(handle, false));
- shared_memory_->Map(length);
- shared_memory_size_ = length;
-
- context_->outBuffer = shared_memory_->memory();
- socket_.reset(new base::SyncSocket(socket_handle));
- // Allow the client to pre-populate the buffer.
- FireAudioCallback();
- if (context_->config.startThread) {
- audio_thread_.reset(
- new base::DelegateSimpleThread(this, "plugin_audio_thread"));
- audio_thread_->Start();
- }
- filter_->Send(new ViewHostMsg_PlayAudioStream(0, stream_id_));
-}
-
-void AudioDeviceContext::OnVolume(double volume) {
-}
-
-void AudioDeviceContext::Run() {
- int pending_data;
- while (sizeof(pending_data) == socket_->Receive(&pending_data,
- sizeof(pending_data)) &&
- pending_data >= 0) {
- FireAudioCallback();
- }
-}
diff --git a/chrome/renderer/pepper_devices.h b/chrome/renderer/pepper_devices.h
deleted file mode 100644
index 1c0ee41..0000000
--- a/chrome/renderer/pepper_devices.h
+++ /dev/null
@@ -1,128 +0,0 @@
-// Copyright (c) 2010 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_DEVICES_H_
-#define CHROME_RENDERER_PEPPER_DEVICES_H_
-#pragma once
-
-#include "app/surface/transport_dib.h"
-#include "base/basictypes.h"
-#include "base/scoped_ptr.h"
-#include "base/shared_memory.h"
-#include "base/threading/simple_thread.h"
-#include "chrome/renderer/audio_message_filter.h"
-#include "third_party/npapi/bindings/npapi.h"
-#include "third_party/npapi/bindings/npapi_extensions.h"
-#include "ui/gfx/rect.h"
-
-class WebPluginDelegatePepper;
-class SkBitmap;
-
-// Lists all contexts currently open for painting. These are ones requested by
-// the plugin but not destroyed by it yet. The source pointer is the raw
-// pixels. We use this to look up the corresponding transport DIB when the
-// plugin tells us to flush or destroy it.
-class Graphics2DDeviceContext {
- public:
- explicit Graphics2DDeviceContext(WebPluginDelegatePepper* plugin_delegate);
- ~Graphics2DDeviceContext();
-
- NPError Initialize(gfx::Rect window_rect,
- const NPDeviceContext2DConfig* config,
- NPDeviceContext2D* context);
-
- NPError Flush(SkBitmap* commited_bitmap, NPDeviceContext2D* context,
- NPDeviceFlushContextCallbackPtr callback, NPP id,
- void* user_data);
-
- // Notifications that the render view has rendered the page and that it has
- // been flushed to the screen.
- void RenderViewInitiatedPaint();
- void RenderViewFlushedPaint();
-
- TransportDIB* transport_dib() { return transport_dib_.get(); }
- skia::PlatformCanvas* canvas() { return canvas_.get(); }
-
- private:
- struct FlushCallbackData;
- typedef std::vector<FlushCallbackData> FlushCallbackVector;
-
- WebPluginDelegatePepper* plugin_delegate_;
-
- static int32 next_buffer_id_;
- scoped_ptr<TransportDIB> transport_dib_;
-
- // The canvas associated with the transport DIB, containing the mapped
- // memory of the image.
- scoped_ptr<skia::PlatformCanvas> canvas_;
-
- // The plugin may be constantly giving us paint messages. "Unpainted" ones
- // are paint requests which have never been painted. These could have been
- // done while the RenderView was already waiting for an ACK from a previous
- // paint, so won't generate a new one yet.
- //
- // "Painted" ones are those paints that have been painted by RenderView, but
- // for which the ACK from the browser has not yet been received.
- //
- // When we get updates from a plugin with a callback, it is first added to
- // the unpainted callbacks. When the renderer has initiated a paint, we'll
- // move it to the painted callbacks list. When the renderer receives a flush,
- // we'll execute the callback and remove it from the list.
- FlushCallbackVector unpainted_flush_callbacks_;
- FlushCallbackVector painted_flush_callbacks_;
-
- DISALLOW_COPY_AND_ASSIGN(Graphics2DDeviceContext);
-};
-
-
-// Each instance of AudioDeviceContext corresponds to one host stream (and one
-// audio context). NPDeviceContextAudio contains the id of the context's
-// stream in the privatePtr member.
-class AudioDeviceContext : public AudioMessageFilter::Delegate,
- public base::DelegateSimpleThread::Delegate {
- public:
- explicit AudioDeviceContext();
- virtual ~AudioDeviceContext();
-
- NPError Initialize(AudioMessageFilter* filter,
- const NPDeviceContextAudioConfig* config,
- NPDeviceContextAudio* context);
-
- base::SharedMemory* shared_memory() { return shared_memory_.get(); }
- uint32 shared_memory_size() { return shared_memory_size_; }
- base::SyncSocket* socket() { return socket_.get(); }
-
- private:
-
- // AudioMessageFilter::Delegate implementation
- virtual void OnRequestPacket(AudioBuffersState buffers_state);
- virtual void OnStateChanged(const ViewMsg_AudioStreamState_Params& state);
- virtual void OnCreated(base::SharedMemoryHandle handle, uint32 length);
- virtual void OnLowLatencyCreated(base::SharedMemoryHandle handle,
- base::SyncSocket::Handle socket_handle,
- uint32 length);
- virtual void OnVolume(double volume);
- virtual void OnDestroy();
- // End of AudioMessageFilter::Delegate implementation
-
- // DelegateSimpleThread::Delegate implementation
- virtual void Run();
- // End of DelegateSimpleThread::Delegate implementation
-
- void FireAudioCallback() {
- if (context_ && context_->config.callback) {
- context_->config.callback(context_);
- }
- }
-
- NPDeviceContextAudio* context_;
- scoped_refptr<AudioMessageFilter> filter_;
- int32 stream_id_;
- scoped_ptr<base::SharedMemory> shared_memory_;
- uint32 shared_memory_size_;
- scoped_ptr<base::SyncSocket> socket_;
- scoped_ptr<base::DelegateSimpleThread> audio_thread_;
-};
-
-#endif // CHROME_RENDERER_PEPPER_DEVICES_H_
diff --git a/chrome/renderer/pepper_devices_browsertest.cc b/chrome/renderer/pepper_devices_browsertest.cc
deleted file mode 100644
index c1e1a6b..0000000
--- a/chrome/renderer/pepper_devices_browsertest.cc
+++ /dev/null
@@ -1,269 +0,0 @@
-// Copyright (c) 2010 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 <map>
-#include <vector>
-
-#include "base/string_util.h"
-#include "base/utf_string_conversions.h"
-#include "build/build_config.h"
-#include "chrome/common/render_messages.h"
-#include "chrome/renderer/pepper_devices.h"
-#include "chrome/renderer/webplugin_delegate_pepper.h"
-#include "chrome/test/render_view_test.h"
-#include "testing/gtest/include/gtest/gtest.h"
-#include "third_party/npapi/bindings/npapi.h"
-#include "third_party/npapi/bindings/npruntime.h"
-#include "third_party/WebKit/Source/WebKit/chromium/public/WebPlugin.h"
-#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginParams.h"
-#include "third_party/WebKit/Source/WebKit/chromium/public/WebRect.h"
-#include "webkit/plugins/npapi/plugin_instance.h"
-#include "webkit/plugins/npapi/plugin_list.h"
-#include "webkit/plugins/npapi/webplugin_impl.h"
-
-class PepperDeviceTest;
-
-namespace {
-
-const FilePath::CharType kTestPluginFileName[] =
- FILE_PATH_LITERAL("pepper-device-tester");
-const char kTestPluginMimeType[] = "chrome-test/pepper-device-test";
-
-// This maps the NPP instances to the test object so our C callbacks can easily
-// get back to the object. There will normally be only one item in this map.
-static std::map<NPP, PepperDeviceTest*> active_tests;
-
-NPError NPP_New(NPMIMEType plugin_type, NPP instance,
- uint16 mode, int16 argc, char* argn[],
- char* argv[], NPSavedData* saved) {
- // Watch out: active_tests won't contain the NPP pointer until after this
- // call is complete, so don't use it.
- return NPERR_NO_ERROR;
-}
-
-NPError NPP_Destroy(NPP instance, NPSavedData** saved) {
- if (!instance)
- return NPERR_INVALID_INSTANCE_ERROR;
- return NPERR_NO_ERROR;
-}
-
-NPError NPP_SetWindow(NPP instance, NPWindow* window) {
- return NPERR_NO_ERROR;
-}
-
-int16 NPP_HandleEvent(NPP instance, void* event) {
- return 0;
-}
-
-NPError NPP_GetValue(NPP instance, NPPVariable variable, void* value) {
- if (!instance)
- return NPERR_INVALID_INSTANCE_ERROR;
- switch (variable) {
- case NPPVpluginNeedsXEmbed:
- *static_cast<NPBool*>(value) = 1;
- return NPERR_NO_ERROR;
- default:
- return NPERR_INVALID_PARAM;
- }
-}
-
-NPError NPP_SetValue(NPP instance, NPNVariable variable, void* value) {
- return NPERR_NO_ERROR;
-}
-
-NPError API_CALL NP_GetEntryPoints(NPPluginFuncs* plugin_funcs) {
- plugin_funcs->newp = NPP_New;
- plugin_funcs->destroy = NPP_Destroy;
- plugin_funcs->setwindow = NPP_SetWindow;
- plugin_funcs->event = NPP_HandleEvent;
- plugin_funcs->getvalue = NPP_GetValue;
- plugin_funcs->setvalue = NPP_SetValue;
- return NPERR_NO_ERROR;
-}
-
-#if defined(OS_MACOSX) || defined(OS_WIN)
-NPError API_CALL NP_Initialize(NPNetscapeFuncs* browser_funcs) {
- return NPERR_NO_ERROR;
-}
-#else
-NPError API_CALL NP_Initialize(NPNetscapeFuncs* browser_funcs,
- NPPluginFuncs* plugin_funcs) {
- NP_GetEntryPoints(plugin_funcs);
- return NPERR_NO_ERROR;
-}
-#endif
-
-NPError API_CALL NP_Shutdown() {
- return NPERR_NO_ERROR;
-}
-
-} // namespace
-
-// PepperDeviceTest ------------------------------------------------------------
-
-class PepperDeviceTest : public RenderViewTest {
- public:
- WebPluginDelegatePepper* pepper_plugin() const { return pepper_plugin_; }
-
- NPP npp() const { return pepper_plugin_->instance()->npp(); }
-
- protected:
- // Logs that the given flush command was called in flush_calls.
- static void FlushCalled(NPP instance,
- NPDeviceContext* context,
- NPError err,
- NPUserData* user_data);
-
- // Audio callback, currently empty.
- static void AudioCallback(NPDeviceContextAudio* context);
-
- // A log of flush commands we can use to check the async callbacks.
- struct FlushData {
- NPP instance;
- NPDeviceContext* context;
- NPError err;
- NPUserData* user_data;
- };
- std::vector<FlushData> flush_calls_;
-
- private:
- // testing::Test implementation.
- virtual void SetUp();
- virtual void TearDown();
-
- scoped_ptr<webkit::npapi::WebPluginImpl> plugin_;
- WebPluginDelegatePepper* pepper_plugin_; // FIXME(brettw): check lifetime.
-};
-
-void PepperDeviceTest::SetUp() {
- RenderViewTest::SetUp();
-
- webkit::npapi::PluginEntryPoints entry_points = {
-#if !defined(OS_POSIX) || defined(OS_MACOSX)
- NP_GetEntryPoints,
-#endif
- NP_Initialize,
- NP_Shutdown
- };
- webkit::npapi::PluginList::Singleton()->RegisterInternalPlugin(
- FilePath(kTestPluginFileName),
- "Pepper device test plugin",
- "Pepper device test plugin",
- kTestPluginMimeType,
- entry_points);
-
- // Create the WebKit plugin with no delegates (this seems to work
- // sufficiently for the test).
- WebKit::WebPluginParams params;
- plugin_.reset(new webkit::npapi::WebPluginImpl(
- NULL, params, FilePath(), std::string(),
- base::WeakPtr<webkit::npapi::WebPluginPageDelegate>()));
-
- // Create a pepper plugin for the RenderView.
- pepper_plugin_ = WebPluginDelegatePepper::Create(
- FilePath(kTestPluginFileName), kTestPluginMimeType, view_->AsWeakPtr());
- ASSERT_TRUE(pepper_plugin_);
- ASSERT_TRUE(pepper_plugin_->Initialize(GURL(), std::vector<std::string>(),
- std::vector<std::string>(),
- plugin_.get(), false));
-
- // Normally the RenderView creates the pepper plugin and registers it with
- // its internal list. Since we're creating it manually, we have to reach in
- // and register it to prevent tear-down from asserting.
- view_->current_oldstyle_pepper_plugins_.insert(pepper_plugin_);
-
- active_tests[npp()] = this;
-
- // Need to specify a window size or graphics calls will fail on the 0x0
- // bitmap.
- gfx::Rect rect(0, 0, 100, 100);
- view_->OnResize(rect.size(), gfx::Rect());
- pepper_plugin_->UpdateGeometry(rect, rect);
-}
-
-void PepperDeviceTest::TearDown() {
- active_tests.erase(active_tests.find(npp()));
-
- plugin_.reset();
- if (pepper_plugin_)
- pepper_plugin_->PluginDestroyed();
-
- webkit::npapi::PluginList::Singleton()->UnregisterInternalPlugin(
- FilePath(kTestPluginFileName));
-
- RenderViewTest::TearDown();
-}
-
-// static
-void PepperDeviceTest::FlushCalled(NPP instance,
- NPDeviceContext* context,
- NPError err,
- NPUserData* user_data) {
- if (active_tests.find(instance) == active_tests.end())
- return;
- PepperDeviceTest* that = active_tests[instance];
-
- FlushData flush_data;
- flush_data.instance = instance;
- flush_data.context = context;
- flush_data.err = err;
- flush_data.user_data = user_data;
- that->flush_calls_.push_back(flush_data);
-}
-
-void PepperDeviceTest::AudioCallback(NPDeviceContextAudio* context) {
-}
-
-
-// -----------------------------------------------------------------------------
-
-// TODO(brettw) this crashes on Mac. Figure out why and enable.
-#if !defined(OS_MACOSX)
-
-TEST_F(PepperDeviceTest, Flush) {
- // Create a 2D device.
- NPDeviceContext2DConfig config;
- NPDeviceContext2D context;
- EXPECT_EQ(NPERR_NO_ERROR,
- pepper_plugin()->Device2DInitializeContext(&config, &context));
-
- // Flush the bitmap. Here we fake the invalidate call to the RenderView since
- // there isn't an actual visible web page that would otherwise get painted.
- // The callback should not get called synchronously.
- pepper_plugin()->Device2DFlushContext(npp(), &context, &FlushCalled, NULL);
- view_->didInvalidateRect(WebKit::WebRect(0, 0, 100, 100));
- EXPECT_TRUE(flush_calls_.empty());
-
- // Run the message loop which should process the pending paints, there should
- // still be no callbacks since the stuff hasn't been copied to the screen,
- // but there should be a paint message sent to the browser.
- MessageLoop::current()->RunAllPending();
- EXPECT_TRUE(flush_calls_.empty());
- EXPECT_TRUE(render_thread_.sink().GetFirstMessageMatching(
- ViewHostMsg_UpdateRect::ID));
-
- // Send a paint ACK, this should trigger the callback.
- view_->OnMessageReceived(ViewMsg_UpdateRect_ACK(view_->routing_id()));
- EXPECT_EQ(1u, flush_calls_.size());
-}
-#endif
-
-TEST_F(PepperDeviceTest, AudioInit) {
- NPDeviceContextAudioConfig config;
- config.sampleRate = NPAudioSampleRate44100Hz;
- config.sampleType = NPAudioSampleTypeInt16;
- config.outputChannelMap = NPAudioChannelStereo;
- config.callback = &AudioCallback;
- config.userData = this;
- NPDeviceContextAudio context;
- EXPECT_EQ(NPERR_NO_ERROR,
- pepper_plugin()->DeviceAudioInitializeContext(&config, &context));
- EXPECT_TRUE(render_thread_.sink().GetFirstMessageMatching(
- ViewHostMsg_CreateAudioStream::ID));
- EXPECT_EQ(NPERR_NO_ERROR,
- pepper_plugin()->DeviceAudioDestroyContext(&context));
- EXPECT_TRUE(render_thread_.sink().GetFirstMessageMatching(
- ViewHostMsg_CloseAudioStream::ID));
-}
-
diff --git a/chrome/renderer/pepper_scrollbar_widget.cc b/chrome/renderer/pepper_scrollbar_widget.cc
deleted file mode 100644
index d81515a..0000000
--- a/chrome/renderer/pepper_scrollbar_widget.cc
+++ /dev/null
@@ -1,300 +0,0 @@
-// Copyright (c) 2010 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_scrollbar_widget.h"
-
-#include "base/basictypes.h"
-#include "base/logging.h"
-#include "base/message_loop.h"
-#include "chrome/renderer/pepper_devices.h"
-#include "skia/ext/platform_canvas.h"
-#include "skia/ext/platform_device.h"
-#include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h"
-#include "third_party/WebKit/Source/WebKit/chromium/public/WebScrollbar.h"
-#include "third_party/WebKit/Source/WebKit/chromium/public/WebVector.h"
-#include "webkit/plugins/npapi/plugin_instance.h"
-#include "webkit/glue/webkit_glue.h"
-
-using WebKit::WebInputEvent;
-using WebKit::WebKeyboardEvent;
-using WebKit::WebMouseEvent;
-using WebKit::WebMouseWheelEvent;
-using WebKit::WebRect;
-using WebKit::WebScrollbar;
-using WebKit::WebVector;
-
-
-// Anonymous namespace for functions converting NPAPI to WebInputEvents types.
-namespace {
-
-WebKeyboardEvent BuildKeyEvent(const NPPepperEvent& event) {
- WebKeyboardEvent key_event;
- switch (event.type) {
- case NPEventType_RawKeyDown:
- key_event.type = WebInputEvent::RawKeyDown;
- break;
- case NPEventType_KeyDown:
- key_event.type = WebInputEvent::KeyDown;
- break;
- case NPEventType_KeyUp:
- key_event.type = WebInputEvent::KeyUp;
- break;
- }
- key_event.timeStampSeconds = event.timeStampSeconds;
- key_event.modifiers = event.u.key.modifier;
- key_event.windowsKeyCode = event.u.key.normalizedKeyCode;
- return key_event;
-}
-
-WebKeyboardEvent BuildCharEvent(const NPPepperEvent& event) {
- WebKeyboardEvent key_event;
- key_event.type = WebInputEvent::Char;
- key_event.timeStampSeconds = event.timeStampSeconds;
- key_event.modifiers = event.u.character.modifier;
- // For consistency, check that the sizes of the texts agree.
- DCHECK(sizeof(event.u.character.text) == sizeof(key_event.text));
- DCHECK(sizeof(event.u.character.unmodifiedText) ==
- sizeof(key_event.unmodifiedText));
- for (size_t i = 0; i < WebKeyboardEvent::textLengthCap; ++i) {
- key_event.text[i] = event.u.character.text[i];
- key_event.unmodifiedText[i] = event.u.character.unmodifiedText[i];
- }
- return key_event;
-}
-
-WebMouseEvent BuildMouseEvent(const NPPepperEvent& event) {
- WebMouseEvent mouse_event;
- switch (event.type) {
- case NPEventType_MouseDown:
- mouse_event.type = WebInputEvent::MouseDown;
- break;
- case NPEventType_MouseUp:
- mouse_event.type = WebInputEvent::MouseUp;
- break;
- case NPEventType_MouseMove:
- mouse_event.type = WebInputEvent::MouseMove;
- break;
- case NPEventType_MouseEnter:
- mouse_event.type = WebInputEvent::MouseEnter;
- break;
- case NPEventType_MouseLeave:
- mouse_event.type = WebInputEvent::MouseLeave;
- break;
- }
- mouse_event.timeStampSeconds = event.timeStampSeconds;
- mouse_event.modifiers = event.u.mouse.modifier;
- mouse_event.button = static_cast<WebMouseEvent::Button>(event.u.mouse.button);
- mouse_event.x = event.u.mouse.x;
- mouse_event.y = event.u.mouse.y;
- mouse_event.clickCount = event.u.mouse.clickCount;
- return mouse_event;
-}
-
-WebMouseWheelEvent BuildMouseWheelEvent(const NPPepperEvent& event) {
- WebMouseWheelEvent mouse_wheel_event;
- mouse_wheel_event.type = WebInputEvent::MouseWheel;
- mouse_wheel_event.timeStampSeconds = event.timeStampSeconds;
- mouse_wheel_event.modifiers = event.u.wheel.modifier;
- mouse_wheel_event.deltaX = event.u.wheel.deltaX;
- mouse_wheel_event.deltaY = event.u.wheel.deltaY;
- mouse_wheel_event.wheelTicksX = event.u.wheel.wheelTicksX;
- mouse_wheel_event.wheelTicksY = event.u.wheel.wheelTicksY;
- mouse_wheel_event.scrollByPage = event.u.wheel.scrollByPage;
- return mouse_wheel_event;
-}
-
-} // namespace
-
-PepperScrollbarWidget::PepperScrollbarWidget(
- const NPScrollbarCreateParams& params) {
- scrollbar_.reset(WebScrollbar::create(
- static_cast<WebKit::WebScrollbarClient*>(this),
- params.vertical ? WebScrollbar::Vertical : WebScrollbar::Horizontal));
- AddRef();
-}
-
-PepperScrollbarWidget::~PepperScrollbarWidget() {
-}
-
-void PepperScrollbarWidget::Destroy() {
- Release();
-}
-
-void PepperScrollbarWidget::Paint(Graphics2DDeviceContext* context,
- const NPRect& dirty) {
- gfx::Rect rect(dirty.left, dirty.top, dirty.right - dirty.left,
- dirty.bottom - dirty.top);
- scrollbar_->paint(webkit_glue::ToWebCanvas(context->canvas()), rect);
- dirty_rect_ = dirty_rect_.Subtract(rect);
-}
-
-bool PepperScrollbarWidget::HandleEvent(const NPPepperEvent& event) {
- bool rv = false;
-
- switch (event.type) {
- case NPEventType_Undefined:
- return false;
- case NPEventType_MouseDown:
- case NPEventType_MouseUp:
- case NPEventType_MouseMove:
- case NPEventType_MouseEnter:
- case NPEventType_MouseLeave:
- rv = scrollbar_->handleInputEvent(BuildMouseEvent(event));
- break;
- case NPEventType_MouseWheel:
- rv = scrollbar_->handleInputEvent(BuildMouseWheelEvent(event));
- break;
- case NPEventType_RawKeyDown:
- case NPEventType_KeyDown:
- case NPEventType_KeyUp:
- rv = scrollbar_->handleInputEvent(BuildKeyEvent(event));
- break;
- case NPEventType_Char:
- rv = scrollbar_->handleInputEvent(BuildCharEvent(event));
- break;
- case NPEventType_Minimize:
- case NPEventType_Focus:
- case NPEventType_Device:
- // NOTIMPLEMENTED();
- break;
- }
-
- return rv;
-}
-
-void PepperScrollbarWidget::GetProperty(
- NPWidgetProperty property, void* value) {
- switch (property) {
- case NPWidgetPropertyLocation: {
- NPRect* rv = static_cast<NPRect*>(value);
- rv->left = location_.x();
- rv->top = location_.y();
- rv->right = location_.right();
- rv->bottom = location_.bottom();
- break;
- }
- case NPWidgetPropertyDirtyRect: {
- NPRect* rv = reinterpret_cast<NPRect*>(value);
- rv->left = dirty_rect_.x();
- rv->top = dirty_rect_.y();
- rv->right = dirty_rect_.right();
- rv->bottom = dirty_rect_.bottom();
- break;
- }
- case NPWidgetPropertyScrollbarThickness: {
- int32* rv = static_cast<int32*>(value);
- *rv = WebScrollbar::defaultThickness();
- break;
- }
- case NPWidgetPropertyScrollbarValue: {
- int32* rv = static_cast<int32*>(value);
- *rv = scrollbar_->value();
- break;
- }
- default:
- NOTREACHED();
- break;
- }
-}
-
-void PepperScrollbarWidget::SetProperty(
- NPWidgetProperty property, void* value) {
- switch (property) {
- case NPWidgetPropertyLocation: {
- NPRect* r = static_cast<NPRect*>(value);
- location_ = gfx::Rect(
- r->left, r->top, r->right - r->left, r->bottom - r->top);
- scrollbar_->setLocation(location_);
- break;
- }
- case NPWidgetPropertyScrollbarValue: {
- int32* position = static_cast<int*>(value);
- scrollbar_->setValue(*position);
- break;
- }
- case NPWidgetPropertyScrollbarDocumentSize: {
- int32* total_length = static_cast<int32*>(value);
- scrollbar_->setDocumentSize(*total_length);
- break;
- }
- case NPWidgetPropertyScrollbarTickMarks: {
- NPScrollbarTickMarks* tickmarks =
- static_cast<NPScrollbarTickMarks*>(value);
- tickmarks_.resize(tickmarks->count);
- for (uint32 i = 0; i < tickmarks->count; ++i) {
- WebRect rect(
- tickmarks->tickmarks[i].left,
- tickmarks->tickmarks[i].top,
- tickmarks->tickmarks[i].right - tickmarks->tickmarks[i].left,
- tickmarks->tickmarks[i].bottom - tickmarks->tickmarks[i].top);
- tickmarks_[i] = rect;
- }
- dirty_rect_ = location_;
- NotifyInvalidate();
- break;
- }
- case NPWidgetPropertyScrollbarScrollByLine:
- case NPWidgetPropertyScrollbarScrollByPage:
- case NPWidgetPropertyScrollbarScrollByDocument:
- case NPWidgetPropertyScrollbarScrollByPixels: {
- bool forward;
- float multiplier = 1.0;
-
- WebScrollbar::ScrollGranularity granularity;
- if (property == NPWidgetPropertyScrollbarScrollByLine) {
- forward = *static_cast<bool*>(value);
- granularity = WebScrollbar::ScrollByLine;
- } else if (property == NPWidgetPropertyScrollbarScrollByPage) {
- forward = *static_cast<bool*>(value);
- granularity = WebScrollbar::ScrollByPage;
- } else if (property == NPWidgetPropertyScrollbarScrollByDocument) {
- forward = *static_cast<bool*>(value);
- granularity = WebScrollbar::ScrollByDocument;
- } else {
- multiplier = static_cast<float>(*static_cast<int32*>(value));
- forward = multiplier >= 0;
- if (multiplier < 0)
- multiplier *= -1;
- granularity = WebScrollbar::ScrollByPixel;
- }
- scrollbar_->scroll(
- forward ? WebScrollbar::ScrollForward : WebScrollbar::ScrollBackward,
- granularity, multiplier);
- break;
- }
- default:
- NOTREACHED();
- break;
- }
-}
-
-void PepperScrollbarWidget::valueChanged(WebScrollbar*) {
- WidgetPropertyChanged(NPWidgetPropertyScrollbarValue);
-}
-
-void PepperScrollbarWidget::invalidateScrollbarRect(WebScrollbar*,
- const WebRect& rect) {
- dirty_rect_ = dirty_rect_.Union(rect);
- // Can't call into the client to tell them about the invalidate right away,
- // since the Scrollbar code is still in the middle of updating its internal
- // state.
- MessageLoop::current()->PostTask(
- FROM_HERE,
- NewRunnableMethod(this, &PepperScrollbarWidget::NotifyInvalidate));
-}
-
-void PepperScrollbarWidget::getTickmarks(WebKit::WebScrollbar*,
- WebVector<WebRect>* tickmarks) const {
- if (tickmarks_.empty()) {
- WebRect* rects = NULL;
- tickmarks->assign(rects, 0);
- } else {
- tickmarks->assign(&tickmarks_[0], tickmarks_.size());
- }
-}
-
-void PepperScrollbarWidget::NotifyInvalidate() {
- if (!dirty_rect_.IsEmpty())
- WidgetPropertyChanged(NPWidgetPropertyDirtyRect);
-}
diff --git a/chrome/renderer/pepper_scrollbar_widget.h b/chrome/renderer/pepper_scrollbar_widget.h
deleted file mode 100644
index c9a4d56..0000000
--- a/chrome/renderer/pepper_scrollbar_widget.h
+++ /dev/null
@@ -1,62 +0,0 @@
-// Copyright (c) 2010 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_SCROLLBAR_WIDGET_H_
-#define CHROME_RENDERER_PEPPER_SCROLLBAR_WIDGET_H_
-#pragma once
-
-#include <vector>
-
-#include "base/ref_counted.h"
-#include "base/scoped_ptr.h"
-#include "build/build_config.h"
-#include "chrome/renderer/pepper_widget.h"
-#include "third_party/WebKit/Source/WebKit/chromium/public/WebRect.h"
-#include "third_party/WebKit/Source/WebKit/chromium/public/WebScrollbarClient.h"
-#include "ui/gfx/point.h"
-#include "ui/gfx/rect.h"
-
-// An implementation of a horizontal/vertical scrollbar.
-class PepperScrollbarWidget : public PepperWidget,
- public WebKit::WebScrollbarClient,
- public base::RefCounted<PepperScrollbarWidget> {
- public:
- explicit PepperScrollbarWidget(const NPScrollbarCreateParams& params);
-
- // PepperWidget
- virtual void Destroy();
- virtual void Paint(Graphics2DDeviceContext* context, const NPRect& dirty);
- virtual bool HandleEvent(const NPPepperEvent& event);
- virtual void GetProperty(NPWidgetProperty property, void* value);
- virtual void SetProperty(NPWidgetProperty property, void* value);
-
- // WebKit::WebScrollbarClient
- virtual void valueChanged(WebKit::WebScrollbar*);
- virtual void invalidateScrollbarRect(WebKit::WebScrollbar*,
- const WebKit::WebRect&);
- virtual void getTickmarks(WebKit::WebScrollbar*,
- WebKit::WebVector<WebKit::WebRect>*) const;
-
-#if defined(OS_LINUX)
- static void SetScrollbarColors(unsigned inactive_color,
- unsigned active_color,
- unsigned track_color);
-#endif
-
- private:
- friend class base::RefCounted<PepperScrollbarWidget>;
-
- ~PepperScrollbarWidget();
-
- void NotifyInvalidate();
-
- gfx::Rect dirty_rect_;
- gfx::Rect location_;
- std::vector<WebKit::WebRect> tickmarks_;
- scoped_ptr<WebKit::WebScrollbar> scrollbar_;
-
- DISALLOW_COPY_AND_ASSIGN(PepperScrollbarWidget);
-};
-
-#endif // CHROME_RENDERER_PEPPER_SCROLLBAR_WIDGET_H_
diff --git a/chrome/renderer/pepper_widget.cc b/chrome/renderer/pepper_widget.cc
deleted file mode 100644
index 176510f..0000000
--- a/chrome/renderer/pepper_widget.cc
+++ /dev/null
@@ -1,146 +0,0 @@
-// Copyright (c) 2010 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_widget.h"
-
-#include "base/hash_tables.h"
-#include "base/lazy_instance.h"
-#include "chrome/renderer/pepper_scrollbar_widget.h"
-#include "chrome/renderer/webplugin_delegate_pepper.h"
-#include "skia/ext/platform_canvas.h"
-#include "webkit/plugins/npapi/plugin_instance.h"
-#include "webkit/plugins/npapi/webplugin.h"
-#include "webkit/plugins/npapi/webplugin_delegate.h"
-
-#if defined(OS_WIN)
-#include "base/win/windows_version.h"
-#endif
-
-static int g_next_id;
-typedef base::hash_map<int, PepperWidget*> WidgetMap;
-static base::LazyInstance<WidgetMap> g_widgets(base::LINKER_INITIALIZED);
-
-NPError NPCreateWidget(NPP instance,
- NPWidgetType type,
- void* params,
- NPWidgetID* id) {
- PepperWidget* widget;
- switch (type) {
- case NPWidgetTypeScrollbar:
- widget = new PepperScrollbarWidget(
- *static_cast<NPScrollbarCreateParams*>(params));
- break;
- default:
- return NPERR_INVALID_PARAM;
- }
-
- *id = ++g_next_id;
- widget->Init(instance, *id);
- return NPERR_NO_ERROR;
-}
-
-NPError NPDestroyWidget(NPP instance, NPWidgetID id) {
- WidgetMap::iterator iter = g_widgets.Get().find(id);
- if (iter == g_widgets.Get().end())
- return NPERR_INVALID_PARAM;
-
- iter->second->Destroy();
- return NPERR_NO_ERROR;
-}
-
-NPError NPPaintWidget(NPP instance,
- NPWidgetID id,
- NPDeviceContext2D* context,
- NPRect* dirty) {
- WidgetMap::iterator iter = g_widgets.Get().find(id);
- if (iter == g_widgets.Get().end())
- return NPERR_INVALID_PARAM;
-
- webkit::npapi::PluginInstance* plugin =
- static_cast<webkit::npapi::PluginInstance*>(instance->ndata);
- WebPluginDelegatePepper* delegate =
- static_cast<WebPluginDelegatePepper*>(plugin->webplugin()->delegate());
- Graphics2DDeviceContext* gdc = delegate->GetGraphicsContext(context);
- iter->second->Paint(gdc, *dirty);
-
-#if defined(OS_WIN)
- if (base::win::GetVersion() == base::win::VERSION_XP) {
- gdc->canvas()->getTopPlatformDevice().makeOpaque(
- dirty->left, dirty->top, dirty->right - dirty->left,
- dirty->bottom - dirty->top);
- }
-#endif
- return NPERR_NO_ERROR;
-}
-
-bool NPHandleWidgetEvent(NPP instance, NPWidgetID id, NPPepperEvent* event) {
- WidgetMap::iterator iter = g_widgets.Get().find(id);
- if (iter == g_widgets.Get().end())
- return false;
-
- return iter->second->HandleEvent(*event);
-}
-
-NPError NPGetWidgetProperty(NPP instance,
- NPWidgetID id,
- NPWidgetProperty property,
- void* value) {
- WidgetMap::iterator iter = g_widgets.Get().find(id);
- if (iter == g_widgets.Get().end())
- return NPERR_INVALID_PARAM;
-
- iter->second->GetProperty(property, value);
- return NPERR_NO_ERROR;
-}
-
-NPError NPSetWidgetProperty(NPP instance,
- NPWidgetID id,
- NPWidgetProperty property,
- void* value) {
- WidgetMap::iterator iter = g_widgets.Get().find(id);
- if (iter == g_widgets.Get().end())
- return NPERR_INVALID_PARAM;
-
- iter->second->SetProperty(property, value);
- return NPERR_NO_ERROR;
-}
-
-NPWidgetExtensions g_widget_extensions = {
- NPCreateWidget,
- NPDestroyWidget,
- NPPaintWidget,
- NPHandleWidgetEvent,
- NPGetWidgetProperty,
- NPSetWidgetProperty
-};
-
-// static
-NPWidgetExtensions* PepperWidget::GetWidgetExtensions() {
- return &g_widget_extensions;
-}
-
-PepperWidget::PepperWidget() : instance_(NULL), id_(0) {
-}
-
-PepperWidget::~PepperWidget() {
- if (id_)
- g_widgets.Get().erase(id_);
-}
-
-void PepperWidget::Init(NPP instance, int id) {
- instance_ = instance;
- id_ = id;
- g_widgets.Get()[id] = this;
-}
-
-void PepperWidget::WidgetPropertyChanged(NPWidgetProperty property) {
- webkit::npapi::PluginInstance* instance =
- static_cast<webkit::npapi::PluginInstance*>(instance_->ndata);
- NPPExtensions* extensions = NULL;
- instance->NPP_GetValue(NPPVPepperExtensions, &extensions);
- if (!extensions)
- return;
-
- extensions->widgetPropertyChanged(instance_, id_, property);
-}
diff --git a/chrome/renderer/pepper_widget.h b/chrome/renderer/pepper_widget.h
deleted file mode 100644
index 7e0654e..0000000
--- a/chrome/renderer/pepper_widget.h
+++ /dev/null
@@ -1,42 +0,0 @@
-// Copyright (c) 2010 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_WIDGET_H_
-#define CHROME_RENDERER_PEPPER_WIDGET_H_
-#pragma once
-
-#include "base/basictypes.h"
-#include "third_party/npapi/bindings/npapi_extensions.h"
-
-class Graphics2DDeviceContext;
-
-// Every class that implements a Pepper widget derives from this.
-class PepperWidget {
- public:
- static NPWidgetExtensions* GetWidgetExtensions();
-
- PepperWidget();
- void Init(NPP instance, int id);
-
- // Called as a result of the corresponding Pepper functions.
- virtual void Destroy() = 0;
- virtual void Paint(Graphics2DDeviceContext* context, const NPRect& dirty) = 0;
- virtual bool HandleEvent(const NPPepperEvent& event) = 0;
- virtual void GetProperty(NPWidgetProperty property, void* value) = 0;
- virtual void SetProperty(NPWidgetProperty property, void* value) = 0;
-
- protected:
- virtual ~PepperWidget();
-
- // Tells the plugin that a property changed.
- void WidgetPropertyChanged(NPWidgetProperty property);
-
- private:
- NPP instance_;
- int id_;
-
- DISALLOW_COPY_AND_ASSIGN(PepperWidget);
-};
-
-#endif // CHROME_RENDERER_PEPPER_WIDGET_H_
diff --git a/chrome/renderer/render_view.cc b/chrome/renderer/render_view.cc
index 3da5fed..513d5f5 100644
--- a/chrome/renderer/render_view.cc
+++ b/chrome/renderer/render_view.cc
@@ -97,7 +97,6 @@
#include "chrome/renderer/visitedlink_slave.h"
#include "chrome/renderer/web_ui_bindings.h"
#include "chrome/renderer/webgraphicscontext3d_command_buffer_impl.h"
-#include "chrome/renderer/webplugin_delegate_pepper.h"
#include "chrome/renderer/webplugin_delegate_proxy.h"
#include "chrome/renderer/websharedworker_proxy.h"
#include "chrome/renderer/webworker_proxy.h"
@@ -3936,46 +3935,15 @@ webkit::npapi::WebPluginDelegate* RenderView::CreatePluginDelegate(
if (!PluginChannelHost::IsListening())
return NULL;
- bool use_pepper_host = false;
bool in_process_plugin = RenderProcess::current()->UseInProcessPlugins();
- // Check for trusted Pepper plugins.
- const char kPepperPrefix[] = "pepper-";
- if (StartsWithASCII(mime_type, kPepperPrefix, true)) {
- if (CommandLine::ForCurrentProcess()->
- HasSwitch(switches::kInternalPepper)) {
- in_process_plugin = true;
- use_pepper_host = true;
- } else {
- // In process Pepper plugins must be explicitly enabled.
- return NULL;
- }
- } else {
- FilePath internal_pdf_path;
- PathService::Get(chrome::FILE_PDF_PLUGIN, &internal_pdf_path);
- if (file_path == internal_pdf_path) {
- in_process_plugin = true;
- use_pepper_host = true;
- }
- }
-
if (in_process_plugin) {
- if (use_pepper_host) {
- WebPluginDelegatePepper* pepper_plugin =
- WebPluginDelegatePepper::Create(file_path, mime_type, AsWeakPtr());
- if (!pepper_plugin)
- return NULL;
-
- current_oldstyle_pepper_plugins_.insert(pepper_plugin);
- return pepper_plugin;
- } else {
#if defined(OS_WIN) // In-proc plugins aren't supported on Linux or Mac.
- return webkit::npapi::WebPluginDelegateImpl::Create(
- file_path, mime_type, gfx::NativeViewFromId(host_window_));
+ return webkit::npapi::WebPluginDelegateImpl::Create(
+ file_path, mime_type, gfx::NativeViewFromId(host_window_));
#else
- NOTIMPLEMENTED();
- return NULL;
+ NOTIMPLEMENTED();
+ return NULL;
#endif
- }
}
return new WebPluginDelegateProxy(mime_type, AsWeakPtr());
@@ -4577,35 +4545,6 @@ void RenderView::InsertCSS(const std::wstring& frame_xpath,
web_frame->insertStyleText(WebString::fromUTF8(css), WebString::fromUTF8(id));
}
-void RenderView::OnPepperPluginDestroy(
- WebPluginDelegatePepper* pepper_plugin) {
- std::set<WebPluginDelegatePepper*>::iterator found_pepper =
- current_oldstyle_pepper_plugins_.find(pepper_plugin);
- if (found_pepper == current_oldstyle_pepper_plugins_.end()) {
- NOTREACHED();
- return;
- }
- current_oldstyle_pepper_plugins_.erase(found_pepper);
-
- // The plugin could have been destroyed while it was waiting for a file
- // choose callback, so check all pending completion callbacks and NULL them.
- for (std::deque< linked_ptr<PendingFileChooser> >::iterator i =
- file_chooser_completions_.begin();
- i != file_chooser_completions_.end(); /* nothing */) {
- if ((*i)->completion == pepper_plugin) {
- // We NULL the first one instead of deleting it because the plugin might
- // be the one waiting for a file choose callback. If the callback later
- // comes, we don't want to send the result to the next callback in line.
- if (i == file_chooser_completions_.begin())
- (*i)->completion = NULL;
- else
- i = file_chooser_completions_.erase(i);
- } else {
- ++i;
- }
- }
-}
-
void RenderView::OnScriptEvalRequest(const string16& frame_xpath,
const string16& jscript,
int id,
@@ -5084,14 +5023,6 @@ void RenderView::OnResize(const gfx::Size& new_size,
void RenderView::DidInitiatePaint() {
// Notify the pepper plugins that we started painting.
pepper_delegate_.ViewInitiatedPaint();
-
- // Notify any "old-style" pepper plugins that we started painting. This is
- // used for internal bookkeeping only, so we know that the set can not change
- // under us.
- for (std::set<WebPluginDelegatePepper*>::iterator i =
- current_oldstyle_pepper_plugins_.begin();
- i != current_oldstyle_pepper_plugins_.end(); ++i)
- (*i)->RenderViewInitiatedPaint();
}
void RenderView::DidFlushPaint() {
@@ -5101,23 +5032,6 @@ void RenderView::DidFlushPaint() {
// won't change out from under us.
pepper_delegate_.ViewFlushedPaint();
- // Notify any old-style pepper plugins that we painted. This will call into
- // the plugin, and we it may ask to close itself as a result. This will, in
- // turn, modify our set, possibly invalidating the iterator. So we iterate on
- // a copy that won't change out from under us.
- // This should be deleted when we don't support old Pepper anymore.
- std::set<WebPluginDelegatePepper*> plugins = current_oldstyle_pepper_plugins_;
- for (std::set<WebPluginDelegatePepper*>::iterator i = plugins.begin();
- i != plugins.end(); ++i) {
- // The copy above makes sure our iterator is never invalid if some plugins
- // are destroyed. But some plugin may decide to close all of its views in
- // response to a paint in one of them, so we need to make sure each one is
- // still "current" before using it.
- if (current_oldstyle_pepper_plugins_.find(*i) !=
- current_oldstyle_pepper_plugins_.end())
- (*i)->RenderViewFlushedPaint();
- }
-
WebFrame* main_frame = webview()->mainFrame();
// If we have a provisional frame we are between the start and commit stages
diff --git a/chrome/renderer/render_view.h b/chrome/renderer/render_view.h
index 7173547..42e3ddb 100644
--- a/chrome/renderer/render_view.h
+++ b/chrome/renderer/render_view.h
@@ -112,8 +112,9 @@ class PluginGroup;
} // namespace npapi
namespace ppapi {
-class PluginInstance;
class FullscreenContainer;
+class PluginInstance;
+class PluginModule;
} // namespace ppapi
} // namespace webkit
@@ -331,11 +332,6 @@ class RenderView : public RenderWidget,
void OnMissingPluginStatus(WebPluginDelegateProxy* delegate,
int status);
- // Notification that the given pepper plugin we created is being deleted the
- // pointer must not be dereferenced as this is called from the destructor of
- // the plugin.
- void OnPepperPluginDestroy(WebPluginDelegatePepper* pepper_plugin);
-
// Creates a fullscreen container for a pepper plugin instance.
webkit::ppapi::FullscreenContainer* CreatePepperFullscreenContainer(
webkit::ppapi::PluginInstance* plugin);
@@ -1304,10 +1300,6 @@ class RenderView : public RenderWidget,
// or tab focus and visibily. These are non-owning references.
std::set<WebPluginDelegateProxy*> plugin_delegates_;
- // A list of all Pepper v1 plugins that we've created that haven't been
- // destroyed yet. Pepper v2 plugins are tracked by the pepper_delegate_.
- std::set<WebPluginDelegatePepper*> current_oldstyle_pepper_plugins_;
-
// Helper objects ------------------------------------------------------------
ScopedRunnableMethodFactory<RenderView> page_info_method_factory_;
diff --git a/chrome/renderer/webplugin_delegate_pepper.cc b/chrome/renderer/webplugin_delegate_pepper.cc
deleted file mode 100644
index 7a9e4ea..0000000
--- a/chrome/renderer/webplugin_delegate_pepper.cc
+++ /dev/null
@@ -1,1350 +0,0 @@
-// Copyright (c) 2011 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.
-
-#define PEPPER_APIS_ENABLED 1
-
-#include "chrome/renderer/webplugin_delegate_pepper.h"
-
-#include <string>
-#include <vector>
-
-#if defined(OS_LINUX)
-#include <unistd.h>
-#endif
-
-#include "base/file_path.h"
-#include "base/file_util.h"
-#include "base/md5.h"
-#include "base/message_loop.h"
-#include "base/metrics/histogram.h"
-#include "base/metrics/stats_counters.h"
-#include "base/path_service.h"
-#include "base/process_util.h"
-#include "base/scoped_ptr.h"
-#include "base/string_number_conversions.h"
-#include "base/string_util.h"
-#include "base/task.h"
-#include "base/time.h"
-#include "base/utf_string_conversions.h"
-#include "chrome/common/chrome_paths.h"
-#include "chrome/common/render_messages.h"
-#include "chrome/common/render_messages_params.h"
-#include "chrome/renderer/pepper_widget.h"
-#include "chrome/renderer/render_thread.h"
-#include "chrome/renderer/render_view.h"
-#include "chrome/renderer/webplugin_delegate_proxy.h"
-#include "ui/gfx/blit.h"
-#include "printing/native_metafile_factory.h"
-#include "printing/native_metafile.h"
-#include "third_party/npapi/bindings/npapi_extensions.h"
-#include "third_party/npapi/bindings/npapi_extensions_private.h"
-#include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h"
-#include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h"
-#include "webkit/glue/webcursor.h"
-#include "webkit/glue/webkit_glue.h"
-#include "webkit/plugins/npapi/plugin_constants_win.h"
-#include "webkit/plugins/npapi/plugin_instance.h"
-#include "webkit/plugins/npapi/plugin_lib.h"
-#include "webkit/plugins/npapi/plugin_list.h"
-#include "webkit/plugins/npapi/plugin_host.h"
-#include "webkit/plugins/npapi/plugin_stream_url.h"
-
-#if defined(OS_MACOSX)
-#include "base/mac/mac_util.h"
-#include "base/mac/scoped_cftyperef.h"
-#elif defined(OS_LINUX)
-#include "chrome/renderer/renderer_sandbox_support_linux.h"
-#include "printing/pdf_ps_metafile_cairo.h"
-#elif defined(OS_WIN)
-#include "printing/units.h"
-#include "skia/ext/vector_platform_device.h"
-#include "ui/gfx/codec/jpeg_codec.h"
-#include "ui/gfx/gdi_util.h"
-#endif
-
-using webkit::npapi::WebPlugin;
-using webkit::npapi::WebPluginDelegate;
-using webkit::npapi::WebPluginResourceClient;
-using WebKit::WebCursorInfo;
-using WebKit::WebKeyboardEvent;
-using WebKit::WebInputEvent;
-using WebKit::WebMouseEvent;
-using WebKit::WebMouseWheelEvent;
-
-namespace {
-
-// Implementation artifacts for a context
-struct Device2DImpl {
- TransportDIB* dib;
-};
-
-} // namespace
-
-static const float kPointsPerInch = 72.0;
-
-#if defined(OS_WIN)
-// Exported by pdf.dll
-typedef bool (*RenderPDFPageToDCProc)(
- const unsigned char* pdf_buffer, int buffer_size, int page_number, HDC dc,
- int dpi_x, int dpi_y, int bounds_origin_x, int bounds_origin_y,
- int bounds_width, int bounds_height, bool fit_to_bounds,
- bool stretch_to_bounds, bool keep_aspect_ratio, bool center_in_bounds);
-#endif // defined(OS_WIN)
-
-WebPluginDelegatePepper* WebPluginDelegatePepper::Create(
- const FilePath& filename,
- const std::string& mime_type,
- const base::WeakPtr<RenderView>& render_view) {
- scoped_refptr<webkit::npapi::PluginLib> plugin_lib(
- webkit::npapi::PluginLib::CreatePluginLib(filename));
- if (plugin_lib.get() == NULL)
- return NULL;
-
- NPError err = plugin_lib->NP_Initialize();
- if (err != NPERR_NO_ERROR)
- return NULL;
-
- scoped_refptr<webkit::npapi::PluginInstance> instance(
- plugin_lib->CreateInstance(mime_type));
- return new WebPluginDelegatePepper(render_view,
- instance.get());
-}
-
-void WebPluginDelegatePepper::didChooseFile(
- const WebKit::WebVector<WebKit::WebString>& file_names) {
- if (file_names.isEmpty()) {
- current_choose_file_callback_(NULL, 0, current_choose_file_user_data_);
- } else {
- // Construct a bunch of 8-bit strings for the callback.
- std::vector<std::string> file_strings;
- file_strings.resize(file_names.size());
- for (size_t i = 0; i < file_names.size(); i++)
- file_strings[i] = file_names[0].utf8();
-
- // Construct an array of pointers to each of the strings.
- std::vector<const char*> pointers_to_strings;
- pointers_to_strings.resize(file_strings.size());
- for (size_t i = 0; i < file_strings.size(); i++)
- pointers_to_strings[i] = file_strings[i].c_str();
-
- current_choose_file_callback_(
- &pointers_to_strings[0],
- static_cast<int>(pointers_to_strings.size()),
- current_choose_file_user_data_);
- }
-}
-
-bool WebPluginDelegatePepper::Initialize(
- const GURL& url,
- const std::vector<std::string>& arg_names,
- const std::vector<std::string>& arg_values,
- WebPlugin* plugin,
- bool load_manually) {
- plugin_ = plugin;
-
- instance_->set_web_plugin(plugin_);
- int argc = 0;
- scoped_array<char*> argn(new char*[arg_names.size()]);
- scoped_array<char*> argv(new char*[arg_names.size()]);
- for (size_t i = 0; i < arg_names.size(); ++i) {
- argn[argc] = const_cast<char*>(arg_names[i].c_str());
- argv[argc] = const_cast<char*>(arg_values[i].c_str());
- argc++;
- }
-
- bool start_result = instance_->Start(
- url, argn.get(), argv.get(), argc, load_manually);
- if (!start_result)
- return false;
-
- plugin_url_ = url.spec();
-
- return true;
-}
-
-void WebPluginDelegatePepper::DestroyInstance() {
- if (instance_ && (instance_->npp()->ndata != NULL)) {
- // Shutdown all streams before destroying so that
- // no streams are left "in progress". Need to do
- // this before calling set_web_plugin(NULL) because the
- // instance uses the helper to do the download.
- instance_->CloseStreams();
-
- window_.window = NULL;
- instance_->NPP_SetWindow(&window_);
-
- instance_->NPP_Destroy();
-
- instance_->set_web_plugin(NULL);
-
- instance_ = 0;
- }
-}
-
-void WebPluginDelegatePepper::UpdateGeometry(
- const gfx::Rect& window_rect,
- const gfx::Rect& clip_rect) {
- // Only resend to the instance if the geometry has changed.
- if (window_rect == window_rect_ && clip_rect == clip_rect_)
- return;
-
- clip_rect_ = clip_rect;
- cutout_rects_.clear();
-
- if (window_rect_ == window_rect)
- return;
- window_rect_ = window_rect;
-
- // TODO(brettw) figure out how to tell the plugin that the size changed and it
- // needs to repaint?
- SkBitmap new_committed;
- new_committed.setConfig(SkBitmap::kARGB_8888_Config,
- window_rect_.width(), window_rect_.height());
- new_committed.allocPixels();
- committed_bitmap_ = new_committed;
-
- if (!instance())
- return;
-
- ForwardSetWindow();
-}
-
-NPObject* WebPluginDelegatePepper::GetPluginScriptableObject() {
- return instance_->GetPluginScriptableObject();
-}
-
-void WebPluginDelegatePepper::DidFinishLoadWithReason(
- const GURL& url, NPReason reason, int notify_id) {
- instance()->DidFinishLoadWithReason(url, reason, notify_id);
-}
-
-int WebPluginDelegatePepper::GetProcessId() {
- // We are in process, so the plugin pid is this current process pid.
- return base::GetCurrentProcId();
-}
-
-void WebPluginDelegatePepper::SendJavaScriptStream(
- const GURL& url,
- const std::string& result,
- bool success,
- int notify_id) {
- instance()->SendJavaScriptStream(url, result, success, notify_id);
-}
-
-void WebPluginDelegatePepper::DidReceiveManualResponse(
- const GURL& url, const std::string& mime_type,
- const std::string& headers, uint32 expected_length, uint32 last_modified) {
- instance()->DidReceiveManualResponse(url, mime_type, headers,
- expected_length, last_modified);
-}
-
-void WebPluginDelegatePepper::DidReceiveManualData(const char* buffer,
- int length) {
- instance()->DidReceiveManualData(buffer, length);
-}
-
-void WebPluginDelegatePepper::DidFinishManualLoading() {
- instance()->DidFinishManualLoading();
-}
-
-void WebPluginDelegatePepper::DidManualLoadFail() {
- instance()->DidManualLoadFail();
-}
-
-FilePath WebPluginDelegatePepper::GetPluginPath() {
- return instance()->plugin_lib()->plugin_info().path;
-}
-
-void WebPluginDelegatePepper::RenderViewInitiatedPaint() {
- // Broadcast event to all 2D contexts.
- Graphics2DMap::iterator iter2d(&graphic2d_contexts_);
- while (!iter2d.IsAtEnd()) {
- iter2d.GetCurrentValue()->RenderViewInitiatedPaint();
- iter2d.Advance();
- }
-}
-
-void WebPluginDelegatePepper::RenderViewFlushedPaint() {
- // Broadcast event to all 2D contexts.
- Graphics2DMap::iterator iter2d(&graphic2d_contexts_);
- while (!iter2d.IsAtEnd()) {
- iter2d.GetCurrentValue()->RenderViewFlushedPaint();
- iter2d.Advance();
- }
-}
-
-WebPluginResourceClient* WebPluginDelegatePepper::CreateResourceClient(
- unsigned long resource_id, const GURL& url, int notify_id) {
- return instance()->CreateStream(resource_id, url, std::string(), notify_id);
-}
-
-WebPluginResourceClient* WebPluginDelegatePepper::CreateSeekableResourceClient(
- unsigned long resource_id, int range_request_id) {
- return instance()->GetRangeRequest(range_request_id);
-}
-
-bool WebPluginDelegatePepper::StartFind(const string16& search_text,
- bool case_sensitive,
- int identifier) {
- if (!GetFindExtensions())
- return false;
- find_identifier_ = identifier;
- GetFindExtensions()->startFind(
- instance()->npp(), UTF16ToUTF8(search_text).c_str(), case_sensitive);
- return true;
-}
-
-void WebPluginDelegatePepper::SelectFindResult(bool forward) {
- GetFindExtensions()->selectFindResult(instance()->npp(), forward);
-}
-
-void WebPluginDelegatePepper::StopFind() {
- find_identifier_ = -1;
- GetFindExtensions()->stopFind(instance()->npp());
-}
-
-void WebPluginDelegatePepper::NumberOfFindResultsChanged(int total,
- bool final_result) {
- DCHECK(find_identifier_ != -1);
-
- render_view_->reportFindInPageMatchCount(
- find_identifier_, total, final_result);
-}
-
-void WebPluginDelegatePepper::SelectedFindResultChanged(int index) {
- render_view_->reportFindInPageSelection(
- find_identifier_, index + 1, WebKit::WebRect());
-}
-
-bool WebPluginDelegatePepper::ChooseFile(const char* mime_types,
- int mode,
- NPChooseFileCallback callback,
- void* user_data) {
- if (!render_view_ || !callback)
- return false;
-
- if (current_choose_file_callback_)
- return false; // Reentrant call to browse, only one can be outstanding
- // per plugin.
-
- // TODO(brettw) do something with the mime types!
- current_choose_file_callback_ = callback;
- current_choose_file_user_data_ = user_data;
-
- ViewHostMsg_RunFileChooser_Params ipc_params;
- switch (mode) {
- case NPChooseFile_Open:
- ipc_params.mode = ViewHostMsg_RunFileChooser_Params::Open;
- break;
- case NPChooseFile_OpenMultiple:
- ipc_params.mode = ViewHostMsg_RunFileChooser_Params::OpenMultiple;
- break;
- case NPChooseFile_Save:
- ipc_params.mode = ViewHostMsg_RunFileChooser_Params::Save;
- break;
- default:
- return false;
- }
- return render_view_->ScheduleFileChooser(ipc_params, this);
-}
-
-NPWidgetExtensions* WebPluginDelegatePepper::GetWidgetExtensions() {
- return PepperWidget::GetWidgetExtensions();
-}
-
-#define COMPILE_ASSERT_MATCHING_ENUM(webkit_name, np_name) \
- COMPILE_ASSERT(int(WebCursorInfo::webkit_name) == int(np_name), \
- mismatching_enums)
-
-COMPILE_ASSERT_MATCHING_ENUM(TypePointer, NPCursorTypePointer);
-COMPILE_ASSERT_MATCHING_ENUM(TypeCross, NPCursorTypeCross);
-COMPILE_ASSERT_MATCHING_ENUM(TypeHand, NPCursorTypeHand);
-COMPILE_ASSERT_MATCHING_ENUM(TypeIBeam, NPCursorTypeIBeam);
-COMPILE_ASSERT_MATCHING_ENUM(TypeWait, NPCursorTypeWait);
-COMPILE_ASSERT_MATCHING_ENUM(TypeHelp, NPCursorTypeHelp);
-COMPILE_ASSERT_MATCHING_ENUM(TypeEastResize, NPCursorTypeEastResize);
-COMPILE_ASSERT_MATCHING_ENUM(TypeNorthResize, NPCursorTypeNorthResize);
-COMPILE_ASSERT_MATCHING_ENUM(TypeNorthEastResize, NPCursorTypeNorthEastResize);
-COMPILE_ASSERT_MATCHING_ENUM(TypeNorthWestResize, NPCursorTypeNorthWestResize);
-COMPILE_ASSERT_MATCHING_ENUM(TypeSouthResize, NPCursorTypeSouthResize);
-COMPILE_ASSERT_MATCHING_ENUM(TypeSouthEastResize, NPCursorTypeSouthEastResize);
-COMPILE_ASSERT_MATCHING_ENUM(TypeSouthWestResize, NPCursorTypeSouthWestResize);
-COMPILE_ASSERT_MATCHING_ENUM(TypeWestResize, NPCursorTypeWestResize);
-COMPILE_ASSERT_MATCHING_ENUM(TypeNorthSouthResize,
- NPCursorTypeNorthSouthResize);
-COMPILE_ASSERT_MATCHING_ENUM(TypeEastWestResize, NPCursorTypeEastWestResize);
-COMPILE_ASSERT_MATCHING_ENUM(TypeNorthEastSouthWestResize,
- NPCursorTypeNorthEastSouthWestResize);
-COMPILE_ASSERT_MATCHING_ENUM(TypeNorthWestSouthEastResize,
- NPCursorTypeNorthWestSouthEastResize);
-COMPILE_ASSERT_MATCHING_ENUM(TypeColumnResize, NPCursorTypeColumnResize);
-COMPILE_ASSERT_MATCHING_ENUM(TypeRowResize, NPCursorTypeRowResize);
-COMPILE_ASSERT_MATCHING_ENUM(TypeMiddlePanning, NPCursorTypeMiddlePanning);
-COMPILE_ASSERT_MATCHING_ENUM(TypeEastPanning, NPCursorTypeEastPanning);
-COMPILE_ASSERT_MATCHING_ENUM(TypeNorthPanning, NPCursorTypeNorthPanning);
-COMPILE_ASSERT_MATCHING_ENUM(TypeNorthEastPanning,
- NPCursorTypeNorthEastPanning);
-COMPILE_ASSERT_MATCHING_ENUM(TypeNorthWestPanning,
- NPCursorTypeNorthWestPanning);
-COMPILE_ASSERT_MATCHING_ENUM(TypeSouthPanning, NPCursorTypeSouthPanning);
-COMPILE_ASSERT_MATCHING_ENUM(TypeSouthEastPanning,
- NPCursorTypeSouthEastPanning);
-COMPILE_ASSERT_MATCHING_ENUM(TypeSouthWestPanning,
- NPCursorTypeSouthWestPanning);
-COMPILE_ASSERT_MATCHING_ENUM(TypeWestPanning, NPCursorTypeWestPanning);
-COMPILE_ASSERT_MATCHING_ENUM(TypeMove, NPCursorTypeMove);
-COMPILE_ASSERT_MATCHING_ENUM(TypeVerticalText, NPCursorTypeVerticalText);
-COMPILE_ASSERT_MATCHING_ENUM(TypeCell, NPCursorTypeCell);
-COMPILE_ASSERT_MATCHING_ENUM(TypeContextMenu, NPCursorTypeContextMenu);
-COMPILE_ASSERT_MATCHING_ENUM(TypeAlias, NPCursorTypeAlias);
-COMPILE_ASSERT_MATCHING_ENUM(TypeProgress, NPCursorTypeProgress);
-COMPILE_ASSERT_MATCHING_ENUM(TypeNoDrop, NPCursorTypeNoDrop);
-COMPILE_ASSERT_MATCHING_ENUM(TypeCopy, NPCursorTypeCopy);
-COMPILE_ASSERT_MATCHING_ENUM(TypeNone, NPCursorTypeNone);
-COMPILE_ASSERT_MATCHING_ENUM(TypeNotAllowed, NPCursorTypeNotAllowed);
-COMPILE_ASSERT_MATCHING_ENUM(TypeZoomIn, NPCursorTypeZoomIn);
-COMPILE_ASSERT_MATCHING_ENUM(TypeZoomOut, NPCursorTypeZoomOut);
-
-bool WebPluginDelegatePepper::SetCursor(NPCursorType type) {
- cursor_.reset(new WebCursorInfo(static_cast<WebCursorInfo::Type>(type)));
- return true;
-}
-
-NPError NPMatchFontWithFallback(NPP instance,
- const NPFontDescription* description,
- NPFontID* id) {
-#if defined(OS_LINUX)
- int fd = renderer_sandbox_support::MatchFontWithFallback(
- description->face, description->weight >= 700, description->italic,
- description->charset);
- if (fd == -1)
- return NPERR_GENERIC_ERROR;
- *id = fd;
- return NPERR_NO_ERROR;
-#else
- NOTIMPLEMENTED();
- return NPERR_GENERIC_ERROR;
-#endif
-}
-
-NPError GetFontTable(NPP instance,
- NPFontID id,
- uint32_t table,
- void* output,
- size_t* output_length) {
-#if defined(OS_LINUX)
- bool rv = renderer_sandbox_support::GetFontTable(
- id, table, static_cast<uint8_t*>(output), output_length);
- return rv ? NPERR_NO_ERROR : NPERR_GENERIC_ERROR;
-#else
- NOTIMPLEMENTED();
- return NPERR_GENERIC_ERROR;
-#endif
-}
-
-NPError NPDestroyFont(NPP instance, NPFontID id) {
-#if defined(OS_LINUX)
- close(id);
- return NPERR_NO_ERROR;
-#else
- NOTIMPLEMENTED();
- return NPERR_GENERIC_ERROR;
-#endif
-}
-
-NPFontExtensions g_font_extensions = {
- NPMatchFontWithFallback,
- GetFontTable,
- NPDestroyFont
-};
-
-NPFontExtensions* WebPluginDelegatePepper::GetFontExtensions() {
- return &g_font_extensions;
-}
-
-void WebPluginDelegatePepper::SetZoomFactor(float scale, bool text_only) {
- NPPExtensions* extensions = NULL;
- instance()->NPP_GetValue(NPPVPepperExtensions, &extensions);
- if (extensions && extensions->zoom)
- extensions->zoom(instance()->npp(), scale, text_only);
-}
-
-bool WebPluginDelegatePepper::HasSelection() const {
- return !GetSelectedText(false).empty();
-}
-
-string16 WebPluginDelegatePepper::GetSelectionAsText() const {
- return GetSelectedText(false);
-}
-
-string16 WebPluginDelegatePepper::GetSelectionAsMarkup() const {
- return GetSelectedText(true);
-}
-
-string16 WebPluginDelegatePepper::GetSelectedText(bool html) const {
- NPPExtensions* extensions = NULL;
- instance_->NPP_GetValue(NPPVPepperExtensions, &extensions);
- if (!extensions || !extensions->getSelection)
- return string16();
-
- void* text;
- NPSelectionType type = html ? NPSelectionTypeHTML : NPSelectionTypePlainText;
- NPP npp = instance_->npp();
- if (extensions->getSelection(npp, &type, &text) != NPERR_NO_ERROR)
- return string16();
-
- string16 rv = UTF8ToUTF16(static_cast<char*>(text));
- webkit::npapi::PluginHost::Singleton()->host_functions()->memfree(text);
- return rv;
-}
-
-NPError WebPluginDelegatePepper::Device2DQueryCapability(int32 capability,
- int32* value) {
- return NPERR_GENERIC_ERROR;
-}
-
-NPError WebPluginDelegatePepper::Device2DQueryConfig(
- const NPDeviceContext2DConfig* request,
- NPDeviceContext2DConfig* obtain) {
- return NPERR_GENERIC_ERROR;
-}
-
-NPError WebPluginDelegatePepper::Device2DInitializeContext(
- const NPDeviceContext2DConfig* config,
- NPDeviceContext2D* context) {
-
- if (!render_view_) {
- return NPERR_GENERIC_ERROR;
- }
-
- // This is a windowless plugin, so set it to have no handle. Defer this
- // until we know the plugin will use the 2D device.
- plugin_->SetWindow(gfx::kNullPluginWindow);
-
- scoped_ptr<Graphics2DDeviceContext> g2d(new Graphics2DDeviceContext(this));
- NPError status = g2d->Initialize(window_rect_, config, context);
- if (NPERR_NO_ERROR == status) {
- context->reserved = reinterpret_cast<void *>(
- graphic2d_contexts_.Add(g2d.release()));
- }
- return status;
-}
-
-NPError WebPluginDelegatePepper::Device2DSetStateContext(
- NPDeviceContext2D* context,
- int32 state,
- intptr_t value) {
- return NPERR_GENERIC_ERROR;
-}
-
-NPError WebPluginDelegatePepper::Device2DGetStateContext(
- NPDeviceContext2D* context,
- int32 state,
- intptr_t* value) {
- if (state == NPExtensionsReservedStateSharedMemory) {
- if (!context)
- return NPERR_INVALID_PARAM;
- Graphics2DDeviceContext* ctx = GetGraphicsContext(context);
- if (!ctx)
- return NPERR_INVALID_PARAM;
- *value = reinterpret_cast<intptr_t>(ctx->transport_dib());
- return NPERR_NO_ERROR;
- } else if (state == NPExtensionsReservedStateSharedMemoryChecksum) {
- if (!context)
- return NPERR_INVALID_PARAM;
- // Bytes per pixel.
- static const int kBytesPixel = 4;
- int32 row_count = context->dirty.bottom - context->dirty.top;
- int32 stride = context->dirty.right - context->dirty.left;
- size_t length = row_count * stride * kBytesPixel;
- MD5Digest md5_result; // 128-bit digest
- MD5Sum(context->region, length, &md5_result);
- std::string hex_md5 = MD5DigestToBase16(md5_result);
- // Return the least significant 8 characters (i.e. 4 bytes)
- // of the 32 character hexadecimal result as an int.
- int int_val;
- DCHECK_EQ(hex_md5.length(), 32u);
- base::HexStringToInt(hex_md5.begin() + 24, hex_md5.end(), &int_val);
- *value = int_val;
- return NPERR_NO_ERROR;
- }
- return NPERR_GENERIC_ERROR;
-}
-
-NPError WebPluginDelegatePepper::Device2DFlushContext(
- NPP id,
- NPDeviceContext2D* context,
- NPDeviceFlushContextCallbackPtr callback,
- void* user_data) {
- if (!context)
- return NPERR_INVALID_PARAM;
-
- Graphics2DDeviceContext* ctx = graphic2d_contexts_.Lookup(
- reinterpret_cast<intptr_t>(context->reserved));
- if (!ctx)
- return NPERR_INVALID_PARAM; // TODO(brettw) call callback.
-
- return ctx->Flush(&committed_bitmap_, context, callback, id, user_data);
-}
-
-NPError WebPluginDelegatePepper::Device2DDestroyContext(
- NPDeviceContext2D* context) {
-
- if (!context || !graphic2d_contexts_.Lookup(
- reinterpret_cast<intptr_t>(context->reserved))) {
- return NPERR_INVALID_PARAM;
- }
- graphic2d_contexts_.Remove(reinterpret_cast<intptr_t>(context->reserved));
- memset(context, 0, sizeof(NPDeviceContext2D));
- return NPERR_NO_ERROR;
-}
-
-Graphics2DDeviceContext* WebPluginDelegatePepper::GetGraphicsContext(
- NPDeviceContext2D* context) {
- return graphic2d_contexts_.Lookup(
- reinterpret_cast<intptr_t>(context->reserved));
-}
-
-NPError WebPluginDelegatePepper::Device3DQueryCapability(int32 capability,
- int32* value) {
- return NPERR_GENERIC_ERROR;
-}
-
-NPError WebPluginDelegatePepper::Device3DQueryConfig(
- const NPDeviceContext3DConfig* request,
- NPDeviceContext3DConfig* obtain) {
- return NPERR_GENERIC_ERROR;
-}
-
-NPError WebPluginDelegatePepper::Device3DInitializeContext(
- const NPDeviceContext3DConfig* config,
- NPDeviceContext3D* context) {
- return NPERR_GENERIC_ERROR;
-}
-
-NPError WebPluginDelegatePepper::Device3DSetStateContext(
- NPDeviceContext3D* context,
- int32 state,
- intptr_t value) {
- return NPERR_GENERIC_ERROR;
-}
-
-NPError WebPluginDelegatePepper::Device3DGetStateContext(
- NPDeviceContext3D* context,
- int32 state,
- intptr_t* value) {
- return NPERR_GENERIC_ERROR;
-}
-
-NPError WebPluginDelegatePepper::Device3DFlushContext(
- NPP id,
- NPDeviceContext3D* context,
- NPDeviceFlushContextCallbackPtr callback,
- void* user_data) {
- return NPERR_GENERIC_ERROR;
-}
-
-NPError WebPluginDelegatePepper::Device3DDestroyContext(
- NPDeviceContext3D* context) {
- return NPERR_GENERIC_ERROR;
-}
-
-NPError WebPluginDelegatePepper::Device3DCreateBuffer(
- NPDeviceContext3D* context,
- size_t size,
- int32* id) {
- return NPERR_GENERIC_ERROR;
-}
-
-NPError WebPluginDelegatePepper::Device3DDestroyBuffer(
- NPDeviceContext3D* context,
- int32 id) {
- return NPERR_GENERIC_ERROR;
-}
-
-NPError WebPluginDelegatePepper::Device3DMapBuffer(
- NPDeviceContext3D* context,
- int32 id,
- NPDeviceBuffer* np_buffer) {
- return NPERR_GENERIC_ERROR;
-}
-
-NPError WebPluginDelegatePepper::Device3DGetNumConfigs(int32* num_configs) {
- return NPERR_GENERIC_ERROR;
-}
-
-NPError WebPluginDelegatePepper::Device3DGetConfigAttribs(
- int32 config,
- int32* attrib_list) {
- return NPERR_GENERIC_ERROR;
-}
-
-NPError WebPluginDelegatePepper::Device3DCreateContext(
- int32 config,
- const int32* attrib_list,
- NPDeviceContext3D** context) {
- return NPERR_GENERIC_ERROR;
-}
-
-NPError WebPluginDelegatePepper::Device3DRegisterCallback(
- NPP id,
- NPDeviceContext3D* context,
- int32 callback_type,
- NPDeviceGenericCallbackPtr callback,
- void* callback_data) {
- return NPERR_GENERIC_ERROR;
-}
-
-NPError WebPluginDelegatePepper::Device3DSynchronizeContext(
- NPP id,
- NPDeviceContext3D* context,
- NPDeviceSynchronizationMode mode,
- const int32* input_attrib_list,
- int32* output_attrib_list,
- NPDeviceSynchronizeContextCallbackPtr callback,
- void* callback_data) {
- return NPERR_GENERIC_ERROR;
-}
-
-NPError WebPluginDelegatePepper::DeviceAudioQueryCapability(int32 capability,
- int32* value) {
- // TODO(neb,cpu) implement QueryCapability
- return NPERR_GENERIC_ERROR;
-}
-
-NPError WebPluginDelegatePepper::DeviceAudioQueryConfig(
- const NPDeviceContextAudioConfig* request,
- NPDeviceContextAudioConfig* obtain) {
- // TODO(neb,cpu) implement QueryConfig
- return NPERR_GENERIC_ERROR;
-}
-
-NPError WebPluginDelegatePepper::DeviceAudioInitializeContext(
- const NPDeviceContextAudioConfig* config,
- NPDeviceContextAudio* context) {
-
- if (!render_view_) {
- return NPERR_GENERIC_ERROR;
- }
-
- scoped_ptr<AudioDeviceContext> audio(new AudioDeviceContext());
- NPError status = audio->Initialize(render_view_->audio_message_filter(),
- config, context);
- if (NPERR_NO_ERROR == status) {
- context->reserved =
- reinterpret_cast<void *>(audio_contexts_.Add(audio.release()));
- }
- return status;
-}
-
-NPError WebPluginDelegatePepper::DeviceAudioSetStateContext(
- NPDeviceContextAudio* context,
- int32 state,
- intptr_t value) {
- // TODO(neb,cpu) implement SetStateContext
- return NPERR_GENERIC_ERROR;
-}
-
-NPError WebPluginDelegatePepper::DeviceAudioGetStateContext(
- NPDeviceContextAudio* context,
- int32 state,
- intptr_t* value) {
- if (state == NPExtensionsReservedStateSharedMemory) {
- if (!context)
- return NPERR_INVALID_PARAM;
- AudioDeviceContext* ctx = audio_contexts_.Lookup(
- reinterpret_cast<intptr_t>(context->reserved));
- if (!ctx)
- return NPERR_INVALID_PARAM;
- *value = reinterpret_cast<intptr_t>(ctx->shared_memory());
- return NPERR_NO_ERROR;
- } else if (state == NPExtensionsReservedStateSharedMemorySize) {
- if (!context)
- return NPERR_INVALID_PARAM;
- AudioDeviceContext* ctx = audio_contexts_.Lookup(
- reinterpret_cast<intptr_t>(context->reserved));
- if (!ctx)
- return NPERR_INVALID_PARAM;
- *value = static_cast<intptr_t>(ctx->shared_memory_size());
- return NPERR_NO_ERROR;
- } else if (state == NPExtensionsReservedStateSyncChannel) {
- if (!context)
- return NPERR_INVALID_PARAM;
- AudioDeviceContext* ctx = audio_contexts_.Lookup(
- reinterpret_cast<intptr_t>(context->reserved));
- if (!ctx)
- return NPERR_INVALID_PARAM;
- *value = reinterpret_cast<intptr_t>(ctx->socket());
- return NPERR_NO_ERROR;
- }
- return NPERR_GENERIC_ERROR;
-}
-
-NPError WebPluginDelegatePepper::DeviceAudioFlushContext(
- NPP id,
- NPDeviceContextAudio* context,
- NPDeviceFlushContextCallbackPtr callback,
- void* user_data) {
- // TODO(neb,cpu) implement FlushContext
- return NPERR_GENERIC_ERROR;
-}
-
-NPError WebPluginDelegatePepper::DeviceAudioDestroyContext(
- NPDeviceContextAudio* context) {
- if (!context || !audio_contexts_.Lookup(
- reinterpret_cast<intptr_t>(context->reserved))) {
- return NPERR_INVALID_PARAM;
- }
- audio_contexts_.Remove(reinterpret_cast<intptr_t>(context->reserved));
- memset(context, 0, sizeof(NPDeviceContextAudio));
- return NPERR_NO_ERROR;
-}
-
-bool WebPluginDelegatePepper::PrintSupportsPrintExtension() {
- return GetPrintExtensions() != NULL;
-}
-
-int WebPluginDelegatePepper::PrintBegin(const gfx::Rect& printable_area,
- int printer_dpi) {
- int32 num_pages = 0;
- NPPPrintExtensions* print_extensions = GetPrintExtensions();
- if (print_extensions) {
- NPRect np_printable_area = {0};
- np_printable_area.left = printable_area.x();
- np_printable_area.top = printable_area.y();
- np_printable_area.right = np_printable_area.left + printable_area.width();
- np_printable_area.bottom = np_printable_area.top + printable_area.height();
- if (NPERR_NO_ERROR == print_extensions->printBegin(instance()->npp(),
- &np_printable_area,
- printer_dpi,
- &num_pages)) {
- current_printable_area_ = printable_area;
- current_printer_dpi_ = printer_dpi;
- }
- }
-#if defined (OS_LINUX)
- num_pages_ = num_pages;
- pdf_output_done_ = false;
-#endif // (OS_LINUX)
- return num_pages;
-}
-
-bool WebPluginDelegatePepper::VectorPrintPage(int page_number,
- WebKit::WebCanvas* canvas) {
- NPPPrintExtensions* print_extensions = GetPrintExtensions();
- if (!print_extensions)
- return false;
-#if defined(OS_WIN)
- // For Windows, we need the PDF DLL to render the output PDF to a DC.
- FilePath pdf_path;
- PathService::Get(chrome::FILE_PDF_PLUGIN, &pdf_path);
- HMODULE pdf_module = GetModuleHandle(pdf_path.value().c_str());
- if (!pdf_module)
- return false;
- RenderPDFPageToDCProc render_proc =
- reinterpret_cast<RenderPDFPageToDCProc>(
- GetProcAddress(pdf_module, "RenderPDFPageToDC"));
- if (!render_proc)
- return false;
-#endif // defined(OS_WIN)
-
- unsigned char* pdf_output = NULL;
- int32 output_size = 0;
- NPPrintPageNumberRange page_range;
-#if defined(OS_LINUX)
- // On Linux we will try and output all pages as PDF in the first call to
- // PrintPage. This is a temporary hack.
- // TODO(sanjeevr): Remove this hack and fix this by changing the print
- // interfaces for WebFrame and WebPlugin.
- if (page_number != 0)
- return pdf_output_done_;
- page_range.firstPageNumber = 0;
- page_range.lastPageNumber = num_pages_ - 1;
-#else // defined(OS_LINUX)
- page_range.firstPageNumber = page_range.lastPageNumber = page_number;
-#endif // defined(OS_LINUX)
- NPError err = print_extensions->printPagesAsPDF(instance()->npp(),
- &page_range, 1,
- &pdf_output, &output_size);
- if (err != NPERR_NO_ERROR)
- return false;
-
- bool ret = false;
-#if defined(OS_LINUX)
- // On Linux we need to get the backing PdfPsMetafile and write the bits
- // directly.
- cairo_t* context = canvas->beginPlatformPaint();
- printing::NativeMetafile* metafile =
- printing::PdfPsMetafile::FromCairoContext(context);
- DCHECK(metafile);
- if (metafile) {
- ret = metafile->SetRawData(pdf_output, output_size);
- if (ret)
- pdf_output_done_ = true;
- }
- canvas->endPlatformPaint();
-#elif defined(OS_MACOSX)
- scoped_ptr<printing::NativeMetafile> metafile(
- printing::NativeMetafileFactory::CreateMetafile());
- // Create a PDF metafile and render from there into the passed in context.
- if (metafile->Init(pdf_output, output_size)) {
- // Flip the transform.
- CGContextSaveGState(canvas);
- CGContextTranslateCTM(canvas, 0, current_printable_area_.height());
- CGContextScaleCTM(canvas, 1.0, -1.0);
- ret = metafile->RenderPage(1, canvas, current_printable_area_.ToCGRect(),
- true, false, true, true);
- CGContextRestoreGState(canvas);
- }
-#elif defined(OS_WIN)
- // On Windows, we now need to render the PDF to the DC that backs the
- // supplied canvas.
- skia::VectorPlatformDevice& device =
- static_cast<skia::VectorPlatformDevice&>(
- canvas->getTopPlatformDevice());
- HDC dc = device.getBitmapDC();
- gfx::Size size_in_pixels;
- size_in_pixels.set_width(
- printing::ConvertUnit(current_printable_area_.width(),
- static_cast<int>(kPointsPerInch),
- current_printer_dpi_));
- size_in_pixels.set_height(
- printing::ConvertUnit(current_printable_area_.height(),
- static_cast<int>(kPointsPerInch),
- current_printer_dpi_));
- // We need to render using the actual printer DPI (rendering to a smaller
- // set of pixels leads to a blurry output). However, we need to counter the
- // scaling up that will happen in the browser.
- XFORM xform = {0};
- xform.eM11 = xform.eM22 = kPointsPerInch / current_printer_dpi_;
- ModifyWorldTransform(dc, &xform, MWT_LEFTMULTIPLY);
-
- ret = render_proc(pdf_output, output_size, 0, dc, current_printer_dpi_,
- current_printer_dpi_, 0, 0, size_in_pixels.width(),
- size_in_pixels.height(), true, false, true, true);
-#endif // defined(OS_WIN)
-
- webkit::npapi::PluginHost::Singleton()->host_functions()->memfree(
- pdf_output);
- return ret;
-}
-
-bool WebPluginDelegatePepper::PrintPage(int page_number,
- WebKit::WebCanvas* canvas) {
- NPPPrintExtensions* print_extensions = GetPrintExtensions();
- if (!print_extensions)
- return false;
-
- // First try and use vector print.
- if (VectorPrintPage(page_number, canvas))
- return true;
-
- DCHECK(!current_printable_area_.IsEmpty());
-
- // Calculate the width and height needed for the raster image.
- NPRect np_printable_area = {0};
- np_printable_area.left = current_printable_area_.x();
- np_printable_area.top = current_printable_area_.y();
- np_printable_area.right =
- current_printable_area_.x() + current_printable_area_.width();
- np_printable_area.bottom =
- current_printable_area_.y() + current_printable_area_.height();
- gfx::Size size_in_pixels;
- if (!CalculatePrintedPageDimensions(page_number, print_extensions,
- &size_in_pixels)) {
- return false;
- }
-
- // Now print the page onto a 2d device context.
- scoped_ptr<Graphics2DDeviceContext> g2d(new Graphics2DDeviceContext(this));
- NPDeviceContext2DConfig config;
- NPDeviceContext2D context;
- gfx::Rect surface_rect(size_in_pixels);
- NPError err = g2d->Initialize(surface_rect, &config, &context);
- if (err != NPERR_NO_ERROR) {
- NOTREACHED();
- return false;
- }
- err = print_extensions->printPageRaster(instance()->npp(), page_number,
- &context);
- if (err != NPERR_NO_ERROR)
- return false;
-
- SkBitmap committed;
- committed.setConfig(SkBitmap::kARGB_8888_Config, size_in_pixels.width(),
- size_in_pixels.height());
- committed.allocPixels();
- err = g2d->Flush(&committed, &context, NULL, instance()->npp(), NULL);
- if (err != NPERR_NO_ERROR) {
- NOTREACHED();
- return false;
- }
- // Draw the printed image into the supplied canvas.
- SkIRect src_rect;
- src_rect.set(0, 0, size_in_pixels.width(), size_in_pixels.height());
- SkRect dest_rect;
- dest_rect.set(SkIntToScalar(current_printable_area_.x()),
- SkIntToScalar(current_printable_area_.y()),
- SkIntToScalar(current_printable_area_.x() +
- current_printable_area_.width()),
- SkIntToScalar(current_printable_area_.y() +
- current_printable_area_.height()));
- bool draw_to_canvas = true;
-#if defined(OS_WIN)
- // Since this is a raster output, the size of the bitmap can be
- // huge (especially at high printer DPIs). On Windows, this can
- // result in a HUGE EMF (on Mac and Linux the output goes to PDF
- // which appears to Flate compress the bitmap). So, if this bitmap
- // is larger than 20 MB, we save the bitmap as a JPEG into the EMF
- // DC. Note: We chose JPEG over PNG because JPEG compression seems
- // way faster (about 4 times faster).
- static const int kCompressionThreshold = 20 * 1024 * 1024;
- if (committed.getSize() > kCompressionThreshold) {
- DrawJPEGToPlatformDC(committed, current_printable_area_, canvas);
- draw_to_canvas = false;
- }
-#endif // defined(OS_WIN)
-#if defined(OS_MACOSX)
- draw_to_canvas = false;
- DrawSkBitmapToCanvas(committed, canvas, current_printable_area_,
- current_printable_area_.height());
- // See comments in the header file.
- last_printed_page_ = committed;
-#else // defined(OS_MACOSX)
- if (draw_to_canvas)
- canvas->drawBitmapRect(committed, &src_rect, dest_rect);
-#endif // defined(OS_MACOSX)
- return true;
-}
-
-void WebPluginDelegatePepper::PrintEnd() {
- NPPPrintExtensions* print_extensions = GetPrintExtensions();
- if (print_extensions)
- print_extensions->printEnd(instance()->npp());
- current_printable_area_ = gfx::Rect();
- current_printer_dpi_ = -1;
-#if defined(OS_MACOSX)
- last_printed_page_ = SkBitmap();
-#elif defined(OS_LINUX)
- num_pages_ = 0;
- pdf_output_done_ = false;
-#endif // defined(OS_LINUX)
-}
-
-WebPluginDelegatePepper::WebPluginDelegatePepper(
- const base::WeakPtr<RenderView>& render_view,
- webkit::npapi::PluginInstance *instance)
- : render_view_(render_view),
- plugin_(NULL),
- instance_(instance),
- current_printer_dpi_(-1),
-#if defined (OS_LINUX)
- num_pages_(0),
- pdf_output_done_(false),
-#endif // (OS_LINUX)
- find_identifier_(-1),
- current_choose_file_callback_(NULL),
- current_choose_file_user_data_(NULL) {
- // For now we keep a window struct, although it isn't used.
- memset(&window_, 0, sizeof(window_));
- // All Pepper plugins are windowless and transparent.
- // TODO(sehr): disable resetting these NPPVs by plugins.
- instance->set_windowless(true);
- instance->set_transparent(true);
-}
-
-WebPluginDelegatePepper::~WebPluginDelegatePepper() {
- DestroyInstance();
-
- if (render_view_)
- render_view_->OnPepperPluginDestroy(this);
-}
-
-void WebPluginDelegatePepper::ForwardSetWindow() {
- window_.clipRect.top = clip_rect_.y();
- window_.clipRect.left = clip_rect_.x();
- window_.clipRect.bottom = clip_rect_.y() + clip_rect_.height();
- window_.clipRect.right = clip_rect_.x() + clip_rect_.width();
- window_.height = window_rect_.height();
- window_.width = window_rect_.width();
- window_.x = window_rect_.x();
- window_.y = window_rect_.y();
- window_.type = NPWindowTypeDrawable;
- instance()->NPP_SetWindow(&window_);
-}
-
-void WebPluginDelegatePepper::PluginDestroyed() {
- delete this;
-}
-
-void WebPluginDelegatePepper::Paint(WebKit::WebCanvas* canvas,
- const gfx::Rect& rect) {
- // Blit from background_context to context.
- if (!committed_bitmap_.isNull()) {
-#if defined(OS_MACOSX)
- DrawSkBitmapToCanvas(committed_bitmap_, canvas, window_rect_,
- static_cast<int>(CGBitmapContextGetHeight(canvas)));
-#else
- canvas->drawBitmap(committed_bitmap_,
- SkIntToScalar(window_rect_.origin().x()),
- SkIntToScalar(window_rect_.origin().y()));
-#endif
- }
-}
-
-void WebPluginDelegatePepper::Print(gfx::NativeDrawingContext context) {
- NOTIMPLEMENTED();
-}
-
-void WebPluginDelegatePepper::InstallMissingPlugin() {
- NOTIMPLEMENTED();
-}
-
-void WebPluginDelegatePepper::SetFocus(bool focused) {
- if (!focused)
- return;
-
- NPPepperEvent npevent;
-
- npevent.type = NPEventType_Focus;
- npevent.size = sizeof(npevent);
- // TODO(sehr): what timestamp should this have?
- npevent.timeStampSeconds = 0.0;
- // Currently this API only supports gaining focus.
- npevent.u.focus.value = 1;
- instance()->NPP_HandleEvent(&npevent);
-}
-
-// Anonymous namespace for functions converting WebInputEvents to NPAPI types.
-namespace {
-NPEventTypes ConvertEventTypes(WebInputEvent::Type wetype) {
- switch (wetype) {
- case WebInputEvent::MouseDown:
- return NPEventType_MouseDown;
- case WebInputEvent::MouseUp:
- return NPEventType_MouseUp;
- case WebInputEvent::MouseMove:
- return NPEventType_MouseMove;
- case WebInputEvent::MouseEnter:
- return NPEventType_MouseEnter;
- case WebInputEvent::MouseLeave:
- return NPEventType_MouseLeave;
- case WebInputEvent::MouseWheel:
- return NPEventType_MouseWheel;
- case WebInputEvent::RawKeyDown:
- return NPEventType_RawKeyDown;
- case WebInputEvent::KeyDown:
- return NPEventType_KeyDown;
- case WebInputEvent::KeyUp:
- return NPEventType_KeyUp;
- case WebInputEvent::Char:
- return NPEventType_Char;
- case WebInputEvent::Undefined:
- default:
- return NPEventType_Undefined;
- }
-}
-
-void BuildKeyEvent(const WebInputEvent* event, NPPepperEvent* npevent) {
- const WebKeyboardEvent* key_event =
- reinterpret_cast<const WebKeyboardEvent*>(event);
- npevent->u.key.modifier = key_event->modifiers;
- npevent->u.key.normalizedKeyCode = key_event->windowsKeyCode;
-}
-
-void BuildCharEvent(const WebInputEvent* event, NPPepperEvent* npevent) {
- const WebKeyboardEvent* key_event =
- reinterpret_cast<const WebKeyboardEvent*>(event);
- npevent->u.character.modifier = key_event->modifiers;
- // For consistency, check that the sizes of the texts agree.
- DCHECK(sizeof(npevent->u.character.text) == sizeof(key_event->text));
- DCHECK(sizeof(npevent->u.character.unmodifiedText) ==
- sizeof(key_event->unmodifiedText));
- for (size_t i = 0; i < WebKeyboardEvent::textLengthCap; ++i) {
- npevent->u.character.text[i] = key_event->text[i];
- npevent->u.character.unmodifiedText[i] = key_event->unmodifiedText[i];
- }
-}
-
-void BuildMouseEvent(const WebInputEvent* event, NPPepperEvent* npevent) {
- const WebMouseEvent* mouse_event =
- reinterpret_cast<const WebMouseEvent*>(event);
- npevent->u.mouse.modifier = mouse_event->modifiers;
- npevent->u.mouse.button = mouse_event->button;
- npevent->u.mouse.x = mouse_event->x;
- npevent->u.mouse.y = mouse_event->y;
- npevent->u.mouse.clickCount = mouse_event->clickCount;
-}
-
-void BuildMouseWheelEvent(const WebInputEvent* event, NPPepperEvent* npevent) {
- const WebMouseWheelEvent* mouse_wheel_event =
- reinterpret_cast<const WebMouseWheelEvent*>(event);
- npevent->u.wheel.modifier = mouse_wheel_event->modifiers;
- npevent->u.wheel.deltaX = mouse_wheel_event->deltaX;
- npevent->u.wheel.deltaY = mouse_wheel_event->deltaY;
- npevent->u.wheel.wheelTicksX = mouse_wheel_event->wheelTicksX;
- npevent->u.wheel.wheelTicksY = mouse_wheel_event->wheelTicksY;
- npevent->u.wheel.scrollByPage = mouse_wheel_event->scrollByPage;
-}
-} // namespace
-
-bool WebPluginDelegatePepper::HandleInputEvent(const WebInputEvent& event,
- WebCursorInfo* cursor_info) {
- NPPepperEvent npevent;
-
- npevent.type = ConvertEventTypes(event.type);
- npevent.size = sizeof(npevent);
- npevent.timeStampSeconds = event.timeStampSeconds;
- switch (npevent.type) {
- case NPEventType_Undefined:
- return false;
- case NPEventType_MouseDown:
- case NPEventType_MouseUp:
- case NPEventType_MouseMove:
- case NPEventType_MouseEnter:
- case NPEventType_MouseLeave:
- BuildMouseEvent(&event, &npevent);
- break;
- case NPEventType_MouseWheel:
- BuildMouseWheelEvent(&event, &npevent);
- break;
- case NPEventType_RawKeyDown:
- case NPEventType_KeyDown:
- case NPEventType_KeyUp:
- BuildKeyEvent(&event, &npevent);
- break;
- case NPEventType_Char:
- BuildCharEvent(&event, &npevent);
- break;
- case NPEventType_Minimize:
- case NPEventType_Focus:
- case NPEventType_Device:
- // NOTIMPLEMENTED();
- break;
- }
- bool rv = instance()->NPP_HandleEvent(&npevent) != 0;
- if (cursor_.get())
- *cursor_info = *cursor_;
- return rv;
-}
-
-bool WebPluginDelegatePepper::CalculatePrintedPageDimensions(
- int page_number,
- NPPPrintExtensions* print_extensions,
- gfx::Size* page_dimensions) {
- int32 width_in_pixels = 0;
- int32 height_in_pixels = 0;
- NPError err = print_extensions->getRasterDimensions(
- instance()->npp(), page_number, &width_in_pixels, &height_in_pixels);
- if (err != NPERR_NO_ERROR)
- return false;
-
- DCHECK(width_in_pixels && height_in_pixels);
- page_dimensions->SetSize(width_in_pixels, height_in_pixels);
- return true;
-}
-
-NPPPrintExtensions* WebPluginDelegatePepper::GetPrintExtensions() {
- NPPPrintExtensions* ret = NULL;
- NPPExtensions* extensions = NULL;
- instance()->NPP_GetValue(NPPVPepperExtensions, &extensions);
- if (extensions && extensions->getPrintExtensions)
- ret = extensions->getPrintExtensions(instance()->npp());
- return ret;
-}
-
-NPPFindExtensions* WebPluginDelegatePepper::GetFindExtensions() {
- NPPFindExtensions* ret = NULL;
- NPPExtensions* extensions = NULL;
- instance()->NPP_GetValue(NPPVPepperExtensions, &extensions);
- if (extensions && extensions->getFindExtensions)
- ret = extensions->getFindExtensions(instance()->npp());
- return ret;
-}
-
-#if defined(OS_WIN)
-bool WebPluginDelegatePepper::DrawJPEGToPlatformDC(
- const SkBitmap& bitmap,
- const gfx::Rect& printable_area,
- WebKit::WebCanvas* canvas) {
- skia::VectorPlatformDevice& device =
- static_cast<skia::VectorPlatformDevice&>(
- canvas->getTopPlatformDevice());
- HDC dc = device.getBitmapDC();
- // TODO(sanjeevr): This is a temporary hack. If we output a JPEG
- // to the EMF, the EnumEnhMetaFile call fails in the browser
- // process. The failure also happens if we output nothing here.
- // We need to investigate the reason for this failure and fix it.
- // In the meantime this temporary hack of drawing an empty
- // rectangle in the DC gets us by.
- Rectangle(dc, 0, 0, 0, 0);
-
- // Ideally we should add JPEG compression to the VectorPlatformDevice class
- // However, Skia currently has no JPEG compression code and we cannot
- // depend on gfx/jpeg_codec.h in Skia. So we do the compression here.
- SkAutoLockPixels lock(bitmap);
- DCHECK(bitmap.getConfig() == SkBitmap::kARGB_8888_Config);
- const uint32_t* pixels =
- static_cast<const uint32_t*>(bitmap.getPixels());
- std::vector<unsigned char> compressed_image;
- base::TimeTicks start_time = base::TimeTicks::Now();
- bool encoded = gfx::JPEGCodec::Encode(
- reinterpret_cast<const unsigned char*>(pixels),
- gfx::JPEGCodec::FORMAT_BGRA, bitmap.width(), bitmap.height(),
- static_cast<int>(bitmap.rowBytes()), 100, &compressed_image);
- UMA_HISTOGRAM_TIMES("PepperPluginPrint.RasterBitmapCompressTime",
- base::TimeTicks::Now() - start_time);
- if (!encoded) {
- NOTREACHED();
- return false;
- }
- BITMAPINFOHEADER bmi = {0};
- gfx::CreateBitmapHeader(bitmap.width(), bitmap.height(), &bmi);
- bmi.biCompression = BI_JPEG;
- bmi.biSizeImage = compressed_image.size();
- bmi.biHeight = -bmi.biHeight;
- StretchDIBits(dc, printable_area.x(), printable_area.y(),
- printable_area.width(), printable_area.height(),
- 0, 0, bitmap.width(), bitmap.height(),
- &compressed_image.front(),
- reinterpret_cast<const BITMAPINFO*>(&bmi),
- DIB_RGB_COLORS, SRCCOPY);
- return true;
-}
-#endif // OS_WIN
-
-#if defined(OS_MACOSX)
-void WebPluginDelegatePepper::DrawSkBitmapToCanvas(
- const SkBitmap& bitmap, WebKit::WebCanvas* canvas,
- const gfx::Rect& dest_rect,
- int canvas_height) {
- SkAutoLockPixels lock(bitmap);
- DCHECK(bitmap.getConfig() == SkBitmap::kARGB_8888_Config);
- base::mac::ScopedCFTypeRef<CGDataProviderRef> data_provider(
- CGDataProviderCreateWithData(
- NULL, bitmap.getAddr32(0, 0),
- bitmap.rowBytes() * bitmap.height(), NULL));
- base::mac::ScopedCFTypeRef<CGImageRef> image(
- CGImageCreate(
- bitmap.width(), bitmap.height(),
- 8, 32, bitmap.rowBytes(),
- base::mac::GetSystemColorSpace(),
- kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host,
- data_provider, NULL, false, kCGRenderingIntentDefault));
-
- // Flip the transform
- CGContextSaveGState(canvas);
- CGContextTranslateCTM(canvas, 0, canvas_height);
- CGContextScaleCTM(canvas, 1.0, -1.0);
-
- CGRect bounds;
- bounds.origin.x = dest_rect.x();
- bounds.origin.y = canvas_height - dest_rect.y() - dest_rect.height();
- bounds.size.width = dest_rect.width();
- bounds.size.height = dest_rect.height();
-
- CGContextDrawImage(canvas, bounds, image);
- CGContextRestoreGState(canvas);
-}
-#endif // defined(OS_MACOSX)
diff --git a/chrome/renderer/webplugin_delegate_pepper.h b/chrome/renderer/webplugin_delegate_pepper.h
deleted file mode 100644
index 9dbeb1a..0000000
--- a/chrome/renderer/webplugin_delegate_pepper.h
+++ /dev/null
@@ -1,310 +0,0 @@
-// Copyright (c) 2010 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_WEBPLUGIN_DELEGATE_PEPPER_H_
-#define CHROME_RENDERER_WEBPLUGIN_DELEGATE_PEPPER_H_
-#pragma once
-
-#include "build/build_config.h"
-
-#include <string>
-#include <vector>
-
-#include "base/id_map.h"
-#include "base/ref_counted.h"
-#include "base/weak_ptr.h"
-#include "base/task.h"
-#include "chrome/renderer/pepper_devices.h"
-#include "third_party/npapi/bindings/npapi.h"
-#include "third_party/skia/include/core/SkBitmap.h"
-#include "third_party/WebKit/Source/WebKit/chromium/public/WebFileChooserCompletion.h"
-#include "ui/gfx/native_widget_types.h"
-#include "ui/gfx/rect.h"
-#include "webkit/plugins/npapi/webplugin_delegate.h"
-
-class FilePath;
-class RenderView;
-class WebCursor;
-class WebPluginDelegateProxy;
-
-namespace webkit {
-namespace npapi {
-class PluginInstance;
-}
-}
-
-// An implementation of WebPluginDelegate for Pepper in-process plugins.
-class WebPluginDelegatePepper : public webkit::npapi::WebPluginDelegate,
- public WebKit::WebFileChooserCompletion {
- public:
- static WebPluginDelegatePepper* Create(
- const FilePath& filename,
- const std::string& mime_type,
- const base::WeakPtr<RenderView>& render_view);
-
- webkit::npapi::PluginInstance* instance() { return instance_.get(); }
-
- // WebKit::WebFileChooserCompletion implementation.
- virtual void didChooseFile(
- const WebKit::WebVector<WebKit::WebString>& file_names);
-
- // WebPluginDelegate implementation
- virtual bool Initialize(const GURL& url,
- const std::vector<std::string>& arg_names,
- const std::vector<std::string>& arg_values,
- webkit::npapi::WebPlugin* plugin,
- bool load_manually);
- virtual void PluginDestroyed();
- virtual void UpdateGeometry(const gfx::Rect& window_rect,
- const gfx::Rect& clip_rect);
- virtual void Paint(WebKit::WebCanvas* canvas, const gfx::Rect& rect);
- virtual void Print(gfx::NativeDrawingContext context);
- virtual void SetFocus(bool focused);
- virtual bool HandleInputEvent(const WebKit::WebInputEvent& event,
- WebKit::WebCursorInfo* cursor);
- virtual NPObject* GetPluginScriptableObject();
- virtual void DidFinishLoadWithReason(const GURL& url, NPReason reason,
- int notify_id);
- virtual int GetProcessId();
- virtual void SendJavaScriptStream(const GURL& url,
- const std::string& result,
- bool success,
- int notify_id);
- virtual void DidReceiveManualResponse(const GURL& url,
- const std::string& mime_type,
- const std::string& headers,
- uint32 expected_length,
- uint32 last_modified);
- virtual void DidReceiveManualData(const char* buffer, int length);
- virtual void DidFinishManualLoading();
- virtual void DidManualLoadFail();
- virtual void InstallMissingPlugin();
- virtual webkit::npapi::WebPluginResourceClient* CreateResourceClient(
- unsigned long resource_id, const GURL& url, int notify_id);
- virtual webkit::npapi::WebPluginResourceClient* CreateSeekableResourceClient(
- unsigned long resource_id, int range_request_id);
- virtual bool StartFind(const string16& search_text,
- bool case_sensitive,
- int identifier);
- virtual void SelectFindResult(bool forward);
- virtual void StopFind();
- virtual void NumberOfFindResultsChanged(int total, bool final_result);
- virtual void SelectedFindResultChanged(int index);
- virtual bool ChooseFile(const char* mime_types,
- int mode,
- NPChooseFileCallback callback,
- void* user_data);
- virtual NPWidgetExtensions* GetWidgetExtensions();
- virtual bool SetCursor(NPCursorType type);
- virtual NPFontExtensions* GetFontExtensions();
- virtual void SetZoomFactor(float scale, bool text_only);
- virtual bool HasSelection() const;
- virtual string16 GetSelectionAsText() const;
- virtual string16 GetSelectionAsMarkup() const;
-
- // WebPlugin2DDeviceDelegate implementation.
- virtual NPError Device2DQueryCapability(int32 capability, int32* value);
- virtual NPError Device2DQueryConfig(const NPDeviceContext2DConfig* request,
- NPDeviceContext2DConfig* obtain);
- virtual NPError Device2DInitializeContext(
- const NPDeviceContext2DConfig* config,
- NPDeviceContext2D* context);
- virtual NPError Device2DSetStateContext(NPDeviceContext2D* context,
- int32 state,
- intptr_t value);
- virtual NPError Device2DGetStateContext(NPDeviceContext2D* context,
- int32 state,
- intptr_t* value);
- virtual NPError Device2DFlushContext(NPP id,
- NPDeviceContext2D* context,
- NPDeviceFlushContextCallbackPtr callback,
- void* user_data);
- virtual NPError Device2DDestroyContext(NPDeviceContext2D* context);
-
- // WebPlugin3DDeviceDelegate implementation.
- virtual NPError Device3DQueryCapability(int32 capability, int32* value);
- virtual NPError Device3DQueryConfig(const NPDeviceContext3DConfig* request,
- NPDeviceContext3DConfig* obtain);
- virtual NPError Device3DInitializeContext(
- const NPDeviceContext3DConfig* config,
- NPDeviceContext3D* context);
- virtual NPError Device3DSetStateContext(NPDeviceContext3D* context,
- int32 state,
- intptr_t value);
- virtual NPError Device3DGetStateContext(NPDeviceContext3D* context,
- int32 state,
- intptr_t* value);
- virtual NPError Device3DFlushContext(NPP id,
- NPDeviceContext3D* context,
- NPDeviceFlushContextCallbackPtr callback,
- void* user_data);
- virtual NPError Device3DDestroyContext(NPDeviceContext3D* context);
- virtual NPError Device3DCreateBuffer(NPDeviceContext3D* context,
- size_t size,
- int32* id);
- virtual NPError Device3DDestroyBuffer(NPDeviceContext3D* context,
- int32 id);
- virtual NPError Device3DMapBuffer(NPDeviceContext3D* context,
- int32 id,
- NPDeviceBuffer* buffer);
- virtual NPError Device3DGetNumConfigs(int32* num_configs);
- virtual NPError Device3DGetConfigAttribs(int32 config,
- int32* attrib_list);
- virtual NPError Device3DCreateContext(int32 config,
- const int32* attrib_list,
- NPDeviceContext3D** context);
- virtual NPError Device3DRegisterCallback(
- NPP id,
- NPDeviceContext3D* context,
- int32 callback_type,
- NPDeviceGenericCallbackPtr callback,
- void* callback_data);
- virtual NPError Device3DSynchronizeContext(
- NPP id,
- NPDeviceContext3D* context,
- NPDeviceSynchronizationMode mode,
- const int32* input_attrib_list,
- int32* output_attrib_list,
- NPDeviceSynchronizeContextCallbackPtr callback,
- void* callback_data);
-
- // WebPluginAudioDeviceDelegate implementation.
- virtual NPError DeviceAudioQueryCapability(int32 capability, int32* value);
- virtual NPError DeviceAudioQueryConfig(
- const NPDeviceContextAudioConfig* request,
- NPDeviceContextAudioConfig* obtain);
- virtual NPError DeviceAudioInitializeContext(
- const NPDeviceContextAudioConfig* config,
- NPDeviceContextAudio* context);
- virtual NPError DeviceAudioSetStateContext(NPDeviceContextAudio* context,
- int32 state, intptr_t value);
- virtual NPError DeviceAudioGetStateContext(NPDeviceContextAudio* context,
- int32 state, intptr_t* value);
- virtual NPError DeviceAudioFlushContext(
- NPP id, NPDeviceContextAudio* context,
- NPDeviceFlushContextCallbackPtr callback, void* user_data);
- virtual NPError DeviceAudioDestroyContext(NPDeviceContextAudio* context);
-
- // WebPluginPrintDelegate implementation.
- virtual bool PrintSupportsPrintExtension();
- virtual int PrintBegin(const gfx::Rect& printable_area, int printer_dpi);
- virtual bool PrintPage(int page_number, WebKit::WebCanvas* canvas);
- virtual void PrintEnd();
-
- gfx::Rect GetRect() const { return window_rect_; }
- gfx::Rect GetClipRect() const { return clip_rect_; }
-
- // Returns the path for the library implementing this plugin.
- FilePath GetPluginPath();
-
- // Notifications when the RenderView painted the screen (InitiatedPaint) and
- // when an ack was received that the browser copied it to the screen
- // (FlushedPaint).
- void RenderViewInitiatedPaint();
- void RenderViewFlushedPaint();
-
- Graphics2DDeviceContext* GetGraphicsContext(NPDeviceContext2D* context);
-
- private:
- WebPluginDelegatePepper(
- const base::WeakPtr<RenderView>& render_view,
- webkit::npapi::PluginInstance *instance);
- ~WebPluginDelegatePepper();
-
- //-----------------------------------------
- // used for windowed and windowless plugins
-
- // Closes down and destroys our plugin instance.
- void DestroyInstance();
-
- void ForwardSetWindow();
-
- // A helper method that invokes the plugin's Print extensions to calculate
- // the size needed in pixels to render the given page in a raster format.
- bool CalculatePrintedPageDimensions(int page_number,
- NPPPrintExtensions* print_extensions,
- gfx::Size* page_dimensions);
- bool VectorPrintPage(int page_number, WebKit::WebCanvas* canvas);
-
- NPPPrintExtensions* GetPrintExtensions();
-
- NPPFindExtensions* GetFindExtensions();
-
-#if defined(OS_WIN)
- // Compresses the given bitmap as JPEG and draws it into the backing platform
- // DC (Windows-only).
- bool DrawJPEGToPlatformDC(const SkBitmap& bitmap,
- const gfx::Rect& printable_area,
- WebKit::WebCanvas* canvas);
-#endif // OS_WIN
-#if defined(OS_MACOSX)
- // Draws the given kARGB_8888_Config bitmap to the specified canvas starting
- // at the specified destination rect.
- void DrawSkBitmapToCanvas(const SkBitmap& bitmap, WebKit::WebCanvas* canvas,
- const gfx::Rect& dest_rect, int canvas_height);
-#endif // OS_MACOSX
-
- // Returns the selection. If nothing is selected, returns an empty string.
- // If html is true, it will return a string only if html data is available.
- string16 GetSelectedText(bool html) const;
-
- base::WeakPtr<RenderView> render_view_;
-
- webkit::npapi::WebPlugin* plugin_;
- scoped_refptr<webkit::npapi::PluginInstance> instance_;
-
- NPWindow window_;
- gfx::Rect window_rect_;
- gfx::Rect clip_rect_;
- std::vector<gfx::Rect> cutout_rects_;
-
- // Open device contexts
- typedef IDMap<Graphics2DDeviceContext, IDMapOwnPointer> Graphics2DMap;
- Graphics2DMap graphic2d_contexts_;
- IDMap<AudioDeviceContext, IDMapOwnPointer> audio_contexts_;
-
- // Plugin graphics context implementation
- SkBitmap committed_bitmap_;
-
- // The url with which the plugin was instantiated.
- std::string plugin_url_;
-
- // The last printable_area passed in to PrintBegin. We remember this because
- // we need to stretch the printed raster bitmap to these dimensions. It is
- // cleared in PrintEnd.
- gfx::Rect current_printable_area_;
- int current_printer_dpi_;
-#if defined(OS_MACOSX)
- // On the Mac, when we draw the bitmap to the PDFContext, it seems necessary
- // to keep the pixels valid until CGContextEndPage is called. We use this
- // variable to hold on to the pixels.
- SkBitmap last_printed_page_;
-#endif // defined(OS_MACOSX)
-#if defined (OS_LINUX)
- // On Linux, we always send all pages from the renderer to the browser.
- // So, if the plugin supports printPagesAsPDF we print the entire output
- // in one shot in the first call to PrintPage.
- // (This is a temporary hack until we change the WebFrame and WebPlugin print
- // interfaces).
- // Specifies the total number of pages to be printed. It it set in PrintBegin.
- int32 num_pages_;
- // Specifies whether we have already output all pages. This is used to ignore
- // subsequent PrintPage requests.
- bool pdf_output_done_;
-#endif // defined(OS_LINUX)
-
- // The id of the current find operation, or -1 if none is in process.
- int find_identifier_;
-
- // When a choose file operation is outstanding, this will contain a
- // pointer to the callback specified by the plugin. Will be NULL otherwise.
- NPChooseFileCallback current_choose_file_callback_;
- void* current_choose_file_user_data_;
-
- scoped_ptr<WebKit::WebCursorInfo> cursor_;
-
- DISALLOW_COPY_AND_ASSIGN(WebPluginDelegatePepper);
-};
-
-#endif // CHROME_RENDERER_WEBPLUGIN_DELEGATE_PEPPER_H_
diff --git a/gpu/demos/demos.gyp b/gpu/demos/demos.gyp
index 767d86b..2e2ead0 100644
--- a/gpu/demos/demos.gyp
+++ b/gpu/demos/demos.gyp
@@ -57,70 +57,6 @@
],
},
{
- 'target_name': 'gpu_demo_framework_pepper',
- 'type': 'static_library',
- # This target injects a bunch of source files to direct dependents.
- # If the dependent is a none-type target (like all.gyp), gyp will
- # generate error due to these injected source files. Workaround this
- # problem by preventing it from being selected by demos.gyp:*.
- # TODO(neb): remove source injection and this flag.
- 'suppress_wildcard': 1,
- 'dependencies': [
- 'gpu_demo_framework',
- '../gpu.gyp:pgl',
- ],
- 'include_dirs': ['../..'],
- 'sources': [
- 'framework/plugin.cc',
- 'framework/plugin.h',
- ],
- 'direct_dependent_settings': {
- 'include_dirs': ['../..'],
- 'sources': ['framework/main_pepper.cc'],
- 'run_as': {
- 'conditions': [
- ['OS=="mac"', {
- 'action': [
- '<(PRODUCT_DIR)/Chromium.app/Contents/MacOS/Chromium',
- '--no-sandbox',
- '--internal-pepper',
- '--enable-gpu-plugin',
- '--load-plugin=<(PRODUCT_DIR)/$(PRODUCT_NAME).plugin',
- 'file://$(SOURCE_ROOT)/pepper_gpu_demo.html',
- ],
- }, { # OS != "mac"
- 'action': [
- '<(PRODUCT_DIR)/<(EXECUTABLE_PREFIX)chrome<(EXECUTABLE_SUFFIX)',
- '--no-sandbox',
- '--internal-pepper',
- '--enable-gpu-plugin',
- '--load-plugin=$(TargetPath)',
- 'file://$(ProjectDir)pepper_gpu_demo.html',
- ],
- }],
- ],
- },
- 'conditions': [
- ['OS=="win"', {
- 'sources': [
- 'framework/plugin.def',
- 'framework/plugin.rc',
- ],
- }],
- ['OS=="mac"', {
- 'sources': [
- 'framework/Plugin_Info.plist',
- ],
- 'xcode_settings': {
- 'INFOPLIST_FILE': 'framework/Plugin_Info.plist',
- },
- 'mac_bundle': 1,
- 'product_extension': 'plugin',
- }],
- ],
- },
- },
- {
'target_name': 'gpu_demo_framework_ppapi',
'type': 'static_library',
'dependencies': [
@@ -270,90 +206,6 @@
['enable_pepper_demos==1', {
'targets': [
{
- 'target_name': 'hello_triangle_pepper',
- 'type': 'loadable_module',
- 'dependencies': [
- 'gpu_demo_framework_pepper',
- '../../third_party/gles2_book/gles2_book.gyp:hello_triangle',
- ],
- 'sources': [
- 'gles2_book/example.h',
- 'gles2_book/demo_hello_triangle.cc',
- ],
- },
- {
- 'target_name': 'mip_map_2d_pepper',
- 'type': 'loadable_module',
- 'dependencies': [
- 'gpu_demo_framework_pepper',
- '../../third_party/gles2_book/gles2_book.gyp:mip_map_2d',
- ],
- 'sources': [
- 'gles2_book/example.h',
- 'gles2_book/demo_mip_map_2d.cc',
- ],
- },
- {
- 'target_name': 'simple_texture_2d_pepper',
- 'type': 'loadable_module',
- 'dependencies': [
- 'gpu_demo_framework_pepper',
- '../../third_party/gles2_book/gles2_book.gyp:simple_texture_2d',
- ],
- 'sources': [
- 'gles2_book/example.h',
- 'gles2_book/demo_simple_texture_2d.cc',
- ],
- },
- {
- 'target_name': 'simple_texture_cubemap_pepper',
- 'type': 'loadable_module',
- 'dependencies': [
- 'gpu_demo_framework_pepper',
- '../../third_party/gles2_book/gles2_book.gyp:simple_texture_cubemap',
- ],
- 'sources': [
- 'gles2_book/example.h',
- 'gles2_book/demo_simple_texture_cubemap.cc',
- ],
- },
- {
- 'target_name': 'simple_vertex_shader_pepper',
- 'type': 'loadable_module',
- 'dependencies': [
- 'gpu_demo_framework_pepper',
- '../../third_party/gles2_book/gles2_book.gyp:simple_vertex_shader',
- ],
- 'sources': [
- 'gles2_book/example.h',
- 'gles2_book/demo_simple_vertex_shader.cc',
- ],
- },
- {
- 'target_name': 'stencil_test_pepper',
- 'type': 'loadable_module',
- 'dependencies': [
- 'gpu_demo_framework_pepper',
- '../../third_party/gles2_book/gles2_book.gyp:stencil_test',
- ],
- 'sources': [
- 'gles2_book/example.h',
- 'gles2_book/demo_stencil_test.cc',
- ],
- },
- {
- 'target_name': 'texture_wrap_pepper',
- 'type': 'loadable_module',
- 'dependencies': [
- 'gpu_demo_framework_pepper',
- '../../third_party/gles2_book/gles2_book.gyp:texture_wrap',
- ],
- 'sources': [
- 'gles2_book/example.h',
- 'gles2_book/demo_texture_wrap.cc',
- ],
- },
- {
'target_name': 'hello_triangle_ppapi',
'type': 'loadable_module',
'variables': { 'chromium_code': 0, },
diff --git a/gpu/demos/framework/main_pepper.cc b/gpu/demos/framework/main_pepper.cc
deleted file mode 100644
index 2f50595..0000000
--- a/gpu/demos/framework/main_pepper.cc
+++ /dev/null
@@ -1,183 +0,0 @@
-// Copyright (c) 2010 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 "gpu/demos/framework/plugin.h"
-#include "gpu/pgl/pgl.h"
-#include "third_party/npapi/bindings/nphostapi.h"
-
-#if __GNUC__ >= 4
-#define EXPORT __attribute__ ((visibility("default")))
-#else
-// We use .def file to export symbols on OS_WIN. We could potentially use
-// __declspec(dllexport) but API_CALL always adds something to the function
-// signature even inside extern "C" {}
-#define EXPORT
-#endif // GNUC
-
-namespace gpu {
-namespace demos {
-// NPP entry points.
-NPError NPP_New(NPMIMEType pluginType,
- NPP instance,
- uint16 mode,
- int16 argc, char* argn[], char* argv[],
- NPSavedData* saved) {
- if (g_browser->version < NPVERS_HAS_PLUGIN_THREAD_ASYNC_CALL) {
- return NPERR_INCOMPATIBLE_VERSION_ERROR;
- }
-
- Plugin* plugin = static_cast<Plugin*>(
- g_browser->createobject(instance, Plugin::GetPluginClass()));
- instance->pdata = plugin;
- plugin->New(pluginType, argc, argn, argv);
-
- return NPERR_NO_ERROR;
-}
-
-NPError NPP_Destroy(NPP instance, NPSavedData** save) {
- Plugin* plugin = static_cast<Plugin*>(instance->pdata);
- if (plugin) g_browser->releaseobject(plugin);
-
- return NPERR_NO_ERROR;
-}
-
-NPError NPP_SetWindow(NPP instance, NPWindow* window) {
- Plugin* plugin = static_cast<Plugin*>(instance->pdata);
- if (plugin) plugin->SetWindow(*window);
-
- return NPERR_NO_ERROR;
-}
-
-NPError NPP_NewStream(NPP instance,
- NPMIMEType type,
- NPStream* stream,
- NPBool seekable,
- uint16* stype) {
- *stype = NP_ASFILEONLY;
- return NPERR_NO_ERROR;
-}
-
-NPError NPP_DestroyStream(NPP instance, NPStream* stream, NPReason reason) {
- return NPERR_NO_ERROR;
-}
-
-void NPP_StreamAsFile(NPP instance, NPStream* stream, const char* fname) {
-}
-
-int32 NPP_Write(NPP instance,
- NPStream* stream,
- int32 offset,
- int32 len,
- void* buffer) {
- return 0;
-}
-
-int32 NPP_WriteReady(NPP instance, NPStream* stream) {
- return 0;
-}
-
-void NPP_Print(NPP instance, NPPrint* platformPrint) {
-}
-
-int16 NPP_HandleEvent(NPP instance, void* event) {
- Plugin* plugin = static_cast<Plugin*>(instance->pdata);
-
- if (plugin)
- return plugin->HandleEvent(*static_cast<NPPepperEvent*>(event));
-
- return 0;
-}
-
-void NPP_URLNotify(NPP instance, const char* url, NPReason reason,
- void* notify_data) {
-}
-
-NPError NPP_GetValue(NPP instance, NPPVariable variable, void* value) {
- NPError err = NPERR_NO_ERROR;
-
- switch (variable) {
-#if defined(OS_LINUX)
- case NPPVpluginNameString:
- *(static_cast<const char**>(value)) = "Pepper GPU Demo";
- break;
- case NPPVpluginDescriptionString:
- *(static_cast<const char**>(value)) = "Pepper plug-in for GPU demo.";
- break;
- case NPPVpluginNeedsXEmbed:
- *(static_cast<NPBool*>(value)) = true;
- break;
-#endif
- case NPPVpluginScriptableNPObject: {
- void** v = static_cast<void**>(value);
- Plugin* plugin = static_cast<Plugin*>(instance->pdata);
- // Return value is expected to be retained
- g_browser->retainobject(plugin);
- *v = plugin;
- break;
- }
- default:
- err = NPERR_GENERIC_ERROR;
- break;
- }
-
- return err;
-}
-
-NPError NPP_SetValue(NPP instance, NPNVariable variable, void* value) {
- return NPERR_GENERIC_ERROR;
-}
-} // namespace demos
-} // namespace gpu
-
-// NP entry points
-extern "C" {
-EXPORT NPError API_CALL NP_GetEntryPoints(NPPluginFuncs* plugin_funcs) {
- plugin_funcs->version = NPVERS_HAS_PLUGIN_THREAD_ASYNC_CALL;
- plugin_funcs->size = sizeof(plugin_funcs);
- plugin_funcs->newp = gpu::demos::NPP_New;
- plugin_funcs->destroy = gpu::demos::NPP_Destroy;
- plugin_funcs->setwindow = gpu::demos::NPP_SetWindow;
- plugin_funcs->newstream = gpu::demos::NPP_NewStream;
- plugin_funcs->destroystream = gpu::demos::NPP_DestroyStream;
- plugin_funcs->asfile = gpu::demos::NPP_StreamAsFile;
- plugin_funcs->writeready = gpu::demos::NPP_WriteReady;
- plugin_funcs->write = gpu::demos::NPP_Write;
- plugin_funcs->print = gpu::demos::NPP_Print;
- plugin_funcs->event = gpu::demos::NPP_HandleEvent;
- plugin_funcs->urlnotify = gpu::demos::NPP_URLNotify;
- plugin_funcs->getvalue = gpu::demos::NPP_GetValue;
- plugin_funcs->setvalue = gpu::demos::NPP_SetValue;
-
- return NPERR_NO_ERROR;
-}
-
-EXPORT NPError API_CALL NP_Initialize(NPNetscapeFuncs* browser_funcs
-#if defined(OS_LINUX)
- , NPPluginFuncs* plugin_funcs
-#endif // OS_LINUX
- ) {
- gpu::demos::g_browser = browser_funcs;
- pglInitialize();
-
-#if defined(OS_LINUX)
- NP_GetEntryPoints(plugin_funcs);
-#endif // OS_LINUX
- return NPERR_NO_ERROR;
-}
-
-EXPORT void API_CALL NP_Shutdown() {
- pglTerminate();
-}
-
-#if defined(OS_LINUX)
-EXPORT NPError API_CALL NP_GetValue(NPP instance, NPPVariable variable,
- void* value) {
- return gpu::demos::NPP_GetValue(instance, variable, value);
-}
-
-EXPORT const char* API_CALL NP_GetMIMEDescription() {
- return "pepper-application/x-gpu-demo::Pepper GPU Demo";
-}
-#endif // OS_LINUX
-} // extern "C"