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

Side by Side Diff: Source/core/inspector/InjectedScriptBase.cpp

Issue 300393002: Merge DevTools Refactor CL to Blink36 (Closed) Base URL: svn://svn.chromium.org/blink/branches/dart/1985
Patch Set: PTAL Created 6 years, 6 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/core/inspector/InjectedScriptBase.h ('k') | Source/core/inspector/InjectedScriptHost.h » ('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) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 25 matching lines...) Expand all
36 #include "bindings/v8/ScriptFunctionCall.h" 36 #include "bindings/v8/ScriptFunctionCall.h"
37 #include "core/inspector/InspectorInstrumentation.h" 37 #include "core/inspector/InspectorInstrumentation.h"
38 #include "core/inspector/InspectorTraceEvents.h" 38 #include "core/inspector/InspectorTraceEvents.h"
39 #include "platform/JSONValues.h" 39 #include "platform/JSONValues.h"
40 #include "wtf/text/WTFString.h" 40 #include "wtf/text/WTFString.h"
41 41
42 using WebCore::TypeBuilder::Runtime::RemoteObject; 42 using WebCore::TypeBuilder::Runtime::RemoteObject;
43 43
44 namespace WebCore { 44 namespace WebCore {
45 45
46 InjectedScriptBase::InjectedScriptBase(const String& name) 46 bool V8InjectedScriptBase::canAccessInspectedWindow() const
47 {
48 return m_inspectedStateAccessCheck(scriptState());
49 }
50
51 void V8InjectedScriptBase::initialize(ScriptObject injectedScriptObject, Inspect edStateAccessCheck accessCheck)
52 {
53 m_injectedScriptObject = injectedScriptObject;
54 m_inspectedStateAccessCheck = accessCheck;
55 }
56
57 V8InjectedScriptBase::V8InjectedScriptBase(const String& name)
47 : m_name(name) 58 : m_name(name)
48 , m_inspectedStateAccessCheck(0) 59 , m_inspectedStateAccessCheck(0)
49 { 60 {
50 } 61 }
51 62
52 InjectedScriptBase::InjectedScriptBase(const String& name, ScriptObject injected ScriptObject, InspectedStateAccessCheck accessCheck) 63 V8InjectedScriptBase::V8InjectedScriptBase(const String& name, ScriptObject inje ctedScriptObject, InspectedStateAccessCheck accessCheck)
53 : m_name(name) 64 : m_name(name)
65 , m_inspectedStateAccessCheck(accessCheck)
54 , m_injectedScriptObject(injectedScriptObject) 66 , m_injectedScriptObject(injectedScriptObject)
55 , m_inspectedStateAccessCheck(accessCheck)
56 { 67 {
57 } 68 }
58 69
59 void InjectedScriptBase::initialize(ScriptObject injectedScriptObject, Inspected StateAccessCheck accessCheck) 70 const ScriptObject& V8InjectedScriptBase::injectedScriptObject() const
60 {
61 m_injectedScriptObject = injectedScriptObject;
62 m_inspectedStateAccessCheck = accessCheck;
63 }
64
65 bool InjectedScriptBase::canAccessInspectedWindow() const
66 {
67 return m_inspectedStateAccessCheck(m_injectedScriptObject.scriptState());
68 }
69
70 const ScriptObject& InjectedScriptBase::injectedScriptObject() const
71 { 71 {
72 return m_injectedScriptObject; 72 return m_injectedScriptObject;
73 } 73 }
74 74
75 ScriptValue InjectedScriptBase::callFunctionWithEvalEnabled(ScriptFunctionCall& function, bool& hadException) const 75 ScriptValue V8InjectedScriptBase::callFunctionWithEvalEnabled(ScriptFunctionCall & function, bool& hadException) const
76 { 76 {
77 ExecutionContext* executionContext = m_injectedScriptObject.scriptState()->e xecutionContext(); 77 ExecutionContext* executionContext = m_injectedScriptObject.scriptState()->e xecutionContext();
78 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "FunctionCall", "data", InspectorFunctionCallEvent::data(executionContext, 0, name(), 1)); 78 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "FunctionCall", "data", InspectorFunctionCallEvent::data(executionContext, 0, name(), 1));
79 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline.stack"), " CallStack", "stack", InspectorCallStackEvent::currentCallStack()); 79 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline.stack"), " CallStack", "stack", InspectorCallStackEvent::currentCallStack());
80 // FIXME(361045): remove InspectorInstrumentation calls once DevTools Timeli ne migrates to tracing. 80 // FIXME(361045): remove InspectorInstrumentation calls once DevTools Timeli ne migrates to tracing.
81 InspectorInstrumentationCookie cookie = InspectorInstrumentation::willCallFu nction(executionContext, 0, name(), 1); 81 InspectorInstrumentationCookie cookie = InspectorInstrumentation::willCallFu nction(executionContext, 0, name(), 1);
82 82
83 ScriptState* scriptState = m_injectedScriptObject.scriptState(); 83 ScriptState* scriptState = m_injectedScriptObject.scriptState();
84 bool evalIsDisabled = false; 84 bool evalIsDisabled = false;
85 if (scriptState) { 85 if (scriptState) {
86 evalIsDisabled = !scriptState->evalEnabled(); 86 evalIsDisabled = !scriptState->evalEnabled();
87 // Temporarily enable allow evals for inspector. 87 // Temporarily enable allow evals for inspector.
88 if (evalIsDisabled) 88 if (evalIsDisabled)
89 scriptState->setEvalEnabled(true); 89 scriptState->setEvalEnabled(true);
90 } 90 }
91 91
92 ScriptValue resultValue = function.call(hadException); 92 ScriptValue resultValue = function.call(hadException);
93 93
94 if (evalIsDisabled) 94 if (evalIsDisabled)
95 scriptState->setEvalEnabled(false); 95 scriptState->setEvalEnabled(false);
96 96
97 InspectorInstrumentation::didCallFunction(cookie); 97 InspectorInstrumentation::didCallFunction(cookie);
98 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "Update Counters", "data", InspectorUpdateCountersEvent::data()); 98 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "Update Counters", "data", InspectorUpdateCountersEvent::data());
99 return resultValue; 99 return resultValue;
100 } 100 }
101 101
102 void InjectedScriptBase::makeCall(ScriptFunctionCall& function, RefPtr<JSONValue >* result) 102 void V8InjectedScriptBase::makeCall(ScriptFunctionCall& function, RefPtr<JSONVal ue>* result)
103 { 103 {
104 if (isEmpty() || !canAccessInspectedWindow()) { 104 if (isEmpty() || !canAccessInspectedWindow()) {
105 *result = JSONValue::null(); 105 *result = JSONValue::null();
106 return; 106 return;
107 } 107 }
108 108
109 bool hadException = false; 109 bool hadException = false;
110 ScriptValue resultValue = callFunctionWithEvalEnabled(function, hadException ); 110 ScriptValue resultValue = callFunctionWithEvalEnabled(function, hadException );
111 111
112 ASSERT(!hadException); 112 ASSERT(!hadException);
113 if (!hadException) { 113 if (!hadException) {
114 *result = resultValue.toJSONValue(m_injectedScriptObject.scriptState()); 114 *result = resultValue.toJSONValue(m_injectedScriptObject.scriptState());
115 if (!*result) 115 if (!*result)
116 *result = JSONString::create(String::format("Object has too long ref erence chain(must not be longer than %d)", JSONValue::maxDepth)); 116 *result = JSONString::create(String::format("Object has too long ref erence chain(must not be longer than %d)", JSONValue::maxDepth));
117 } else { 117 } else {
118 *result = JSONString::create("Exception while making a call."); 118 *result = JSONString::create("Exception while making a call.");
119 } 119 }
120 } 120 }
121 121
122 void InjectedScriptBase::makeEvalCall(ErrorString* errorString, ScriptFunctionCa ll& function, RefPtr<TypeBuilder::Runtime::RemoteObject>* objectResult, TypeBuil der::OptOutput<bool>* wasThrown) 122 void V8InjectedScriptBase::makeEvalCall(ErrorString* errorString, ScriptFunction Call& function, RefPtr<TypeBuilder::Runtime::RemoteObject>* objectResult, TypeBu ilder::OptOutput<bool>* wasThrown)
123 { 123 {
124 RefPtr<JSONValue> result; 124 RefPtr<JSONValue> result;
125 makeCall(function, &result); 125 makeCall(function, &result);
126 if (!result) { 126 if (!result) {
127 *errorString = "Internal error: result value is empty"; 127 *errorString = "Internal error: result value is empty";
128 return; 128 return;
129 } 129 }
130 if (result->type() == JSONValue::TypeString) { 130 if (result->type() == JSONValue::TypeString) {
131 result->asString(errorString); 131 result->asString(errorString);
132 ASSERT(errorString->length()); 132 ASSERT(errorString->length());
133 return; 133 return;
134 } 134 }
135 RefPtr<JSONObject> resultPair = result->asObject(); 135 RefPtr<JSONObject> resultPair = result->asObject();
136 if (!resultPair) { 136 if (!resultPair) {
137 *errorString = "Internal error: result is not an Object"; 137 *errorString = "Internal error: result is not an Object";
138 return; 138 return;
139 } 139 }
140 RefPtr<JSONObject> resultObj = resultPair->getObject("result"); 140 RefPtr<JSONObject> resultObj = resultPair->getObject("result");
141 bool wasThrownVal = false; 141 bool wasThrownVal = false;
142 if (!resultObj || !resultPair->getBoolean("wasThrown", &wasThrownVal)) { 142 if (!resultObj || !resultPair->getBoolean("wasThrown", &wasThrownVal)) {
143 *errorString = "Internal error: result is not a pair of value and wasThr own flag"; 143 *errorString = "Internal error: result is not a pair of value and wasThr own flag";
144 return; 144 return;
145 } 145 }
146 *objectResult = TypeBuilder::Runtime::RemoteObject::runtimeCast(resultObj); 146 *objectResult = TypeBuilder::Runtime::RemoteObject::runtimeCast(resultObj);
147 *wasThrown = wasThrownVal; 147 *wasThrown = wasThrownVal;
148 } 148 }
149 149
150 } // namespace WebCore 150 } // namespace WebCore
151 151
OLDNEW
« no previous file with comments | « Source/core/inspector/InjectedScriptBase.h ('k') | Source/core/inspector/InjectedScriptHost.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698