nsresult
OperationStreamListener::StatusAndHrefFromResponse(nsIDOMElement *responseElt,
                                                   nsACString &href,
                                                   PRUint32 *statusCode)
{
    nsAutoString hrefString;
    nsresult rv = NS_WD_ElementTextChildValue(responseElt,
                                              NS_LITERAL_STRING("href"),
                                              hrefString);
    NS_ENSURE_SUCCESS(rv, rv);
    href = NS_ConvertUTF16toUTF8(hrefString);
    
    nsAutoString statusString;
    rv = NS_WD_ElementTextChildValue(responseElt, NS_LITERAL_STRING("status"),
                                     statusString);
    // XXX if we don't find a status element (or hit any other parse error,
    // for that matter) we need to signal this back to the caller
    //
    NS_ENSURE_SUCCESS(rv, rv);

    NS_ConvertUTF16toUTF8 statusUTF8(statusString);
    LOG(("status: %s", statusUTF8.get()));
    PRInt32 statusVal = nsCAutoString(Substring(statusUTF8, 8)).ToInteger(&rv, 10);
    NS_ENSURE_SUCCESS(rv, rv);
    
    *statusCode = (PRUint32)statusVal;
    
    return NS_OK;
}
NS_IMETHODIMP
GetToStringStreamListener::OnStopRequest(nsIRequest *aRequest,
                                         nsISupports *aContext,
                                         nsresult aStatusCode)
{
    PRUint32 status, rv;
    nsCOMPtr<nsIHttpChannel> channel = do_QueryInterface(aContext);

    LOG(("OperationStreamListener::OnStopRequest() entered"));

    rv = channel ? channel->GetResponseStatus(&status) : NS_ERROR_UNEXPECTED;

    if (NS_FAILED(rv))
        return SignalCompletion(rv);

    if (status != 200)
        return SignalCompletion(status);

    nsCOMPtr<nsISupportsCString>
        suppString(do_CreateInstance("@mozilla.org/supports-cstring;1",
                                     &rv));
    NS_ENSURE_SUCCESS(rv, rv);
    suppString->SetData(mBody);

    SignalDetail(status, nsCAutoString(""), suppString);
    SignalCompletion(status);
    return NS_OK;
}
bool
nsMIMEInfoAndroid::GetMimeInfoForMimeType(const nsACString& aMimeType,
                                          nsMIMEInfoAndroid** aMimeInfo)
{
  nsRefPtr<nsMIMEInfoAndroid> info = new nsMIMEInfoAndroid(aMimeType);
  mozilla::AndroidBridge* bridge = mozilla::AndroidBridge::Bridge();
  // we don't have access to the bridge, so just assume we can handle
  // the mime type for now and let the system deal with it
  if (!bridge){
    info.forget(aMimeInfo);
    return false;
  }

  nsIHandlerApp* systemDefault = nsnull;
  bridge->GetHandlersForMimeType(nsCAutoString(aMimeType).get(), 
                                 info->mHandlerApps, &systemDefault);
  
  if (systemDefault)
    info->mPrefApp = systemDefault;

  nsCAutoString fileExt;
  bridge->GetExtensionFromMimeType(aMimeType, fileExt);
  info->SetPrimaryExtension(fileExt);
  
  PRUint32 len;
  info->mHandlerApps->GetLength(&len);
  if (len == 1) {
    info.forget(aMimeInfo);
    return false;
  }
  
  info.forget(aMimeInfo);
  return true;
}
nsresult GlobalPrinters::InitializeGlobalPrinters ()
{
  if (PrintersAreAllocated()) 
    return NS_OK;

  mGlobalNumPrinters = 0;
  mGlobalNumPrinters = nsDeviceContextSpecOS2::PrnDlg.GetNumPrinters();
  if (!mGlobalNumPrinters) 
    return NS_ERROR_GFX_PRINTER_NO_PRINTER_AVAILABLE; 

  mGlobalPrinterList = new nsStringArray();
  if (!mGlobalPrinterList) 
     return NS_ERROR_OUT_OF_MEMORY;

  nsresult rv;
  nsCOMPtr<nsIPrefBranch> pPrefs = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv);
  BOOL prefFailed = NS_FAILED(rv); // don't return on failure, optional feature

  for (ULONG i = 0; i < mGlobalNumPrinters; i++) {
    nsXPIDLCString printer;
    nsDeviceContextSpecOS2::PrnDlg.GetPrinter(i, getter_Copies(printer));

    nsAutoChar16Buffer printerName;
    PRInt32 printerNameLength;
    rv = MultiByteToWideChar(0, printer, strlen(printer),
                             printerName, printerNameLength);
    mGlobalPrinterList->AppendString(nsDependentString(printerName.Elements()));

    // store printer description in prefs for the print dialog
    if (!prefFailed) {
       nsCAutoString printerDescription;
       printerDescription = nsCAutoString(nsDeviceContextSpecOS2::PrnDlg.GetPrintDriver(i)->szDeviceName);
       printerDescription += " (";
       printerDescription += nsCAutoString(nsDeviceContextSpecOS2::PrnDlg.GetDriverType(i));
       printerDescription += ")";
       pPrefs->SetCharPref(nsPrintfCString(256,
                                           "print.printer_%s.printer_description",
                                           printer.get()).get(),
                           printerDescription.get());
    }
  } 
  return NS_OK;
}
Beispiel #5
0
PRBool test_string_tointeger()
{
  PRInt32 rv;
  for (const ToIntegerTest* t = kToIntegerTests; t->str; ++t) {
    PRInt32 result = nsCAutoString(t->str).ToInteger(&rv, t->radix);
    if (rv != t->rv || result != t->result)
      return PR_FALSE;
  }
  return PR_TRUE;
}
NS_IMETHODIMP
nsWebDAVService::CopyTo(nsIWebDAVResource *resource,
                        const nsACString &destination,
                        PRBool recursive, PRBool overwrite,
                        nsIWebDAVOperationListener *listener,
                        nsIInterfaceRequestor *notificationCallbacks,
                        nsISupports *closure)

{
    nsCOMPtr<nsIHttpChannel> channel;
    nsresult rv = ChannelFromResource(resource, notificationCallbacks, getter_AddRefs(channel));
    NS_ENSURE_SUCCESS(rv, rv);

    nsCOMPtr<nsIStreamListener> streamListener;
    rv = NS_WD_NewOperationStreamListener(resource, listener, closure,
                                          nsIWebDAVOperationListener::COPY,
                                          getter_AddRefs(streamListener));
    NS_ENSURE_SUCCESS(rv, rv);

    channel->SetRequestMethod(NS_LITERAL_CSTRING("COPY"));
    if (!overwrite) {
        channel->SetRequestHeader(NS_LITERAL_CSTRING("Overwrite"),
                                  NS_LITERAL_CSTRING("F"),
                                  PR_FALSE);
    } else {
        channel->SetRequestHeader(NS_LITERAL_CSTRING("Overwrite"),
                                  NS_LITERAL_CSTRING("F"),
                                  PR_FALSE);
    }

    if (recursive) {
        channel->SetRequestHeader(NS_LITERAL_CSTRING("Depth"),
                                  NS_LITERAL_CSTRING("infinity"), PR_FALSE);
    } else {
        channel->SetRequestHeader(NS_LITERAL_CSTRING("Depth"),
                                  NS_LITERAL_CSTRING("0"), PR_FALSE);
    }

    channel->SetRequestHeader(NS_LITERAL_CSTRING("Destination"),
                              destination, PR_FALSE);

#ifdef PR_LOGGING
    if (LOG_ENABLED()) {
        nsCOMPtr<nsIURI> uri;
        channel->GetURI(getter_AddRefs(uri));
        nsCAutoString spec;
        uri->GetSpec(spec);
        LOG(("COPY starting for %s -> %s", spec.get(),
             nsCAutoString(destination).get()));
    }
#endif

    return channel->AsyncOpen(streamListener, channel);
}
/**
   aPref is a long string, which holds an exhaustive list of allowed tags
   and attributes. All other tags and attributes will be removed.

   aPref has the format
   "html head body ul ol li a(href,name,title) img(src,alt,title) #text"
   i.e.
   - tags are separated by whitespace
   - the attribute list follows the tag directly in brackets
   - the attributes are separated by commas.

   There is no way to express further restrictions, like "no text inside the
   <head> element". This is so to considerably reduce the complexity of the
   pref and this implementation.

   Update: Akk told me that I might be able to use DTD classes. Later(TM)...
 */
nsresult
mozSanitizingHTMLSerializer::ParsePrefs(const nsAString& aPref)
{
  char* pref = ToNewCString(aPref);
  char* tags_lasts;
  for (char* iTag = PL_strtok_r(pref, " ", &tags_lasts);
       iTag;
       iTag = PL_strtok_r(NULL, " ", &tags_lasts))
  {
    ParseTagPref(nsCAutoString(iTag));
  }
  delete[] pref;

  return NS_OK;
}
/**
 * Returns MIME info for the aURL, which may contain the whole URL or only a protocol
 */
nsresult
nsMIMEInfoAndroid::GetMimeInfoForURL(const nsACString &aURL,
                                     bool *found,
                                     nsIHandlerInfo **info)
{
  nsMIMEInfoAndroid *mimeinfo = new nsMIMEInfoAndroid(aURL);
  NS_ADDREF(*info = mimeinfo);
  *found = true;
  
  mozilla::AndroidBridge* bridge = mozilla::AndroidBridge::Bridge();
  if (!bridge) {
    // we don't have access to the bridge, so just assume we can handle
    // the protocol for now and let the system deal with it
    return NS_OK;
  }

  nsIHandlerApp* systemDefault = nsnull;
  bridge->GetHandlersForURL(nsCAutoString(aURL).get(), 
                            mimeinfo->mHandlerApps, &systemDefault);
  
  if (systemDefault)
    mimeinfo->mPrefApp = systemDefault;


  nsCAutoString fileExt;
  nsCAutoString mimeType;
  mimeinfo->GetType(mimeType);
  bridge->GetExtensionFromMimeType(mimeType, fileExt);
  mimeinfo->SetPrimaryExtension(fileExt);
  
  PRUint32 len;
  mimeinfo->mHandlerApps->GetLength(&len);
  if (len == 1) {
    // Code that calls this requires an object regardless if the OS has
    // something for us, so we return the empty object.
    *found = false;
    return NS_OK;
  }
  
  return NS_OK;
}
Beispiel #9
0
/* AString getAttribute (in nsIAtom name); */
NS_IMETHODIMP
xgGtkElement::GetAttribute (nsIAtom *name, nsAString &_retval)
{
    GParamSpec *spec;
    guint signal_id;
    if (!Resolve (name, &spec, &signal_id)) {
	return NS_ERROR_FAILURE;
    }
    if (!spec) {
	return NS_ERROR_FAILURE;
    }

    GValue gval = { 0 };
    g_value_init (&gval, G_TYPE_STRING);
    g_object_get_property (G_OBJECT (mObject), spec->name, &gval);
    if (G_VALUE_HOLDS (&gval, G_TYPE_STRING)) {
	_retval = NS_ConvertUTF8toUTF16 (nsCAutoString (g_value_get_string (&gval)));	
	g_value_unset (&gval);
	return NS_OK;
    }
    g_value_unset (&gval);
    return NS_ERROR_FAILURE;
}
bool
TestKeywords()
{
  nsCSSKeywords::AddRefTable();

  bool success = true;
  nsCSSKeyword id;
  nsCSSKeyword index;

  extern const char* const kCSSRawKeywords[];

  // First make sure we can find all of the tags that are supposed to
  // be in the table. Futz with the case to make sure any case will
  // work
  const char*const*  et = &kCSSRawKeywords[0];
  const char*const*  end = &kCSSRawKeywords[eCSSKeyword_COUNT - 1];
  index = eCSSKeyword_UNKNOWN;
  while (et < end) {
    char tagName[512];
    char* underscore = &(tagName[0]);

    PL_strcpy(tagName, *et);
    while (*underscore) {
      if (*underscore == '_') {
        *underscore = '-';
      }
      underscore++;
    }
    index = nsCSSKeyword(PRInt32(index) + 1);

    id = nsCSSKeywords::LookupKeyword(nsCString(tagName));
    if (id <= eCSSKeyword_UNKNOWN) {
      printf("bug: can't find '%s'\n", tagName);
      success = false;
    }
    if (id != index) {
      printf("bug: name='%s' id=%d index=%d\n", tagName, id, index);
      success = false;
    }

    // fiddle with the case to make sure we can still find it
    if (('a' <= tagName[0]) && (tagName[0] <= 'z')) {
      tagName[0] = tagName[0] - 32;
    }
    id = nsCSSKeywords::LookupKeyword(nsCString(tagName));
    if (id <= eCSSKeyword_UNKNOWN) {
      printf("bug: can't find '%s'\n", tagName);
      success = false;
    }
    if (id != index) {
      printf("bug: name='%s' id=%d index=%d\n", tagName, id, index);
      success = false;
    }
    et++;
  }

  // Now make sure we don't find some garbage
  for (int i = 0; i < (int) (sizeof(kJunkNames) / sizeof(const char*)); i++) {
    const char* const tag = kJunkNames[i];
    id = nsCSSKeywords::LookupKeyword(nsCAutoString(tag));
    if (eCSSKeyword_UNKNOWN < id) {
      printf("bug: found '%s'\n", tag ? tag : "(null)");
      success = false;
    }
  }

  nsCSSKeywords::ReleaseTable();
  return success;
}
static bool
TestProps()
{
  bool success = true;
  nsCSSProperty id;
  nsCSSProperty index;

  // Everything appears to assert if we don't do this first...
  nsCSSProps::AddRefTable();

  // First make sure we can find all of the tags that are supposed to
  // be in the table. Futz with the case to make sure any case will
  // work
  extern const char* const kCSSRawProperties[];
  const char*const* et = &kCSSRawProperties[0];
  const char*const* end = &kCSSRawProperties[eCSSProperty_COUNT];
  index = eCSSProperty_UNKNOWN;
  while (et < end) {
    char tagName[100];
    PL_strcpy(tagName, *et);
    index = nsCSSProperty(PRInt32(index) + 1);

    id = nsCSSProps::LookupProperty(nsCString(tagName), nsCSSProps::eAny);
    if (id == eCSSProperty_UNKNOWN) {
      printf("bug: can't find '%s'\n", tagName);
      success = false;
    }
    if (id != index) {
      printf("bug: name='%s' id=%d index=%d\n", tagName, id, index);
      success = false;
    }

    // fiddle with the case to make sure we can still find it
    if (('a' <= tagName[0]) && (tagName[0] <= 'z')) {
      tagName[0] = tagName[0] - 32;
    }
    id = nsCSSProps::LookupProperty(NS_ConvertASCIItoUTF16(tagName),
                                    nsCSSProps::eAny);
    if (id < 0) {
      printf("bug: can't find '%s'\n", tagName);
      success = false;
    }
    if (index != id) {
      printf("bug: name='%s' id=%d index=%d\n", tagName, id, index);
      success = false;
    }
    et++;
  }

  // Now make sure we don't find some garbage
  for (int i = 0; i < (int) (sizeof(kJunkNames) / sizeof(const char*)); i++) {
    const char* const tag = kJunkNames[i];
    id = nsCSSProps::LookupProperty(nsCAutoString(tag), nsCSSProps::eAny);
    if (id >= 0) {
      printf("bug: found '%s'\n", tag ? tag : "(null)");
      success = false;
    }
  }

  nsCSSProps::ReleaseTable();
  return success;
}
Beispiel #12
0
NS_IMETHODIMP
compzillaWindow::GetProperty (PRUint32 iprop, nsIPropertyBag2 **bag2)
{
    *bag2 = nsnull;

    Atom prop = (Atom)iprop;

    nsISupports *bag;
    nsCOMPtr<nsIWritablePropertyBag2> wbag;
    nsCOMPtr<nsIPropertyBag2> rbag;

    nsresult rv = CallCreateInstance("@mozilla.org/hash-property-bag;1", &bag);
    if (NS_FAILED(rv)) {
        return rv;
    }
 
    wbag = do_QueryInterface (bag);
    rbag = do_QueryInterface (bag);

#define SET_BAG() do { \
    NS_ADDREF (rbag); \
    *bag2 = rbag; \
} while (0)

#define SET_PROP(_bag, _type, _key, _val) \
    (_bag)->SetPropertyAs##_type (NS_LITERAL_STRING (_key), _val)

    switch (prop) {
        // ICCCM properties

    case XA_WM_NAME:
    case XA_WM_ICON_NAME: {
        // XXX this is missing some massaging, since the WM_NAME
        // property isn't in utf8, but in some locale character set
        // (latin1?  who knows).  Check the gtk+ source on how to
        // handle this.
        nsCAutoString str;
        if (NS_OK == GetUTF8StringProperty (prop, str)) {
            SET_BAG ();
            SET_PROP(wbag, AUTF8String, "text", str);
        }
        break;
    }

    case XA_WM_HINTS: {
        XWMHints *wmHints;

        wmHints = XGetWMHints (mDisplay, mWindow);

        if (wmHints) {
            SET_BAG ();
            SET_PROP(wbag, Int32, "wmHints.flags", wmHints->flags);
            SET_PROP(wbag, Bool, "wmHints.input", wmHints->input);
            SET_PROP(wbag, Int32, "wmHints.initialState", wmHints->initial_state);
            SET_PROP(wbag, Uint32, "wmHints.iconPixmap", wmHints->icon_pixmap);
            SET_PROP(wbag, Uint32, "wmHints.iconWindow", wmHints->icon_window);
            SET_PROP(wbag, Int32, "wmHints.iconX", wmHints->icon_x);
            SET_PROP(wbag, Int32, "wmHints.iconY", wmHints->icon_y);
            SET_PROP(wbag, Uint32, "wmHints.iconMask", wmHints->icon_mask);
            SET_PROP(wbag, Uint32, "wmHints.windowGroup", wmHints->window_group);

            XFree (wmHints);
        }
        break;
    }

    case XA_WM_NORMAL_HINTS: {
        XSizeHints sizeHints;
        long supplied;

        // XXX check return value
        XGetWMNormalHints (mDisplay, mWindow, &sizeHints, &supplied);

        SET_BAG ();

        SET_PROP(wbag, Int32, "sizeHints.flags", sizeHints.flags);

        SET_PROP(wbag, Int32, "sizeHints.x", sizeHints.x);
        SET_PROP(wbag, Int32, "sizeHints.y", sizeHints.y);
        SET_PROP(wbag, Int32, "sizeHints.width", sizeHints.width);
        SET_PROP(wbag, Int32, "sizeHints.height", sizeHints.height);

        SET_PROP(wbag, Int32, "sizeHints.minWidth", sizeHints.min_width);
        SET_PROP(wbag, Int32, "sizeHints.minHeight", sizeHints.min_height);

        SET_PROP(wbag, Int32, "sizeHints.maxWidth", sizeHints.max_width);
        SET_PROP(wbag, Int32, "sizeHints.maxHeight", sizeHints.max_height);

        SET_PROP(wbag, Int32, "sizeHints.widthInc", sizeHints.width_inc);
        SET_PROP(wbag, Int32, "sizeHints.heightInc", sizeHints.height_inc);

        SET_PROP(wbag, Int32, "sizeHints.minAspect.x", sizeHints.min_aspect.x);
        SET_PROP(wbag, Int32, "sizeHints.minAspect.y", sizeHints.min_aspect.y);

        SET_PROP(wbag, Int32, "sizeHints.maxAspect.x", sizeHints.max_aspect.x);
        SET_PROP(wbag, Int32, "sizeHints.maxAspect.y", sizeHints.max_aspect.y);

        if ((supplied & (PBaseSize|PWinGravity)) != 0) {
            SET_PROP(wbag, Int32, "sizeHints.baseWidth", sizeHints.base_width);
            SET_PROP(wbag, Int32, "sizeHints.baseHeight", sizeHints.base_height);

            SET_PROP(wbag, Int32, "sizeHints.winGravity", sizeHints.win_gravity);
        }
        break;
    }
    case XA_WM_CLASS: {
        // 2 strings, separated by a \0

        char *instance, *_class;

        Atom actual_type;
        int format;
        unsigned long nitems;
        unsigned long bytes_after_return;
        unsigned char *data;

        XGetWindowProperty (mDisplay, mWindow, (Atom)prop,
                            0, BUFSIZ, false, XA_STRING,
                            &actual_type, &format, &nitems, &bytes_after_return, 
                            &data);

        instance = (char*)data;
        _class = instance + strlen (instance) + 1;

        SET_BAG ();
        SET_PROP (wbag, ACString, "instanceName", nsCAutoString (instance));
        SET_PROP (wbag, ACString, "className", nsCAutoString (_class));

        XFree (data);

        break;
    }
    case XA_WM_TRANSIENT_FOR: {
        // the parent X window's canvas element
        break;
    }
    case XA_WM_CLIENT_MACHINE: {
        nsCAutoString str;
        if (NS_OK == GetUTF8StringProperty (prop, str)) {
            SET_BAG ();
            SET_PROP(wbag, AUTF8String, "text", str);
        }
    }
    default:
        // ICCCM properties which don't have predefined atoms

        if (prop == atoms.x.WM_COLORMAP_WINDOWS) {
            // if we ever support this, shoot me..
        }
        else if (prop == atoms.x.WM_PROTOCOLS) {
            // an array of Atoms.
        }

        // non - ICCCM properties go here

        // EWMH properties

        else if (prop == atoms.x._NET_WM_NAME
                 || prop == atoms.x._NET_WM_VISIBLE_NAME
                 || prop == atoms.x._NET_WM_ICON_NAME
                 || prop == atoms.x._NET_WM_VISIBLE_ICON_NAME) {
            // utf8 encoded string
            nsCAutoString str;
            if (NS_OK == GetUTF8StringProperty (prop, str)) {
                SET_BAG ();
                SET_PROP(wbag, AUTF8String, "text", str);
            }
        }
        else if (prop == atoms.x._NET_WM_DESKTOP) {
        }
        else if (prop == atoms.x._NET_WM_WINDOW_TYPE) {
            // XXX _NET_WM_WINDOW_TYPE is actually an array of atoms, not just 1.
            // this also needs fixing in the JS.
            PRUint32 atom;
            if (NS_OK == GetAtomProperty (prop, &atom)) {
                SET_BAG ();
                SET_PROP(wbag, Uint32, "atom", atom);
            }
        }
        else if (prop == atoms.x._NET_WM_STATE) {
        }
        else if (prop == atoms.x._NET_WM_ALLOWED_ACTIONS) {
        }
        else if (prop == atoms.x._NET_WM_STRUT) {
            PRUint32 *cards;
            PRUint32 nitems;

            if (NS_OK == GetCardinalListProperty (prop, &cards, 4)) {
                SET_BAG ();
                SET_PROP (wbag, Uint32, "left", cards[0]);
                SET_PROP (wbag, Uint32, "right", cards[1]);
                SET_PROP (wbag, Uint32, "top", cards[2]);
                SET_PROP (wbag, Uint32, "bottom", cards[3]);
            
                XFree (cards);
            }
        }
        else if (prop == atoms.x._NET_WM_STRUT_PARTIAL) {
            PRUint32 *cards;
            PRUint32 nitems;

            if (NS_OK == GetCardinalListProperty (prop, &cards, 12)) {
                SET_BAG ();
                SET_PROP (wbag, Bool, "partial", true);

                SET_PROP (wbag, Uint32, "left", cards[0]);
                SET_PROP (wbag, Uint32, "right", cards[1]);
                SET_PROP (wbag, Uint32, "top", cards[2]);
                SET_PROP (wbag, Uint32, "bottom", cards[3]);

                SET_PROP (wbag, Uint32, "leftStartY", cards[4]);
                SET_PROP (wbag, Uint32, "leftEndY", cards[5]);
                SET_PROP (wbag, Uint32, "rightStartY", cards[6]);
                SET_PROP (wbag, Uint32, "rightEndY", cards[7]);

                SET_PROP (wbag, Uint32, "topStartX", cards[8]);
                SET_PROP (wbag, Uint32, "topEndX", cards[9]);
                SET_PROP (wbag, Uint32, "bottomStartX", cards[10]);
                SET_PROP (wbag, Uint32, "bottomEndX", cards[11]);
                
                XFree (cards);
            }
        }
        else if (prop == atoms.x._NET_WM_ICON_GEOMETRY) {
            PRUint32 *cards;
            PRUint32 nitems;

            if (NS_OK == GetCardinalListProperty (prop, &cards, 4)) {
                SET_BAG ();
                SET_PROP (wbag, Bool, "partial", false);
                SET_PROP(wbag, Uint32, "x", cards[0]);
                SET_PROP(wbag, Uint32, "y", cards[1]);
                SET_PROP(wbag, Uint32, "width", cards[2]);
                SET_PROP(wbag, Uint32, "height", cards[3]);
                XFree (cards);
            }
        }
        else if (prop == atoms.x._NET_WM_ICON) {
            Atom actual_type;
            int format;
            unsigned long nitems;
            unsigned long bytes_after_return;
            unsigned char *data;
            
            if (XGetWindowProperty (mDisplay, mWindow, prop,
                                    0, BUFSIZ, false, XA_CARDINAL,
                                    &actual_type, &format, &nitems, &bytes_after_return, 
                                    &data) == Success) {
                nsCAutoString dataStr;
                dataStr.Assign ((char *) data, (format / 8) * nitems);

                SET_BAG ();
                SET_PROP(wbag, ACString, "data", dataStr);
                XFree (data);
            }
        }
        else if (prop == atoms.x._NET_WM_PID) {
        }
        else if (prop == atoms.x._NET_WM_HANDLED_ICONS) {
        }
        else if (prop == atoms.x._NET_WM_USER_TIME) {
        }
        else if (prop == atoms.x._NET_FRAME_EXTENTS) {
        }

        break;
    }

#undef SET_PROP
#undef SET_BAG

    return NS_OK;
}
Beispiel #13
0
// nsClipboard::GetNativeClipboardData ie. Paste
//
NS_IMETHODIMP
nsClipboard::GetNativeClipboardData(nsITransferable *aTransferable,
                                    QClipboard::Mode clipboardMode)
{
    if (nsnull == aTransferable)
    {
        qDebug("  GetNativeClipboardData: Transferable is null!");
        return NS_ERROR_FAILURE;
    }

    // get flavor list that includes all acceptable flavors (including
    // ones obtained through conversion)
    nsCOMPtr<nsISupportsArray> flavorList;
    nsresult errCode = aTransferable->FlavorsTransferableCanImport(
        getter_AddRefs(flavorList));

    if (NS_FAILED(errCode))
    {
        qDebug("nsClipboard::GetNativeClipboardData(): no FlavorsTransferable %i !",
               errCode);
        return NS_ERROR_FAILURE;
    }

    QClipboard *cb = QApplication::clipboard();
    const QMimeData *mimeData = cb->mimeData(clipboardMode);

    // Walk through flavors and see which flavor matches the one being pasted
    PRUint32 flavorCount;
    flavorList->Count(&flavorCount);
    nsCAutoString foundFlavor;

    for (PRUint32 i = 0; i < flavorCount; ++i)
    {
        nsCOMPtr<nsISupports> genericFlavor;
        flavorList->GetElementAt(i,getter_AddRefs(genericFlavor));
        nsCOMPtr<nsISupportsCString> currentFlavor(do_QueryInterface( genericFlavor) );

        if (currentFlavor)
        {
            nsXPIDLCString flavorStr;
            currentFlavor->ToString(getter_Copies(flavorStr));

            // Ok, so which flavor the data being pasted could be?
            // Text?
            if (!strcmp(flavorStr.get(), kUnicodeMime)) 
            {
                if (mimeData->hasText())
                {
                    // Clipboard has text and flavor accepts text, so lets
                    // handle the data as text
                    foundFlavor = nsCAutoString(flavorStr);

                    // Get the text data from clipboard
                    QString text = mimeData->text();
                    const QChar *unicode = text.unicode();
                    // Is there a more correct way to get the size in UTF16?
                    PRUint32 len = (PRUint32) 2*text.size();

                    // And then to genericDataWrapper
                    nsCOMPtr<nsISupports> genericDataWrapper;
                    nsPrimitiveHelpers::CreatePrimitiveForData(
                        foundFlavor.get(),
                        (void*)unicode,
                        len,
                        getter_AddRefs(genericDataWrapper));

                    // Data is good, set it to the transferable
                    aTransferable->SetTransferData(foundFlavor.get(),
                                                   genericDataWrapper,len);
                    // And thats all
                    break;
                }
            }

            // Image?
            if (!strcmp(flavorStr.get(), kJPEGImageMime)
             || !strcmp(flavorStr.get(), kPNGImageMime)
             || !strcmp(flavorStr.get(), kGIFImageMime))
            {
                qDebug("nsClipboard::GetNativeClipboardData(): Pasting image data not implemented!");
                break;
            }
        }
    }

    return NS_OK;
}