OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/about_handler.h" | 5 #include "chrome/renderer/about_handler.h" |
6 | 6 |
7 #include "base/logging.h" | |
8 #include "base/process_util.h" | 7 #include "base/process_util.h" |
9 #include "base/threading/platform_thread.h" | 8 #include "base/threading/platform_thread.h" |
10 #include "chrome/common/about_handler.h" | 9 #include "chrome/common/about_handler.h" |
11 #include "content/common/url_constants.h" | |
12 #include "googleurl/src/gurl.h" | 10 #include "googleurl/src/gurl.h" |
13 | 11 |
14 typedef void (*AboutHandlerFuncPtr)(); | 12 typedef void (*AboutHandlerFuncPtr)(); |
15 | 13 |
16 // This needs to match up with chrome_about_handler::about_urls in | 14 // This needs to match up with chrome_about_handler::about_urls in |
17 // chrome/common/about_handler.cc. | 15 // chrome/common/about_handler.cc. |
18 static const AboutHandlerFuncPtr about_urls_handlers[] = { | 16 static const AboutHandlerFuncPtr about_urls_handlers[] = { |
19 AboutHandler::AboutCrash, | 17 AboutHandler::AboutCrash, |
20 AboutHandler::AboutKill, | 18 AboutHandler::AboutKill, |
21 AboutHandler::AboutHang, | 19 AboutHandler::AboutHang, |
22 AboutHandler::AboutShortHang, | 20 AboutHandler::AboutShortHang, |
23 NULL, | 21 NULL, |
24 }; | 22 }; |
25 | 23 |
26 // static | 24 // static |
27 bool AboutHandler::MaybeHandle(const GURL& url) { | 25 bool AboutHandler::MaybeHandle(const GURL& url) { |
28 if (!url.SchemeIs(chrome::kChromeUIScheme)) | 26 if (url.scheme() != chrome_about_handler::kAboutScheme) |
29 return false; | 27 return false; |
30 | 28 |
31 int about_urls_handler_index = 0; | 29 int about_urls_handler_index = 0; |
32 const char* const* url_handler = chrome_about_handler::about_urls; | 30 const char* const* url_handler = chrome_about_handler::about_urls; |
33 while (*url_handler) { | 31 while (*url_handler) { |
34 if (GURL(*url_handler) == url) { | 32 if (GURL(*url_handler) == url) { |
35 about_urls_handlers[about_urls_handler_index](); | 33 about_urls_handlers[about_urls_handler_index](); |
36 return true; // theoretically :] | 34 return true; // theoretically :] |
37 } | 35 } |
38 url_handler++; | 36 url_handler++; |
39 about_urls_handler_index++; | 37 about_urls_handler_index++; |
40 } | 38 } |
41 return false; | 39 return false; |
42 } | 40 } |
43 | 41 |
44 // static | 42 // static |
45 void AboutHandler::AboutCrash() { | 43 void AboutHandler::AboutCrash() { |
46 CHECK(false); | 44 int *zero = NULL; |
| 45 *zero = 0; // Null pointer dereference: kaboom! |
47 } | 46 } |
48 | 47 |
49 // static | 48 // static |
50 void AboutHandler::AboutKill() { | 49 void AboutHandler::AboutKill() { |
51 base::KillProcess(base::GetCurrentProcessHandle(), 1, false); | 50 base::KillProcess(base::GetCurrentProcessHandle(), 1, false); |
52 } | 51 } |
53 | 52 |
54 // static | 53 // static |
55 void AboutHandler::AboutHang() { | 54 void AboutHandler::AboutHang() { |
56 for (;;) { | 55 for (;;) { |
57 base::PlatformThread::Sleep(1000); | 56 base::PlatformThread::Sleep(1000); |
58 } | 57 } |
59 } | 58 } |
60 | 59 |
61 // static | 60 // static |
62 void AboutHandler::AboutShortHang() { | 61 void AboutHandler::AboutShortHang() { |
63 base::PlatformThread::Sleep(20000); | 62 base::PlatformThread::Sleep(20000); |
64 } | 63 } |
65 | 64 |
66 // static | 65 // static |
67 size_t AboutHandler::AboutURLHandlerSize() { | 66 size_t AboutHandler::AboutURLHandlerSize() { |
68 return arraysize(about_urls_handlers); | 67 return arraysize(about_urls_handlers); |
69 } | 68 } |
OLD | NEW |