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

Side by Side Diff: third_party/WebKit/Source/core/inspector/InjectedScriptManager.cpp

Issue 1636223002: DevTools: remove ScriptState/Value from the InjectedScript APIs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. 2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved.
3 * Copyright (C) 2008 Matt Lilek <webkit@mattlilek.com> 3 * Copyright (C) 2008 Matt Lilek <webkit@mattlilek.com>
4 * Copyright (C) 2012 Google Inc. All rights reserved. 4 * Copyright (C) 2012 Google Inc. All rights reserved.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 9 *
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 InjectedScript* InjectedScriptManager::findInjectedScript(RemoteObjectIdBase* ob jectId) const 81 InjectedScript* InjectedScriptManager::findInjectedScript(RemoteObjectIdBase* ob jectId) const
82 { 82 {
83 return objectId ? findInjectedScript(objectId->contextId()) : nullptr; 83 return objectId ? findInjectedScript(objectId->contextId()) : nullptr;
84 } 84 }
85 85
86 void InjectedScriptManager::discardInjectedScripts() 86 void InjectedScriptManager::discardInjectedScripts()
87 { 87 {
88 m_idToInjectedScript.clear(); 88 m_idToInjectedScript.clear();
89 } 89 }
90 90
91 int InjectedScriptManager::discardInjectedScriptFor(ScriptState* scriptState) 91 int InjectedScriptManager::discardInjectedScriptFor(v8::Local<v8::Context> conte xt)
92 { 92 {
93 ScriptState::Scope scope(scriptState); 93 int contextId = V8Debugger::contextId(context);
94 int contextId = V8Debugger::contextId(scriptState->context());
95 m_idToInjectedScript.remove(contextId); 94 m_idToInjectedScript.remove(contextId);
96 return contextId; 95 return contextId;
97 } 96 }
98 97
99 void InjectedScriptManager::releaseObjectGroup(const String& objectGroup) 98 void InjectedScriptManager::releaseObjectGroup(const String& objectGroup)
100 { 99 {
101 Vector<int> keys; 100 Vector<int> keys;
102 keys.appendRange(m_idToInjectedScript.keys().begin(), m_idToInjectedScript.k eys().end()); 101 keys.appendRange(m_idToInjectedScript.keys().begin(), m_idToInjectedScript.k eys().end());
103 for (auto& key : keys) { 102 for (auto& key : keys) {
104 IdToInjectedScriptMap::iterator s = m_idToInjectedScript.find(key); 103 IdToInjectedScriptMap::iterator s = m_idToInjectedScript.find(key);
(...skipping 10 matching lines...) Expand all
115 it->value->setCustomObjectFormatterEnabled(enabled); 114 it->value->setCustomObjectFormatterEnabled(enabled);
116 } 115 }
117 } 116 }
118 117
119 String InjectedScriptManager::injectedScriptSource() 118 String InjectedScriptManager::injectedScriptSource()
120 { 119 {
121 const WebData& injectedScriptSourceResource = Platform::current()->loadResou rce("InjectedScriptSource.js"); 120 const WebData& injectedScriptSourceResource = Platform::current()->loadResou rce("InjectedScriptSource.js");
122 return String(injectedScriptSourceResource.data(), injectedScriptSourceResou rce.size()); 121 return String(injectedScriptSourceResource.data(), injectedScriptSourceResou rce.size());
123 } 122 }
124 123
125 InjectedScript* InjectedScriptManager::injectedScriptFor(ScriptState* scriptStat e) 124 InjectedScript* InjectedScriptManager::injectedScriptFor(v8::Local<v8::Context> context)
126 { 125 {
127 ScriptState::Scope scope(scriptState); 126 v8::HandleScope handles(context->GetIsolate());
dgozman 2016/01/27 02:36:37 Not needed.
pfeldman 2016/01/27 16:56:20 Done.
128 int contextId = V8Debugger::contextId(scriptState->context()); 127 v8::Context::Scope scope(context);
dgozman 2016/01/27 02:36:37 Now you have to artificially enter this context in
pfeldman 2016/01/27 16:56:20 This is a trial check for access. Actual access is
128 int contextId = V8Debugger::contextId(context);
129 129
130 IdToInjectedScriptMap::iterator it = m_idToInjectedScript.find(contextId); 130 IdToInjectedScriptMap::iterator it = m_idToInjectedScript.find(contextId);
131 if (it != m_idToInjectedScript.end()) 131 if (it != m_idToInjectedScript.end())
132 return it->value.get(); 132 return it->value.get();
133 133
134 if (!m_client->canAccessContext(scriptState->context())) 134 if (!m_client->callingContextCanAccessContext(context))
135 return nullptr; 135 return nullptr;
136 136
137 RefPtr<InjectedScriptNative> injectedScriptNative = adoptRef(new InjectedScr iptNative(scriptState->isolate())); 137 RefPtr<InjectedScriptNative> injectedScriptNative = adoptRef(new InjectedScr iptNative(context->GetIsolate()));
138 ScriptValue injectedScriptValue = createInjectedScript(injectedScriptSource( ), scriptState, contextId, injectedScriptNative.get()); 138 v8::Local<v8::Object> injectedScriptValue = createInjectedScript(injectedScr iptSource(), context, contextId, injectedScriptNative.get());
139 OwnPtr<InjectedScript> result = adoptPtr(new InjectedScript(injectedScriptVa lue, m_client, injectedScriptNative.release(), contextId)); 139 OwnPtr<InjectedScript> result = adoptPtr(new InjectedScript(injectedScriptVa lue, m_client, injectedScriptNative.release(), contextId));
140 InjectedScript* resultPtr = result.get(); 140 InjectedScript* resultPtr = result.get();
141 if (m_customObjectFormatterEnabled) 141 if (m_customObjectFormatterEnabled)
142 result->setCustomObjectFormatterEnabled(m_customObjectFormatterEnabled); 142 result->setCustomObjectFormatterEnabled(m_customObjectFormatterEnabled);
143 m_idToInjectedScript.set(contextId, result.release()); 143 m_idToInjectedScript.set(contextId, result.release());
144 return resultPtr; 144 return resultPtr;
145 } 145 }
146 146
147 } // namespace blink 147 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698