| 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 "chrome/renderer/chrome_render_process_observer.h" | 5 #include "chrome/renderer/chrome_render_process_observer.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/allocator/allocator_extension.h" | 10 #include "base/allocator/allocator_extension.h" |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 | 50 |
| 51 using blink::WebCache; | 51 using blink::WebCache; |
| 52 using blink::WebRuntimeFeatures; | 52 using blink::WebRuntimeFeatures; |
| 53 using blink::WebSecurityPolicy; | 53 using blink::WebSecurityPolicy; |
| 54 using blink::WebString; | 54 using blink::WebString; |
| 55 using content::RenderThread; | 55 using content::RenderThread; |
| 56 | 56 |
| 57 namespace { | 57 namespace { |
| 58 | 58 |
| 59 const int kCacheStatsDelayMS = 2000; | 59 const int kCacheStatsDelayMS = 2000; |
| 60 const size_t kUnitializedCacheCapacity = UINT_MAX; | |
| 61 | 60 |
| 62 class RendererResourceDelegate : public content::ResourceDispatcherDelegate { | 61 class RendererResourceDelegate : public content::ResourceDispatcherDelegate { |
| 63 public: | 62 public: |
| 64 RendererResourceDelegate() | 63 RendererResourceDelegate() |
| 65 : weak_factory_(this) { | 64 : weak_factory_(this) { |
| 66 } | 65 } |
| 67 | 66 |
| 68 virtual content::RequestPeer* OnRequestComplete( | 67 virtual content::RequestPeer* OnRequestComplete( |
| 69 content::RequestPeer* current_peer, | 68 content::RequestPeer* current_peer, |
| 70 content::ResourceType resource_type, | 69 content::ResourceType resource_type, |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 ++round_id_; | 240 ++round_id_; |
| 242 } | 241 } |
| 243 | 242 |
| 244 } // namespace | 243 } // namespace |
| 245 | 244 |
| 246 bool ChromeRenderProcessObserver::is_incognito_process_ = false; | 245 bool ChromeRenderProcessObserver::is_incognito_process_ = false; |
| 247 | 246 |
| 248 ChromeRenderProcessObserver::ChromeRenderProcessObserver( | 247 ChromeRenderProcessObserver::ChromeRenderProcessObserver( |
| 249 ChromeContentRendererClient* client) | 248 ChromeContentRendererClient* client) |
| 250 : client_(client), | 249 : client_(client), |
| 251 clear_cache_pending_(false), | 250 webkit_initialized_(false) { |
| 252 webkit_initialized_(false), | |
| 253 pending_cache_min_dead_capacity_(0), | |
| 254 pending_cache_max_dead_capacity_(0), | |
| 255 pending_cache_capacity_(kUnitializedCacheCapacity) { | |
| 256 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 251 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 257 | 252 |
| 258 #if defined(ENABLE_AUTOFILL_DIALOG) | 253 #if defined(ENABLE_AUTOFILL_DIALOG) |
| 259 WebRuntimeFeatures::enableRequestAutocomplete(true); | 254 WebRuntimeFeatures::enableRequestAutocomplete(true); |
| 260 #endif | 255 #endif |
| 261 | 256 |
| 262 if (command_line.HasSwitch(switches::kEnableShowModalDialog)) | 257 if (command_line.HasSwitch(switches::kEnableShowModalDialog)) |
| 263 WebRuntimeFeatures::enableShowModalDialog(true); | 258 WebRuntimeFeatures::enableShowModalDialog(true); |
| 264 | 259 |
| 265 RenderThread* thread = RenderThread::Get(); | 260 RenderThread* thread = RenderThread::Get(); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 | 293 |
| 299 ChromeRenderProcessObserver::~ChromeRenderProcessObserver() { | 294 ChromeRenderProcessObserver::~ChromeRenderProcessObserver() { |
| 300 } | 295 } |
| 301 | 296 |
| 302 bool ChromeRenderProcessObserver::OnControlMessageReceived( | 297 bool ChromeRenderProcessObserver::OnControlMessageReceived( |
| 303 const IPC::Message& message) { | 298 const IPC::Message& message) { |
| 304 bool handled = true; | 299 bool handled = true; |
| 305 IPC_BEGIN_MESSAGE_MAP(ChromeRenderProcessObserver, message) | 300 IPC_BEGIN_MESSAGE_MAP(ChromeRenderProcessObserver, message) |
| 306 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetIsIncognitoProcess, | 301 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetIsIncognitoProcess, |
| 307 OnSetIsIncognitoProcess) | 302 OnSetIsIncognitoProcess) |
| 308 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetCacheCapacities, OnSetCacheCapacities) | |
| 309 IPC_MESSAGE_HANDLER(ChromeViewMsg_ClearCache, OnClearCache) | |
| 310 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetFieldTrialGroup, OnSetFieldTrialGroup) | 303 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetFieldTrialGroup, OnSetFieldTrialGroup) |
| 311 IPC_MESSAGE_HANDLER(ChromeViewMsg_GetV8HeapStats, OnGetV8HeapStats) | 304 IPC_MESSAGE_HANDLER(ChromeViewMsg_GetV8HeapStats, OnGetV8HeapStats) |
| 312 IPC_MESSAGE_HANDLER(ChromeViewMsg_GetCacheResourceStats, | 305 IPC_MESSAGE_HANDLER(ChromeViewMsg_GetCacheResourceStats, |
| 313 OnGetCacheResourceStats) | 306 OnGetCacheResourceStats) |
| 314 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetContentSettingRules, | 307 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetContentSettingRules, |
| 315 OnSetContentSettingRules) | 308 OnSetContentSettingRules) |
| 316 IPC_MESSAGE_UNHANDLED(handled = false) | 309 IPC_MESSAGE_UNHANDLED(handled = false) |
| 317 IPC_END_MESSAGE_MAP() | 310 IPC_END_MESSAGE_MAP() |
| 318 return handled; | 311 return handled; |
| 319 } | 312 } |
| 320 | 313 |
| 321 void ChromeRenderProcessObserver::WebKitInitialized() { | 314 void ChromeRenderProcessObserver::WebKitInitialized() { |
| 322 webkit_initialized_ = true; | 315 webkit_initialized_ = true; |
| 323 if (pending_cache_capacity_ != kUnitializedCacheCapacity) { | |
| 324 WebCache::setCapacities(pending_cache_min_dead_capacity_, | |
| 325 pending_cache_max_dead_capacity_, | |
| 326 pending_cache_capacity_); | |
| 327 } | |
| 328 | |
| 329 // chrome-native: is a scheme used for placeholder navigations that allow | 316 // chrome-native: is a scheme used for placeholder navigations that allow |
| 330 // UIs to be drawn with platform native widgets instead of HTML. These pages | 317 // UIs to be drawn with platform native widgets instead of HTML. These pages |
| 331 // should not be accessible, and should also be treated as empty documents | 318 // should not be accessible, and should also be treated as empty documents |
| 332 // that can commit synchronously. No code should be runnable in these pages, | 319 // that can commit synchronously. No code should be runnable in these pages, |
| 333 // so it should not need to access anything nor should it allow javascript | 320 // so it should not need to access anything nor should it allow javascript |
| 334 // URLs since it should never be visible to the user. | 321 // URLs since it should never be visible to the user. |
| 335 WebString native_scheme(base::ASCIIToUTF16(chrome::kChromeNativeScheme)); | 322 WebString native_scheme(base::ASCIIToUTF16(chrome::kChromeNativeScheme)); |
| 336 WebSecurityPolicy::registerURLSchemeAsDisplayIsolated(native_scheme); | 323 WebSecurityPolicy::registerURLSchemeAsDisplayIsolated(native_scheme); |
| 337 WebSecurityPolicy::registerURLSchemeAsEmptyDocument(native_scheme); | 324 WebSecurityPolicy::registerURLSchemeAsEmptyDocument(native_scheme); |
| 338 WebSecurityPolicy::registerURLSchemeAsNoAccess(native_scheme); | 325 WebSecurityPolicy::registerURLSchemeAsNoAccess(native_scheme); |
| 339 WebSecurityPolicy::registerURLSchemeAsNotAllowingJavascriptURLs( | 326 WebSecurityPolicy::registerURLSchemeAsNotAllowingJavascriptURLs( |
| 340 native_scheme); | 327 native_scheme); |
| 341 } | 328 } |
| 342 | 329 |
| 343 void ChromeRenderProcessObserver::OnRenderProcessShutdown() { | 330 void ChromeRenderProcessObserver::OnRenderProcessShutdown() { |
| 344 webkit_initialized_ = false; | 331 webkit_initialized_ = false; |
| 345 } | 332 } |
| 346 | 333 |
| 347 void ChromeRenderProcessObserver::OnSetIsIncognitoProcess( | 334 void ChromeRenderProcessObserver::OnSetIsIncognitoProcess( |
| 348 bool is_incognito_process) { | 335 bool is_incognito_process) { |
| 349 is_incognito_process_ = is_incognito_process; | 336 is_incognito_process_ = is_incognito_process; |
| 350 } | 337 } |
| 351 | 338 |
| 352 void ChromeRenderProcessObserver::OnSetContentSettingRules( | 339 void ChromeRenderProcessObserver::OnSetContentSettingRules( |
| 353 const RendererContentSettingRules& rules) { | 340 const RendererContentSettingRules& rules) { |
| 354 content_setting_rules_ = rules; | 341 content_setting_rules_ = rules; |
| 355 } | 342 } |
| 356 | 343 |
| 357 void ChromeRenderProcessObserver::OnSetCacheCapacities(size_t min_dead_capacity, | |
| 358 size_t max_dead_capacity, | |
| 359 size_t capacity) { | |
| 360 if (!webkit_initialized_) { | |
| 361 pending_cache_min_dead_capacity_ = min_dead_capacity; | |
| 362 pending_cache_max_dead_capacity_ = max_dead_capacity; | |
| 363 pending_cache_capacity_ = capacity; | |
| 364 return; | |
| 365 } | |
| 366 | |
| 367 WebCache::setCapacities( | |
| 368 min_dead_capacity, max_dead_capacity, capacity); | |
| 369 } | |
| 370 | |
| 371 void ChromeRenderProcessObserver::OnClearCache(bool on_navigation) { | |
| 372 if (on_navigation || !webkit_initialized_) { | |
| 373 clear_cache_pending_ = true; | |
| 374 } else { | |
| 375 WebCache::clear(); | |
| 376 } | |
| 377 } | |
| 378 | |
| 379 void ChromeRenderProcessObserver::OnGetCacheResourceStats() { | 344 void ChromeRenderProcessObserver::OnGetCacheResourceStats() { |
| 380 WebCache::ResourceTypeStats stats; | 345 WebCache::ResourceTypeStats stats; |
| 381 if (webkit_initialized_) | 346 if (webkit_initialized_) |
| 382 WebCache::getResourceTypeStats(&stats); | 347 WebCache::getResourceTypeStats(&stats); |
| 383 RenderThread::Get()->Send(new ChromeViewHostMsg_ResourceTypeStats(stats)); | 348 RenderThread::Get()->Send(new ChromeViewHostMsg_ResourceTypeStats(stats)); |
| 384 } | 349 } |
| 385 | 350 |
| 386 void ChromeRenderProcessObserver::OnSetFieldTrialGroup( | 351 void ChromeRenderProcessObserver::OnSetFieldTrialGroup( |
| 387 const std::string& field_trial_name, | 352 const std::string& field_trial_name, |
| 388 const std::string& group_name) { | 353 const std::string& group_name) { |
| 389 base::FieldTrial* trial = | 354 base::FieldTrial* trial = |
| 390 base::FieldTrialList::CreateFieldTrial(field_trial_name, group_name); | 355 base::FieldTrialList::CreateFieldTrial(field_trial_name, group_name); |
| 391 // TODO(mef): Remove this check after the investigation of 359406 is complete. | 356 // TODO(mef): Remove this check after the investigation of 359406 is complete. |
| 392 CHECK(trial) << field_trial_name << ":" << group_name; | 357 CHECK(trial) << field_trial_name << ":" << group_name; |
| 393 // Ensure the trial is marked as "used" by calling group() on it. This is | 358 // Ensure the trial is marked as "used" by calling group() on it. This is |
| 394 // needed to ensure the trial is properly reported in renderer crash reports. | 359 // needed to ensure the trial is properly reported in renderer crash reports. |
| 395 trial->group(); | 360 trial->group(); |
| 396 chrome_variations::SetChildProcessLoggingVariationList(); | 361 chrome_variations::SetChildProcessLoggingVariationList(); |
| 397 } | 362 } |
| 398 | 363 |
| 399 void ChromeRenderProcessObserver::OnGetV8HeapStats() { | 364 void ChromeRenderProcessObserver::OnGetV8HeapStats() { |
| 400 HeapStatisticsCollector::Instance()->InitiateCollection(); | 365 HeapStatisticsCollector::Instance()->InitiateCollection(); |
| 401 } | 366 } |
| 402 | 367 |
| 403 void ChromeRenderProcessObserver::ExecutePendingClearCache() { | |
| 404 if (clear_cache_pending_ && webkit_initialized_) { | |
| 405 clear_cache_pending_ = false; | |
| 406 WebCache::clear(); | |
| 407 } | |
| 408 } | |
| 409 | |
| 410 const RendererContentSettingRules* | 368 const RendererContentSettingRules* |
| 411 ChromeRenderProcessObserver::content_setting_rules() const { | 369 ChromeRenderProcessObserver::content_setting_rules() const { |
| 412 return &content_setting_rules_; | 370 return &content_setting_rules_; |
| 413 } | 371 } |
| OLD | NEW |