| 472 | } |
| 473 | |
| 474 | void CefPythonApp::DoJavascriptBindingsForBrowser( |
| 475 | CefRefPtr<CefBrowser> browser) { |
| 476 | // get frame |
| 477 | // get context |
| 478 | // if bindToFrames is true loop through all frames, |
| 479 | // otherwise just the main frame. |
| 480 | // post task on a valid v8 thread |
| 481 | CefRefPtr<CefDictionaryValue> jsBindings = GetJavascriptBindings(browser); |
| 482 | if (!jsBindings.get()) { |
| 483 | // Bindings must be set before this function is called. |
| 484 | LOG(ERROR) << "[Renderer process] DoJavascriptBindingsForBrowser():" |
| 485 | " bindings not set"; |
| 486 | return; |
| 487 | } |
| 488 | std::vector<int64> frameIds; |
| 489 | std::vector<CefString> frameNames; |
| 490 | if (jsBindings->HasKey("bindToFrames") |
| 491 | && jsBindings->GetType("bindToFrames") == VTYPE_BOOL |
| 492 | && jsBindings->GetBool("bindToFrames")) { |
| 493 | // GetFrameIdentifiers() is buggy, returns always a vector |
| 494 | // filled with zeroes (as of revision 1448). Use GetFrameNames() |
| 495 | // instead. |
| 496 | browser->GetFrameNames(frameNames); |
| 497 | for (std::vector<CefString>::iterator it = frameNames.begin(); \ |
| 498 | it != frameNames.end(); ++it) { |
| 499 | CefRefPtr<CefFrame> frame = browser->GetFrame(*it); |
| 500 | if (frame.get()) { |
| 501 | frameIds.push_back(frame->GetIdentifier()); |
| 502 | // | printf("GetFrameNames(): frameId = %lu\n", |
| 503 | // | frame->GetIdentifier()); |
| 504 | } |
| 505 | } |
| 506 | } |
| 507 | // BUG in CEF: |
| 508 | // GetFrameNames() does not return the main frame (as of revision 1448). |
| 509 | // Make it work for the future when this bug gets fixed. |
| 510 | std::vector<int64>::iterator find_it = std::find( |
| 511 | frameIds.begin(), frameIds.end(), |
| 512 | browser->GetMainFrame()->GetIdentifier()); |
| 513 | if (find_it == frameIds.end()) { |
| 514 | // Main frame not found in frameIds vector, add it now. |
| 515 | // | printf("Adding main frame to frameIds: %lu\n", |
| 516 | // | browser->GetMainFrame()->GetIdentifier()); |
| 517 | frameIds.push_back(browser->GetMainFrame()->GetIdentifier()); |
| 518 | } |
| 519 | if (!frameIds.size()) { |
| 520 | LOG(ERROR) << "[Renderer process] DoJavascriptBindingsForBrowser():" |
| 521 | " frameIds.size() == 0"; |
| 522 | return; |
| 523 | } |
| 524 | for (std::vector<int64>::iterator it = frameIds.begin(); \ |
| 525 | it != frameIds.end(); ++it) { |
| 526 | if (*it <= 0) { |
| 527 | // GetFrameIdentifiers() bug that returned a vector |
| 528 | // filled with zeros. This problem was fixed by using' |
| 529 | // GetFrameNames() so this block of code should not |
| 530 | // be executed anymore. |
| 531 | LOG(ERROR) << "[Renderer process] DoJavascriptBindingsForBrowser():" |