diff options
author | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-29 20:38:38 +0000 |
---|---|---|
committer | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-29 20:38:38 +0000 |
commit | ba6b5cfec256bf3e2050a128289c062effede0d2 (patch) | |
tree | 274a882ae1ca7e4c1667813d76f3d9cc0158fc2f /chrome/renderer | |
parent | 894f4a077ae70c658a285377c0f957c0259817d3 (diff) | |
download | chromium_src-ba6b5cfec256bf3e2050a128289c062effede0d2.zip chromium_src-ba6b5cfec256bf3e2050a128289c062effede0d2.tar.gz chromium_src-ba6b5cfec256bf3e2050a128289c062effede0d2.tar.bz2 |
Allow quering Pepper plugin for selected text for the context menu. Also take out the ability to access the clipboard since it's not exposed to HTML for security reasons.
Review URL: http://codereview.chromium.org/2841028
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@51159 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer')
-rw-r--r-- | chrome/renderer/webplugin_delegate_pepper.cc | 33 | ||||
-rw-r--r-- | chrome/renderer/webplugin_delegate_pepper.h | 4 |
2 files changed, 35 insertions, 2 deletions
diff --git a/chrome/renderer/webplugin_delegate_pepper.cc b/chrome/renderer/webplugin_delegate_pepper.cc index 3ceac28..d388f1c 100644 --- a/chrome/renderer/webplugin_delegate_pepper.cc +++ b/chrome/renderer/webplugin_delegate_pepper.cc @@ -55,6 +55,7 @@ #include "webkit/glue/plugins/plugin_list.h" #include "webkit/glue/plugins/plugin_host.h" #include "webkit/glue/plugins/plugin_stream_url.h" +#include "webkit/glue/scoped_clipboard_writer_glue.h" #include "webkit/glue/webkit_glue.h" #if defined(ENABLE_GPU) @@ -509,10 +510,38 @@ void WebPluginDelegatePepper::Zoom(int factor) { } void WebPluginDelegatePepper::Copy() { + ScopedClipboardWriterGlue scw(webkit_glue::ClipboardGetClipboard()); + string16 text = GetSelectedText(true); + if (!text.empty()) { + // Got html data. + scw.WriteHTML(text, std::string()); + return; + } + + text = GetSelectedText(false); + if (!text.empty()) + scw.WriteText(text); +} + +string16 WebPluginDelegatePepper::GetSelectedText() { + return GetSelectedText(false); +} + +string16 WebPluginDelegatePepper::GetSelectedText(bool html) { NPPExtensions* extensions = NULL; instance()->NPP_GetValue(NPPVPepperExtensions, &extensions); - if (extensions && extensions->copy) - extensions->copy(instance()->npp()); + 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)); + NPAPI::PluginHost::Singleton()->host_functions()->memfree(text); + return rv; } NPError WebPluginDelegatePepper::Device2DQueryCapability(int32 capability, diff --git a/chrome/renderer/webplugin_delegate_pepper.h b/chrome/renderer/webplugin_delegate_pepper.h index efc60ff..3524112 100644 --- a/chrome/renderer/webplugin_delegate_pepper.h +++ b/chrome/renderer/webplugin_delegate_pepper.h @@ -97,6 +97,7 @@ class WebPluginDelegatePepper : public webkit_glue::WebPluginDelegate, virtual NPFontExtensions* GetFontExtensions(); virtual void Zoom(int factor); virtual void Copy(); + virtual string16 GetSelectedText(); // WebPlugin2DDeviceDelegate implementation. virtual NPError Device2DQueryCapability(int32 capability, int32* value); @@ -265,6 +266,9 @@ class WebPluginDelegatePepper : public webkit_glue::WebPluginDelegate, void SendNestedDelegateGeometryToBrowser(const gfx::Rect& window_rect, const gfx::Rect& clip_rect); + // 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); base::WeakPtr<RenderView> render_view_; |