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

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

Issue 10993078: Use extensions socket permission for TCP/UDP socket APIs in Pepper (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: nit Created 8 years, 2 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
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
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 #include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h" 72 #include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
73 #include "chrome/browser/user_style_sheet_watcher.h" 73 #include "chrome/browser/user_style_sheet_watcher.h"
74 #include "chrome/browser/user_style_sheet_watcher_factory.h" 74 #include "chrome/browser/user_style_sheet_watcher_factory.h"
75 #include "chrome/browser/view_type_utils.h" 75 #include "chrome/browser/view_type_utils.h"
76 #include "chrome/common/child_process_logging.h" 76 #include "chrome/common/child_process_logging.h"
77 #include "chrome/common/chrome_constants.h" 77 #include "chrome/common/chrome_constants.h"
78 #include "chrome/common/chrome_switches.h" 78 #include "chrome/common/chrome_switches.h"
79 #include "chrome/common/extensions/extension.h" 79 #include "chrome/common/extensions/extension.h"
80 #include "chrome/common/extensions/extension_process_policy.h" 80 #include "chrome/common/extensions/extension_process_policy.h"
81 #include "chrome/common/extensions/extension_set.h" 81 #include "chrome/common/extensions/extension_set.h"
82 #include "chrome/common/extensions/permissions/socket_permission.h"
82 #include "chrome/common/logging_chrome.h" 83 #include "chrome/common/logging_chrome.h"
83 #include "chrome/common/pref_names.h" 84 #include "chrome/common/pref_names.h"
84 #include "chrome/common/render_messages.h" 85 #include "chrome/common/render_messages.h"
85 #include "chrome/common/url_constants.h" 86 #include "chrome/common/url_constants.h"
86 #include "content/public/browser/browser_child_process_host.h" 87 #include "content/public/browser/browser_child_process_host.h"
87 #include "content/public/browser/browser_main_parts.h" 88 #include "content/public/browser/browser_main_parts.h"
88 #include "content/public/browser/browser_ppapi_host.h" 89 #include "content/public/browser/browser_ppapi_host.h"
89 #include "content/public/browser/browser_url_handler.h" 90 #include "content/public/browser/browser_url_handler.h"
90 #include "content/public/browser/child_process_security_policy.h" 91 #include "content/public/browser/child_process_security_policy.h"
91 #include "content/public/browser/render_process_host.h" 92 #include "content/public/browser/render_process_host.h"
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 if (process_type == switches::kPpapiPluginProcess) 386 if (process_type == switches::kPpapiPluginProcess)
386 return PpapiCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket(); 387 return PpapiCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
387 388
388 if (process_type == switches::kGpuProcess) 389 if (process_type == switches::kGpuProcess)
389 return GpuCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket(); 390 return GpuCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
390 391
391 return -1; 392 return -1;
392 } 393 }
393 #endif // defined(OS_POSIX) && !defined(OS_MACOSX) 394 #endif // defined(OS_POSIX) && !defined(OS_MACOSX)
394 395
396 extensions::SocketPermission::CheckParam ConvertSocketPermissions(
397 const content::ContentBrowserClient::SocketPermissionParam& params) {
398 extensions::SocketPermissionData::OperationType type =
399 extensions::SocketPermissionData::NONE;
400 switch (params.type) {
401 case content::ContentBrowserClient::SocketPermissionParam::TCP_CONNECT:
402 type = extensions::SocketPermissionData::TCP_CONNECT;
403 break;
404
405 case content::ContentBrowserClient::SocketPermissionParam::TCP_LISTEN:
406 type = extensions::SocketPermissionData::TCP_LISTEN;
407 break;
408
409 case content::ContentBrowserClient::SocketPermissionParam::UDP_BIND:
410 type = extensions::SocketPermissionData::UDP_BIND;
411 break;
412
413 case content::ContentBrowserClient::SocketPermissionParam::UDP_SEND_TO:
414 type = extensions::SocketPermissionData::UDP_SEND_TO;
415 break;
416
417 default:
418 NOTREACHED();
419 }
420 return extensions::SocketPermission::CheckParam(
421 type, params.host, params.port);
422 }
423
395 } // namespace 424 } // namespace
396 425
397 namespace chrome { 426 namespace chrome {
398 427
399 ChromeContentBrowserClient::ChromeContentBrowserClient() { 428 ChromeContentBrowserClient::ChromeContentBrowserClient() {
400 for (size_t i = 0; i < arraysize(kPredefinedAllowedSocketOrigins); ++i) 429 for (size_t i = 0; i < arraysize(kPredefinedAllowedSocketOrigins); ++i)
401 allowed_socket_origins_.insert(kPredefinedAllowedSocketOrigins[i]); 430 allowed_socket_origins_.insert(kPredefinedAllowedSocketOrigins[i]);
402 } 431 }
403 432
404 ChromeContentBrowserClient::~ChromeContentBrowserClient() { 433 ChromeContentBrowserClient::~ChromeContentBrowserClient() {
(...skipping 1287 matching lines...) Expand 10 before | Expand all | Expand 10 after
1692 } 1721 }
1693 1722
1694 void ChromeContentBrowserClient::DidCreatePpapiPlugin( 1723 void ChromeContentBrowserClient::DidCreatePpapiPlugin(
1695 content::BrowserPpapiHost* browser_host) { 1724 content::BrowserPpapiHost* browser_host) {
1696 browser_host->GetPpapiHost()->AddHostFactoryFilter( 1725 browser_host->GetPpapiHost()->AddHostFactoryFilter(
1697 scoped_ptr<ppapi::host::HostFactory>( 1726 scoped_ptr<ppapi::host::HostFactory>(
1698 new ChromeBrowserPepperHostFactory(browser_host))); 1727 new ChromeBrowserPepperHostFactory(browser_host)));
1699 } 1728 }
1700 1729
1701 bool ChromeContentBrowserClient::AllowPepperSocketAPI( 1730 bool ChromeContentBrowserClient::AllowPepperSocketAPI(
1702 content::BrowserContext* browser_context, const GURL& url) { 1731 content::BrowserContext* browser_context,
1732 const GURL& url,
1733 const SocketPermissionParam& params) {
1703 if (!url.is_valid()) 1734 if (!url.is_valid())
1704 return false; 1735 return false;
1705 1736
1706 std::string host = url.host(); 1737 std::string host = url.host();
1707 if (url.SchemeIs(kExtensionScheme) && allowed_socket_origins_.count(host)) 1738 if (url.SchemeIs(kExtensionScheme) && allowed_socket_origins_.count(host))
1708 return true; 1739 return true;
1709 1740
1710 Profile* profile = Profile::FromBrowserContext(browser_context); 1741 Profile* profile = Profile::FromBrowserContext(browser_context);
1711 const Extension* extension = NULL; 1742 const Extension* extension = NULL;
1712 if (profile && profile->GetExtensionService()) { 1743 if (profile && profile->GetExtensionService()) {
(...skipping 15 matching lines...) Expand all
1728 StringTokenizer t(allowed_list, ","); 1759 StringTokenizer t(allowed_list, ",");
1729 while (t.GetNext()) { 1760 while (t.GetNext()) {
1730 if (t.token() == host) 1761 if (t.token() == host)
1731 return true; 1762 return true;
1732 } 1763 }
1733 } 1764 }
1734 1765
1735 if (!extension) 1766 if (!extension)
1736 return false; 1767 return false;
1737 1768
1738 if (extension->HasAPIPermission(APIPermission::kSocket)) 1769 extensions::SocketPermission::CheckParam extension_params =
1770 ConvertSocketPermissions(params);
1771 if (extension->CheckAPIPermissionWithParam(APIPermission::kSocket,
1772 &extension_params))
1739 return true; 1773 return true;
1740 1774
1741 return false; 1775 return false;
1742 } 1776 }
1743 1777
1744 bool ChromeContentBrowserClient::AllowPepperPrivateFileAPI() { 1778 bool ChromeContentBrowserClient::AllowPepperPrivateFileAPI() {
1745 return CommandLine::ForCurrentProcess()->HasSwitch( 1779 return CommandLine::ForCurrentProcess()->HasSwitch(
1746 switches::kPpapiFlashInProcess); 1780 switches::kPpapiFlashInProcess);
1747 } 1781 }
1748 1782
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
1840 partition_id = extension->id(); 1874 partition_id = extension->id();
1841 } 1875 }
1842 1876
1843 // Enforce that IsValidStoragePartitionId() implementation stays in sync. 1877 // Enforce that IsValidStoragePartitionId() implementation stays in sync.
1844 DCHECK(IsValidStoragePartitionId(browser_context, partition_id)); 1878 DCHECK(IsValidStoragePartitionId(browser_context, partition_id));
1845 return partition_id; 1879 return partition_id;
1846 } 1880 }
1847 1881
1848 1882
1849 } // namespace chrome 1883 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698