Index: chrome/browser/chrome_content_browser_client.cc |
diff --git a/chrome/browser/chrome_content_browser_client.cc b/chrome/browser/chrome_content_browser_client.cc |
index 361ad7b19d015e51e1c38617c230bb872950d698..b0cc3931595b5d06865593c69febe2889a953275 100644 |
--- a/chrome/browser/chrome_content_browser_client.cc |
+++ b/chrome/browser/chrome_content_browser_client.cc |
@@ -13,9 +13,7 @@ |
#include "base/lazy_instance.h" |
#include "base/path_service.h" |
#include "base/prefs/pref_service.h" |
-#include "base/sha1.h" |
#include "base/string_number_conversions.h" |
-#include "base/strings/string_tokenizer.h" |
#include "base/utf_string_conversions.h" |
#include "chrome/app/breakpad_mac.h" |
#include "chrome/browser/app_mode/app_mode_utils.h" |
@@ -50,6 +48,7 @@ |
#include "chrome/browser/net/chrome_net_log.h" |
#include "chrome/browser/notifications/desktop_notification_service.h" |
#include "chrome/browser/notifications/desktop_notification_service_factory.h" |
+#include "chrome/browser/pepper_util.h" |
#include "chrome/browser/platform_util.h" |
#include "chrome/browser/plugins/plugin_info_message_filter.h" |
#include "chrome/browser/prefs/scoped_user_pref_update.h" |
@@ -462,16 +461,6 @@ void SetApplicationLocaleOnIOThread(const std::string& locale) { |
g_io_thread_application_locale.Get() = locale; |
} |
-std::string HashHost(const std::string& host) { |
- const std::string id_hash = base::SHA1HashString(host); |
- DCHECK(id_hash.length() == base::kSHA1Length); |
- return base::HexEncode(id_hash.c_str(), id_hash.length()); |
-} |
- |
-bool HostIsInSet(const std::string& host, const std::set<std::string>& set) { |
- return set.count(host) > 0 || set.count(HashHost(host)) > 0; |
-} |
- |
} // namespace |
namespace chrome { |
@@ -2132,60 +2121,12 @@ bool ChromeContentBrowserClient::AllowPepperSocketAPI( |
content::BrowserContext* browser_context, |
const GURL& url, |
const content::SocketPermissionRequest& params) { |
- if (!url.is_valid()) |
- return false; |
- |
- std::string host = url.host(); |
- if (url.SchemeIs(extensions::kExtensionScheme) && |
- HostIsInSet(host, allowed_socket_origins_)) { |
- return true; |
- } |
- |
- Profile* profile = Profile::FromBrowserContext(browser_context); |
- const Extension* extension = NULL; |
- ExtensionService* extension_service = !profile ? NULL : |
- extensions::ExtensionSystem::Get(profile)->extension_service(); |
- if (extension_service) { |
- extension = extension_service->extensions()-> |
- GetExtensionOrAppByURL(ExtensionURLInfo(url)); |
- } |
- // Check the modules that are imported by this extension to see if any of them |
- // is whitelisted. |
- if (extension) { |
- const std::vector<extensions::SharedModuleInfo::ImportInfo>& imports = |
- extensions::SharedModuleInfo::GetImports(extension); |
- std::vector<extensions::SharedModuleInfo::ImportInfo>::const_iterator it; |
- for (it = imports.begin(); it != imports.end(); ++it) { |
- const Extension* imported_extension = extension_service-> |
- GetExtensionById(it->extension_id, false); |
- if (imported_extension && |
- extensions::SharedModuleInfo::IsSharedModule(imported_extension) && |
- HostIsInSet(it->extension_id, allowed_socket_origins_)) { |
- return true; |
- } |
- } |
- } |
- |
- // Need to check this now and not on construction because otherwise it won't |
- // work with browser_tests. |
- const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
- std::string allowed_list = |
- command_line.GetSwitchValueASCII(switches::kAllowNaClSocketAPI); |
- if (allowed_list == "*") { |
- // The wildcard allows socket API only for packaged and platform apps. |
- return extension && |
- (extension->GetType() == Manifest::TYPE_LEGACY_PACKAGED_APP || |
- extension->GetType() == Manifest::TYPE_PLATFORM_APP); |
- } else if (!allowed_list.empty()) { |
- base::StringTokenizer t(allowed_list, ","); |
- while (t.GetNext()) { |
- if (t.token() == host) |
- return true; |
- } |
- } |
- |
- return false; |
+ return IsExtensionOrSharedModuleWhitelisted( |
+ Profile::FromBrowserContext(browser_context), |
+ url, |
+ allowed_socket_origins_, |
+ switches::kAllowNaClSocketAPI); |
} |
base::FilePath ChromeContentBrowserClient::GetHyphenDictionaryDirectory() { |