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

Side by Side Diff: Source/modules/cachestorage/InspectorCacheStorageAgent.cpp

Issue 1177983007: Cache Storage: restrict access to secure origins (Blink-side) (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Factor out common checks Created 5 years, 6 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 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 "config.h" 5 #include "config.h"
6 #include "modules/cachestorage/InspectorCacheStorageAgent.h" 6 #include "modules/cachestorage/InspectorCacheStorageAgent.h"
7 7
8 #include "core/InspectorBackendDispatcher.h" 8 #include "core/InspectorBackendDispatcher.h"
9 #include "core/InspectorTypeBuilder.h" 9 #include "core/InspectorTypeBuilder.h"
10 #include "core/dom/Document.h"
11 #include "core/dom/ExecutionContext.h"
12 #include "core/frame/Frame.h"
13 #include "core/page/Page.h"
10 #include "platform/JSONValues.h" 14 #include "platform/JSONValues.h"
11 #include "platform/heap/Handle.h" 15 #include "platform/heap/Handle.h"
12 #include "platform/weborigin/DatabaseIdentifier.h" 16 #include "platform/weborigin/DatabaseIdentifier.h"
13 #include "platform/weborigin/KURL.h" 17 #include "platform/weborigin/KURL.h"
14 #include "platform/weborigin/SecurityOrigin.h" 18 #include "platform/weborigin/SecurityOrigin.h"
15 #include "public/platform/Platform.h" 19 #include "public/platform/Platform.h"
16 #include "public/platform/WebServiceWorkerCache.h" 20 #include "public/platform/WebServiceWorkerCache.h"
17 #include "public/platform/WebServiceWorkerCacheError.h" 21 #include "public/platform/WebServiceWorkerCacheError.h"
18 #include "public/platform/WebServiceWorkerCacheStorage.h" 22 #include "public/platform/WebServiceWorkerCacheStorage.h"
19 #include "public/platform/WebServiceWorkerRequest.h" 23 #include "public/platform/WebServiceWorkerRequest.h"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 size_t pipe = id.find('|'); 63 size_t pipe = id.find('|');
60 if (pipe == WTF::kNotFound) { 64 if (pipe == WTF::kNotFound) {
61 *errorString = "Invalid cache id."; 65 *errorString = "Invalid cache id.";
62 return false; 66 return false;
63 } 67 }
64 *securityOrigin = id.substring(0, pipe); 68 *securityOrigin = id.substring(0, pipe);
65 *cacheName = id.substring(pipe + 1); 69 *cacheName = id.substring(pipe + 1);
66 return true; 70 return true;
67 } 71 }
68 72
69 PassOwnPtr<WebServiceWorkerCacheStorage> assertCacheStorage(ErrorString* errorSt ring, const String& securityOrigin)
70 {
71 RefPtr<SecurityOrigin> secOrigin = SecurityOrigin::createFromString(security Origin);
72 String identifier = createDatabaseIdentifierFromSecurityOrigin(secOrigin.get ());
73 OwnPtr<WebServiceWorkerCacheStorage> cache = adoptPtr(Platform::current()->c acheStorage(identifier));
74 if (!cache)
75 *errorString = "Could not find cache storage.";
76 return cache.release();
77 }
78
79 PassOwnPtr<WebServiceWorkerCacheStorage> assertCacheStorageAndNameForId(ErrorStr ing* errorString, const String& cacheId, String* cacheName)
80 {
81 String securityOrigin;
82 if (!parseCacheId(errorString, cacheId, &securityOrigin, cacheName)) {
83 return nullptr;
84 }
85 return assertCacheStorage(errorString, securityOrigin);
86 }
87
88 CString serviceWorkerCacheErrorString(WebServiceWorkerCacheError* error) 73 CString serviceWorkerCacheErrorString(WebServiceWorkerCacheError* error)
89 { 74 {
90 switch (*error) { 75 switch (*error) {
91 case WebServiceWorkerCacheErrorNotImplemented: 76 case WebServiceWorkerCacheErrorNotImplemented:
92 return CString("not implemented."); 77 return CString("not implemented.");
93 break; 78 break;
94 case WebServiceWorkerCacheErrorNotFound: 79 case WebServiceWorkerCacheErrorNotFound:
95 return CString("not found."); 80 return CString("not found.");
96 break; 81 break;
97 case WebServiceWorkerCacheErrorExists: 82 case WebServiceWorkerCacheErrorExists:
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 } 370 }
386 371
387 private: 372 private:
388 String m_requestSpec; 373 String m_requestSpec;
389 String m_cacheName; 374 String m_cacheName;
390 RefPtrWillBePersistent<DeleteEntryCallback> m_callback; 375 RefPtrWillBePersistent<DeleteEntryCallback> m_callback;
391 }; 376 };
392 377
393 } // namespace 378 } // namespace
394 379
395 InspectorCacheStorageAgent::InspectorCacheStorageAgent() 380 InspectorCacheStorageAgent::InspectorCacheStorageAgent(Page* page)
396 : InspectorBaseAgent<InspectorCacheStorageAgent, InspectorFrontend::CacheSto rage>("CacheStorage") 381 : InspectorBaseAgent<InspectorCacheStorageAgent, InspectorFrontend::CacheSto rage>("CacheStorage")
382 , m_page(page)
397 { 383 {
398 } 384 }
399 385
400 InspectorCacheStorageAgent::~InspectorCacheStorageAgent() { } 386 InspectorCacheStorageAgent::~InspectorCacheStorageAgent() { }
401 387
402 DEFINE_TRACE(InspectorCacheStorageAgent) 388 DEFINE_TRACE(InspectorCacheStorageAgent)
403 { 389 {
404 InspectorBaseAgent::trace(visitor); 390 InspectorBaseAgent::trace(visitor);
405 } 391 }
406 392
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 { 430 {
445 String cacheName; 431 String cacheName;
446 OwnPtr<WebServiceWorkerCacheStorage> cache = assertCacheStorageAndNameForId( errorString, cacheId, &cacheName); 432 OwnPtr<WebServiceWorkerCacheStorage> cache = assertCacheStorageAndNameForId( errorString, cacheId, &cacheName);
447 if (!cache) { 433 if (!cache) {
448 callback->sendFailure(*errorString); 434 callback->sendFailure(*errorString);
449 return; 435 return;
450 } 436 }
451 cache->dispatchOpen(new GetCacheForDeleteEntry(request, cacheName, callback) , WebString(cacheName)); 437 cache->dispatchOpen(new GetCacheForDeleteEntry(request, cacheName, callback) , WebString(cacheName));
452 } 438 }
453 439
440 ExecutionContext* InspectorCacheStorageAgent::assertExecutionContextForOrigin(Er rorString* error, SecurityOrigin* origin)
441 {
442 for (Frame* frame = m_page->mainFrame(); frame; frame = frame->tree().traver seNext()) {
443 if (!frame->isLocalFrame())
444 continue;
445 LocalFrame* localFrame = toLocalFrame(frame);
446 if (localFrame->document() && localFrame->document()->securityOrigin()-> isSameSchemeHostPort(origin))
447 return localFrame->document();
448 }
449
450 *error = "No frame is available for the request";
451 return 0;
452 }
453
454 PassOwnPtr<WebServiceWorkerCacheStorage> InspectorCacheStorageAgent::assertCache Storage(ErrorString* errorString, const String& securityOrigin)
455 {
456 RefPtr<SecurityOrigin> secOrigin = SecurityOrigin::createFromString(security Origin);
457 ExecutionContext* executionContext = assertExecutionContextForOrigin(errorSt ring, secOrigin.get());
458 if (!executionContext || !executionContext->isPrivilegedContext(*errorString ))
jsbell 2015/06/19 20:32:40 This should call a public static on CacheStorage r
459 return nullptr;
460
461 String identifier = createDatabaseIdentifierFromSecurityOrigin(secOrigin.get ());
462 OwnPtr<WebServiceWorkerCacheStorage> cache = adoptPtr(Platform::current()->c acheStorage(identifier));
463 if (!cache)
464 *errorString = "Could not find cache storage.";
465 return cache.release();
466 }
467
468 PassOwnPtr<WebServiceWorkerCacheStorage> InspectorCacheStorageAgent::assertCache StorageAndNameForId(ErrorString* errorString, const String& cacheId, String* cac heName)
469 {
470 String securityOrigin;
471 if (!parseCacheId(errorString, cacheId, &securityOrigin, cacheName))
472 return nullptr;
473 return assertCacheStorage(errorString, securityOrigin);
474 }
475
454 476
455 } // namespace blink 477 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698