Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Paths and file:// protocol #67

Open
n-smits opened this issue Jul 6, 2021 · 0 comments
Open

Paths and file:// protocol #67

n-smits opened this issue Jul 6, 2021 · 0 comments

Comments

@n-smits
Copy link

n-smits commented Jul 6, 2021

How to link ui files together? Paths resolve to eg. c:/path/foo, instead of c:/../project-root/ui-root/path/foo. If linked manually it works, but obv that's not the way. This happens with any resource e.g.

<link href="path/to/style.css">
<a href="path/to/page.html">
<img src="path/to/img.png">

because blui:// protocol starts at root c by default, because it actually just replaces string to file:// protocol, and root for file is c, while for http:// it would be ok. I'm using node to pre generate static htmls (it shouldn't matter, but specifically vue, vue-router, webpack, react-snap). When developing (npm run dev and open localhost:8080) everything is ok, because it serves http:// protocol .

I see UBluEye::LoadURL does path string replace to add project dir FPaths::ProjectDir() but if I'm not mistaken, that handles only initial access and not the problem I'm having, the html resource access. Best option is handling this with cef, implementing an actual custom blui:// protocol (wiki link). (I'm basing my "best" based on 1. CppCon 2019 HTML 5 for GUI in C++, 2. Blog post on c# cef without http, 3. StackOverflow - webpack in cef). Is this done somewhere? I couldn't find it.

I've added public CefBrowserProcessHandler to BluManager and

void BluManager::OnRegisterCustomSchemes (CefRawPtr<CefSchemeRegistrar> registrar) {
  UE_LOG(LogBlu, Log, TEXT("PROCESS: OnRegisterCustomSchemes (ui://)")); // called on editor start
  registrar->AddCustomScheme("ui", CEF_SCHEME_OPTION_CSP_BYPASSING); // <----- option ok? means:
  // If CEF_SCHEME_OPTION_CSP_BYPASSING is set the scheme can bypass Content-
  // Security-Policy (CSP) checks. This value should not be set in most cases
  // where CEF_SCHEME_OPTION_STANDARD is set.
}
void BluManager::OnContextInitialized () {
  UE_LOG(LogBlu, Log, TEXT("PROCESS: OnContextInitialized <----- I never get called"));
  // CefRegisterSchemeHandlerFactory("ui", CefString(), new MakeSchemeUI());
}

Also I've added SchemeUI.h but don't know how to continue.

// this is just declarations <---------

#pragma once
#include "CEFInclude.h"
#include "BluLog.h" // moved logs

class UseSchemeUI : public CefResourceHandler {
  
  virtual bool Open (
    CefRefPtr<CefRequest> request,
    bool& handle_request,
    CefRefPtr<CefCallback> callback
  ) override {
    handle_request = true;
    UE_LOG(LogBlu, Log, TEXT("UseSchemeUI <----- I never get called"));
    return true;
  }
  virtual void Cancel() override {}
  virtual void GetResponseHeaders (
    CefRefPtr<CefResponse> response,
    int64& response_length,
    CefString& redirectUrl
  ) override {}
  
  IMPLEMENT_REFCOUNTING(UseSchemeUI);
};

class MakeSchemeUI : public CefSchemeHandlerFactory { public:
  virtual CefRefPtr<CefResourceHandler> Create (
    CefRefPtr<CefBrowser> browser,
    CefRefPtr<CefFrame> frame,
    const CefString& scheme_name,
    CefRefPtr<CefRequest> request
  ) override { return new UseSchemeUI(); }

  IMPLEMENT_REFCOUNTING(MakeSchemeUI);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants