Firebreath JSAPI will not be recognized in firefox

First, I’m talking about what I’m doing with Firebreath.

  • I am developing a plugin for viewing images in a browser using firebreath.
  • In my plugin, I define two types of MIME, one for the main viewer and one for the 2D plan.
  • Only one main viewer is allowed on each page, but can have several types of 2D plan. And they all use the same model document, open in the main viewer.
  • So, after creating a two-dimensional view in the plan, I need to transfer the document object (firebreath JSAPI) to the 2nd plan view.

Then, suppose the main viewer and plan view are loaded with the names "mainviewer" and "planview", and I will close the document to schedule the view, as shown below,

planview.attach(mainviewer.doc); 
(the signature is "bool attach(const FB::JSObjectPtr& myDoc)" and 
The mainviewer.doc is just a firebreath JSAPI)

RESEARCH is that in firefox, the passed JSObject cannot be recognized as JSAPI by calling

FB::JSAPIPtr jsAPI = myDoc->getJSAPI(); // THIS WILL RETURN **NULL**.
m_main_doc = FB::ptr_cast<LcFbViewerDocumentAPI>(jsAPI); // Cast to my document API.

This problem only occurs if the host browser is firefox, IE / Chrome works well.

So what happened to the passed JSAPI when using firefox?

+5
source share
1 answer

, ( FireFox) NPObjects , ; - ++, . FireBreath NPJavascriptObject ( NPObject, FireBreath JSAPI ), JSAPI.

JSAPI. instance_id JSAPI, std:: map, , .

// in the class def
static int counter;
int instance_id;

// In the .cpp file
int MyPluginAPI::counter(0);

std::map<int, FB::JSAPIWeakPtr> apiMap;
FB::JSAPIPtr getJSAPIObjectById(int id) {
    std::map<int, FB::JSAPIWeakPtr> fnd = apiMap.find(id);
    if (fnd != apiMap.end()) {
        return fnd.second->lock(); // it a weak pointer, lock to get the shared_ptr
    } else {
        return FB::JSAPIPtr(); // Alternately throw an exception
    }
}

MyPluginAPI::MyPluginAPI() {
    instance_id = counter++;
    // Note that you can't get at the shared_ptr in the constructor,
    // so you'll have to call an init function after creating the JSAPI object

    registerProperty("instance_id",
                 make_property(this,
                    &FBTestPluginAPI::get_instId));
}

int MyPluginAPI::get_instId() { return instance_id; }

void MyPluginAPI::init() {
    apiMap[instance_id] = shared_from_this();
}

, , , ptrs, , . , JSAPIPtr, JSObjectPtr.

void doSomethingWithAnAPI(const FB::JSObjectPtr& obj) {
    if (obj) {
        int id = obj->GetProperty("instance_id");
        FB::JSAPIPtr ptr = getJSAPIObjectById(id);
        if (ptr) {
            // Hurray! We have the object
        }
    }
}

, .

+4

All Articles