summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/tab_contents/render_view_context_menu.cc3
-rw-r--r--chrome/renderer/webplugin_delegate_pepper.cc33
-rw-r--r--chrome/renderer/webplugin_delegate_pepper.h4
-rw-r--r--third_party/npapi/bindings/npapi_extensions.h30
-rw-r--r--webkit/glue/plugins/npapi_extension_thunk.cc7
-rw-r--r--webkit/glue/plugins/webplugin_delegate.h2
-rw-r--r--webkit/glue/plugins/webplugin_impl.cc7
-rw-r--r--webkit/glue/plugins/webplugin_impl.h1
8 files changed, 66 insertions, 21 deletions
diff --git a/chrome/browser/tab_contents/render_view_context_menu.cc b/chrome/browser/tab_contents/render_view_context_menu.cc
index 8fb7fa2..ffbf57c 100644
--- a/chrome/browser/tab_contents/render_view_context_menu.cc
+++ b/chrome/browser/tab_contents/render_view_context_menu.cc
@@ -738,7 +738,8 @@ bool RenderViewContextMenu::IsCommandIdEnabled(int id) const {
source_tab_contents_->language_state().original_language();
std::string target_lang = g_browser_process->GetApplicationLocale();
target_lang = TranslateManager2::GetLanguageCode(target_lang);
- return original_lang != target_lang &&
+ return !!(params_.edit_flags & WebContextMenuData::CanTranslate) &&
+ original_lang != target_lang &&
!source_tab_contents_->language_state().IsPageTranslated() &&
!source_tab_contents_->interstitial_page() &&
TranslateManager2::IsTranslatableURL(params_.page_url);
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_;
diff --git a/third_party/npapi/bindings/npapi_extensions.h b/third_party/npapi/bindings/npapi_extensions.h
index cbc9e69..ec0eaf9 100644
--- a/third_party/npapi/bindings/npapi_extensions.h
+++ b/third_party/npapi/bindings/npapi_extensions.h
@@ -410,11 +410,6 @@ typedef NPDevice* (*NPAcquireDevicePtr)(
NPP instance,
NPDeviceID device);
-/* Copy UTF-8 string into clipboard */
-typedef void (*NPCopyTextToClipboardPtr)(
- NPP instance,
- const char* content);
-
/* Updates the number of find results for the current search term. If
* there are no matches 0 should be passed in. Only when the plugin has
* finished searching should it pass in the final count with finalResult set to
@@ -711,8 +706,6 @@ typedef NPFontExtensions* (*NPGetFontExtensionsPtr)(
struct NPNExtensions {
/* Device interface acquisition */
NPAcquireDevicePtr acquireDevice;
- /* Clipboard functionality */
- NPCopyTextToClipboardPtr copyTextToClipboard;
/* Find */
NPNumberOfFindResultsChangedPtr numberOfFindResultsChanged;
NPSelectedFindResultChangedPtr selectedFindResultChanged;
@@ -1045,16 +1038,31 @@ typedef NPError (*NPPWidgetPropertyChangedPtr) (
NPWidgetID id,
NPWidgetProperty property);
-/* Tells the plugin to copy the selected text */
-typedef NPError (*NPPCopyPtr) (
- NPP instance);
+/* type of selection */
+typedef enum {
+ NPSelectionTypeAny = 0,
+ NPSelectionTypePlainText = 1,
+ NPSelectionTypeHTML = 2
+} NPSelectionType;
+
+/* Gets the selection. NPERR_GENERIC_ERROR is returned if nothing is selected.
+ * 'type' is both an input and output parameter. The caller can request a
+ * specific type, and if the plugin can't provide it, it will return
+ * NPERR_GENERIC_ERROR. Or the caller can specify NPSelectionTypeAny to let the
+ * plugin pick the best format for the data. The result is returned in a buffer
+ * that's owned by the caller and which is allocated using NPN_MemAlloc. If no
+ * data is available, NPERR_GENERIC_ERROR is returned. */
+typedef NPError (*NPPGetSelectionPtr) (
+ NPP instance,
+ NPSelectionType* type,
+ void** data);
typedef struct _NPPExtensions {
NPPGetPrintExtensionsPtr getPrintExtensions;
NPPGetFindExtensionsPtr getFindExtensions;
NPPZoomPtr zoom;
NPPWidgetPropertyChangedPtr widgetPropertyChanged;
- NPPCopyPtr copy;
+ NPPGetSelectionPtr getSelection;
} NPPExtensions;
#endif /* _NP_EXTENSIONS_H_ */
diff --git a/webkit/glue/plugins/npapi_extension_thunk.cc b/webkit/glue/plugins/npapi_extension_thunk.cc
index d2abd27..4779535 100644
--- a/webkit/glue/plugins/npapi_extension_thunk.cc
+++ b/webkit/glue/plugins/npapi_extension_thunk.cc
@@ -11,7 +11,6 @@
#include "webkit/glue/plugins/plugin_instance.h"
#include "webkit/glue/plugins/webplugin.h"
#include "webkit/glue/plugins/webplugin_delegate.h"
-#include "webkit/glue/scoped_clipboard_writer_glue.h"
#include "webkit/glue/webkit_glue.h"
// FindInstance()
@@ -473,11 +472,6 @@ static NPDevice* AcquireDevice(NPP id, NPDeviceID device_id) {
}
}
-static void CopyTextToClipboard(NPP id, const char* content) {
- ScopedClipboardWriterGlue scw(webkit_glue::ClipboardGetClipboard());
- scw.WriteText(UTF8ToUTF16(content));
-}
-
static NPError ChooseFile(NPP id,
const char* mime_types,
NPChooseFileMode mode,
@@ -539,7 +533,6 @@ namespace NPAPI {
NPError GetPepperExtensionsFunctions(void* value) {
static const NPNExtensions kExtensions = {
&AcquireDevice,
- &CopyTextToClipboard,
&NumberOfFindResultsChanged,
&SelectedFindResultChanged,
&ChooseFile,
diff --git a/webkit/glue/plugins/webplugin_delegate.h b/webkit/glue/plugins/webplugin_delegate.h
index 413a509..f496d52 100644
--- a/webkit/glue/plugins/webplugin_delegate.h
+++ b/webkit/glue/plugins/webplugin_delegate.h
@@ -159,6 +159,8 @@ class WebPluginDelegate : public WebPlugin2DDeviceDelegate,
virtual void Zoom(int factor) {}
// Copy the selected text.
virtual void Copy() {}
+ // Gets the selected UTF8 text, if any.
+ virtual string16 GetSelectedText() { return string16(); }
};
} // namespace webkit_glue
diff --git a/webkit/glue/plugins/webplugin_impl.cc b/webkit/glue/plugins/webplugin_impl.cc
index a83f35c..96f7b4b 100644
--- a/webkit/glue/plugins/webplugin_impl.cc
+++ b/webkit/glue/plugins/webplugin_impl.cc
@@ -422,6 +422,13 @@ void WebPluginImpl::printEnd() {
delegate_->PrintEnd();
}
+WebString WebPluginImpl::selectedText() {
+ if (!delegate_)
+ return WebString();
+
+ return delegate_->GetSelectedText();
+}
+
// -----------------------------------------------------------------------------
diff --git a/webkit/glue/plugins/webplugin_impl.h b/webkit/glue/plugins/webplugin_impl.h
index 9c2fa33..8436ae7 100644
--- a/webkit/glue/plugins/webplugin_impl.h
+++ b/webkit/glue/plugins/webplugin_impl.h
@@ -93,6 +93,7 @@ class WebPluginImpl : public WebPlugin,
int printer_dpi);
virtual bool printPage(int page_number, WebKit::WebCanvas* canvas);
virtual void printEnd();
+ virtual WebKit::WebString selectedText();
// WebPlugin implementation:
void SetWindow(gfx::PluginWindowHandle window);