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_path.h" | 8 #include "base/file_path.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
160 }; | 160 }; |
161 #endif // defined(OS_ANDROID) | 161 #endif // defined(OS_ANDROID) |
162 | 162 |
163 //------------------------------------------------------------------------------ | 163 //------------------------------------------------------------------------------ |
164 | 164 |
165 RendererWebKitPlatformSupportImpl::RendererWebKitPlatformSupportImpl() | 165 RendererWebKitPlatformSupportImpl::RendererWebKitPlatformSupportImpl() |
166 : clipboard_client_(new RendererClipboardClient), | 166 : clipboard_client_(new RendererClipboardClient), |
167 clipboard_(new webkit_glue::WebClipboardImpl(clipboard_client_.get())), | 167 clipboard_(new webkit_glue::WebClipboardImpl(clipboard_client_.get())), |
168 mime_registry_(new RendererWebKitPlatformSupportImpl::MimeRegistry), | 168 mime_registry_(new RendererWebKitPlatformSupportImpl::MimeRegistry), |
169 sudden_termination_disables_(0), | 169 sudden_termination_disables_(0), |
170 plugin_refresh_allowed_(true), | |
170 shared_worker_repository_(new WebSharedWorkerRepositoryImpl) { | 171 shared_worker_repository_(new WebSharedWorkerRepositoryImpl) { |
171 if (g_sandbox_enabled) { | 172 if (g_sandbox_enabled) { |
172 sandbox_support_.reset( | 173 sandbox_support_.reset( |
173 new RendererWebKitPlatformSupportImpl::SandboxSupport); | 174 new RendererWebKitPlatformSupportImpl::SandboxSupport); |
174 } else { | 175 } else { |
175 DVLOG(1) << "Disabling sandbox support for testing."; | 176 DVLOG(1) << "Disabling sandbox support for testing."; |
176 } | 177 } |
177 } | 178 } |
178 | 179 |
179 RendererWebKitPlatformSupportImpl::~RendererWebKitPlatformSupportImpl() { | 180 RendererWebKitPlatformSupportImpl::~RendererWebKitPlatformSupportImpl() { |
180 } | 181 } |
181 | 182 |
182 //------------------------------------------------------------------------------ | 183 //------------------------------------------------------------------------------ |
183 | 184 |
184 namespace { | 185 namespace { |
185 | 186 |
186 bool SendSyncMessageFromAnyThreadInternal(IPC::SyncMessage* msg) { | 187 bool SendSyncMessageFromAnyThreadInternal(IPC::SyncMessage* msg) { |
187 RenderThreadImpl* render_thread = RenderThreadImpl::current(); | 188 content::RenderThread* render_thread = content::RenderThread::Get(); |
jam
2012/07/31 20:05:07
nit: just do a "using content::RenderThread" at th
Fady Samuel
2012/07/31 20:20:59
Done.
| |
188 if (render_thread) | 189 if (render_thread) |
189 return render_thread->Send(msg); | 190 return render_thread->Send(msg); |
190 scoped_refptr<IPC::SyncMessageFilter> sync_msg_filter( | 191 scoped_refptr<IPC::SyncMessageFilter> sync_msg_filter( |
191 ChildThread::current()->sync_message_filter()); | 192 ChildThread::current()->sync_message_filter()); |
192 return sync_msg_filter->Send(msg); | 193 return sync_msg_filter->Send(msg); |
193 } | 194 } |
194 | 195 |
195 bool SendSyncMessageFromAnyThread(IPC::SyncMessage* msg) { | 196 bool SendSyncMessageFromAnyThread(IPC::SyncMessage* msg) { |
196 base::TimeTicks begin = base::TimeTicks::Now(); | 197 base::TimeTicks begin = base::TimeTicks::Now(); |
197 const bool success = SendSyncMessageFromAnyThreadInternal(msg); | 198 const bool success = SendSyncMessageFromAnyThreadInternal(msg); |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
289 double response_time, | 290 double response_time, |
290 const char* data, | 291 const char* data, |
291 size_t size) { | 292 size_t size) { |
292 if (!CheckPreparsedJsCachingEnabled()) | 293 if (!CheckPreparsedJsCachingEnabled()) |
293 return; | 294 return; |
294 | 295 |
295 // Let the browser know we generated cacheable metadata for this resource. The | 296 // Let the browser know we generated cacheable metadata for this resource. The |
296 // browser may cache it and return it on subsequent responses to speed | 297 // browser may cache it and return it on subsequent responses to speed |
297 // the processing of this resource. | 298 // the processing of this resource. |
298 std::vector<char> copy(data, data + size); | 299 std::vector<char> copy(data, data + size); |
299 RenderThreadImpl::current()->Send( | 300 content::RenderThread::Get()->Send( |
300 new ViewHostMsg_DidGenerateCacheableMetadata(url, response_time, copy)); | 301 new ViewHostMsg_DidGenerateCacheableMetadata(url, response_time, copy)); |
301 } | 302 } |
302 | 303 |
303 WebString RendererWebKitPlatformSupportImpl::defaultLocale() { | 304 WebString RendererWebKitPlatformSupportImpl::defaultLocale() { |
304 return ASCIIToUTF16(RenderThreadImpl::Get()->GetLocale()); | 305 return ASCIIToUTF16(content::RenderThread::Get()->GetLocale()); |
305 } | 306 } |
306 | 307 |
307 void RendererWebKitPlatformSupportImpl::suddenTerminationChanged(bool enabled) { | 308 void RendererWebKitPlatformSupportImpl::suddenTerminationChanged(bool enabled) { |
308 if (enabled) { | 309 if (enabled) { |
309 // We should not get more enables than disables, but we want it to be a | 310 // We should not get more enables than disables, but we want it to be a |
310 // non-fatal error if it does happen. | 311 // non-fatal error if it does happen. |
311 DCHECK_GT(sudden_termination_disables_, 0); | 312 DCHECK_GT(sudden_termination_disables_, 0); |
312 sudden_termination_disables_ = std::max(sudden_termination_disables_ - 1, | 313 sudden_termination_disables_ = std::max(sudden_termination_disables_ - 1, |
313 0); | 314 0); |
314 if (sudden_termination_disables_ != 0) | 315 if (sudden_termination_disables_ != 0) |
315 return; | 316 return; |
316 } else { | 317 } else { |
317 sudden_termination_disables_++; | 318 sudden_termination_disables_++; |
318 if (sudden_termination_disables_ != 1) | 319 if (sudden_termination_disables_ != 1) |
319 return; | 320 return; |
320 } | 321 } |
321 | 322 |
322 RenderThreadImpl* thread = RenderThreadImpl::current(); | 323 content::RenderThread* thread = content::RenderThread::Get(); |
323 if (thread) // NULL in unittests. | 324 if (thread) // NULL in unittests. |
324 thread->Send(new ViewHostMsg_SuddenTerminationChanged(enabled)); | 325 thread->Send(new ViewHostMsg_SuddenTerminationChanged(enabled)); |
325 } | 326 } |
326 | 327 |
327 WebStorageNamespace* | 328 WebStorageNamespace* |
328 RendererWebKitPlatformSupportImpl::createLocalStorageNamespace( | 329 RendererWebKitPlatformSupportImpl::createLocalStorageNamespace( |
329 const WebString& path, unsigned quota) { | 330 const WebString& path, unsigned quota) { |
330 return new WebStorageNamespaceImpl(); | 331 return new WebStorageNamespaceImpl(); |
331 } | 332 } |
332 | 333 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
378 | 379 |
379 WebString | 380 WebString |
380 RendererWebKitPlatformSupportImpl::MimeRegistry::mimeTypeForExtension( | 381 RendererWebKitPlatformSupportImpl::MimeRegistry::mimeTypeForExtension( |
381 const WebString& file_extension) { | 382 const WebString& file_extension) { |
382 if (IsPluginProcess()) | 383 if (IsPluginProcess()) |
383 return SimpleWebMimeRegistryImpl::mimeTypeForExtension(file_extension); | 384 return SimpleWebMimeRegistryImpl::mimeTypeForExtension(file_extension); |
384 | 385 |
385 // The sandbox restricts our access to the registry, so we need to proxy | 386 // The sandbox restricts our access to the registry, so we need to proxy |
386 // these calls over to the browser process. | 387 // these calls over to the browser process. |
387 std::string mime_type; | 388 std::string mime_type; |
388 RenderThreadImpl::current()->Send( | 389 content::RenderThread::Get()->Send( |
389 new MimeRegistryMsg_GetMimeTypeFromExtension( | 390 new MimeRegistryMsg_GetMimeTypeFromExtension( |
390 webkit_glue::WebStringToFilePathString(file_extension), &mime_type)); | 391 webkit_glue::WebStringToFilePathString(file_extension), &mime_type)); |
391 return ASCIIToUTF16(mime_type); | 392 return ASCIIToUTF16(mime_type); |
392 | 393 |
393 } | 394 } |
394 | 395 |
395 WebString RendererWebKitPlatformSupportImpl::MimeRegistry::mimeTypeFromFile( | 396 WebString RendererWebKitPlatformSupportImpl::MimeRegistry::mimeTypeFromFile( |
396 const WebString& file_path) { | 397 const WebString& file_path) { |
397 if (IsPluginProcess()) | 398 if (IsPluginProcess()) |
398 return SimpleWebMimeRegistryImpl::mimeTypeFromFile(file_path); | 399 return SimpleWebMimeRegistryImpl::mimeTypeFromFile(file_path); |
399 | 400 |
400 // The sandbox restricts our access to the registry, so we need to proxy | 401 // The sandbox restricts our access to the registry, so we need to proxy |
401 // these calls over to the browser process. | 402 // these calls over to the browser process. |
402 std::string mime_type; | 403 std::string mime_type; |
403 RenderThreadImpl::current()->Send(new MimeRegistryMsg_GetMimeTypeFromFile( | 404 content::RenderThread::Get()->Send(new MimeRegistryMsg_GetMimeTypeFromFile( |
404 FilePath(webkit_glue::WebStringToFilePathString(file_path)), | 405 FilePath(webkit_glue::WebStringToFilePathString(file_path)), |
405 &mime_type)); | 406 &mime_type)); |
406 return ASCIIToUTF16(mime_type); | 407 return ASCIIToUTF16(mime_type); |
407 | 408 |
408 } | 409 } |
409 | 410 |
410 WebString | 411 WebString |
411 RendererWebKitPlatformSupportImpl::MimeRegistry::preferredExtensionForMIMEType( | 412 RendererWebKitPlatformSupportImpl::MimeRegistry::preferredExtensionForMIMEType( |
412 const WebString& mime_type) { | 413 const WebString& mime_type) { |
413 if (IsPluginProcess()) | 414 if (IsPluginProcess()) |
414 return SimpleWebMimeRegistryImpl::preferredExtensionForMIMEType(mime_type); | 415 return SimpleWebMimeRegistryImpl::preferredExtensionForMIMEType(mime_type); |
415 | 416 |
416 // The sandbox restricts our access to the registry, so we need to proxy | 417 // The sandbox restricts our access to the registry, so we need to proxy |
417 // these calls over to the browser process. | 418 // these calls over to the browser process. |
418 FilePath::StringType file_extension; | 419 FilePath::StringType file_extension; |
419 RenderThreadImpl::current()->Send( | 420 content::RenderThread::Get()->Send( |
420 new MimeRegistryMsg_GetPreferredExtensionForMimeType( | 421 new MimeRegistryMsg_GetPreferredExtensionForMimeType( |
421 UTF16ToASCII(mime_type), &file_extension)); | 422 UTF16ToASCII(mime_type), &file_extension)); |
422 return webkit_glue::FilePathStringToWebString(file_extension); | 423 return webkit_glue::FilePathStringToWebString(file_extension); |
423 } | 424 } |
424 | 425 |
425 //------------------------------------------------------------------------------ | 426 //------------------------------------------------------------------------------ |
426 | 427 |
427 bool RendererWebKitPlatformSupportImpl::FileUtilities::getFileInfo( | 428 bool RendererWebKitPlatformSupportImpl::FileUtilities::getFileInfo( |
428 const WebString& path, | 429 const WebString& path, |
429 WebFileInfo& web_file_info) { | 430 WebFileInfo& web_file_info) { |
(...skipping 19 matching lines...) Expand all Loading... | |
449 } | 450 } |
450 | 451 |
451 //------------------------------------------------------------------------------ | 452 //------------------------------------------------------------------------------ |
452 | 453 |
453 #if defined(OS_WIN) | 454 #if defined(OS_WIN) |
454 | 455 |
455 bool RendererWebKitPlatformSupportImpl::SandboxSupport::ensureFontLoaded( | 456 bool RendererWebKitPlatformSupportImpl::SandboxSupport::ensureFontLoaded( |
456 HFONT font) { | 457 HFONT font) { |
457 LOGFONT logfont; | 458 LOGFONT logfont; |
458 GetObject(font, sizeof(LOGFONT), &logfont); | 459 GetObject(font, sizeof(LOGFONT), &logfont); |
459 RenderThreadImpl::current()->PreCacheFont(logfont); | 460 content::RenderThread::Get()->PreCacheFont(logfont); |
460 return true; | 461 return true; |
461 } | 462 } |
462 | 463 |
463 #elif defined(OS_MACOSX) | 464 #elif defined(OS_MACOSX) |
464 | 465 |
465 bool RendererWebKitPlatformSupportImpl::SandboxSupport::loadFont( | 466 bool RendererWebKitPlatformSupportImpl::SandboxSupport::loadFont( |
466 NSFont* src_font, CGFontRef* out, uint32* font_id) { | 467 NSFont* src_font, CGFontRef* out, uint32* font_id) { |
467 uint32 font_data_size; | 468 uint32 font_data_size; |
468 FontDescriptor src_font_descriptor(src_font); | 469 FontDescriptor src_font_descriptor(src_font); |
469 base::SharedMemoryHandle font_data; | 470 base::SharedMemoryHandle font_data; |
470 if (!RenderThreadImpl::current()->Send(new ViewHostMsg_LoadFont( | 471 if (!content::RenderThread::Get()->Send(new ViewHostMsg_LoadFont( |
471 src_font_descriptor, &font_data_size, &font_data, font_id))) { | 472 src_font_descriptor, &font_data_size, &font_data, font_id))) { |
472 *out = NULL; | 473 *out = NULL; |
473 *font_id = 0; | 474 *font_id = 0; |
474 return false; | 475 return false; |
475 } | 476 } |
476 | 477 |
477 if (font_data_size == 0 || font_data == base::SharedMemory::NULLHandle() || | 478 if (font_data_size == 0 || font_data == base::SharedMemory::NULLHandle() || |
478 *font_id == 0) { | 479 *font_id == 0) { |
479 LOG(ERROR) << "Bad response from ViewHostMsg_LoadFont() for " << | 480 LOG(ERROR) << "Bad response from ViewHostMsg_LoadFont() for " << |
480 src_font_descriptor.font_name; | 481 src_font_descriptor.font_name; |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
563 RendererWebKitPlatformSupportImpl::sharedWorkerRepository() { | 564 RendererWebKitPlatformSupportImpl::sharedWorkerRepository() { |
564 if (!CommandLine::ForCurrentProcess()->HasSwitch( | 565 if (!CommandLine::ForCurrentProcess()->HasSwitch( |
565 switches::kDisableSharedWorkers)) { | 566 switches::kDisableSharedWorkers)) { |
566 return shared_worker_repository_.get(); | 567 return shared_worker_repository_.get(); |
567 } else { | 568 } else { |
568 return NULL; | 569 return NULL; |
569 } | 570 } |
570 } | 571 } |
571 | 572 |
572 bool RendererWebKitPlatformSupportImpl::canAccelerate2dCanvas() { | 573 bool RendererWebKitPlatformSupportImpl::canAccelerate2dCanvas() { |
573 RenderThreadImpl* thread = RenderThreadImpl::current(); | 574 RenderThreadImpl* thread = RenderThreadImpl::current(); |
jam
2012/07/31 20:05:07
what about here and the few usages below of Render
Fady Samuel
2012/07/31 20:20:59
Added TODOs.
| |
574 GpuChannelHost* host = thread->EstablishGpuChannelSync( | 575 GpuChannelHost* host = thread->EstablishGpuChannelSync( |
575 content::CAUSE_FOR_GPU_LAUNCH_CANVAS_2D); | 576 content::CAUSE_FOR_GPU_LAUNCH_CANVAS_2D); |
576 if (!host) | 577 if (!host) |
577 return false; | 578 return false; |
578 | 579 |
579 const content::GPUInfo& gpu_info = host->gpu_info(); | 580 const content::GPUInfo& gpu_info = host->gpu_info(); |
580 if (gpu_info.can_lose_context || gpu_info.software_rendering) | 581 if (gpu_info.can_lose_context || gpu_info.software_rendering) |
581 return false; | 582 return false; |
582 | 583 |
583 return true; | 584 return true; |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
641 } | 642 } |
642 | 643 |
643 //------------------------------------------------------------------------------ | 644 //------------------------------------------------------------------------------ |
644 | 645 |
645 WebKit::WebString | 646 WebKit::WebString |
646 RendererWebKitPlatformSupportImpl::signedPublicKeyAndChallengeString( | 647 RendererWebKitPlatformSupportImpl::signedPublicKeyAndChallengeString( |
647 unsigned key_size_index, | 648 unsigned key_size_index, |
648 const WebKit::WebString& challenge, | 649 const WebKit::WebString& challenge, |
649 const WebKit::WebURL& url) { | 650 const WebKit::WebURL& url) { |
650 std::string signed_public_key; | 651 std::string signed_public_key; |
651 RenderThreadImpl::current()->Send(new ViewHostMsg_Keygen( | 652 content::RenderThread::Get()->Send(new ViewHostMsg_Keygen( |
652 static_cast<uint32>(key_size_index), | 653 static_cast<uint32>(key_size_index), |
653 challenge.utf8(), | 654 challenge.utf8(), |
654 GURL(url), | 655 GURL(url), |
655 &signed_public_key)); | 656 &signed_public_key)); |
656 return WebString::fromUTF8(signed_public_key); | 657 return WebString::fromUTF8(signed_public_key); |
657 } | 658 } |
658 | 659 |
659 //------------------------------------------------------------------------------ | 660 //------------------------------------------------------------------------------ |
660 | 661 |
661 void RendererWebKitPlatformSupportImpl::screenColorProfile( | 662 void RendererWebKitPlatformSupportImpl::screenColorProfile( |
662 WebVector<char>* to_profile) { | 663 WebVector<char>* to_profile) { |
663 std::vector<char> profile; | 664 std::vector<char> profile; |
664 RenderThreadImpl::current()->Send( | 665 content::RenderThread::Get()->Send( |
665 new ViewHostMsg_GetMonitorColorProfile(&profile)); | 666 new ViewHostMsg_GetMonitorColorProfile(&profile)); |
666 *to_profile = profile; | 667 *to_profile = profile; |
667 } | 668 } |
668 | 669 |
669 //------------------------------------------------------------------------------ | 670 //------------------------------------------------------------------------------ |
670 | 671 |
671 WebBlobRegistry* RendererWebKitPlatformSupportImpl::blobRegistry() { | 672 WebBlobRegistry* RendererWebKitPlatformSupportImpl::blobRegistry() { |
672 // ChildThread::current can be NULL when running some tests. | 673 // ChildThread::current can be NULL when running some tests. |
673 if (!blob_registry_.get() && ChildThread::current()) { | 674 if (!blob_registry_.get() && ChildThread::current()) { |
674 blob_registry_.reset(new WebBlobRegistryImpl(ChildThread::current())); | 675 blob_registry_.reset(new WebBlobRegistryImpl(ChildThread::current())); |
675 } | 676 } |
676 return blob_registry_.get(); | 677 return blob_registry_.get(); |
677 } | 678 } |
678 | 679 |
679 //------------------------------------------------------------------------------ | 680 //------------------------------------------------------------------------------ |
680 | 681 |
681 void RendererWebKitPlatformSupportImpl::sampleGamepads(WebGamepads& gamepads) { | 682 void RendererWebKitPlatformSupportImpl::sampleGamepads(WebGamepads& gamepads) { |
682 if (!gamepad_shared_memory_reader_.get()) | 683 if (!gamepad_shared_memory_reader_.get()) |
683 gamepad_shared_memory_reader_.reset(new content::GamepadSharedMemoryReader); | 684 gamepad_shared_memory_reader_.reset(new content::GamepadSharedMemoryReader); |
684 gamepad_shared_memory_reader_->SampleGamepads(gamepads); | 685 gamepad_shared_memory_reader_->SampleGamepads(gamepads); |
685 } | 686 } |
686 | 687 |
687 WebKit::WebString RendererWebKitPlatformSupportImpl::userAgent( | 688 WebKit::WebString RendererWebKitPlatformSupportImpl::userAgent( |
688 const WebKit::WebURL& url) { | 689 const WebKit::WebURL& url) { |
689 return WebKitPlatformSupportImpl::userAgent(url); | 690 return WebKitPlatformSupportImpl::userAgent(url); |
690 } | 691 } |
691 | 692 |
692 void RendererWebKitPlatformSupportImpl::GetPlugins( | 693 void RendererWebKitPlatformSupportImpl::GetPlugins( |
693 bool refresh, std::vector<webkit::WebPluginInfo>* plugins) { | 694 bool refresh, std::vector<webkit::WebPluginInfo>* plugins) { |
694 if (!RenderThreadImpl::current()->plugin_refresh_allowed()) | 695 if (!plugin_refresh_allowed()) |
695 refresh = false; | 696 refresh = false; |
696 RenderThreadImpl::current()->Send( | 697 content::RenderThread::Get()->Send( |
697 new ViewHostMsg_GetPlugins(refresh, plugins)); | 698 new ViewHostMsg_GetPlugins(refresh, plugins)); |
698 } | 699 } |
699 | 700 |
700 //------------------------------------------------------------------------------ | 701 //------------------------------------------------------------------------------ |
701 | 702 |
702 WebPeerConnection00Handler* | 703 WebPeerConnection00Handler* |
703 RendererWebKitPlatformSupportImpl::createPeerConnection00Handler( | 704 RendererWebKitPlatformSupportImpl::createPeerConnection00Handler( |
704 WebPeerConnection00HandlerClient* client) { | 705 WebPeerConnection00HandlerClient* client) { |
705 WebFrame* web_frame = WebFrame::frameForCurrentContext(); | 706 WebFrame* web_frame = WebFrame::frameForCurrentContext(); |
706 if (!web_frame) | 707 if (!web_frame) |
(...skipping 21 matching lines...) Expand all Loading... | |
728 bool enable) { | 729 bool enable) { |
729 bool was_enabled = g_sandbox_enabled; | 730 bool was_enabled = g_sandbox_enabled; |
730 g_sandbox_enabled = enable; | 731 g_sandbox_enabled = enable; |
731 return was_enabled; | 732 return was_enabled; |
732 } | 733 } |
733 | 734 |
734 GpuChannelHostFactory* | 735 GpuChannelHostFactory* |
735 RendererWebKitPlatformSupportImpl::GetGpuChannelHostFactory() { | 736 RendererWebKitPlatformSupportImpl::GetGpuChannelHostFactory() { |
736 return RenderThreadImpl::current(); | 737 return RenderThreadImpl::current(); |
737 } | 738 } |
OLD | NEW |