[email protected] | d4a8ca48 | 2013-10-30 21:06:40 | [diff] [blame] | 1 | // Copyright 2013 The Chromium Authors. All rights reserved. |
[email protected] | 8bf104801 | 2012-02-08 01:22:18 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. | ||||
4 | |||||
[email protected] | d4a8ca48 | 2013-10-30 21:06:40 | [diff] [blame] | 5 | #include "content/browser/frame_host/debug_urls.h" |
[email protected] | 8bf104801 | 2012-02-08 01:22:18 | [diff] [blame] | 6 | |
[email protected] | 029bd94 | 2013-01-22 08:30:33 | [diff] [blame] | 7 | #include <vector> |
8 | |||||
[email protected] | 4775298 | 2014-07-29 08:01:43 | [diff] [blame] | 9 | #include "base/command_line.h" |
[email protected] | b4b3479 | 2014-06-14 08:29:37 | [diff] [blame] | 10 | #include "base/debug/asan_invalid_access.h" |
11 | #include "base/debug/profiler.h" | ||||
[email protected] | 74ebfb1 | 2013-06-07 20:48:00 | [diff] [blame] | 12 | #include "base/strings/utf_string_conversions.h" |
[email protected] | 4775298 | 2014-07-29 08:01:43 | [diff] [blame] | 13 | #include "cc/base/switches.h" |
[email protected] | 8bf104801 | 2012-02-08 01:22:18 | [diff] [blame] | 14 | #include "content/browser/gpu/gpu_process_host_ui_shim.h" |
[email protected] | 029bd94 | 2013-01-22 08:30:33 | [diff] [blame] | 15 | #include "content/public/browser/browser_thread.h" |
[email protected] | 7327029 | 2013-08-09 03:48:07 | [diff] [blame] | 16 | #include "content/public/common/content_constants.h" |
[email protected] | 8bf104801 | 2012-02-08 01:22:18 | [diff] [blame] | 17 | #include "content/public/common/url_constants.h" |
[email protected] | 029bd94 | 2013-01-22 08:30:33 | [diff] [blame] | 18 | #include "ppapi/proxy/ppapi_messages.h" |
[email protected] | 707e1c4 | 2013-07-09 21:18:58 | [diff] [blame] | 19 | #include "url/gurl.h" |
[email protected] | 8bf104801 | 2012-02-08 01:22:18 | [diff] [blame] | 20 | |
thestig | c4cac8f | 2014-09-04 21:17:50 | [diff] [blame] | 21 | #if defined(ENABLE_PLUGINS) |
22 | #include "content/browser/ppapi_plugin_process_host.h" | ||||
23 | #endif | ||||
24 | |||||
[email protected] | 8bf104801 | 2012-02-08 01:22:18 | [diff] [blame] | 25 | namespace content { |
26 | |||||
[email protected] | 029bd94 | 2013-01-22 08:30:33 | [diff] [blame] | 27 | namespace { |
28 | |||||
[email protected] | b4b3479 | 2014-06-14 08:29:37 | [diff] [blame] | 29 | // Define the Asan debug URLs. |
30 | const char kAsanCrashDomain[] = "crash"; | ||||
31 | const char kAsanHeapOverflow[] = "/browser-heap-overflow"; | ||||
32 | const char kAsanHeapUnderflow[] = "/browser-heap-underflow"; | ||||
33 | const char kAsanUseAfterFree[] = "/browser-use-after-free"; | ||||
34 | #if defined(SYZYASAN) | ||||
35 | const char kAsanCorruptHeapBlock[] = "/browser-corrupt-heap-block"; | ||||
36 | const char kAsanCorruptHeap[] = "/browser-corrupt-heap"; | ||||
37 | #endif | ||||
38 | |||||
[email protected] | 029bd94 | 2013-01-22 08:30:33 | [diff] [blame] | 39 | void HandlePpapiFlashDebugURL(const GURL& url) { |
40 | #if defined(ENABLE_PLUGINS) | ||||
[email protected] | f8a6d73 | 2013-03-02 22:46:03 | [diff] [blame] | 41 | bool crash = url == GURL(kChromeUIPpapiFlashCrashURL); |
[email protected] | 029bd94 | 2013-01-22 08:30:33 | [diff] [blame] | 42 | |
43 | std::vector<PpapiPluginProcessHost*> hosts; | ||||
[email protected] | 3295612 | 2013-12-25 07:29:24 | [diff] [blame] | 44 | PpapiPluginProcessHost::FindByName( |
45 | base::UTF8ToUTF16(kFlashPluginName), &hosts); | ||||
[email protected] | 029bd94 | 2013-01-22 08:30:33 | [diff] [blame] | 46 | for (std::vector<PpapiPluginProcessHost*>::iterator iter = hosts.begin(); |
47 | iter != hosts.end(); ++iter) { | ||||
48 | if (crash) | ||||
49 | (*iter)->Send(new PpapiMsg_Crash()); | ||||
50 | else | ||||
51 | (*iter)->Send(new PpapiMsg_Hang()); | ||||
52 | } | ||||
53 | #endif | ||||
54 | } | ||||
55 | |||||
[email protected] | b4b3479 | 2014-06-14 08:29:37 | [diff] [blame] | 56 | bool IsAsanDebugURL(const GURL& url) { |
57 | #if defined(SYZYASAN) | ||||
58 | if (!base::debug::IsBinaryInstrumented()) | ||||
59 | return false; | ||||
60 | #endif | ||||
61 | |||||
62 | if (!(url.is_valid() && url.SchemeIs(kChromeUIScheme) && | ||||
63 | url.DomainIs(kAsanCrashDomain, sizeof(kAsanCrashDomain) - 1) && | ||||
64 | url.has_path())) { | ||||
65 | return false; | ||||
66 | } | ||||
67 | |||||
68 | if (url.path() == kAsanHeapOverflow || url.path() == kAsanHeapUnderflow || | ||||
69 | url.path() == kAsanUseAfterFree) { | ||||
70 | return true; | ||||
71 | } | ||||
72 | |||||
73 | #if defined(SYZYASAN) | ||||
74 | if (url.path() == kAsanCorruptHeapBlock || url.path() == kAsanCorruptHeap) | ||||
75 | return true; | ||||
76 | #endif | ||||
77 | |||||
78 | return false; | ||||
79 | } | ||||
80 | |||||
81 | bool HandleAsanDebugURL(const GURL& url) { | ||||
82 | #if defined(SYZYASAN) | ||||
83 | if (!base::debug::IsBinaryInstrumented()) | ||||
84 | return false; | ||||
85 | |||||
86 | if (url.path() == kAsanCorruptHeapBlock) { | ||||
87 | base::debug::AsanCorruptHeapBlock(); | ||||
88 | return true; | ||||
89 | } else if (url.path() == kAsanCorruptHeap) { | ||||
90 | base::debug::AsanCorruptHeap(); | ||||
91 | return true; | ||||
92 | } | ||||
93 | #endif | ||||
94 | |||||
95 | #if defined(ADDRESS_SANITIZER) || defined(SYZYASAN) | ||||
96 | if (url.path() == kAsanHeapOverflow) { | ||||
97 | base::debug::AsanHeapOverflow(); | ||||
98 | } else if (url.path() == kAsanHeapUnderflow) { | ||||
99 | base::debug::AsanHeapUnderflow(); | ||||
100 | } else if (url.path() == kAsanUseAfterFree) { | ||||
101 | base::debug::AsanHeapUseAfterFree(); | ||||
102 | } else { | ||||
103 | return false; | ||||
104 | } | ||||
105 | #endif | ||||
106 | |||||
107 | return true; | ||||
108 | } | ||||
109 | |||||
110 | |||||
[email protected] | 029bd94 | 2013-01-22 08:30:33 | [diff] [blame] | 111 | } // namespace |
112 | |||||
Sylvain Defresne | c6ccc77d | 2014-09-19 10:19:35 | [diff] [blame^] | 113 | bool HandleDebugURL(const GURL& url, ui::PageTransition transition) { |
[email protected] | 4775298 | 2014-07-29 08:01:43 | [diff] [blame] | 114 | // Ensure that the user explicitly navigated to this URL, unless |
115 | // kEnableGpuBenchmarking is enabled by Telemetry. | ||||
[email protected] | 47927870 | 2014-08-11 20:32:09 | [diff] [blame] | 116 | bool is_telemetry_navigation = |
117 | base::CommandLine::ForCurrentProcess()->HasSwitch( | ||||
118 | cc::switches::kEnableGpuBenchmarking) && | ||||
Sylvain Defresne | c6ccc77d | 2014-09-19 10:19:35 | [diff] [blame^] | 119 | (transition & ui::PAGE_TRANSITION_TYPED); |
[email protected] | 8bf104801 | 2012-02-08 01:22:18 | [diff] [blame] | 120 | |
Sylvain Defresne | c6ccc77d | 2014-09-19 10:19:35 | [diff] [blame^] | 121 | if (!(transition & ui::PAGE_TRANSITION_FROM_ADDRESS_BAR) && |
[email protected] | 4775298 | 2014-07-29 08:01:43 | [diff] [blame] | 122 | !is_telemetry_navigation) |
123 | return false; | ||||
[email protected] | eabfe191 | 2014-05-12 10:07:28 | [diff] [blame] | 124 | |
[email protected] | b4b3479 | 2014-06-14 08:29:37 | [diff] [blame] | 125 | if (IsAsanDebugURL(url)) |
126 | return HandleAsanDebugURL(url); | ||||
127 | |||||
[email protected] | 46ed086 | 2013-04-14 02:47:56 | [diff] [blame] | 128 | if (url.host() == kChromeUIBrowserCrashHost) { |
[email protected] | 8bf104801 | 2012-02-08 01:22:18 | [diff] [blame] | 129 | // Induce an intentional crash in the browser process. |
130 | CHECK(false); | ||||
131 | return true; | ||||
132 | } | ||||
133 | |||||
[email protected] | f8a6d73 | 2013-03-02 22:46:03 | [diff] [blame] | 134 | if (url == GURL(kChromeUIGpuCleanURL)) { |
[email protected] | 8bf104801 | 2012-02-08 01:22:18 | [diff] [blame] | 135 | GpuProcessHostUIShim* shim = GpuProcessHostUIShim::GetOneInstance(); |
136 | if (shim) | ||||
137 | shim->SimulateRemoveAllContext(); | ||||
138 | return true; | ||||
139 | } | ||||
140 | |||||
[email protected] | f8a6d73 | 2013-03-02 22:46:03 | [diff] [blame] | 141 | if (url == GURL(kChromeUIGpuCrashURL)) { |
[email protected] | 8bf104801 | 2012-02-08 01:22:18 | [diff] [blame] | 142 | GpuProcessHostUIShim* shim = GpuProcessHostUIShim::GetOneInstance(); |
143 | if (shim) | ||||
144 | shim->SimulateCrash(); | ||||
145 | return true; | ||||
146 | } | ||||
147 | |||||
[email protected] | f8a6d73 | 2013-03-02 22:46:03 | [diff] [blame] | 148 | if (url == GURL(kChromeUIGpuHangURL)) { |
[email protected] | 8bf104801 | 2012-02-08 01:22:18 | [diff] [blame] | 149 | GpuProcessHostUIShim* shim = GpuProcessHostUIShim::GetOneInstance(); |
150 | if (shim) | ||||
151 | shim->SimulateHang(); | ||||
152 | return true; | ||||
153 | } | ||||
154 | |||||
[email protected] | f8a6d73 | 2013-03-02 22:46:03 | [diff] [blame] | 155 | if (url == GURL(kChromeUIPpapiFlashCrashURL) || |
156 | url == GURL(kChromeUIPpapiFlashHangURL)) { | ||||
[email protected] | 029bd94 | 2013-01-22 08:30:33 | [diff] [blame] | 157 | BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
158 | base::Bind(&HandlePpapiFlashDebugURL, url)); | ||||
159 | return true; | ||||
160 | } | ||||
161 | |||||
[email protected] | 8bf104801 | 2012-02-08 01:22:18 | [diff] [blame] | 162 | return false; |
163 | } | ||||
164 | |||||
[email protected] | c02f1ba | 2014-02-03 06:53:53 | [diff] [blame] | 165 | bool IsRendererDebugURL(const GURL& url) { |
166 | if (!url.is_valid()) | ||||
167 | return false; | ||||
168 | |||||
[email protected] | cca6f39 | 2014-05-28 21:32:26 | [diff] [blame] | 169 | if (url.SchemeIs(url::kJavaScriptScheme)) |
[email protected] | c02f1ba | 2014-02-03 06:53:53 | [diff] [blame] | 170 | return true; |
171 | |||||
172 | return url == GURL(kChromeUICrashURL) || | ||||
[email protected] | f0e90cf9 | 2014-07-21 17:13:58 | [diff] [blame] | 173 | url == GURL(kChromeUIDumpURL) || |
[email protected] | c02f1ba | 2014-02-03 06:53:53 | [diff] [blame] | 174 | url == GURL(kChromeUIKillURL) || |
175 | url == GURL(kChromeUIHangURL) || | ||||
176 | url == GURL(kChromeUIShorthangURL); | ||||
177 | } | ||||
178 | |||||
[email protected] | 8bf104801 | 2012-02-08 01:22:18 | [diff] [blame] | 179 | } // namespace content |