diff options
author | yoz@chromium.org <yoz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-13 00:34:35 +0000 |
---|---|---|
committer | yoz@chromium.org <yoz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-13 00:34:35 +0000 |
commit | 083917c81339b1349c300b191f3ddc9c333c16d7 (patch) | |
tree | 7af7bfe39855cce5a69699349987b768bb4f2273 /chrome/browser | |
parent | 3d07d6b4e56e29cddad26ad679b400d7e5aa4e22 (diff) | |
download | chromium_src-083917c81339b1349c300b191f3ddc9c333c16d7.zip chromium_src-083917c81339b1349c300b191f3ddc9c333c16d7.tar.gz chromium_src-083917c81339b1349c300b191f3ddc9c333c16d7.tar.bz2 |
Move protocol_handler from chrome/browser to chrome/common so that extensions can use it.
BUG=86115
TEST=existing tests
Review URL: http://codereview.chromium.org/7275036
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@92281 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
8 files changed, 6 insertions, 145 deletions
diff --git a/chrome/browser/custom_handlers/protocol_handler.cc b/chrome/browser/custom_handlers/protocol_handler.cc deleted file mode 100644 index a2a076d..0000000 --- a/chrome/browser/custom_handlers/protocol_handler.cc +++ /dev/null @@ -1,76 +0,0 @@ -// Copyright (c) 2011 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/browser/custom_handlers/protocol_handler.h" - -#include "base/string_util.h" -#include "base/utf_string_conversions.h" -#include "net/base/escape.h" - -ProtocolHandler::ProtocolHandler(const std::string& protocol, - const GURL& url, - const string16& title) - : protocol_(protocol), - url_(url), - title_(title) { -} - -ProtocolHandler ProtocolHandler::CreateProtocolHandler( - const std::string& protocol, - const GURL& url, - const string16& title) { - std::string lower_protocol = StringToLowerASCII(protocol); - return ProtocolHandler(lower_protocol, url, title); -} - -ProtocolHandler::ProtocolHandler() { -} - -bool ProtocolHandler::IsValidDict(const DictionaryValue* value) { - return value->HasKey("protocol") && value->HasKey("url") && - value->HasKey("title"); -} - -const ProtocolHandler& ProtocolHandler::EmptyProtocolHandler() { - static const ProtocolHandler* const kEmpty = new ProtocolHandler(); - return *kEmpty; -} - -ProtocolHandler ProtocolHandler::CreateProtocolHandler( - const DictionaryValue* value) { - if (!IsValidDict(value)) { - return EmptyProtocolHandler(); - } - std::string protocol, url; - string16 title; - value->GetString("protocol", &protocol); - value->GetString("url", &url); - value->GetString("title", &title); - return ProtocolHandler::CreateProtocolHandler(protocol, GURL(url), title); -} - -GURL ProtocolHandler::TranslateUrl(const GURL& url) const { - std::string translatedUrlSpec(url_.spec()); - ReplaceSubstringsAfterOffset(&translatedUrlSpec, 0, "%s", - EscapeQueryParamValue(url.spec(), true)); - return GURL(translatedUrlSpec); -} - -DictionaryValue* ProtocolHandler::Encode() const { - DictionaryValue* d = new DictionaryValue(); - d->Set("protocol", Value::CreateStringValue(protocol_)); - d->Set("url", Value::CreateStringValue(url_.spec())); - d->Set("title", Value::CreateStringValue(title_)); - return d; -} - -bool ProtocolHandler::operator==(const ProtocolHandler& other) const { - return protocol_ == other.protocol_ && - url_ == other.url_ && - title_ == other.title_; -} - -bool ProtocolHandler::operator<(const ProtocolHandler& other) const { - return title_ < other.title_; -} diff --git a/chrome/browser/custom_handlers/protocol_handler.h b/chrome/browser/custom_handlers/protocol_handler.h deleted file mode 100644 index 2798399..0000000 --- a/chrome/browser/custom_handlers/protocol_handler.h +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright (c) 2011 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_BROWSER_CUSTOM_HANDLERS_PROTOCOL_HANDLER_H_ -#define CHROME_BROWSER_CUSTOM_HANDLERS_PROTOCOL_HANDLER_H_ -#pragma once - -#include <string> - -#include "base/values.h" -#include "googleurl/src/gurl.h" - -// A single tuple of (protocol, url, title) that indicates how URLs of the -// given protocol should be rewritten to be handled. - -class ProtocolHandler { - public: - static ProtocolHandler CreateProtocolHandler(const std::string& protocol, - const GURL& url, - const string16& title); - - // Creates a ProtocolHandler with fields from the dictionary. Returns an - // empty ProtocolHandler if the input is invalid. - static ProtocolHandler CreateProtocolHandler(const DictionaryValue* value); - - // Returns true if the dictionary value has all the necessary fields to - // define a ProtocolHandler. - static bool IsValidDict(const DictionaryValue* value); - - // Canonical empty ProtocolHandler. - static const ProtocolHandler& EmptyProtocolHandler(); - - // Interpolates the given URL into the URL template of this handler. - GURL TranslateUrl(const GURL& url) const; - - // Encodes this protocol handler as a DictionaryValue. The caller is - // responsible for deleting the returned value. - DictionaryValue* Encode() const; - - const std::string& protocol() const { return protocol_; } - const GURL& url() const { return url_;} - const string16& title() const { return title_; } - - bool IsEmpty() const { - return protocol_.empty(); - } - - bool operator==(const ProtocolHandler& other) const; - bool operator<(const ProtocolHandler& other) const; - - private: - ProtocolHandler(const std::string& protocol, - const GURL& url, - const string16& title); - ProtocolHandler(); - - std::string protocol_; - GURL url_; - string16 title_; -}; - -#endif // CHROME_BROWSER_CUSTOM_HANDLERS_PROTOCOL_HANDLER_H_ diff --git a/chrome/browser/custom_handlers/protocol_handler_registry.cc b/chrome/browser/custom_handlers/protocol_handler_registry.cc index bc20774..d7a10b8 100644 --- a/chrome/browser/custom_handlers/protocol_handler_registry.cc +++ b/chrome/browser/custom_handlers/protocol_handler_registry.cc @@ -10,13 +10,13 @@ #include "base/logging.h" #include "base/memory/scoped_ptr.h" #include "base/stl_util-inl.h" -#include "chrome/browser/custom_handlers/protocol_handler.h" #include "chrome/browser/custom_handlers/register_protocol_handler_infobar_delegate.h" #include "chrome/browser/net/chrome_url_request_context.h" #include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/profiles/profile_io_data.h" #include "chrome/common/chrome_notification_types.h" #include "chrome/common/chrome_switches.h" +#include "chrome/common/custom_handlers/protocol_handler.h" #include "chrome/common/pref_names.h" #include "content/browser/browser_thread.h" #include "content/browser/child_process_security_policy.h" diff --git a/chrome/browser/custom_handlers/protocol_handler_registry.h b/chrome/browser/custom_handlers/protocol_handler_registry.h index 391bd19..4b51af5 100644 --- a/chrome/browser/custom_handlers/protocol_handler_registry.h +++ b/chrome/browser/custom_handlers/protocol_handler_registry.h @@ -13,9 +13,9 @@ #include "base/basictypes.h" #include "base/memory/ref_counted.h" #include "base/values.h" -#include "chrome/browser/custom_handlers/protocol_handler.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/shell_integration.h" +#include "chrome/common/custom_handlers/protocol_handler.h" #include "content/browser/browser_thread.h" #include "content/common/notification_service.h" #include "net/url_request/url_request.h" diff --git a/chrome/browser/custom_handlers/protocol_handler_registry_unittest.cc b/chrome/browser/custom_handlers/protocol_handler_registry_unittest.cc index 93a7ba8..15319a6 100644 --- a/chrome/browser/custom_handlers/protocol_handler_registry_unittest.cc +++ b/chrome/browser/custom_handlers/protocol_handler_registry_unittest.cc @@ -11,8 +11,8 @@ #include "base/scoped_ptr.h" #include "base/task.h" #include "base/utf_string_conversions.h" -#include "chrome/browser/custom_handlers/protocol_handler.h" #include "chrome/common/chrome_notification_types.h" +#include "chrome/common/custom_handlers/protocol_handler.h" #include "chrome/test/testing_browser_process.h" #include "chrome/test/testing_browser_process_test.h" #include "chrome/test/testing_pref_service.h" diff --git a/chrome/browser/custom_handlers/register_protocol_handler_infobar_delegate.h b/chrome/browser/custom_handlers/register_protocol_handler_infobar_delegate.h index d194a86..c49ec69 100644 --- a/chrome/browser/custom_handlers/register_protocol_handler_infobar_delegate.h +++ b/chrome/browser/custom_handlers/register_protocol_handler_infobar_delegate.h @@ -7,8 +7,8 @@ #pragma once #include "base/string16.h" -#include "chrome/browser/custom_handlers/protocol_handler.h" #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" +#include "chrome/common/custom_handlers/protocol_handler.h" class ProtocolHandlerRegistry; class TabContents; diff --git a/chrome/browser/ui/tab_contents/tab_contents_wrapper.cc b/chrome/browser/ui/tab_contents/tab_contents_wrapper.cc index c34f832..3dfc4ba 100644 --- a/chrome/browser/ui/tab_contents/tab_contents_wrapper.cc +++ b/chrome/browser/ui/tab_contents/tab_contents_wrapper.cc @@ -11,7 +11,6 @@ #include "chrome/browser/automation/automation_tab_helper.h" #include "chrome/browser/browser_shutdown.h" #include "chrome/browser/content_settings/tab_specific_content_settings.h" -#include "chrome/browser/custom_handlers/protocol_handler.h" #include "chrome/browser/custom_handlers/protocol_handler_registry.h" #include "chrome/browser/custom_handlers/register_protocol_handler_infobar_delegate.h" #include "chrome/browser/extensions/extension_tab_helper.h" @@ -49,6 +48,7 @@ #include "chrome/browser/ui/tab_contents/tab_contents_wrapper_delegate.h" #include "chrome/common/chrome_notification_types.h" #include "chrome/common/chrome_switches.h" +#include "chrome/common/custom_handlers/protocol_handler.h" #include "chrome/common/pref_names.h" #include "chrome/common/render_messages.h" #include "content/browser/child_process_security_policy.h" diff --git a/chrome/browser/ui/webui/options/handler_options_handler.h b/chrome/browser/ui/webui/options/handler_options_handler.h index f7cb567..f0ab822 100644 --- a/chrome/browser/ui/webui/options/handler_options_handler.h +++ b/chrome/browser/ui/webui/options/handler_options_handler.h @@ -7,9 +7,9 @@ #include <string> -#include "chrome/browser/custom_handlers/protocol_handler.h" #include "chrome/browser/custom_handlers/protocol_handler_registry.h" #include "chrome/browser/ui/webui/options/options_ui.h" +#include "chrome/common/custom_handlers/protocol_handler.h" #include "content/common/notification_registrar.h" namespace base { |