Move about://-related constants from //content to //url
[chromium-blink-merge.git] / content / browser / frame_host / debug_urls.cc
blob0542f9e77570aea15d3cc1faa29a6846c0d2340b
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"
7 #include <vector>
9 #include "base/strings/utf_string_conversions.h"
10 #include "content/browser/gpu/gpu_process_host_ui_shim.h"
11 #include "content/browser/ppapi_plugin_process_host.h"
12 #include "content/public/browser/browser_thread.h"
13 #include "content/public/common/content_constants.h"
14 #include "content/public/common/url_constants.h"
15 #include "ppapi/proxy/ppapi_messages.h"
16 #include "url/gurl.h"
18 namespace content {
20 namespace {
22 void HandlePpapiFlashDebugURL(const GURL& url) {
23 #if defined(ENABLE_PLUGINS)
24 bool crash = url == GURL(kChromeUIPpapiFlashCrashURL);
26 std::vector<PpapiPluginProcessHost*> hosts;
27 PpapiPluginProcessHost::FindByName(
28 base::UTF8ToUTF16(kFlashPluginName), &hosts);
29 for (std::vector<PpapiPluginProcessHost*>::iterator iter = hosts.begin();
30 iter != hosts.end(); ++iter) {
31 if (crash)
32 (*iter)->Send(new PpapiMsg_Crash());
33 else
34 (*iter)->Send(new PpapiMsg_Hang());
36 #endif
39 } // namespace
41 bool HandleDebugURL(const GURL& url, PageTransition transition) {
42 // Ensure that the user explicitly navigated to this URL.
43 if (!(transition & PAGE_TRANSITION_FROM_ADDRESS_BAR))
44 return false;
46 // NOTE: when you add handling of any URLs to this function, also
47 // update IsDebugURL, below.
49 if (url.host() == kChromeUIBrowserCrashHost) {
50 // Induce an intentional crash in the browser process.
51 CHECK(false);
52 return true;
55 if (url == GURL(kChromeUIGpuCleanURL)) {
56 GpuProcessHostUIShim* shim = GpuProcessHostUIShim::GetOneInstance();
57 if (shim)
58 shim->SimulateRemoveAllContext();
59 return true;
62 if (url == GURL(kChromeUIGpuCrashURL)) {
63 GpuProcessHostUIShim* shim = GpuProcessHostUIShim::GetOneInstance();
64 if (shim)
65 shim->SimulateCrash();
66 return true;
69 if (url == GURL(kChromeUIGpuHangURL)) {
70 GpuProcessHostUIShim* shim = GpuProcessHostUIShim::GetOneInstance();
71 if (shim)
72 shim->SimulateHang();
73 return true;
76 if (url == GURL(kChromeUIPpapiFlashCrashURL) ||
77 url == GURL(kChromeUIPpapiFlashHangURL)) {
78 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
79 base::Bind(&HandlePpapiFlashDebugURL, url));
80 return true;
83 return false;
86 bool IsDebugURL(const GURL& url) {
87 // NOTE: when you add any URLs to this list, also update
88 // HandleDebugURL, above.
89 return IsRendererDebugURL(url) ||
90 (url.is_valid() &&
91 (url.host() == kChromeUIBrowserCrashHost ||
92 url == GURL(kChromeUIGpuCleanURL) ||
93 url == GURL(kChromeUIGpuCrashURL) ||
94 url == GURL(kChromeUIGpuHangURL) ||
95 url == GURL(kChromeUIPpapiFlashCrashURL) ||
96 url == GURL(kChromeUIPpapiFlashHangURL)));
99 bool IsRendererDebugURL(const GURL& url) {
100 if (!url.is_valid())
101 return false;
103 if (url.SchemeIs(url::kJavaScriptScheme))
104 return true;
106 return url == GURL(kChromeUICrashURL) ||
107 url == GURL(kChromeUIKillURL) ||
108 url == GURL(kChromeUIHangURL) ||
109 url == GURL(kChromeUIShorthangURL);
112 } // namespace content