cloudtrends / chromiumembedded

Automatically exported from code.google.com/p/chromiumembedded
1 stars 1 forks source link

Add support for creating and parsing URLs #181

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Chromium supports creating and parsing URLs via googleurl (GURL).  We should 
expose that support via CEF, supplying consumers with a mechanism for creating 
a URL from its components and breaking a URL string down into individual 
components.

I've attached a diff for this change based on some discussions we've had on the 
CEF forum.

Original issue reported on code.google.com by emerick on 31 Jan 2011 at 5:23

Attachments:

GoogleCodeExporter commented 9 years ago
Looks good except for the following:

+bool CefParseURL(const CefString& url,
+                 CefURLParts& parts)
+{
+  GURL gurl(url.ToString());
+  if (!gurl.is_valid())
+    return false;
+
+  cef_string_copy(UTF8ToWide(gurl.host()).c_str(), gurl.host().length(),
+    &parts.host);
+  cef_string_copy(UTF8ToWide(gurl.path()).c_str(), gurl.path().length(),
+    &parts.path);
+  cef_string_copy(UTF8ToWide(gurl.query()).c_str(), gurl.query().length(),
+    &parts.query);
+  cef_string_copy(UTF8ToWide(gurl.scheme()).c_str(), gurl.scheme().length(),
+    &parts.scheme);
+  cef_string_copy(UTF8ToWide(gurl.spec()).c_str(), gurl.spec().length(),
+    &parts.spec);
+
+  return true;
+}

We can't assume that the CefString underlying type will be wide. Instead, use 
this approach to wrap each of the CefURLParts members and perform automatic 
type conversion if needed:

CefString hostStr(&parts.host);
hostStr = gurl.host();

Original comment by magreenb...@gmail.com on 31 Jan 2011 at 5:50

GoogleCodeExporter commented 9 years ago
Thanks for the tip, I didn't realize I could associate the CefString and 
cef_string_t like that.  I've attached a new patch with that change.

Original comment by emerick on 31 Jan 2011 at 6:18

Attachments:

GoogleCodeExporter commented 9 years ago
Committed as revision 177 with support for additional URL components (username, 
password, port) and a unit test.

Original comment by magreenb...@gmail.com on 31 Jan 2011 at 8:48