OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/renderer/renderer_webkitplatformsupport_impl.h" | 5 #include "content/renderer/renderer_webkitplatformsupport_impl.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
(...skipping 21 matching lines...) Expand all Loading... |
32 #include "content/renderer/render_thread_impl.h" | 32 #include "content/renderer/render_thread_impl.h" |
33 #include "content/renderer/renderer_clipboard_client.h" | 33 #include "content/renderer/renderer_clipboard_client.h" |
34 #include "content/renderer/websharedworkerrepository_impl.h" | 34 #include "content/renderer/websharedworkerrepository_impl.h" |
35 #include "googleurl/src/gurl.h" | 35 #include "googleurl/src/gurl.h" |
36 #include "ipc/ipc_sync_message_filter.h" | 36 #include "ipc/ipc_sync_message_filter.h" |
37 #include "media/audio/audio_output_device.h" | 37 #include "media/audio/audio_output_device.h" |
38 #include "media/base/audio_hardware_config.h" | 38 #include "media/base/audio_hardware_config.h" |
39 #include "third_party/WebKit/Source/Platform/chromium/public/WebBlobRegistry.h" | 39 #include "third_party/WebKit/Source/Platform/chromium/public/WebBlobRegistry.h" |
40 #include "third_party/WebKit/Source/Platform/chromium/public/WebFileInfo.h" | 40 #include "third_party/WebKit/Source/Platform/chromium/public/WebFileInfo.h" |
41 #include "third_party/WebKit/Source/Platform/chromium/public/WebGamepads.h" | 41 #include "third_party/WebKit/Source/Platform/chromium/public/WebGamepads.h" |
| 42 #include "third_party/WebKit/Source/Platform/chromium/public/WebHyphenator.h" |
42 #include "third_party/WebKit/Source/Platform/chromium/public/WebMediaStreamCente
r.h" | 43 #include "third_party/WebKit/Source/Platform/chromium/public/WebMediaStreamCente
r.h" |
43 #include "third_party/WebKit/Source/Platform/chromium/public/WebMediaStreamCente
rClient.h" | 44 #include "third_party/WebKit/Source/Platform/chromium/public/WebMediaStreamCente
rClient.h" |
44 #include "third_party/WebKit/Source/Platform/chromium/public/WebURL.h" | 45 #include "third_party/WebKit/Source/Platform/chromium/public/WebURL.h" |
45 #include "third_party/WebKit/Source/Platform/chromium/public/WebVector.h" | 46 #include "third_party/WebKit/Source/Platform/chromium/public/WebVector.h" |
46 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 47 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
47 #include "third_party/WebKit/Source/WebKit/chromium/public/WebRuntimeFeatures.h" | 48 #include "third_party/WebKit/Source/WebKit/chromium/public/WebRuntimeFeatures.h" |
48 #include "webkit/base/file_path_string_conversions.h" | 49 #include "webkit/base/file_path_string_conversions.h" |
49 #include "webkit/glue/simple_webmimeregistry_impl.h" | 50 #include "webkit/glue/simple_webmimeregistry_impl.h" |
50 #include "webkit/glue/webclipboard_impl.h" | 51 #include "webkit/glue/webclipboard_impl.h" |
51 #include "webkit/glue/webfileutilities_impl.h" | 52 #include "webkit/glue/webfileutilities_impl.h" |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 }; | 112 }; |
112 | 113 |
113 class RendererWebKitPlatformSupportImpl::FileUtilities | 114 class RendererWebKitPlatformSupportImpl::FileUtilities |
114 : public webkit_glue::WebFileUtilitiesImpl { | 115 : public webkit_glue::WebFileUtilitiesImpl { |
115 public: | 116 public: |
116 virtual bool getFileInfo(const WebString& path, WebFileInfo& result); | 117 virtual bool getFileInfo(const WebString& path, WebFileInfo& result); |
117 virtual base::PlatformFile openFile(const WebKit::WebString& path, | 118 virtual base::PlatformFile openFile(const WebKit::WebString& path, |
118 int mode); | 119 int mode); |
119 }; | 120 }; |
120 | 121 |
| 122 class RendererWebKitPlatformSupportImpl::Hyphenator |
| 123 : public WebKit::WebHyphenator { |
| 124 public: |
| 125 Hyphenator(); |
| 126 virtual ~Hyphenator(); |
| 127 |
| 128 virtual bool canHyphenate(const WebKit::WebString& locale) OVERRIDE; |
| 129 virtual size_t computeLastHyphenLocation( |
| 130 const char16* characters, |
| 131 size_t length, |
| 132 size_t before_index, |
| 133 const WebKit::WebString& locale) OVERRIDE; |
| 134 private: |
| 135 scoped_ptr<content::Hyphenator> hyphenator_; |
| 136 |
| 137 DISALLOW_COPY_AND_ASSIGN(Hyphenator); |
| 138 }; |
| 139 |
121 #if defined(OS_ANDROID) | 140 #if defined(OS_ANDROID) |
122 // WebKit doesn't use WebSandboxSupport on android so we don't need to | 141 // WebKit doesn't use WebSandboxSupport on android so we don't need to |
123 // implement anything here. | 142 // implement anything here. |
124 class RendererWebKitPlatformSupportImpl::SandboxSupport { | 143 class RendererWebKitPlatformSupportImpl::SandboxSupport { |
125 }; | 144 }; |
126 #else | 145 #else |
127 class RendererWebKitPlatformSupportImpl::SandboxSupport | 146 class RendererWebKitPlatformSupportImpl::SandboxSupport |
128 : public WebKit::WebSandboxSupport { | 147 : public WebKit::WebSandboxSupport { |
129 public: | 148 public: |
130 virtual ~SandboxSupport() {} | 149 virtual ~SandboxSupport() {} |
(...skipping 24 matching lines...) Expand all Loading... |
155 #endif | 174 #endif |
156 }; | 175 }; |
157 #endif // defined(OS_ANDROID) | 176 #endif // defined(OS_ANDROID) |
158 | 177 |
159 //------------------------------------------------------------------------------ | 178 //------------------------------------------------------------------------------ |
160 | 179 |
161 RendererWebKitPlatformSupportImpl::RendererWebKitPlatformSupportImpl() | 180 RendererWebKitPlatformSupportImpl::RendererWebKitPlatformSupportImpl() |
162 : clipboard_client_(new RendererClipboardClient), | 181 : clipboard_client_(new RendererClipboardClient), |
163 clipboard_(new webkit_glue::WebClipboardImpl(clipboard_client_.get())), | 182 clipboard_(new webkit_glue::WebClipboardImpl(clipboard_client_.get())), |
164 mime_registry_(new RendererWebKitPlatformSupportImpl::MimeRegistry), | 183 mime_registry_(new RendererWebKitPlatformSupportImpl::MimeRegistry), |
| 184 hyphenator_(new RendererWebKitPlatformSupportImpl::Hyphenator), |
165 sudden_termination_disables_(0), | 185 sudden_termination_disables_(0), |
166 plugin_refresh_allowed_(true), | 186 plugin_refresh_allowed_(true), |
167 shared_worker_repository_(new WebSharedWorkerRepositoryImpl) { | 187 shared_worker_repository_(new WebSharedWorkerRepositoryImpl) { |
168 if (g_sandbox_enabled && sandboxEnabled()) { | 188 if (g_sandbox_enabled && sandboxEnabled()) { |
169 sandbox_support_.reset( | 189 sandbox_support_.reset( |
170 new RendererWebKitPlatformSupportImpl::SandboxSupport); | 190 new RendererWebKitPlatformSupportImpl::SandboxSupport); |
171 } else { | 191 } else { |
172 DVLOG(1) << "Disabling sandbox support for testing."; | 192 DVLOG(1) << "Disabling sandbox support for testing."; |
173 } | 193 } |
174 } | 194 } |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
418 const WebString& path, | 438 const WebString& path, |
419 int mode) { | 439 int mode) { |
420 IPC::PlatformFileForTransit handle = IPC::InvalidPlatformFileForTransit(); | 440 IPC::PlatformFileForTransit handle = IPC::InvalidPlatformFileForTransit(); |
421 SendSyncMessageFromAnyThread(new FileUtilitiesMsg_OpenFile( | 441 SendSyncMessageFromAnyThread(new FileUtilitiesMsg_OpenFile( |
422 webkit_base::WebStringToFilePath(path), mode, &handle)); | 442 webkit_base::WebStringToFilePath(path), mode, &handle)); |
423 return IPC::PlatformFileForTransitToPlatformFile(handle); | 443 return IPC::PlatformFileForTransitToPlatformFile(handle); |
424 } | 444 } |
425 | 445 |
426 //------------------------------------------------------------------------------ | 446 //------------------------------------------------------------------------------ |
427 | 447 |
| 448 RendererWebKitPlatformSupportImpl::Hyphenator::Hyphenator() {} |
| 449 |
| 450 RendererWebKitPlatformSupportImpl::Hyphenator::~Hyphenator() {} |
| 451 |
| 452 bool RendererWebKitPlatformSupportImpl::Hyphenator::canHyphenate( |
| 453 const WebKit::WebString& locale) { |
| 454 // Return false unless WebKit asks for US English dictionaries because WebKit |
| 455 // can currently hyphenate only English words. |
| 456 if (!locale.isEmpty() && !locale.equals("en-US")) |
| 457 return false; |
| 458 |
| 459 // Create a hyphenator object and attach it to the render thread so it can |
| 460 // receive a dictionary file opened by a browser. |
| 461 if (!hyphenator_.get()) { |
| 462 hyphenator_.reset(new content::Hyphenator(base::kInvalidPlatformFileValue)); |
| 463 if (!hyphenator_.get()) |
| 464 return false; |
| 465 return hyphenator_->Attach(RenderThreadImpl::current(), locale); |
| 466 } |
| 467 return hyphenator_->CanHyphenate(locale); |
| 468 } |
| 469 |
| 470 size_t RendererWebKitPlatformSupportImpl::Hyphenator::computeLastHyphenLocation( |
| 471 const char16* characters, |
| 472 size_t length, |
| 473 size_t before_index, |
| 474 const WebKit::WebString& locale) { |
| 475 // Crash if WebKit calls this function when canHyphenate returns false. |
| 476 DCHECK(locale.isEmpty() || locale.equals("en-US")); |
| 477 DCHECK(hyphenator_.get()); |
| 478 return hyphenator_->ComputeLastHyphenLocation(string16(characters, length), |
| 479 before_index); |
| 480 } |
| 481 |
| 482 //------------------------------------------------------------------------------ |
| 483 |
428 #if defined(OS_WIN) | 484 #if defined(OS_WIN) |
429 | 485 |
430 bool RendererWebKitPlatformSupportImpl::SandboxSupport::ensureFontLoaded( | 486 bool RendererWebKitPlatformSupportImpl::SandboxSupport::ensureFontLoaded( |
431 HFONT font) { | 487 HFONT font) { |
432 LOGFONT logfont; | 488 LOGFONT logfont; |
433 GetObject(font, sizeof(LOGFONT), &logfont); | 489 GetObject(font, sizeof(LOGFONT), &logfont); |
434 RenderThread::Get()->PreCacheFont(logfont); | 490 RenderThread::Get()->PreCacheFont(logfont); |
435 return true; | 491 return true; |
436 } | 492 } |
437 | 493 |
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
767 g_test_gamepads.Get() = pads; | 823 g_test_gamepads.Get() = pads; |
768 } | 824 } |
769 | 825 |
770 GpuChannelHostFactory* | 826 GpuChannelHostFactory* |
771 RendererWebKitPlatformSupportImpl::GetGpuChannelHostFactory() { | 827 RendererWebKitPlatformSupportImpl::GetGpuChannelHostFactory() { |
772 return RenderThreadImpl::current(); | 828 return RenderThreadImpl::current(); |
773 } | 829 } |
774 | 830 |
775 //------------------------------------------------------------------------------ | 831 //------------------------------------------------------------------------------ |
776 | 832 |
| 833 WebKit::WebHyphenator* RendererWebKitPlatformSupportImpl::hyphenator() { |
| 834 WebKit::WebHyphenator* hyphenator = |
| 835 GetContentClient()->renderer()->OverrideWebHyphenator(); |
| 836 if (hyphenator) |
| 837 return hyphenator; |
| 838 return hyphenator_.get(); |
| 839 } |
| 840 |
777 bool RendererWebKitPlatformSupportImpl::canHyphenate( | 841 bool RendererWebKitPlatformSupportImpl::canHyphenate( |
778 const WebKit::WebString& locale) { | 842 const WebKit::WebString& locale) { |
779 // Return false unless WebKit asks for US English dictionaries because WebKit | 843 return hyphenator()->canHyphenate(locale); |
780 // can currently hyphenate only English words. | |
781 if (!locale.isEmpty() && !locale.equals("en-US")) | |
782 return false; | |
783 | |
784 // Create a hyphenator object and attach it to the render thread so it can | |
785 // receive a dictionary file opened by a browser. | |
786 if (!hyphenator_.get()) { | |
787 hyphenator_.reset(new Hyphenator(base::kInvalidPlatformFileValue)); | |
788 if (!hyphenator_.get()) | |
789 return false; | |
790 return hyphenator_->Attach(RenderThreadImpl::current(), locale); | |
791 } | |
792 return hyphenator_->CanHyphenate(locale); | |
793 } | 844 } |
794 | 845 |
795 size_t RendererWebKitPlatformSupportImpl::computeLastHyphenLocation( | 846 size_t RendererWebKitPlatformSupportImpl::computeLastHyphenLocation( |
796 const char16* characters, | 847 const char16* characters, |
797 size_t length, | 848 size_t length, |
798 size_t before_index, | 849 size_t before_index, |
799 const WebKit::WebString& locale) { | 850 const WebKit::WebString& locale) { |
800 // Crash if WebKit calls this function when canHyphenate returns false. | 851 return hyphenator()->computeLastHyphenLocation( |
801 DCHECK(locale.isEmpty() || locale.equals("en-US")); | 852 characters, length, before_index, locale); |
802 DCHECK(hyphenator_.get()); | |
803 return hyphenator_->ComputeLastHyphenLocation(string16(characters, length), | |
804 before_index); | |
805 } | 853 } |
806 | 854 |
807 //------------------------------------------------------------------------------ | 855 //------------------------------------------------------------------------------ |
808 | 856 |
809 bool RendererWebKitPlatformSupportImpl::processMemorySizesInBytes( | 857 bool RendererWebKitPlatformSupportImpl::processMemorySizesInBytes( |
810 size_t* private_bytes, size_t* shared_bytes) { | 858 size_t* private_bytes, size_t* shared_bytes) { |
811 content::RenderThread::Get()->Send( | 859 content::RenderThread::Get()->Send( |
812 new ViewHostMsg_GetProcessMemorySizes(private_bytes, shared_bytes)); | 860 new ViewHostMsg_GetProcessMemorySizes(private_bytes, shared_bytes)); |
813 return true; | 861 return true; |
814 } | 862 } |
815 | 863 |
816 } // namespace content | 864 } // namespace content |
OLD | NEW |