summaryrefslogtreecommitdiffstats
path: root/content/renderer
diff options
context:
space:
mode:
authorjochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-03-01 07:48:07 +0000
committerjochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-03-01 07:48:07 +0000
commitea315d056841c6ea0f30f17b2e61ce930c1c5ccd (patch)
tree1c44dc5e0e5810cd949a0c276bab437ab3add79a /content/renderer
parent9b2608479f2cca81e90ab4ab91ddae2fe9a0723c (diff)
downloadchromium_src-ea315d056841c6ea0f30f17b2e61ce930c1c5ccd.zip
chromium_src-ea315d056841c6ea0f30f17b2e61ce930c1c5ccd.tar.gz
chromium_src-ea315d056841c6ea0f30f17b2e61ce930c1c5ccd.tar.bz2
Switch from using individual methods for hyphenation to using the WebHyphantor interface
Also allow the content embedder to override the hyphenator used. BUG=178693 Review URL: https://codereview.chromium.org/12335128 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@185486 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/renderer')
-rw-r--r--content/renderer/renderer_webkitplatformsupport_impl.cc86
-rw-r--r--content/renderer/renderer_webkitplatformsupport_impl.h7
2 files changed, 71 insertions, 22 deletions
diff --git a/content/renderer/renderer_webkitplatformsupport_impl.cc b/content/renderer/renderer_webkitplatformsupport_impl.cc
index 3f88b32..14e9fab 100644
--- a/content/renderer/renderer_webkitplatformsupport_impl.cc
+++ b/content/renderer/renderer_webkitplatformsupport_impl.cc
@@ -39,6 +39,7 @@
#include "third_party/WebKit/Source/Platform/chromium/public/WebBlobRegistry.h"
#include "third_party/WebKit/Source/Platform/chromium/public/WebFileInfo.h"
#include "third_party/WebKit/Source/Platform/chromium/public/WebGamepads.h"
+#include "third_party/WebKit/Source/Platform/chromium/public/WebHyphenator.h"
#include "third_party/WebKit/Source/Platform/chromium/public/WebMediaStreamCenter.h"
#include "third_party/WebKit/Source/Platform/chromium/public/WebMediaStreamCenterClient.h"
#include "third_party/WebKit/Source/Platform/chromium/public/WebURL.h"
@@ -118,6 +119,24 @@ class RendererWebKitPlatformSupportImpl::FileUtilities
int mode);
};
+class RendererWebKitPlatformSupportImpl::Hyphenator
+ : public WebKit::WebHyphenator {
+ public:
+ Hyphenator();
+ virtual ~Hyphenator();
+
+ virtual bool canHyphenate(const WebKit::WebString& locale) OVERRIDE;
+ virtual size_t computeLastHyphenLocation(
+ const char16* characters,
+ size_t length,
+ size_t before_index,
+ const WebKit::WebString& locale) OVERRIDE;
+ private:
+ scoped_ptr<content::Hyphenator> hyphenator_;
+
+ DISALLOW_COPY_AND_ASSIGN(Hyphenator);
+};
+
#if defined(OS_ANDROID)
// WebKit doesn't use WebSandboxSupport on android so we don't need to
// implement anything here.
@@ -162,6 +181,7 @@ RendererWebKitPlatformSupportImpl::RendererWebKitPlatformSupportImpl()
: clipboard_client_(new RendererClipboardClient),
clipboard_(new webkit_glue::WebClipboardImpl(clipboard_client_.get())),
mime_registry_(new RendererWebKitPlatformSupportImpl::MimeRegistry),
+ hyphenator_(new RendererWebKitPlatformSupportImpl::Hyphenator),
sudden_termination_disables_(0),
plugin_refresh_allowed_(true),
shared_worker_repository_(new WebSharedWorkerRepositoryImpl) {
@@ -429,6 +449,42 @@ base::PlatformFile RendererWebKitPlatformSupportImpl::FileUtilities::openFile(
//------------------------------------------------------------------------------
+RendererWebKitPlatformSupportImpl::Hyphenator::Hyphenator() {}
+
+RendererWebKitPlatformSupportImpl::Hyphenator::~Hyphenator() {}
+
+bool RendererWebKitPlatformSupportImpl::Hyphenator::canHyphenate(
+ const WebKit::WebString& locale) {
+ // Return false unless WebKit asks for US English dictionaries because WebKit
+ // can currently hyphenate only English words.
+ if (!locale.isEmpty() && !locale.equals("en-US"))
+ return false;
+
+ // Create a hyphenator object and attach it to the render thread so it can
+ // receive a dictionary file opened by a browser.
+ if (!hyphenator_.get()) {
+ hyphenator_.reset(new content::Hyphenator(base::kInvalidPlatformFileValue));
+ if (!hyphenator_.get())
+ return false;
+ return hyphenator_->Attach(RenderThreadImpl::current(), locale);
+ }
+ return hyphenator_->CanHyphenate(locale);
+}
+
+size_t RendererWebKitPlatformSupportImpl::Hyphenator::computeLastHyphenLocation(
+ const char16* characters,
+ size_t length,
+ size_t before_index,
+ const WebKit::WebString& locale) {
+ // Crash if WebKit calls this function when canHyphenate returns false.
+ DCHECK(locale.isEmpty() || locale.equals("en-US"));
+ DCHECK(hyphenator_.get());
+ return hyphenator_->ComputeLastHyphenLocation(string16(characters, length),
+ before_index);
+}
+
+//------------------------------------------------------------------------------
+
#if defined(OS_WIN)
bool RendererWebKitPlatformSupportImpl::SandboxSupport::ensureFontLoaded(
@@ -778,22 +834,17 @@ RendererWebKitPlatformSupportImpl::GetGpuChannelHostFactory() {
//------------------------------------------------------------------------------
+WebKit::WebHyphenator* RendererWebKitPlatformSupportImpl::hyphenator() {
+ WebKit::WebHyphenator* hyphenator =
+ GetContentClient()->renderer()->OverrideWebHyphenator();
+ if (hyphenator)
+ return hyphenator;
+ return hyphenator_.get();
+}
+
bool RendererWebKitPlatformSupportImpl::canHyphenate(
const WebKit::WebString& locale) {
- // Return false unless WebKit asks for US English dictionaries because WebKit
- // can currently hyphenate only English words.
- if (!locale.isEmpty() && !locale.equals("en-US"))
- return false;
-
- // Create a hyphenator object and attach it to the render thread so it can
- // receive a dictionary file opened by a browser.
- if (!hyphenator_.get()) {
- hyphenator_.reset(new Hyphenator(base::kInvalidPlatformFileValue));
- if (!hyphenator_.get())
- return false;
- return hyphenator_->Attach(RenderThreadImpl::current(), locale);
- }
- return hyphenator_->CanHyphenate(locale);
+ return hyphenator()->canHyphenate(locale);
}
size_t RendererWebKitPlatformSupportImpl::computeLastHyphenLocation(
@@ -801,11 +852,8 @@ size_t RendererWebKitPlatformSupportImpl::computeLastHyphenLocation(
size_t length,
size_t before_index,
const WebKit::WebString& locale) {
- // Crash if WebKit calls this function when canHyphenate returns false.
- DCHECK(locale.isEmpty() || locale.equals("en-US"));
- DCHECK(hyphenator_.get());
- return hyphenator_->ComputeLastHyphenLocation(string16(characters, length),
- before_index);
+ return hyphenator()->computeLastHyphenLocation(
+ characters, length, before_index, locale);
}
//------------------------------------------------------------------------------
diff --git a/content/renderer/renderer_webkitplatformsupport_impl.h b/content/renderer/renderer_webkitplatformsupport_impl.h
index d3c415f..2bfef45 100644
--- a/content/renderer/renderer_webkitplatformsupport_impl.h
+++ b/content/renderer/renderer_webkitplatformsupport_impl.h
@@ -20,7 +20,6 @@ class WebClipboardImpl;
namespace content {
class GamepadSharedMemoryReader;
-class Hyphenator;
class RendererClipboardClient;
class WebFileSystemImpl;
class WebSharedWorkerRepositoryImpl;
@@ -40,6 +39,7 @@ class CONTENT_EXPORT RendererWebKitPlatformSupportImpl
virtual WebKit::WebFileUtilities* fileUtilities();
virtual WebKit::WebSandboxSupport* sandboxSupport();
virtual WebKit::WebCookieJar* cookieJar();
+ virtual WebKit::WebHyphenator* hyphenator();
virtual bool sandboxEnabled();
virtual unsigned long long visitedLinkHash(
const char* canonicalURL, size_t length);
@@ -135,6 +135,9 @@ class CONTENT_EXPORT RendererWebKitPlatformSupportImpl
class SandboxSupport;
scoped_ptr<SandboxSupport> sandbox_support_;
+ class Hyphenator;
+ scoped_ptr<Hyphenator> hyphenator_;
+
// This counter keeps track of the number of times sudden termination is
// enabled or disabled. It starts at 0 (enabled) and for every disable
// increments by 1, for every enable decrements by 1. When it reaches 0,
@@ -155,8 +158,6 @@ class CONTENT_EXPORT RendererWebKitPlatformSupportImpl
scoped_ptr<WebKit::WebBlobRegistry> blob_registry_;
scoped_ptr<GamepadSharedMemoryReader> gamepad_shared_memory_reader_;
-
- scoped_ptr<content::Hyphenator> hyphenator_;
};
} // namespace content