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

Side by Side Diff: Source/bindings/v8/V8WindowShell.cpp

Issue 261883004: set isolated world security origins (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 7 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2008, 2009, 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2008, 2009, 2011 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 223
224 if (m_world->isMainWorld()) { 224 if (m_world->isMainWorld()) {
225 updateDocument(); 225 updateDocument();
226 if (m_frame->document()) { 226 if (m_frame->document()) {
227 setSecurityToken(m_frame->document()->securityOrigin()); 227 setSecurityToken(m_frame->document()->securityOrigin());
228 ContentSecurityPolicy* csp = m_frame->document()->contentSecurityPol icy(); 228 ContentSecurityPolicy* csp = m_frame->document()->contentSecurityPol icy();
229 context->AllowCodeGenerationFromStrings(csp->allowEval(0, ContentSec urityPolicy::SuppressReport)); 229 context->AllowCodeGenerationFromStrings(csp->allowEval(0, ContentSec urityPolicy::SuppressReport));
230 context->SetErrorMessageForCodeGenerationFromStrings(v8String(m_isol ate, csp->evalDisabledErrorMessage())); 230 context->SetErrorMessageForCodeGenerationFromStrings(v8String(m_isol ate, csp->evalDisabledErrorMessage()));
231 } 231 }
232 } else { 232 } else {
233 // Using the default security token means that the canAccess is always
234 // called, which is slow.
235 // FIXME: Use tokens where possible. This will mean keeping track of all
236 // created contexts so that they can all be updated when the
237 // document domain
238 // changes.
239 context->UseDefaultSecurityToken();
240
241 SecurityOrigin* origin = m_world->isolatedWorldSecurityOrigin(); 233 SecurityOrigin* origin = m_world->isolatedWorldSecurityOrigin();
234 setSecurityToken(origin);
242 if (origin && InspectorInstrumentation::hasFrontends()) { 235 if (origin && InspectorInstrumentation::hasFrontends()) {
243 InspectorInstrumentation::didCreateIsolatedContext(m_frame, ScriptSt ate::current(m_isolate), origin); 236 InspectorInstrumentation::didCreateIsolatedContext(m_frame, ScriptSt ate::current(m_isolate), origin);
244 } 237 }
245 } 238 }
246 m_frame->loader().client()->didCreateScriptContext(context, m_world->extensi onGroup(), m_world->worldId()); 239 m_frame->loader().client()->didCreateScriptContext(context, m_world->extensi onGroup(), m_world->worldId());
247 return true; 240 return true;
248 } 241 }
249 242
250 void V8WindowShell::createContext() 243 void V8WindowShell::createContext()
251 { 244 {
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 { 362 {
370 ASSERT(isContextInitialized()); 363 ASSERT(isContextInitialized());
371 if (!m_world->isMainWorld()) 364 if (!m_world->isMainWorld())
372 return; 365 return;
373 v8::HandleScope handleScope(m_isolate); 366 v8::HandleScope handleScope(m_isolate);
374 m_scriptState->context()->Global()->ForceDelete(v8AtomicString(m_isolate, "d ocument")); 367 m_scriptState->context()->Global()->ForceDelete(v8AtomicString(m_isolate, "d ocument"));
375 } 368 }
376 369
377 void V8WindowShell::setSecurityToken(SecurityOrigin* origin) 370 void V8WindowShell::setSecurityToken(SecurityOrigin* origin)
378 { 371 {
379 ASSERT(m_world->isMainWorld());
380 // If two tokens are equal, then the SecurityOrigins canAccess each other. 372 // If two tokens are equal, then the SecurityOrigins canAccess each other.
381 // If two tokens are not equal, then we have to call canAccess. 373 // If two tokens are not equal, then we have to call canAccess.
382 // Note: we can't use the HTTPOrigin if it was set from the DOM. 374 // Note: we can't use the HTTPOrigin if it was set from the DOM.
383 String token; 375 String token;
384 // We stick with an empty token if document.domain was modified or if we 376 // We stick with an empty token if document.domain was modified or if we
385 // are in the initial empty document, so that we can do a full canAccess 377 // are in the initial empty document, so that we can do a full canAccess
386 // check in those cases. 378 // check in those cases.
387 if (!origin->domainWasSetInDOM() 379 bool delaySet = m_world->isMainWorld()
388 && !m_frame->loader().stateMachine()->isDisplayingInitialEmptyDocument() ) 380 && (origin->domainWasSetInDOM()
381 || m_frame->loader().stateMachine()->isDisplayingInitialEmptyDocumen t());
382 if (origin && !delaySet)
389 token = origin->toString(); 383 token = origin->toString();
390 384
391 // An empty or "null" token means we always have to call 385 // An empty or "null" token means we always have to call
392 // canAccess. The toString method on securityOrigins returns the 386 // canAccess. The toString method on securityOrigins returns the
393 // string "null" for empty security origins and for security 387 // string "null" for empty security origins and for security
394 // origins that should only allow access to themselves. In this 388 // origins that should only allow access to themselves. In this
395 // case, we use the global object as the security token to avoid 389 // case, we use the global object as the security token to avoid
396 // calling canAccess when a script accesses its own objects. 390 // calling canAccess when a script accesses its own objects.
397 v8::HandleScope handleScope(m_isolate); 391 v8::HandleScope handleScope(m_isolate);
398 v8::Handle<v8::Context> context = m_scriptState->context(); 392 v8::Handle<v8::Context> context = m_scriptState->context();
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 483
490 void V8WindowShell::updateSecurityOrigin(SecurityOrigin* origin) 484 void V8WindowShell::updateSecurityOrigin(SecurityOrigin* origin)
491 { 485 {
492 ASSERT(m_world->isMainWorld()); 486 ASSERT(m_world->isMainWorld());
493 if (!isContextInitialized()) 487 if (!isContextInitialized())
494 return; 488 return;
495 setSecurityToken(origin); 489 setSecurityToken(origin);
496 } 490 }
497 491
498 } // WebCore 492 } // WebCore
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698