summaryrefslogtreecommitdiffstats
path: root/webkit/glue/npruntime_util.cc
diff options
context:
space:
mode:
authormichaeln@google.com <michaeln@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-22 23:00:09 +0000
committermichaeln@google.com <michaeln@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-22 23:00:09 +0000
commitcc21fb5b4e675a86c8862b934aa8e100643e75e4 (patch)
treef5055650bc147382260bc397f417560c6090812e /webkit/glue/npruntime_util.cc
parent5abb7f799f538318c702f0f26372b38464ab888a (diff)
downloadchromium_src-cc21fb5b4e675a86c8862b934aa8e100643e75e4.zip
chromium_src-cc21fb5b4e675a86c8862b934aa8e100643e75e4.tar.gz
chromium_src-cc21fb5b4e675a86c8862b934aa8e100643e75e4.tar.bz2
CPAPI gears drag drop and renderer IPC.
CPAPI (0.10) functions for gears drag drop; one to extract thedrag type/data given an NPObject *event, one to override thedrop effect (drag cursor). Gears drag drop API receives a browser event as an NPObject* sothe event is untrusted. Provide IPC calls to the renderer sogears can pass the event to renderer/V8 for checking, prior todrag type/data extraction, or the setting of the drop effect. Original patch by Noel Gordon via: http://codereview.chromium.org/99240 BUG=7995 TEST=none Review URL: http://codereview.chromium.org/112056 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@16808 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/glue/npruntime_util.cc')
-rw-r--r--webkit/glue/npruntime_util.cc121
1 files changed, 118 insertions, 3 deletions
diff --git a/webkit/glue/npruntime_util.cc b/webkit/glue/npruntime_util.cc
index e9bd7b8..152a9e3 100644
--- a/webkit/glue/npruntime_util.cc
+++ b/webkit/glue/npruntime_util.cc
@@ -6,16 +6,31 @@
#include "webkit/glue/npruntime_util.h"
-// Import the definition of PrivateIdentifier
#if USE(V8_BINDING)
-#include "NPV8Object.h"
+#include "ChromiumDataObject.h"
+#include "ClipboardChromium.h"
+#include "EventNames.h"
+#include "MouseEvent.h"
+#include "NPV8Object.h" // for PrivateIdentifier
+#include "v8_helpers.h"
+#include "v8_proxy.h"
#elif USE(JAVASCRIPTCORE_BINDINGS)
#include "bridge/c/c_utility.h"
+#endif
+
#undef LOG
+
+#include "base/pickle.h"
+#if USE(V8_BINDING)
+#include "webkit/api/public/WebDragData.h"
+#include "webkit/glue/glue_util.h"
+#endif
+
+using WebKit::WebDragData;
+#if USE(JAVASCRIPTCORE_BINDINGS)
using JSC::Bindings::PrivateIdentifier;
#endif
-#include "base/pickle.h"
namespace webkit_glue {
@@ -64,4 +79,104 @@ bool DeserializeNPIdentifier(const Pickle& pickle, void** pickle_iter,
return true;
}
+#if USE(V8)
+
+inline v8::Local<v8::Value> GetEvent(const v8::Handle<v8::Context>& context) {
+ static v8::Persistent<v8::String> event(
+ v8::Persistent<v8::String>::New(v8::String::NewSymbol("event")));
+ return context->Global()->GetHiddenValue(event);
+}
+
+static bool DragEventData(NPObject* npobj, int* event_id, WebDragData* data) {
+ using WebCore::V8Proxy;
+
+ if (npobj == NULL)
+ return false;
+ if (npobj->_class != npScriptObjectClass)
+ return false;
+
+ v8::HandleScope handle_scope;
+ v8::Handle<v8::Context> context = v8::Context::GetEntered();
+ if (context.IsEmpty())
+ return false;
+
+ // Get the current WebCore event.
+ v8::Handle<v8::Value> current_event(GetEvent(context));
+ WebCore::Event* event = V8Proxy::ToNativeEvent(current_event);
+ if (event == NULL)
+ return false;
+
+ // Check that the given npobj is that event.
+ V8NPObject* object = reinterpret_cast<V8NPObject*>(npobj);
+ WebCore::Event* given = V8Proxy::ToNativeEvent(object->v8Object);
+ if (given != event)
+ return false;
+
+ // Check the execution frames are same origin.
+ V8Proxy* current = V8Proxy::retrieve(V8Proxy::retrieveFrame());
+ WebCore::Frame* frame = V8Proxy::retrieveFrame(context);
+ if (!current || !current->CanAccessFrame(frame, false))
+ return false;
+
+ const WebCore::EventNames& event_names(WebCore::eventNames());
+ const WebCore::AtomicString& event_type(event->type());
+
+ enum DragTargetMouseEventId {
+ DragEnterId = 1, DragOverId = 2, DragLeaveId = 3, DropId = 4
+ };
+
+ // The event type should be a drag event.
+ if (event_type == event_names.dragenterEvent) {
+ *event_id = DragEnterId;
+ } else if (event_type == event_names.dragoverEvent) {
+ *event_id = DragOverId;
+ } else if (event_type == event_names.dragleaveEvent) {
+ *event_id = DragLeaveId;
+ } else if (event_type == event_names.dropEvent) {
+ *event_id = DropId;
+ } else {
+ return false;
+ }
+
+ // Drag events are mouse events and should have a clipboard.
+ WebCore::MouseEvent* me = reinterpret_cast<WebCore::MouseEvent*>(event);
+ WebCore::Clipboard* clipboard = me->clipboard();
+ if (!clipboard)
+ return false;
+
+ // And that clipboard should be accessible by WebKit policy.
+ WebCore::ClipboardChromium* chrome =
+ reinterpret_cast<WebCore::ClipboardChromium*>(clipboard);
+ HashSet<WebCore::String> accessible(chrome->types());
+ if (accessible.isEmpty())
+ return false;
+
+ RefPtr<WebCore::ChromiumDataObject> data_object(chrome->dataObject());
+ if (data_object && data)
+ *data = ChromiumDataObjectToWebDragData(data_object);
+
+ return data_object != NULL;
+}
+
+#endif
+
+bool GetDragData(NPObject* event, int* event_id, WebDragData* data) {
+#if USE(V8)
+ return DragEventData(event, event_id, data);
+#else
+ // Not supported on other ports (JSC, etc).
+ return false;
+#endif
+}
+
+bool IsDragEvent(NPObject* event) {
+#if USE(V8)
+ int event_id;
+ return DragEventData(event, &event_id, NULL); // Check the event only.
+#else
+ // Not supported on other ports (JSC, etc).
+ return false;
+#endif
+}
+
} // namespace webkit_glue