Commit 70545d68 authored by timothy@apple.com's avatar timothy@apple.com

Make addSourceToFrame not dependent on InspectorResource so it

can be used to add source of a passed in string and mime-type to
a frame. Added addResourceSourceToFrame for use by SourceView.

Also fixes an assertion because of an incorrect static_cast of identifiers
to unsigned long long, when they can be unsigned.

Reviewed by Geoff Garen.

* page/InspectorController.cpp:
(WebCore::addSourceToFrame): Helper function used by addSourceToFrame
and addResourceSourceToFrame.
(WebCore::addSourceToFrame): Generalized to take a source and mime-type string.
(WebCore::addResourceSourceToFrame): Renamed from addSourceToFrame.
(WebCore::getResourceDocumentNode): Fixes the static_cast to be long long.
(WebCore::InspectorController::windowScriptObjectAvailable): Adds
addResourceSourceToFrame to the JavaScript class.
* page/inspector/SourceView.js: Use the new addResourceSourceToFrame.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@33406 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent c8a33e45
2008-05-13 Timothy Hatcher <timothy@apple.com>
Make addSourceToFrame not dependent on InspectorResource so it
can be used to add source of a passed in string and mime-type to
a frame. Added addResourceSourceToFrame for use by SourceView.
Also fixes an assertion because of an incorrect static_cast of identifiers
to unsigned long long, when they can be unsigned.
Reviewed by Geoff Garen.
* page/InspectorController.cpp:
(WebCore::addSourceToFrame): Helper function used by addSourceToFrame
and addResourceSourceToFrame.
(WebCore::addSourceToFrame): Generalized to take a source and mime-type string.
(WebCore::addResourceSourceToFrame): Renamed from addSourceToFrame.
(WebCore::getResourceDocumentNode): Fixes the static_cast to be long long.
(WebCore::InspectorController::windowScriptObjectAvailable): Adds
addResourceSourceToFrame to the JavaScript class.
* page/inspector/SourceView.js: Use the new addResourceSourceToFrame.
2008-05-13 Timothy Hatcher <timothy@apple.com>
Add debugger related functions to the InspectorController and
......@@ -383,7 +383,43 @@ private:
#pragma mark -
#pragma mark JavaScript Callbacks
static JSValueRef addSourceToFrame(JSContextRef ctx, JSObjectRef /*function*/, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
static bool addSourceToFrame(const String& mimeType, const String& source, Node* frameNode)
{
ASSERT_ARG(frameNode, frameNode);
if (!frameNode)
return false;
if (!frameNode->attached()) {
ASSERT_NOT_REACHED();
return false;
}
ASSERT(frameNode->isElementNode());
if (!frameNode->isElementNode())
return false;
Element* element = static_cast<Element*>(frameNode);
ASSERT(element->isFrameOwnerElement());
if (!element->isFrameOwnerElement())
return false;
HTMLFrameOwnerElement* frameOwner = static_cast<HTMLFrameOwnerElement*>(element);
ASSERT(frameOwner->contentFrame());
if (!frameOwner->contentFrame())
return false;
FrameLoader* loader = frameOwner->contentFrame()->loader();
loader->setResponseMIMEType(mimeType);
loader->begin();
loader->write(source);
loader->end();
return true;
}
static JSValueRef addResourceSourceToFrame(JSContextRef ctx, JSObjectRef /*function*/, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
JSValueRef undefined = JSValueMakeUndefined(ctx);
......@@ -395,7 +431,7 @@ static JSValueRef addSourceToFrame(JSContextRef ctx, JSObjectRef /*function*/, J
if (!JSValueIsNumber(ctx, identifierValue))
return undefined;
unsigned long identifier = static_cast<unsigned long>(JSValueToNumber(ctx, identifierValue, exception));
long long identifier = static_cast<long long>(JSValueToNumber(ctx, identifierValue, exception));
if (exception && *exception)
return undefined;
......@@ -408,36 +444,36 @@ static JSValueRef addSourceToFrame(JSContextRef ctx, JSObjectRef /*function*/, J
if (sourceString.isEmpty())
return undefined;
Node* node = toNode(toJS(arguments[1]));
ASSERT(node);
if (!node)
return undefined;
addSourceToFrame(resource->mimeType, sourceString, toNode(toJS(arguments[1])));
if (!node->attached()) {
ASSERT_NOT_REACHED();
return undefined;
}
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<InspectorController*>(JSObjectGetPrivate(thisObject));
if (argumentCount < 3 || !controller)
return undefined;
}
ASSERT(node->isElementNode());
if (!node->isElementNode())
JSValueRef mimeTypeValue = arguments[0];
if (!JSValueIsString(ctx, mimeTypeValue))
return undefined;
Element* element = static_cast<Element*>(node);
ASSERT(element->isFrameOwnerElement());
if (!element->isFrameOwnerElement())
JSValueRef sourceValue = arguments[1];
if (!JSValueIsString(ctx, sourceValue))
return undefined;
HTMLFrameOwnerElement* frameOwner = static_cast<HTMLFrameOwnerElement*>(element);
ASSERT(frameOwner->contentFrame());
if (!frameOwner->contentFrame())
String mimeType = toString(ctx, mimeTypeValue, exception);
if (mimeType.isEmpty())
return undefined;
FrameLoader* loader = frameOwner->contentFrame()->loader();
String source = toString(ctx, sourceValue, exception);
if (source.isEmpty())
return undefined;
loader->setResponseMIMEType(resource->mimeType);
loader->begin();
loader->write(sourceString);
loader->end();
addSourceToFrame(mimeType, source, toNode(toJS(arguments[2])));
return undefined;
}
......@@ -454,7 +490,7 @@ static JSValueRef getResourceDocumentNode(JSContextRef ctx, JSObjectRef /*functi
if (!JSValueIsNumber(ctx, identifierValue))
return undefined;
unsigned long identifier = static_cast<unsigned long>(JSValueToNumber(ctx, identifierValue, exception));
long long identifier = static_cast<long long>(JSValueToNumber(ctx, identifierValue, exception));
if (exception && *exception)
return undefined;
......@@ -1113,6 +1149,7 @@ void InspectorController::windowScriptObjectAvailable()
ASSERT(global);
static JSStaticFunction staticFunctions[] = {
{ "addResourceSourceToFrame", addResourceSourceToFrame, kJSPropertyAttributeNone },
{ "addSourceToFrame", addSourceToFrame, kJSPropertyAttributeNone },
{ "getResourceDocumentNode", getResourceDocumentNode, kJSPropertyAttributeNone },
{ "highlightDOMNode", highlightDOMNode, kJSPropertyAttributeNone },
......
......@@ -55,7 +55,7 @@ WebInspector.SourceView.prototype = {
this.attach();
InspectorController.addSourceToFrame(this.resource.identifier, this.frameElement);
InspectorController.addResourceSourceToFrame(this.resource.identifier, this.frameElement);
WebInspector.addMainEventListeners(this.frameElement.contentDocument);
var length = this.messages.length;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment