diff options
author | thestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-18 04:09:14 +0000 |
---|---|---|
committer | thestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-18 04:09:14 +0000 |
commit | 3e0f7d520ae052fa4f092d75e61ca3605109f44f (patch) | |
tree | 8272de51d40a9f8ca4e6d3ab94e34fa20693669e /chrome | |
parent | 5ed60cdb3f706f8e033d67d5f4e3b4663fa7630d (diff) | |
download | chromium_src-3e0f7d520ae052fa4f092d75e61ca3605109f44f.zip chromium_src-3e0f7d520ae052fa4f092d75e61ca3605109f44f.tar.gz chromium_src-3e0f7d520ae052fa4f092d75e61ca3605109f44f.tar.bz2 |
Split part of about_handler into chrome/common to break the browser-renderer dependency.
BUG=46666
TEST=none
Review URL: http://codereview.chromium.org/2814012
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@50209 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/browser_about_handler.cc | 15 | ||||
-rw-r--r-- | chrome/browser/browser_about_handler_unittest.cc | 5 | ||||
-rw-r--r-- | chrome/chrome_common.gypi | 6 | ||||
-rwxr-xr-x | chrome/chrome_tests.gypi | 1 | ||||
-rw-r--r-- | chrome/common/about_handler.cc | 34 | ||||
-rw-r--r-- | chrome/common/about_handler.h | 23 | ||||
-rw-r--r-- | chrome/renderer/about_handler.cc | 52 | ||||
-rw-r--r-- | chrome/renderer/about_handler.h | 7 | ||||
-rw-r--r-- | chrome/renderer/renderer_about_handler_unittest.cc | 20 |
9 files changed, 115 insertions, 48 deletions
diff --git a/chrome/browser/browser_about_handler.cc b/chrome/browser/browser_about_handler.cc index 0b744ed..b15e08b 100644 --- a/chrome/browser/browser_about_handler.cc +++ b/chrome/browser/browser_about_handler.cc @@ -4,6 +4,7 @@ #include "chrome/browser/browser_about_handler.h" +#include <algorithm> #include <string> #include <vector> @@ -37,12 +38,12 @@ #include "chrome/browser/renderer_host/render_process_host.h" #include "chrome/browser/renderer_host/render_view_host.h" #include "chrome/browser/sync/profile_sync_service.h" +#include "chrome/common/about_handler.h" #include "chrome/common/chrome_paths.h" #include "chrome/common/jstemplate_builder.h" #include "chrome/common/pref_names.h" #include "chrome/common/render_messages.h" #include "chrome/common/url_constants.h" -#include "chrome/renderer/about_handler.h" #include "googleurl/src/gurl.h" #include "grit/browser_resources.h" #include "grit/chromium_strings.h" @@ -53,17 +54,13 @@ #include "v8/include/v8.h" #endif -#if defined(OS_CHROMEOS) -#include "chrome/browser/chromeos/cros/syslogs_library.h" -#include "chrome/browser/chromeos/cros/cros_library.h" -#endif - #if defined(OS_WIN) #include "chrome/browser/views/about_ipc_dialog.h" #include "chrome/browser/views/about_network_dialog.h" #elif defined(OS_CHROMEOS) #include "chrome/browser/chromeos/cros/cros_library.h" #include "chrome/browser/chromeos/cros/network_library.h" +#include "chrome/browser/chromeos/cros/syslogs_library.h" #include "chrome/browser/chromeos/version_loader.h" #elif defined(OS_MACOSX) #include "chrome/browser/cocoa/about_ipc_dialog.h" @@ -200,7 +197,7 @@ class ChromeOSAboutVersionHandler { chromeos::VersionLoader loader_; // Used to request the version. - CancelableRequestConsumer consumer_; + CancelableRequestConsumer consumer_; DISALLOW_COPY_AND_ASSIGN(ChromeOSAboutVersionHandler); }; @@ -368,7 +365,7 @@ std::string AboutStats() { std::string full_name = table->GetRowName(index); if (full_name.length() == 0) break; - DCHECK(full_name[1] == ':'); + DCHECK_EQ(':', full_name[1]); char counter_type = full_name[0]; std::string name = full_name.substr(2); @@ -996,7 +993,7 @@ bool WillHandleBrowserAboutURL(GURL* url, Profile* profile) { // There are a few about: URLs that we hand over to the renderer. If the // renderer wants them, don't do any rewriting. - if (AboutHandler::WillHandle(*url)) + if (chrome_about_handler::WillHandle(*url)) return false; // Anything else requires our special handler, make sure its initialized. diff --git a/chrome/browser/browser_about_handler_unittest.cc b/chrome/browser/browser_about_handler_unittest.cc index d83125b..be08e564f 100644 --- a/chrome/browser/browser_about_handler_unittest.cc +++ b/chrome/browser/browser_about_handler_unittest.cc @@ -5,8 +5,8 @@ #include "base/basictypes.h" #include "base/scoped_ptr.h" #include "chrome/browser/browser_about_handler.h" +#include "chrome/common/about_handler.h" #include "chrome/common/url_constants.h" -#include "chrome/renderer/about_handler.h" #include "googleurl/src/gurl.h" #include "testing/gtest/include/gtest/gtest.h" @@ -87,7 +87,8 @@ TEST(BrowserAboutHandlerTest, WillHandleBrowserAboutURL) { for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) { GURL url(test_data[i].test_url); - EXPECT_EQ(test_data[i].about_handled, AboutHandler::WillHandle(url)); + EXPECT_EQ(test_data[i].about_handled, + chrome_about_handler::WillHandle(url)); EXPECT_EQ(test_data[i].browser_handled, WillHandleBrowserAboutURL(&url, NULL)); EXPECT_EQ(test_data[i].result_url, url); diff --git a/chrome/chrome_common.gypi b/chrome/chrome_common.gypi index b491315..b97a423 100644 --- a/chrome/chrome_common.gypi +++ b/chrome/chrome_common.gypi @@ -23,6 +23,8 @@ # .cc, .h, and .mm files under chrome/common that are used on all # platforms, including both 32-bit and 64-bit Windows. # Test files are not included. + 'common/about_handler.cc', + 'common/about_handler.h', 'common/app_mode_common_mac.h', 'common/app_mode_common_mac.mm', 'common/bindings_policy.h', @@ -59,7 +61,7 @@ 'common/message_router.cc', 'common/message_router.h', 'common/metrics_helpers.cc', - 'common/metrics_helpers.h', + 'common/metrics_helpers.h', 'common/nacl_cmd_line.cc', 'common/nacl_cmd_line.h', 'common/nacl_messages.h', @@ -371,7 +373,7 @@ '../app/app.gyp:app_resources', '../base/base.gyp:base_nacl_win64', '../ipc/ipc.gyp:ipc_win64', - '../third_party/libxml/libxml.gyp:libxml', + '../third_party/libxml/libxml.gyp:libxml', ], 'include_dirs': [ '../third_party/npapi', diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index 30ba481..fe8926f 100755 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -1038,6 +1038,7 @@ 'renderer/render_view_unittest.cc', 'renderer/render_view_unittest_mac.mm', 'renderer/render_widget_unittest.cc', + 'renderer/renderer_about_handler_unittest.cc', 'renderer/renderer_main_unittest.cc', 'renderer/spellchecker/spellcheck_unittest.cc', 'renderer/spellchecker/spellcheck_worditerator_unittest.cc', diff --git a/chrome/common/about_handler.cc b/chrome/common/about_handler.cc new file mode 100644 index 0000000..84658a0 --- /dev/null +++ b/chrome/common/about_handler.cc @@ -0,0 +1,34 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/common/about_handler.h" + +namespace chrome_about_handler { + +// This needs to match up with about_urls_handlers in +// chrome/renderer/about_handler.cc. +const char* const about_urls[] = { + chrome::kAboutCrashURL, + chrome::kAboutHangURL, + chrome::kAboutShorthangURL, + NULL, +}; +const size_t about_urls_size = arraysize(about_urls); + +const char* const kAboutScheme = "about"; + +bool WillHandle(const GURL& url) { + if (url.scheme() != kAboutScheme) + return false; + + const char* const* url_handler = about_urls; + while (*url_handler) { + if (GURL(*url_handler) == url) + return true; + url_handler++; + } + return false; +} + +} // namespace chrome_about_handler diff --git a/chrome/common/about_handler.h b/chrome/common/about_handler.h new file mode 100644 index 0000000..f5d0818 --- /dev/null +++ b/chrome/common/about_handler.h @@ -0,0 +1,23 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_COMMON_ABOUT_HANDLER_H__ +#define CHROME_COMMON_ABOUT_HANDLER_H__ + +#include "chrome/common/url_constants.h" +#include "googleurl/src/gurl.h" + +namespace chrome_about_handler { + +extern const char* const about_urls[]; +extern const size_t about_urls_size; // Only used for testing +extern const char* const kAboutScheme; + +// Returns true if the URL is one that AboutHandler will handle when +// AboutHandler::MaybeHandle is called. +bool WillHandle(const GURL& url); + +} // namespace chrome_about_handler + +#endif // CHROME_COMMON_ABOUT_HANDLER_H__ diff --git a/chrome/renderer/about_handler.cc b/chrome/renderer/about_handler.cc index 8412949..56618df 100644 --- a/chrome/renderer/about_handler.cc +++ b/chrome/renderer/about_handler.cc @@ -5,48 +5,33 @@ #include "chrome/renderer/about_handler.h" #include "base/platform_thread.h" -#include "chrome/common/url_constants.h" -#include "googleurl/src/gurl.h" +#include "chrome/common/about_handler.h" -struct AboutHandlerUrl { - const char *url; - void (*action)(); -}; +typedef void (*AboutHandlerFuncPtr)(); -static AboutHandlerUrl about_urls[] = { - { chrome::kAboutCrashURL, AboutHandler::AboutCrash }, - { chrome::kAboutHangURL, AboutHandler::AboutHang }, - { chrome::kAboutShorthangURL, AboutHandler::AboutShortHang }, - { NULL, NULL } +// This needs to match up with chrome_about_handler::about_urls in +// chrome/common/about_handler.cc. +static const AboutHandlerFuncPtr about_urls_handlers[] = { + AboutHandler::AboutCrash, + AboutHandler::AboutHang, + AboutHandler::AboutShortHang, + NULL, }; -static const char* kAboutScheme = "about"; - -bool AboutHandler::WillHandle(const GURL& url) { - if (url.scheme() != kAboutScheme) - return false; - - struct AboutHandlerUrl* url_handler = about_urls; - while (url_handler->url) { - if (url == GURL(url_handler->url)) - return true; - url_handler++; - } - return false; -} - // static bool AboutHandler::MaybeHandle(const GURL& url) { - if (url.scheme() != kAboutScheme) + if (url.scheme() != chrome_about_handler::kAboutScheme) return false; - struct AboutHandlerUrl* url_handler = about_urls; - while (url_handler->url) { - if (url == GURL(url_handler->url)) { - url_handler->action(); + int about_urls_handler_index = 0; + const char* const* url_handler = chrome_about_handler::about_urls; + while (*url_handler) { + if (GURL(*url_handler) == url) { + about_urls_handlers[about_urls_handler_index](); return true; // theoretically :] } url_handler++; + about_urls_handler_index++; } return false; } @@ -68,3 +53,8 @@ void AboutHandler::AboutHang() { void AboutHandler::AboutShortHang() { PlatformThread::Sleep(20000); } + +// static +size_t AboutHandler::AboutURLHandlerSize() { + return arraysize(about_urls_handlers); +} diff --git a/chrome/renderer/about_handler.h b/chrome/renderer/about_handler.h index 3c811b3..270b4b1 100644 --- a/chrome/renderer/about_handler.h +++ b/chrome/renderer/about_handler.h @@ -20,10 +20,6 @@ class AboutHandler { // true if the URL was handled. static bool MaybeHandle(const GURL& url); - // Returns true if the URL is one that this AboutHandler will handle when - // MaybeHandle is called. - static bool WillHandle(const GURL& url); - // Induces a renderer crash. static void AboutCrash(); @@ -33,6 +29,9 @@ class AboutHandler { // Induces a brief (20 second) hang to make sure hang monitors go away. static void AboutShortHang(); + // Returns the size of |about_urls_handlers|. Used for testing only. + static size_t AboutURLHandlerSize(); + private: AboutHandler(); ~AboutHandler(); diff --git a/chrome/renderer/renderer_about_handler_unittest.cc b/chrome/renderer/renderer_about_handler_unittest.cc new file mode 100644 index 0000000..633663c --- /dev/null +++ b/chrome/renderer/renderer_about_handler_unittest.cc @@ -0,0 +1,20 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/common/about_handler.h" +#include "chrome/renderer/about_handler.h" +#include "testing/gtest/include/gtest/gtest.h" + +// This is just to make sure the about_urls array in +// chrome/common/about_handler.cc matches up with the about_urls_handlers +// in chrome/renderer/about_handler.cc. They used to be in one array, but +// we broke them apart to break a browser <-> renderer dependency. +// We cannot test this with COMPILE_ASSERT because +// chrome/renderer/about_handler.cc doesn't know about the size of about_urls +// in chrome/common/about_handler.cc at compile time. + +TEST(RendererAboutHandlerTest, AboutUrlHandlerArray) { + ASSERT_EQ(chrome_about_handler::about_urls_size, + AboutHandler::AboutURLHandlerSize()); +} |