| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <limits> | 8 #include <limits> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 const mojo::Callback<void(ResourceUsageDataPtr)>& callback) override { | 176 const mojo::Callback<void(ResourceUsageDataPtr)>& callback) override { |
| 177 DCHECK(callback_.is_null()); | 177 DCHECK(callback_.is_null()); |
| 178 weak_factory_.InvalidateWeakPtrs(); | 178 weak_factory_.InvalidateWeakPtrs(); |
| 179 usage_data_ = ResourceUsageData::New(); | 179 usage_data_ = ResourceUsageData::New(); |
| 180 usage_data_->reports_v8_stats = true; | 180 usage_data_->reports_v8_stats = true; |
| 181 callback_ = callback; | 181 callback_ = callback; |
| 182 | 182 |
| 183 // Since it is not safe to call any Blink or V8 functions until Blink has | 183 // Since it is not safe to call any Blink or V8 functions until Blink has |
| 184 // been initialized (which also initializes V8), early out and send 0 back | 184 // been initialized (which also initializes V8), early out and send 0 back |
| 185 // for all resources. | 185 // for all resources. |
| 186 if (!observer_ || !observer_->webkit_initialized()) { | 186 if (!observer_) { |
| 187 SendResults(); | 187 SendResults(); |
| 188 return; | 188 return; |
| 189 } | 189 } |
| 190 | 190 |
| 191 WebCache::ResourceTypeStats stats; | 191 WebCache::ResourceTypeStats stats; |
| 192 WebCache::getResourceTypeStats(&stats); | 192 WebCache::getResourceTypeStats(&stats); |
| 193 usage_data_->web_cache_stats = ResourceTypeStats::From(stats); | 193 usage_data_->web_cache_stats = ResourceTypeStats::From(stats); |
| 194 | 194 |
| 195 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 195 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
| 196 if (isolate) { | 196 if (isolate) { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 base::WeakPtr<ChromeRenderProcessObserver> observer, | 231 base::WeakPtr<ChromeRenderProcessObserver> observer, |
| 232 mojo::InterfaceRequest<ResourceUsageReporter> request) { | 232 mojo::InterfaceRequest<ResourceUsageReporter> request) { |
| 233 new ResourceUsageReporterImpl(observer, std::move(request)); | 233 new ResourceUsageReporterImpl(observer, std::move(request)); |
| 234 } | 234 } |
| 235 | 235 |
| 236 } // namespace | 236 } // namespace |
| 237 | 237 |
| 238 bool ChromeRenderProcessObserver::is_incognito_process_ = false; | 238 bool ChromeRenderProcessObserver::is_incognito_process_ = false; |
| 239 | 239 |
| 240 ChromeRenderProcessObserver::ChromeRenderProcessObserver() | 240 ChromeRenderProcessObserver::ChromeRenderProcessObserver() |
| 241 : webkit_initialized_(false), weak_factory_(this) { | 241 : weak_factory_(this) { |
| 242 const base::CommandLine& command_line = | 242 const base::CommandLine& command_line = |
| 243 *base::CommandLine::ForCurrentProcess(); | 243 *base::CommandLine::ForCurrentProcess(); |
| 244 | 244 |
| 245 #if defined(ENABLE_AUTOFILL_DIALOG) | 245 #if defined(ENABLE_AUTOFILL_DIALOG) |
| 246 WebRuntimeFeatures::enableRequestAutocomplete(true); | 246 WebRuntimeFeatures::enableRequestAutocomplete(true); |
| 247 #endif | 247 #endif |
| 248 | 248 |
| 249 if (command_line.HasSwitch(switches::kDisableJavaScriptHarmonyShipping)) { | 249 if (command_line.HasSwitch(switches::kDisableJavaScriptHarmonyShipping)) { |
| 250 std::string flag("--noharmony-shipping"); | 250 std::string flag("--noharmony-shipping"); |
| 251 v8::V8::SetFlagsFromString(flag.c_str(), static_cast<int>(flag.size())); | 251 v8::V8::SetFlagsFromString(flag.c_str(), static_cast<int>(flag.size())); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 267 | 267 |
| 268 thread->GetServiceRegistry()->AddService<ResourceUsageReporter>( | 268 thread->GetServiceRegistry()->AddService<ResourceUsageReporter>( |
| 269 base::Bind(CreateResourceUsageReporter, weak_factory_.GetWeakPtr())); | 269 base::Bind(CreateResourceUsageReporter, weak_factory_.GetWeakPtr())); |
| 270 | 270 |
| 271 // Configure modules that need access to resources. | 271 // Configure modules that need access to resources. |
| 272 net::NetModule::SetResourceProvider(chrome_common_net::NetResourceProvider); | 272 net::NetModule::SetResourceProvider(chrome_common_net::NetResourceProvider); |
| 273 media::SetLocalizedStringProvider( | 273 media::SetLocalizedStringProvider( |
| 274 chrome_common_media::LocalizedStringProvider); | 274 chrome_common_media::LocalizedStringProvider); |
| 275 | 275 |
| 276 InitFieldTrialObserving(command_line); | 276 InitFieldTrialObserving(command_line); |
| 277 |
| 278 // chrome-native: is a scheme used for placeholder navigations that allow |
| 279 // UIs to be drawn with platform native widgets instead of HTML. These pages |
| 280 // should not be accessible, and should also be treated as empty documents |
| 281 // that can commit synchronously. No code should be runnable in these pages, |
| 282 // so it should not need to access anything nor should it allow javascript |
| 283 // URLs since it should never be visible to the user. |
| 284 WebString native_scheme(base::ASCIIToUTF16(chrome::kChromeNativeScheme)); |
| 285 WebSecurityPolicy::registerURLSchemeAsDisplayIsolated(native_scheme); |
| 286 WebSecurityPolicy::registerURLSchemeAsEmptyDocument(native_scheme); |
| 287 WebSecurityPolicy::registerURLSchemeAsNoAccess(native_scheme); |
| 288 WebSecurityPolicy::registerURLSchemeAsNotAllowingJavascriptURLs( |
| 289 native_scheme); |
| 277 } | 290 } |
| 278 | 291 |
| 279 ChromeRenderProcessObserver::~ChromeRenderProcessObserver() {} | 292 ChromeRenderProcessObserver::~ChromeRenderProcessObserver() {} |
| 280 | 293 |
| 281 void ChromeRenderProcessObserver::InitFieldTrialObserving( | 294 void ChromeRenderProcessObserver::InitFieldTrialObserving( |
| 282 const base::CommandLine& command_line) { | 295 const base::CommandLine& command_line) { |
| 283 // Set up initial set of crash dump data for field trials in this renderer. | 296 // Set up initial set of crash dump data for field trials in this renderer. |
| 284 variations::SetVariationListCrashKeys(); | 297 variations::SetVariationListCrashKeys(); |
| 285 | 298 |
| 286 // Listen for field trial activations to report them to the browser. | 299 // Listen for field trial activations to report them to the browser. |
| (...skipping 26 matching lines...) Expand all Loading... |
| 313 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetIsIncognitoProcess, | 326 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetIsIncognitoProcess, |
| 314 OnSetIsIncognitoProcess) | 327 OnSetIsIncognitoProcess) |
| 315 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetFieldTrialGroup, OnSetFieldTrialGroup) | 328 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetFieldTrialGroup, OnSetFieldTrialGroup) |
| 316 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetContentSettingRules, | 329 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetContentSettingRules, |
| 317 OnSetContentSettingRules) | 330 OnSetContentSettingRules) |
| 318 IPC_MESSAGE_UNHANDLED(handled = false) | 331 IPC_MESSAGE_UNHANDLED(handled = false) |
| 319 IPC_END_MESSAGE_MAP() | 332 IPC_END_MESSAGE_MAP() |
| 320 return handled; | 333 return handled; |
| 321 } | 334 } |
| 322 | 335 |
| 323 void ChromeRenderProcessObserver::WebKitInitialized() { | |
| 324 webkit_initialized_ = true; | |
| 325 // chrome-native: is a scheme used for placeholder navigations that allow | |
| 326 // UIs to be drawn with platform native widgets instead of HTML. These pages | |
| 327 // should not be accessible, and should also be treated as empty documents | |
| 328 // that can commit synchronously. No code should be runnable in these pages, | |
| 329 // so it should not need to access anything nor should it allow javascript | |
| 330 // URLs since it should never be visible to the user. | |
| 331 WebString native_scheme(base::ASCIIToUTF16(chrome::kChromeNativeScheme)); | |
| 332 WebSecurityPolicy::registerURLSchemeAsDisplayIsolated(native_scheme); | |
| 333 WebSecurityPolicy::registerURLSchemeAsEmptyDocument(native_scheme); | |
| 334 WebSecurityPolicy::registerURLSchemeAsNoAccess(native_scheme); | |
| 335 WebSecurityPolicy::registerURLSchemeAsNotAllowingJavascriptURLs( | |
| 336 native_scheme); | |
| 337 } | |
| 338 | |
| 339 void ChromeRenderProcessObserver::OnRenderProcessShutdown() { | |
| 340 webkit_initialized_ = false; | |
| 341 } | |
| 342 | |
| 343 void ChromeRenderProcessObserver::OnSetIsIncognitoProcess( | 336 void ChromeRenderProcessObserver::OnSetIsIncognitoProcess( |
| 344 bool is_incognito_process) { | 337 bool is_incognito_process) { |
| 345 is_incognito_process_ = is_incognito_process; | 338 is_incognito_process_ = is_incognito_process; |
| 346 } | 339 } |
| 347 | 340 |
| 348 void ChromeRenderProcessObserver::OnSetContentSettingRules( | 341 void ChromeRenderProcessObserver::OnSetContentSettingRules( |
| 349 const RendererContentSettingRules& rules) { | 342 const RendererContentSettingRules& rules) { |
| 350 content_setting_rules_ = rules; | 343 content_setting_rules_ = rules; |
| 351 } | 344 } |
| 352 | 345 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 ChromeRenderProcessObserver::content_setting_rules() const { | 383 ChromeRenderProcessObserver::content_setting_rules() const { |
| 391 return &content_setting_rules_; | 384 return &content_setting_rules_; |
| 392 } | 385 } |
| 393 | 386 |
| 394 void ChromeRenderProcessObserver::OnFieldTrialGroupFinalized( | 387 void ChromeRenderProcessObserver::OnFieldTrialGroupFinalized( |
| 395 const std::string& trial_name, | 388 const std::string& trial_name, |
| 396 const std::string& group_name) { | 389 const std::string& group_name) { |
| 397 content::RenderThread::Get()->Send( | 390 content::RenderThread::Get()->Send( |
| 398 new ChromeViewHostMsg_FieldTrialActivated(trial_name)); | 391 new ChromeViewHostMsg_FieldTrialActivated(trial_name)); |
| 399 } | 392 } |
| OLD | NEW |