Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(47)

Side by Side Diff: chrome/renderer/about_handler.cc

Issue 2814012: Split part of about_handler into chrome/common to break the browser-renderer ... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: with unit test Created 10 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/renderer/about_handler.h ('k') | chrome/renderer/renderer_about_handler_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 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/platform_thread.h" 7 #include "base/platform_thread.h"
8 #include "chrome/common/url_constants.h" 8 #include "chrome/common/about_handler.h"
9 #include "googleurl/src/gurl.h"
10 9
11 struct AboutHandlerUrl { 10 typedef void (*AboutHandlerFuncPtr)();
12 const char *url; 11
13 void (*action)(); 12 // This needs to match up with chrome_about_handler::about_urls in
13 // chrome/common/about_handler.cc.
14 static const AboutHandlerFuncPtr about_urls_handlers[] = {
15 AboutHandler::AboutCrash,
16 AboutHandler::AboutHang,
17 AboutHandler::AboutShortHang,
18 NULL,
14 }; 19 };
15 20
16 static AboutHandlerUrl about_urls[] = { 21 // static
17 { chrome::kAboutCrashURL, AboutHandler::AboutCrash }, 22 bool AboutHandler::MaybeHandle(const GURL& url) {
18 { chrome::kAboutHangURL, AboutHandler::AboutHang }, 23 if (url.scheme() != chrome_about_handler::kAboutScheme)
19 { chrome::kAboutShorthangURL, AboutHandler::AboutShortHang },
20 { NULL, NULL }
21 };
22
23 static const char* kAboutScheme = "about";
24
25 bool AboutHandler::WillHandle(const GURL& url) {
26 if (url.scheme() != kAboutScheme)
27 return false; 24 return false;
28 25
29 struct AboutHandlerUrl* url_handler = about_urls; 26 int about_urls_handler_index = 0;
30 while (url_handler->url) { 27 const char* const* url_handler = chrome_about_handler::about_urls;
31 if (url == GURL(url_handler->url)) 28 while (*url_handler) {
32 return true; 29 if (GURL(*url_handler) == url) {
30 about_urls_handlers[about_urls_handler_index]();
31 return true; // theoretically :]
32 }
33 url_handler++; 33 url_handler++;
34 about_urls_handler_index++;
34 } 35 }
35 return false; 36 return false;
36 } 37 }
37
38 // static
39 bool AboutHandler::MaybeHandle(const GURL& url) {
40 if (url.scheme() != kAboutScheme)
41 return false;
42
43 struct AboutHandlerUrl* url_handler = about_urls;
44 while (url_handler->url) {
45 if (url == GURL(url_handler->url)) {
46 url_handler->action();
47 return true; // theoretically :]
48 }
49 url_handler++;
50 }
51 return false;
52 }
53 38
54 // static 39 // static
55 void AboutHandler::AboutCrash() { 40 void AboutHandler::AboutCrash() {
56 int *zero = NULL; 41 int *zero = NULL;
57 *zero = 0; // Null pointer dereference: kaboom! 42 *zero = 0; // Null pointer dereference: kaboom!
58 } 43 }
59 44
60 // static 45 // static
61 void AboutHandler::AboutHang() { 46 void AboutHandler::AboutHang() {
62 for (;;) { 47 for (;;) {
63 PlatformThread::Sleep(1000); 48 PlatformThread::Sleep(1000);
64 } 49 }
65 } 50 }
66 51
67 // static 52 // static
68 void AboutHandler::AboutShortHang() { 53 void AboutHandler::AboutShortHang() {
69 PlatformThread::Sleep(20000); 54 PlatformThread::Sleep(20000);
70 } 55 }
56
57 // static
58 size_t AboutHandler::AboutURLHandlerSize() {
59 return arraysize(about_urls_handlers);
60 }
OLDNEW
« no previous file with comments | « chrome/renderer/about_handler.h ('k') | chrome/renderer/renderer_about_handler_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698