| OLD | NEW |
| 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 18 matching lines...) Expand all Loading... |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "core/inspector/InjectedScriptManager.h" | 31 #include "core/inspector/InjectedScriptManager.h" |
| 32 | 32 |
| 33 #include "bindings/core/v8/ScriptValue.h" | 33 #include "bindings/core/v8/ScriptValue.h" |
| 34 #include "core/inspector/InjectedScript.h" | 34 #include "core/inspector/InjectedScript.h" |
| 35 #include "core/inspector/InjectedScriptHost.h" | 35 #include "core/inspector/InjectedScriptHost.h" |
| 36 #include "core/inspector/InjectedScriptNative.h" | 36 #include "core/inspector/InjectedScriptNative.h" |
| 37 #include "core/inspector/RemoteObjectId.h" | 37 #include "core/inspector/RemoteObjectId.h" |
| 38 #include "core/inspector/v8/V8Debugger.h" | 38 #include "core/inspector/v8/V8Debugger.h" |
| 39 #include "core/inspector/v8/V8DebuggerClient.h" |
| 39 #include "public/platform/Platform.h" | 40 #include "public/platform/Platform.h" |
| 40 #include "public/platform/WebData.h" | 41 #include "public/platform/WebData.h" |
| 41 #include "wtf/PassOwnPtr.h" | 42 #include "wtf/PassOwnPtr.h" |
| 42 | 43 |
| 43 namespace blink { | 44 namespace blink { |
| 44 | 45 |
| 45 PassOwnPtr<InjectedScriptManager> InjectedScriptManager::createForPage() | 46 PassOwnPtr<InjectedScriptManager> InjectedScriptManager::create(V8DebuggerClient
* client) |
| 46 { | 47 { |
| 47 return adoptPtr(new InjectedScriptManager(&InjectedScriptManager::canAccessI
nspectedWindow)); | 48 return adoptPtr(new InjectedScriptManager(client)); |
| 48 } | 49 } |
| 49 | 50 |
| 50 PassOwnPtr<InjectedScriptManager> InjectedScriptManager::createForWorker() | 51 InjectedScriptManager::InjectedScriptManager(V8DebuggerClient* client) |
| 51 { | |
| 52 return adoptPtr(new InjectedScriptManager(&InjectedScriptManager::canAccessI
nspectedWorkerGlobalScope)); | |
| 53 } | |
| 54 | |
| 55 InjectedScriptManager::InjectedScriptManager(InspectedStateAccessCheck accessChe
ck) | |
| 56 : m_injectedScriptHost(InjectedScriptHost::create()) | 52 : m_injectedScriptHost(InjectedScriptHost::create()) |
| 57 , m_inspectedStateAccessCheck(accessCheck) | |
| 58 , m_customObjectFormatterEnabled(false) | 53 , m_customObjectFormatterEnabled(false) |
| 54 , m_client(client) |
| 59 { | 55 { |
| 60 } | 56 } |
| 61 | 57 |
| 62 InjectedScriptManager::~InjectedScriptManager() | 58 InjectedScriptManager::~InjectedScriptManager() |
| 63 { | 59 { |
| 64 } | 60 } |
| 65 | 61 |
| 66 void InjectedScriptManager::disconnect() | 62 void InjectedScriptManager::disconnect() |
| 67 { | 63 { |
| 68 m_injectedScriptHost->disconnect(); | 64 m_injectedScriptHost->disconnect(); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 93 } | 89 } |
| 94 | 90 |
| 95 int InjectedScriptManager::discardInjectedScriptFor(ScriptState* scriptState) | 91 int InjectedScriptManager::discardInjectedScriptFor(ScriptState* scriptState) |
| 96 { | 92 { |
| 97 ScriptState::Scope scope(scriptState); | 93 ScriptState::Scope scope(scriptState); |
| 98 int contextId = V8Debugger::contextId(scriptState->context()); | 94 int contextId = V8Debugger::contextId(scriptState->context()); |
| 99 m_idToInjectedScript.remove(contextId); | 95 m_idToInjectedScript.remove(contextId); |
| 100 return contextId; | 96 return contextId; |
| 101 } | 97 } |
| 102 | 98 |
| 103 bool InjectedScriptManager::canAccessInspectedWorkerGlobalScope(ScriptState*) | |
| 104 { | |
| 105 return true; | |
| 106 } | |
| 107 | |
| 108 void InjectedScriptManager::releaseObjectGroup(const String& objectGroup) | 99 void InjectedScriptManager::releaseObjectGroup(const String& objectGroup) |
| 109 { | 100 { |
| 110 Vector<int> keys; | 101 Vector<int> keys; |
| 111 keys.appendRange(m_idToInjectedScript.keys().begin(), m_idToInjectedScript.k
eys().end()); | 102 keys.appendRange(m_idToInjectedScript.keys().begin(), m_idToInjectedScript.k
eys().end()); |
| 112 for (auto& key : keys) { | 103 for (auto& key : keys) { |
| 113 IdToInjectedScriptMap::iterator s = m_idToInjectedScript.find(key); | 104 IdToInjectedScriptMap::iterator s = m_idToInjectedScript.find(key); |
| 114 if (s != m_idToInjectedScript.end()) | 105 if (s != m_idToInjectedScript.end()) |
| 115 s->value->releaseObjectGroup(objectGroup); // m_idToInjectedScript m
ay change here. | 106 s->value->releaseObjectGroup(objectGroup); // m_idToInjectedScript m
ay change here. |
| 116 } | 107 } |
| 117 } | 108 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 133 | 124 |
| 134 InjectedScript* InjectedScriptManager::injectedScriptFor(ScriptState* scriptStat
e) | 125 InjectedScript* InjectedScriptManager::injectedScriptFor(ScriptState* scriptStat
e) |
| 135 { | 126 { |
| 136 ScriptState::Scope scope(scriptState); | 127 ScriptState::Scope scope(scriptState); |
| 137 int contextId = V8Debugger::contextId(scriptState->context()); | 128 int contextId = V8Debugger::contextId(scriptState->context()); |
| 138 | 129 |
| 139 IdToInjectedScriptMap::iterator it = m_idToInjectedScript.find(contextId); | 130 IdToInjectedScriptMap::iterator it = m_idToInjectedScript.find(contextId); |
| 140 if (it != m_idToInjectedScript.end()) | 131 if (it != m_idToInjectedScript.end()) |
| 141 return it->value.get(); | 132 return it->value.get(); |
| 142 | 133 |
| 143 if (!m_inspectedStateAccessCheck(scriptState)) | 134 if (!m_client->canAccessContext(scriptState->context())) |
| 144 return nullptr; | 135 return nullptr; |
| 145 | 136 |
| 146 RefPtr<InjectedScriptNative> injectedScriptNative = adoptRef(new InjectedScr
iptNative(scriptState->isolate())); | 137 RefPtr<InjectedScriptNative> injectedScriptNative = adoptRef(new InjectedScr
iptNative(scriptState->isolate())); |
| 147 ScriptValue injectedScriptValue = createInjectedScript(injectedScriptSource(
), scriptState, contextId, injectedScriptNative.get()); | 138 ScriptValue injectedScriptValue = createInjectedScript(injectedScriptSource(
), scriptState, contextId, injectedScriptNative.get()); |
| 148 OwnPtr<InjectedScript> result = adoptPtr(new InjectedScript(injectedScriptVa
lue, m_inspectedStateAccessCheck, injectedScriptNative.release(), contextId)); | 139 OwnPtr<InjectedScript> result = adoptPtr(new InjectedScript(injectedScriptVa
lue, m_client, injectedScriptNative.release(), contextId)); |
| 149 InjectedScript* resultPtr = result.get(); | 140 InjectedScript* resultPtr = result.get(); |
| 150 if (m_customObjectFormatterEnabled) | 141 if (m_customObjectFormatterEnabled) |
| 151 result->setCustomObjectFormatterEnabled(m_customObjectFormatterEnabled); | 142 result->setCustomObjectFormatterEnabled(m_customObjectFormatterEnabled); |
| 152 m_idToInjectedScript.set(contextId, result.release()); | 143 m_idToInjectedScript.set(contextId, result.release()); |
| 153 return resultPtr; | 144 return resultPtr; |
| 154 } | 145 } |
| 155 | 146 |
| 156 } // namespace blink | 147 } // namespace blink |
| OLD | NEW |