| 549 | } |
| 550 | |
| 551 | void CefPythonApp::DoJavascriptBindingsForFrame(CefRefPtr<CefBrowser> browser, |
| 552 | CefRefPtr<CefFrame> frame, |
| 553 | CefRefPtr<CefV8Context> context) { |
| 554 | CefRefPtr<CefDictionaryValue> jsBindings = GetJavascriptBindings(browser); |
| 555 | if (!jsBindings.get()) { |
| 556 | // Bindings may not yet be set, it's okay. |
| 557 | LOG(INFO) << "[Renderer process] DoJavascriptBindingsForFrame():" |
| 558 | " bindings not set yet"; |
| 559 | return; |
| 560 | } |
| 561 | LOG(INFO) << "[Renderer process] DoJavascriptBindingsForFrame():" |
| 562 | " bindings are set"; |
| 563 | if (!(jsBindings->HasKey("functions") |
| 564 | && jsBindings->GetType("functions") == VTYPE_DICTIONARY |
| 565 | && jsBindings->HasKey("properties") |
| 566 | && jsBindings->GetType("properties") == VTYPE_DICTIONARY |
| 567 | && jsBindings->HasKey("objects") |
| 568 | && jsBindings->GetType("objects") == VTYPE_DICTIONARY |
| 569 | && jsBindings->HasKey("bindToFrames") |
| 570 | && jsBindings->GetType("bindToFrames") == VTYPE_BOOL)) { |
| 571 | LOG(ERROR) << "[Renderer process] DoJavascriptBindingsForFrame():" |
| 572 | " invalid data [1]"; |
| 573 | return; |
| 574 | } |
| 575 | |
| 576 | // A context must be explicitly entered before creating a |
| 577 | // V8 Object, Array, Function or Date asynchronously. |
| 578 | // NOTE: you cannot call CefV8Context::GetEnteredContext |
| 579 | // or GetCurrentContext when CefV8Context::InContext |
| 580 | // returns false, as it will result in crashes. |
| 581 | bool didEnterContext = false; |
| 582 | if (!CefV8Context::InContext()) { |
| 583 | if (!context->IsValid()) { |
| 584 | // BUG in CEF (Issue 130), the "context" provided by CEF may |
| 585 | // not be valid. May be a timing issue. Or may be caused by |
| 586 | // a redirect to a different origin and that creates a new |
| 587 | // renderer process. |
| 588 | // This message is logged in the tutorial.py example which |
| 589 | // uses data uri created from html string. |
| 590 | LOG(INFO) << "[Renderer process] DoJavascriptBindingsForFrame():" |
| 591 | " V8 context provided by CEF is invalid"; |
| 592 | return; |
| 593 | } |
| 594 | context->Enter(); |
| 595 | didEnterContext = true; |
| 596 | } |
| 597 | CefRefPtr<CefDictionaryValue> functions = \ |
| 598 | jsBindings->GetDictionary("functions"); |
| 599 | CefRefPtr<CefDictionaryValue> properties = \ |
| 600 | jsBindings->GetDictionary("properties"); |
| 601 | CefRefPtr<CefDictionaryValue> objects = \ |
| 602 | jsBindings->GetDictionary("objects"); |
| 603 | // Here in this function we bind only for the current frame. |
| 604 | // | bool bindToFrames = jsBindings->GetBool("bindToFrames"); |
| 605 | if (!(functions->IsValid() && properties->IsValid() |
| 606 | && objects->IsValid())) { |
| 607 | LOG(ERROR) << "[Renderer process] DoJavascriptBindingsForFrame():" |
| 608 | " invalid data [2]"; |
nothing calls this directly
no test coverage detected