OLD | NEW |
---|---|
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 Loading... | |
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 const size_t kMessageWhitelistSize = 0; | |
73 const uint32 kMessageWhitelist[] = { | |
74 0 | |
75 }; | |
76 | |
70 bool Send(IPC::Message* message) { | 77 bool Send(IPC::Message* message) { |
71 return content::UtilityThread::Get()->Send(message); | 78 return content::UtilityThread::Get()->Send(message); |
72 } | 79 } |
73 | 80 |
74 void ReleaseProcessIfNeeded() { | 81 void ReleaseProcessIfNeeded() { |
75 content::UtilityThread::Get()->ReleaseProcessIfNeeded(); | 82 content::UtilityThread::Get()->ReleaseProcessIfNeeded(); |
76 } | 83 } |
77 | 84 |
78 } // namespace | 85 } // namespace |
79 | 86 |
80 ChromeContentUtilityClient::ChromeContentUtilityClient() { | 87 ChromeContentUtilityClient::ChromeContentUtilityClient() |
88 : filter_messages_(false) { | |
mef
2014/01/10 18:22:55
nit: tab
Drew Haven
2014/01/16 02:52:05
Done.
| |
81 #if !defined(OS_ANDROID) | 89 #if !defined(OS_ANDROID) |
82 handlers_.push_back(new ProfileImportHandler()); | 90 handlers_.push_back(new ProfileImportHandler()); |
mef
2014/01/10 18:22:55
nit: tab not needed?
Drew Haven
2014/01/16 02:52:05
Thanks. My windows vim indentation-config needs n
| |
83 #endif // OS_ANDROID | 91 #endif // OS_ANDROID |
84 | 92 |
85 #if defined(ENABLE_MDNS) | 93 #if defined(ENABLE_MDNS) |
86 if (CommandLine::ForCurrentProcess()->HasSwitch( | 94 if (CommandLine::ForCurrentProcess()->HasSwitch( |
87 switches::kUtilityProcessEnableMDns)) { | 95 switches::kUtilityProcessEnableMDns)) { |
88 handlers_.push_back(new local_discovery::ServiceDiscoveryMessageHandler()); | 96 handlers_.push_back(new local_discovery::ServiceDiscoveryMessageHandler()); |
89 } | 97 } |
90 #endif // ENABLE_MDNS | 98 #endif // ENABLE_MDNS |
91 } | 99 } |
92 | 100 |
93 ChromeContentUtilityClient::~ChromeContentUtilityClient() { | 101 ChromeContentUtilityClient::~ChromeContentUtilityClient() { |
94 } | 102 } |
95 | 103 |
96 void ChromeContentUtilityClient::UtilityThreadStarted() { | 104 void ChromeContentUtilityClient::UtilityThreadStarted() { |
97 #if defined(OS_WIN) | 105 #if defined(OS_WIN) |
98 // Load the pdf plugin before the sandbox is turned on. This is for Windows | 106 // Load the pdf plugin before the sandbox is turned on. This is for Windows |
99 // only because we need this DLL only on Windows. | 107 // only because we need this DLL only on Windows. |
100 base::FilePath pdf; | 108 base::FilePath pdf; |
101 if (PathService::Get(chrome::FILE_PDF_PLUGIN, &pdf) && | 109 if (PathService::Get(chrome::FILE_PDF_PLUGIN, &pdf) && |
102 base::PathExists(pdf)) { | 110 base::PathExists(pdf)) { |
103 bool rv = !!LoadLibrary(pdf.value().c_str()); | 111 bool rv = !!LoadLibrary(pdf.value().c_str()); |
104 DCHECK(rv) << "Couldn't load PDF plugin"; | 112 DCHECK(rv) << "Couldn't load PDF plugin"; |
105 } | 113 } |
106 #endif | 114 #endif |
107 | 115 |
108 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 116 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
109 std::string lang = command_line->GetSwitchValueASCII(switches::kLang); | 117 std::string lang = command_line->GetSwitchValueASCII(switches::kLang); |
110 if (!lang.empty()) | 118 if (!lang.empty()) |
111 extension_l10n_util::SetProcessLocale(lang); | 119 extension_l10n_util::SetProcessLocale(lang); |
120 | |
121 if (command_line->HasSwitch(switches::kUtilityProcessRunningElevated)) { | |
122 DVLOG(0) << "Running elevated, restricting messages."; | |
123 for (size_t i = 0; i < kMessageWhitelistSize; i++) { | |
124 DVLOG(0) << "Adding " << kMessageWhitelist[i] << " to whitelist."; | |
125 message_id_whitelist_.insert(kMessageWhitelist[i]); | |
126 } | |
127 filter_messages_ = true; | |
128 } | |
112 } | 129 } |
113 | 130 |
114 bool ChromeContentUtilityClient::OnMessageReceived( | 131 bool ChromeContentUtilityClient::OnMessageReceived( |
115 const IPC::Message& message) { | 132 const IPC::Message& message) { |
133 if (filter_messages_ | |
134 && message_id_whitelist_.find(message.type()) | |
135 == message_id_whitelist_.end()) { | |
136 DVLOG(0) << "Rejecting message for not being in whitelist: " | |
137 << message.type(); | |
138 return false; | |
139 } | |
140 | |
116 bool handled = true; | 141 bool handled = true; |
117 IPC_BEGIN_MESSAGE_MAP(ChromeContentUtilityClient, message) | 142 IPC_BEGIN_MESSAGE_MAP(ChromeContentUtilityClient, message) |
118 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_UnpackExtension, OnUnpackExtension) | 143 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_UnpackExtension, OnUnpackExtension) |
119 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_UnpackWebResource, | 144 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_UnpackWebResource, |
120 OnUnpackWebResource) | 145 OnUnpackWebResource) |
121 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_ParseUpdateManifest, | 146 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_ParseUpdateManifest, |
122 OnParseUpdateManifest) | 147 OnParseUpdateManifest) |
123 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_DecodeImage, OnDecodeImage) | 148 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_DecodeImage, OnDecodeImage) |
124 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_DecodeImageBase64, OnDecodeImageBase64) | 149 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_DecodeImageBase64, OnDecodeImageBase64) |
125 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_RenderPDFPagesToMetafile, | 150 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_RenderPDFPagesToMetafile, |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
172 local_discovery::ServiceDiscoveryMessageHandler::PreSandboxStartup(); | 197 local_discovery::ServiceDiscoveryMessageHandler::PreSandboxStartup(); |
173 #endif // ENABLE_MDNS | 198 #endif // ENABLE_MDNS |
174 | 199 |
175 // Load media libraries for media file validation. | 200 // Load media libraries for media file validation. |
176 base::FilePath media_path; | 201 base::FilePath media_path; |
177 PathService::Get(content::DIR_MEDIA_LIBS, &media_path); | 202 PathService::Get(content::DIR_MEDIA_LIBS, &media_path); |
178 if (!media_path.empty()) | 203 if (!media_path.empty()) |
179 media::InitializeMediaLibrary(media_path); | 204 media::InitializeMediaLibrary(media_path); |
180 } | 205 } |
181 | 206 |
207 void ChromeContentUtilityClient::AddHandler(UtilityMessageHandler* handler) { | |
208 handlers_.push_back(handler); | |
209 } | |
210 | |
211 void ChromeContentUtilityClient::AddWhitelistMessageType(int message_type) { | |
212 DVLOG(0) << "Adding " << message_type << " to whitelist."; | |
213 message_id_whitelist_.insert(message_type); | |
214 } | |
215 | |
182 void ChromeContentUtilityClient::OnUnpackExtension( | 216 void ChromeContentUtilityClient::OnUnpackExtension( |
183 const base::FilePath& extension_path, | 217 const base::FilePath& extension_path, |
184 const std::string& extension_id, | 218 const std::string& extension_id, |
185 int location, | 219 int location, |
186 int creation_flags) { | 220 int creation_flags) { |
187 CHECK_GT(location, extensions::Manifest::INVALID_LOCATION); | 221 CHECK_GT(location, extensions::Manifest::INVALID_LOCATION); |
188 CHECK_LT(location, extensions::Manifest::NUM_LOCATIONS); | 222 CHECK_LT(location, extensions::Manifest::NUM_LOCATIONS); |
189 extensions::ExtensionsClient::Set( | 223 extensions::ExtensionsClient::Set( |
190 extensions::ChromeExtensionsClient::GetInstance()); | 224 extensions::ChromeExtensionsClient::GetInstance()); |
191 extensions::Unpacker unpacker( | 225 extensions::Unpacker unpacker( |
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
602 picasa::PicasaAlbumsIndexer indexer(album_uids); | 636 picasa::PicasaAlbumsIndexer indexer(album_uids); |
603 indexer.ParseFolderINI(folders_inis); | 637 indexer.ParseFolderINI(folders_inis); |
604 | 638 |
605 Send(new ChromeUtilityHostMsg_IndexPicasaAlbumsContents_Finished( | 639 Send(new ChromeUtilityHostMsg_IndexPicasaAlbumsContents_Finished( |
606 indexer.albums_images())); | 640 indexer.albums_images())); |
607 ReleaseProcessIfNeeded(); | 641 ReleaseProcessIfNeeded(); |
608 } | 642 } |
609 #endif // defined(OS_WIN) || defined(OS_MACOSX) | 643 #endif // defined(OS_WIN) || defined(OS_MACOSX) |
610 | 644 |
611 } // namespace chrome | 645 } // namespace chrome |
OLD | NEW |