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