Exposing GURL from CEF

Having problems with building or using CEF's C/C++ APIs? This forum is here to help. Please do not post bug reports or feature requests here.

Exposing GURL from CEF

Postby emerick » Fri Jan 28, 2011 1:45 pm

I've created a CefURL class to expose some of GURL's functionality in CEF, because it's something that I needed in my current project. It doesn't wrap every method that GURL provides, but it does wrap the ones that I deemed to be the most relevant. If anyone has any interest in this, I can put together a patch; it might even be something to consider adding to CEF, but I leave that up to Marshall. Here's the relevant class definition:

Code: Select all
// Class used to represent a URL
/*--cef(source=library)--*/
class CefURL : public CefBase
{
public:
  // Create a new CefURL object.
  /*--cef()--*/
  static CefRefPtr<CefURL> CreateURL(const CefString& url);

  // Return true if the URL is empty.
  /*--cef()--*/
  virtual bool IsEmpty() =0;

  // Return true if the URL is valid.
  /*--cef()--*/
  virtual bool IsValid() =0;

  // Return the URL specification.
  /*--cef()--*/
  virtual CefString GetSpec() =0;

  // Return the URL's scheme, not including the colon.
  /*--cef()--*/
  virtual CefString GetScheme() =0;

  // Return the URL's host.  This may be a hostname, an IPv4 address, or an
  // IPv6 literal surrounded by square brackets, like "[2001:db8::1]".
  /*--cef()--*/
  virtual CefString GetHost() =0;

  // Return the URL's path, including first slash following host.
  /*--cef()--*/
  virtual CefString GetPath() =0;

  // Return the URL's query (everything following ?).
  /*--cef()--*/
  virtual CefString GetQuery() =0;
};


Emerick
emerick
Expert
 
Posts: 154
Joined: Sun Feb 21, 2010 7:57 pm
Location: Belmont, MA

Re: Exposing GURL from CEF

Postby magreenblatt » Fri Jan 28, 2011 2:05 pm

Hi Emerick,

Wrapping a GURL in a reference-counted object (which is what I assume you're doing) seems rather heavy-weight. It would probably be better to have a single static function where you pass in the URL string and a structure reference and it fills in the structure with the various URL parts.

Code: Select all
typedef struct _cef_urlparts_t
{
  cef_string_t spec;
  cef_string_t scheme;
  cef_string_t host;
  cef_string_t path;
  ...
} cef_urlparts_t;

class CefURLParts : public cef_urlparts_t
{
 // Implement the same as the CefSettings class
};

// Parse the specified |url| into its component parts.
// Returns false if the URL is empty or invalid.
bool CefParseURL(const CefString& url, CefURLParts& parts);

If the user needs to distinguish between empty and invalid they can check the string length (0 = empty) before calling the function.

Regards,
Marshall
magreenblatt
Site Admin
 
Posts: 12408
Joined: Fri May 29, 2009 6:57 pm

Re: Exposing GURL from CEF

Postby emerick » Fri Jan 28, 2011 2:14 pm

Right, I see what you're saying. I hadn't thought about the reference-counted object as being "heavy-weight", but it makes sense now that you mention it. It should be easy for me to incorporate your changes; once I have something working, I'll post a patch and you can take a look.

Thanks,

Emerick
emerick
Expert
 
Posts: 154
Joined: Sun Feb 21, 2010 7:57 pm
Location: Belmont, MA

Re: Exposing GURL from CEF

Postby magreenblatt » Fri Jan 28, 2011 2:21 pm

While we're thinking about this, it might also be nice to have a function that takes the URL parts and creates the combined URL string.

Code: Select all
bool CefCreateURL(const CefURLParts& parts, CefString& url);
magreenblatt
Site Admin
 
Posts: 12408
Joined: Fri May 29, 2009 6:57 pm

Re: Exposing GURL from CEF

Postby emerick » Fri Jan 28, 2011 2:33 pm

Yeah, I agree that makes sense.
emerick
Expert
 
Posts: 154
Joined: Sun Feb 21, 2010 7:57 pm
Location: Belmont, MA

Re: Exposing GURL from CEF

Postby emerick » Fri Jan 28, 2011 4:06 pm

Is there no facility for appending two CefString's via operator+? I'm using a std::wstring temporary to achieve the same result right now, but it feels a bit awkward.

Emerick
emerick
Expert
 
Posts: 154
Joined: Sun Feb 21, 2010 7:57 pm
Location: Belmont, MA

Re: Exposing GURL from CEF

Postby magreenblatt » Fri Jan 28, 2011 4:17 pm

Is there no facility for appending two CefString's via operator+?

Unfortunately not.

I'm using a std::wstring temporary to achieve the same result right now, but it feels a bit awkward.

You should probably use std::string instead. You can also use base::StringPrintf() from base/stringprintf.h.
magreenblatt
Site Admin
 
Posts: 12408
Joined: Fri May 29, 2009 6:57 pm

Re: Exposing GURL from CEF

Postby emerick » Mon Jan 31, 2011 12:24 pm

I created a new item in the issue tracker and attached a patch. Here's the link:

http://code.google.com/p/chromiumembedd ... ail?id=181

Emerick
emerick
Expert
 
Posts: 154
Joined: Sun Feb 21, 2010 7:57 pm
Location: Belmont, MA


Return to Support Forum

Who is online

Users browsing this forum: amaitland, Google [Bot] and 61 guests