| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/platform_file.h" | 10 #include "base/platform_file.h" |
| 11 #include "base/shared_memory.h" | 11 #include "base/shared_memory.h" |
| 12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
| 13 #include "content/common/content_switches.h" | 13 #include "content/common/content_switches.h" |
| 14 #include "content/common/database_util.h" | 14 #include "content/common/database_util.h" |
| 15 #include "content/common/file_system/webfilesystem_impl.h" | 15 #include "content/common/file_system/webfilesystem_impl.h" |
| 16 #include "content/common/file_utilities_messages.h" | 16 #include "content/common/file_utilities_messages.h" |
| 17 #include "content/common/mime_registry_messages.h" | 17 #include "content/common/mime_registry_messages.h" |
| 18 #include "content/common/npobject_util.h" | 18 #include "content/common/npobject_util.h" |
| 19 #include "content/common/view_messages.h" | 19 #include "content/common/view_messages.h" |
| 20 #include "content/common/webblobregistry_impl.h" | 20 #include "content/common/webblobregistry_impl.h" |
| 21 #include "content/common/webmessageportchannel_impl.h" | 21 #include "content/common/webmessageportchannel_impl.h" |
| 22 #include "content/public/renderer/content_renderer_client.h" | 22 #include "content/public/renderer/content_renderer_client.h" |
| 23 #include "content/renderer/gpu/webgraphicscontext3d_command_buffer_impl.h" | 23 #include "content/renderer/gpu/webgraphicscontext3d_command_buffer_impl.h" |
| 24 #include "content/renderer/media/audio_device.h" | 24 #include "content/renderer/media/audio_device.h" |
| 25 #include "content/renderer/render_thread.h" | 25 #include "content/renderer/render_thread_impl.h" |
| 26 #include "content/renderer/render_view.h" | 26 #include "content/renderer/render_view.h" |
| 27 #include "content/renderer/renderer_webaudiodevice_impl.h" | 27 #include "content/renderer/renderer_webaudiodevice_impl.h" |
| 28 #include "content/renderer/renderer_webidbfactory_impl.h" | 28 #include "content/renderer/renderer_webidbfactory_impl.h" |
| 29 #include "content/renderer/renderer_webstoragenamespace_impl.h" | 29 #include "content/renderer/renderer_webstoragenamespace_impl.h" |
| 30 #include "content/renderer/websharedworkerrepository_impl.h" | 30 #include "content/renderer/websharedworkerrepository_impl.h" |
| 31 #include "googleurl/src/gurl.h" | 31 #include "googleurl/src/gurl.h" |
| 32 #include "ipc/ipc_sync_message_filter.h" | 32 #include "ipc/ipc_sync_message_filter.h" |
| 33 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBlobRegistry.h" | 33 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBlobRegistry.h" |
| 34 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 34 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
| 35 #include "third_party/WebKit/Source/WebKit/chromium/public/WebGraphicsContext3D.
h" | 35 #include "third_party/WebKit/Source/WebKit/chromium/public/WebGraphicsContext3D.
h" |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 // Even if the sandbox is disabled, there's no reason why the code should | 185 // Even if the sandbox is disabled, there's no reason why the code should |
| 186 // act any differently...unless we're in single process mode. In which | 186 // act any differently...unless we're in single process mode. In which |
| 187 // case, we have no other choice. WebKitPlatformSupport.h discourages using | 187 // case, we have no other choice. WebKitPlatformSupport.h discourages using |
| 188 // this switch unless absolutely necessary, so hopefully we won't end up | 188 // this switch unless absolutely necessary, so hopefully we won't end up |
| 189 // with too many code paths being different in single-process mode. | 189 // with too many code paths being different in single-process mode. |
| 190 return !CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess); | 190 return !CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess); |
| 191 } | 191 } |
| 192 | 192 |
| 193 bool RendererWebKitPlatformSupportImpl::SendSyncMessageFromAnyThread( | 193 bool RendererWebKitPlatformSupportImpl::SendSyncMessageFromAnyThread( |
| 194 IPC::SyncMessage* msg) { | 194 IPC::SyncMessage* msg) { |
| 195 RenderThread* render_thread = RenderThread::current(); | 195 RenderThreadImpl* render_thread = RenderThreadImpl::current(); |
| 196 if (render_thread) | 196 if (render_thread) |
| 197 return render_thread->Send(msg); | 197 return render_thread->Send(msg); |
| 198 | 198 |
| 199 scoped_refptr<IPC::SyncMessageFilter> sync_msg_filter( | 199 scoped_refptr<IPC::SyncMessageFilter> sync_msg_filter( |
| 200 ChildThread::current()->sync_message_filter()); | 200 ChildThread::current()->sync_message_filter()); |
| 201 return sync_msg_filter->Send(msg); | 201 return sync_msg_filter->Send(msg); |
| 202 } | 202 } |
| 203 | 203 |
| 204 unsigned long long RendererWebKitPlatformSupportImpl::visitedLinkHash( | 204 unsigned long long RendererWebKitPlatformSupportImpl::visitedLinkHash( |
| 205 const char* canonical_url, | 205 const char* canonical_url, |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 double response_time, | 246 double response_time, |
| 247 const char* data, | 247 const char* data, |
| 248 size_t size) { | 248 size_t size) { |
| 249 if (!CheckPreparsedJsCachingEnabled()) | 249 if (!CheckPreparsedJsCachingEnabled()) |
| 250 return; | 250 return; |
| 251 | 251 |
| 252 // Let the browser know we generated cacheable metadata for this resource. The | 252 // Let the browser know we generated cacheable metadata for this resource. The |
| 253 // browser may cache it and return it on subsequent responses to speed | 253 // browser may cache it and return it on subsequent responses to speed |
| 254 // the processing of this resource. | 254 // the processing of this resource. |
| 255 std::vector<char> copy(data, data + size); | 255 std::vector<char> copy(data, data + size); |
| 256 RenderThread::current()->Send(new ViewHostMsg_DidGenerateCacheableMetadata( | 256 RenderThreadImpl::current()->Send( |
| 257 url, response_time, copy)); | 257 new ViewHostMsg_DidGenerateCacheableMetadata(url, response_time, copy)); |
| 258 } | 258 } |
| 259 | 259 |
| 260 WebString RendererWebKitPlatformSupportImpl::defaultLocale() { | 260 WebString RendererWebKitPlatformSupportImpl::defaultLocale() { |
| 261 return ASCIIToUTF16(RenderThread::Get()->GetLocale()); | 261 return ASCIIToUTF16(RenderThreadImpl::Get()->GetLocale()); |
| 262 } | 262 } |
| 263 | 263 |
| 264 void RendererWebKitPlatformSupportImpl::suddenTerminationChanged(bool enabled) { | 264 void RendererWebKitPlatformSupportImpl::suddenTerminationChanged(bool enabled) { |
| 265 if (enabled) { | 265 if (enabled) { |
| 266 // We should not get more enables than disables, but we want it to be a | 266 // We should not get more enables than disables, but we want it to be a |
| 267 // non-fatal error if it does happen. | 267 // non-fatal error if it does happen. |
| 268 DCHECK_GT(sudden_termination_disables_, 0); | 268 DCHECK_GT(sudden_termination_disables_, 0); |
| 269 sudden_termination_disables_ = std::max(sudden_termination_disables_ - 1, | 269 sudden_termination_disables_ = std::max(sudden_termination_disables_ - 1, |
| 270 0); | 270 0); |
| 271 if (sudden_termination_disables_ != 0) | 271 if (sudden_termination_disables_ != 0) |
| 272 return; | 272 return; |
| 273 } else { | 273 } else { |
| 274 sudden_termination_disables_++; | 274 sudden_termination_disables_++; |
| 275 if (sudden_termination_disables_ != 1) | 275 if (sudden_termination_disables_ != 1) |
| 276 return; | 276 return; |
| 277 } | 277 } |
| 278 | 278 |
| 279 RenderThread* thread = RenderThread::current(); | 279 RenderThreadImpl* thread = RenderThreadImpl::current(); |
| 280 if (thread) // NULL in unittests. | 280 if (thread) // NULL in unittests. |
| 281 thread->Send(new ViewHostMsg_SuddenTerminationChanged(enabled)); | 281 thread->Send(new ViewHostMsg_SuddenTerminationChanged(enabled)); |
| 282 } | 282 } |
| 283 | 283 |
| 284 WebStorageNamespace* | 284 WebStorageNamespace* |
| 285 RendererWebKitPlatformSupportImpl::createLocalStorageNamespace( | 285 RendererWebKitPlatformSupportImpl::createLocalStorageNamespace( |
| 286 const WebString& path, unsigned quota) { | 286 const WebString& path, unsigned quota) { |
| 287 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess)) | 287 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess)) |
| 288 return WebStorageNamespace::createLocalStorageNamespace(path, quota); | 288 return WebStorageNamespace::createLocalStorageNamespace(path, quota); |
| 289 return new RendererWebStorageNamespaceImpl(DOM_STORAGE_LOCAL); | 289 return new RendererWebStorageNamespaceImpl(DOM_STORAGE_LOCAL); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 | 348 |
| 349 WebString | 349 WebString |
| 350 RendererWebKitPlatformSupportImpl::MimeRegistry::mimeTypeForExtension( | 350 RendererWebKitPlatformSupportImpl::MimeRegistry::mimeTypeForExtension( |
| 351 const WebString& file_extension) { | 351 const WebString& file_extension) { |
| 352 if (IsPluginProcess()) | 352 if (IsPluginProcess()) |
| 353 return SimpleWebMimeRegistryImpl::mimeTypeForExtension(file_extension); | 353 return SimpleWebMimeRegistryImpl::mimeTypeForExtension(file_extension); |
| 354 | 354 |
| 355 // The sandbox restricts our access to the registry, so we need to proxy | 355 // The sandbox restricts our access to the registry, so we need to proxy |
| 356 // these calls over to the browser process. | 356 // these calls over to the browser process. |
| 357 std::string mime_type; | 357 std::string mime_type; |
| 358 RenderThread::current()->Send( | 358 RenderThreadImpl::current()->Send( |
| 359 new MimeRegistryMsg_GetMimeTypeFromExtension( | 359 new MimeRegistryMsg_GetMimeTypeFromExtension( |
| 360 webkit_glue::WebStringToFilePathString(file_extension), &mime_type)); | 360 webkit_glue::WebStringToFilePathString(file_extension), &mime_type)); |
| 361 return ASCIIToUTF16(mime_type); | 361 return ASCIIToUTF16(mime_type); |
| 362 | 362 |
| 363 } | 363 } |
| 364 | 364 |
| 365 WebString RendererWebKitPlatformSupportImpl::MimeRegistry::mimeTypeFromFile( | 365 WebString RendererWebKitPlatformSupportImpl::MimeRegistry::mimeTypeFromFile( |
| 366 const WebString& file_path) { | 366 const WebString& file_path) { |
| 367 if (IsPluginProcess()) | 367 if (IsPluginProcess()) |
| 368 return SimpleWebMimeRegistryImpl::mimeTypeFromFile(file_path); | 368 return SimpleWebMimeRegistryImpl::mimeTypeFromFile(file_path); |
| 369 | 369 |
| 370 // The sandbox restricts our access to the registry, so we need to proxy | 370 // The sandbox restricts our access to the registry, so we need to proxy |
| 371 // these calls over to the browser process. | 371 // these calls over to the browser process. |
| 372 std::string mime_type; | 372 std::string mime_type; |
| 373 RenderThread::current()->Send(new MimeRegistryMsg_GetMimeTypeFromFile( | 373 RenderThreadImpl::current()->Send(new MimeRegistryMsg_GetMimeTypeFromFile( |
| 374 FilePath(webkit_glue::WebStringToFilePathString(file_path)), | 374 FilePath(webkit_glue::WebStringToFilePathString(file_path)), |
| 375 &mime_type)); | 375 &mime_type)); |
| 376 return ASCIIToUTF16(mime_type); | 376 return ASCIIToUTF16(mime_type); |
| 377 | 377 |
| 378 } | 378 } |
| 379 | 379 |
| 380 WebString | 380 WebString |
| 381 RendererWebKitPlatformSupportImpl::MimeRegistry::preferredExtensionForMIMEType( | 381 RendererWebKitPlatformSupportImpl::MimeRegistry::preferredExtensionForMIMEType( |
| 382 const WebString& mime_type) { | 382 const WebString& mime_type) { |
| 383 if (IsPluginProcess()) | 383 if (IsPluginProcess()) |
| 384 return SimpleWebMimeRegistryImpl::preferredExtensionForMIMEType(mime_type); | 384 return SimpleWebMimeRegistryImpl::preferredExtensionForMIMEType(mime_type); |
| 385 | 385 |
| 386 // 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 |
| 387 // these calls over to the browser process. | 387 // these calls over to the browser process. |
| 388 FilePath::StringType file_extension; | 388 FilePath::StringType file_extension; |
| 389 RenderThread::current()->Send( | 389 RenderThreadImpl::current()->Send( |
| 390 new MimeRegistryMsg_GetPreferredExtensionForMimeType( | 390 new MimeRegistryMsg_GetPreferredExtensionForMimeType( |
| 391 UTF16ToASCII(mime_type), &file_extension)); | 391 UTF16ToASCII(mime_type), &file_extension)); |
| 392 return webkit_glue::FilePathStringToWebString(file_extension); | 392 return webkit_glue::FilePathStringToWebString(file_extension); |
| 393 } | 393 } |
| 394 | 394 |
| 395 //------------------------------------------------------------------------------ | 395 //------------------------------------------------------------------------------ |
| 396 | 396 |
| 397 bool RendererWebKitPlatformSupportImpl::FileUtilities::getFileSize( | 397 bool RendererWebKitPlatformSupportImpl::FileUtilities::getFileSize( |
| 398 const WebString& path, long long& result) { | 398 const WebString& path, long long& result) { |
| 399 if (SendSyncMessageFromAnyThread(new FileUtilitiesMsg_GetFileSize( | 399 if (SendSyncMessageFromAnyThread(new FileUtilitiesMsg_GetFileSize( |
| 400 webkit_glue::WebStringToFilePath(path), | 400 webkit_glue::WebStringToFilePath(path), |
| 401 reinterpret_cast<int64*>(&result)))) { | 401 reinterpret_cast<int64*>(&result)))) { |
| 402 return result >= 0; | 402 return result >= 0; |
| 403 } | 403 } |
| 404 | 404 |
| 405 result = -1; | 405 result = -1; |
| 406 return false; | 406 return false; |
| 407 } | 407 } |
| 408 | 408 |
| 409 void RendererWebKitPlatformSupportImpl::FileUtilities::revealFolderInOS( | 409 void RendererWebKitPlatformSupportImpl::FileUtilities::revealFolderInOS( |
| 410 const WebString& path) { | 410 const WebString& path) { |
| 411 FilePath file_path(webkit_glue::WebStringToFilePath(path)); | 411 FilePath file_path(webkit_glue::WebStringToFilePath(path)); |
| 412 file_util::AbsolutePath(&file_path); | 412 file_util::AbsolutePath(&file_path); |
| 413 RenderThread::current()->Send(new ViewHostMsg_RevealFolderInOS(file_path)); | 413 RenderThreadImpl::current()->Send( |
| 414 new ViewHostMsg_RevealFolderInOS(file_path)); |
| 414 } | 415 } |
| 415 | 416 |
| 416 bool RendererWebKitPlatformSupportImpl::FileUtilities::getFileModificationTime( | 417 bool RendererWebKitPlatformSupportImpl::FileUtilities::getFileModificationTime( |
| 417 const WebString& path, | 418 const WebString& path, |
| 418 double& result) { | 419 double& result) { |
| 419 base::Time time; | 420 base::Time time; |
| 420 if (SendSyncMessageFromAnyThread(new FileUtilitiesMsg_GetFileModificationTime( | 421 if (SendSyncMessageFromAnyThread(new FileUtilitiesMsg_GetFileModificationTime( |
| 421 webkit_glue::WebStringToFilePath(path), &time))) { | 422 webkit_glue::WebStringToFilePath(path), &time))) { |
| 422 result = time.ToDoubleT(); | 423 result = time.ToDoubleT(); |
| 423 return !time.is_null(); | 424 return !time.is_null(); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 437 } | 438 } |
| 438 | 439 |
| 439 //------------------------------------------------------------------------------ | 440 //------------------------------------------------------------------------------ |
| 440 | 441 |
| 441 #if defined(OS_WIN) | 442 #if defined(OS_WIN) |
| 442 | 443 |
| 443 bool RendererWebKitPlatformSupportImpl::SandboxSupport::ensureFontLoaded( | 444 bool RendererWebKitPlatformSupportImpl::SandboxSupport::ensureFontLoaded( |
| 444 HFONT font) { | 445 HFONT font) { |
| 445 LOGFONT logfont; | 446 LOGFONT logfont; |
| 446 GetObject(font, sizeof(LOGFONT), &logfont); | 447 GetObject(font, sizeof(LOGFONT), &logfont); |
| 447 RenderThread::current()->PreCacheFont(logfont); | 448 RenderThreadImpl::current()->PreCacheFont(logfont); |
| 448 return true; | 449 return true; |
| 449 } | 450 } |
| 450 | 451 |
| 451 #elif defined(OS_MACOSX) | 452 #elif defined(OS_MACOSX) |
| 452 | 453 |
| 453 bool RendererWebKitPlatformSupportImpl::SandboxSupport::loadFont( | 454 bool RendererWebKitPlatformSupportImpl::SandboxSupport::loadFont( |
| 454 NSFont* src_font, CGFontRef* out, uint32* font_id) { | 455 NSFont* src_font, CGFontRef* out, uint32* font_id) { |
| 455 uint32 font_data_size; | 456 uint32 font_data_size; |
| 456 FontDescriptor src_font_descriptor(src_font); | 457 FontDescriptor src_font_descriptor(src_font); |
| 457 base::SharedMemoryHandle font_data; | 458 base::SharedMemoryHandle font_data; |
| 458 if (!RenderThread::current()->Send(new ViewHostMsg_LoadFont( | 459 if (!RenderThreadImpl::current()->Send(new ViewHostMsg_LoadFont( |
| 459 src_font_descriptor, &font_data_size, &font_data, font_id))) { | 460 src_font_descriptor, &font_data_size, &font_data, font_id))) { |
| 460 *out = NULL; | 461 *out = NULL; |
| 461 *font_id = 0; | 462 *font_id = 0; |
| 462 return false; | 463 return false; |
| 463 } | 464 } |
| 464 | 465 |
| 465 if (font_data_size == 0 || font_data == base::SharedMemory::NULLHandle() || | 466 if (font_data_size == 0 || font_data == base::SharedMemory::NULLHandle() || |
| 466 *font_id == 0) { | 467 *font_id == 0) { |
| 467 NOTREACHED() << "Bad response from ViewHostMsg_LoadFont() for " << | 468 NOTREACHED() << "Bad response from ViewHostMsg_LoadFont() for " << |
| 468 src_font_descriptor.font_name; | 469 src_font_descriptor.font_name; |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 585 } | 586 } |
| 586 | 587 |
| 587 //------------------------------------------------------------------------------ | 588 //------------------------------------------------------------------------------ |
| 588 | 589 |
| 589 WebKit::WebString | 590 WebKit::WebString |
| 590 RendererWebKitPlatformSupportImpl::signedPublicKeyAndChallengeString( | 591 RendererWebKitPlatformSupportImpl::signedPublicKeyAndChallengeString( |
| 591 unsigned key_size_index, | 592 unsigned key_size_index, |
| 592 const WebKit::WebString& challenge, | 593 const WebKit::WebString& challenge, |
| 593 const WebKit::WebURL& url) { | 594 const WebKit::WebURL& url) { |
| 594 std::string signed_public_key; | 595 std::string signed_public_key; |
| 595 RenderThread::current()->Send(new ViewHostMsg_Keygen( | 596 RenderThreadImpl::current()->Send(new ViewHostMsg_Keygen( |
| 596 static_cast<uint32>(key_size_index), | 597 static_cast<uint32>(key_size_index), |
| 597 challenge.utf8(), | 598 challenge.utf8(), |
| 598 GURL(url), | 599 GURL(url), |
| 599 &signed_public_key)); | 600 &signed_public_key)); |
| 600 return WebString::fromUTF8(signed_public_key); | 601 return WebString::fromUTF8(signed_public_key); |
| 601 } | 602 } |
| 602 | 603 |
| 603 //------------------------------------------------------------------------------ | 604 //------------------------------------------------------------------------------ |
| 604 | 605 |
| 605 WebBlobRegistry* RendererWebKitPlatformSupportImpl::blobRegistry() { | 606 WebBlobRegistry* RendererWebKitPlatformSupportImpl::blobRegistry() { |
| 606 // RenderThread::current can be NULL when running some tests. | 607 // RenderThreadImpl::current can be NULL when running some tests. |
| 607 if (!blob_registry_.get() && RenderThread::current()) { | 608 if (!blob_registry_.get() && RenderThreadImpl::current()) { |
| 608 blob_registry_.reset(new WebBlobRegistryImpl(RenderThread::Get())); | 609 blob_registry_.reset(new WebBlobRegistryImpl(RenderThreadImpl::Get())); |
| 609 } | 610 } |
| 610 return blob_registry_.get(); | 611 return blob_registry_.get(); |
| 611 } | 612 } |
| OLD | NEW |