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

Side by Side Diff: Source/bindings/core/dart/DartInjectedScriptManager.cpp

Issue 1532413002: Added Dartium changes onto 45.0.2454.104 (Closed) Base URL: http://src.chromium.org/blink/branches/chromium/2454
Patch Set: Created 5 years 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 11 matching lines...) Expand all
22 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY 22 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
23 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "config.h" 31 #include "config.h"
32 #include "bindings/core/dart/DartInjectedScriptManager.h"
33
34 #include "bindings/common/ScriptValue.h"
35 #include "bindings/core/dart/DartInjectedScript.h"
36 #include "bindings/core/dart/DartScriptState.h"
37 #include "core/inspector/InjectedScriptHost.h"
32 #include "core/inspector/InjectedScriptManager.h" 38 #include "core/inspector/InjectedScriptManager.h"
33
34 #include "bindings/core/v8/ScriptValue.h"
35 #include "core/inspector/InjectedScript.h"
36 #include "core/inspector/InjectedScriptHost.h"
37 #include "core/inspector/InjectedScriptNative.h"
38 #include "core/inspector/JSONParser.h" 39 #include "core/inspector/JSONParser.h"
39 #include "platform/JSONValues.h" 40 #include "platform/JSONValues.h"
40 #include "public/platform/Platform.h" 41 #include "public/platform/Platform.h"
41 #include "public/platform/WebData.h" 42 #include "public/platform/WebData.h"
42 #include "wtf/PassOwnPtr.h" 43 #include "wtf/PassOwnPtr.h"
43 44
44 namespace blink { 45 namespace blink {
45 46
46 PassOwnPtrWillBeRawPtr<InjectedScriptManager> InjectedScriptManager::createForPa ge() 47 DartInjectedScriptManager::DartInjectedScriptManager(InspectedStateAccessCheck a ccessCheck, InjectedScriptManager* javaScriptInjectedScriptManager)
47 { 48 : m_nextInjectedScriptId(1000000000) // Elegant design so that Dart and Java Script ids don't overlap.
48 return adoptPtrWillBeNoop(new InjectedScriptManager(&InjectedScriptManager:: canAccessInspectedWindow));
49 }
50
51 PassOwnPtrWillBeRawPtr<InjectedScriptManager> InjectedScriptManager::createForWo rker()
52 {
53 return adoptPtrWillBeNoop(new InjectedScriptManager(&InjectedScriptManager:: canAccessInspectedWorkerGlobalScope));
54 }
55
56 InjectedScriptManager::InjectedScriptManager(InspectedStateAccessCheck accessChe ck)
57 : m_nextInjectedScriptId(1)
58 , m_injectedScriptHost(InjectedScriptHost::create())
59 , m_inspectedStateAccessCheck(accessCheck) 49 , m_inspectedStateAccessCheck(accessCheck)
60 , m_customObjectFormatterEnabled(false) 50 , m_javaScriptInjectedScriptManager(javaScriptInjectedScriptManager)
61 { 51 {
62 } 52 }
63 53
64 InjectedScriptManager::~InjectedScriptManager() 54 DartInjectedScriptManager::~DartInjectedScriptManager()
65 { 55 {
66 } 56 }
67 57
68 DEFINE_TRACE(InjectedScriptManager) 58 InjectedScriptHost* DartInjectedScriptManager::injectedScriptHost()
69 { 59 {
70 visitor->trace(m_injectedScriptHost); 60 return m_javaScriptInjectedScriptManager->injectedScriptHost();
71 } 61 }
72 62
73 void InjectedScriptManager::disconnect() 63 DartInjectedScript* DartInjectedScriptManager::injectedScriptForId(int id)
74 {
75 m_injectedScriptHost->disconnect();
76 m_injectedScriptHost.clear();
77 }
78
79 InjectedScriptHost* InjectedScriptManager::injectedScriptHost()
80 {
81 return m_injectedScriptHost.get();
82 }
83
84 InjectedScript InjectedScriptManager::injectedScriptForId(int id)
85 { 64 {
86 IdToInjectedScriptMap::iterator it = m_idToInjectedScript.find(id); 65 IdToInjectedScriptMap::iterator it = m_idToInjectedScript.find(id);
87 if (it != m_idToInjectedScript.end()) 66 if (it != m_idToInjectedScript.end())
88 return it->value; 67 return it->value;
89 for (auto& state : m_scriptStateToId) { 68 for (ScriptStateToId::iterator it = m_scriptStateToId.begin(); it != m_scrip tStateToId.end(); ++it) {
90 if (state.value == id) 69 if (it->value == id)
91 return injectedScriptFor(state.key.get()); 70 return injectedScriptFor(it->key.get());
92 } 71 }
93 return InjectedScript(); 72 return 0;
94 } 73 }
95 74
96 int InjectedScriptManager::injectedScriptIdFor(ScriptState* scriptState) 75 int DartInjectedScriptManager::injectedScriptIdFor(ScriptState* scriptState)
97 { 76 {
98 ScriptStateToId::iterator it = m_scriptStateToId.find(scriptState); 77 ScriptStateToId::iterator it = m_scriptStateToId.find(scriptState);
99 if (it != m_scriptStateToId.end()) 78 if (it != m_scriptStateToId.end())
100 return it->value; 79 return it->value;
101 int id = m_nextInjectedScriptId++; 80 int id = m_nextInjectedScriptId++;
102 m_scriptStateToId.set(scriptState, id); 81 m_scriptStateToId.set(scriptState, id);
103 return id; 82 return id;
104 } 83 }
105 84
106 InjectedScript InjectedScriptManager::injectedScriptForObjectId(const String& ob jectId) 85 DartInjectedScript* DartInjectedScriptManager::injectedScriptForObjectId(const S tring& objectId)
107 { 86 {
108 RefPtr<JSONValue> parsedObjectId = parseJSON(objectId); 87 RefPtr<JSONValue> parsedObjectId = parseJSON(objectId);
109 if (parsedObjectId && parsedObjectId->type() == JSONValue::TypeObject) { 88 if (parsedObjectId && parsedObjectId->type() == JSONValue::TypeObject) {
110 long injectedScriptId = 0; 89 long injectedScriptId = 0;
111 bool success = parsedObjectId->asObject()->getNumber("injectedScriptId", &injectedScriptId); 90 bool success = parsedObjectId->asObject()->getNumber("injectedScriptId", &injectedScriptId);
112 if (success) 91 if (success) {
113 return m_idToInjectedScript.get(injectedScriptId); 92 IdToInjectedScriptMap::iterator s = m_idToInjectedScript.find(inject edScriptId);
93 if (s != m_idToInjectedScript.end())
94 return s->value;
95 }
114 } 96 }
115 return InjectedScript(); 97 return 0;
116 } 98 }
117 99
118 void InjectedScriptManager::discardInjectedScripts() 100 void DartInjectedScriptManager::discardInjectedScripts()
119 { 101 {
120 m_idToInjectedScript.clear(); 102 m_idToInjectedScript.clear();
121 m_scriptStateToId.clear(); 103 m_scriptStateToId.clear();
122 } 104 }
123 105
124 void InjectedScriptManager::discardInjectedScriptFor(ScriptState* scriptState) 106 void DartInjectedScriptManager::discardInjectedScriptsFor(LocalDOMWindow* window )
125 { 107 {
126 ScriptStateToId::iterator it = m_scriptStateToId.find(scriptState); 108 if (m_scriptStateToId.isEmpty())
127 if (it == m_scriptStateToId.end())
128 return; 109 return;
129 110
130 m_idToInjectedScript.remove(it->value); 111 Vector<long> idsToRemove;
131 m_scriptStateToId.remove(it); 112 IdToInjectedScriptMap::iterator end = m_idToInjectedScript.end();
113 for (IdToInjectedScriptMap::iterator it = m_idToInjectedScript.begin(); it ! = end; ++it) {
114 ScriptState* scriptState = it->value->scriptState();
115 if (window != scriptState->domWindow())
116 continue;
117 m_scriptStateToId.remove(scriptState);
118 idsToRemove.append(it->key);
119 }
120 for (size_t i = 0; i < idsToRemove.size(); i++)
121 delete m_idToInjectedScript.get(idsToRemove[i]);
122 m_idToInjectedScript.removeAll(idsToRemove);
123
124
125 // Now remove script states that have id but no injected script.
126 Vector<ScriptState*> scriptStatesToRemove;
127 for (ScriptStateToId::iterator it = m_scriptStateToId.begin(); it != m_scrip tStateToId.end(); ++it) {
128 ScriptState* scriptState = it->key.get();
129 if (window == scriptState->domWindow())
130 scriptStatesToRemove.append(scriptState);
131 }
132 m_scriptStateToId.removeAll(scriptStatesToRemove);
132 } 133 }
133 134
134 bool InjectedScriptManager::canAccessInspectedWorkerGlobalScope(ScriptState*) 135 bool DartInjectedScriptManager::canAccessInspectedWorkerGlobalScope(ScriptState* )
135 { 136 {
136 return true; 137 return true;
137 } 138 }
138 139
139 void InjectedScriptManager::releaseObjectGroup(const String& objectGroup) 140 void DartInjectedScriptManager::releaseObjectGroup(const String& objectGroup)
140 { 141 {
141 Vector<int> keys; 142 Vector<int> keys;
142 keys.appendRange(m_idToInjectedScript.keys().begin(), m_idToInjectedScript.k eys().end()); 143 keys.appendRange(m_idToInjectedScript.keys().begin(), m_idToInjectedScript.k eys().end());
143 for (auto& key : keys) { 144 for (Vector<int>::iterator k = keys.begin(); k != keys.end(); ++k) {
144 IdToInjectedScriptMap::iterator s = m_idToInjectedScript.find(key); 145 IdToInjectedScriptMap::iterator s = m_idToInjectedScript.find(*k);
145 if (s != m_idToInjectedScript.end()) 146 if (s != m_idToInjectedScript.end())
146 s->value.releaseObjectGroup(objectGroup); // m_idToInjectedScript ma y change here. 147 s->value->releaseObjectGroup(objectGroup); // m_idToInjectedScript m ay change here.
147 } 148 }
148 } 149 }
149 150
150 void InjectedScriptManager::setCustomObjectFormatterEnabled(bool enabled) 151 DartInjectedScript* DartInjectedScriptManager::injectedScriptFor(ScriptState* in spectedScriptState)
151 { 152 {
152 m_customObjectFormatterEnabled = enabled; 153 if (!inspectedScriptState)
153 IdToInjectedScriptMap::iterator end = m_idToInjectedScript.end(); 154 return 0;
154 for (IdToInjectedScriptMap::iterator it = m_idToInjectedScript.begin(); it ! = end; ++it) {
155 if (!it->value.isEmpty())
156 it->value.setCustomObjectFormatterEnabled(enabled);
157 }
158 }
159
160 String InjectedScriptManager::injectedScriptSource()
161 {
162 const WebData& injectedScriptSourceResource = Platform::current()->loadResou rce("InjectedScriptSource.js");
163 return String(injectedScriptSourceResource.data(), injectedScriptSourceResou rce.size());
164 }
165
166 InjectedScript InjectedScriptManager::injectedScriptFor(ScriptState* inspectedSc riptState)
167 {
168 ScriptStateToId::iterator it = m_scriptStateToId.find(inspectedScriptState); 155 ScriptStateToId::iterator it = m_scriptStateToId.find(inspectedScriptState);
169 if (it != m_scriptStateToId.end()) { 156 if (it != m_scriptStateToId.end()) {
170 IdToInjectedScriptMap::iterator it1 = m_idToInjectedScript.find(it->valu e); 157 IdToInjectedScriptMap::iterator it1 = m_idToInjectedScript.find(it->valu e);
171 if (it1 != m_idToInjectedScript.end()) 158 if (it1 != m_idToInjectedScript.end())
172 return it1->value; 159 return it1->value;
173 } 160 }
174 161
175 if (!m_inspectedStateAccessCheck(inspectedScriptState)) 162 if (!m_inspectedStateAccessCheck(inspectedScriptState))
176 return InjectedScript(); 163 return 0;
177 164
178 int id = injectedScriptIdFor(inspectedScriptState); 165 int id = injectedScriptIdFor(inspectedScriptState);
179 RefPtr<InjectedScriptNative> injectedScriptNative = adoptRef(new InjectedScr iptNative(inspectedScriptState->isolate())); 166
180 ScriptValue injectedScriptValue = createInjectedScript(injectedScriptSource( ), inspectedScriptState, id, injectedScriptNative.get()); 167 DartInjectedScript* result;
181 InjectedScript result(injectedScriptValue, m_inspectedStateAccessCheck, inje ctedScriptNative.release()); 168 ASSERT(!inspectedScriptState->isJavaScript());
182 if (m_customObjectFormatterEnabled) 169 result = new DartInjectedScript(static_cast<DartScriptState*>(inspectedScrip tState), m_inspectedStateAccessCheck, id, injectedScriptHost(), m_javaScriptInje ctedScriptManager);
183 result.setCustomObjectFormatterEnabled(m_customObjectFormatterEnabled);
184 m_idToInjectedScript.set(id, result); 170 m_idToInjectedScript.set(id, result);
185 return result; 171 return result;
186 } 172 }
187 173
188 } // namespace blink 174 } // namespace blink
175
OLDNEW
« no previous file with comments | « Source/bindings/core/dart/DartInjectedScriptManager.h ('k') | Source/bindings/core/dart/DartInspectorConsoleMessage.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698