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

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

Issue 209713003: Make DOMWrapperWorld::current() return a reference instead of a pointer (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 9 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
« no previous file with comments | « Source/bindings/v8/ScriptController.h ('k') | Source/bindings/v8/ScriptPreprocessor.cpp » ('j') | 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 Google Inc. All rights reserved. 2 * Copyright (C) 2008, 2009 Google Inc. All rights reserved.
3 * Copyright (C) 2009 Apple Inc. All rights reserved. 3 * Copyright (C) 2009 Apple Inc. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are 6 * modification, are permitted provided that the following conditions are
7 * met: 7 * met:
8 * 8 *
9 * * Redistributions of source code must retain the above copyright 9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 return result; 207 return result;
208 } 208 }
209 209
210 bool ScriptController::initializeMainWorld() 210 bool ScriptController::initializeMainWorld()
211 { 211 {
212 if (m_windowShell->isContextInitialized()) 212 if (m_windowShell->isContextInitialized())
213 return false; 213 return false;
214 return windowShell(DOMWrapperWorld::mainWorld())->isContextInitialized(); 214 return windowShell(DOMWrapperWorld::mainWorld())->isContextInitialized();
215 } 215 }
216 216
217 V8WindowShell* ScriptController::existingWindowShell(DOMWrapperWorld* world) 217 V8WindowShell* ScriptController::existingWindowShell(DOMWrapperWorld& world)
218 { 218 {
219 ASSERT(world); 219 if (world.isMainWorld())
220
221 if (world->isMainWorld())
222 return m_windowShell->isContextInitialized() ? m_windowShell.get() : 0; 220 return m_windowShell->isContextInitialized() ? m_windowShell.get() : 0;
223 221
224 IsolatedWorldMap::iterator iter = m_isolatedWorlds.find(world->worldId()); 222 IsolatedWorldMap::iterator iter = m_isolatedWorlds.find(world.worldId());
225 if (iter == m_isolatedWorlds.end()) 223 if (iter == m_isolatedWorlds.end())
226 return 0; 224 return 0;
227 return iter->value->isContextInitialized() ? iter->value.get() : 0; 225 return iter->value->isContextInitialized() ? iter->value.get() : 0;
228 } 226 }
229 227
230 V8WindowShell* ScriptController::windowShell(DOMWrapperWorld* world) 228 V8WindowShell* ScriptController::windowShell(DOMWrapperWorld& world)
231 { 229 {
232 ASSERT(world);
233
234 V8WindowShell* shell = 0; 230 V8WindowShell* shell = 0;
235 if (world->isMainWorld()) 231 if (world.isMainWorld())
236 shell = m_windowShell.get(); 232 shell = m_windowShell.get();
237 else { 233 else {
238 IsolatedWorldMap::iterator iter = m_isolatedWorlds.find(world->worldId() ); 234 IsolatedWorldMap::iterator iter = m_isolatedWorlds.find(world.worldId()) ;
239 if (iter != m_isolatedWorlds.end()) 235 if (iter != m_isolatedWorlds.end())
240 shell = iter->value.get(); 236 shell = iter->value.get();
241 else { 237 else {
242 OwnPtr<V8WindowShell> isolatedWorldShell = V8WindowShell::create(m_f rame, world, m_isolate); 238 OwnPtr<V8WindowShell> isolatedWorldShell = V8WindowShell::create(m_f rame, world, m_isolate);
243 shell = isolatedWorldShell.get(); 239 shell = isolatedWorldShell.get();
244 m_isolatedWorlds.set(world->worldId(), isolatedWorldShell.release()) ; 240 m_isolatedWorlds.set(world.worldId(), isolatedWorldShell.release());
245 } 241 }
246 } 242 }
247 if (!shell->isContextInitialized() && shell->initializeIfNeeded()) 243 if (!shell->isContextInitialized() && shell->initializeIfNeeded())
248 m_frame->loader().dispatchDidClearWindowObjectInWorld(world); 244 m_frame->loader().dispatchDidClearWindowObjectInWorld(world);
249 return shell; 245 return shell;
250 } 246 }
251 247
252 bool ScriptController::shouldBypassMainWorldContentSecurityPolicy() 248 bool ScriptController::shouldBypassMainWorldContentSecurityPolicy()
253 { 249 {
254 v8::Handle<v8::Context> context = m_isolate->GetCurrentContext(); 250 v8::Handle<v8::Context> context = m_isolate->GetCurrentContext();
255 if (context.IsEmpty() || !toDOMWindow(context)) 251 if (context.IsEmpty() || !toDOMWindow(context))
256 return false; 252 return false;
257 DOMWrapperWorld* world = DOMWrapperWorld::current(m_isolate); 253 DOMWrapperWorld& world = DOMWrapperWorld::current(m_isolate);
258 return world->isIsolatedWorld() ? world->isolatedWorldHasContentSecurityPoli cy() : false; 254 return world.isIsolatedWorld() ? world.isolatedWorldHasContentSecurityPolicy () : false;
259 } 255 }
260 256
261 TextPosition ScriptController::eventHandlerPosition() const 257 TextPosition ScriptController::eventHandlerPosition() const
262 { 258 {
263 ScriptableDocumentParser* parser = m_frame->document()->scriptableDocumentPa rser(); 259 ScriptableDocumentParser* parser = m_frame->document()->scriptableDocumentPa rser();
264 if (parser) 260 if (parser)
265 return parser->textPosition(); 261 return parser->textPosition();
266 return TextPosition::minimumPosition(); 262 return TextPosition::minimumPosition();
267 } 263 }
268 264
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 void ScriptController::setCaptureCallStackForUncaughtExceptions(bool value) 443 void ScriptController::setCaptureCallStackForUncaughtExceptions(bool value)
448 { 444 {
449 v8::V8::SetCaptureStackTraceForUncaughtExceptions(value, ScriptCallStack::ma xCallStackSizeToCapture, stackTraceOptions); 445 v8::V8::SetCaptureStackTraceForUncaughtExceptions(value, ScriptCallStack::ma xCallStackSizeToCapture, stackTraceOptions);
450 } 446 }
451 447
452 void ScriptController::collectIsolatedContexts(Vector<std::pair<ScriptState*, Se curityOrigin*> >& result) 448 void ScriptController::collectIsolatedContexts(Vector<std::pair<ScriptState*, Se curityOrigin*> >& result)
453 { 449 {
454 v8::HandleScope handleScope(m_isolate); 450 v8::HandleScope handleScope(m_isolate);
455 for (IsolatedWorldMap::iterator it = m_isolatedWorlds.begin(); it != m_isola tedWorlds.end(); ++it) { 451 for (IsolatedWorldMap::iterator it = m_isolatedWorlds.begin(); it != m_isola tedWorlds.end(); ++it) {
456 V8WindowShell* isolatedWorldShell = it->value.get(); 452 V8WindowShell* isolatedWorldShell = it->value.get();
457 SecurityOrigin* origin = isolatedWorldShell->world()->isolatedWorldSecur ityOrigin(); 453 SecurityOrigin* origin = isolatedWorldShell->world().isolatedWorldSecuri tyOrigin();
458 if (!origin) 454 if (!origin)
459 continue; 455 continue;
460 v8::Local<v8::Context> v8Context = isolatedWorldShell->context(); 456 v8::Local<v8::Context> v8Context = isolatedWorldShell->context();
461 if (v8Context.IsEmpty()) 457 if (v8Context.IsEmpty())
462 continue; 458 continue;
463 ScriptState* scriptState = ScriptState::forContext(v8Context); 459 ScriptState* scriptState = ScriptState::forContext(v8Context);
464 result.append(std::pair<ScriptState*, SecurityOrigin*>(scriptState, orig in)); 460 result.append(std::pair<ScriptState*, SecurityOrigin*>(scriptState, orig in));
465 } 461 }
466 } 462 }
467 463
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
613 609
614 void ScriptController::executeScriptInIsolatedWorld(int worldID, const Vector<Sc riptSourceCode>& sources, int extensionGroup, Vector<ScriptValue>* results) 610 void ScriptController::executeScriptInIsolatedWorld(int worldID, const Vector<Sc riptSourceCode>& sources, int extensionGroup, Vector<ScriptValue>* results)
615 { 611 {
616 ASSERT(worldID > 0); 612 ASSERT(worldID > 0);
617 613
618 v8::HandleScope handleScope(m_isolate); 614 v8::HandleScope handleScope(m_isolate);
619 v8::Local<v8::Array> v8Results; 615 v8::Local<v8::Array> v8Results;
620 { 616 {
621 v8::EscapableHandleScope evaluateHandleScope(m_isolate); 617 v8::EscapableHandleScope evaluateHandleScope(m_isolate);
622 RefPtr<DOMWrapperWorld> world = DOMWrapperWorld::ensureIsolatedWorld(wor ldID, extensionGroup); 618 RefPtr<DOMWrapperWorld> world = DOMWrapperWorld::ensureIsolatedWorld(wor ldID, extensionGroup);
623 V8WindowShell* isolatedWorldShell = windowShell(world.get()); 619 V8WindowShell* isolatedWorldShell = windowShell(*world);
624 620
625 if (!isolatedWorldShell->isContextInitialized()) 621 if (!isolatedWorldShell->isContextInitialized())
626 return; 622 return;
627 623
628 v8::Local<v8::Context> context = isolatedWorldShell->context(); 624 v8::Local<v8::Context> context = isolatedWorldShell->context();
629 v8::Context::Scope contextScope(context); 625 v8::Context::Scope contextScope(context);
630 v8::Local<v8::Array> resultArray = v8::Array::New(m_isolate, sources.siz e()); 626 v8::Local<v8::Array> resultArray = v8::Array::New(m_isolate, sources.siz e());
631 627
632 for (size_t i = 0; i < sources.size(); ++i) { 628 for (size_t i = 0; i < sources.size(); ++i) {
633 v8::Local<v8::Value> evaluationResult = executeScriptAndReturnValue( context, sources[i]); 629 v8::Local<v8::Value> evaluationResult = executeScriptAndReturnValue( context, sources[i]);
634 if (evaluationResult.IsEmpty()) 630 if (evaluationResult.IsEmpty())
635 evaluationResult = v8::Local<v8::Value>::New(m_isolate, v8::Unde fined(m_isolate)); 631 evaluationResult = v8::Local<v8::Value>::New(m_isolate, v8::Unde fined(m_isolate));
636 resultArray->Set(i, evaluationResult); 632 resultArray->Set(i, evaluationResult);
637 } 633 }
638 634
639 v8Results = evaluateHandleScope.Escape(resultArray); 635 v8Results = evaluateHandleScope.Escape(resultArray);
640 } 636 }
641 637
642 if (results && !v8Results.IsEmpty()) { 638 if (results && !v8Results.IsEmpty()) {
643 for (size_t i = 0; i < v8Results->Length(); ++i) 639 for (size_t i = 0; i < v8Results->Length(); ++i)
644 results->append(ScriptValue(v8Results->Get(i), m_isolate)); 640 results->append(ScriptValue(v8Results->Get(i), m_isolate));
645 } 641 }
646 } 642 }
647 643
648 } // namespace WebCore 644 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/bindings/v8/ScriptController.h ('k') | Source/bindings/v8/ScriptPreprocessor.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698