From 38b62835d5e389f17b1071377eabd531085c5a1a Mon Sep 17 00:00:00 2001 From: "ojan@google.com" Date: Tue, 7 Oct 2008 20:47:13 +0000 Subject: Merge in InspectorController changes. Get rid of all the crazy ifdef'ing in port/.../InspectorController.cpp. Change jsc build back to useing the InspectorController in third_party/WebKit. Review URL: http://codereview.chromium.org/6519 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@2961 0039d316-1c4b-4281-b951-d872f2087c98 --- webkit/build/KJSBindings/KJSBindings.vcproj | 2 +- webkit/glue/webview_impl.cc | 2 +- webkit/pending/InspectorController.h | 364 +---- webkit/port/page/inspector/InspectorController.cpp | 1552 ++---------------- .../port/page/inspector/InspectorControllerKJS.cpp | 1678 -------------------- 5 files changed, 212 insertions(+), 3386 deletions(-) delete mode 100644 webkit/port/page/inspector/InspectorControllerKJS.cpp diff --git a/webkit/build/KJSBindings/KJSBindings.vcproj b/webkit/build/KJSBindings/KJSBindings.vcproj index 101780d..9118789 100644 --- a/webkit/build/KJSBindings/KJSBindings.vcproj +++ b/webkit/build/KJSBindings/KJSBindings.vcproj @@ -2406,7 +2406,7 @@ > inspectorController()->showConsole(); + page_->inspectorController()->showPanel(InspectorController::ConsolePanel); } void WebViewImpl::DragSourceEndedAt( diff --git a/webkit/pending/InspectorController.h b/webkit/pending/InspectorController.h index eb83ba6..2ec61b7 100644 --- a/webkit/pending/InspectorController.h +++ b/webkit/pending/InspectorController.h @@ -29,19 +29,9 @@ #ifndef InspectorController_h #define InspectorController_h -#if USE(V8) -// NOTE: The revision of the inspector JS and C++ that we are merged to -// is stored in trunk/webkit/port/page/inspector/BASE_REVISION. - -// TODO(ojan): When we merge to webkit trunk, get rid of the need for this. -// This part of this file contains the version of InspectorController.h that -// we are synced to in trunk WebKit along with our (extensive) changes for V8. -// The block below for #elif USE(JAVSCRIPTCORE_BINDINGS) has the old version -// of InspectorController.h from the 3.1 branch, which we need to keep for the -// KJS build. We unfortunately can't just use a different header file for -// each build because a bunch of different files pull in this header file. - +#if USE(JSC) #include "JavaScriptDebugListener.h" +#endif #include "Console.h" #include "PlatformString.h" @@ -121,23 +111,41 @@ public: void hideHighlight(); void show(); - void showConsole(); - void showTimeline(); + void showPanel(SpecialPanels); void close(); +#if USE(JSC) + bool isRecordingUserInitiatedProfile() const { return m_recordingUserInitiatedProfile; } + void startUserInitiatedProfiling(); + void stopUserInitiatedProfiling(); +#endif + bool windowVisible(); - void setWindowVisible(bool visible = true); + void setWindowVisible(bool visible = true, bool attached = false); #if USE(JSC) - void addMessageToConsole(MessageSource, MessageLevel, KJS::ExecState*, const KJS::List& arguments, unsigned lineNumber, const String& sourceID); + void addMessageToConsole(MessageSource, MessageLevel, KJS::ExecState*, const KJS::ArgList& arguments, unsigned lineNumber, const String& sourceID); #elif USE(V8) // TODO(ojan): Do we need to implement this version? #endif void addMessageToConsole(MessageSource, MessageLevel, const String& message, unsigned lineNumber, const String& sourceID); + void clearConsoleMessages(); + void toggleRecordButton(bool); + +#if USE(JSC) + void addProfile(PassRefPtr, unsigned lineNumber, const KJS::UString& sourceURL); + void addProfileMessageToConsole(PassRefPtr prpProfile, unsigned lineNumber, const KJS::UString& sourceURL); + void addScriptProfile(KJS::Profile* profile); + const Vector >& profiles() const { return m_profiles; } +#endif + void attachWindow(); void detachWindow(); + void setAttachedWindow(bool); + void setAttachedWindowHeight(unsigned height); + #if USE(JSC) JSContextRef scriptContext() const { return m_scriptContext; }; void setScriptContext(JSContextRef context) { m_scriptContext = context; }; @@ -177,13 +185,41 @@ public: const ResourcesMap& resources() const { return m_resources; } void moveWindowBy(float x, float y) const; + void closeWindow(); void startDebuggingAndReloadInspectedPage(); void stopDebugging(); + +#if USE(JSC) bool debuggerAttached() const { return m_debuggerAttached; } + JavaScriptCallFrame* currentCallFrame() const; + + void addBreakpoint(int sourceID, unsigned lineNumber); + void removeBreakpoint(int sourceID, unsigned lineNumber); + + bool pauseOnExceptions(); + void setPauseOnExceptions(bool pause); + + void pauseInDebugger(); + void resumeDebugger(); + + void stepOverStatementInDebugger(); + void stepIntoStatementInDebugger(); + void stepOutOfFunctionInDebugger(); +#endif + void drawNodeHighlight(GraphicsContext&) const; +#if USE(JSC) + void count(const KJS::UString& title, unsigned lineNumber, const String& sourceID); + + void startTiming(const KJS::UString& title); + bool stopTiming(const KJS::UString& title, double& elapsed); + + void startGroup(MessageSource source, KJS::ExecState* exec, const KJS::ArgList& arguments, unsigned lineNumber, const String& sourceURL); + void endGroup(MessageSource source, unsigned lineNumber, const String& sourceURL); +#endif #if USE(V8) // InspectorController.idl @@ -223,6 +259,7 @@ private: #endif void updateScriptResourceRequest(InspectorResource*); void updateScriptResourceResponse(InspectorResource*); + void updateScriptResourceType(InspectorResource*); void updateScriptResource(InspectorResource*, int length); void updateScriptResource(InspectorResource*, bool finished, bool failed = false); void updateScriptResource(InspectorResource*, double startTime, double responseReceivedTime, double endTime); @@ -258,20 +295,17 @@ private: #if USE(JSC) JSValueRef callSimpleFunction(JSContextRef, JSObjectRef thisObject, const char* functionName) const; - JSValueRef callFunction(JSContextRef, JSObjectRef thisObject, const char* functionName, size_t argumentCount, const JSValueRef arguments[], JSValueRef& exception) const; - bool handleException(JSContextRef, JSValueRef exception, unsigned lineNumber) const; + JSValueRef callFunction(JSContextRef, JSObjectRef thisObject, const char* functionName, size_t argumentCount, const JSValueRef arguments[], JSValueRef& exception) const; + + bool handleException(JSContextRef, JSValueRef exception, unsigned lineNumber) const; #endif void showWindow(); - void closeWindow(); #if USE(JSC) - virtual void didParseSource(KJS::ExecState*, const KJS::UString& source, int startingLineNumber, const KJS::UString& sourceURL, int sourceID); - virtual void failedToParseSource(KJS::ExecState*, const KJS::UString& source, int startingLineNumber, const KJS::UString& sourceURL, int errorLine, const KJS::UString& errorMessage); - virtual void didEnterCallFrame(KJS::ExecState*, int sourceID, int lineNumber); - virtual void willExecuteStatement(KJS::ExecState*, int sourceID, int lineNumber); - virtual void willLeaveCallFrame(KJS::ExecState*, int sourceID, int lineNumber); - virtual void exceptionWasRaised(KJS::ExecState*, int sourceID, int lineNumber); + virtual void didParseSource(KJS::ExecState*, const KJS::SourceProvider& source, int startingLineNumber, const KJS::UString& sourceURL, int sourceID); + virtual void failedToParseSource(KJS::ExecState*, const KJS::SourceProvider& source, int startingLineNumber, const KJS::UString& sourceURL, int errorLine, const KJS::UString& errorMessage); + virtual void didPause(); #elif USE(V8) // TODO(ojan): implement when we start integrating in the debugger. #endif @@ -282,283 +316,14 @@ private: RefPtr m_nodeToFocus; RefPtr m_mainResource; ResourcesMap m_resources; + HashSet m_knownResources; FrameResourcesMap m_frameResources; Vector m_consoleMessages; -#if ENABLE(DATABASE) - DatabaseResourcesSet m_databaseResources; -#endif -#if USE(JSC) - JSObjectRef m_scriptObject; - JSObjectRef m_controllerScriptObject; - JSContextRef m_scriptContext; -#elif USE(V8) - v8::Persistent m_scriptObject; -#endif - bool m_windowVisible; - bool m_debuggerAttached; - SpecialPanels m_showAfterVisible; - unsigned long m_nextIdentifier; - RefPtr m_highlightedNode; -}; - -} // namespace WebCore - -#elif USE(JSC) -// TODO(ojan): When we merge to webkit trunk, get rid of all the code below. -// This part of this file contains the version of InspectorController.h that -// we are synced to in the 3.1 branch, which we need to keep for the -// KJS build. We unfortunately can't just use a different header file for -// each build because a bunch of different files pull in this header file. - -#include "Chrome.h" -#include -#if USE(JSC) -#include -#elif USE(V8) -#include -#endif -#include -#include -#include - - -namespace WebCore { - -class Database; -class DocumentLoader; -class GraphicsContext; -class DOMWindow; -class InspectorClient; -class Node; -class ResourceResponse; -class ResourceError; - -struct ConsoleMessage; -struct InspectorDatabaseResource; -struct InspectorResource; -class ResourceRequest; - -class InspectorController : public RefCounted { -public: - - typedef HashMap > ResourcesMap; - typedef HashMap, ResourcesMap*> FrameResourcesMap; - typedef HashSet > DatabaseResourcesSet; - - typedef enum { - CurrentPanel, - ConsolePanel, - DatabasesPanel, - ElementsPanel, - ProfilesPanel, - ResourcesPanel, - ScriptsPanel - } SpecialPanels; - - InspectorController(Page*, InspectorClient*); - ~InspectorController(); - - void inspectedPageDestroyed(); - void pageDestroyed() { m_page = 0; } - void inspectedPageDestroyed(); - - bool enabled() const; - - Page* inspectedPage() const { return m_inspectedPage; } - - String localizedStringsURL(); - - void inspect(Node*); - void highlight(Node*); - void hideHighlight(); - - void show(); - void showPanel(SpecialPanels); - void close(); - - bool isRecordingUserInitiatedProfile() const { return m_recordingUserInitiatedProfile; } - void startUserInitiatedProfiling(); - void stopUserInitiatedProfiling(); - void finishedProfiling(PassRefPtr); - - bool windowVisible(); - void setWindowVisible(bool visible = true, bool attached = false); - - void addMessageToConsole(MessageSource, MessageLevel, KJS::ExecState*, const KJS::ArgList& arguments, unsigned lineNumber, const String& sourceID); - void addMessageToConsole(MessageSource, MessageLevel, const String& message, unsigned lineNumber, const String& sourceID); - void clearConsoleMessages(); - void toggleRecordButton(bool); - - void addProfile(PassRefPtr, int lineNumber, const KJS::UString& sourceURL); - void addProfileMessageToConsole(PassRefPtr prpProfile, int lineNumber, const KJS::UString& sourceURL); - void addScriptProfile(KJS::Profile* profile); - const Vector >& profiles() const { return m_profiles; } - - void attachWindow(); - void detachWindow(); - - void setAttachedWindow(bool); - void setAttachedWindowHeight(unsigned height); - #if USE(JSC) - JSContextRef scriptContext() const { return m_scriptContext; }; - void setScriptContext(JSContextRef context) { m_scriptContext = context; }; -#endif - - void inspectedWindowScriptObjectCleared(Frame*); - void windowScriptObjectAvailable(); - - void scriptObjectReady(); - - void populateScriptObjects(); - void resetScriptObjects(); - - void didCommitLoad(DocumentLoader*); - void frameDetachedFromParent(Frame*); - - void didLoadResourceFromMemoryCache(DocumentLoader*, const ResourceRequest&, const ResourceResponse&, int length); - - void identifierForInitialRequest(unsigned long identifier, DocumentLoader*, const ResourceRequest&); - void willSendRequest(DocumentLoader*, unsigned long identifier, ResourceRequest&, const ResourceResponse& redirectResponse); - void didReceiveResponse(DocumentLoader*, unsigned long identifier, const ResourceResponse&); - void didReceiveContentLength(DocumentLoader*, unsigned long identifier, int lengthReceived); - void didFinishLoading(DocumentLoader*, unsigned long identifier); - void didFailLoading(DocumentLoader*, unsigned long identifier, const ResourceError&); - void resourceRetrievedByXMLHttpRequest(unsigned long identifier, KJS::UString& sourceString); - -#if ENABLE(DATABASE) - void didOpenDatabase(Database*, const String& domain, const String& name, const String& version); -#endif - - const ResourcesMap& resources() const { return m_resources; } - - void moveWindowBy(float x, float y) const; - void closeWindow(); - - void startDebuggingAndReloadInspectedPage(); - void stopDebugging(); - bool debuggerAttached() const { return m_debuggerAttached; } - - JavaScriptCallFrame* currentCallFrame() const; - - void addBreakpoint(int sourceID, unsigned lineNumber); - void removeBreakpoint(int sourceID, unsigned lineNumber); - - bool pauseOnExceptions(); - void setPauseOnExceptions(bool pause); - - void pauseInDebugger(); - void resumeDebugger(); - - void stepOverStatementInDebugger(); - void stepIntoStatementInDebugger(); - void stepOutOfFunctionInDebugger(); - - void drawNodeHighlight(GraphicsContext&) const; - - void startTiming(const KJS::UString& title); - bool stopTiming(const KJS::UString& title, double& elapsed); - - void startGroup(MessageSource source, KJS::ExecState* exec, const KJS::ArgList& arguments, unsigned lineNumber, const String& sourceURL); - void endGroup(MessageSource source, unsigned lineNumber, const String& sourceURL); -#if USE(V8) - // InspectorController.idl - void addSourceToFrame(unsigned long identifier, Node* frame); - Node* getResourceDocumentNode(unsigned long identifier); - void highlightDOMNode(Node* node); - void hideDOMNodeHighlight(); - void loaded(); - void attach(); - void detach(); - void log(const String& message); - // TODO(jackson): search should return an array of JSRanges - void search(Node* node, const String& query); - DOMWindow* inspectedWindow(); - String platform() const; -#endif - -private: - void focusNode(); - - void addConsoleMessage(ConsoleMessage*); - void addScriptConsoleMessage(const ConsoleMessage*); - -#if USE(V8) - void setScriptObject(v8::Handle newScriptObject) - { - if (!m_scriptObject.IsEmpty()) { - m_scriptObject.Dispose(); - m_scriptObject.Clear(); - } - - if (!newScriptObject.IsEmpty()) - m_scriptObject = v8::Persistent::New(newScriptObject); - } -#endif - - void addResource(InspectorResource*); - void removeResource(InspectorResource*); - -#if USE(JSC) - JSObjectRef addScriptResource(InspectorResource*); -#elif USE(V8) - void addScriptResource(InspectorResource*); -#endif - void removeScriptResource(InspectorResource*); - -#if USE(JSC) - JSObjectRef addAndUpdateScriptResource(InspectorResource*); -#elif USE(V8) - void addAndUpdateScriptResource(InspectorResource*); + Vector > m_profiles; #endif - void updateScriptResourceRequest(InspectorResource*); - void updateScriptResourceResponse(InspectorResource*); - void updateScriptResourceType(InspectorResource*); - void updateScriptResource(InspectorResource*, int length); - void updateScriptResource(InspectorResource*, bool finished, bool failed = false); - void updateScriptResource(InspectorResource*, double startTime, double responseReceivedTime, double endTime); - - void pruneResources(ResourcesMap*, DocumentLoader* loaderToKeep = 0); - void removeAllResources(ResourcesMap* map) { pruneResources(map); } - - // Return true if the inspector should track request/response activity. - // Chrome's policy is to only log requests if the inspector is already open. - // This reduces the passive bloat from InspectorController: http://b/1113875 - bool trackResources() const { return m_trackResources; } - - // Start/stop resource tracking. - void enableTrackResources(bool trackResources); - - bool m_trackResources; - -#if ENABLE(DATABASE) - JSObjectRef addDatabaseScriptResource(InspectorDatabaseResource*); - void removeDatabaseScriptResource(InspectorDatabaseResource*); -#endif - - JSValueRef callSimpleFunction(JSContextRef, JSObjectRef thisObject, const char* functionName) const; - JSValueRef callFunction(JSContextRef, JSObjectRef thisObject, const char* functionName, size_t argumentCount, const JSValueRef arguments[], JSValueRef& exception) const; - - bool handleException(JSContextRef, JSValueRef exception, unsigned lineNumber) const; - - void showWindow(); - void closeWindow(); - - virtual void didParseSource(KJS::ExecState*, const KJS::SourceProvider& source, int startingLineNumber, const KJS::UString& sourceURL, int sourceID); - virtual void failedToParseSource(KJS::ExecState*, const KJS::SourceProvider& source, int startingLineNumber, const KJS::UString& sourceURL, int errorLine, const KJS::UString& errorMessage); - virtual void didPause(); - - Page* m_inspectedPage; - InspectorClient* m_client; - Page* m_page; - RefPtr m_nodeToFocus; - RefPtr m_mainResource; - ResourcesMap m_resources; - HashSet m_knownResources; - FrameResourcesMap m_frameResources; - Vector m_consoleMessages; - Vector > m_profiles; - HashMap m_times; + HashMap m_times; + HashMap m_counts; #if ENABLE(DATABASE) DatabaseResourcesSet m_databaseResources; #endif @@ -574,7 +339,6 @@ private: bool m_attachDebuggerWhenShown; bool m_recordingUserInitiatedProfile; SpecialPanels m_showAfterVisible; - // TODO(ojan): Come up with a solution for this that avoids collisions. unsigned long m_nextIdentifier; RefPtr m_highlightedNode; unsigned m_groupLevel; @@ -582,6 +346,4 @@ private: } // namespace WebCore -#endif - #endif // !defined(InspectorController_h) diff --git a/webkit/port/page/inspector/InspectorController.cpp b/webkit/port/page/inspector/InspectorController.cpp index 0feb7d5..52dfab9 100644 --- a/webkit/port/page/inspector/InspectorController.cpp +++ b/webkit/port/page/inspector/InspectorController.cpp @@ -56,16 +56,8 @@ #include "GraphicsContext.h" #include "HTMLFrameOwnerElement.h" #include "InspectorClient.h" -#if USE(JSC) -#include "JSDOMWindow.h" -#include "JSInspectedObjectWrapper.h" -#include "JSInspectorCallbackWrapper.h" -#include "JSNode.h" -#include "JSRange.h" -#elif USE(V8) #include "v8_proxy.h" #include "v8_binding.h" -#endif // TODO(ojan): Import this and enable the JavaScriptDebugServer in the code below. // We need to do this once we start adding debugger hooks or when we do the next // full webkit merge, whichever comes first. @@ -74,19 +66,12 @@ #include "Range.h" #include "ResourceRequest.h" #include "ResourceResponse.h" +#include "ScriptController.h" #include "Settings.h" #include "SharedBuffer.h" #include "SystemTime.h" #include "TextEncoding.h" #include "TextIterator.h" -#if USE(JSC) -#include "kjs_proxy.h" -#include -#include -#include -#include -#include -#endif #include #if ENABLE(DATABASE) @@ -94,11 +79,6 @@ #include "JSDatabase.h" #endif -#if USE(JSC) -using namespace KJS; -using namespace std; -#endif - namespace WebCore { // Maximum size of the console message cache. @@ -139,104 +119,24 @@ namespace bug1228513 { } } // namespace bug1228513 -#if USE(JSC) -// TODO(ojan): We probably need to implement these functions to get the wrapped JS calls -// to the DOM working. -static JSRetainPtr jsStringRef(const char* str) -{ - return JSRetainPtr(Adopt, JSStringCreateWithUTF8CString(str)); -} - -static JSRetainPtr jsStringRef(const String& str) -{ - return JSRetainPtr(Adopt, JSStringCreateWithCharacters(str.characters(), str.length())); -} - -#define HANDLE_EXCEPTION(exception) handleException((exception), __LINE__) - -JSValueRef InspectorController::callSimpleFunction(JSContextRef context, JSObjectRef thisObject, const char* functionName) const -{ - ASSERT_ARG(context, context); - ASSERT_ARG(thisObject, thisObject); - - JSValueRef exception = 0; - - JSValueRef functionProperty = JSObjectGetProperty(context, thisObject, jsStringRef(functionName).get(), &exception); - if (HANDLE_EXCEPTION(exception)) - return JSValueMakeUndefined(context); - - JSObjectRef function = JSValueToObject(context, functionProperty, &exception); - if (HANDLE_EXCEPTION(exception)) - return JSValueMakeUndefined(context); - - JSValueRef result = JSObjectCallAsFunction(context, function, thisObject, 0, 0, &exception); - if (HANDLE_EXCEPTION(exception)) - return JSValueMakeUndefined(context); - - return result; -} - -#endif - -#pragma mark - -#pragma mark ConsoleMessage Struct - - -struct ConsoleMessage { - ConsoleMessage(MessageSource s, MessageLevel l, const String& m, unsigned li, const String& u) - : source(s) - , level(l) - , message(m) - , line(li) - , url(u) - { - } - -#if USE(JSC) - // TODO(ojan): I think we'll need something like this when we wrap JS calls to the DOM - ConsoleMessage(MessageSource s, MessageLevel l, ExecState* exec, const List& args, unsigned li, const String& u) - : source(s) - , level(l) - , wrappedArguments(args.size()) - , line(li) - , url(u) - { - JSLock lock; - for (unsigned i = 0; i < args.size(); ++i) - wrappedArguments[i] = JSInspectedObjectWrapper::wrap(exec, args[i]); +struct ConsoleMessage { + ConsoleMessage(MessageSource s, MessageLevel l, const String& m, unsigned li, const String& u, unsigned g) + : source(s) + , level(l) + , message(m) + , line(li) + , url(u) + , groupLevel(g) + { } -#endif - - MessageSource source; - MessageLevel level; - String message; -#if USE(JSC) - Vector > wrappedArguments; -#endif - unsigned line; - String url; + MessageSource source; + MessageLevel level; + String message; + unsigned line; + String url; + unsigned groupLevel; }; -#pragma mark - -#pragma mark XMLHttpRequestResource Class - -#if USE(JSC) -struct XMLHttpRequestResource { - XMLHttpRequestResource(KJS::UString& sourceString) - { - KJS::JSLock lock; - this->sourceString = sourceString.rep(); - } - - ~XMLHttpRequestResource() - { - KJS::JSLock lock; - sourceString.clear(); - } - - RefPtr sourceString; -}; -#elif USE(V8) struct XMLHttpRequestResource { XMLHttpRequestResource(const String& str) { @@ -247,10 +147,8 @@ struct XMLHttpRequestResource { String sourceString; }; -#endif -#pragma mark - -#pragma mark InspectorResource Struct +// InspectorResource Struct struct InspectorResource : public RefCounted { // Keep these in sync with WebInspector.Resource.Type @@ -261,6 +159,7 @@ struct InspectorResource : public RefCounted { Font, Script, XHR, + Media, Other }; @@ -274,11 +173,7 @@ struct InspectorResource : public RefCounted { ~InspectorResource() { -#if USE(JSC) - setScriptObject(0, 0); -#elif USE(V8) setScriptObject(v8::Handle()); -#endif } Type type() const @@ -313,20 +208,6 @@ struct InspectorResource : public RefCounted { } } -#if USE(JSC) - void setScriptObject(JSContextRef context, JSObjectRef newScriptObject) - { - if (scriptContext && scriptObject) - JSValueUnprotect(scriptContext, scriptObject); - - scriptObject = newScriptObject; - scriptContext = context; - - ASSERT((context && newScriptObject) || (!context && !newScriptObject)); - if (context && newScriptObject) - JSValueProtect(context, newScriptObject); - } -#elif USE(V8) void setScriptObject(v8::Handle newScriptObject) { //XXXMB - the InspectorController and InspectorResource both maintain persistent handles @@ -338,31 +219,19 @@ struct InspectorResource : public RefCounted { if (!newScriptObject.IsEmpty()) scriptObject = v8::Persistent::New(newScriptObject); } -#endif -// TODO(ojan): XHR requests show up in the inspector, but not their contents. -// Something is wrong obviously, but not sure what. Not the highest priority -// thing the inspector needs fixed right now though. -#if USE(JSC) - void setXMLHttpRequestProperties(KJS::UString& data) - { - xmlHttpRequestResource.set(new XMLHttpRequestResource(data)); - } -#elif USE(V8) + // TODO(ojan): XHR requests show up in the inspector, but not their contents. + // Something is wrong obviously, but not sure what. Not the highest priority + // thing the inspector needs fixed right now though. void setXMLHttpRequestProperties(String& data) { xmlHttpRequestResource.set(new XMLHttpRequestResource(data)); } -#endif String sourceString() const { if (xmlHttpRequestResource) { -#if USE(JSC) - return KJS::UString(xmlHttpRequestResource->sourceString); -#elif USE(V8) return xmlHttpRequestResource->sourceString; -#endif } String sourceString; @@ -423,12 +292,7 @@ struct InspectorResource : public RefCounted { HTTPHeaderMap responseHeaderFields; String mimeType; String suggestedFilename; -#if USE(JSC) - JSContextRef scriptContext; - JSObjectRef scriptObject; -#elif USE(V8) v8::Persistent scriptObject; -#endif long long expectedContentLength; bool cached; bool finished; @@ -440,25 +304,14 @@ struct InspectorResource : public RefCounted { double endTime; // Helper function to determine when the script object is initialized -#if USE(JSC) - inline bool hasScriptObject() const { return scriptObject; } -#elif USE(V8) inline bool hasScriptObject() { return !scriptObject.IsEmpty(); } -#endif protected: - // TODO(ojan): Get rid of the need to set the initialRefCount the next time we do a - // full webkit merge. Apple changed the default refcount to 1: http://trac.webkit.org/changeset/30406 InspectorResource(unsigned long identifier, DocumentLoader* documentLoader, Frame* frame) - : RefCounted(1) - , identifier(identifier) + : identifier(identifier) , loader(documentLoader) , frame(frame) , xmlHttpRequestResource(0) -#if USE(JSC) - , scriptContext(0) - , scriptObject(0) -#endif , expectedContentLength(0) , cached(false) , finished(false) @@ -472,8 +325,7 @@ protected: } }; -#pragma mark - -#pragma mark InspectorDatabaseResource Struct +// InspectorDatabaseResource Struct #if ENABLE(DATABASE) struct InspectorDatabaseResource : public RefCounted { @@ -506,11 +358,8 @@ struct InspectorDatabaseResource : public RefCounted JSObjectRef scriptObject; private: - // TODO(ojan): Get rid of the need to set the initialRefCount the next time we do a - // full webkit merge. Apple changed the default refcount to 1: http://trac.webkit.org/changeset/30406 InspectorDatabaseResource(Database* database, const String& domain, const String& name, const String& version) - : RefCounted(1) - , database(database) + : database(database) , domain(domain) , name(name) , version(version) @@ -521,69 +370,8 @@ private: }; #endif -#pragma mark - -#pragma mark JavaScript Callbacks - -#if USE(JSC) -static JSValueRef addSourceToFrame(JSContextRef ctx, JSObjectRef /*function*/, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) -{ - JSValueRef undefined = JSValueMakeUndefined(ctx); - - InspectorController* controller = reinterpret_cast(JSObjectGetPrivate(thisObject)); - if (argumentCount < 2 || !controller) - return undefined; - - JSValueRef identifierValue = arguments[0]; - if (!JSValueIsNumber(ctx, identifierValue)) - return undefined; - - unsigned long identifier = static_cast(JSValueToNumber(ctx, identifierValue, exception)); - if (exception && *exception) - return undefined; - - RefPtr resource = controller->resources().get(identifier); - ASSERT(resource); - if (!resource) - return undefined; - - String sourceString = resource->sourceString(); - if (sourceString.isEmpty()) - return undefined; - - Node* node = toNode(toJS(arguments[1])); - ASSERT(node); - if (!node) - return undefined; - - if (!node->attached()) { - ASSERT_NOT_REACHED(); - return undefined; - } - - ASSERT(node->isElementNode()); - if (!node->isElementNode()) - return undefined; - - Element* element = static_cast(node); - ASSERT(element->isFrameOwnerElement()); - if (!element->isFrameOwnerElement()) - return undefined; - - HTMLFrameOwnerElement* frameOwner = static_cast(element); - ASSERT(frameOwner->contentFrame()); - if (!frameOwner->contentFrame()) - return undefined; - - FrameLoader* loader = frameOwner->contentFrame()->loader(); - - loader->setResponseMIMEType(resource->mimeType); - loader->begin(); - loader->write(sourceString); - loader->end(); +// JavaScript Callbacks - return undefined; -} -#elif USE(V8) void InspectorController::addSourceToFrame(unsigned long identifier, Node* node) { RefPtr resource = this->resources().get(identifier); @@ -625,46 +413,7 @@ void InspectorController::addSourceToFrame(unsigned long identifier, Node* node) loader->write(sourceString); loader->end(); } -#endif - -#if USE(JSC) -static JSValueRef getResourceDocumentNode(JSContextRef ctx, JSObjectRef /*function*/, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) -{ - JSValueRef undefined = JSValueMakeUndefined(ctx); - - InspectorController* controller = reinterpret_cast(JSObjectGetPrivate(thisObject)); - if (!argumentCount || argumentCount > 1 || !controller) - return undefined; - - JSValueRef identifierValue = arguments[0]; - if (!JSValueIsNumber(ctx, identifierValue)) - return undefined; - - unsigned long identifier = static_cast(JSValueToNumber(ctx, identifierValue, exception)); - if (exception && *exception) - return undefined; - - RefPtr resource = controller->resources().get(identifier); - ASSERT(resource); - if (!resource) - return undefined; - - Frame* frame = resource->frame.get(); - - Document* document = frame->document(); - if (!document) - return undefined; - - if (document->isPluginDocument() || document->isImageDocument()) - return undefined; - ExecState* exec = toJSDOMWindowWrapper(resource->frame.get())->window()->globalExec(); - - KJS::JSLock lock; - JSValueRef documentValue = toRef(JSInspectedObjectWrapper::wrap(exec, toJS(exec, document))); - return documentValue; -} -#elif USE(V8) Node* InspectorController::getResourceDocumentNode(unsigned long identifier) { RefPtr resource = this->resources().get(identifier); ASSERT(resource); @@ -682,29 +431,6 @@ Node* InspectorController::getResourceDocumentNode(unsigned long identifier) { return document; } -#endif - -#if USE(JSC) -static JSValueRef highlightDOMNode(JSContextRef context, JSObjectRef /*function*/, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* /*exception*/) -{ - JSValueRef undefined = JSValueMakeUndefined(context); - - InspectorController* controller = reinterpret_cast(JSObjectGetPrivate(thisObject)); - if (argumentCount < 1 || !controller) - return undefined; - - JSQuarantinedObjectWrapper* wrapper = JSQuarantinedObjectWrapper::asWrapper(toJS(arguments[0])); - if (!wrapper) - return undefined; - Node* node = toNode(wrapper->unwrappedObject()); - if (!node) - return undefined; - - controller->highlight(node); - - return undefined; -} -#elif USE(V8) void InspectorController::highlightDOMNode(Node* node) { if (!enabled()) @@ -713,22 +439,6 @@ void InspectorController::highlightDOMNode(Node* node) ASSERT_ARG(node, node); m_client->highlight(node); } -#endif - -#if USE(JSC) -static JSValueRef hideDOMNodeHighlight(JSContextRef context, JSObjectRef /*function*/, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* /*exception*/) -{ - JSValueRef undefined = JSValueMakeUndefined(context); - - InspectorController* controller = reinterpret_cast(JSObjectGetPrivate(thisObject)); - if (argumentCount || !controller) - return undefined; - - controller->hideHighlight(); - - return undefined; -} -#elif USE(V8) void InspectorController::hideDOMNodeHighlight() { if (!enabled()) @@ -736,139 +446,22 @@ void InspectorController::hideDOMNodeHighlight() m_client->hideHighlight(); } -#endif -#if USE(JSC) -static JSValueRef loaded(JSContextRef ctx, JSObjectRef /*function*/, JSObjectRef thisObject, size_t /*argumentCount*/, const JSValueRef[] /*arguments[]*/, JSValueRef* /*exception*/) -{ - InspectorController* controller = reinterpret_cast(JSObjectGetPrivate(thisObject)); - if (!controller) - return JSValueMakeUndefined(ctx); - - controller->scriptObjectReady(); - return JSValueMakeUndefined(ctx); -} -#elif USE(V8) void InspectorController::loaded() { scriptObjectReady(); } -#endif - -#if USE(JSC) -static JSValueRef unloading(JSContextRef ctx, JSObjectRef /*function*/, JSObjectRef thisObject, size_t /*argumentCount*/, const JSValueRef[] /*arguments[]*/, JSValueRef* /*exception*/) -{ - InspectorController* controller = reinterpret_cast(JSObjectGetPrivate(thisObject)); - if (!controller) - return JSValueMakeUndefined(ctx); - controller->close(); - return JSValueMakeUndefined(ctx); -} -#elif USE(V8) // We don't need to implement this because we just map windowUnloading to // InspectorController::close in the IDL file. -#endif - -#if USE(JSC) -static JSValueRef attach(JSContextRef ctx, JSObjectRef /*function*/, JSObjectRef thisObject, size_t /*argumentCount*/, const JSValueRef[] /*arguments[]*/, JSValueRef* /*exception*/) -{ - InspectorController* controller = reinterpret_cast(JSObjectGetPrivate(thisObject)); - if (!controller) - return JSValueMakeUndefined(ctx); - controller->attachWindow(); - return JSValueMakeUndefined(ctx); -} -#elif USE(V8) void InspectorController::attach() { attachWindow(); } -#endif -#if USE(JSC) -static JSValueRef detach(JSContextRef ctx, JSObjectRef /*function*/, JSObjectRef thisObject, size_t /*argumentCount*/, const JSValueRef[] /*arguments[]*/, JSValueRef* /*exception*/) -{ - InspectorController* controller = reinterpret_cast(JSObjectGetPrivate(thisObject)); - if (!controller) - return JSValueMakeUndefined(ctx); - - controller->detachWindow(); - return JSValueMakeUndefined(ctx); -} -#elif USE(V8) void InspectorController::detach() { detachWindow(); } -#endif -#if USE(JSC) -static JSValueRef search(JSContextRef ctx, JSObjectRef /*function*/, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) -{ - InspectorController* controller = reinterpret_cast(JSObjectGetPrivate(thisObject)); - if (!controller) - return JSValueMakeUndefined(ctx); - - if (argumentCount < 2 || !JSValueIsString(ctx, arguments[1])) - return JSValueMakeUndefined(ctx); - - Node* node = toNode(toJS(arguments[0])); - if (!node) - return JSValueMakeUndefined(ctx); - - JSRetainPtr searchString(Adopt, JSValueToStringCopy(ctx, arguments[1], exception)); - if (exception && *exception) - return JSValueMakeUndefined(ctx); - - String target(JSStringGetCharactersPtr(searchString.get()), JSStringGetLength(searchString.get())); - - JSObjectRef global = JSContextGetGlobalObject(ctx); - - JSValueRef arrayProperty = JSObjectGetProperty(ctx, global, jsStringRef("Array").get(), exception); - if (exception && *exception) - return JSValueMakeUndefined(ctx); - - JSObjectRef arrayConstructor = JSValueToObject(ctx, arrayProperty, exception); - if (exception && *exception) - return JSValueMakeUndefined(ctx); - - JSObjectRef result = JSObjectCallAsConstructor(ctx, arrayConstructor, 0, 0, exception); - if (exception && *exception) - return JSValueMakeUndefined(ctx); - - JSValueRef pushProperty = JSObjectGetProperty(ctx, result, jsStringRef("push").get(), exception); - if (exception && *exception) - return JSValueMakeUndefined(ctx); - - JSObjectRef pushFunction = JSValueToObject(ctx, pushProperty, exception); - if (exception && *exception) - return JSValueMakeUndefined(ctx); - - RefPtr searchRange(rangeOfContents(node)); - - ExceptionCode ec = 0; - do { - RefPtr resultRange(findPlainText(searchRange.get(), target, true, false)); - if (resultRange->collapsed(ec)) - break; - - // A non-collapsed result range can in some funky whitespace cases still not - // advance the range's start position (4509328). Break to avoid infinite loop. - VisiblePosition newStart = endVisiblePosition(resultRange.get(), DOWNSTREAM); - if (newStart == startVisiblePosition(searchRange.get(), DOWNSTREAM)) - break; - - KJS::JSLock lock; - JSValueRef arg0 = toRef(toJS(toJS(ctx), resultRange.get())); - JSObjectCallAsFunction(ctx, pushFunction, result, 1, &arg0, exception); - if (exception && *exception) - return JSValueMakeUndefined(ctx); - - setStart(searchRange.get(), newStart); - } while (true); - - return result; -} -#elif USE(V8) // TODO(ojan): See when/if this works. We should either make it work or remove it. void InspectorController::search(Node* node, const String& target) { v8::HandleScope handle_scope; @@ -905,7 +498,6 @@ void InspectorController::search(Node* node, const String& target) { // TODO(jackson): Figure out how to return array } -#endif #if ENABLE(DATABASE) static JSValueRef databaseTableNames(JSContextRef ctx, JSObjectRef /*function*/, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) @@ -963,186 +555,38 @@ static JSValueRef databaseTableNames(JSContextRef ctx, JSObjectRef /*function*/, } #endif -#if USE(JSC) -static JSValueRef inspectedWindow(JSContextRef ctx, JSObjectRef /*function*/, JSObjectRef thisObject, size_t /*argumentCount*/, const JSValueRef[] /*arguments[]*/, JSValueRef* /*exception*/) -{ - InspectorController* controller = reinterpret_cast(JSObjectGetPrivate(thisObject)); - if (!controller) - return JSValueMakeUndefined(ctx); - - JSDOMWindow* inspectedWindow = toJSDOMWindow(controller->inspectedPage()->mainFrame()); - JSLock lock; - return toRef(JSInspectedObjectWrapper::wrap(inspectedWindow->globalExec(), inspectedWindow)); -} -#elif USE(V8) DOMWindow* InspectorController::inspectedWindow() { // Can be null if page was already destroyed. if (!m_inspectedPage) return NULL; return m_inspectedPage->mainFrame()->domWindow(); } -#endif - -#if USE(JSC) -static JSValueRef localizedStrings(JSContextRef ctx, JSObjectRef /*function*/, JSObjectRef thisObject, size_t /*argumentCount*/, const JSValueRef[] /*arguments[]*/, JSValueRef* /*exception*/) -{ - InspectorController* controller = reinterpret_cast(JSObjectGetPrivate(thisObject)); - if (!controller) - return JSValueMakeUndefined(ctx); - - String url = controller->localizedStringsURL(); - if (url.isNull()) - return JSValueMakeNull(ctx); - - return JSValueMakeString(ctx, jsStringRef(url).get()); -} -#elif USE(V8) -// TODO(ojan): Figure out how/if to implement this function. -#endif - -#if USE(JSC) -static JSValueRef platform(JSContextRef ctx, JSObjectRef /*function*/, JSObjectRef thisObject, size_t /*argumentCount*/, const JSValueRef[] /*arguments[]*/, JSValueRef* /*exception*/) -{ -#if PLATFORM(MAC) -#ifdef BUILDING_ON_TIGER - static const String platform = "mac-tiger"; -#else - static const String platform = "mac-leopard"; -#endif -#elif PLATFORM(WIN_OS) - static const String platform = "windows"; -#elif PLATFORM(QT) - static const String platform = "qt"; -#elif PLATFORM(GTK) - static const String platform = "gtk"; -#elif PLATFORM(WX) - static const String platform = "wx"; -#else - static const String platform = "unknown"; -#endif - - JSValueRef platformValue = JSValueMakeString(ctx, jsStringRef(platform).get()); - return platformValue; -} -#elif USE(V8) String InspectorController::platform() const { return String("windows"); } -#endif - -#if USE(JSC) -static JSValueRef moveByUnrestricted(JSContextRef ctx, JSObjectRef /*function*/, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) -{ - InspectorController* controller = reinterpret_cast(JSObjectGetPrivate(thisObject)); - if (!controller) - return JSValueMakeUndefined(ctx); - - if (argumentCount < 2) - return JSValueMakeUndefined(ctx); - - double x = JSValueToNumber(ctx, arguments[0], exception); - if (exception && *exception) - return JSValueMakeUndefined(ctx); - - double y = JSValueToNumber(ctx, arguments[1], exception); - if (exception && *exception) - return JSValueMakeUndefined(ctx); - - controller->moveWindowBy(narrowPrecisionToFloat(x), narrowPrecisionToFloat(y)); - - return JSValueMakeUndefined(ctx); -} -#elif USE(V8) -// TODO(ojan): Figure out how/if to implement this function. -#endif - -#if USE(JSC) -static JSValueRef wrapCallback(JSContextRef ctx, JSObjectRef /*function*/, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) -{ - InspectorController* controller = reinterpret_cast(JSObjectGetPrivate(thisObject)); - if (!controller) - return JSValueMakeUndefined(ctx); - - if (argumentCount < 1) - return JSValueMakeUndefined(ctx); - - JSLock lock; - return toRef(JSInspectorCallbackWrapper::wrap(toJS(ctx), toJS(arguments[0]))); -} -#elif USE(V8) -// TODO(ojan): Figure out how to wrap JS calls to the DOM with V8. -// Eventually, get it working over IPC. -#endif - -#if USE(JSC) -static JSValueRef startDebuggingAndReloadInspectedPage(JSContextRef ctx, JSObjectRef /*function*/, JSObjectRef thisObject, size_t /*argumentCount*/, const JSValueRef[] /*arguments*/, JSValueRef* /*exception*/) -{ - InspectorController* controller = reinterpret_cast(JSObjectGetPrivate(thisObject)); - if (!controller) - return JSValueMakeUndefined(ctx); - controller->startDebuggingAndReloadInspectedPage(); - - return JSValueMakeUndefined(ctx); -} -#elif USE(V8) -// TODO(ojan): Figure out how/if to implement this function. -#endif - -#if USE(JSC) -static JSValueRef stopDebugging(JSContextRef ctx, JSObjectRef /*function*/, JSObjectRef thisObject, size_t /*argumentCount*/, const JSValueRef[] /*arguments*/, JSValueRef* /*exception*/) -{ - InspectorController* controller = reinterpret_cast(JSObjectGetPrivate(thisObject)); - if (!controller) - return JSValueMakeUndefined(ctx); - - controller->stopDebugging(); - - return JSValueMakeUndefined(ctx); -} -#elif USE(V8) -// TODO(ojan): Figure out how/if to implement this function. -#endif - -#if USE(JSC) -static JSValueRef debuggerAttached(JSContextRef ctx, JSObjectRef /*function*/, JSObjectRef thisObject, size_t /*argumentCount*/, const JSValueRef[] /*arguments*/, JSValueRef* /*exception*/) -{ - InspectorController* controller = reinterpret_cast(JSObjectGetPrivate(thisObject)); - if (!controller) - return JSValueMakeUndefined(ctx); - return JSValueMakeBoolean(ctx, controller->debuggerAttached()); -} -#elif USE(V8) -// TODO(ojan): Figure out how/if to implement this function. -#endif - -#pragma mark - -#pragma mark InspectorController Class +// InspectorController Class InspectorController::InspectorController(Page* page, InspectorClient* client) : -#if USE(V8) // The V8 version of InspectorController is RefCounted while the JSC // version uses an OwnPtr (http://b/904340). However, since we're not // using a create method to initialize the InspectorController, we need // to start the RefCount at 0. - RefCounted(0), -#endif - m_bug1228513_inspectorState(bug1228513::VALID) + RefCounted(0) + , m_bug1228513_inspectorState(bug1228513::VALID) , m_inspectedPage(page) , m_client(client) , m_page(0) -#if USE(JSC) - , m_scriptObject(0) // is an uninitialized V8 object - , m_controllerScriptObject(0) // is equivalent to |this| - , m_scriptContext(0) // isn't necessary for V8 -#endif , m_windowVisible(false) , m_debuggerAttached(false) + , m_attachDebuggerWhenShown(false) + , m_recordingUserInitiatedProfile(false) , m_showAfterVisible(ElementsPanel) , m_nextIdentifier(-2) , m_trackResources(false) + , m_groupLevel(0) { ASSERT_ARG(page, page); ASSERT_ARG(client, client); @@ -1153,21 +597,6 @@ InspectorController::~InspectorController() m_bug1228513_inspectorState = bug1228513::DELETED; m_client->inspectorDestroyed(); -#if USE(JSC) - if (m_scriptContext) { - JSValueRef exception = 0; - - JSObjectRef global = JSContextGetGlobalObject(m_scriptContext); - JSValueRef controllerProperty = JSObjectGetProperty(m_scriptContext, global, jsStringRef("InspectorController").get(), &exception); - if (!HANDLE_EXCEPTION(exception)) { - if (JSObjectRef controller = JSValueToObject(m_scriptContext, controllerProperty, &exception)) { - if (!HANDLE_EXCEPTION(exception)) - JSObjectSetPrivate(controller, 0); - } - } - } -#endif - if (m_page) m_page->setParentInspectorController(0); @@ -1180,8 +609,9 @@ InspectorController::~InspectorController() void InspectorController::inspectedPageDestroyed() { + close(); + ASSERT(m_inspectedPage); - stopDebugging(); m_inspectedPage = 0; } @@ -1211,6 +641,17 @@ String InspectorController::localizedStringsURL() return m_client->localizedStringsURL(); } +// Trying to inspect something in a frame with JavaScript disabled would later lead to +// crashes trying to create JavaScript wrappers. Some day we could fix this issue, but +// for now prevent crashes here by never targeting a node in such a frame. +static bool canPassNodeToJavaScript(Node* node) +{ + if (!node) + return false; + Frame* frame = node->document()->frame(); + return frame && frame->script()->isEnabled(); +} + void InspectorController::inspect(Node* node) { if (!node || !enabled()) @@ -1231,47 +672,6 @@ void InspectorController::inspect(Node* node) focusNode(); } -#if USE(JSC) -void InspectorController::focusNode() -{ - if (!enabled()) - return; - - ASSERT(m_scriptContext); - ASSERT(m_scriptObject); - ASSERT(m_nodeToFocus); - - Frame* frame = m_nodeToFocus->document()->frame(); - if (!frame) - return; - - ExecState* exec = toJSDOMWindow(frame)->globalExec(); - - JSValueRef arg0; - - { - KJS::JSLock lock; - arg0 = toRef(JSInspectedObjectWrapper::wrap(exec, toJS(exec, m_nodeToFocus.get()))); - } - - m_nodeToFocus = 0; - - JSValueRef exception = 0; - - JSValueRef functionProperty = JSObjectGetProperty(m_scriptContext, m_scriptObject, jsStringRef("updateFocusedNode").get(), &exception); - if (HANDLE_EXCEPTION(exception)) - return; - - JSObjectRef function = JSValueToObject(m_scriptContext, functionProperty, &exception); - if (HANDLE_EXCEPTION(exception)) - return; - - ASSERT(function); - - JSObjectCallAsFunction(m_scriptContext, function, m_scriptObject, 1, &arg0, &exception); - HANDLE_EXCEPTION(exception); -} -#elif USE(V8) void InspectorController::focusNode() { if (!enabled() || !m_nodeToFocus) @@ -1295,7 +695,6 @@ void InspectorController::focusNode() v8::Handle args[] = { nodeToFocus }; func->Call(m_scriptObject, 1, args); } -#endif void InspectorController::highlight(Node* node) { @@ -1318,7 +717,7 @@ bool InspectorController::windowVisible() return m_windowVisible; } -void InspectorController::setWindowVisible(bool visible) +void InspectorController::setWindowVisible(bool visible, bool attached) { // Policy: only log resources while the inspector window is visible. enableTrackResources(visible); @@ -1328,26 +727,24 @@ void InspectorController::setWindowVisible(bool visible) m_windowVisible = visible; -#if USE(JSC) - if (!m_scriptContext || !m_scriptObject) - return; -#elif USE(V8) if (!hasScriptObject()) return; -#endif if (m_windowVisible) { + setAttachedWindow(attached); populateScriptObjects(); if (m_nodeToFocus) focusNode(); - if (m_showAfterVisible == ConsolePanel) - showConsole(); - else if (m_showAfterVisible == ResourcesPanel) - showTimeline(); - } else + if (m_attachDebuggerWhenShown) + startDebuggingAndReloadInspectedPage(); + if (m_showAfterVisible != CurrentPanel) + showPanel(m_showAfterVisible); + } else { + stopDebugging(); resetScriptObjects(); + } - m_showAfterVisible = ElementsPanel; + m_showAfterVisible = CurrentPanel; } void InspectorController::enableTrackResources(bool trackResources) @@ -1364,23 +761,12 @@ void InspectorController::enableTrackResources(bool trackResources) m_resources.clear(); } - -#if USE(JSC) -void InspectorController::addMessageToConsole(MessageSource source, MessageLevel level, ExecState* exec, const List& arguments, unsigned lineNumber, const String& sourceURL) -{ - if (!enabled()) - return; - - addConsoleMessage(new ConsoleMessage(source, level, exec, arguments, lineNumber, sourceURL)); -} -#endif - void InspectorController::addMessageToConsole(MessageSource source, MessageLevel level, const String& message, unsigned lineNumber, const String& sourceID) { if (!enabled()) return; - addConsoleMessage(new ConsoleMessage(source, level, message, lineNumber, sourceID)); + addConsoleMessage(new ConsoleMessage(source, level, message, lineNumber, sourceID, m_groupLevel)); } void InspectorController::addConsoleMessage(ConsoleMessage* consoleMessage) @@ -1406,6 +792,12 @@ void InspectorController::addConsoleMessage(ConsoleMessage* consoleMessage) addScriptConsoleMessage(consoleMessage); } +void InspectorController::clearConsoleMessages() +{ + deleteAllValues(m_consoleMessages); + m_consoleMessages.clear(); +} + void InspectorController::attachWindow() { if (!enabled()) @@ -1420,7 +812,6 @@ void InspectorController::detachWindow() m_client->detachWindow(); } -#if USE(V8) void InspectorController::setScriptObject(v8::Handle newScriptObject) { if (hasScriptObject()) { @@ -1431,85 +822,24 @@ void InspectorController::setScriptObject(v8::Handle newScriptObject if (!newScriptObject.IsEmpty()) m_scriptObject = v8::Persistent::New(newScriptObject); } -#endif -#if USE(JSC) -void InspectorController::inspectedWindowScriptObjectCleared(Frame* frame) -{ - if (!enabled() || !m_scriptContext || !m_scriptObject) - return; - - JSDOMWindow* win = toJSDOMWindow(frame); - ExecState* exec = win->globalExec(); - - JSValueRef arg0; - - { - KJS::JSLock lock(false); - arg0 = toRef(JSInspectedObjectWrapper::wrap(exec, win)); - } - - JSValueRef exception = 0; - callFunction(m_scriptContext, m_scriptObject, "inspectedWindowCleared", 1, &arg0, exception); -} -#elif USE(V8) void InspectorController::inspectedWindowScriptObjectCleared(Frame* frame) { // TODO(tc): We need to call inspectedWindowCleared, but that won't matter // until we merge in inspector.js as well. notImplemented(); } -#endif -#if USE(JSC) -void InspectorController::windowScriptObjectAvailable() +void InspectorController::setAttachedWindow(bool attached) { - if (!m_page || !enabled()) - return; - - m_scriptContext = toRef(m_page->mainFrame()->scriptProxy()->globalObject()->globalExec()); - - JSObjectRef global = JSContextGetGlobalObject(m_scriptContext); - ASSERT(global); - - static JSStaticFunction staticFunctions[] = { - { "addSourceToFrame", addSourceToFrame, kJSPropertyAttributeNone }, - { "getResourceDocumentNode", getResourceDocumentNode, kJSPropertyAttributeNone }, - { "highlightDOMNode", highlightDOMNode, kJSPropertyAttributeNone }, - { "hideDOMNodeHighlight", hideDOMNodeHighlight, kJSPropertyAttributeNone }, - { "loaded", loaded, kJSPropertyAttributeNone }, - { "windowUnloading", unloading, kJSPropertyAttributeNone }, - { "attach", attach, kJSPropertyAttributeNone }, - { "detach", detach, kJSPropertyAttributeNone }, - { "search", search, kJSPropertyAttributeNone }, -#if ENABLE(DATABASE) - { "databaseTableNames", databaseTableNames, kJSPropertyAttributeNone }, -#endif - { "inspectedWindow", inspectedWindow, kJSPropertyAttributeNone }, - { "localizedStringsURL", localizedStrings, kJSPropertyAttributeNone }, - { "platform", platform, kJSPropertyAttributeNone }, - { "moveByUnrestricted", moveByUnrestricted, kJSPropertyAttributeNone }, - { "wrapCallback", wrapCallback, kJSPropertyAttributeNone }, - { "startDebuggingAndReloadInspectedPage", WebCore::startDebuggingAndReloadInspectedPage, kJSPropertyAttributeNone }, - { "stopDebugging", WebCore::stopDebugging, kJSPropertyAttributeNone }, - { "debuggerAttached", WebCore::debuggerAttached, kJSPropertyAttributeNone }, - { 0, 0, 0 } - }; - - JSClassDefinition inspectorControllerDefinition = { - 0, kJSClassAttributeNone, "InspectorController", 0, 0, staticFunctions, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 - }; - - JSClassRef controllerClass = JSClassCreate(&inspectorControllerDefinition); - ASSERT(controllerClass); - - m_controllerScriptObject = JSObjectMake(m_scriptContext, controllerClass, reinterpret_cast(this)); - ASSERT(m_controllerScriptObject); + notImplemented(); +} - JSObjectSetProperty(m_scriptContext, global, jsStringRef("InspectorController").get(), m_controllerScriptObject, kJSPropertyAttributeNone, 0); +void InspectorController::setAttachedWindowHeight(unsigned height) +{ + notImplemented(); } -#elif USE(V8) + void InspectorController::windowScriptObjectAvailable() { if (!m_page || !enabled()) @@ -1524,40 +854,7 @@ void InspectorController::windowScriptObjectAvailable() v8::Handle inspectorController = V8Proxy::ToV8Object(V8ClassIndex::INSPECTORCONTROLLER, this); global->Set(v8::String::New("InspectorController"), inspectorController); } -#endif - -#if USE(JSC) -void InspectorController::scriptObjectReady() -{ - ASSERT(m_scriptContext); - if (!m_scriptContext) - return; - - JSObjectRef global = JSContextGetGlobalObject(m_scriptContext); - ASSERT(global); - - JSValueRef exception = 0; - - JSValueRef inspectorValue = JSObjectGetProperty(m_scriptContext, global, jsStringRef("WebInspector").get(), &exception); - if (HANDLE_EXCEPTION(exception)) - return; - - ASSERT(inspectorValue); - if (!inspectorValue) - return; - m_scriptObject = JSValueToObject(m_scriptContext, inspectorValue, &exception); - if (HANDLE_EXCEPTION(exception)) - return; - - ASSERT(m_scriptObject); - - JSValueProtect(m_scriptContext, m_scriptObject); - - // Make sure our window is visible now that the page loaded - showWindow(); -} -#elif USE(V8) void InspectorController::scriptObjectReady() { if (!m_page || !enabled()) @@ -1574,7 +871,6 @@ void InspectorController::scriptObjectReady() // Make sure our window is visible now that the page loaded m_client->showWindow(); } -#endif void InspectorController::show() { @@ -1596,7 +892,7 @@ void InspectorController::show() showWindow(); } -void InspectorController::showConsole() +void InspectorController::showPanel(SpecialPanels panel) { if (!enabled()) return; @@ -1604,59 +900,53 @@ void InspectorController::showConsole() show(); if (!hasScriptObject()) { - m_showAfterVisible = ConsolePanel; + m_showAfterVisible = panel; return; } -#if USE(JSC) - callSimpleFunction(m_scriptContext, m_scriptObject, "showConsole"); -#elif USE(V8) - if (windowVisible()) { - v8::HandleScope handle_scope; - v8::Handle context = V8Proxy::GetContext(m_page->mainFrame()); - v8::Context::Scope scope(context); - - v8::Handle showConsole = m_scriptObject->Get(v8::String::New("showConsole")); - ASSERT(showConsole->IsFunction()); - - v8::Handle func(v8::Function::Cast(*showConsole)); - func->Call(m_scriptObject, 0, NULL); - } else { - m_client->showWindow(); - } -#endif -} - - -void InspectorController::showTimeline() -{ - if (!enabled()) + if (panel == CurrentPanel) return; - show(); - - if (!hasScriptObject()) { - m_showAfterVisible = ResourcesPanel; - return; + const char* showFunctionName; + switch (panel) { + case ConsolePanel: + showFunctionName = "showConsole"; + break; + case DatabasesPanel: + showFunctionName = "showDatabasesPanel"; + break; + case ElementsPanel: + showFunctionName = "showElementsPanel"; + break; + case ProfilesPanel: + showFunctionName = "showProfilesPanel"; + break; + case ResourcesPanel: + showFunctionName = "showResourcesPanel"; + break; + case ScriptsPanel: + showFunctionName = "showScriptsPanel"; + break; + default: + ASSERT_NOT_REACHED(); + showFunctionName = 0; } -#if USE(JSC) - callSimpleFunction(m_scriptContext, m_scriptObject, "showTimeline"); -#elif USE(V8) - if (windowVisible()) { + if (windowVisible() && showFunctionName) { v8::HandleScope handle_scope; v8::Handle context = V8Proxy::GetContext(m_page->mainFrame()); v8::Context::Scope scope(context); - v8::Handle showTimeline = m_scriptObject->Get(v8::String::New("showTimeline")); - ASSERT(showTimeline->IsFunction()); + // TODO(ojan): Use showFunctionName here. For some reason some of these + // are not functions (e.g. showElementsPanel). + v8::Handle showFunction = m_scriptObject->Get(v8::String::New("showConsole")); + ASSERT(showFunction->IsFunction()); - v8::Handle func(v8::Function::Cast(*showTimeline)); + v8::Handle func(v8::Function::Cast(*showFunction)); func->Call(m_scriptObject, 0, NULL); } else { m_client->showWindow(); } -#endif } void InspectorController::close() @@ -1666,57 +956,29 @@ void InspectorController::close() ++bug1228513::g_totalNumClose; + stopDebugging(); closeWindow(); if (m_page) { - m_page->setParentInspectorController(0); -#if USE(V8) v8::HandleScope handle_scope; v8::Handle context = V8Proxy::GetContext(m_page->mainFrame()); v8::Context::Scope scope(context); setScriptObject(v8::Handle()); -#endif } -#if USE(JSC) - ASSERT(m_scriptContext && m_scriptObject); - JSValueUnprotect(m_scriptContext, m_scriptObject); -#endif - m_page = 0; -#if USE(JSC) - m_scriptObject = 0; - m_scriptContext = 0; -#endif } void InspectorController::showWindow() { ASSERT(enabled()); - m_client->showWindow(); } void InspectorController::closeWindow() { - stopDebugging(); m_client->closeWindow(); } -#if USE(JSC) -static void addHeaders(JSContextRef context, JSObjectRef object, const HTTPHeaderMap& headers, JSValueRef* exception) -{ - ASSERT_ARG(context, context); - ASSERT_ARG(object, object); - - HTTPHeaderMap::const_iterator end = headers.end(); - for (HTTPHeaderMap::const_iterator it = headers.begin(); it != end; ++it) { - JSValueRef value = JSValueMakeString(context, jsStringRef(it->second).get()); - JSObjectSetProperty(context, object, jsStringRef(it->first).get(), value, kJSPropertyAttributeNone, exception); - if (exception && *exception) - return; - } -} -#elif USE(V8) static void addHeaders(v8::Handle object, const HTTPHeaderMap& headers) { ASSERT_ARG(object, !object.IsEmpty()); @@ -1726,108 +988,21 @@ static void addHeaders(v8::Handle object, const HTTPHeaderMap& heade object->Set(field, v8StringOrNull(it->second)); } } -#endif - -#if USE(JSC) -static JSObjectRef scriptObjectForRequest(JSContextRef context, const InspectorResource* resource, JSValueRef* exception) -{ - ASSERT_ARG(context, context); - JSObjectRef object = JSObjectMake(context, 0, 0); - addHeaders(context, object, resource->requestHeaderFields, exception); - - return object; -} -#elif USE(V8) static v8::Handle scriptObjectForRequest(const InspectorResource* resource) { v8::Handle object = v8::Object::New(); addHeaders(object, resource->requestHeaderFields); - return object; -} -#endif - -#if USE(JSC) -static JSObjectRef scriptObjectForResponse(JSContextRef context, const InspectorResource* resource, JSValueRef* exception) -{ - ASSERT_ARG(context, context); - - JSObjectRef object = JSObjectMake(context, 0, 0); - addHeaders(context, object, resource->responseHeaderFields, exception); - - return object; -} -#elif USE(V8) -static v8::Handle scriptObjectForResponse(const InspectorResource* resource) -{ - v8::Handle object = v8::Object::New(); - addHeaders(object, resource->responseHeaderFields); - return object; -} -#endif - -#if USE(JSC) -JSObjectRef InspectorController::addScriptResource(InspectorResource* resource) -{ - ASSERT_ARG(resource, resource); - - ASSERT(m_scriptContext); - ASSERT(m_scriptObject); - if (!m_scriptContext || !m_scriptObject) - return 0; - - if (!resource->scriptObject) { - JSValueRef exception = 0; - - JSValueRef resourceProperty = JSObjectGetProperty(m_scriptContext, m_scriptObject, jsStringRef("Resource").get(), &exception); - if (HANDLE_EXCEPTION(exception)) - return 0; - - JSObjectRef resourceConstructor = JSValueToObject(m_scriptContext, resourceProperty, &exception); - if (HANDLE_EXCEPTION(exception)) - return 0; - - JSValueRef urlValue = JSValueMakeString(m_scriptContext, jsStringRef(resource->requestURL.string()).get()); - JSValueRef domainValue = JSValueMakeString(m_scriptContext, jsStringRef(resource->requestURL.host()).get()); - JSValueRef pathValue = JSValueMakeString(m_scriptContext, jsStringRef(resource->requestURL.path()).get()); - JSValueRef lastPathComponentValue = JSValueMakeString(m_scriptContext, jsStringRef(resource->requestURL.lastPathComponent()).get()); - - JSValueRef identifier = JSValueMakeNumber(m_scriptContext, resource->identifier); - JSValueRef mainResource = JSValueMakeBoolean(m_scriptContext, m_mainResource == resource); - JSValueRef cached = JSValueMakeBoolean(m_scriptContext, resource->cached); - - JSObjectRef scriptObject = scriptObjectForRequest(m_scriptContext, resource, &exception); - if (HANDLE_EXCEPTION(exception)) - return 0; - - JSValueRef arguments[] = { scriptObject, urlValue, domainValue, pathValue, lastPathComponentValue, identifier, mainResource, cached }; - JSObjectRef result = JSObjectCallAsConstructor(m_scriptContext, resourceConstructor, 8, arguments, &exception); - if (HANDLE_EXCEPTION(exception)) - return 0; - - ASSERT(result); - - resource->setScriptObject(m_scriptContext, result); - } - - JSValueRef exception = 0; - - JSValueRef addResourceProperty = JSObjectGetProperty(m_scriptContext, m_scriptObject, jsStringRef("addResource").get(), &exception); - if (HANDLE_EXCEPTION(exception)) - return 0; - - JSObjectRef addResourceFunction = JSValueToObject(m_scriptContext, addResourceProperty, &exception); - if (HANDLE_EXCEPTION(exception)) - return 0; - - JSValueRef addArguments[] = { resource->scriptObject }; - JSObjectCallAsFunction(m_scriptContext, addResourceFunction, m_scriptObject, 1, addArguments, &exception); - if (HANDLE_EXCEPTION(exception)) - return 0; + return object; +} - return resource->scriptObject; +static v8::Handle scriptObjectForResponse(const InspectorResource* resource) +{ + v8::Handle object = v8::Object::New(); + addHeaders(object, resource->responseHeaderFields); + return object; } -#elif USE(V8) + void InspectorController::addScriptResource(InspectorResource* resource) { ASSERT_ARG(resource, resource); @@ -1867,24 +1042,7 @@ void InspectorController::addScriptResource(InspectorResource* resource) v8::Handle addArguments[] = { object }; (v8::Function::Cast(*addResourceFunction))->Call(m_scriptObject, 1, addArguments); } -#endif - -#if USE(JSC) -JSObjectRef InspectorController::addAndUpdateScriptResource(InspectorResource* resource) -{ - ASSERT_ARG(resource, resource); - JSObjectRef scriptResource = addScriptResource(resource); - if (!scriptResource) - return 0; - - updateScriptResourceResponse(resource); - updateScriptResource(resource, resource->length); - updateScriptResource(resource, resource->startTime, resource->responseReceivedTime, resource->endTime); - updateScriptResource(resource, resource->finished, resource->failed); - return scriptResource; -} -#elif USE(V8) void InspectorController::addAndUpdateScriptResource(InspectorResource* resource) { ASSERT_ARG(resource, resource); @@ -1896,39 +1054,7 @@ void InspectorController::addAndUpdateScriptResource(InspectorResource* resource updateScriptResource(resource, resource->startTime, resource->responseReceivedTime, resource->endTime); updateScriptResource(resource, resource->finished, resource->failed); } -#endif - -#if USE(JSC) -void InspectorController::removeScriptResource(InspectorResource* resource) -{ - ASSERT(m_scriptContext); - ASSERT(m_scriptObject); - if (!m_scriptContext || !m_scriptObject) - return; - - ASSERT(resource); - ASSERT(resource->scriptObject); - if (!resource || !resource->scriptObject) - return; - - JSObjectRef scriptObject = resource->scriptObject; - resource->setScriptObject(0, 0); - - JSValueRef exception = 0; - - JSValueRef removeResourceProperty = JSObjectGetProperty(m_scriptContext, m_scriptObject, jsStringRef("removeResource").get(), &exception); - if (HANDLE_EXCEPTION(exception)) - return; - - JSObjectRef removeResourceFunction = JSValueToObject(m_scriptContext, removeResourceProperty, &exception); - if (HANDLE_EXCEPTION(exception)) - return; - JSValueRef arguments[] = { scriptObject }; - JSObjectCallAsFunction(m_scriptContext, removeResourceFunction, m_scriptObject, 1, arguments, &exception); - HANDLE_EXCEPTION(exception); -} -#elif USE(V8) void InspectorController::removeScriptResource(InspectorResource* resource) { ASSERT(hasScriptObject()); @@ -1951,7 +1077,6 @@ void InspectorController::removeScriptResource(InspectorResource* resource) resource->setScriptObject(v8::Handle()); } -#endif static void updateResourceRequest(InspectorResource* resource, const ResourceRequest& request) { @@ -1968,51 +1093,6 @@ static void updateResourceResponse(InspectorResource* resource, const ResourceRe resource->suggestedFilename = response.suggestedFilename(); } -#if USE(JSC) -void InspectorController::updateScriptResourceRequest(InspectorResource* resource) -{ - ASSERT(resource->scriptObject); - ASSERT(m_scriptContext); - if (!resource->scriptObject || !m_scriptContext) - return; - - JSValueRef urlValue = JSValueMakeString(m_scriptContext, jsStringRef(resource->requestURL.string()).get()); - JSValueRef domainValue = JSValueMakeString(m_scriptContext, jsStringRef(resource->requestURL.host()).get()); - JSValueRef pathValue = JSValueMakeString(m_scriptContext, jsStringRef(resource->requestURL.path()).get()); - JSValueRef lastPathComponentValue = JSValueMakeString(m_scriptContext, jsStringRef(resource->requestURL.lastPathComponent()).get()); - - JSValueRef mainResourceValue = JSValueMakeBoolean(m_scriptContext, m_mainResource == resource); - - JSValueRef exception = 0; - - JSObjectSetProperty(m_scriptContext, resource->scriptObject, jsStringRef("url").get(), urlValue, kJSPropertyAttributeNone, &exception); - if (HANDLE_EXCEPTION(exception)) - return; - - JSObjectSetProperty(m_scriptContext, resource->scriptObject, jsStringRef("domain").get(), domainValue, kJSPropertyAttributeNone, &exception); - if (HANDLE_EXCEPTION(exception)) - return; - - JSObjectSetProperty(m_scriptContext, resource->scriptObject, jsStringRef("path").get(), pathValue, kJSPropertyAttributeNone, &exception); - if (HANDLE_EXCEPTION(exception)) - return; - - JSObjectSetProperty(m_scriptContext, resource->scriptObject, jsStringRef("lastPathComponent").get(), lastPathComponentValue, kJSPropertyAttributeNone, &exception); - if (HANDLE_EXCEPTION(exception)) - return; - - JSObjectRef scriptObject = scriptObjectForRequest(m_scriptContext, resource, &exception); - if (HANDLE_EXCEPTION(exception)) - return; - - JSObjectSetProperty(m_scriptContext, resource->scriptObject, jsStringRef("requestHeaders").get(), scriptObject, kJSPropertyAttributeNone, &exception); - if (HANDLE_EXCEPTION(exception)) - return; - - JSObjectSetProperty(m_scriptContext, resource->scriptObject, jsStringRef("mainResource").get(), mainResourceValue, kJSPropertyAttributeNone, &exception); - HANDLE_EXCEPTION(exception); -} -#elif USE(V8) void InspectorController::updateScriptResourceRequest(InspectorResource* resource) { ASSERT(resource->hasScriptObject()); @@ -2032,54 +1112,7 @@ void InspectorController::updateScriptResourceRequest(InspectorResource* resourc resource->scriptObject->Set(v8::String::New("requestHeaders"), scriptObjectForRequest(resource)); resource->scriptObject->Set(v8::String::New("mainResource"), (m_mainResource == resource)?v8::True():v8::False()); } -#endif - -#if USE(JSC) -void InspectorController::updateScriptResourceResponse(InspectorResource* resource) -{ - ASSERT(resource->scriptObject); - ASSERT(m_scriptContext); - if (!resource->scriptObject || !m_scriptContext) - return; - - JSValueRef mimeTypeValue = JSValueMakeString(m_scriptContext, jsStringRef(resource->mimeType).get()); - - JSValueRef suggestedFilenameValue = JSValueMakeString(m_scriptContext, jsStringRef(resource->suggestedFilename).get()); - - JSValueRef expectedContentLengthValue = JSValueMakeNumber(m_scriptContext, static_cast(resource->expectedContentLength)); - JSValueRef statusCodeValue = JSValueMakeNumber(m_scriptContext, resource->responseStatusCode); - - JSValueRef exception = 0; - JSObjectSetProperty(m_scriptContext, resource->scriptObject, jsStringRef("mimeType").get(), mimeTypeValue, kJSPropertyAttributeNone, &exception); - if (HANDLE_EXCEPTION(exception)) - return; - - JSObjectSetProperty(m_scriptContext, resource->scriptObject, jsStringRef("suggestedFilename").get(), suggestedFilenameValue, kJSPropertyAttributeNone, &exception); - if (HANDLE_EXCEPTION(exception)) - return; - - JSObjectSetProperty(m_scriptContext, resource->scriptObject, jsStringRef("expectedContentLength").get(), expectedContentLengthValue, kJSPropertyAttributeNone, &exception); - if (HANDLE_EXCEPTION(exception)) - return; - - JSObjectSetProperty(m_scriptContext, resource->scriptObject, jsStringRef("statusCode").get(), statusCodeValue, kJSPropertyAttributeNone, &exception); - if (HANDLE_EXCEPTION(exception)) - return; - - JSObjectRef scriptObject = scriptObjectForResponse(m_scriptContext, resource, &exception); - if (HANDLE_EXCEPTION(exception)) - return; - - JSObjectSetProperty(m_scriptContext, resource->scriptObject, jsStringRef("responseHeaders").get(), scriptObject, kJSPropertyAttributeNone, &exception); - if (HANDLE_EXCEPTION(exception)) - return; - - JSValueRef typeValue = JSValueMakeNumber(m_scriptContext, resource->type()); - JSObjectSetProperty(m_scriptContext, resource->scriptObject, jsStringRef("type").get(), typeValue, kJSPropertyAttributeNone, &exception); - HANDLE_EXCEPTION(exception); -} -#elif USE(V8) void InspectorController::updateScriptResourceResponse(InspectorResource* resource) { ASSERT(resource->hasScriptObject()); @@ -2099,24 +1132,12 @@ void InspectorController::updateScriptResourceResponse(InspectorResource* resour resource->scriptObject->Set(v8::String::New("responseHeaders"), scriptObjectForResponse(resource)); resource->scriptObject->Set(v8::String::New("type"), v8::Number::New(resource->type())); } -#endif -#if USE(JSC) -void InspectorController::updateScriptResource(InspectorResource* resource, int length) +void InspectorController::updateScriptResourceType(InspectorResource* resource) { - ASSERT(resource->scriptObject); - ASSERT(m_scriptContext); - if (!resource->scriptObject || !m_scriptContext) - return; - - JSValueRef lengthValue = JSValueMakeNumber(m_scriptContext, length); - - JSValueRef exception = 0; - - JSObjectSetProperty(m_scriptContext, resource->scriptObject, jsStringRef("contentLength").get(), lengthValue, kJSPropertyAttributeNone, &exception); - HANDLE_EXCEPTION(exception); + notImplemented(); } -#elif USE(V8) + void InspectorController::updateScriptResource(InspectorResource* resource, int length) { ASSERT(resource->hasScriptObject()); @@ -2131,29 +1152,7 @@ void InspectorController::updateScriptResource(InspectorResource* resource, int m_scriptObject->Set(v8::String::New("contentLength"), v8::Number::New(length)); } -#endif - -#if USE(JSC) -void InspectorController::updateScriptResource(InspectorResource* resource, bool finished, bool failed) -{ - ASSERT(resource->scriptObject); - ASSERT(m_scriptContext); - if (!resource->scriptObject || !m_scriptContext) - return; - - JSValueRef failedValue = JSValueMakeBoolean(m_scriptContext, failed); - JSValueRef finishedValue = JSValueMakeBoolean(m_scriptContext, finished); - - JSValueRef exception = 0; - JSObjectSetProperty(m_scriptContext, resource->scriptObject, jsStringRef("failed").get(), failedValue, kJSPropertyAttributeNone, &exception); - if (HANDLE_EXCEPTION(exception)) - return; - - JSObjectSetProperty(m_scriptContext, resource->scriptObject, jsStringRef("finished").get(), finishedValue, kJSPropertyAttributeNone, &exception); - HANDLE_EXCEPTION(exception); -} -#elif USE(V8) void InspectorController::updateScriptResource(InspectorResource* resource, bool finished, bool failed) { ASSERT(resource->hasScriptObject()); @@ -2168,34 +1167,7 @@ void InspectorController::updateScriptResource(InspectorResource* resource, bool resource->scriptObject->Set(v8::String::New("failed"), (failed)?v8::True():v8::False()); resource->scriptObject->Set(v8::String::New("finished"), (finished)?v8::True():v8::False()); } -#endif -#if USE(JSC) -void InspectorController::updateScriptResource(InspectorResource* resource, double startTime, double responseReceivedTime, double endTime) -{ - ASSERT(resource->scriptObject); - ASSERT(m_scriptContext); - if (!resource->scriptObject || !m_scriptContext) - return; - - JSValueRef startTimeValue = JSValueMakeNumber(m_scriptContext, startTime); - JSValueRef responseReceivedTimeValue = JSValueMakeNumber(m_scriptContext, responseReceivedTime); - JSValueRef endTimeValue = JSValueMakeNumber(m_scriptContext, endTime); - - JSValueRef exception = 0; - - JSObjectSetProperty(m_scriptContext, resource->scriptObject, jsStringRef("startTime").get(), startTimeValue, kJSPropertyAttributeNone, &exception); - if (HANDLE_EXCEPTION(exception)) - return; - - JSObjectSetProperty(m_scriptContext, resource->scriptObject, jsStringRef("responseReceivedTime").get(), responseReceivedTimeValue, kJSPropertyAttributeNone, &exception); - if (HANDLE_EXCEPTION(exception)) - return; - - JSObjectSetProperty(m_scriptContext, resource->scriptObject, jsStringRef("endTime").get(), endTimeValue, kJSPropertyAttributeNone, &exception); - HANDLE_EXCEPTION(exception); -} -#elif USE(V8) void InspectorController::updateScriptResource(InspectorResource* resource, double startTime, double responseReceivedTime, double endTime) { ASSERT(resource->hasScriptObject()); @@ -2211,30 +1183,7 @@ void InspectorController::updateScriptResource(InspectorResource* resource, doub resource->scriptObject->Set(v8::String::New("responseReceivedTime"), v8::Number::New(responseReceivedTime)); resource->scriptObject->Set(v8::String::New("endTime"), v8::Number::New(endTime)); } -#endif - -#if USE(JSC) -void InspectorController::populateScriptObjects() -{ - ASSERT(m_scriptContext); - if (!m_scriptContext) - return; - ResourcesMap::iterator resourcesEnd = m_resources.end(); - for (ResourcesMap::iterator it = m_resources.begin(); it != resourcesEnd; ++it) - addAndUpdateScriptResource(it->second.get()); - - unsigned messageCount = m_consoleMessages.size(); - for (unsigned i = 0; i < messageCount; ++i) - addScriptConsoleMessage(m_consoleMessages[i]); - -#if ENABLE(DATABASE) - DatabaseResourcesSet::iterator databasesEnd = m_databaseResources.end(); - for (DatabaseResourcesSet::iterator it = m_databaseResources.begin(); it != databasesEnd; ++it) - addDatabaseScriptResource((*it).get()); -#endif -} -#elif USE(V8) void InspectorController::populateScriptObjects() { ResourcesMap::iterator resourcesEnd = m_resources.end(); @@ -2244,162 +1193,11 @@ void InspectorController::populateScriptObjects() unsigned messageCount = m_consoleMessages.size(); for (unsigned i = 0; i < messageCount; ++i) addScriptConsoleMessage(m_consoleMessages[i]); -} -#endif - -#if ENABLE(DATABASE) -JSObjectRef InspectorController::addDatabaseScriptResource(InspectorDatabaseResource* resource) -{ - ASSERT_ARG(resource, resource); - - if (resource->scriptObject) - return resource->scriptObject; - - ASSERT(m_scriptContext); - ASSERT(m_scriptObject); - if (!m_scriptContext || !m_scriptObject) - return 0; - - Frame* frame = resource->database->document()->frame(); - if (!frame) - return 0; - - JSValueRef exception = 0; - - JSValueRef databaseProperty = JSObjectGetProperty(m_scriptContext, m_scriptObject, jsStringRef("Database").get(), &exception); - if (HANDLE_EXCEPTION(exception)) - return 0; - - JSObjectRef databaseConstructor = JSValueToObject(m_scriptContext, databaseProperty, &exception); - if (HANDLE_EXCEPTION(exception)) - return 0; - - ExecState* exec = toJSDOMWindow(frame)->globalExec(); - - JSValueRef database; - - { - KJS::JSLock lock; - database = toRef(JSInspectedObjectWrapper::wrap(exec, toJS(exec, resource->database.get()))); - } - - JSValueRef domainValue = JSValueMakeString(m_scriptContext, jsStringRef(resource->domain).get()); - JSValueRef nameValue = JSValueMakeString(m_scriptContext, jsStringRef(resource->name).get()); - JSValueRef versionValue = JSValueMakeString(m_scriptContext, jsStringRef(resource->version).get()); - - JSValueRef arguments[] = { database, domainValue, nameValue, versionValue }; - JSObjectRef result = JSObjectCallAsConstructor(m_scriptContext, databaseConstructor, 4, arguments, &exception); - if (HANDLE_EXCEPTION(exception)) - return 0; - - ASSERT(result); - - JSValueRef addDatabaseProperty = JSObjectGetProperty(m_scriptContext, m_scriptObject, jsStringRef("addDatabase").get(), &exception); - if (HANDLE_EXCEPTION(exception)) - return 0; - - JSObjectRef addDatabaseFunction = JSValueToObject(m_scriptContext, addDatabaseProperty, &exception); - if (HANDLE_EXCEPTION(exception)) - return 0; - - JSValueRef addArguments[] = { result }; - JSObjectCallAsFunction(m_scriptContext, addDatabaseFunction, m_scriptObject, 1, addArguments, &exception); - if (HANDLE_EXCEPTION(exception)) - return 0; - - resource->setScriptObject(m_scriptContext, result); - - return result; -} -void InspectorController::removeDatabaseScriptResource(InspectorDatabaseResource* resource) -{ - ASSERT(m_scriptContext); - ASSERT(m_scriptObject); - if (!m_scriptContext || !m_scriptObject) - return; - - ASSERT(resource); - ASSERT(resource->scriptObject); - if (!resource || !resource->scriptObject) - return; - - JSObjectRef scriptObject = resource->scriptObject; - resource->setScriptObject(0, 0); - - JSValueRef exception = 0; - - JSValueRef removeDatabaseProperty = JSObjectGetProperty(m_scriptContext, m_scriptObject, jsStringRef("removeDatabase").get(), &exception); - if (HANDLE_EXCEPTION(exception)) - return; - - JSObjectRef removeDatabaseFunction = JSValueToObject(m_scriptContext, removeDatabaseProperty, &exception); - if (HANDLE_EXCEPTION(exception)) - return; - - JSValueRef arguments[] = { scriptObject }; - JSObjectCallAsFunction(m_scriptContext, removeDatabaseFunction, m_scriptObject, 1, arguments, &exception); - HANDLE_EXCEPTION(exception); + // TODO(ojan): Call populateInterface javascript function here. + // Need to add it to the IDL and whatnot. } -#endif - -#if USE(JSC) -void InspectorController::addScriptConsoleMessage(const ConsoleMessage* message) -{ - ASSERT_ARG(message, message); - - if (!m_scriptContext || !m_scriptObject) - return; - - JSValueRef exception = 0; - - JSValueRef messageConstructorProperty = JSObjectGetProperty(m_scriptContext, m_scriptObject, jsStringRef("ConsoleMessage").get(), &exception); - if (HANDLE_EXCEPTION(exception)) - return; - - JSObjectRef messageConstructor = JSValueToObject(m_scriptContext, messageConstructorProperty, &exception); - if (HANDLE_EXCEPTION(exception)) - return; - - JSValueRef addMessageProperty = JSObjectGetProperty(m_scriptContext, m_scriptObject, jsStringRef("addMessageToConsole").get(), &exception); - if (HANDLE_EXCEPTION(exception)) - return; - - JSObjectRef addMessage = JSValueToObject(m_scriptContext, addMessageProperty, &exception); - if (HANDLE_EXCEPTION(exception)) - return; - - JSValueRef sourceValue = JSValueMakeNumber(m_scriptContext, message->source); - JSValueRef levelValue = JSValueMakeNumber(m_scriptContext, message->level); - JSValueRef lineValue = JSValueMakeNumber(m_scriptContext, message->line); - JSValueRef urlValue = JSValueMakeString(m_scriptContext, jsStringRef(message->url).get()); - - static const unsigned maximumMessageArguments = 256; - JSValueRef arguments[maximumMessageArguments]; - unsigned argumentCount = 0; - arguments[argumentCount++] = sourceValue; - arguments[argumentCount++] = levelValue; - arguments[argumentCount++] = lineValue; - arguments[argumentCount++] = urlValue; - - if (!message->wrappedArguments.isEmpty()) { - unsigned remainingSpaceInArguments = maximumMessageArguments - argumentCount; - unsigned argumentsToAdd = min(remainingSpaceInArguments, static_cast(message->wrappedArguments.size())); - for (unsigned i = 0; i < argumentsToAdd; ++i) - arguments[argumentCount++] = toRef(message->wrappedArguments[i]); - } else { - JSValueRef messageValue = JSValueMakeString(m_scriptContext, jsStringRef(message->message).get()); - arguments[argumentCount++] = messageValue; - } - - JSObjectRef messageObject = JSObjectCallAsConstructor(m_scriptContext, messageConstructor, argumentCount, arguments, &exception); - if (HANDLE_EXCEPTION(exception)) - return; - JSObjectCallAsFunction(m_scriptContext, addMessage, m_scriptObject, 1, &messageObject, &exception); - HANDLE_EXCEPTION(exception); -} -#elif USE(V8) void InspectorController::addScriptConsoleMessage(const ConsoleMessage* message) { ASSERT_ARG(message, message); @@ -2437,6 +1235,7 @@ void InspectorController::addScriptConsoleMessage(const ConsoleMessage* message) v8::Number::New(message->line), v8StringOrNull(message->url), v8StringOrNull(message->message), + v8::Number::New(message->groupLevel), }; v8::Handle consoleMessage = @@ -2447,26 +1246,16 @@ void InspectorController::addScriptConsoleMessage(const ConsoleMessage* message) v8::Handle args2[] = { consoleMessage }; (v8::Function::Cast(*addMessageToConsole))->Call(m_scriptObject, 1, args2); } -#endif void InspectorController::resetScriptObjects() { -#if USE(JSC) - if (!m_scriptContext || !m_scriptObject) - return; -#elif USE(V8) if (!hasScriptObject()) return; -#endif ResourcesMap::iterator resourcesEnd = m_resources.end(); for (ResourcesMap::iterator it = m_resources.begin(); it != resourcesEnd; ++it) { InspectorResource* resource = it->second.get(); -#if USE(JSC) - resource->setScriptObject(0, 0); -#elif USE(V8) resource->setScriptObject(v8::Handle()); -#endif } #if ENABLE(DATABASE) @@ -2477,9 +1266,6 @@ void InspectorController::resetScriptObjects() } #endif -#if USE(JSC) - callSimpleFunction(m_scriptContext, m_scriptObject, "reset"); -#elif USE(V8) v8::HandleScope handle_scope; v8::Handle context = V8Proxy::GetContext(m_page->mainFrame()); v8::Context::Scope scope(context); @@ -2489,7 +1275,6 @@ void InspectorController::resetScriptObjects() v8::Handle func(v8::Function::Cast(*reset)); func->Call(m_scriptObject, 0, NULL); -#endif } void InspectorController::pruneResources(ResourcesMap* resourceMap, DocumentLoader* loaderToKeep) @@ -2516,10 +1301,13 @@ void InspectorController::didCommitLoad(DocumentLoader* loader) if (!enabled()) return; + ASSERT(m_inspectedPage); + if (loader->frame() == m_inspectedPage->mainFrame()) { m_client->inspectedURLChanged(loader->url().string()); deleteAllValues(m_consoleMessages); m_consoleMessages.clear(); + m_groupLevel = 0; #if ENABLE(DATABASE) m_databaseResources.clear(); @@ -2563,6 +1351,7 @@ void InspectorController::addResource(InspectorResource* resource) { ASSERT(trackResources()); m_resources.set(resource->identifier, resource); + m_knownResources.add(resource->requestURL.string()); Frame* frame = resource->frame.get(); ResourcesMap* resourceMap = m_frameResources.get(frame); @@ -2598,6 +1387,10 @@ void InspectorController::didLoadResourceFromMemoryCache(DocumentLoader* loader, if (!enabled() || !trackResources()) return; + // If the resource URL is already known, we don't need to add it again since this is just a cached load. + if (m_knownResources.contains(request.url().string())) + return; + RefPtr resource = InspectorResource::create(m_nextIdentifier--, loader, loader->frame()); resource->finished = true; @@ -2610,6 +1403,8 @@ void InspectorController::didLoadResourceFromMemoryCache(DocumentLoader* loader, resource->responseReceivedTime = resource->startTime; resource->endTime = resource->startTime; + ASSERT(m_inspectedPage); + if (loader->frame() == m_inspectedPage->mainFrame() && request.url() == loader->requestURL()) m_mainResource = resource; @@ -2745,25 +1540,10 @@ void InspectorController::didFailLoading(DocumentLoader* loader, unsigned long i } } -#if USE(JSC) -void InspectorController::resourceRetrievedByXMLHttpRequest(unsigned long identifier, KJS::UString& sourceString) -{ - if (!enabled()) - return; - - InspectorResource* resource = m_resources.get(identifier).get(); - if (!resource) - return; - - resource->setXMLHttpRequestProperties(sourceString); -} -#elif USE(V8) -// TODO(ojan): Implement! void InspectorController::resourceRetrievedByXMLHttpRequest(unsigned long identifier, String& sourceString) { + notImplemented(); } -#endif - #if ENABLE(DATABASE) void InspectorController::didOpenDatabase(Database* database, const String& domain, const String& name, const String& version) @@ -2792,20 +1572,11 @@ void InspectorController::moveWindowBy(float x, float y) const void InspectorController::startDebuggingAndReloadInspectedPage() { - /* - JavaScriptDebugServer::shared().addListener(this, m_inspectedPage); - m_debuggerAttached = true; - m_inspectedPage->mainFrame()->loader()->reload(); - */ notImplemented(); } void InspectorController::stopDebugging() { - /* - JavaScriptDebugServer::shared().removeListener(this, m_inspectedPage); - m_debuggerAttached = false; - */ notImplemented(); } @@ -2849,28 +1620,44 @@ static void drawHighlightForBoxes(GraphicsContext& context, const Vectorpage()->mainFrame()->view()->windowToContents(frame->view()->contentsToWindow(rect)); +} + void InspectorController::drawNodeHighlight(GraphicsContext& context) const { if (!m_highlightedNode) return; RenderObject* renderer = m_highlightedNode->renderer(); - if (!renderer) + Frame* containingFrame = m_highlightedNode->document()->frame(); + if (!renderer || !containingFrame) return; IntRect contentBox = renderer->absoluteContentBox(); + IntRect boundingBox = renderer->absoluteBoundingBoxRect(); + // FIXME: Should we add methods to RenderObject to obtain these rects? IntRect paddingBox(contentBox.x() - renderer->paddingLeft(), contentBox.y() - renderer->paddingTop(), contentBox.width() + renderer->paddingLeft() + renderer->paddingRight(), contentBox.height() + renderer->paddingTop() + renderer->paddingBottom()); IntRect borderBox(paddingBox.x() - renderer->borderLeft(), paddingBox.y() - renderer->borderTop(), paddingBox.width() + renderer->borderLeft() + renderer->borderRight(), paddingBox.height() + renderer->borderTop() + renderer->borderBottom()); IntRect marginBox(borderBox.x() - renderer->marginLeft(), borderBox.y() - renderer->marginTop(), borderBox.width() + renderer->marginLeft() + renderer->marginRight(), borderBox.height() + renderer->marginTop() + renderer->marginBottom()); - IntRect boundingBox = renderer->absoluteBoundingBoxRect(); - + convertFromFrameToMainFrame(containingFrame, contentBox); + convertFromFrameToMainFrame(containingFrame, paddingBox); + convertFromFrameToMainFrame(containingFrame, borderBox); + convertFromFrameToMainFrame(containingFrame, marginBox); + convertFromFrameToMainFrame(containingFrame, boundingBox); + Vector lineBoxRects; if (renderer->isInline() || (renderer->isText() && !m_highlightedNode->isSVGElement())) { // FIXME: We should show margins/padding/border for inlines. renderer->addLineBoxRects(lineBoxRects); } + + for (unsigned i = 0; i < lineBoxRects.size(); ++i) + convertFromFrameToMainFrame(containingFrame, lineBoxRects[i]); + if (lineBoxRects.isEmpty() && contentBox.isEmpty()) { // If we have no line boxes and our content box is empty, we'll just draw our bounding box. // This can happen, e.g., with an enclosing an . @@ -2879,6 +1666,8 @@ void InspectorController::drawNodeHighlight(GraphicsContext& context) const lineBoxRects.append(boundingBox); } + ASSERT(m_inspectedPage); + FrameView* view = m_inspectedPage->mainFrame()->view(); FloatRect overlayRect = view->visibleContentRect(); @@ -2897,51 +1686,4 @@ void InspectorController::drawNodeHighlight(GraphicsContext& context) const drawHighlightForBoxes(context, lineBoxRects, contentBox, paddingBox, borderBox, marginBox); } -#if USE(JSC) -bool InspectorController::handleException(JSValueRef exception, unsigned lineNumber) const -{ - if (!exception) - return false; - - if (!m_page) - return true; - - JSRetainPtr messageString(Adopt, JSValueToStringCopy(m_scriptContext, exception, 0)); - String message(JSStringGetCharactersPtr(messageString.get()), JSStringGetLength(messageString.get())); - - m_page->mainFrame()->domWindow()->console()->addMessage(JSMessageSource, ErrorMessageLevel, message, lineNumber, __FILE__); - return true; -} - -#pragma mark - -#pragma mark JavaScriptDebugListener functions - -void InspectorController::didParseSource(ExecState*, const UString& /*source*/, int /*startingLineNumber*/, const UString& /*sourceURL*/, int /*sourceID*/) -{ -} - -void InspectorController::failedToParseSource(ExecState*, const UString& /*source*/, int /*startingLineNumber*/, const UString& /*sourceURL*/, int /*errorLine*/, const UString& /*errorMessage*/) -{ -} - -void InspectorController::didEnterCallFrame(ExecState*, int /*sourceID*/, int /*lineNumber*/) -{ -} - -void InspectorController::willExecuteStatement(ExecState*, int /*sourceID*/, int /*lineNumber*/) -{ -} - -void InspectorController::willLeaveCallFrame(ExecState*, int /*sourceID*/, int /*lineNumber*/) -{ -} - -void InspectorController::exceptionWasRaised(ExecState*, int /*sourceID*/, int /*lineNumber*/) -{ -} - -#elif USE(V8) -// TODO(ojan): Implement! -#endif - } // namespace WebCore diff --git a/webkit/port/page/inspector/InspectorControllerKJS.cpp b/webkit/port/page/inspector/InspectorControllerKJS.cpp deleted file mode 100644 index da0bbb55..0000000 --- a/webkit/port/page/inspector/InspectorControllerKJS.cpp +++ /dev/null @@ -1,1678 +0,0 @@ -/* - * Copyright (C) 2007 Apple Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of - * its contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -// -// TODO(mbelshe) Let's get rid of this file with the next merge. -// Unfortunately we needed to fork the KJS version and V8 version -// of this file. -// - -#include "config.h" -#include "InspectorController.h" - -#include "CString.h" -#include "CachedResource.h" -#include "DocLoader.h" -#include "Document.h" -#include "DocumentLoader.h" -#include "Element.h" -#include "FloatConversion.h" -#include "FloatRect.h" -#include "Frame.h" -#include "FrameLoader.h" -#include "FrameTree.h" -#include "FrameView.h" -#include "GraphicsContext.h" -#include "HTMLFrameOwnerElement.h" -#include "InspectorClient.h" -#include "JSRange.h" -#include "Page.h" -#include "Range.h" -#include "ResourceRequest.h" -#include "ResourceResponse.h" -#include "Settings.h" -#include "SharedBuffer.h" -#include "SystemTime.h" -#include "TextEncoding.h" -#include "TextIterator.h" -#include "kjs_dom.h" -#include "kjs_proxy.h" -#include "kjs_window.h" -#include -#include -#include -#include -#include - -#if ENABLE(DATABASE) -#include "Database.h" -#include "JSDatabase.h" -#endif - -namespace WebCore { - -static JSValueRef callSimpleFunction(JSContextRef context, JSObjectRef thisObject, const char* functionName) -{ - return JSValueMakeUndefined(context); - // This make the inspector totally non-functional in a KJS build, but keeps - // it from crashing when you open it. Allows the UI test to pass. - /* - ASSERT_ARG(context, context); - ASSERT_ARG(thisObject, thisObject); - - JSRetainPtr functionNameString(Adopt, JSStringCreateWithUTF8CString(functionName)); - JSObjectRef function = JSValueToObject(context, JSObjectGetProperty(context, thisObject, functionNameString.get(), 0), 0); - - return JSObjectCallAsFunction(context, function, thisObject, 0, 0, 0); - */ -} - -#pragma mark - -#pragma mark ConsoleMessage Struct - -struct ConsoleMessage { - ConsoleMessage(MessageSource s, MessageLevel l, const String& m, unsigned li, const String& u) - : source(s) - , level(l) - , message(m) - , line(li) - , url(u) - { - } - - MessageSource source; - MessageLevel level; - String message; - unsigned line; - String url; -}; - -#pragma mark - -#pragma mark InspectorResource Struct - -struct InspectorResource : public RefCounted { - // Keep these in sync with WebInspector.Resource.Type - enum Type { - Doc, - Stylesheet, - Image, - Font, - Script, - Other - }; - - InspectorResource(long long identifier, DocumentLoader* documentLoader, Frame* frame) - : identifier(identifier) - , loader(documentLoader) - , frame(frame) - , scriptContext(0) - , scriptObject(0) - , expectedContentLength(0) - , cached(false) - , finished(false) - , failed(false) - , length(0) - , responseStatusCode(0) - , startTime(-1.0) - , responseReceivedTime(-1.0) - , endTime(-1.0) - { - } - - ~InspectorResource() - { - setScriptObject(0, 0); - } - - Type type() const - { - if (requestURL == loader->requestURL()) - return Doc; - - if (loader->frameLoader() && requestURL == loader->frameLoader()->iconURL()) - return Image; - - CachedResource* cachedResource = frame->document()->docLoader()->cachedResource(requestURL.string()); - if (!cachedResource) - return Other; - - switch (cachedResource->type()) { - case CachedResource::ImageResource: - return Image; - case CachedResource::FontResource: - return Font; - case CachedResource::CSSStyleSheet: -#if ENABLE(XSLT) - case CachedResource::XSLStyleSheet: -#endif - return Stylesheet; - case CachedResource::Script: - return Script; - default: - return Other; - } - } - - void setScriptObject(JSContextRef context, JSObjectRef newScriptObject) - { - if (scriptContext && scriptObject) - JSValueUnprotect(scriptContext, scriptObject); - - scriptObject = newScriptObject; - scriptContext = context; - - ASSERT((context && newScriptObject) || (!context && !newScriptObject)); - if (context && newScriptObject) - JSValueProtect(context, newScriptObject); - } - - long long identifier; - RefPtr loader; - RefPtr frame; - KURL requestURL; - HTTPHeaderMap requestHeaderFields; - HTTPHeaderMap responseHeaderFields; - String mimeType; - String suggestedFilename; - JSContextRef scriptContext; - JSObjectRef scriptObject; - long long expectedContentLength; - bool cached; - bool finished; - bool failed; - int length; - int responseStatusCode; - double startTime; - double responseReceivedTime; - double endTime; -}; - -#pragma mark - -#pragma mark InspectorDatabaseResource Struct - -#if ENABLE(DATABASE) -struct InspectorDatabaseResource : public RefCounted { - InspectorDatabaseResource(Database* database, String domain, String name, String version) - : database(database) - , domain(domain) - , name(name) - , version(version) - , scriptContext(0) - , scriptObject(0) - { - } - - InspectorDatabaseResource() - { - setScriptObject(0, 0); - } - - void setScriptObject(JSContextRef context, JSObjectRef newScriptObject) - { - if (scriptContext && scriptObject) - JSValueUnprotect(scriptContext, scriptObject); - - scriptObject = newScriptObject; - scriptContext = context; - - ASSERT((context && newScriptObject) || (!context && !newScriptObject)); - if (context && newScriptObject) - JSValueProtect(context, newScriptObject); - } - - RefPtr database; - String domain; - String name; - String version; - JSContextRef scriptContext; - JSObjectRef scriptObject; -}; -#endif - -#pragma mark - -#pragma mark JavaScript Callbacks - -static JSValueRef addSourceToFrame(JSContextRef ctx, JSObjectRef /*function*/, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* /*exception*/) -{ - JSValueRef undefined = JSValueMakeUndefined(ctx); - - InspectorController* controller = reinterpret_cast(JSObjectGetPrivate(thisObject)); - if (argumentCount < 2 || !controller) - return undefined; - - JSValueRef identifierValue = arguments[0]; - if (!JSValueIsNumber(ctx, identifierValue)) - return undefined; - - unsigned long identifier = static_cast(JSValueToNumber(ctx, identifierValue, 0)); - RefPtr resource = controller->resources().get(identifier); - ASSERT(resource); - if (!resource) - return undefined; - - RefPtr buffer; - String textEncodingName; - if (resource->requestURL == resource->loader->requestURL()) { - buffer = resource->loader->mainResourceData(); - textEncodingName = resource->frame->document()->inputEncoding(); - } else { - CachedResource* cachedResource = resource->frame->document()->docLoader()->cachedResource(resource->requestURL.string()); - if (!cachedResource) - return undefined; - - // TODO(mbelshe): Fix me! - // Removing this, which disables this feature from the KJS - // version of the inspector controller. We don't care for now. - // Will resolve with next merge. - //buffer = cachedResource->data(); - //textEncodingName = cachedResource->encoding(); - } - - if (!buffer) - return undefined; - - TextEncoding encoding(textEncodingName); - if (!encoding.isValid()) - encoding = WindowsLatin1Encoding(); - String sourceString = encoding.decode(buffer->data(), buffer->size()); - - Node* node = toNode(toJS(arguments[1])); - ASSERT(node); - if (!node) - return undefined; - - if (!node->attached()) { - ASSERT_NOT_REACHED(); - return undefined; - } - - ASSERT(node->isElementNode()); - if (!node->isElementNode()) - return undefined; - - Element* element = static_cast(node); - ASSERT(element->isFrameOwnerElement()); - if (!element->isFrameOwnerElement()) - return undefined; - - HTMLFrameOwnerElement* frameOwner = static_cast(element); - ASSERT(frameOwner->contentFrame()); - if (!frameOwner->contentFrame()) - return undefined; - - FrameLoader* loader = frameOwner->contentFrame()->loader(); - - loader->setResponseMIMEType(resource->mimeType); - loader->begin(); - loader->write(sourceString); - loader->end(); - - return undefined; -} - -static JSValueRef getResourceDocumentNode(JSContextRef ctx, JSObjectRef /*function*/, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* /*exception*/) -{ - JSValueRef undefined = JSValueMakeUndefined(ctx); - - InspectorController* controller = reinterpret_cast(JSObjectGetPrivate(thisObject)); - if (!argumentCount || argumentCount > 1 || !controller) - return undefined; - - JSValueRef identifierValue = arguments[0]; - if (!JSValueIsNumber(ctx, identifierValue)) - return undefined; - - unsigned long identifier = static_cast(JSValueToNumber(ctx, identifierValue, 0)); - RefPtr resource = controller->resources().get(identifier); - ASSERT(resource); - if (!resource) - return undefined; - - Document* document = resource->frame->document(); - if (!document) - return undefined; - - if (document->isPluginDocument() || document->isImageDocument()) - return undefined; - - KJS::JSLock lock; - JSValueRef documentValue = toRef(toJS(toJS(controller->scriptContext()), document)); - return documentValue; -} - -static JSValueRef highlightDOMNode(JSContextRef context, JSObjectRef /*function*/, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* /*exception*/) -{ - JSValueRef undefined = JSValueMakeUndefined(context); - - InspectorController* controller = reinterpret_cast(JSObjectGetPrivate(thisObject)); - if (argumentCount < 1 || !controller) - return undefined; - - Node* node = toNode(toJS(arguments[0])); - if (!node) - return undefined; - - controller->highlight(node); - - return undefined; -} - -static JSValueRef hideDOMNodeHighlight(JSContextRef context, JSObjectRef /*function*/, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* /*exception*/) -{ - JSValueRef undefined = JSValueMakeUndefined(context); - - InspectorController* controller = reinterpret_cast(JSObjectGetPrivate(thisObject)); - if (argumentCount || !controller) - return undefined; - - controller->hideHighlight(); - - return undefined; -} - -static JSValueRef loaded(JSContextRef ctx, JSObjectRef /*function*/, JSObjectRef thisObject, size_t /*argumentCount*/, const JSValueRef[] /*arguments[]*/, JSValueRef* /*exception*/) -{ - InspectorController* controller = reinterpret_cast(JSObjectGetPrivate(thisObject)); - if (!controller) - return JSValueMakeUndefined(ctx); - - controller->scriptObjectReady(); - return JSValueMakeUndefined(ctx); -} - -static JSValueRef unloading(JSContextRef ctx, JSObjectRef /*function*/, JSObjectRef thisObject, size_t /*argumentCount*/, const JSValueRef[] /*arguments[]*/, JSValueRef* /*exception*/) -{ - InspectorController* controller = reinterpret_cast(JSObjectGetPrivate(thisObject)); - if (!controller) - return JSValueMakeUndefined(ctx); - - controller->close(); - return JSValueMakeUndefined(ctx); -} - -static JSValueRef noop(JSContextRef ctx, JSObjectRef /*function*/, JSObjectRef thisObject, size_t /*argumentCount*/, const JSValueRef[] /*arguments[]*/, JSValueRef* /*exception*/) -{ - return JSValueMakeUndefined(ctx); -} -static JSValueRef attach(JSContextRef ctx, JSObjectRef /*function*/, JSObjectRef thisObject, size_t /*argumentCount*/, const JSValueRef[] /*arguments[]*/, JSValueRef* /*exception*/) -{ - InspectorController* controller = reinterpret_cast(JSObjectGetPrivate(thisObject)); - if (!controller) - return JSValueMakeUndefined(ctx); - - controller->attachWindow(); - return JSValueMakeUndefined(ctx); -} - -static JSValueRef detach(JSContextRef ctx, JSObjectRef /*function*/, JSObjectRef thisObject, size_t /*argumentCount*/, const JSValueRef[] /*arguments[]*/, JSValueRef* /*exception*/) -{ - InspectorController* controller = reinterpret_cast(JSObjectGetPrivate(thisObject)); - if (!controller) - return JSValueMakeUndefined(ctx); - - controller->detachWindow(); - return JSValueMakeUndefined(ctx); -} - -static JSValueRef search(JSContextRef ctx, JSObjectRef /*function*/, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* /*exception*/) -{ - InspectorController* controller = reinterpret_cast(JSObjectGetPrivate(thisObject)); - if (!controller) - return JSValueMakeUndefined(ctx); - - if (argumentCount < 2 || !JSValueIsString(ctx, arguments[1])) - return JSValueMakeUndefined(ctx); - - Node* node = toNode(toJS(arguments[0])); - if (!node) - return JSValueMakeUndefined(ctx); - - JSRetainPtr searchString(Adopt, JSValueToStringCopy(ctx, arguments[1], 0)); - String target(JSStringGetCharactersPtr(searchString.get()), JSStringGetLength(searchString.get())); - - JSObjectRef global = JSContextGetGlobalObject(ctx); - JSRetainPtr arrayString(Adopt, JSStringCreateWithUTF8CString("Array")); - JSObjectRef arrayConstructor = JSValueToObject(ctx, JSObjectGetProperty(ctx, global, arrayString.get(), 0), 0); - - JSObjectRef result = JSObjectCallAsConstructor(ctx, arrayConstructor, 0, 0, 0); - - JSRetainPtr pushString(Adopt, JSStringCreateWithUTF8CString("push")); - JSObjectRef pushFunction = JSValueToObject(ctx, JSObjectGetProperty(ctx, result, pushString.get(), 0), 0); - - RefPtr searchRange(rangeOfContents(node)); - - int exception = 0; - do { - RefPtr resultRange(findPlainText(searchRange.get(), target, true, false)); - if (resultRange->collapsed(exception)) - break; - - // A non-collapsed result range can in some funky whitespace cases still not - // advance the range's start position (4509328). Break to avoid infinite loop. - VisiblePosition newStart = endVisiblePosition(resultRange.get(), DOWNSTREAM); - if (newStart == startVisiblePosition(searchRange.get(), DOWNSTREAM)) - break; - - KJS::JSLock lock; - JSValueRef arg0 = toRef(toJS(toJS(ctx), resultRange.get())); - JSObjectCallAsFunction(ctx, pushFunction, result, 1, &arg0, 0); - - setStart(searchRange.get(), newStart); - } while (true); - - return result; -} - -#if ENABLE(DATABASE) -static JSValueRef databaseTableNames(JSContextRef ctx, JSObjectRef /*function*/, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* /*exception*/) -{ - InspectorController* controller = reinterpret_cast(JSObjectGetPrivate(thisObject)); - if (!controller) - return JSValueMakeUndefined(ctx); - - if (argumentCount < 1) - return JSValueMakeUndefined(ctx); - - Database* database = toDatabase(toJS(arguments[0])); - if (!database) - return JSValueMakeUndefined(ctx); - - JSObjectRef global = JSContextGetGlobalObject(ctx); - JSRetainPtr arrayString(Adopt, JSStringCreateWithUTF8CString("Array")); - JSObjectRef arrayConstructor = JSValueToObject(ctx, JSObjectGetProperty(ctx, global, arrayString.get(), 0), 0); - - JSObjectRef result = JSObjectCallAsConstructor(ctx, arrayConstructor, 0, 0, 0); - - JSRetainPtr pushString(Adopt, JSStringCreateWithUTF8CString("push")); - JSObjectRef pushFunction = JSValueToObject(ctx, JSObjectGetProperty(ctx, result, pushString.get(), 0), 0); - - Vector tableNames = database->tableNames(); - unsigned length = tableNames.size(); - for (unsigned i = 0; i < length; ++i) { - String tableName = tableNames[i]; - JSRetainPtr tableNameString(Adopt, JSStringCreateWithCharacters(tableName.characters(), tableName.length())); - JSValueRef tableNameValue = JSValueMakeString(ctx, tableNameString.get()); - - JSValueRef pushArguments[] = { tableNameValue }; - JSObjectCallAsFunction(ctx, pushFunction, result, 1, pushArguments, 0); - } - - return result; -} -#endif - -static JSValueRef inspectedWindow(JSContextRef ctx, JSObjectRef /*function*/, JSObjectRef thisObject, size_t /*argumentCount*/, const JSValueRef[] /*arguments[]*/, JSValueRef* /*exception*/) -{ - InspectorController* controller = reinterpret_cast(JSObjectGetPrivate(thisObject)); - if (!controller) - return JSValueMakeUndefined(ctx); - - return toRef(KJS::Window::retrieve(controller->inspectedPage()->mainFrame())); -} - -static JSValueRef localizedStrings(JSContextRef ctx, JSObjectRef /*function*/, JSObjectRef thisObject, size_t /*argumentCount*/, const JSValueRef[] /*arguments[]*/, JSValueRef* /*exception*/) -{ - InspectorController* controller = reinterpret_cast(JSObjectGetPrivate(thisObject)); - if (!controller) - return JSValueMakeUndefined(ctx); - - String url = controller->localizedStringsURL(); - if (url.isNull()) - return JSValueMakeNull(ctx); - - JSRetainPtr urlString(Adopt, JSStringCreateWithCharacters(url.characters(), url.length())); - return JSValueMakeString(ctx, urlString.get()); -} - -static JSValueRef platform(JSContextRef ctx, JSObjectRef /*function*/, JSObjectRef thisObject, size_t /*argumentCount*/, const JSValueRef[] /*arguments[]*/, JSValueRef* /*exception*/) -{ -#if PLATFORM(MAC) -#ifdef BUILDING_ON_TIGER - static const String platform = "mac-tiger"; -#else - static const String platform = "mac-leopard"; -#endif -#elif PLATFORM(WIN_OS) - static const String platform = "windows"; -#elif PLATFORM(QT) - static const String platform = "qt"; -#elif PLATFORM(GTK) - static const String platform = "gtk"; -#elif PLATFORM(WX) - static const String platform = "wx"; -#else - static const String platform = "unknown"; -#endif - - JSRetainPtr platformString(Adopt, JSStringCreateWithCharacters(platform.characters(), platform.length())); - JSValueRef platformValue = JSValueMakeString(ctx, platformString.get()); - - return platformValue; -} - -static JSValueRef moveByUnrestricted(JSContextRef ctx, JSObjectRef /*function*/, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* /*exception*/) -{ - InspectorController* controller = reinterpret_cast(JSObjectGetPrivate(thisObject)); - if (!controller) - return JSValueMakeUndefined(ctx); - - if (argumentCount < 2) - return JSValueMakeUndefined(ctx); - - controller->moveWindowBy(narrowPrecisionToFloat(JSValueToNumber(ctx, arguments[0], 0)), narrowPrecisionToFloat(JSValueToNumber(ctx, arguments[1], 0))); - - return JSValueMakeUndefined(ctx); -} - -#pragma mark - -#pragma mark InspectorController Class - -InspectorController::InspectorController(Page* page, InspectorClient* client) - : m_inspectedPage(page) - , m_client(client) - , m_page(0) - , m_scriptObject(0) - , m_controllerScriptObject(0) - , m_scriptContext(0) - , m_windowVisible(false) - , m_showAfterVisible(FocusedNodeDocumentPanel) - , m_nextIdentifier(-2) -{ - ASSERT_ARG(page, page); - ASSERT_ARG(client, client); -} - -InspectorController::~InspectorController() -{ - m_client->inspectorDestroyed(); - - if (m_scriptContext) { - JSObjectRef global = JSContextGetGlobalObject(m_scriptContext); - JSRetainPtr controllerProperty(Adopt, JSStringCreateWithUTF8CString("InspectorController")); - JSObjectRef controller = JSValueToObject(m_scriptContext, JSObjectGetProperty(m_scriptContext, global, controllerProperty.get(), 0), 0); - if (controller) - JSObjectSetPrivate(controller, 0); - } - - if (m_page) - m_page->setParentInspectorController(0); - - // m_inspected page should already be cleared by inspectedPageDestroyed - ASSERT(!m_inspectedPage); - - deleteAllValues(m_frameResources); - deleteAllValues(m_consoleMessages); -} - -void InspectorController::inspectedPageDestroyed() -{ - ASSERT(m_inspectedPage); - m_inspectedPage = 0; -} - -bool InspectorController::enabled() const -{ - if (!m_inspectedPage) - return false; - - return m_inspectedPage->settings()->developerExtrasEnabled(); -} - -String InspectorController::localizedStringsURL() -{ - if (!enabled()) - return String(); - return m_client->localizedStringsURL(); -} - -// Trying to inspect something in a frame with JavaScript disabled would later lead to -// crashes trying to create JavaScript wrappers. Some day we could fix this issue, but -// for now prevent crashes here by never targeting a node in such a frame. -static bool canPassNodeToJavaScript(Node* node) -{ - if (!node) - return false; - Frame* frame = node->document()->frame(); - return frame && frame->scriptProxy()->isEnabled(); -} - -void InspectorController::inspect(Node* node) -{ - if (!canPassNodeToJavaScript(node) || !enabled()) - return; - - show(); - - if (node->nodeType() != Node::ELEMENT_NODE && node->nodeType() != Node::DOCUMENT_NODE) - node = node->parentNode(); - m_nodeToFocus = node; - - if (!m_scriptObject) { - m_showAfterVisible = FocusedNodeDocumentPanel; - return; - } - - if (windowVisible()) - focusNode(); -} - -void InspectorController::focusNode() -{ - if (!enabled()) - return; - - ASSERT(m_scriptContext); - ASSERT(m_scriptObject); - ASSERT(m_nodeToFocus); - - JSValueRef arg0; - - { - KJS::JSLock lock; - arg0 = toRef(toJS(toJS(m_scriptContext), m_nodeToFocus.get())); - } - - m_nodeToFocus = 0; - - JSRetainPtr functionProperty(Adopt, JSStringCreateWithUTF8CString("updateFocusedNode")); - JSObjectRef function = JSValueToObject(m_scriptContext, JSObjectGetProperty(m_scriptContext, m_scriptObject, functionProperty.get(), 0), 0); - ASSERT(function); - - JSObjectCallAsFunction(m_scriptContext, function, m_scriptObject, 1, &arg0, 0); -} - -void InspectorController::highlight(Node* node) -{ - if (!enabled()) - return; - ASSERT_ARG(node, node); - m_highlightedNode = node; - m_client->highlight(node); -} - -void InspectorController::hideHighlight() -{ - if (!enabled()) - return; - m_client->hideHighlight(); -} - -bool InspectorController::windowVisible() -{ - return m_windowVisible; -} - -void InspectorController::setWindowVisible(bool visible) -{ - if (visible == m_windowVisible) - return; - - m_windowVisible = visible; - - if (!m_scriptContext || !m_scriptObject) - return; - - if (m_windowVisible) { - populateScriptResources(); - if (m_nodeToFocus) - focusNode(); - if (m_showAfterVisible == ConsolePanel) - showConsole(); - else if (m_showAfterVisible == TimelinePanel) - showTimeline(); - } else { - clearScriptResources(); - clearScriptConsoleMessages(); - clearDatabaseScriptResources(); - clearNetworkTimeline(); - } - - m_showAfterVisible = FocusedNodeDocumentPanel; -} - -void InspectorController::addMessageToConsole(MessageSource source, MessageLevel level, const String& message, unsigned lineNumber, const String& sourceID) -{ - if (!enabled()) - return; - - ConsoleMessage* consoleMessage = new ConsoleMessage(source, level, message, lineNumber, sourceID); - m_consoleMessages.append(consoleMessage); - - if (windowVisible()) - addScriptConsoleMessage(consoleMessage); -} - -void InspectorController::attachWindow() -{ - if (!enabled()) - return; - m_client->attachWindow(); -} - -void InspectorController::detachWindow() -{ - if (!enabled()) - return; - m_client->detachWindow(); -} - -void InspectorController::windowScriptObjectAvailable() -{ - if (!m_page || !enabled()) - return; - - m_scriptContext = toRef(m_page->mainFrame()->scriptProxy()->globalObject()->globalExec()); - - JSObjectRef global = JSContextGetGlobalObject(m_scriptContext); - ASSERT(global); - - static JSStaticFunction staticFunctions[] = { - { "addSourceToFrame", addSourceToFrame, kJSPropertyAttributeNone }, - { "getResourceDocumentNode", getResourceDocumentNode, kJSPropertyAttributeNone }, - { "highlightDOMNode", highlightDOMNode, kJSPropertyAttributeNone }, - { "hideDOMNodeHighlight", hideDOMNodeHighlight, kJSPropertyAttributeNone }, - { "loaded", loaded, kJSPropertyAttributeNone }, - { "windowUnloading", unloading, kJSPropertyAttributeNone }, - { "attach", attach, kJSPropertyAttributeNone }, - { "detach", detach, kJSPropertyAttributeNone }, - { "search", search, kJSPropertyAttributeNone }, - { "clearResources", noop, kJSPropertyAttributeNone }, -#if ENABLE(DATABASE) - { "databaseTableNames", databaseTableNames, kJSPropertyAttributeNone }, -#endif - { "inspectedWindow", inspectedWindow, kJSPropertyAttributeNone }, - { "localizedStringsURL", localizedStrings, kJSPropertyAttributeNone }, - { "platform", platform, kJSPropertyAttributeNone }, - { "moveByUnrestricted", moveByUnrestricted, kJSPropertyAttributeNone }, - { 0, 0, 0 } - }; - - JSClassDefinition inspectorControllerDefinition = { - 0, kJSClassAttributeNone, "InspectorController", 0, 0, staticFunctions, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 - }; - - JSClassRef controllerClass = JSClassCreate(&inspectorControllerDefinition); - ASSERT(controllerClass); - - m_controllerScriptObject = JSObjectMake(m_scriptContext, controllerClass, reinterpret_cast(this)); - ASSERT(m_controllerScriptObject); - - JSRetainPtr controllerObjectString(Adopt, JSStringCreateWithUTF8CString("InspectorController")); - JSObjectSetProperty(m_scriptContext, global, controllerObjectString.get(), m_controllerScriptObject, kJSPropertyAttributeNone, 0); -} - -void InspectorController::scriptObjectReady() -{ - ASSERT(m_scriptContext); - if (!m_scriptContext) - return; - - JSObjectRef global = JSContextGetGlobalObject(m_scriptContext); - ASSERT(global); - - JSRetainPtr inspectorString(Adopt, JSStringCreateWithUTF8CString("WebInspector")); - JSValueRef inspectorValue = JSObjectGetProperty(m_scriptContext, global, inspectorString.get(), 0); - - ASSERT(inspectorValue); - if (!inspectorValue) - return; - - m_scriptObject = JSValueToObject(m_scriptContext, inspectorValue, 0); - ASSERT(m_scriptObject); - - JSValueProtect(m_scriptContext, m_scriptObject); - - // Make sure our window is visible now that the page loaded - m_client->showWindow(); -} - -void InspectorController::show() -{ - if (!enabled()) - return; - - if (!m_page) { - m_page = m_client->createPage(); - if (!m_page) - return; - m_page->setParentInspectorController(this); - - // m_client->showWindow() will be called after the page loads in scriptObjectReady() - return; - } - - m_client->showWindow(); -} - -void InspectorController::showConsole() -{ - if (!enabled()) - return; - - show(); - - if (!m_scriptObject) { - m_showAfterVisible = ConsolePanel; - return; - } - - callSimpleFunction(m_scriptContext, m_scriptObject, "showConsole"); -} - -void InspectorController::showTimeline() -{ - if (!enabled()) - return; - - show(); - - if (!m_scriptObject) { - m_showAfterVisible = TimelinePanel; - return; - } - - callSimpleFunction(m_scriptContext, m_scriptObject, "showTimeline"); -} - -void InspectorController::close() -{ - if (!enabled()) - return; - - m_client->closeWindow(); - if (m_page) - m_page->setParentInspectorController(0); - - ASSERT(m_scriptContext && m_scriptObject); - JSValueUnprotect(m_scriptContext, m_scriptObject); - - m_page = 0; - m_scriptObject = 0; - m_scriptContext = 0; -} - -static void addHeaders(JSContextRef context, JSObjectRef object, const HTTPHeaderMap& headers) -{ - ASSERT_ARG(context, context); - ASSERT_ARG(object, object); - - HTTPHeaderMap::const_iterator end = headers.end(); - for (HTTPHeaderMap::const_iterator it = headers.begin(); it != end; ++it) { - JSRetainPtr field(Adopt, JSStringCreateWithCharacters(it->first.characters(), it->first.length())); - JSRetainPtr valueString(Adopt, JSStringCreateWithCharacters(it->second.characters(), it->second.length())); - JSValueRef value = JSValueMakeString(context, valueString.get()); - JSObjectSetProperty(context, object, field.get(), value, kJSPropertyAttributeNone, 0); - } -} - -static JSObjectRef scriptObjectForRequest(JSContextRef context, const InspectorResource* resource) -{ - ASSERT_ARG(context, context); - - JSObjectRef object = JSObjectMake(context, 0, 0); - addHeaders(context, object, resource->requestHeaderFields); - - return object; -} - -static JSObjectRef scriptObjectForResponse(JSContextRef context, const InspectorResource* resource) -{ - ASSERT_ARG(context, context); - - JSObjectRef object = JSObjectMake(context, 0, 0); - addHeaders(context, object, resource->responseHeaderFields); - - return object; -} - -JSObjectRef InspectorController::addScriptResource(InspectorResource* resource) -{ - ASSERT_ARG(resource, resource); - - ASSERT(m_scriptContext); - ASSERT(m_scriptObject); - if (!m_scriptContext || !m_scriptObject) - return 0; - - if (!resource->scriptObject) { - JSRetainPtr resourceString(Adopt, JSStringCreateWithUTF8CString("Resource")); - JSObjectRef resourceConstructor = JSValueToObject(m_scriptContext, JSObjectGetProperty(m_scriptContext, m_scriptObject, resourceString.get(), 0), 0); - - String urlString = resource->requestURL.string(); - JSRetainPtr url(Adopt, JSStringCreateWithCharacters(urlString.characters(), urlString.length())); - JSValueRef urlValue = JSValueMakeString(m_scriptContext, url.get()); - - urlString = resource->requestURL.host(); - JSRetainPtr domain(Adopt, JSStringCreateWithCharacters(urlString.characters(), urlString.length())); - JSValueRef domainValue = JSValueMakeString(m_scriptContext, domain.get()); - - urlString = resource->requestURL.path(); - JSRetainPtr path(Adopt, JSStringCreateWithCharacters(urlString.characters(), urlString.length())); - JSValueRef pathValue = JSValueMakeString(m_scriptContext, path.get()); - - urlString = resource->requestURL.lastPathComponent(); - JSRetainPtr lastPathComponent(Adopt, JSStringCreateWithCharacters(urlString.characters(), urlString.length())); - JSValueRef lastPathComponentValue = JSValueMakeString(m_scriptContext, lastPathComponent.get()); - - JSValueRef identifier = JSValueMakeNumber(m_scriptContext, resource->identifier); - JSValueRef mainResource = JSValueMakeBoolean(m_scriptContext, m_mainResource == resource); - JSValueRef cached = JSValueMakeBoolean(m_scriptContext, resource->cached); - - JSValueRef arguments[] = { scriptObjectForRequest(m_scriptContext, resource), urlValue, domainValue, pathValue, lastPathComponentValue, identifier, mainResource, cached }; - JSObjectRef result = JSObjectCallAsConstructor(m_scriptContext, resourceConstructor, 8, arguments, 0); - ASSERT(result); - - resource->setScriptObject(m_scriptContext, result); - } - - JSRetainPtr addResourceString(Adopt, JSStringCreateWithUTF8CString("addResource")); - JSObjectRef addResourceFunction = JSValueToObject(m_scriptContext, JSObjectGetProperty(m_scriptContext, m_scriptObject, addResourceString.get(), 0), 0); - - JSValueRef addArguments[] = { resource->scriptObject }; - JSObjectCallAsFunction(m_scriptContext, addResourceFunction, m_scriptObject, 1, addArguments, 0); - - return resource->scriptObject; -} - -JSObjectRef InspectorController::addAndUpdateScriptResource(InspectorResource* resource) -{ - ASSERT_ARG(resource, resource); - - JSObjectRef scriptResource = addScriptResource(resource); - updateScriptResourceResponse(resource); - updateScriptResource(resource, resource->length); - updateScriptResource(resource, resource->startTime, resource->responseReceivedTime, resource->endTime); - updateScriptResource(resource, resource->finished, resource->failed); - return scriptResource; -} - -void InspectorController::removeScriptResource(InspectorResource* resource) -{ - ASSERT(m_scriptContext); - ASSERT(m_scriptObject); - if (!m_scriptContext || !m_scriptObject) - return; - - ASSERT(resource); - ASSERT(resource->scriptObject); - if (!resource || !resource->scriptObject) - return; - - JSRetainPtr removeResourceString(Adopt, JSStringCreateWithUTF8CString("removeResource")); - JSObjectRef removeResourceFunction = JSValueToObject(m_scriptContext, JSObjectGetProperty(m_scriptContext, m_scriptObject, removeResourceString.get(), 0), 0); - - JSValueRef arguments[] = { resource->scriptObject }; - JSObjectCallAsFunction(m_scriptContext, removeResourceFunction, m_scriptObject, 1, arguments, 0); - - resource->setScriptObject(0, 0); -} - -static void updateResourceRequest(InspectorResource* resource, const ResourceRequest& request) -{ - resource->requestHeaderFields = request.httpHeaderFields(); - resource->requestURL = request.url(); -} - -static void updateResourceResponse(InspectorResource* resource, const ResourceResponse& response) -{ - resource->expectedContentLength = response.expectedContentLength(); - resource->mimeType = response.mimeType(); - resource->responseHeaderFields = response.httpHeaderFields(); - resource->responseStatusCode = response.httpStatusCode(); - resource->suggestedFilename = response.suggestedFilename(); -} - -void InspectorController::updateScriptResourceRequest(InspectorResource* resource) -{ - ASSERT(resource->scriptObject); - ASSERT(m_scriptContext); - if (!resource->scriptObject || !m_scriptContext) - return; - - String urlString = resource->requestURL.string(); - JSRetainPtr url(Adopt, JSStringCreateWithCharacters(urlString.characters(), urlString.length())); - JSValueRef urlValue = JSValueMakeString(m_scriptContext, url.get()); - - urlString = resource->requestURL.host(); - JSRetainPtr domain(Adopt, JSStringCreateWithCharacters(urlString.characters(), urlString.length())); - JSValueRef domainValue = JSValueMakeString(m_scriptContext, domain.get()); - - urlString = resource->requestURL.path(); - JSRetainPtr path(Adopt, JSStringCreateWithCharacters(urlString.characters(), urlString.length())); - JSValueRef pathValue = JSValueMakeString(m_scriptContext, path.get()); - - urlString = resource->requestURL.lastPathComponent(); - JSRetainPtr lastPathComponent(Adopt, JSStringCreateWithCharacters(urlString.characters(), urlString.length())); - JSValueRef lastPathComponentValue = JSValueMakeString(m_scriptContext, lastPathComponent.get()); - - JSValueRef mainResourceValue = JSValueMakeBoolean(m_scriptContext, m_mainResource == resource); - - JSRetainPtr propertyName(Adopt, JSStringCreateWithUTF8CString("url")); - JSObjectSetProperty(m_scriptContext, resource->scriptObject, propertyName.get(), urlValue, kJSPropertyAttributeNone, 0); - - propertyName.adopt(JSStringCreateWithUTF8CString("domain")); - JSObjectSetProperty(m_scriptContext, resource->scriptObject, propertyName.get(), domainValue, kJSPropertyAttributeNone, 0); - - propertyName.adopt(JSStringCreateWithUTF8CString("path")); - JSObjectSetProperty(m_scriptContext, resource->scriptObject, propertyName.get(), pathValue, kJSPropertyAttributeNone, 0); - - propertyName.adopt(JSStringCreateWithUTF8CString("lastPathComponent")); - JSObjectSetProperty(m_scriptContext, resource->scriptObject, propertyName.get(), lastPathComponentValue, kJSPropertyAttributeNone, 0); - - propertyName.adopt(JSStringCreateWithUTF8CString("requestHeaders")); - JSObjectSetProperty(m_scriptContext, resource->scriptObject, propertyName.get(), scriptObjectForRequest(m_scriptContext, resource), kJSPropertyAttributeNone, 0); - - propertyName.adopt(JSStringCreateWithUTF8CString("mainResource")); - JSObjectSetProperty(m_scriptContext, resource->scriptObject, propertyName.get(), mainResourceValue, kJSPropertyAttributeNone, 0); -} - -void InspectorController::updateScriptResourceResponse(InspectorResource* resource) -{ - ASSERT(resource->scriptObject); - ASSERT(m_scriptContext); - if (!resource->scriptObject || !m_scriptContext) - return; - - JSRetainPtr mimeType(Adopt, JSStringCreateWithCharacters(resource->mimeType.characters(), resource->mimeType.length())); - JSValueRef mimeTypeValue = JSValueMakeString(m_scriptContext, mimeType.get()); - - JSRetainPtr suggestedFilename(Adopt, JSStringCreateWithCharacters(resource->suggestedFilename.characters(), resource->suggestedFilename.length())); - JSValueRef suggestedFilenameValue = JSValueMakeString(m_scriptContext, suggestedFilename.get()); - - JSValueRef expectedContentLengthValue = JSValueMakeNumber(m_scriptContext, static_cast(resource->expectedContentLength)); - JSValueRef statusCodeValue = JSValueMakeNumber(m_scriptContext, resource->responseStatusCode); - - JSRetainPtr propertyName(Adopt, JSStringCreateWithUTF8CString("mimeType")); - JSObjectSetProperty(m_scriptContext, resource->scriptObject, propertyName.get(), mimeTypeValue, kJSPropertyAttributeNone, 0); - - propertyName.adopt(JSStringCreateWithUTF8CString("suggestedFilename")); - JSObjectSetProperty(m_scriptContext, resource->scriptObject, propertyName.get(), suggestedFilenameValue, kJSPropertyAttributeNone, 0); - - propertyName.adopt(JSStringCreateWithUTF8CString("expectedContentLength")); - JSObjectSetProperty(m_scriptContext, resource->scriptObject, propertyName.get(), expectedContentLengthValue, kJSPropertyAttributeNone, 0); - - propertyName.adopt(JSStringCreateWithUTF8CString("statusCode")); - JSObjectSetProperty(m_scriptContext, resource->scriptObject, propertyName.get(), statusCodeValue, kJSPropertyAttributeNone, 0); - - propertyName.adopt(JSStringCreateWithUTF8CString("responseHeaders")); - JSObjectSetProperty(m_scriptContext, resource->scriptObject, propertyName.get(), scriptObjectForResponse(m_scriptContext, resource), kJSPropertyAttributeNone, 0); - - JSValueRef typeValue = JSValueMakeNumber(m_scriptContext, resource->type()); - propertyName.adopt(JSStringCreateWithUTF8CString("type")); - JSObjectSetProperty(m_scriptContext, resource->scriptObject, propertyName.get(), typeValue, kJSPropertyAttributeNone, 0); -} - -void InspectorController::updateScriptResource(InspectorResource* resource, int length) -{ - ASSERT(resource->scriptObject); - ASSERT(m_scriptContext); - if (!resource->scriptObject || !m_scriptContext) - return; - - JSValueRef lengthValue = JSValueMakeNumber(m_scriptContext, length); - - JSRetainPtr propertyName(Adopt, JSStringCreateWithUTF8CString("contentLength")); - JSObjectSetProperty(m_scriptContext, resource->scriptObject, propertyName.get(), lengthValue, kJSPropertyAttributeNone, 0); -} - -void InspectorController::updateScriptResource(InspectorResource* resource, bool finished, bool failed) -{ - ASSERT(resource->scriptObject); - ASSERT(m_scriptContext); - if (!resource->scriptObject || !m_scriptContext) - return; - - JSValueRef failedValue = JSValueMakeBoolean(m_scriptContext, failed); - JSValueRef finishedValue = JSValueMakeBoolean(m_scriptContext, finished); - - JSRetainPtr propertyName(Adopt, JSStringCreateWithUTF8CString("failed")); - JSObjectSetProperty(m_scriptContext, resource->scriptObject, propertyName.get(), failedValue, kJSPropertyAttributeNone, 0); - - propertyName.adopt(JSStringCreateWithUTF8CString("finished")); - JSObjectSetProperty(m_scriptContext, resource->scriptObject, propertyName.get(), finishedValue, kJSPropertyAttributeNone, 0); -} - -void InspectorController::updateScriptResource(InspectorResource* resource, double startTime, double responseReceivedTime, double endTime) -{ - ASSERT(resource->scriptObject); - ASSERT(m_scriptContext); - if (!resource->scriptObject || !m_scriptContext) - return; - - JSValueRef startTimeValue = JSValueMakeNumber(m_scriptContext, startTime); - JSValueRef responseReceivedTimeValue = JSValueMakeNumber(m_scriptContext, responseReceivedTime); - JSValueRef endTimeValue = JSValueMakeNumber(m_scriptContext, endTime); - - JSRetainPtr propertyName(Adopt, JSStringCreateWithUTF8CString("startTime")); - JSObjectSetProperty(m_scriptContext, resource->scriptObject, propertyName.get(), startTimeValue, kJSPropertyAttributeNone, 0); - - propertyName.adopt(JSStringCreateWithUTF8CString("responseReceivedTime")); - JSObjectSetProperty(m_scriptContext, resource->scriptObject, propertyName.get(), responseReceivedTimeValue, kJSPropertyAttributeNone, 0); - - propertyName.adopt(JSStringCreateWithUTF8CString("endTime")); - JSObjectSetProperty(m_scriptContext, resource->scriptObject, propertyName.get(), endTimeValue, kJSPropertyAttributeNone, 0); -} - -void InspectorController::populateScriptResources() -{ - ASSERT(m_scriptContext); - if (!m_scriptContext) - return; - - clearScriptResources(); - clearScriptConsoleMessages(); - clearDatabaseScriptResources(); - clearNetworkTimeline(); - - ResourcesMap::iterator resourcesEnd = m_resources.end(); - for (ResourcesMap::iterator it = m_resources.begin(); it != resourcesEnd; ++it) - addAndUpdateScriptResource(it->second.get()); - - unsigned messageCount = m_consoleMessages.size(); - for (unsigned i = 0; i < messageCount; ++i) - addScriptConsoleMessage(m_consoleMessages[i]); - -#if ENABLE(DATABASE) - DatabaseResourcesSet::iterator databasesEnd = m_databaseResources.end(); - for (DatabaseResourcesSet::iterator it = m_databaseResources.begin(); it != databasesEnd; ++it) - addDatabaseScriptResource((*it).get()); -#endif -} - -#if ENABLE(DATABASE) -JSObjectRef InspectorController::addDatabaseScriptResource(InspectorDatabaseResource* resource) -{ - ASSERT_ARG(resource, resource); - - if (resource->scriptObject) - return resource->scriptObject; - - ASSERT(m_scriptContext); - ASSERT(m_scriptObject); - if (!m_scriptContext || !m_scriptObject) - return 0; - - JSRetainPtr databaseString(Adopt, JSStringCreateWithUTF8CString("Database")); - JSObjectRef databaseConstructor = JSValueToObject(m_scriptContext, JSObjectGetProperty(m_scriptContext, m_scriptObject, databaseString.get(), 0), 0); - - JSValueRef database; - - { - KJS::JSLock lock; - database = toRef(toJS(toJS(m_scriptContext), resource->database.get())); - } - - JSRetainPtr domain(Adopt, JSStringCreateWithCharacters(resource->domain.characters(), resource->domain.length())); - JSValueRef domainValue = JSValueMakeString(m_scriptContext, domain.get()); - - JSRetainPtr name(Adopt, JSStringCreateWithCharacters(resource->name.characters(), resource->name.length())); - JSValueRef nameValue = JSValueMakeString(m_scriptContext, name.get()); - - JSRetainPtr version(Adopt, JSStringCreateWithCharacters(resource->version.characters(), resource->version.length())); - JSValueRef versionValue = JSValueMakeString(m_scriptContext, version.get()); - - JSValueRef arguments[] = { database, domainValue, nameValue, versionValue }; - JSObjectRef result = JSObjectCallAsConstructor(m_scriptContext, databaseConstructor, 4, arguments, 0); - - resource->setScriptObject(m_scriptContext, result); - - ASSERT(result); - - JSRetainPtr addResourceString(Adopt, JSStringCreateWithUTF8CString("addResource")); - JSObjectRef addResourceFunction = JSValueToObject(m_scriptContext, JSObjectGetProperty(m_scriptContext, m_scriptObject, addResourceString.get(), 0), 0); - - JSValueRef addArguments[] = { result }; - JSObjectCallAsFunction(m_scriptContext, addResourceFunction, m_scriptObject, 1, addArguments, 0); - - return result; -} - -void InspectorController::removeDatabaseScriptResource(InspectorDatabaseResource* resource) -{ - ASSERT(m_scriptContext); - ASSERT(m_scriptObject); - if (!m_scriptContext || !m_scriptObject) - return; - - ASSERT(resource); - ASSERT(resource->scriptObject); - if (!resource || !resource->scriptObject) - return; - - JSRetainPtr removeResourceString(Adopt, JSStringCreateWithUTF8CString("removeResource")); - JSObjectRef removeResourceFunction = JSValueToObject(m_scriptContext, JSObjectGetProperty(m_scriptContext, m_scriptObject, removeResourceString.get(), 0), 0); - - JSValueRef arguments[] = { resource->scriptObject }; - JSObjectCallAsFunction(m_scriptContext, removeResourceFunction, m_scriptObject, 1, arguments, 0); - - resource->setScriptObject(0, 0); -} -#endif - -void InspectorController::addScriptConsoleMessage(const ConsoleMessage* message) -{ - ASSERT_ARG(message, message); - - JSRetainPtr messageConstructorString(Adopt, JSStringCreateWithUTF8CString("ConsoleMessage")); - JSObjectRef messageConstructor = JSValueToObject(m_scriptContext, JSObjectGetProperty(m_scriptContext, m_scriptObject, messageConstructorString.get(), 0), 0); - - JSRetainPtr addMessageString(Adopt, JSStringCreateWithUTF8CString("addMessageToConsole")); - JSObjectRef addMessage = JSValueToObject(m_scriptContext, JSObjectGetProperty(m_scriptContext, m_scriptObject, addMessageString.get(), 0), 0); - - JSValueRef sourceValue = JSValueMakeNumber(m_scriptContext, message->source); - JSValueRef levelValue = JSValueMakeNumber(m_scriptContext, message->level); - JSRetainPtr messageString(Adopt, JSStringCreateWithCharacters(message->message.characters(), message->message.length())); - JSValueRef messageValue = JSValueMakeString(m_scriptContext, messageString.get()); - JSValueRef lineValue = JSValueMakeNumber(m_scriptContext, message->line); - JSRetainPtr urlString(Adopt, JSStringCreateWithCharacters(message->url.characters(), message->url.length())); - JSValueRef urlValue = JSValueMakeString(m_scriptContext, urlString.get()); - - JSValueRef args[] = { sourceValue, levelValue, messageValue, lineValue, urlValue }; - JSObjectRef messageObject = JSObjectCallAsConstructor(m_scriptContext, messageConstructor, 5, args, 0); - - JSObjectCallAsFunction(m_scriptContext, addMessage, m_scriptObject, 1, &messageObject, 0); -} - -void InspectorController::clearScriptResources() -{ - if (!m_scriptContext || !m_scriptObject) - return; - - ResourcesMap::iterator resourcesEnd = m_resources.end(); - for (ResourcesMap::iterator it = m_resources.begin(); it != resourcesEnd; ++it) { - InspectorResource* resource = it->second.get(); - resource->setScriptObject(0, 0); - } - - callSimpleFunction(m_scriptContext, m_scriptObject, "clearResources"); -} - -void InspectorController::clearDatabaseScriptResources() -{ -#if ENABLE(DATABASE) - if (!m_scriptContext || !m_scriptObject) - return; - - DatabaseResourcesSet::iterator databasesEnd = m_databaseResources.end(); - for (DatabaseResourcesSet::iterator it = m_databaseResources.begin(); it != databasesEnd; ++it) { - InspectorDatabaseResource* resource = (*it).get(); - resource->setScriptObject(0, 0); - } - - callSimpleFunction(m_scriptContext, m_scriptObject, "clearDatabaseResources"); -#endif -} - -void InspectorController::clearScriptConsoleMessages() -{ - if (!m_scriptContext || !m_scriptObject) - return; - - callSimpleFunction(m_scriptContext, m_scriptObject, "clearConsoleMessages"); -} - -void InspectorController::clearNetworkTimeline() -{ - if (!m_scriptContext || !m_scriptObject) - return; - - callSimpleFunction(m_scriptContext, m_scriptObject, "clearNetworkTimeline"); -} - -void InspectorController::pruneResources(ResourcesMap* resourceMap, DocumentLoader* loaderToKeep) -{ - ASSERT_ARG(resourceMap, resourceMap); - - ResourcesMap mapCopy(*resourceMap); - ResourcesMap::iterator end = mapCopy.end(); - for (ResourcesMap::iterator it = mapCopy.begin(); it != end; ++it) { - InspectorResource* resource = (*it).second.get(); - if (resource == m_mainResource) - continue; - - if (!loaderToKeep || resource->loader != loaderToKeep) { - removeResource(resource); - if (windowVisible() && resource->scriptObject) - removeScriptResource(resource); - } - } -} - -void InspectorController::didCommitLoad(DocumentLoader* loader) -{ - if (!enabled()) - return; - - if (loader->frame() == m_inspectedPage->mainFrame()) { - m_client->inspectedURLChanged(loader->url().string()); - - deleteAllValues(m_consoleMessages); - m_consoleMessages.clear(); - -#if ENABLE(DATABASE) - m_databaseResources.clear(); -#endif - - if (windowVisible()) { - clearScriptConsoleMessages(); -#if ENABLE(DATABASE) - clearDatabaseScriptResources(); -#endif - clearNetworkTimeline(); - - if (!loader->isLoadingFromCachedPage()) { - ASSERT(m_mainResource && m_mainResource->loader == loader); - // We don't add the main resource until its load is committed. This is - // needed to keep the load for a user-entered URL from showing up in the - // list of resources for the page they are navigating away from. - addAndUpdateScriptResource(m_mainResource.get()); - } else { - // Pages loaded from the page cache are committed before - // m_mainResource is the right resource for this load, so we - // clear it here. It will be re-assigned in - // identifierForInitialRequest. - m_mainResource = 0; - } - } - } - - for (Frame* frame = loader->frame(); frame; frame = frame->tree()->traverseNext(loader->frame())) - if (ResourcesMap* resourceMap = m_frameResources.get(frame)) - pruneResources(resourceMap, loader); -} - -void InspectorController::frameDetachedFromParent(Frame* frame) -{ - if (!enabled()) - return; - if (ResourcesMap* resourceMap = m_frameResources.get(frame)) - removeAllResources(resourceMap); -} - -void InspectorController::addResource(InspectorResource* resource) -{ - m_resources.set(resource->identifier, resource); - - Frame* frame = resource->frame.get(); - ResourcesMap* resourceMap = m_frameResources.get(frame); - if (resourceMap) - resourceMap->set(resource->identifier, resource); - else { - resourceMap = new ResourcesMap; - resourceMap->set(resource->identifier, resource); - m_frameResources.set(frame, resourceMap); - } -} - -void InspectorController::removeResource(InspectorResource* resource) -{ - m_resources.remove(resource->identifier); - - Frame* frame = resource->frame.get(); - ResourcesMap* resourceMap = m_frameResources.get(frame); - if (!resourceMap) { - ASSERT_NOT_REACHED(); - return; - } - - resourceMap->remove(resource->identifier); - if (resourceMap->isEmpty()) { - m_frameResources.remove(frame); - delete resourceMap; - } -} - -void InspectorController::didLoadResourceFromMemoryCache(DocumentLoader* loader, const ResourceRequest& request, const ResourceResponse& response, int length) -{ - if (!enabled()) - return; - - InspectorResource* resource = new InspectorResource(m_nextIdentifier--, loader, loader->frame()); - resource->finished = true; - - updateResourceRequest(resource, request); - updateResourceResponse(resource, response); - - resource->length = length; - resource->cached = true; - resource->startTime = currentTime(); - resource->responseReceivedTime = resource->startTime; - resource->endTime = resource->startTime; - - if (loader->frame() == m_inspectedPage->mainFrame() && request.url() == loader->requestURL()) - m_mainResource = resource; - - addResource(resource); - - if (windowVisible()) - addAndUpdateScriptResource(resource); -} - -void InspectorController::identifierForInitialRequest(unsigned long identifier, DocumentLoader* loader, const ResourceRequest& request) -{ - if (!enabled()) - return; - - InspectorResource* resource = new InspectorResource(identifier, loader, loader->frame()); - - updateResourceRequest(resource, request); - - if (loader->frame() == m_inspectedPage->mainFrame() && request.url() == loader->requestURL()) - m_mainResource = resource; - - addResource(resource); - - if (windowVisible() && loader->isLoadingFromCachedPage() && resource == m_mainResource) - addAndUpdateScriptResource(resource); -} - -void InspectorController::willSendRequest(DocumentLoader* loader, unsigned long identifier, ResourceRequest& request, const ResourceResponse& redirectResponse) -{ - if (!enabled()) - return; - - InspectorResource* resource = m_resources.get(identifier).get(); - if (!resource) - return; - - resource->startTime = currentTime(); - - if (!redirectResponse.isNull()) { - updateResourceRequest(resource, request); - updateResourceResponse(resource, redirectResponse); - } - - if (resource != m_mainResource && windowVisible()) { - if (!resource->scriptObject) - addScriptResource(resource); - else - updateScriptResourceRequest(resource); - - updateScriptResource(resource, resource->startTime, resource->responseReceivedTime, resource->endTime); - - if (!redirectResponse.isNull()) - updateScriptResourceResponse(resource); - } -} - -void InspectorController::didReceiveResponse(DocumentLoader*, unsigned long identifier, const ResourceResponse& response) -{ - if (!enabled()) - return; - - InspectorResource* resource = m_resources.get(identifier).get(); - if (!resource) - return; - - updateResourceResponse(resource, response); - - resource->responseReceivedTime = currentTime(); - - if (windowVisible() && resource->scriptObject) { - updateScriptResourceResponse(resource); - updateScriptResource(resource, resource->startTime, resource->responseReceivedTime, resource->endTime); - } -} - -void InspectorController::didReceiveContentLength(DocumentLoader*, unsigned long identifier, int lengthReceived) -{ - if (!enabled()) - return; - - InspectorResource* resource = m_resources.get(identifier).get(); - if (!resource) - return; - - resource->length += lengthReceived; - - if (windowVisible() && resource->scriptObject) - updateScriptResource(resource, resource->length); -} - -void InspectorController::didFinishLoading(DocumentLoader* loader, unsigned long identifier) -{ - if (!enabled()) - return; - - RefPtr resource = m_resources.get(identifier); - if (!resource) - return; - - removeResource(resource.get()); - - resource->finished = true; - resource->endTime = currentTime(); - - addResource(resource.get()); - - if (windowVisible() && resource->scriptObject) { - updateScriptResource(resource.get(), resource->startTime, resource->responseReceivedTime, resource->endTime); - updateScriptResource(resource.get(), resource->finished); - } -} - -void InspectorController::didFailLoading(DocumentLoader* loader, unsigned long identifier, const ResourceError& /*error*/) -{ - if (!enabled()) - return; - - RefPtr resource = m_resources.get(identifier); - if (!resource) - return; - - removeResource(resource.get()); - - resource->finished = true; - resource->failed = true; - resource->endTime = currentTime(); - - addResource(resource.get()); - - if (windowVisible() && resource->scriptObject) { - updateScriptResource(resource.get(), resource->startTime, resource->responseReceivedTime, resource->endTime); - updateScriptResource(resource.get(), resource->finished, resource->failed); - } -} - -#if ENABLE(DATABASE) -void InspectorController::didOpenDatabase(Database* database, const String& domain, const String& name, const String& version) -{ - if (!enabled()) - return; - - InspectorDatabaseResource* resource = new InspectorDatabaseResource(database, domain, name, version); - - m_databaseResources.add(resource); - - if (windowVisible()) - addDatabaseScriptResource(resource); -} -#endif - -void InspectorController::moveWindowBy(float x, float y) const -{ - if (!m_page || !enabled()) - return; - - FloatRect frameRect = m_page->chrome()->windowRect(); - frameRect.move(x, y); - m_page->chrome()->setWindowRect(frameRect); -} - -void InspectorController::drawNodeHighlight(GraphicsContext& context) const -{ - static const Color overlayFillColor(0, 0, 0, 128); - static const int outlineThickness = 1; - - if (!m_highlightedNode) - return; - - RenderObject* renderer = m_highlightedNode->renderer(); - if (!renderer) - return; - IntRect nodeRect(renderer->absoluteBoundingBoxRect()); - - Vector rects; - if (renderer->isInline() || (renderer->isText() && !m_highlightedNode->isSVGElement())) - renderer->addLineBoxRects(rects); - if (rects.isEmpty()) - rects.append(nodeRect); - - FrameView* view = m_inspectedPage->mainFrame()->view(); - FloatRect overlayRect = static_cast(view)->visibleContentRect(); - - if (!overlayRect.contains(nodeRect) && !nodeRect.contains(enclosingIntRect(overlayRect))) { - Element* element; - if (m_highlightedNode->isElementNode()) - element = static_cast(m_highlightedNode.get()); - else - element = static_cast(m_highlightedNode->parent()); - element->scrollIntoViewIfNeeded(); - overlayRect = static_cast(view)->visibleContentRect(); - } - - context.translate(-overlayRect.x(), -overlayRect.y()); - - // Draw translucent gray fill, out of which we will cut holes. - context.fillRect(overlayRect, overlayFillColor); - - // Draw white frames around holes in first pass, so they will be erased in - // places where holes overlap or abut. - for (size_t i = 0; i < rects.size(); ++i) { - IntRect rect = rects[i]; - rect.inflate(outlineThickness); - context.fillRect(rect, Color::white); - } - - // Erase holes in second pass. - for (size_t i = 0; i < rects.size(); ++i) - context.clearRect(rects[i]); -} - -} // namespace WebCore -- cgit v1.1