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

Side by Side Diff: chrome/browser/chrome_content_browser_client.cc

Issue 15521002: Flag and whitelist to allow crxfs api in NaCl (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 7 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/browser/chrome_content_browser_client.h" 5 #include "chrome/browser/chrome_content_browser_client.h"
6 6
7 #include <set> 7 #include <set>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/lazy_instance.h" 13 #include "base/lazy_instance.h"
14 #include "base/path_service.h" 14 #include "base/path_service.h"
15 #include "base/prefs/pref_service.h" 15 #include "base/prefs/pref_service.h"
16 #include "base/sha1.h"
17 #include "base/string_number_conversions.h" 16 #include "base/string_number_conversions.h"
18 #include "base/strings/string_tokenizer.h"
19 #include "base/utf_string_conversions.h" 17 #include "base/utf_string_conversions.h"
20 #include "chrome/app/breakpad_mac.h" 18 #include "chrome/app/breakpad_mac.h"
21 #include "chrome/browser/app_mode/app_mode_utils.h" 19 #include "chrome/browser/app_mode/app_mode_utils.h"
22 #include "chrome/browser/browser_about_handler.h" 20 #include "chrome/browser/browser_about_handler.h"
23 #include "chrome/browser/browser_process.h" 21 #include "chrome/browser/browser_process.h"
24 #include "chrome/browser/browsing_data/browsing_data_helper.h" 22 #include "chrome/browser/browsing_data/browsing_data_helper.h"
25 #include "chrome/browser/browsing_data/browsing_data_remover.h" 23 #include "chrome/browser/browsing_data/browsing_data_remover.h"
26 #include "chrome/browser/character_encoding.h" 24 #include "chrome/browser/character_encoding.h"
27 #include "chrome/browser/chrome_net_benchmarking_message_filter.h" 25 #include "chrome/browser/chrome_net_benchmarking_message_filter.h"
28 #include "chrome/browser/chrome_quota_permission_context.h" 26 #include "chrome/browser/chrome_quota_permission_context.h"
(...skipping 14 matching lines...) Expand all
43 #include "chrome/browser/extensions/extension_webkit_preferences.h" 41 #include "chrome/browser/extensions/extension_webkit_preferences.h"
44 #include "chrome/browser/extensions/suggest_permission_util.h" 42 #include "chrome/browser/extensions/suggest_permission_util.h"
45 #include "chrome/browser/geolocation/chrome_access_token_store.h" 43 #include "chrome/browser/geolocation/chrome_access_token_store.h"
46 #include "chrome/browser/google/google_util.h" 44 #include "chrome/browser/google/google_util.h"
47 #include "chrome/browser/media/media_capture_devices_dispatcher.h" 45 #include "chrome/browser/media/media_capture_devices_dispatcher.h"
48 #include "chrome/browser/metrics/chrome_browser_main_extra_parts_metrics.h" 46 #include "chrome/browser/metrics/chrome_browser_main_extra_parts_metrics.h"
49 #include "chrome/browser/nacl_host/nacl_process_host.h" 47 #include "chrome/browser/nacl_host/nacl_process_host.h"
50 #include "chrome/browser/net/chrome_net_log.h" 48 #include "chrome/browser/net/chrome_net_log.h"
51 #include "chrome/browser/notifications/desktop_notification_service.h" 49 #include "chrome/browser/notifications/desktop_notification_service.h"
52 #include "chrome/browser/notifications/desktop_notification_service_factory.h" 50 #include "chrome/browser/notifications/desktop_notification_service_factory.h"
51 #include "chrome/browser/pepper_util.h"
53 #include "chrome/browser/platform_util.h" 52 #include "chrome/browser/platform_util.h"
54 #include "chrome/browser/plugins/plugin_info_message_filter.h" 53 #include "chrome/browser/plugins/plugin_info_message_filter.h"
55 #include "chrome/browser/prefs/scoped_user_pref_update.h" 54 #include "chrome/browser/prefs/scoped_user_pref_update.h"
56 #include "chrome/browser/prerender/prerender_manager.h" 55 #include "chrome/browser/prerender/prerender_manager.h"
57 #include "chrome/browser/prerender/prerender_manager_factory.h" 56 #include "chrome/browser/prerender/prerender_manager_factory.h"
58 #include "chrome/browser/prerender/prerender_message_filter.h" 57 #include "chrome/browser/prerender/prerender_message_filter.h"
59 #include "chrome/browser/prerender/prerender_tracker.h" 58 #include "chrome/browser/prerender/prerender_tracker.h"
60 #include "chrome/browser/printing/printing_message_filter.h" 59 #include "chrome/browser/printing/printing_message_filter.h"
61 #include "chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.h" 60 #include "chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.h"
62 #include "chrome/browser/profiles/profile.h" 61 #include "chrome/browser/profiles/profile.h"
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 effective_url = effective_url.ReplaceComponents(replacements); 454 effective_url = effective_url.ReplaceComponents(replacements);
456 return effective_url; 455 return effective_url;
457 } 456 }
458 #endif 457 #endif
459 458
460 void SetApplicationLocaleOnIOThread(const std::string& locale) { 459 void SetApplicationLocaleOnIOThread(const std::string& locale) {
461 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 460 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
462 g_io_thread_application_locale.Get() = locale; 461 g_io_thread_application_locale.Get() = locale;
463 } 462 }
464 463
465 std::string HashHost(const std::string& host) {
466 const std::string id_hash = base::SHA1HashString(host);
467 DCHECK(id_hash.length() == base::kSHA1Length);
468 return base::HexEncode(id_hash.c_str(), id_hash.length());
469 }
470
471 bool HostIsInSet(const std::string& host, const std::set<std::string>& set) {
472 return set.count(host) > 0 || set.count(HashHost(host)) > 0;
473 }
474
475 } // namespace 464 } // namespace
476 465
477 namespace chrome { 466 namespace chrome {
478 467
479 ChromeContentBrowserClient::ChromeContentBrowserClient() { 468 ChromeContentBrowserClient::ChromeContentBrowserClient() {
480 for (size_t i = 0; i < arraysize(kPredefinedAllowedSocketOrigins); ++i) 469 for (size_t i = 0; i < arraysize(kPredefinedAllowedSocketOrigins); ++i)
481 allowed_socket_origins_.insert(kPredefinedAllowedSocketOrigins[i]); 470 allowed_socket_origins_.insert(kPredefinedAllowedSocketOrigins[i]);
482 } 471 }
483 472
484 ChromeContentBrowserClient::~ChromeContentBrowserClient() { 473 ChromeContentBrowserClient::~ChromeContentBrowserClient() {
(...skipping 1640 matching lines...) Expand 10 before | Expand all | Expand 10 after
2125 return false; 2114 return false;
2126 2115
2127 return extension->HasAPIPermission(APIPermission::kWebView) || 2116 return extension->HasAPIPermission(APIPermission::kWebView) ||
2128 extension->HasAPIPermission(APIPermission::kAdView); 2117 extension->HasAPIPermission(APIPermission::kAdView);
2129 } 2118 }
2130 2119
2131 bool ChromeContentBrowserClient::AllowPepperSocketAPI( 2120 bool ChromeContentBrowserClient::AllowPepperSocketAPI(
2132 content::BrowserContext* browser_context, 2121 content::BrowserContext* browser_context,
2133 const GURL& url, 2122 const GURL& url,
2134 const content::SocketPermissionRequest& params) { 2123 const content::SocketPermissionRequest& params) {
2135 if (!url.is_valid())
2136 return false;
2137 2124
2138 std::string host = url.host(); 2125 return IsExtensionOrSharedModuleWhitelisted(
2139 if (url.SchemeIs(extensions::kExtensionScheme) && 2126 Profile::FromBrowserContext(browser_context),
2140 HostIsInSet(host, allowed_socket_origins_)) { 2127 url,
2141 return true; 2128 allowed_socket_origins_,
2142 } 2129 switches::kAllowNaClSocketAPI);
2143
2144 Profile* profile = Profile::FromBrowserContext(browser_context);
2145 const Extension* extension = NULL;
2146 ExtensionService* extension_service = !profile ? NULL :
2147 extensions::ExtensionSystem::Get(profile)->extension_service();
2148 if (extension_service) {
2149 extension = extension_service->extensions()->
2150 GetExtensionOrAppByURL(ExtensionURLInfo(url));
2151 }
2152
2153 // Check the modules that are imported by this extension to see if any of them
2154 // is whitelisted.
2155 if (extension) {
2156 const std::vector<extensions::SharedModuleInfo::ImportInfo>& imports =
2157 extensions::SharedModuleInfo::GetImports(extension);
2158 std::vector<extensions::SharedModuleInfo::ImportInfo>::const_iterator it;
2159 for (it = imports.begin(); it != imports.end(); ++it) {
2160 const Extension* imported_extension = extension_service->
2161 GetExtensionById(it->extension_id, false);
2162 if (imported_extension &&
2163 extensions::SharedModuleInfo::IsSharedModule(imported_extension) &&
2164 HostIsInSet(it->extension_id, allowed_socket_origins_)) {
2165 return true;
2166 }
2167 }
2168 }
2169
2170 // Need to check this now and not on construction because otherwise it won't
2171 // work with browser_tests.
2172 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
2173 std::string allowed_list =
2174 command_line.GetSwitchValueASCII(switches::kAllowNaClSocketAPI);
2175 if (allowed_list == "*") {
2176 // The wildcard allows socket API only for packaged and platform apps.
2177 return extension &&
2178 (extension->GetType() == Manifest::TYPE_LEGACY_PACKAGED_APP ||
2179 extension->GetType() == Manifest::TYPE_PLATFORM_APP);
2180 } else if (!allowed_list.empty()) {
2181 base::StringTokenizer t(allowed_list, ",");
2182 while (t.GetNext()) {
2183 if (t.token() == host)
2184 return true;
2185 }
2186 }
2187
2188 return false;
2189 } 2130 }
2190 2131
2191 base::FilePath ChromeContentBrowserClient::GetHyphenDictionaryDirectory() { 2132 base::FilePath ChromeContentBrowserClient::GetHyphenDictionaryDirectory() {
2192 base::FilePath directory; 2133 base::FilePath directory;
2193 PathService::Get(chrome::DIR_APP_DICTIONARIES, &directory); 2134 PathService::Get(chrome::DIR_APP_DICTIONARIES, &directory);
2194 return directory.Append(FILE_PATH_LITERAL("Hyphen")); 2135 return directory.Append(FILE_PATH_LITERAL("Hyphen"));
2195 } 2136 }
2196 2137
2197 ui::SelectFilePolicy* ChromeContentBrowserClient::CreateSelectFilePolicy( 2138 ui::SelectFilePolicy* ChromeContentBrowserClient::CreateSelectFilePolicy(
2198 WebContents* web_contents) { 2139 WebContents* web_contents) {
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
2316 #if defined(USE_NSS) 2257 #if defined(USE_NSS)
2317 crypto::CryptoModuleBlockingPasswordDelegate* 2258 crypto::CryptoModuleBlockingPasswordDelegate*
2318 ChromeContentBrowserClient::GetCryptoPasswordDelegate( 2259 ChromeContentBrowserClient::GetCryptoPasswordDelegate(
2319 const GURL& url) { 2260 const GURL& url) {
2320 return chrome::NewCryptoModuleBlockingDialogDelegate( 2261 return chrome::NewCryptoModuleBlockingDialogDelegate(
2321 chrome::kCryptoModulePasswordKeygen, url.host()); 2262 chrome::kCryptoModulePasswordKeygen, url.host());
2322 } 2263 }
2323 #endif 2264 #endif
2324 2265
2325 } // namespace chrome 2266 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698