blob: 6bfc3cc3719ec2d63950f568ef7e311e199ad48f [file] [log] [blame]
[email protected]d4a8ca482013-10-30 21:06:401// Copyright 2013 The Chromium Authors. All rights reserved.
[email protected]8bf1048012012-02-08 01:22:182// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]d4a8ca482013-10-30 21:06:405#include "content/browser/frame_host/debug_urls.h"
[email protected]8bf1048012012-02-08 01:22:186
[email protected]029bd942013-01-22 08:30:337#include <vector>
8
[email protected]47752982014-07-29 08:01:439#include "base/command_line.h"
[email protected]b4b34792014-06-14 08:29:3710#include "base/debug/asan_invalid_access.h"
11#include "base/debug/profiler.h"
[email protected]74ebfb12013-06-07 20:48:0012#include "base/strings/utf_string_conversions.h"
[email protected]47752982014-07-29 08:01:4313#include "cc/base/switches.h"
[email protected]8bf1048012012-02-08 01:22:1814#include "content/browser/gpu/gpu_process_host_ui_shim.h"
[email protected]029bd942013-01-22 08:30:3315#include "content/public/browser/browser_thread.h"
[email protected]73270292013-08-09 03:48:0716#include "content/public/common/content_constants.h"
[email protected]8bf1048012012-02-08 01:22:1817#include "content/public/common/url_constants.h"
[email protected]029bd942013-01-22 08:30:3318#include "ppapi/proxy/ppapi_messages.h"
[email protected]707e1c42013-07-09 21:18:5819#include "url/gurl.h"
[email protected]8bf1048012012-02-08 01:22:1820
thestigc4cac8f2014-09-04 21:17:5021#if defined(ENABLE_PLUGINS)
22#include "content/browser/ppapi_plugin_process_host.h"
23#endif
24
[email protected]8bf1048012012-02-08 01:22:1825namespace content {
26
[email protected]029bd942013-01-22 08:30:3327namespace {
28
[email protected]b4b34792014-06-14 08:29:3729// Define the Asan debug URLs.
30const char kAsanCrashDomain[] = "crash";
31const char kAsanHeapOverflow[] = "/browser-heap-overflow";
32const char kAsanHeapUnderflow[] = "/browser-heap-underflow";
33const char kAsanUseAfterFree[] = "/browser-use-after-free";
34#if defined(SYZYASAN)
35const char kAsanCorruptHeapBlock[] = "/browser-corrupt-heap-block";
36const char kAsanCorruptHeap[] = "/browser-corrupt-heap";
37#endif
38
[email protected]029bd942013-01-22 08:30:3339void HandlePpapiFlashDebugURL(const GURL& url) {
40#if defined(ENABLE_PLUGINS)
[email protected]f8a6d732013-03-02 22:46:0341 bool crash = url == GURL(kChromeUIPpapiFlashCrashURL);
[email protected]029bd942013-01-22 08:30:3342
43 std::vector<PpapiPluginProcessHost*> hosts;
[email protected]32956122013-12-25 07:29:2444 PpapiPluginProcessHost::FindByName(
45 base::UTF8ToUTF16(kFlashPluginName), &hosts);
[email protected]029bd942013-01-22 08:30:3346 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]b4b34792014-06-14 08:29:3756bool 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
81bool 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]029bd942013-01-22 08:30:33111} // namespace
112
Sylvain Defresnec6ccc77d2014-09-19 10:19:35113bool HandleDebugURL(const GURL& url, ui::PageTransition transition) {
[email protected]47752982014-07-29 08:01:43114 // Ensure that the user explicitly navigated to this URL, unless
115 // kEnableGpuBenchmarking is enabled by Telemetry.
[email protected]479278702014-08-11 20:32:09116 bool is_telemetry_navigation =
117 base::CommandLine::ForCurrentProcess()->HasSwitch(
118 cc::switches::kEnableGpuBenchmarking) &&
Sylvain Defresnec6ccc77d2014-09-19 10:19:35119 (transition & ui::PAGE_TRANSITION_TYPED);
[email protected]8bf1048012012-02-08 01:22:18120
Sylvain Defresnec6ccc77d2014-09-19 10:19:35121 if (!(transition & ui::PAGE_TRANSITION_FROM_ADDRESS_BAR) &&
[email protected]47752982014-07-29 08:01:43122 !is_telemetry_navigation)
123 return false;
[email protected]eabfe1912014-05-12 10:07:28124
[email protected]b4b34792014-06-14 08:29:37125 if (IsAsanDebugURL(url))
126 return HandleAsanDebugURL(url);
127
[email protected]46ed0862013-04-14 02:47:56128 if (url.host() == kChromeUIBrowserCrashHost) {
[email protected]8bf1048012012-02-08 01:22:18129 // Induce an intentional crash in the browser process.
130 CHECK(false);
131 return true;
132 }
133
[email protected]f8a6d732013-03-02 22:46:03134 if (url == GURL(kChromeUIGpuCleanURL)) {
[email protected]8bf1048012012-02-08 01:22:18135 GpuProcessHostUIShim* shim = GpuProcessHostUIShim::GetOneInstance();
136 if (shim)
137 shim->SimulateRemoveAllContext();
138 return true;
139 }
140
[email protected]f8a6d732013-03-02 22:46:03141 if (url == GURL(kChromeUIGpuCrashURL)) {
[email protected]8bf1048012012-02-08 01:22:18142 GpuProcessHostUIShim* shim = GpuProcessHostUIShim::GetOneInstance();
143 if (shim)
144 shim->SimulateCrash();
145 return true;
146 }
147
[email protected]f8a6d732013-03-02 22:46:03148 if (url == GURL(kChromeUIGpuHangURL)) {
[email protected]8bf1048012012-02-08 01:22:18149 GpuProcessHostUIShim* shim = GpuProcessHostUIShim::GetOneInstance();
150 if (shim)
151 shim->SimulateHang();
152 return true;
153 }
154
[email protected]f8a6d732013-03-02 22:46:03155 if (url == GURL(kChromeUIPpapiFlashCrashURL) ||
156 url == GURL(kChromeUIPpapiFlashHangURL)) {
[email protected]029bd942013-01-22 08:30:33157 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
158 base::Bind(&HandlePpapiFlashDebugURL, url));
159 return true;
160 }
161
[email protected]8bf1048012012-02-08 01:22:18162 return false;
163}
164
[email protected]c02f1ba2014-02-03 06:53:53165bool IsRendererDebugURL(const GURL& url) {
166 if (!url.is_valid())
167 return false;
168
[email protected]cca6f392014-05-28 21:32:26169 if (url.SchemeIs(url::kJavaScriptScheme))
[email protected]c02f1ba2014-02-03 06:53:53170 return true;
171
172 return url == GURL(kChromeUICrashURL) ||
[email protected]f0e90cf92014-07-21 17:13:58173 url == GURL(kChromeUIDumpURL) ||
[email protected]c02f1ba2014-02-03 06:53:53174 url == GURL(kChromeUIKillURL) ||
175 url == GURL(kChromeUIHangURL) ||
176 url == GURL(kChromeUIShorthangURL);
177}
178
[email protected]8bf1048012012-02-08 01:22:18179} // namespace content