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 "chrome/renderer/chrome_render_process_observer.h" | 5 #include "chrome/renderer/chrome_render_process_observer.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/metrics/field_trial.h" | 9 #include "base/metrics/field_trial.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
11 #include "base/native_library.h" | 11 #include "base/native_library.h" |
12 #include "base/path_service.h" | 12 #include "base/path_service.h" |
13 #include "base/process_util.h" | 13 #include "base/process_util.h" |
14 #include "base/threading/platform_thread.h" | 14 #include "base/threading/platform_thread.h" |
15 #include "chrome/common/chrome_paths.h" | 15 #include "chrome/common/chrome_paths.h" |
16 #include "chrome/common/chrome_switches.h" | 16 #include "chrome/common/chrome_switches.h" |
17 #include "chrome/common/extensions/extension_localization_peer.h" | 17 #include "chrome/common/extensions/extension_localization_peer.h" |
18 #include "chrome/common/net/net_resource_provider.h" | 18 #include "chrome/common/net/net_resource_provider.h" |
19 #include "chrome/common/render_messages.h" | 19 #include "chrome/common/render_messages.h" |
20 #include "chrome/renderer/content_settings_observer.h" | 20 #include "chrome/renderer/content_settings_observer.h" |
21 #include "chrome/renderer/security_filter_peer.h" | 21 #include "chrome/renderer/security_filter_peer.h" |
22 #include "content/common/resource_dispatcher.h" | 22 #include "content/common/resource_dispatcher.h" |
23 #include "content/common/resource_dispatcher_delegate.h" | 23 #include "content/common/resource_dispatcher_delegate.h" |
24 #include "content/common/view_messages.h" | 24 #include "content/common/view_messages.h" |
25 #include "content/renderer/render_thread.h" | 25 #include "content/renderer/render_thread.h" |
26 #include "content/renderer/render_view.h" | 26 #include "content/renderer/render_view.h" |
27 #include "content/renderer/render_view_visitor.h" | 27 #include "content/renderer/render_view_visitor.h" |
28 #include "crypto/nss_util.h" | 28 #include "crypto/nss_util.h" |
| 29 #include "media/base/media.h" |
| 30 #include "media/base/media_switches.h" |
29 #include "net/base/net_errors.h" | 31 #include "net/base/net_errors.h" |
30 #include "net/base/net_module.h" | 32 #include "net/base/net_module.h" |
31 #include "third_party/sqlite/sqlite3.h" | 33 #include "third_party/sqlite/sqlite3.h" |
32 #include "third_party/tcmalloc/chromium/src/google/malloc_extension.h" | 34 #include "third_party/tcmalloc/chromium/src/google/malloc_extension.h" |
33 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCache.h" | 35 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCache.h" |
34 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCrossOriginPreflig
htResultCache.h" | 36 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCrossOriginPreflig
htResultCache.h" |
35 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFontCache.h" | 37 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFontCache.h" |
36 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 38 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
| 39 #include "third_party/WebKit/Source/WebKit/chromium/public/WebRuntimeFeatures.h" |
37 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | 40 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
38 #include "v8/include/v8.h" | 41 #include "v8/include/v8.h" |
39 | 42 |
40 #if defined(OS_WIN) | 43 #if defined(OS_WIN) |
41 #include "app/win/iat_patch_function.h" | 44 #include "app/win/iat_patch_function.h" |
42 #endif | 45 #endif |
43 | 46 |
44 #if defined(OS_MACOSX) | 47 #if defined(OS_MACOSX) |
45 #include "base/eintr_wrapper.h" | 48 #include "base/eintr_wrapper.h" |
46 #include "chrome/app/breakpad_mac.h" | 49 #include "chrome/app/breakpad_mac.h" |
47 #endif | 50 #endif |
48 | 51 |
49 using WebKit::WebCache; | 52 using WebKit::WebCache; |
50 using WebKit::WebCrossOriginPreflightResultCache; | 53 using WebKit::WebCrossOriginPreflightResultCache; |
51 using WebKit::WebFontCache; | 54 using WebKit::WebFontCache; |
| 55 using WebKit::WebRuntimeFeatures; |
52 | 56 |
53 namespace { | 57 namespace { |
54 | 58 |
55 static const unsigned int kCacheStatsDelayMS = 2000 /* milliseconds */; | 59 static const unsigned int kCacheStatsDelayMS = 2000 /* milliseconds */; |
56 | 60 |
57 class RendererResourceDelegate : public ResourceDispatcherDelegate { | 61 class RendererResourceDelegate : public ResourceDispatcherDelegate { |
58 public: | 62 public: |
59 RendererResourceDelegate() | 63 RendererResourceDelegate() |
60 : ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { | 64 : ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { |
61 } | 65 } |
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
372 // TODO(bulach): implement openssl support. | 376 // TODO(bulach): implement openssl support. |
373 NOTREACHED() << "Remoting is not supported for openssl"; | 377 NOTREACHED() << "Remoting is not supported for openssl"; |
374 #endif | 378 #endif |
375 } | 379 } |
376 #elif defined(OS_WIN) | 380 #elif defined(OS_WIN) |
377 // crypt32.dll is used to decode X509 certificates for Chromoting. | 381 // crypt32.dll is used to decode X509 certificates for Chromoting. |
378 // Only load this library when the feature is enabled. | 382 // Only load this library when the feature is enabled. |
379 std::string error; | 383 std::string error; |
380 base::LoadNativeLibrary(FilePath(L"crypt32.dll"), &error); | 384 base::LoadNativeLibrary(FilePath(L"crypt32.dll"), &error); |
381 #endif | 385 #endif |
| 386 |
| 387 // Note that under Linux, the media library will normally already have |
| 388 // been initialized by the Zygote before this instance became a Renderer. |
| 389 FilePath media_path; |
| 390 PathService::Get(chrome::DIR_MEDIA_LIBS, &media_path); |
| 391 if (!media_path.empty()) |
| 392 media::InitializeMediaLibrary(media_path); |
| 393 |
| 394 #if !defined(OS_MACOSX) |
| 395 // TODO(hclam): Add more checks here. Currently this is not used. |
| 396 if (media::IsMediaLibraryInitialized() && |
| 397 CommandLine::ForCurrentProcess()->HasSwitch( |
| 398 switches::kEnableOpenMax)) { |
| 399 media::InitializeOpenMaxLibrary(media_path); |
| 400 } |
| 401 #endif |
382 } | 402 } |
383 | 403 |
384 ChromeRenderProcessObserver::~ChromeRenderProcessObserver() { | 404 ChromeRenderProcessObserver::~ChromeRenderProcessObserver() { |
385 } | 405 } |
386 | 406 |
387 bool ChromeRenderProcessObserver::OnControlMessageReceived( | 407 bool ChromeRenderProcessObserver::OnControlMessageReceived( |
388 const IPC::Message& message) { | 408 const IPC::Message& message) { |
389 bool handled = true; | 409 bool handled = true; |
390 IPC_BEGIN_MESSAGE_MAP(ChromeRenderProcessObserver, message) | 410 IPC_BEGIN_MESSAGE_MAP(ChromeRenderProcessObserver, message) |
391 IPC_MESSAGE_HANDLER(ViewMsg_SetIsIncognitoProcess, OnSetIsIncognitoProcess) | 411 IPC_MESSAGE_HANDLER(ViewMsg_SetIsIncognitoProcess, OnSetIsIncognitoProcess) |
392 IPC_MESSAGE_HANDLER(ViewMsg_SetContentSettingsForCurrentURL, | 412 IPC_MESSAGE_HANDLER(ViewMsg_SetContentSettingsForCurrentURL, |
393 OnSetContentSettingsForCurrentURL) | 413 OnSetContentSettingsForCurrentURL) |
394 IPC_MESSAGE_HANDLER(ViewMsg_SetCacheCapacities, OnSetCacheCapacities) | 414 IPC_MESSAGE_HANDLER(ViewMsg_SetCacheCapacities, OnSetCacheCapacities) |
395 IPC_MESSAGE_HANDLER(ViewMsg_ClearCache, OnClearCache) | 415 IPC_MESSAGE_HANDLER(ViewMsg_ClearCache, OnClearCache) |
396 IPC_MESSAGE_HANDLER(ViewMsg_SetFieldTrialGroup, OnSetFieldTrialGroup) | 416 IPC_MESSAGE_HANDLER(ViewMsg_SetFieldTrialGroup, OnSetFieldTrialGroup) |
397 #if defined(USE_TCMALLOC) | 417 #if defined(USE_TCMALLOC) |
398 IPC_MESSAGE_HANDLER(ViewMsg_GetRendererTcmalloc, OnGetRendererTcmalloc) | 418 IPC_MESSAGE_HANDLER(ViewMsg_GetRendererTcmalloc, OnGetRendererTcmalloc) |
399 #endif | 419 #endif |
400 IPC_MESSAGE_HANDLER(ViewMsg_GetV8HeapStats, OnGetV8HeapStats) | 420 IPC_MESSAGE_HANDLER(ViewMsg_GetV8HeapStats, OnGetV8HeapStats) |
401 IPC_MESSAGE_HANDLER(ViewMsg_GetCacheResourceStats, OnGetCacheResourceStats) | 421 IPC_MESSAGE_HANDLER(ViewMsg_GetCacheResourceStats, OnGetCacheResourceStats) |
402 IPC_MESSAGE_HANDLER(ViewMsg_PurgeMemory, OnPurgeMemory) | 422 IPC_MESSAGE_HANDLER(ViewMsg_PurgeMemory, OnPurgeMemory) |
403 IPC_MESSAGE_UNHANDLED(handled = false) | 423 IPC_MESSAGE_UNHANDLED(handled = false) |
404 IPC_END_MESSAGE_MAP() | 424 IPC_END_MESSAGE_MAP() |
405 return handled; | 425 return handled; |
406 } | 426 } |
407 | 427 |
| 428 void ChromeRenderProcessObserver::WebKitInitialized() { |
| 429 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 430 |
| 431 WebRuntimeFeatures::enableMediaPlayer(media::IsMediaLibraryInitialized()); |
| 432 |
| 433 WebRuntimeFeatures::enableSpellCheckAPI( |
| 434 !command_line.HasSwitch(switches::kDisableSpellcheckAPI)); |
| 435 } |
| 436 |
408 void ChromeRenderProcessObserver::OnSetIsIncognitoProcess( | 437 void ChromeRenderProcessObserver::OnSetIsIncognitoProcess( |
409 bool is_incognito_process) { | 438 bool is_incognito_process) { |
410 is_incognito_process_ = is_incognito_process; | 439 is_incognito_process_ = is_incognito_process; |
411 } | 440 } |
412 | 441 |
413 void ChromeRenderProcessObserver::OnSetContentSettingsForCurrentURL( | 442 void ChromeRenderProcessObserver::OnSetContentSettingsForCurrentURL( |
414 const GURL& url, | 443 const GURL& url, |
415 const ContentSettings& content_settings) { | 444 const ContentSettings& content_settings) { |
416 RenderViewContentSettingsSetter setter(url, content_settings); | 445 RenderViewContentSettingsSetter setter(url, content_settings); |
417 RenderView::ForEach(&setter); | 446 RenderView::ForEach(&setter); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
480 // to free everything possible in just one pass. | 509 // to free everything possible in just one pass. |
481 while (!v8::V8::IdleNotification()) { | 510 while (!v8::V8::IdleNotification()) { |
482 } | 511 } |
483 | 512 |
484 #if !defined(OS_MACOSX) && defined(USE_TCMALLOC) | 513 #if !defined(OS_MACOSX) && defined(USE_TCMALLOC) |
485 // Tell tcmalloc to release any free pages it's still holding. | 514 // Tell tcmalloc to release any free pages it's still holding. |
486 MallocExtension::instance()->ReleaseFreeMemory(); | 515 MallocExtension::instance()->ReleaseFreeMemory(); |
487 #endif | 516 #endif |
488 } | 517 } |
489 | 518 |
OLD | NEW |