diff options
author | koz@chromium.org <koz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-02-03 06:55:14 +0000 |
---|---|---|
committer | koz@chromium.org <koz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-02-03 06:55:14 +0000 |
commit | 5eda962962d8b405733cd9a5184b367070096dea (patch) | |
tree | 76cc3b970a04b7630956a4bab2bf342082b54e1b | |
parent | c02f1bab5a382072c5488762038435a80dc10e67 (diff) | |
download | chromium_src-5eda962962d8b405733cd9a5184b367070096dea.zip chromium_src-5eda962962d8b405733cd9a5184b367070096dea.tar.gz chromium_src-5eda962962d8b405733cd9a5184b367070096dea.tar.bz2 |
Have the PDF plugin eagerly notify the host of the link under the cursor.
We do this so the host can synchronously query the link under
the cursor for the out of process PDF plugin.
Review URL: https://codereview.chromium.org/135853009
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@248443 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/renderer/pepper/pepper_pdf_host.cc | 13 | ||||
-rw-r--r-- | chrome/renderer/pepper/pepper_pdf_host.h | 3 | ||||
-rw-r--r-- | chrome/renderer/pepper/ppb_pdf_impl.cc | 9 | ||||
-rw-r--r-- | content/public/renderer/pepper_plugin_instance.h | 3 | ||||
-rw-r--r-- | content/renderer/pepper/fake_pepper_plugin_instance.cc | 2 | ||||
-rw-r--r-- | content/renderer/pepper/fake_pepper_plugin_instance.h | 1 | ||||
-rw-r--r-- | content/renderer/pepper/pepper_plugin_instance_impl.cc | 16 | ||||
-rw-r--r-- | content/renderer/pepper/pepper_plugin_instance_impl.h | 4 | ||||
-rw-r--r-- | content/renderer/pepper/ppp_pdf.h | 2 | ||||
-rw-r--r-- | ppapi/api/private/finish_writing_these/ppb_pdf.idl | 9 | ||||
-rw-r--r-- | ppapi/c/private/ppb_pdf.h | 3 | ||||
-rw-r--r-- | ppapi/cpp/private/pdf.cc | 6 | ||||
-rw-r--r-- | ppapi/cpp/private/pdf.h | 2 | ||||
-rw-r--r-- | ppapi/proxy/pdf_resource.cc | 4 | ||||
-rw-r--r-- | ppapi/proxy/pdf_resource.h | 1 | ||||
-rw-r--r-- | ppapi/proxy/ppapi_messages.h | 4 | ||||
-rw-r--r-- | ppapi/thunk/ppb_pdf_api.h | 1 | ||||
-rw-r--r-- | ppapi/thunk/ppb_pdf_thunk.cc | 8 |
18 files changed, 88 insertions, 3 deletions
diff --git a/chrome/renderer/pepper/pepper_pdf_host.cc b/chrome/renderer/pepper/pepper_pdf_host.cc index 0d9b594..1a55636 100644 --- a/chrome/renderer/pepper/pepper_pdf_host.cc +++ b/chrome/renderer/pepper/pepper_pdf_host.cc @@ -150,6 +150,8 @@ int32_t PepperPDFHost::OnResourceMessageReceived( OnHostMsgGetResourceImage) PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_PDF_SetSelectedText, OnHostMsgSetSelectedText) + PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_PDF_SetLinkUnderCursor, + OnHostMsgSetLinkUnderCursor) IPC_END_MESSAGE_MAP() return PP_ERROR_FAILED; } @@ -355,6 +357,17 @@ int32_t PepperPDFHost::OnHostMsgSetSelectedText( return PP_OK; } +int32_t PepperPDFHost::OnHostMsgSetLinkUnderCursor( + ppapi::host::HostMessageContext* context, + const std::string& url) { + content::PepperPluginInstance* instance = + host_->GetPluginInstance(pp_instance()); + if (!instance) + return PP_ERROR_FAILED; + instance->SetLinkUnderCursor(url); + return PP_OK; +} + // TODO(raymes): This function is mainly copied from ppb_image_data_proxy.cc. // It's a mess and needs to be fixed in several ways but this is better done // when we refactor PPB_ImageData. On success, the image handle will be diff --git a/chrome/renderer/pepper/pepper_pdf_host.h b/chrome/renderer/pepper/pepper_pdf_host.h index 39036f2..93b5c39 100644 --- a/chrome/renderer/pepper/pepper_pdf_host.h +++ b/chrome/renderer/pepper/pepper_pdf_host.h @@ -66,6 +66,9 @@ class PepperPDFHost : public ppapi::host::ResourceHost { int32_t OnHostMsgSetSelectedText( ppapi::host::HostMessageContext* context, const base::string16& selected_text); + int32_t OnHostMsgSetLinkUnderCursor( + ppapi::host::HostMessageContext* context, + const std::string& url); bool CreateImageData(PP_Instance instance, PP_ImageDataFormat format, diff --git a/chrome/renderer/pepper/ppb_pdf_impl.cc b/chrome/renderer/pepper/ppb_pdf_impl.cc index d9d618c..d0c9341 100644 --- a/chrome/renderer/pepper/ppb_pdf_impl.cc +++ b/chrome/renderer/pepper/ppb_pdf_impl.cc @@ -434,6 +434,14 @@ void SetSelectedText(PP_Instance instance_id, const char* selected_text) { NOTIMPLEMENTED(); } +void SetLinkUnderCursor(PP_Instance instance_id, const char* url) { + content::PepperPluginInstance* instance = + content::PepperPluginInstance::Get(instance_id); + if (!instance) + return; + instance->SetLinkUnderCursor(url); +} + const PPB_PDF ppb_pdf = { &GetLocalizedString, &GetResourceImage, @@ -453,6 +461,7 @@ const PPB_PDF ppb_pdf = { &ModalPromptForPassword, &IsOutOfProcess, &SetSelectedText, + &SetLinkUnderCursor, }; } // namespace diff --git a/content/public/renderer/pepper_plugin_instance.h b/content/public/renderer/pepper_plugin_instance.h index 89caccf..8628ac8 100644 --- a/content/public/renderer/pepper_plugin_instance.h +++ b/content/public/renderer/pepper_plugin_instance.h @@ -107,6 +107,9 @@ class PepperPluginInstance { // Sets the selected text for this plugin. virtual void SetSelectedText(const base::string16& selected_text) = 0; + + // Sets the link currently under the cursor. + virtual void SetLinkUnderCursor(const std::string& url) = 0; }; } // namespace content diff --git a/content/renderer/pepper/fake_pepper_plugin_instance.cc b/content/renderer/pepper/fake_pepper_plugin_instance.cc index af1a900..1a54058 100644 --- a/content/renderer/pepper/fake_pepper_plugin_instance.cc +++ b/content/renderer/pepper/fake_pepper_plugin_instance.cc @@ -81,4 +81,6 @@ void FakePepperPluginInstance::SetEmbedProperty(PP_Var key, PP_Var value) {} void FakePepperPluginInstance::SetSelectedText( const base::string16& selected_text) {} +void FakePepperPluginInstance::SetLinkUnderCursor(const std::string& url) {} + } // namespace content diff --git a/content/renderer/pepper/fake_pepper_plugin_instance.h b/content/renderer/pepper/fake_pepper_plugin_instance.h index d97d020..30b5ca4 100644 --- a/content/renderer/pepper/fake_pepper_plugin_instance.h +++ b/content/renderer/pepper/fake_pepper_plugin_instance.h @@ -40,6 +40,7 @@ class FakePepperPluginInstance : public PepperPluginInstance { const base::FilePath& path) OVERRIDE; virtual void SetEmbedProperty(PP_Var key, PP_Var value) OVERRIDE; virtual void SetSelectedText(const base::string16& selected_text) OVERRIDE; + virtual void SetLinkUnderCursor(const std::string& url) OVERRIDE; private: GURL gurl_; diff --git a/content/renderer/pepper/pepper_plugin_instance_impl.cc b/content/renderer/pepper/pepper_plugin_instance_impl.cc index 4d96508..4f28202 100644 --- a/content/renderer/pepper/pepper_plugin_instance_impl.cc +++ b/content/renderer/pepper/pepper_plugin_instance_impl.cc @@ -1251,6 +1251,10 @@ void PepperPluginInstanceImpl::SetSelectedText( selected_text_ = selected_text; } +void PepperPluginInstanceImpl::SetLinkUnderCursor(const std::string& url) { + link_under_cursor_ = base::UTF8ToUTF16(url); +} + base::string16 PepperPluginInstanceImpl::GetSelectedText(bool html) { // Keep a reference on the stack. See NOTE above. scoped_refptr<PepperPluginInstanceImpl> ref(this); @@ -1272,13 +1276,21 @@ base::string16 PepperPluginInstanceImpl::GetLinkAtPosition( const gfx::Point& point) { // Keep a reference on the stack. See NOTE above. scoped_refptr<PepperPluginInstanceImpl> ref(this); - if (!LoadPdfInterface()) - return base::string16(); + if (!LoadPdfInterface()) { + // TODO(koz): Change the containing function to GetLinkUnderCursor(). We can + // return |link_under_cursor_| here because this is only ever called with + // the current mouse coordinates. + return link_under_cursor_; + } PP_Point p; p.x = point.x(); p.y = point.y(); PP_Var rv = plugin_pdf_interface_->GetLinkAtPosition(pp_instance(), p); + // If the plugin returns undefined for this function it has switched to + // providing us with the link under the cursor eagerly. + if (rv.type == PP_VARTYPE_UNDEFINED) + return link_under_cursor_; StringVar* string = StringVar::FromPPVar(rv); base::string16 link; if (string) diff --git a/content/renderer/pepper/pepper_plugin_instance_impl.h b/content/renderer/pepper/pepper_plugin_instance_impl.h index 1817e4b..02861bd 100644 --- a/content/renderer/pepper/pepper_plugin_instance_impl.h +++ b/content/renderer/pepper/pepper_plugin_instance_impl.h @@ -373,6 +373,7 @@ class CONTENT_EXPORT PepperPluginInstanceImpl const base::FilePath& path) OVERRIDE; virtual void SetEmbedProperty(PP_Var key, PP_Var value) OVERRIDE; virtual void SetSelectedText(const base::string16& selected_text) OVERRIDE; + virtual void SetLinkUnderCursor(const std::string& url) OVERRIDE; // PPB_Instance_API implementation. virtual PP_Bool BindGraphics(PP_Instance instance, @@ -853,6 +854,9 @@ class CONTENT_EXPORT PepperPluginInstanceImpl // calls and handles PPB_ContentDecryptor_Private calls. scoped_ptr<ContentDecryptorDelegate> content_decryptor_delegate_; + // The link currently under the cursor. + base::string16 link_under_cursor_; + // Dummy NPP value used when calling in to WebBindings, to allow the bindings // to correctly track NPObjects belonging to this plugin instance. scoped_ptr<struct _NPP> npp_; diff --git a/content/renderer/pepper/ppp_pdf.h b/content/renderer/pepper/ppp_pdf.h index 6ad67bf..3e52ad7 100644 --- a/content/renderer/pepper/ppp_pdf.h +++ b/content/renderer/pepper/ppp_pdf.h @@ -22,6 +22,8 @@ PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_PrivatePageTransformType, 4); struct PPP_Pdf_1 { // Returns an absolute URL if the position is over a link. + // Deprecated: The plugin now notifies the host when the cursor is over a + // link. PP_Var (*GetLinkAtPosition)(PP_Instance instance, PP_Point point); diff --git a/ppapi/api/private/finish_writing_these/ppb_pdf.idl b/ppapi/api/private/finish_writing_these/ppb_pdf.idl index adb2c75..20e077f 100644 --- a/ppapi/api/private/finish_writing_these/ppb_pdf.idl +++ b/ppapi/api/private/finish_writing_these/ppb_pdf.idl @@ -151,8 +151,15 @@ interface PPB_PDF_0_1 { PP_Bool IsOutOfProcess( [in] PP_Instance instance); - /* Sets the selected text of the plugin. */ + /* Sets the selected text of the plugin. If |selected_text| is empty, then no + * text is selected. */ void SetSelectedText( [in] PP_Instance instance, [in] str_t selected_text); + + /* Sets the link under the cursor. If |url| is empty, then no link is under + * the cursor. */ + void SetLinkUnderCursor( + [in] PP_Instance instance, + [in] str_t url); }; diff --git a/ppapi/c/private/ppb_pdf.h b/ppapi/c/private/ppb_pdf.h index 20f975a..c0b570b 100644 --- a/ppapi/c/private/ppb_pdf.h +++ b/ppapi/c/private/ppb_pdf.h @@ -166,6 +166,9 @@ struct PPB_PDF { // Sets the selected text of the plugin. void(*SetSelectedText)(PP_Instance instance, const char* selected_text); + + // Sets the link currently under the cursor. + void (*SetLinkUnderCursor)(PP_Instance instance, const char* url); }; #endif // PPAPI_C_PRIVATE_PPB_PDF_H_ diff --git a/ppapi/cpp/private/pdf.cc b/ppapi/cpp/private/pdf.cc index 31b7dc2..7a3a877 100644 --- a/ppapi/cpp/private/pdf.cc +++ b/ppapi/cpp/private/pdf.cc @@ -214,4 +214,10 @@ void PDF::SetSelectedText(const InstanceHandle& instance, } } +// static +void PDF::SetLinkUnderCursor(const InstanceHandle& instance, const char* url) { + if (has_interface<PPB_PDF>()) + get_interface<PPB_PDF>()->SetLinkUnderCursor(instance.pp_instance(), url); +} + } // namespace pp diff --git a/ppapi/cpp/private/pdf.h b/ppapi/cpp/private/pdf.h index 1e81b34..327d681 100644 --- a/ppapi/cpp/private/pdf.h +++ b/ppapi/cpp/private/pdf.h @@ -67,6 +67,8 @@ class PDF { static bool IsOutOfProcess(const InstanceHandle& instance); static void SetSelectedText(const InstanceHandle& instance, const char* selected_text); + static void SetLinkUnderCursor(const InstanceHandle& instance, + const char* url); }; } // namespace pp diff --git a/ppapi/proxy/pdf_resource.cc b/ppapi/proxy/pdf_resource.cc index 6cd6de7..1398866 100644 --- a/ppapi/proxy/pdf_resource.cc +++ b/ppapi/proxy/pdf_resource.cc @@ -200,5 +200,9 @@ void PDFResource::SetSelectedText(const char* selected_text) { PpapiHostMsg_PDF_SetSelectedText(base::UTF8ToUTF16(selected_text))); } +void PDFResource::SetLinkUnderCursor(const char* url) { + Post(RENDERER, PpapiHostMsg_PDF_SetLinkUnderCursor(url)); +} + } // namespace proxy } // namespace ppapi diff --git a/ppapi/proxy/pdf_resource.h b/ppapi/proxy/pdf_resource.h index aa30cab..46f7cbe 100644 --- a/ppapi/proxy/pdf_resource.h +++ b/ppapi/proxy/pdf_resource.h @@ -56,6 +56,7 @@ class PPAPI_PROXY_EXPORT PDFResource virtual PP_Resource GetResourceImage(PP_ResourceImage image_id) OVERRIDE; virtual PP_Bool IsOutOfProcess() OVERRIDE; virtual void SetSelectedText(const char* selected_text) OVERRIDE; + virtual void SetLinkUnderCursor(const char* url) OVERRIDE; private: std::string locale_; diff --git a/ppapi/proxy/ppapi_messages.h b/ppapi/proxy/ppapi_messages.h index 9a2ad06..a6f8f2c 100644 --- a/ppapi/proxy/ppapi_messages.h +++ b/ppapi/proxy/ppapi_messages.h @@ -2021,6 +2021,10 @@ IPC_MESSAGE_CONTROL2(PpapiPluginMsg_PDF_GetResourceImageReply, IPC_MESSAGE_CONTROL1(PpapiHostMsg_PDF_SetSelectedText, base::string16 /* selected_text */) +// Called by the plugin to set the link under the cursor. +IPC_MESSAGE_CONTROL1(PpapiHostMsg_PDF_SetLinkUnderCursor, + std::string /* url */) + // VideoCapture_Dev, plugin -> host IPC_MESSAGE_CONTROL0(PpapiHostMsg_VideoCapture_Create) IPC_MESSAGE_CONTROL0(PpapiHostMsg_VideoCapture_StartCapture) diff --git a/ppapi/thunk/ppb_pdf_api.h b/ppapi/thunk/ppb_pdf_api.h index b7d6f78..a37da2b 100644 --- a/ppapi/thunk/ppb_pdf_api.h +++ b/ppapi/thunk/ppb_pdf_api.h @@ -33,6 +33,7 @@ class PPB_PDF_API { float scale) = 0; virtual PP_Bool IsOutOfProcess() = 0; virtual void SetSelectedText(const char* selected_text) = 0; + virtual void SetLinkUnderCursor(const char* url) = 0; static const SingletonResourceID kSingletonResourceID = PDF_SINGLETON_ID; }; diff --git a/ppapi/thunk/ppb_pdf_thunk.cc b/ppapi/thunk/ppb_pdf_thunk.cc index 36cb821..a8aa080 100644 --- a/ppapi/thunk/ppb_pdf_thunk.cc +++ b/ppapi/thunk/ppb_pdf_thunk.cc @@ -154,6 +154,13 @@ void SetSelectedText(PP_Instance instance, enter.functions()->SetSelectedText(selected_text); } +void SetLinkUnderCursor(PP_Instance instance, const char* url) { + EnterInstanceAPI<PPB_PDF_API> enter(instance); + if (enter.failed()) + return; + enter.functions()->SetLinkUnderCursor(url); +} + const PPB_PDF g_ppb_pdf_thunk = { &GetLocalizedString, &GetResourceImage, @@ -173,6 +180,7 @@ const PPB_PDF g_ppb_pdf_thunk = { &ModalPromptForPassword, &IsOutOfProcess, &SetSelectedText, + &SetLinkUnderCursor, }; } // namespace |