Permalink
Browse files

Added WebFrameLoadDelegate webView:foundUnknownScriptType:forFrame

This delegate method is invoked when a non-javascript script tag
is found while loading the frame. Used for evaluating python, ruby, php, etc.
  • Loading branch information...
1 parent 115b6bb commit 9db85970479f776f6840320d1df4118b039ff89f Josh Roesslein committed Feb 24, 2011
@@ -176,7 +176,8 @@ void ScriptElement::requestScript(const String& sourceUrl)
void ScriptElement::evaluateScript(const ScriptSourceCode& sourceCode)
{
- if (wasAlreadyStarted() || sourceCode.isEmpty() || !shouldExecuteAsJavaScript())
+ // TITANIUM: do not return if non-javascript.
+ if (wasAlreadyStarted() || sourceCode.isEmpty())
return;
RefPtr<Document> document = m_element->document();
@@ -194,7 +195,14 @@ void ScriptElement::evaluateScript(const ScriptSourceCode& sourceCode)
// Create a script from the script element node, using the script
// block's source and the script block's type.
// Note: This is where the script is compiled and actually executed.
- frame->script()->evaluate(sourceCode);
+ //
+ // TITANIUM: If the script is Javascript let WebKit evaluate it.
+ // Otherwise notify Titanium to evaluate the script if possible.
+ if (shouldExecuteAsJavaScript()) {
+ frame->script()->evaluate(sourceCode);
+ } else {
+ frame->loader()->foundUnknownScriptType(sourceCode.source());
+ }
}
Document::updateStyleForAllDocuments();
@@ -213,7 +221,12 @@ void ScriptElement::executeScript(const ScriptSourceCode& sourceCode)
m_wasAlreadyStarted = true;
- frame->script()->executeScript(sourceCode);
+ // TITANIUM: handle non-javascript scripts with our callback.
+ if (shouldExecuteAsJavaScript()) {
+ frame->script()->executeScript(sourceCode);
+ } else {
+ frame->loader()->foundUnknownScriptType(sourceCode.source());
+ }
}
void ScriptElement::stopLoadRequest()
@@ -292,8 +292,9 @@ void HTMLScriptRunner::runScript(Element* script, const TextPosition1& scriptSta
ScriptElement* scriptElement = toScriptElement(script);
ASSERT(scriptElement);
- if (!scriptElement->shouldExecuteAsJavaScript())
- return;
+ // TITANIUM: disable this otherwise non-javascript scripts never get executed.
+ /*if (!scriptElement->shouldExecuteAsJavaScript())
+ return;*/
if (script->hasAttribute(srcAttr)) {
if (script->hasAttribute(asyncAttr)) // Async takes precendence over defer.
@@ -373,6 +373,9 @@ class EmptyFrameLoaderClient : public FrameLoaderClient {
virtual void documentElementAvailable() { }
virtual void didPerformFirstNavigation() const { }
+ // TITANIUM
+ virtual void foundUnknownScriptType(const String&) { }
+
virtual void registerForIconNotification(bool) { }
#if USE(V8)
@@ -3382,6 +3382,12 @@ void FrameLoader::dispatchDidClearWindowObjectInWorld(DOMWrapperWorld* world)
InspectorInstrumentation::didClearWindowObjectInWorld(m_frame, world);
}
+// TITANIUM
+void FrameLoader::foundUnknownScriptType(const String& source)
+{
+ m_client->foundUnknownScriptType(source);
+}
+
void FrameLoader::updateSandboxFlags()
{
SandboxFlags flags = m_forcedSandboxFlags;
@@ -243,6 +243,9 @@ class FrameLoader {
void dispatchDidClearWindowObjectsInAllWorlds();
void dispatchDocumentElementAvailable();
+ // TITANIUM
+ void foundUnknownScriptType(const String& source);
+
void ownerElementSandboxFlagsChanged() { updateSandboxFlags(); }
bool isSandboxed(SandboxFlags mask) const { return m_sandboxFlags & mask; }
@@ -264,6 +264,9 @@ namespace WebCore {
virtual void documentElementAvailable() = 0;
virtual void didPerformFirstNavigation() const = 0; // "Navigation" here means a transition from one page to another that ends up in the back/forward list.
+ // TITANIUM
+ virtual void foundUnknownScriptType(const String& source) = 0;
+
#if USE(V8)
virtual void didCreateScriptContextForFrame() = 0;
virtual void didDestroyScriptContextForFrame() = 0;
@@ -221,6 +221,9 @@ class WebFrameLoaderClient : public WebCore::FrameLoaderClient {
virtual void documentElementAvailable();
virtual void didPerformFirstNavigation() const;
+ // TITANIUM
+ virtual void foundUnknownScriptType(const String& source);
+
virtual void registerForIconNotification(bool listen);
#if ENABLE(JAVA_BRIDGE)
@@ -1963,6 +1963,18 @@ virtual void notifyWidget(WidgetNotification notification)
[preferences setCacheModel:WebCacheModelDocumentBrowser];
}
+// TITANIUM
+void WebFrameLoaderClient::foundUnknownScriptType(const String& source)
+{
+ WebView* webView = getWebView(m_webFrame.get());
+ WebFrameLoadDelegateImplementationCache* implementations = WebViewGetFrameLoadDelegateImplementations(webView);
+
+ if (implementations->foundUnknownScriptTypeForFrameFunc) {
+ CallFrameLoadDelegate(implementations->foundUnknownScriptTypeForFrameFunc, webView, @selector(webView:foundUnknownScriptType:forFrame:),
+ (NSString *)source, m_webFrame.get());
+ }
+}
+
PassRefPtr<FrameNetworkingContext> WebFrameLoaderClient::createNetworkingContext()
{
return WebFrameNetworkingContext::create(core(m_webFrame.get()));
@@ -76,6 +76,7 @@ struct WebFrameLoadDelegateImplementationCache {
IMP didFinishDocumentLoadForFrameFunc;
IMP didDisplayInsecureContentFunc;
IMP didRunInsecureContentFunc;
+ IMP foundUnknownScriptTypeForFrameFunc;
};
struct WebScriptDebugDelegateImplementationCache {
@@ -1590,6 +1590,7 @@ - (void)_cacheFrameLoadDelegateImplementations
cache->windowScriptObjectAvailableFunc = getMethod(delegate, @selector(webView:windowScriptObjectAvailable:));
cache->didDisplayInsecureContentFunc = getMethod(delegate, @selector(webViewDidDisplayInsecureContent:));
cache->didRunInsecureContentFunc = getMethod(delegate, @selector(webView:didRunInsecureContent:));
+ cache->foundUnknownScriptTypeForFrameFunc = getMethod(delegate, @selector(webView:foundUnknownScriptType:forFrame:));
}
- (void)_cacheScriptDebugDelegateImplementations

0 comments on commit 9db8597

Please sign in to comment.