import #include "/resource_util.h" in client_app.cc

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.

import #include "/resource_util.h" in client_app.cc

Postby daka1 » Sun Feb 22, 2015 5:43 am

In a chromium embedded simple client example I am trying to import #include "cefclient/browser/resource_util.h" in client_app.cc

To get access to a method called:
Code: Select all
bool GetResourceDir(std::string& dir);

I need this method so that i can get the bundle path to load my bundled plugins.


However my build fails saying: ld: symbol(s) not found for architecture x86_64

I can see that resource_util.h contains some flag "IFDEF POSIX", I am on a mac so i guess that should work, removing this does not seem to impact the problem:

Code: Select all
#ifndef CEF_TESTS_CEFCLIENT_BROWSER_RESOURCE_UTIL_H_
#define CEF_TESTS_CEFCLIENT_BROWSER_RESOURCE_UTIL_H_
#pragma once

#include <string>
#include "include/cef_stream.h"

namespace client {

#if defined(OS_POSIX)
// Returns the directory containing resource files.
bool GetResourceDir(std::string& dir);
#endif

// Retrieve a resource as a string.
bool LoadBinaryResource(const char* resource_name, std::string& resource_data);

// Retrieve a resource as a steam reader.
CefRefPtr<CefStreamReader> GetBinaryResourceReader(const char* resource_name);

}  // namespace client

#endif  // CEF_TESTS_CEFCLIENT_BROWSER_RESOURCE_UTIL_H_

The folder contains both: resource_util_mac.mm as well as resource_util_posix.cc. In resource_util_posix the method is used as well, without the compiler complaining:

Code: Select all
CefRefPtr<CefStreamReader> GetBinaryResourceReader(const char* resource_name) {
  std::string path;
  if  (!GetResourceDir(path)) //<------
    return NULL;

  path.append("/");
  path.append(resource_name);

  if (!FileExists(path.c_str()))
    return NULL;

  return CefStreamReader::CreateForFile(path);
}

}  // namespace client

This method is being called from test_runner.cc

Code: Select all
CefRefPtr<CefResourceHandler> GetResourceHandler(
    CefRefPtr<CefBrowser> browser,
    CefRefPtr<CefFrame> frame,
    CefRefPtr<CefRequest> request) {
  std::string url = request->GetURL();
  if (url.find(kTestOrigin) == 0) {
    // Handle URLs in the test origin.
    std::string file_name, mime_type;
    if (ParseTestUrl(url, &file_name, &mime_type)) {
      if (file_name == "request.html") {
        // Show the request contents.
        const std::string& dump = DumpRequestContents(request);
        std::string str = "<html><body bgcolor=\"white\"><pre>" + dump +
                          "</pre></body></html>";
        CefRefPtr<CefStreamReader> stream =
            CefStreamReader::CreateForData(
                static_cast<void*>(const_cast<char*>(str.c_str())),
                str.size());
        DCHECK(stream.get());
        return new CefStreamResourceHandler("text/html", stream);
      } else {
        // Load the resource from file.
        CefRefPtr<CefStreamReader> stream =
            GetBinaryResourceReader(file_name.c_str());
        if (stream.get())
          return new CefStreamResourceHandler(mime_type, stream);
      }
    }
  }

  return NULL;
}

How come the GetResourceDir being accessible/importable from test_runner but not client_app?

My initial problem being:
How can i GetResourceDir from client_app?
daka1
Techie
 
Posts: 42
Joined: Fri Feb 20, 2015 4:49 am

Re: import #include "/resource_util.h" in client_app.cc

Postby magreenblatt » Tue Feb 24, 2015 5:09 pm

The cefclient/common/client_app.cc file is included from both the browser process (cefclient target) and renderer process (cefclient Helper target). You cannot use cefclient/browser/resource_util.h from the renderer process. This is also indicated by the directories in which the files live.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: import #include "/resource_util.h" in client_app.cc

Postby daka1 » Wed Feb 25, 2015 7:00 am

Ok, so i create a helper class for getting such data in the renderer space to. It seems to work, a little duplicated code but not much...

I will probably need more renderer helpers later anyways..
daka1
Techie
 
Posts: 42
Joined: Fri Feb 20, 2015 4:49 am


Return to Support Forum

Who is online

Users browsing this forum: No registered users and 104 guests