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

Side by Side Diff: chrome/utility/chrome_content_utility_client.cc

Issue 98603007: Launches a privileged utility process. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Cleans up formatting and removes some unnecessary functions. Adds an additional non-elevated white… Created 6 years, 11 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/utility/chrome_content_utility_client.h" 5 #include "chrome/utility/chrome_content_utility_client.h"
6 6
7 #include "base/base64.h" 7 #include "base/base64.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 60
61 #if defined(ENABLE_MDNS) 61 #if defined(ENABLE_MDNS)
62 #include "chrome/utility/local_discovery/service_discovery_message_handler.h" 62 #include "chrome/utility/local_discovery/service_discovery_message_handler.h"
63 #include "content/public/common/content_switches.h" 63 #include "content/public/common/content_switches.h"
64 #endif // ENABLE_MDNS 64 #endif // ENABLE_MDNS
65 65
66 namespace chrome { 66 namespace chrome {
67 67
68 namespace { 68 namespace {
69 69
70 // This whitelist is the default list of whitelist entries when running
71 // elevated.
72 static const uint32 kMessageWhitelist[] = { 0 };
73 static const size_t kMessageWhitelistSize = arraysize(kMessageWhitelist);
74
70 bool Send(IPC::Message* message) { 75 bool Send(IPC::Message* message) {
71 return content::UtilityThread::Get()->Send(message); 76 return content::UtilityThread::Get()->Send(message);
72 } 77 }
73 78
74 void ReleaseProcessIfNeeded() { 79 void ReleaseProcessIfNeeded() {
75 content::UtilityThread::Get()->ReleaseProcessIfNeeded(); 80 content::UtilityThread::Get()->ReleaseProcessIfNeeded();
76 } 81 }
77 82
78 } // namespace 83 } // namespace
79 84
80 ChromeContentUtilityClient::ChromeContentUtilityClient() { 85 ChromeContentUtilityClient::ChromeContentUtilityClient()
86 : filter_messages_(false) {
81 #if !defined(OS_ANDROID) 87 #if !defined(OS_ANDROID)
82 handlers_.push_back(new ProfileImportHandler()); 88 handlers_.push_back(new ProfileImportHandler());
83 #endif // OS_ANDROID 89 #endif // OS_ANDROID
84 90
85 #if defined(ENABLE_MDNS) 91 #if defined(ENABLE_MDNS)
86 if (CommandLine::ForCurrentProcess()->HasSwitch( 92 if (CommandLine::ForCurrentProcess()->HasSwitch(
87 switches::kUtilityProcessEnableMDns)) { 93 switches::kUtilityProcessEnableMDns)) {
88 handlers_.push_back(new local_discovery::ServiceDiscoveryMessageHandler()); 94 handlers_.push_back(new local_discovery::ServiceDiscoveryMessageHandler());
89 } 95 }
90 #endif // ENABLE_MDNS 96 #endif // ENABLE_MDNS
(...skipping 11 matching lines...) Expand all
102 base::PathExists(pdf)) { 108 base::PathExists(pdf)) {
103 bool rv = !!LoadLibrary(pdf.value().c_str()); 109 bool rv = !!LoadLibrary(pdf.value().c_str());
104 DCHECK(rv) << "Couldn't load PDF plugin"; 110 DCHECK(rv) << "Couldn't load PDF plugin";
105 } 111 }
106 #endif 112 #endif
107 113
108 CommandLine* command_line = CommandLine::ForCurrentProcess(); 114 CommandLine* command_line = CommandLine::ForCurrentProcess();
109 std::string lang = command_line->GetSwitchValueASCII(switches::kLang); 115 std::string lang = command_line->GetSwitchValueASCII(switches::kLang);
110 if (!lang.empty()) 116 if (!lang.empty())
111 extension_l10n_util::SetProcessLocale(lang); 117 extension_l10n_util::SetProcessLocale(lang);
118
119 if (command_line->HasSwitch(switches::kUtilityProcessRunningElevated)) {
120 DVLOG(0) << "Utility process is running elevated, restricting messages.";
121 for (size_t i = 0; i < kMessageWhitelistSize; i++) {
122 message_id_whitelist_.insert(kMessageWhitelist[i]);
123 }
124 filter_messages_ = true;
125 }
112 } 126 }
113 127
114 bool ChromeContentUtilityClient::OnMessageReceived( 128 bool ChromeContentUtilityClient::OnMessageReceived(
115 const IPC::Message& message) { 129 const IPC::Message& message) {
130 if (filter_messages_
131 && message_id_whitelist_.find(message.type())
132 == message_id_whitelist_.end()) {
133 DVLOG(0) << "Message rejected, not in whitelist: "
134 << message.type();
135 return false;
136 }
137
116 bool handled = true; 138 bool handled = true;
117 IPC_BEGIN_MESSAGE_MAP(ChromeContentUtilityClient, message) 139 IPC_BEGIN_MESSAGE_MAP(ChromeContentUtilityClient, message)
118 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_UnpackExtension, OnUnpackExtension) 140 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_UnpackExtension, OnUnpackExtension)
119 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_UnpackWebResource, 141 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_UnpackWebResource,
120 OnUnpackWebResource) 142 OnUnpackWebResource)
121 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_ParseUpdateManifest, 143 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_ParseUpdateManifest,
122 OnParseUpdateManifest) 144 OnParseUpdateManifest)
123 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_DecodeImage, OnDecodeImage) 145 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_DecodeImage, OnDecodeImage)
124 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_DecodeImageBase64, OnDecodeImageBase64) 146 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_DecodeImageBase64, OnDecodeImageBase64)
125 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_RenderPDFPagesToMetafile, 147 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_RenderPDFPagesToMetafile,
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 local_discovery::ServiceDiscoveryMessageHandler::PreSandboxStartup(); 194 local_discovery::ServiceDiscoveryMessageHandler::PreSandboxStartup();
173 #endif // ENABLE_MDNS 195 #endif // ENABLE_MDNS
174 196
175 // Load media libraries for media file validation. 197 // Load media libraries for media file validation.
176 base::FilePath media_path; 198 base::FilePath media_path;
177 PathService::Get(content::DIR_MEDIA_LIBS, &media_path); 199 PathService::Get(content::DIR_MEDIA_LIBS, &media_path);
178 if (!media_path.empty()) 200 if (!media_path.empty())
179 media::InitializeMediaLibrary(media_path); 201 media::InitializeMediaLibrary(media_path);
180 } 202 }
181 203
204 void ChromeContentUtilityClient::AddHandler(UtilityMessageHandler* handler) {
205 handlers_.push_back(handler);
206 }
207
208 void ChromeContentUtilityClient::AddWhitelistMessageType(int message_type) {
209 message_id_whitelist_.insert(message_type);
210 }
211
182 void ChromeContentUtilityClient::OnUnpackExtension( 212 void ChromeContentUtilityClient::OnUnpackExtension(
183 const base::FilePath& extension_path, 213 const base::FilePath& extension_path,
184 const std::string& extension_id, 214 const std::string& extension_id,
185 int location, 215 int location,
186 int creation_flags) { 216 int creation_flags) {
187 CHECK_GT(location, extensions::Manifest::INVALID_LOCATION); 217 CHECK_GT(location, extensions::Manifest::INVALID_LOCATION);
188 CHECK_LT(location, extensions::Manifest::NUM_LOCATIONS); 218 CHECK_LT(location, extensions::Manifest::NUM_LOCATIONS);
189 extensions::ExtensionsClient::Set( 219 extensions::ExtensionsClient::Set(
190 extensions::ChromeExtensionsClient::GetInstance()); 220 extensions::ChromeExtensionsClient::GetInstance());
191 extensions::Unpacker unpacker( 221 extensions::Unpacker unpacker(
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after
602 picasa::PicasaAlbumsIndexer indexer(album_uids); 632 picasa::PicasaAlbumsIndexer indexer(album_uids);
603 indexer.ParseFolderINI(folders_inis); 633 indexer.ParseFolderINI(folders_inis);
604 634
605 Send(new ChromeUtilityHostMsg_IndexPicasaAlbumsContents_Finished( 635 Send(new ChromeUtilityHostMsg_IndexPicasaAlbumsContents_Finished(
606 indexer.albums_images())); 636 indexer.albums_images()));
607 ReleaseProcessIfNeeded(); 637 ReleaseProcessIfNeeded();
608 } 638 }
609 #endif // defined(OS_WIN) || defined(OS_MACOSX) 639 #endif // defined(OS_WIN) || defined(OS_MACOSX)
610 640
611 } // namespace chrome 641 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698