2011-02-04 Daniel Cheng <dcheng@chromium.org>
[WebKit.git] / Source / WebKit / chromium / src / PlatformBridge.cpp
index 4dde3caac7693acf829014b72bb6b31453ddfab7..b09d1506740fad9d25d32024102da05bd5da0d9e 100644 (file)
@@ -132,6 +132,14 @@ static WebWidgetClient* toWebWidgetClient(Widget* widget)
     return chromeClientImpl->webView()->client();
 }
 
+static WebClipboard* getClipboard(const Frame* frame)
+{
+    WebFrameImpl* frameImpl = WebFrameImpl::fromFrame(frame);
+    if (!frameImpl || !frameImpl->client())
+        return 0;
+    return frameImpl->client()->clipboard();
+}
+
 static WebCookieJar* getCookieJar(const Document* document)
 {
     WebFrameImpl* frameImpl = WebFrameImpl::fromFrame(document->frame());
@@ -217,9 +225,15 @@ void PlatformBridge::clipboardWriteData(const String& type,
 }
 
 HashSet<String> PlatformBridge::clipboardReadAvailableTypes(
-    PasteboardPrivate::ClipboardBuffer buffer, bool* containsFilenames)
+    const Frame* frame,
+    PasteboardPrivate::ClipboardBuffer buffer,
+    bool* containsFilenames)
 {
-    WebVector<WebString> result = webKitClient()->clipboard()->readAvailableTypes(
+    WebClipboard* clipboard = getClipboard(frame);
+    if (!clipboard)
+        return HashSet<String>();
+
+    WebVector<WebString> result = clipboard->readAvailableTypes(
         static_cast<WebClipboard::Buffer>(buffer), containsFilenames);
     HashSet<String> types;
     for (size_t i = 0; i < result.size(); ++i)
@@ -227,12 +241,19 @@ HashSet<String> PlatformBridge::clipboardReadAvailableTypes(
     return types;
 }
 
-bool PlatformBridge::clipboardReadData(PasteboardPrivate::ClipboardBuffer buffer,
-                                       const String& type, String& data, String& metadata)
+bool PlatformBridge::clipboardReadData(const Frame* frame,
+                                       PasteboardPrivate::ClipboardBuffer buffer,
+                                       const String& type,
+                                       String& data,
+                                       String& metadata)
 {
+    WebClipboard* clipboard = getClipboard(frame);
+    if (!clipboard)
+        return false;
+
     WebString resultData;
     WebString resultMetadata;
-    bool succeeded = webKitClient()->clipboard()->readData(
+    bool succeeded = clipboard->readData(
         static_cast<WebClipboard::Buffer>(buffer), type, &resultData, &resultMetadata);
     if (succeeded) {
         data = resultData;
@@ -241,9 +262,14 @@ bool PlatformBridge::clipboardReadData(PasteboardPrivate::ClipboardBuffer buffer
     return succeeded;
 }
 
-Vector<String> PlatformBridge::clipboardReadFilenames(PasteboardPrivate::ClipboardBuffer buffer)
+Vector<String> PlatformBridge::clipboardReadFilenames(const Frame* frame,
+                                                      PasteboardPrivate::ClipboardBuffer buffer)
 {
-    WebVector<WebString> result = webKitClient()->clipboard()->readFilenames(
+    WebClipboard* clipboard = getClipboard(frame);
+    if (!clipboard)
+        return Vector<String>();
+
+    WebVector<WebString> result = clipboard->readFilenames(
         static_cast<WebClipboard::Buffer>(buffer));
     Vector<String> convertedResult;
     for (size_t i = 0; i < result.size(); ++i)