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

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

Issue 1622213002: DevTools: make InjectedScript heap-allocated. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixed protocol tests. 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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 { 67 {
68 m_injectedScriptHost->disconnect(); 68 m_injectedScriptHost->disconnect();
69 m_injectedScriptHost.clear(); 69 m_injectedScriptHost.clear();
70 } 70 }
71 71
72 InjectedScriptHost* InjectedScriptManager::injectedScriptHost() 72 InjectedScriptHost* InjectedScriptManager::injectedScriptHost()
73 { 73 {
74 return m_injectedScriptHost.get(); 74 return m_injectedScriptHost.get();
75 } 75 }
76 76
77 InjectedScript InjectedScriptManager::findInjectedScript(int id) const 77 InjectedScript* InjectedScriptManager::findInjectedScript(int id) const
78 { 78 {
79 IdToInjectedScriptMap::const_iterator it = m_idToInjectedScript.find(id); 79 IdToInjectedScriptMap::const_iterator it = m_idToInjectedScript.find(id);
80 if (it != m_idToInjectedScript.end()) 80 if (it != m_idToInjectedScript.end())
81 return it->value; 81 return it->value.get();
82 return InjectedScript(); 82 return nullptr;
83 } 83 }
84 84
85 InjectedScript InjectedScriptManager::findInjectedScript(RemoteObjectIdBase* obj ectId) const 85 InjectedScript* InjectedScriptManager::findInjectedScript(RemoteObjectIdBase* ob jectId) const
86 { 86 {
87 if (!objectId) 87 return objectId ? findInjectedScript(objectId->contextId()) : nullptr;
88 return InjectedScript();
89 return m_idToInjectedScript.get(objectId->contextId());
90 } 88 }
91 89
92 void InjectedScriptManager::discardInjectedScripts() 90 void InjectedScriptManager::discardInjectedScripts()
93 { 91 {
94 m_idToInjectedScript.clear(); 92 m_idToInjectedScript.clear();
95 } 93 }
96 94
97 int InjectedScriptManager::discardInjectedScriptFor(ScriptState* scriptState) 95 int InjectedScriptManager::discardInjectedScriptFor(ScriptState* scriptState)
98 { 96 {
99 ScriptState::Scope scope(scriptState); 97 ScriptState::Scope scope(scriptState);
100 int contextId = V8Debugger::contextId(scriptState->context()); 98 int contextId = V8Debugger::contextId(scriptState->context());
101 m_idToInjectedScript.remove(contextId); 99 m_idToInjectedScript.remove(contextId);
102 return contextId; 100 return contextId;
103 } 101 }
104 102
105 bool InjectedScriptManager::canAccessInspectedWorkerGlobalScope(ScriptState*) 103 bool InjectedScriptManager::canAccessInspectedWorkerGlobalScope(ScriptState*)
106 { 104 {
107 return true; 105 return true;
108 } 106 }
109 107
110 void InjectedScriptManager::releaseObjectGroup(const String& objectGroup) 108 void InjectedScriptManager::releaseObjectGroup(const String& objectGroup)
111 { 109 {
112 Vector<int> keys; 110 Vector<int> keys;
113 keys.appendRange(m_idToInjectedScript.keys().begin(), m_idToInjectedScript.k eys().end()); 111 keys.appendRange(m_idToInjectedScript.keys().begin(), m_idToInjectedScript.k eys().end());
114 for (auto& key : keys) { 112 for (auto& key : keys) {
115 IdToInjectedScriptMap::iterator s = m_idToInjectedScript.find(key); 113 IdToInjectedScriptMap::iterator s = m_idToInjectedScript.find(key);
116 if (s != m_idToInjectedScript.end()) 114 if (s != m_idToInjectedScript.end())
117 s->value.releaseObjectGroup(objectGroup); // m_idToInjectedScript ma y change here. 115 s->value->releaseObjectGroup(objectGroup); // m_idToInjectedScript m ay change here.
118 } 116 }
119 } 117 }
120 118
121 void InjectedScriptManager::setCustomObjectFormatterEnabled(bool enabled) 119 void InjectedScriptManager::setCustomObjectFormatterEnabled(bool enabled)
122 { 120 {
123 m_customObjectFormatterEnabled = enabled; 121 m_customObjectFormatterEnabled = enabled;
124 IdToInjectedScriptMap::iterator end = m_idToInjectedScript.end(); 122 IdToInjectedScriptMap::iterator end = m_idToInjectedScript.end();
125 for (IdToInjectedScriptMap::iterator it = m_idToInjectedScript.begin(); it ! = end; ++it) { 123 for (IdToInjectedScriptMap::iterator it = m_idToInjectedScript.begin(); it ! = end; ++it) {
126 if (!it->value.isEmpty()) 124 it->value->setCustomObjectFormatterEnabled(enabled);
127 it->value.setCustomObjectFormatterEnabled(enabled);
128 } 125 }
129 } 126 }
130 127
131 String InjectedScriptManager::injectedScriptSource() 128 String InjectedScriptManager::injectedScriptSource()
132 { 129 {
133 const WebData& injectedScriptSourceResource = Platform::current()->loadResou rce("InjectedScriptSource.js"); 130 const WebData& injectedScriptSourceResource = Platform::current()->loadResou rce("InjectedScriptSource.js");
134 return String(injectedScriptSourceResource.data(), injectedScriptSourceResou rce.size()); 131 return String(injectedScriptSourceResource.data(), injectedScriptSourceResou rce.size());
135 } 132 }
136 133
137 InjectedScript InjectedScriptManager::injectedScriptFor(ScriptState* scriptState ) 134 InjectedScript* InjectedScriptManager::injectedScriptFor(ScriptState* scriptStat e)
138 { 135 {
139 ScriptState::Scope scope(scriptState); 136 ScriptState::Scope scope(scriptState);
140 int contextId = V8Debugger::contextId(scriptState->context()); 137 int contextId = V8Debugger::contextId(scriptState->context());
141 138
142 IdToInjectedScriptMap::iterator it = m_idToInjectedScript.find(contextId); 139 IdToInjectedScriptMap::iterator it = m_idToInjectedScript.find(contextId);
143 if (it != m_idToInjectedScript.end()) 140 if (it != m_idToInjectedScript.end())
144 return it->value; 141 return it->value.get();
145 142
146 if (!m_inspectedStateAccessCheck(scriptState)) 143 if (!m_inspectedStateAccessCheck(scriptState))
147 return InjectedScript(); 144 return nullptr;
148 145
149 RefPtr<InjectedScriptNative> injectedScriptNative = adoptRef(new InjectedScr iptNative(scriptState->isolate())); 146 RefPtr<InjectedScriptNative> injectedScriptNative = adoptRef(new InjectedScr iptNative(scriptState->isolate()));
150 ScriptValue injectedScriptValue = createInjectedScript(injectedScriptSource( ), scriptState, contextId, injectedScriptNative.get()); 147 ScriptValue injectedScriptValue = createInjectedScript(injectedScriptSource( ), scriptState, contextId, injectedScriptNative.get());
151 InjectedScript result(injectedScriptValue, m_inspectedStateAccessCheck, inje ctedScriptNative.release(), contextId); 148 OwnPtr<InjectedScript> result = adoptPtr(new InjectedScript(injectedScriptVa lue, m_inspectedStateAccessCheck, injectedScriptNative.release(), contextId));
149 InjectedScript* resultPtr = result.get();
152 if (m_customObjectFormatterEnabled) 150 if (m_customObjectFormatterEnabled)
153 result.setCustomObjectFormatterEnabled(m_customObjectFormatterEnabled); 151 result->setCustomObjectFormatterEnabled(m_customObjectFormatterEnabled);
154 m_idToInjectedScript.set(contextId, result); 152 m_idToInjectedScript.set(contextId, result.release());
155 return result; 153 return resultPtr;
156 } 154 }
157 155
158 } // namespace blink 156 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698