objective c - Chromium entry point for fully initialized CEF OS X client -


i have chromium client implementation os x. support double-click action on data file can read , displayed inside chromium client. need implement method application:openfile. method called long time before application initialized. need call application:openfile after chromium client initialized , nswindow present.

which method automatically called after chromium initialized , chrome window available?

the class cefloadhandler has method called onloadend. method called, when web-app loaded browser. careful! @ time javascript part of web-app must not initialized. if relying on full initialized javascript (all javascript objects etc.) have check inside javascript code.

see full answer how implement application:openfile chromium clients:

after lot of research , debugging came solution how implement application:openfile chromium based applications on os x. first of all, there 3 parts/layers have solved.

  1. cocoa part application:openfile
  2. chromium part browser initialization code
  3. javascript part initialization part

beginning 1:

the apple documentation application:openfile describes in discussion part, application:openfile called before applicationdidfinishlaunching. means, if rely on full initialized client (i can't imagine how's not?), have store url of file somewhere, e.g. ivar/property in application:openfile or in example below in std::vector of chromium handler. if application if initialized , browser window displayed, you're able directly call chromium handler method in turn calls appropriate javascript function!

// *** // application:openfile // ***  - (bool)application:(nsapplication *)theapplication openfile:(nsstring *)filename {   auapplication * clientapp = (auapplication *)theapplication;   nswindow* targetwindow = [clientapp findtargetwindow];   //check if browser window , running   if (targetwindow) {     [self processfile:filename];   }   else {     //this method saves file url open file      //when application+javascript initialized     au::test::handler* handler = au::test::handler::getinstance();     handler->addpendingfile([filename utf8string]);    }   return yes; }  // *** // processfile // ***  - (bool)processfile:(nsstring *)file {   //this method calls javascript function open file   std::string filename([file utf8string]);   au::test::handler* handler = au::test::handler::getinstance();   handler->onopenfile(filename);    return yes; } 

the 2 part:

on chromium side have store file url in appropriate structure. i'm using std::vector that. file url saved in chromium method onloadend. here chromium have loaded html+javascript parts in browser. careful. initialization of javascript not done yet! in example below have assign javascript property store file url.

// *** // handler::onloadend // ***  void handler::onloadend(cefrefptr<cefbrowser> browser,                cefrefptr<cefframe> frame,                int httpstatuscode) {   if (!m_pendingopenfiles.empty()) {     std::string file(m_pendingopenfiles[0]);     std::cout << "pending file later opening: " << file << std::endl;     //this method below calling javascript function assign     //a property `pendingfile`     onpendingfile(file);     //don't forget pop file url afterwards      //or use store container instead of `std::vector`     //if don't plan implement `application:openfiles` well!!!     m_pendingopenfiles.pop_back();   } } 

the 3 part:

on javascript side have check after application initialization if property pendingfile assigned or not open file appropriately.


Comments