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

Side by Side Diff: extensions/renderer/dispatcher.cc

Issue 2574763003: Remove chrome-extension-resource:// scheme (Closed)
Patch Set: Remove BUILD reference to resources/extension outdir. Created 4 years 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "extensions/renderer/dispatcher.h" 5 #include "extensions/renderer/dispatcher.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <utility> 10 #include <utility>
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 PopulateSourceMap(); 240 PopulateSourceMap();
241 WakeEventPage::Get()->Init(RenderThread::Get()); 241 WakeEventPage::Get()->Init(RenderThread::Get());
242 // Ideally this should be done after checking 242 // Ideally this should be done after checking
243 // ExtensionAPIEnabledInExtensionServiceWorkers(), but the Dispatcher is 243 // ExtensionAPIEnabledInExtensionServiceWorkers(), but the Dispatcher is
244 // created so early that sending an IPC from browser/ process to synchronize 244 // created so early that sending an IPC from browser/ process to synchronize
245 // this enabled-ness is too late. 245 // this enabled-ness is too late.
246 WorkerThreadDispatcher::Get()->Init(RenderThread::Get()); 246 WorkerThreadDispatcher::Get()->Init(RenderThread::Get());
247 247
248 RenderThread::Get()->RegisterExtension(SafeBuiltins::CreateV8Extension()); 248 RenderThread::Get()->RegisterExtension(SafeBuiltins::CreateV8Extension());
249 249
250 // WebSecurityPolicy whitelists. They should be registered for both 250 // Register WebSecurityPolicy whitelists for the chrome-extension:// scheme.
251 // chrome-extension: and chrome-extension-resource. 251 WebString extension_scheme(base::ASCIIToUTF16(kExtensionScheme));
252 using RegisterFunction = void (*)(const WebString&);
253 RegisterFunction register_functions[] = {
254 // Treat as secure because communication with them is entirely in the
255 // browser, so there is no danger of manipulation or eavesdropping on
256 // communication with them by third parties.
257 WebSecurityPolicy::registerURLSchemeAsSecure,
258 // As far as Blink is concerned, they should be allowed to receive CORS
259 // requests. At the Extensions layer, requests will actually be blocked
260 // unless overridden by the web_accessible_resources manifest key.
261 // TODO(kalman): See what happens with a service worker.
262 WebSecurityPolicy::registerURLSchemeAsCORSEnabled,
263 // Resources should bypass Content Security Policy checks when included in
264 // protected resources. TODO(kalman): What are "protected resources"?
265 WebSecurityPolicy::registerURLSchemeAsBypassingContentSecurityPolicy,
266 // Extension resources are HTTP-like and safe to expose to the fetch API.
267 // The rules for the fetch API are consistent with XHR.
268 WebSecurityPolicy::registerURLSchemeAsSupportingFetchAPI,
269 // Extension resources, when loaded as the top-level document, should
270 // bypass Blink's strict first-party origin checks.
271 WebSecurityPolicy::registerURLSchemeAsFirstPartyWhenTopLevel,
272 };
273 252
274 WebString extension_scheme(base::ASCIIToUTF16(kExtensionScheme)); 253 // Treat as secure because communication with them is entirely in the browser,
275 WebString extension_resource_scheme(base::ASCIIToUTF16( 254 // so there is no danger of manipulation or eavesdropping on communication
276 kExtensionResourceScheme)); 255 // with them by third parties.
277 for (RegisterFunction func : register_functions) { 256 WebSecurityPolicy::registerURLSchemeAsSecure(extension_scheme);
278 func(extension_scheme); 257
279 func(extension_resource_scheme); 258 // As far as Blink is concerned, they should be allowed to receive CORS
280 } 259 // requests. At the Extensions layer, requests will actually be blocked unless
260 // overridden by the web_accessible_resources manifest key.
261 // TODO(kalman): See what happens with a service worker.
262 WebSecurityPolicy::registerURLSchemeAsCORSEnabled(extension_scheme);
263
264 // Resources should bypass Content Security Policy checks when included in
265 // protected resources. TODO(kalman): What are "protected resources"?
266 WebSecurityPolicy::registerURLSchemeAsBypassingContentSecurityPolicy(
267 extension_scheme);
268
269 // Extension resources are HTTP-like and safe to expose to the fetch API. The
270 // rules for the fetch API are consistent with XHR.
271 WebSecurityPolicy::registerURLSchemeAsSupportingFetchAPI(extension_scheme);
272
273 // Extension resources, when loaded as the top-level document, should bypass
274 // Blink's strict first-party origin checks.
275 WebSecurityPolicy::registerURLSchemeAsFirstPartyWhenTopLevel(
276 extension_scheme);
281 277
282 // For extensions, we want to ensure we call the IdleHandler every so often, 278 // For extensions, we want to ensure we call the IdleHandler every so often,
283 // even if the extension keeps up activity. 279 // even if the extension keeps up activity.
284 if (set_idle_notifications_) { 280 if (set_idle_notifications_) {
285 forced_idle_timer_.reset(new base::RepeatingTimer); 281 forced_idle_timer_.reset(new base::RepeatingTimer);
286 forced_idle_timer_->Start( 282 forced_idle_timer_->Start(
287 FROM_HERE, 283 FROM_HERE,
288 base::TimeDelta::FromMilliseconds(kMaxExtensionIdleHandlerDelayMs), 284 base::TimeDelta::FromMilliseconds(kMaxExtensionIdleHandlerDelayMs),
289 RenderThread::Get(), 285 RenderThread::Get(),
290 &RenderThread::IdleHandler); 286 &RenderThread::IdleHandler);
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 389
394 VLOG(1) << "Num tracked contexts: " << script_context_set_->size(); 390 VLOG(1) << "Num tracked contexts: " << script_context_set_->size();
395 } 391 }
396 392
397 void Dispatcher::DidInitializeServiceWorkerContextOnWorkerThread( 393 void Dispatcher::DidInitializeServiceWorkerContextOnWorkerThread(
398 v8::Local<v8::Context> v8_context, 394 v8::Local<v8::Context> v8_context,
399 int64_t service_worker_version_id, 395 int64_t service_worker_version_id,
400 const GURL& url) { 396 const GURL& url) {
401 const base::TimeTicks start_time = base::TimeTicks::Now(); 397 const base::TimeTicks start_time = base::TimeTicks::Now();
402 398
403 if (!url.SchemeIs(kExtensionScheme) && 399 if (!url.SchemeIs(kExtensionScheme)) {
404 !url.SchemeIs(kExtensionResourceScheme)) { 400 // Early-out if this isn't a chrome-extension:// scheme, because looking up
405 // Early-out if this isn't a chrome-extension:// or resource scheme, 401 // the extension registry is unnecessary if it's not. Checking this will
406 // because looking up the extension registry is unnecessary if it's not. 402 // also skip over hosted apps, which is the desired behavior - hosted app
407 // Checking this will also skip over hosted apps, which is the desired 403 // service workers are not our concern.
408 // behavior - hosted app service workers are not our concern.
409 return; 404 return;
410 } 405 }
411 406
412 const Extension* extension = 407 const Extension* extension =
413 RendererExtensionRegistry::Get()->GetExtensionOrAppByURL(url); 408 RendererExtensionRegistry::Get()->GetExtensionOrAppByURL(url);
414 409
415 if (!extension) { 410 if (!extension) {
416 // TODO(kalman): This is no good. Instead we need to either: 411 // TODO(kalman): This is no good. Instead we need to either:
417 // 412 //
418 // - Hold onto the v8::Context and create the ScriptContext and install 413 // - Hold onto the v8::Context and create the ScriptContext and install
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 520
526 script_context_set_->Remove(context); 521 script_context_set_->Remove(context);
527 VLOG(1) << "Num tracked contexts: " << script_context_set_->size(); 522 VLOG(1) << "Num tracked contexts: " << script_context_set_->size();
528 } 523 }
529 524
530 // static 525 // static
531 void Dispatcher::WillDestroyServiceWorkerContextOnWorkerThread( 526 void Dispatcher::WillDestroyServiceWorkerContextOnWorkerThread(
532 v8::Local<v8::Context> v8_context, 527 v8::Local<v8::Context> v8_context,
533 int64_t service_worker_version_id, 528 int64_t service_worker_version_id,
534 const GURL& url) { 529 const GURL& url) {
535 if (url.SchemeIs(kExtensionScheme) || 530 if (url.SchemeIs(kExtensionScheme)) {
536 url.SchemeIs(kExtensionResourceScheme)) {
537 // See comment in DidInitializeServiceWorkerContextOnWorkerThread. 531 // See comment in DidInitializeServiceWorkerContextOnWorkerThread.
538 g_worker_script_context_set.Get().Remove(v8_context, url); 532 g_worker_script_context_set.Get().Remove(v8_context, url);
539 // TODO(devlin): We're not calling 533 // TODO(devlin): We're not calling
540 // ExtensionBindingsSystem::WillReleaseScriptContext() here. This should be 534 // ExtensionBindingsSystem::WillReleaseScriptContext() here. This should be
541 // fine, since the entire bindings system is being destroyed when we 535 // fine, since the entire bindings system is being destroyed when we
542 // remove the worker data, but we might want to notify the system anyway. 536 // remove the worker data, but we might want to notify the system anyway.
543 } 537 }
544 if (ExtensionsClient::Get()->ExtensionAPIEnabledInExtensionServiceWorkers()) 538 if (ExtensionsClient::Get()->ExtensionAPIEnabledInExtensionServiceWorkers())
545 WorkerThreadDispatcher::Get()->RemoveWorkerData(service_worker_version_id); 539 WorkerThreadDispatcher::Get()->RemoveWorkerData(service_worker_version_id);
546 } 540 }
(...skipping 918 matching lines...) Expand 10 before | Expand all | Expand 10 after
1465 // The "guestViewDeny" module must always be loaded last. It registers 1459 // The "guestViewDeny" module must always be loaded last. It registers
1466 // error-providing custom elements for the GuestView types that are not 1460 // error-providing custom elements for the GuestView types that are not
1467 // available, and thus all of those types must have been checked and loaded 1461 // available, and thus all of those types must have been checked and loaded
1468 // (or not loaded) beforehand. 1462 // (or not loaded) beforehand.
1469 if (context_type == Feature::BLESSED_EXTENSION_CONTEXT) { 1463 if (context_type == Feature::BLESSED_EXTENSION_CONTEXT) {
1470 module_system->Require("guestViewDeny"); 1464 module_system->Require("guestViewDeny");
1471 } 1465 }
1472 } 1466 }
1473 1467
1474 } // namespace extensions 1468 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/common/file_util_unittest.cc ('k') | extensions/shell/browser/shell_browser_context.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698