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

Side by Side Diff: chrome/browser/nacl_host/nacl_browser_delegate_impl.cc

Issue 2479593006: Move enable extensions define to a build flag. (Closed)
Patch Set: Merge Created 4 years, 1 month 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/nacl_host/nacl_browser_delegate_impl.h" 5 #include "chrome/browser/nacl_host/nacl_browser_delegate_impl.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/path_service.h" 12 #include "base/path_service.h"
13 #include "base/strings/string_split.h" 13 #include "base/strings/string_split.h"
14 #include "chrome/browser/browser_process.h" 14 #include "chrome/browser/browser_process.h"
15 #include "chrome/browser/component_updater/pnacl_component_installer.h" 15 #include "chrome/browser/component_updater/pnacl_component_installer.h"
16 #if defined(ENABLE_EXTENSIONS)
17 #include "chrome/browser/extensions/extension_service.h"
18 #endif
19 #include "chrome/browser/nacl_host/nacl_infobar_delegate.h" 16 #include "chrome/browser/nacl_host/nacl_infobar_delegate.h"
20 #include "chrome/browser/profiles/profile.h" 17 #include "chrome/browser/profiles/profile.h"
21 #include "chrome/browser/profiles/profile_manager.h" 18 #include "chrome/browser/profiles/profile_manager.h"
22 #include "chrome/browser/renderer_host/pepper/chrome_browser_pepper_host_factory .h" 19 #include "chrome/browser/renderer_host/pepper/chrome_browser_pepper_host_factory .h"
23 #include "chrome/common/channel_info.h" 20 #include "chrome/common/channel_info.h"
24 #include "chrome/common/chrome_paths.h" 21 #include "chrome/common/chrome_paths.h"
25 #include "chrome/common/chrome_paths_internal.h" 22 #include "chrome/common/chrome_paths_internal.h"
26 #include "chrome/common/logging_chrome.h" 23 #include "chrome/common/logging_chrome.h"
27 #include "chrome/common/pepper_permission_util.h" 24 #include "chrome/common/pepper_permission_util.h"
28 #include "content/public/browser/browser_thread.h" 25 #include "content/public/browser/browser_thread.h"
29 #if defined(ENABLE_EXTENSIONS) 26 #include "extensions/features/features.h"
27 #include "url/gurl.h"
28
29 #if BUILDFLAG(ENABLE_EXTENSIONS)
30 #include "chrome/browser/extensions/extension_service.h"
30 #include "extensions/browser/extension_system.h" 31 #include "extensions/browser/extension_system.h"
31 #include "extensions/browser/info_map.h" 32 #include "extensions/browser/info_map.h"
32 #include "extensions/browser/process_manager.h" 33 #include "extensions/browser/process_manager.h"
33 #include "extensions/common/constants.h" 34 #include "extensions/common/constants.h"
34 #include "extensions/common/extension.h" 35 #include "extensions/common/extension.h"
35 #include "extensions/common/url_pattern.h" 36 #include "extensions/common/url_pattern.h"
36 #endif 37 #endif
37 #include "url/gurl.h"
38 38
39 namespace { 39 namespace {
40 40
41 // These are temporarily needed for testing non-sfi mode on ChromeOS without 41 // These are temporarily needed for testing non-sfi mode on ChromeOS without
42 // passing command-line arguments to Chrome. 42 // passing command-line arguments to Chrome.
43 const char* const kAllowedNonSfiOrigins[] = { 43 const char* const kAllowedNonSfiOrigins[] = {
44 "6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F", // see http://crbug.com/355141 44 "6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F", // see http://crbug.com/355141
45 "4EB74897CB187C7633357C2FE832E0AD6A44883A" // see http://crbug.com/355141 45 "4EB74897CB187C7633357C2FE832E0AD6A44883A" // see http://crbug.com/355141
46 }; 46 };
47 47
(...skipping 15 matching lines...) Expand all
63 const content::BrowserPpapiHost::OnKeepaliveInstanceData& instance_data, 63 const content::BrowserPpapiHost::OnKeepaliveInstanceData& instance_data,
64 const base::FilePath& profile_data_directory) { 64 const base::FilePath& profile_data_directory) {
65 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 65 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
66 66
67 // Only one instance will exist for NaCl embeds, even when more than one 67 // Only one instance will exist for NaCl embeds, even when more than one
68 // embed of the same plugin exists on the same page. 68 // embed of the same plugin exists on the same page.
69 DCHECK_EQ(1U, instance_data.size()); 69 DCHECK_EQ(1U, instance_data.size());
70 if (instance_data.size() < 1) 70 if (instance_data.size() < 1)
71 return; 71 return;
72 72
73 #if defined(ENABLE_EXTENSIONS) 73 #if BUILDFLAG(ENABLE_EXTENSIONS)
74 extensions::ProcessManager::OnKeepaliveFromPlugin( 74 extensions::ProcessManager::OnKeepaliveFromPlugin(
75 instance_data[0].render_process_id, 75 instance_data[0].render_process_id,
76 instance_data[0].render_frame_id, 76 instance_data[0].render_frame_id,
77 instance_data[0].document_url.host()); 77 instance_data[0].document_url.host());
78 #endif 78 #endif
79 } 79 }
80 80
81 // Calls OnKeepaliveOnUIThread on UI thread. 81 // Calls OnKeepaliveOnUIThread on UI thread.
82 void OnKeepalive( 82 void OnKeepalive(
83 const content::BrowserPpapiHost::OnKeepaliveInstanceData& instance_data, 83 const content::BrowserPpapiHost::OnKeepaliveInstanceData& instance_data,
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 return chrome::GetVersionString(); 139 return chrome::GetVersionString();
140 } 140 }
141 141
142 ppapi::host::HostFactory* NaClBrowserDelegateImpl::CreatePpapiHostFactory( 142 ppapi::host::HostFactory* NaClBrowserDelegateImpl::CreatePpapiHostFactory(
143 content::BrowserPpapiHost* ppapi_host) { 143 content::BrowserPpapiHost* ppapi_host) {
144 return new ChromeBrowserPepperHostFactory(ppapi_host); 144 return new ChromeBrowserPepperHostFactory(ppapi_host);
145 } 145 }
146 146
147 void NaClBrowserDelegateImpl::SetDebugPatterns( 147 void NaClBrowserDelegateImpl::SetDebugPatterns(
148 const std::string& debug_patterns) { 148 const std::string& debug_patterns) {
149 #if defined(ENABLE_EXTENSIONS) 149 #if BUILDFLAG(ENABLE_EXTENSIONS)
150 if (debug_patterns.empty()) { 150 if (debug_patterns.empty()) {
151 return; 151 return;
152 } 152 }
153 std::vector<std::string> patterns; 153 std::vector<std::string> patterns;
154 if (debug_patterns[0] == '!') { 154 if (debug_patterns[0] == '!') {
155 std::string negated_patterns = debug_patterns; 155 std::string negated_patterns = debug_patterns;
156 inverse_debug_patterns_ = true; 156 inverse_debug_patterns_ = true;
157 negated_patterns.erase(0, 1); 157 negated_patterns.erase(0, 1);
158 patterns = base::SplitString( 158 patterns = base::SplitString(
159 negated_patterns, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); 159 negated_patterns, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
160 } else { 160 } else {
161 patterns = base::SplitString( 161 patterns = base::SplitString(
162 debug_patterns, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); 162 debug_patterns, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
163 } 163 }
164 for (const std::string& pattern_str : patterns) { 164 for (const std::string& pattern_str : patterns) {
165 // Allow chrome:// schema, which is used to filter out the internal 165 // Allow chrome:// schema, which is used to filter out the internal
166 // PNaCl translator. Also allow chrome-extension:// schema (which 166 // PNaCl translator. Also allow chrome-extension:// schema (which
167 // can have NaCl modules). The default is to disallow these schema 167 // can have NaCl modules). The default is to disallow these schema
168 // since they can be dangerous in the context of chrome extension 168 // since they can be dangerous in the context of chrome extension
169 // permissions, but they are okay here, for NaCl GDB avoidance. 169 // permissions, but they are okay here, for NaCl GDB avoidance.
170 URLPattern pattern(URLPattern::SCHEME_ALL); 170 URLPattern pattern(URLPattern::SCHEME_ALL);
171 if (pattern.Parse(pattern_str) == URLPattern::PARSE_SUCCESS) { 171 if (pattern.Parse(pattern_str) == URLPattern::PARSE_SUCCESS) {
172 // If URL pattern has scheme equal to *, Parse method resets valid 172 // If URL pattern has scheme equal to *, Parse method resets valid
173 // schemes mask to http and https only, so we need to reset it after 173 // schemes mask to http and https only, so we need to reset it after
174 // Parse to re-include chrome-extension and chrome schema. 174 // Parse to re-include chrome-extension and chrome schema.
175 pattern.SetValidSchemes(URLPattern::SCHEME_ALL); 175 pattern.SetValidSchemes(URLPattern::SCHEME_ALL);
176 debug_patterns_.push_back(pattern); 176 debug_patterns_.push_back(pattern);
177 } 177 }
178 } 178 }
179 #endif // defined(ENABLE_EXTENSIONS) 179 #endif // BUILDFLAG(ENABLE_EXTENSIONS)
180 } 180 }
181 181
182 bool NaClBrowserDelegateImpl::URLMatchesDebugPatterns( 182 bool NaClBrowserDelegateImpl::URLMatchesDebugPatterns(
183 const GURL& manifest_url) { 183 const GURL& manifest_url) {
184 #if defined(ENABLE_EXTENSIONS) 184 #if BUILDFLAG(ENABLE_EXTENSIONS)
185 // Empty patterns are forbidden so we ignore them. 185 // Empty patterns are forbidden so we ignore them.
186 if (debug_patterns_.empty()) { 186 if (debug_patterns_.empty()) {
187 return true; 187 return true;
188 } 188 }
189 bool matches = false; 189 bool matches = false;
190 for (std::vector<URLPattern>::iterator iter = debug_patterns_.begin(); 190 for (std::vector<URLPattern>::iterator iter = debug_patterns_.begin();
191 iter != debug_patterns_.end(); ++iter) { 191 iter != debug_patterns_.end(); ++iter) {
192 if (iter->MatchesURL(manifest_url)) { 192 if (iter->MatchesURL(manifest_url)) {
193 matches = true; 193 matches = true;
194 break; 194 break;
195 } 195 }
196 } 196 }
197 if (inverse_debug_patterns_) { 197 if (inverse_debug_patterns_) {
198 return !matches; 198 return !matches;
199 } else { 199 } else {
200 return matches; 200 return matches;
201 } 201 }
202 #else 202 #else
203 return false; 203 return false;
204 #endif // defined(ENABLE_EXTENSIONS) 204 #endif // BUILDFLAG(ENABLE_EXTENSIONS)
205 } 205 }
206 206
207 // This function is security sensitive. Be sure to check with a security 207 // This function is security sensitive. Be sure to check with a security
208 // person before you modify it. 208 // person before you modify it.
209 bool NaClBrowserDelegateImpl::MapUrlToLocalFilePath( 209 bool NaClBrowserDelegateImpl::MapUrlToLocalFilePath(
210 const GURL& file_url, 210 const GURL& file_url,
211 bool use_blocking_api, 211 bool use_blocking_api,
212 const base::FilePath& profile_directory, 212 const base::FilePath& profile_directory,
213 base::FilePath* file_path) { 213 base::FilePath* file_path) {
214 #if defined(ENABLE_EXTENSIONS) 214 #if BUILDFLAG(ENABLE_EXTENSIONS)
215 scoped_refptr<extensions::InfoMap> extension_info_map = 215 scoped_refptr<extensions::InfoMap> extension_info_map =
216 GetExtensionInfoMap(profile_directory); 216 GetExtensionInfoMap(profile_directory);
217 return extension_info_map->MapUrlToLocalFilePath( 217 return extension_info_map->MapUrlToLocalFilePath(
218 file_url, use_blocking_api, file_path); 218 file_url, use_blocking_api, file_path);
219 #else 219 #else
220 return false; 220 return false;
221 #endif 221 #endif
222 } 222 }
223 223
224 content::BrowserPpapiHost::OnKeepaliveCallback 224 content::BrowserPpapiHost::OnKeepaliveCallback
225 NaClBrowserDelegateImpl::GetOnKeepaliveCallback() { 225 NaClBrowserDelegateImpl::GetOnKeepaliveCallback() {
226 return base::Bind(&OnKeepalive); 226 return base::Bind(&OnKeepalive);
227 } 227 }
228 228
229 bool NaClBrowserDelegateImpl::IsNonSfiModeAllowed( 229 bool NaClBrowserDelegateImpl::IsNonSfiModeAllowed(
230 const base::FilePath& profile_directory, 230 const base::FilePath& profile_directory,
231 const GURL& manifest_url) { 231 const GURL& manifest_url) {
232 #if defined(ENABLE_EXTENSIONS) 232 #if BUILDFLAG(ENABLE_EXTENSIONS)
233 const extensions::ExtensionSet* extension_set = 233 const extensions::ExtensionSet* extension_set =
234 &GetExtensionInfoMap(profile_directory)->extensions(); 234 &GetExtensionInfoMap(profile_directory)->extensions();
235 return chrome::IsExtensionOrSharedModuleWhitelisted( 235 return chrome::IsExtensionOrSharedModuleWhitelisted(
236 manifest_url, extension_set, allowed_nonsfi_origins_); 236 manifest_url, extension_set, allowed_nonsfi_origins_);
237 #else 237 #else
238 return false; 238 return false;
239 #endif 239 #endif
240 } 240 }
241 241
242 #if defined(ENABLE_EXTENSIONS) 242 #if BUILDFLAG(ENABLE_EXTENSIONS)
243 scoped_refptr<extensions::InfoMap> NaClBrowserDelegateImpl::GetExtensionInfoMap( 243 scoped_refptr<extensions::InfoMap> NaClBrowserDelegateImpl::GetExtensionInfoMap(
244 const base::FilePath& profile_directory) { 244 const base::FilePath& profile_directory) {
245 // Get the profile associated with the renderer. 245 // Get the profile associated with the renderer.
246 Profile* profile = profile_manager_->GetProfileByPath(profile_directory); 246 Profile* profile = profile_manager_->GetProfileByPath(profile_directory);
247 DCHECK(profile); 247 DCHECK(profile);
248 scoped_refptr<extensions::InfoMap> extension_info_map = 248 scoped_refptr<extensions::InfoMap> extension_info_map =
249 extensions::ExtensionSystem::Get(profile)->info_map(); 249 extensions::ExtensionSystem::Get(profile)->info_map();
250 DCHECK(extension_info_map.get()); 250 DCHECK(extension_info_map.get());
251 return extension_info_map; 251 return extension_info_map;
252 } 252 }
253 #endif 253 #endif
OLDNEW
« no previous file with comments | « chrome/browser/nacl_host/nacl_browser_delegate_impl.h ('k') | chrome/browser/net/chrome_extensions_network_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698