1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/browser/frame_host/debug_urls.h"
9 #include "base/command_line.h"
10 #include "base/debug/asan_invalid_access.h"
11 #include "base/debug/profiler.h"
12 #include "base/strings/utf_string_conversions.h"
13 #include "cc/base/switches.h"
14 #include "content/browser/gpu/gpu_process_host_ui_shim.h"
15 #include "content/browser/ppapi_plugin_process_host.h"
16 #include "content/public/browser/browser_thread.h"
17 #include "content/public/common/content_constants.h"
18 #include "content/public/common/url_constants.h"
19 #include "ppapi/proxy/ppapi_messages.h"
26 // Define the Asan debug URLs.
27 const char kAsanCrashDomain
[] = "crash";
28 const char kAsanHeapOverflow
[] = "/browser-heap-overflow";
29 const char kAsanHeapUnderflow
[] = "/browser-heap-underflow";
30 const char kAsanUseAfterFree
[] = "/browser-use-after-free";
32 const char kAsanCorruptHeapBlock
[] = "/browser-corrupt-heap-block";
33 const char kAsanCorruptHeap
[] = "/browser-corrupt-heap";
36 void HandlePpapiFlashDebugURL(const GURL
& url
) {
37 #if defined(ENABLE_PLUGINS)
38 bool crash
= url
== GURL(kChromeUIPpapiFlashCrashURL
);
40 std::vector
<PpapiPluginProcessHost
*> hosts
;
41 PpapiPluginProcessHost::FindByName(
42 base::UTF8ToUTF16(kFlashPluginName
), &hosts
);
43 for (std::vector
<PpapiPluginProcessHost
*>::iterator iter
= hosts
.begin();
44 iter
!= hosts
.end(); ++iter
) {
46 (*iter
)->Send(new PpapiMsg_Crash());
48 (*iter
)->Send(new PpapiMsg_Hang());
53 bool IsAsanDebugURL(const GURL
& url
) {
55 if (!base::debug::IsBinaryInstrumented())
59 if (!(url
.is_valid() && url
.SchemeIs(kChromeUIScheme
) &&
60 url
.DomainIs(kAsanCrashDomain
, sizeof(kAsanCrashDomain
) - 1) &&
65 if (url
.path() == kAsanHeapOverflow
|| url
.path() == kAsanHeapUnderflow
||
66 url
.path() == kAsanUseAfterFree
) {
71 if (url
.path() == kAsanCorruptHeapBlock
|| url
.path() == kAsanCorruptHeap
)
78 bool HandleAsanDebugURL(const GURL
& url
) {
80 if (!base::debug::IsBinaryInstrumented())
83 if (url
.path() == kAsanCorruptHeapBlock
) {
84 base::debug::AsanCorruptHeapBlock();
86 } else if (url
.path() == kAsanCorruptHeap
) {
87 base::debug::AsanCorruptHeap();
92 #if defined(ADDRESS_SANITIZER) || defined(SYZYASAN)
93 if (url
.path() == kAsanHeapOverflow
) {
94 base::debug::AsanHeapOverflow();
95 } else if (url
.path() == kAsanHeapUnderflow
) {
96 base::debug::AsanHeapUnderflow();
97 } else if (url
.path() == kAsanUseAfterFree
) {
98 base::debug::AsanHeapUseAfterFree();
110 bool HandleDebugURL(const GURL
& url
, PageTransition transition
) {
111 // Ensure that the user explicitly navigated to this URL, unless
112 // kEnableGpuBenchmarking is enabled by Telemetry.
113 bool is_telemetry_navigation
=
114 base::CommandLine::ForCurrentProcess()->HasSwitch(
115 cc::switches::kEnableGpuBenchmarking
) &&
116 (transition
& PAGE_TRANSITION_TYPED
);
118 if (!(transition
& PAGE_TRANSITION_FROM_ADDRESS_BAR
) &&
119 !is_telemetry_navigation
)
122 if (IsAsanDebugURL(url
))
123 return HandleAsanDebugURL(url
);
125 if (url
.host() == kChromeUIBrowserCrashHost
) {
126 // Induce an intentional crash in the browser process.
131 if (url
== GURL(kChromeUIGpuCleanURL
)) {
132 GpuProcessHostUIShim
* shim
= GpuProcessHostUIShim::GetOneInstance();
134 shim
->SimulateRemoveAllContext();
138 if (url
== GURL(kChromeUIGpuCrashURL
)) {
139 GpuProcessHostUIShim
* shim
= GpuProcessHostUIShim::GetOneInstance();
141 shim
->SimulateCrash();
145 if (url
== GURL(kChromeUIGpuHangURL
)) {
146 GpuProcessHostUIShim
* shim
= GpuProcessHostUIShim::GetOneInstance();
148 shim
->SimulateHang();
152 if (url
== GURL(kChromeUIPpapiFlashCrashURL
) ||
153 url
== GURL(kChromeUIPpapiFlashHangURL
)) {
154 BrowserThread::PostTask(BrowserThread::IO
, FROM_HERE
,
155 base::Bind(&HandlePpapiFlashDebugURL
, url
));
162 bool IsRendererDebugURL(const GURL
& url
) {
166 if (url
.SchemeIs(url::kJavaScriptScheme
))
169 return url
== GURL(kChromeUICrashURL
) ||
170 url
== GURL(kChromeUIDumpURL
) ||
171 url
== GURL(kChromeUIKillURL
) ||
172 url
== GURL(kChromeUIHangURL
) ||
173 url
== GURL(kChromeUIShorthangURL
);
176 } // namespace content