summaryrefslogtreecommitdiffstats
path: root/webkit
diff options
context:
space:
mode:
authorojan@google.com <ojan@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-11-26 01:13:43 +0000
committerojan@google.com <ojan@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-11-26 01:13:43 +0000
commit45abb0b369be7575b9e5b081ec405b4c0cfa6c2e (patch)
tree7a7f090a3fa8ff2ed043ea01c2a7ad3712e514d4 /webkit
parent665b38a69560c163bb8e90c6916341d2e8d2bd24 (diff)
downloadchromium_src-45abb0b369be7575b9e5b081ec405b4c0cfa6c2e.zip
chromium_src-45abb0b369be7575b9e5b081ec405b4c0cfa6c2e.tar.gz
chromium_src-45abb0b369be7575b9e5b081ec405b4c0cfa6c2e.tar.bz2
src/webkit side of webKit merge 38600:38625.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@6023 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r--webkit/build/V8Bindings/SConscript1
-rw-r--r--webkit/build/V8Bindings/V8Bindings.vcproj8
-rw-r--r--webkit/glue/webframe_impl.cc10
-rw-r--r--webkit/glue/webplugin_impl.cc17
-rw-r--r--webkit/port/bindings/v8/ScriptController.cpp39
-rw-r--r--webkit/port/bindings/v8/ScriptController.h11
-rw-r--r--webkit/port/bindings/v8/ScriptValue.cpp48
-rw-r--r--webkit/port/bindings/v8/ScriptValue.h79
-rw-r--r--webkit/webkit.xcodeproj/project.pbxproj6
9 files changed, 165 insertions, 54 deletions
diff --git a/webkit/build/V8Bindings/SConscript b/webkit/build/V8Bindings/SConscript
index 30b9083..afccfc7 100644
--- a/webkit/build/V8Bindings/SConscript
+++ b/webkit/build/V8Bindings/SConscript
@@ -329,6 +329,7 @@ inputs = [
'$PORT_DIR/bindings/v8/npruntime.cpp',
'$PORT_DIR/bindings/v8/RGBColor.cpp',
'$PORT_DIR/bindings/v8/ScriptCallContextV8.cpp',
+ '$PORT_DIR/bindings/v8/ScriptValue.cpp',
'$PORT_DIR/bindings/v8/v8_custom.cpp',
'$PORT_DIR/bindings/v8/v8_events.cpp',
'$PORT_DIR/bindings/v8/v8_helpers.cpp',
diff --git a/webkit/build/V8Bindings/V8Bindings.vcproj b/webkit/build/V8Bindings/V8Bindings.vcproj
index cb38118..28eb130 100644
--- a/webkit/build/V8Bindings/V8Bindings.vcproj
+++ b/webkit/build/V8Bindings/V8Bindings.vcproj
@@ -2521,6 +2521,14 @@
>
</File>
<File
+ RelativePath="..\..\port\bindings\v8\ScriptValue.cpp"
+ >
+ </File>
+ <File
+ RelativePath="..\..\port\bindings\v8\ScriptValue.h"
+ >
+ </File>
+ <File
RelativePath="..\..\port\bindings\v8\v8_binding.h"
>
</File>
diff --git a/webkit/glue/webframe_impl.cc b/webkit/glue/webframe_impl.cc
index e3f9d47..4058d76 100644
--- a/webkit/glue/webframe_impl.cc
+++ b/webkit/glue/webframe_impl.cc
@@ -106,6 +106,7 @@ MSVC_PUSH_WARNING_LEVEL(0);
#include "ResourceHandle.h"
#include "ResourceRequest.h"
#include "ScriptController.h"
+#include "ScriptValue.h"
#include "ScrollbarTheme.h"
#include "SelectionController.h"
#include "Settings.h"
@@ -349,13 +350,14 @@ void WebFrameImpl::InternalLoadRequest(const WebRequest* request,
// but will it change out from under us?
String script =
decodeURLEscapeSequences(kurl.string().substring(sizeof("javascript:")-1));
- bool succ = false;
- String value = frame_->loader()->executeScript(script, &succ, true);
- if (succ && !frame_->loader()->isScheduledLocationChangePending()) {
+ WebCore::ScriptValue result = frame_->loader()->executeScript(script, true);
+ String scriptResult;
+ if (result.getString(scriptResult) &&
+ !frame_->loader()->isScheduledLocationChangePending()) {
// TODO(darin): We need to figure out how to represent this in session
// history. Hint: don't re-eval script when the user or script navigates
// back-n-forth (instead store the script result somewhere).
- LoadDocumentData(kurl, value, String("text/html"), String());
+ LoadDocumentData(kurl, scriptResult, String("text/html"), String());
}
return;
}
diff --git a/webkit/glue/webplugin_impl.cc b/webkit/glue/webplugin_impl.cc
index 4d915cc..61d2587 100644
--- a/webkit/glue/webplugin_impl.cc
+++ b/webkit/glue/webplugin_impl.cc
@@ -36,6 +36,7 @@ MSVC_PUSH_WARNING_LEVEL(0);
#include "ResourceHandleClient.h"
#include "ResourceResponse.h"
#include "ScriptController.h"
+#include "ScriptValue.h"
#include "ScrollView.h"
#include "Widget.h"
MSVC_POP_WARNING();
@@ -357,18 +358,20 @@ bool WebPluginImpl::ExecuteScript(const std::string& url,
// we also need to addref the frame.
WTF::RefPtr<WebCore::Frame> cur_frame(frame());
+ WebCore::ScriptValue result =
+ frame()->loader()->executeScript(script_str, popups_allowed);
+ WebCore::String script_result;
+ std::wstring wresult;
bool succ = false;
- WebCore::String result_str = frame()->loader()->executeScript(script_str,
- &succ,
- popups_allowed);
- std::wstring result;
- if (succ)
- result = webkit_glue::StringToStdWString(result_str);
+ if (result.getString(script_result)) {
+ succ = true;
+ wresult = webkit_glue::StringToStdWString(script_result);
+ }
// delegate_ could be NULL because executeScript caused the container to be
// deleted.
if (delegate_)
- delegate_->SendJavaScriptStream(url, result, succ, notify_needed,
+ delegate_->SendJavaScriptStream(url, wresult, succ, notify_needed,
notify_data);
return succ;
diff --git a/webkit/port/bindings/v8/ScriptController.cpp b/webkit/port/bindings/v8/ScriptController.cpp
index b9ab314..0086459 100644
--- a/webkit/port/bindings/v8/ScriptController.cpp
+++ b/webkit/port/bindings/v8/ScriptController.cpp
@@ -263,17 +263,16 @@ bool ScriptController::processingUserGesture() const
// Evaluate a script file in the environment of this proxy.
-String ScriptController::evaluate(const String& filename, int baseLine,
+ScriptValue ScriptController::evaluate(const String& filename, int baseLine,
const String& code, Node* node, bool* succ)
{
if (succ)
*succ = false;
- String result;
v8::HandleScope hs;
v8::Handle<v8::Context> context = V8Proxy::GetContext(m_proxy->frame());
if (context.IsEmpty())
- return result;
+ return ScriptValue();
v8::Context::Scope scope(context);
@@ -284,42 +283,12 @@ String ScriptController::evaluate(const String& filename, int baseLine,
node);
if (obj.IsEmpty() || obj->IsUndefined())
- return result;
-
- // If the return value is not a string, return 0 (what KJS does).
- if (!obj->IsString()) {
- v8::TryCatch exception_block;
- obj = obj->ToString();
- if (exception_block.HasCaught())
- obj = v8::String::New("");
- }
+ return ScriptValue();
- result = ToWebCoreString(obj);
if (succ)
*succ = true;
- return result;
-}
-
-v8::Persistent<v8::Value> ScriptController::evaluate(const String& filename,
- int baseLine,
- const String& code,
- Node* node)
-{
- v8::HandleScope hs;
- v8::Handle<v8::Context> context = V8Proxy::GetContext(m_proxy->frame());
- if (context.IsEmpty())
- return v8::Persistent<v8::Value>();
-
- v8::Context::Scope scope(context);
-
- v8::Local<v8::Value> obj = m_proxy->Evaluate(filename, baseLine, code, node);
-
- if (obj.IsEmpty())
- return v8::Persistent<v8::Value>();
-
- // TODO(fqian): keep track the global handle created.
- return v8::Persistent<v8::Value>::New(obj);
+ return ScriptValue(obj);
}
void ScriptController::disposeJSResult(v8::Persistent<v8::Value> result)
diff --git a/webkit/port/bindings/v8/ScriptController.h b/webkit/port/bindings/v8/ScriptController.h
index da87bf6..71954f1 100644
--- a/webkit/port/bindings/v8/ScriptController.h
+++ b/webkit/port/bindings/v8/ScriptController.h
@@ -35,6 +35,7 @@
#include "HashMap.h"
#include "MessagePort.h"
+#include "ScriptValue.h"
#include "SecurityOrigin.h"
#include "bindings/npruntime.h"
@@ -147,14 +148,8 @@ public:
// Evaluate a script file in the environment of this proxy.
// If succeeded, 'succ' is set to true and result is returned
// as a string.
- String evaluate(const String& filename, int baseLine, const String& code, Node* node = NULL, bool* succ = NULL);
-
- // Second API function for evaluating a JS code.
- // It returns a JSResult which must be disposed by calling
- // disposeJSResult. If the result is not disposed, it can cause
- // serious memory leak. The caller determines whether the evaluation
- // is successful by checking the value of JSResult.
- JSResult evaluate(const String& filename, int baseLine, const String& code, Node*);
+ ScriptValue evaluate(const String& filename, int baseLine, const String& code, Node* node = NULL, bool* succ = NULL);
+
void disposeJSResult(JSResult result);
void collectGarbage();
diff --git a/webkit/port/bindings/v8/ScriptValue.cpp b/webkit/port/bindings/v8/ScriptValue.cpp
new file mode 100644
index 0000000..b6c105d
--- /dev/null
+++ b/webkit/port/bindings/v8/ScriptValue.cpp
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2006, 2007, 2008 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.
+ */
+
+#include "config.h"
+#include "ScriptValue.h"
+
+#include "v8_binding.h"
+
+namespace WebCore {
+
+bool ScriptValue::getString(String& result) const
+{
+ if (m_value.IsEmpty())
+ return false;
+
+ if (!m_value->IsString())
+ return false;
+
+ result = ToWebCoreString(m_value);
+ return true;
+}
+
+} // namespace WebCore
diff --git a/webkit/port/bindings/v8/ScriptValue.h b/webkit/port/bindings/v8/ScriptValue.h
new file mode 100644
index 0000000..664858f
--- /dev/null
+++ b/webkit/port/bindings/v8/ScriptValue.h
@@ -0,0 +1,79 @@
+/*
+ * Copyright (c) 2008, Google 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:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * 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.
+ * * Neither the name of Google Inc. 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 THE COPYRIGHT HOLDERS AND 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 THE COPYRIGHT
+ * OWNER OR 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.
+ */
+
+#ifndef ScriptValue_h
+#define ScriptValue_h
+
+#include "v8.h"
+
+namespace WebCore {
+
+class String;
+
+class ScriptValue {
+public:
+ ScriptValue() {}
+
+ ScriptValue(v8::Handle<v8::Value> value)
+ {
+ m_value = v8::Persistent<v8::Value>::New(value);
+ }
+
+ ScriptValue(const ScriptValue& value)
+ {
+ m_value = v8::Persistent<v8::Value>::New(value.m_value);
+ }
+
+ ScriptValue& operator=(const ScriptValue& value)
+ {
+ if (this == &value)
+ return *this;
+
+ m_value.Dispose();
+ m_value = v8::Persistent<v8::Value>::New(value.m_value);
+ return *this;
+ }
+
+ ~ScriptValue()
+ {
+ m_value.Dispose();
+ m_value.Clear();
+ }
+
+ bool getString(String& result) const;
+
+private:
+ mutable v8::Persistent<v8::Value> m_value;
+};
+
+} // namespace WebCore
+
+#endif // ScriptValue_h
diff --git a/webkit/webkit.xcodeproj/project.pbxproj b/webkit/webkit.xcodeproj/project.pbxproj
index 854eef7..63b1a17 100644
--- a/webkit/webkit.xcodeproj/project.pbxproj
+++ b/webkit/webkit.xcodeproj/project.pbxproj
@@ -459,6 +459,7 @@
82F14D610ED230E700B36428 /* webcursor_mac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 82F14D600ED230E700B36428 /* webcursor_mac.mm */; };
934CC0040EBFE0E000A658F2 /* chromium_bridge_impl.cc in Sources */ = {isa = PBXBuildFile; fileRef = 934CC0030EBFE0E000A658F2 /* chromium_bridge_impl.cc */; };
934CC2280EDCC37600A658F2 /* RGBColor.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 934CC2270EDCC37600A658F2 /* RGBColor.cpp */; };
+ 934CC3590EDCCEFE00A658F2 /* ScriptValue.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 934CC3570EDCCEFE00A658F2 /* ScriptValue.cpp */; };
93BF8E990EA6B0E50030F05C /* AuthenticationChallengeChromium.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 93BF8E600EA6AED30030F05C /* AuthenticationChallengeChromium.cpp */; };
93BF8E9A0EA6B0EA0030F05C /* CookieJarChromium.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 93BF8E610EA6AED30030F05C /* CookieJarChromium.cpp */; };
93BF8E9B0EA6B0EF0030F05C /* DNSChromium.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 93BF8E620EA6AED30030F05C /* DNSChromium.cpp */; };
@@ -3967,6 +3968,8 @@
934CC0030EBFE0E000A658F2 /* chromium_bridge_impl.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = chromium_bridge_impl.cc; sourceTree = "<group>"; };
934CC2270EDCC37600A658F2 /* RGBColor.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RGBColor.cpp; sourceTree = "<group>"; };
934CC2290EDCC38400A658F2 /* RGBColor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RGBColor.h; sourceTree = "<group>"; };
+ 934CC3570EDCCEFE00A658F2 /* ScriptValue.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ScriptValue.cpp; sourceTree = "<group>"; };
+ 934CC3580EDCCEFE00A658F2 /* ScriptValue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScriptValue.h; sourceTree = "<group>"; };
93BF8E5F0EA6AED30030F05C /* AuthenticationChallenge.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AuthenticationChallenge.h; path = chromium/AuthenticationChallenge.h; sourceTree = "<group>"; };
93BF8E600EA6AED30030F05C /* AuthenticationChallengeChromium.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = AuthenticationChallengeChromium.cpp; path = chromium/AuthenticationChallengeChromium.cpp; sourceTree = "<group>"; };
93BF8E610EA6AED30030F05C /* CookieJarChromium.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CookieJarChromium.cpp; path = chromium/CookieJarChromium.cpp; sourceTree = "<group>"; };
@@ -4508,6 +4511,8 @@
E40063600EA907510055B38E /* ScriptCallContextV8.cpp */,
E40060D90EA69E0B0055B38E /* ScriptController.h */,
E40060DA0EA69E0B0055B38E /* ScriptController.cpp */,
+ 934CC3570EDCCEFE00A658F2 /* ScriptValue.cpp */,
+ 934CC3580EDCCEFE00A658F2 /* ScriptValue.h */,
7B0095DB0DAFF0DC00F72082 /* v8_binding.h */,
4DB7F5590E9BD66300C66CE0 /* v8_collection.h */,
7B0095DC0DAFF0DC00F72082 /* v8_custom.cpp */,
@@ -8153,6 +8158,7 @@
7B0095F30DAFF0DD00F72082 /* np_v8object.cpp in Sources */,
7B0095F50DAFF0DD00F72082 /* npruntime.cpp in Sources */,
934CC2280EDCC37600A658F2 /* RGBColor.cpp in Sources */,
+ 934CC3590EDCCEFE00A658F2 /* ScriptValue.cpp in Sources */,
7B0091390DAFEFBE00F72082 /* SVGElementFactory.cpp in Sources */,
7B00913B0DAFEFBE00F72082 /* SVGNames.cpp in Sources */,
7B00913E0DAFEFBE00F72082 /* UserAgentStyleSheetsData.cpp in Sources */,