Commit 5491de18 authored by raymes's avatar raymes Committed by Commit bot

Make Edit>Speech>Speak Selection work for PDFs on Mac

This makes Speak Selection from the menu work for PDFs on Mac. It also
simplifies the code slightly by creating a function which gets the "full page"
guest if there is one.

BUG=476787

Review URL: https://codereview.chromium.org/1042743002

Cr-Commit-Position: refs/heads/master@{#325584}
parent 260051d3
...@@ -180,21 +180,12 @@ bool BrowserPluginEmbedder::HandleKeyboardEvent( ...@@ -180,21 +180,12 @@ bool BrowserPluginEmbedder::HandleKeyboardEvent(
return event_consumed; return event_consumed;
} }
bool BrowserPluginEmbedder::Find(int request_id, BrowserPluginGuest* BrowserPluginEmbedder::GetFullPageGuest() {
const base::string16& search_text, WebContentsImpl* guest_contents = static_cast<WebContentsImpl*>(
const blink::WebFindOptions& options) { GetBrowserPluginGuestManager()->GetFullPageGuest(web_contents()));
return GetBrowserPluginGuestManager()->ForEachGuest( if (!guest_contents)
web_contents(), return nullptr;
base::Bind(&BrowserPluginEmbedder::FindInGuest, return guest_contents->GetBrowserPluginGuest();
request_id,
search_text,
options));
}
bool BrowserPluginEmbedder::StopFinding(StopFindAction action) {
return GetBrowserPluginGuestManager()->ForEachGuest(
web_contents(),
base::Bind(&BrowserPluginEmbedder::StopFindingInGuest, action));
} }
// static // static
...@@ -209,29 +200,4 @@ bool BrowserPluginEmbedder::UnlockMouseIfNecessaryCallback(bool* mouse_unlocked, ...@@ -209,29 +200,4 @@ bool BrowserPluginEmbedder::UnlockMouseIfNecessaryCallback(bool* mouse_unlocked,
return false; return false;
} }
// static
bool BrowserPluginEmbedder::FindInGuest(int request_id,
const base::string16& search_text,
const blink::WebFindOptions& options,
WebContents* guest) {
if (static_cast<WebContentsImpl*>(guest)->GetBrowserPluginGuest()->Find(
request_id, search_text, options)) {
// There can only ever currently be one browser plugin that handles find so
// we can break the iteration at this point.
return true;
}
return false;
}
bool BrowserPluginEmbedder::StopFindingInGuest(StopFindAction action,
WebContents* guest) {
if (static_cast<WebContentsImpl*>(guest)->GetBrowserPluginGuest()
->StopFinding(action)) {
// There can only ever currently be one browser plugin that handles find so
// we can break the iteration at this point.
return true;
}
return false;
}
} // namespace content } // namespace content
...@@ -67,12 +67,10 @@ class CONTENT_EXPORT BrowserPluginEmbedder : public WebContentsObserver { ...@@ -67,12 +67,10 @@ class CONTENT_EXPORT BrowserPluginEmbedder : public WebContentsObserver {
// Used to handle special keyboard events. // Used to handle special keyboard events.
bool HandleKeyboardEvent(const NativeWebKeyboardEvent& event); bool HandleKeyboardEvent(const NativeWebKeyboardEvent& event);
// Find the given |search_text| in the page. Returns true if the find request // Returns the "full page" guest if there is one. That is, if there is a
// is handled by this browser plugin embedder. // single BrowserPlugin in the embedder which takes up the full page, then it
bool Find(int request_id, // is returned.
const base::string16& search_text, BrowserPluginGuest* GetFullPageGuest();
const blink::WebFindOptions& options);
bool StopFinding(StopFindAction action);
private: private:
explicit BrowserPluginEmbedder(WebContentsImpl* web_contents); explicit BrowserPluginEmbedder(WebContentsImpl* web_contents);
...@@ -89,12 +87,6 @@ class CONTENT_EXPORT BrowserPluginEmbedder : public WebContentsObserver { ...@@ -89,12 +87,6 @@ class CONTENT_EXPORT BrowserPluginEmbedder : public WebContentsObserver {
static bool UnlockMouseIfNecessaryCallback(bool* mouse_unlocked, static bool UnlockMouseIfNecessaryCallback(bool* mouse_unlocked,
WebContents* guest); WebContents* guest);
static bool FindInGuest(int request_id,
const base::string16& search_text,
const blink::WebFindOptions& options,
WebContents* guest);
static bool StopFindingInGuest(StopFindAction action, WebContents* guest);
// Message handlers. // Message handlers.
void OnAttach(RenderFrameHost* render_frame_host, void OnAttach(RenderFrameHost* render_frame_host,
......
...@@ -47,6 +47,8 @@ ...@@ -47,6 +47,8 @@
#include "content/common/input_messages.h" #include "content/common/input_messages.h"
#include "content/common/view_messages.h" #include "content/common/view_messages.h"
#include "content/common/webplugin_geometry.h" #include "content/common/webplugin_geometry.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_plugin_guest_manager.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "content/public/browser/native_web_keyboard_event.h" #include "content/public/browser/native_web_keyboard_event.h"
#include "content/public/browser/notification_service.h" #include "content/public/browser/notification_service.h"
...@@ -107,6 +109,23 @@ BOOL EventIsReservedBySystem(NSEvent* event) { ...@@ -107,6 +109,23 @@ BOOL EventIsReservedBySystem(NSEvent* event) {
return helper->map()->IsEventReserved(event); return helper->map()->IsEventReserved(event);
} }
RenderWidgetHostViewMac* GetRenderWidgetHostViewToUse(
RenderWidgetHostViewMac* render_widget_host_view) {
WebContents* web_contents = render_widget_host_view->GetWebContents();
if (!web_contents)
return render_widget_host_view;
content::BrowserPluginGuestManager* guest_manager =
web_contents->GetBrowserContext()->GetGuestManager();
if (!guest_manager)
return render_widget_host_view;
content::WebContents* guest =
guest_manager->GetFullPageGuest(web_contents);
if (!guest)
return render_widget_host_view;
return static_cast<RenderWidgetHostViewMac*>(
guest->GetRenderWidgetHostView());
}
} // namespace } // namespace
// These are not documented, so use only after checking -respondsToSelector:. // These are not documented, so use only after checking -respondsToSelector:.
...@@ -3274,11 +3293,11 @@ extern NSString *NSTextInputReplacementRangeAttributeName; ...@@ -3274,11 +3293,11 @@ extern NSString *NSTextInputReplacementRangeAttributeName;
} }
- (void)startSpeaking:(id)sender { - (void)startSpeaking:(id)sender {
renderWidgetHostView_->SpeakSelection(); GetRenderWidgetHostViewToUse(renderWidgetHostView_.get())->SpeakSelection();
} }
- (void)stopSpeaking:(id)sender { - (void)stopSpeaking:(id)sender {
renderWidgetHostView_->StopSpeaking(); GetRenderWidgetHostViewToUse(renderWidgetHostView_.get())->StopSpeaking();
} }
- (void)cancelComposition { - (void)cancelComposition {
......
...@@ -2503,18 +2503,20 @@ void WebContentsImpl::Find(int request_id, ...@@ -2503,18 +2503,20 @@ void WebContentsImpl::Find(int request_id,
const base::string16& search_text, const base::string16& search_text,
const blink::WebFindOptions& options) { const blink::WebFindOptions& options) {
// See if a top level browser plugin handles the find request first. // See if a top level browser plugin handles the find request first.
if (browser_plugin_embedder_ && if (browser_plugin_embedder_) {
browser_plugin_embedder_->Find(request_id, search_text, options)) { BrowserPluginGuest* guest = browser_plugin_embedder_->GetFullPageGuest();
return; if (guest && guest->Find(request_id, search_text, options))
return;
} }
Send(new ViewMsg_Find(GetRoutingID(), request_id, search_text, options)); Send(new ViewMsg_Find(GetRoutingID(), request_id, search_text, options));
} }
void WebContentsImpl::StopFinding(StopFindAction action) { void WebContentsImpl::StopFinding(StopFindAction action) {
// See if a top level browser plugin handles the stop finding request first. // See if a top level browser plugin handles the stop finding request first.
if (browser_plugin_embedder_ && if (browser_plugin_embedder_) {
browser_plugin_embedder_->StopFinding(action)) { BrowserPluginGuest* guest = browser_plugin_embedder_->GetFullPageGuest();
return; if (guest && guest->StopFinding(action))
return;
} }
Send(new ViewMsg_StopFinding(GetRoutingID(), action)); Send(new ViewMsg_StopFinding(GetRoutingID(), action));
} }
......
...@@ -18,5 +18,10 @@ bool BrowserPluginGuestManager::ForEachGuest( ...@@ -18,5 +18,10 @@ bool BrowserPluginGuestManager::ForEachGuest(
return false; return false;
} }
WebContents* BrowserPluginGuestManager::GetFullPageGuest(
WebContents* embedder_web_contents) {
return nullptr;
}
} // content } // content
...@@ -29,6 +29,11 @@ class CONTENT_EXPORT BrowserPluginGuestManager { ...@@ -29,6 +29,11 @@ class CONTENT_EXPORT BrowserPluginGuestManager {
typedef base::Callback<bool(WebContents*)> GuestCallback; typedef base::Callback<bool(WebContents*)> GuestCallback;
virtual bool ForEachGuest(WebContents* embedder_web_contents, virtual bool ForEachGuest(WebContents* embedder_web_contents,
const GuestCallback& callback); const GuestCallback& callback);
// Returns the "full page" guest if there is one. That is, if there is a
// single BrowserPlugin in the given embedder which takes up the full page,
// then it is returned.
virtual WebContents* GetFullPageGuest(WebContents* embedder_web_contents);
}; };
} // namespace content } // namespace content
......
...@@ -188,6 +188,14 @@ bool GuestViewManager::ForEachGuest(WebContents* owner_web_contents, ...@@ -188,6 +188,14 @@ bool GuestViewManager::ForEachGuest(WebContents* owner_web_contents,
return false; return false;
} }
WebContents* GuestViewManager::GetFullPageGuest(
WebContents* embedder_web_contents) {
WebContents* result = nullptr;
ForEachGuest(embedder_web_contents,
base::Bind(&GuestViewManager::GetFullPageGuestHelper, &result));
return result;
}
void GuestViewManager::AddGuest(int guest_instance_id, void GuestViewManager::AddGuest(int guest_instance_id,
WebContents* guest_web_contents) { WebContents* guest_web_contents) {
CHECK(!ContainsKey(guest_web_contents_by_instance_id_, guest_instance_id)); CHECK(!ContainsKey(guest_web_contents_by_instance_id_, guest_instance_id));
...@@ -285,6 +293,18 @@ bool GuestViewManager::CanUseGuestInstanceID(int guest_instance_id) { ...@@ -285,6 +293,18 @@ bool GuestViewManager::CanUseGuestInstanceID(int guest_instance_id) {
return !ContainsKey(removed_instance_ids_, guest_instance_id); return !ContainsKey(removed_instance_ids_, guest_instance_id);
} }
// static
bool GuestViewManager::GetFullPageGuestHelper(
content::WebContents** result,
content::WebContents* guest_web_contents) {
auto guest_view = GuestViewBase::FromWebContents(guest_web_contents);
if (guest_view && guest_view->is_full_page_plugin()) {
*result = guest_web_contents;
return true;
}
return false;
}
bool GuestViewManager::CanEmbedderAccessInstanceID( bool GuestViewManager::CanEmbedderAccessInstanceID(
int embedder_render_process_id, int embedder_render_process_id,
int guest_instance_id) { int guest_instance_id) {
......
...@@ -92,6 +92,8 @@ class GuestViewManager : public content::BrowserPluginGuestManager, ...@@ -92,6 +92,8 @@ class GuestViewManager : public content::BrowserPluginGuestManager,
int element_instance_id) override; int element_instance_id) override;
bool ForEachGuest(content::WebContents* owner_web_contents, bool ForEachGuest(content::WebContents* owner_web_contents,
const GuestCallback& callback) override; const GuestCallback& callback) override;
content::WebContents* GetFullPageGuest(
content::WebContents* embedder_web_contents) override;
protected: protected:
friend class GuestViewBase; friend class GuestViewBase;
...@@ -124,6 +126,9 @@ class GuestViewManager : public content::BrowserPluginGuestManager, ...@@ -124,6 +126,9 @@ class GuestViewManager : public content::BrowserPluginGuestManager,
// from this manager using RemoveGuest. // from this manager using RemoveGuest.
bool CanUseGuestInstanceID(int guest_instance_id); bool CanUseGuestInstanceID(int guest_instance_id);
static bool GetFullPageGuestHelper(content::WebContents** result,
content::WebContents* guest_web_contents);
// Static factory instance (always NULL for non-test). // Static factory instance (always NULL for non-test).
static GuestViewManagerFactory* factory_; static GuestViewManagerFactory* factory_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment