OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
Slic3r::GUI::PrinterWebView Class Reference

#include </home/runner/work/OrcaSlicer/OrcaSlicer/src/slic3r/GUI/PrinterWebView.hpp>

Inheritance diagram for Slic3r::GUI::PrinterWebView:
Collaboration diagram for Slic3r::GUI::PrinterWebView:

Public Member Functions

 PrinterWebView (wxWindow *parent)
virtual ~PrinterWebView ()
void load_url (wxString &url, wxString apikey="")
void UpdateState ()
void OnClose (wxCloseEvent &evt)
void OnError (wxWebViewEvent &evt)
void OnLoaded (wxWebViewEvent &evt)
void OnNewWindow (wxWebViewEvent &evt)
void OnScriptMessage (wxWebViewEvent &evt)
void reload ()
void update_mode ()
bool Show (bool show=true) override

Static Public Member Functions

static PrinterWebView * if_built ()
static PrinterWebView * ensure ()
static void when_built (std::function< void(PrinterWebView &)> fn)

Private Member Functions

void SendAPIKey ()
void create_browser ()
void reset_browser ()

Private Attributes

wxWebView * m_browser
long m_zoomFactor
wxString m_apikey
bool m_apikey_sent
wxString m_url
wxString m_url_deferred
PrintHostType m_host_type {htOctoPrint}
bool m_url_loaded {false}
std::unique_ptr< PrinterWebViewHandler > m_handler
bool m_reset_on_show {false}

Static Private Attributes

static Lazy< PrinterWebView > * s_lazy

Friends

class PrinterWebViewHandler

Detailed Description

Constructor & Destructor Documentation

◆ PrinterWebView()

Slic3r::GUI::PrinterWebView::PrinterWebView ( wxWindow * parent)
132 : wxPanel(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize)
133 , m_browser(nullptr)
134 , m_zoomFactor(100)
135 , m_apikey()
136 , m_apikey_sent(false)
138 , m_handler(std::make_unique<PrinterWebViewHandler>(*this))
139 {
140
141 wxBoxSizer* topsizer = new wxBoxSizer(wxVERTICAL);
142
143 // Create the webview
146
147 SetSizer(topsizer);
148
149 topsizer->Add(m_browser, wxSizerFlags().Expand().Proportion(1));
150
151 // Log backend information
152 /* m_browser->GetUserAgent() may lead crash
153 if (wxGetApp().get_mode() == comDevelop) {
154 wxLogMessage(wxWebView::GetBackendVersionInfo().ToString());
155 wxLogMessage("Backend: %s Version: %s", m_browser->GetClassInfo()->GetClassName(),
156 wxWebView::GetBackendVersionInfo().ToString());
157 wxLogMessage("User Agent: %s", m_browser->GetUserAgent());
158 }
159 */
160
161 //Connect the idle events
162 Bind(wxEVT_CLOSE_WINDOW, &PrinterWebView::OnClose, this);
163
164 }
wxWebView * m_browser
Definition PrinterWebView.hpp:65
void OnClose(wxCloseEvent &evt)
Definition PrinterWebView.cpp:283
bool m_apikey_sent
Definition PrinterWebView.hpp:68
long m_zoomFactor
Definition PrinterWebView.hpp:66
bool m_reset_on_show
Definition PrinterWebView.hpp:77
wxString m_apikey
Definition PrinterWebView.hpp:67
std::unique_ptr< PrinterWebViewHandler > m_handler
Definition PrinterWebView.hpp:76
void create_browser()
Definition PrinterWebView.cpp:182
wxString m_url_deferred
Definition PrinterWebView.hpp:71
static bool NeedsRecreateOnShow()
Definition WebView.cpp:424

References create_browser(), m_apikey, m_apikey_sent, m_browser, m_handler, m_reset_on_show, m_url_deferred, m_zoomFactor, Slic3r::make_unique(), WebView::NeedsRecreateOnShow(), OnClose(), and PrinterWebViewHandler.

Here is the call graph for this function:

◆ ~PrinterWebView()

Slic3r::GUI::PrinterWebView::~PrinterWebView ( )
virtual
167{
168 BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " Start";
169 SetEvtHandlerEnabled(false);
170 m_handler.reset();
171
172 // Destroy the webview
173 if(m_browser){
174 m_browser->Destroy();
175 m_browser = nullptr;
176 }
177
178
179 BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " End";
180}

References m_browser, and m_handler.

Member Function Documentation

◆ create_browser()

void Slic3r::GUI::PrinterWebView::create_browser ( )
private
183{
186
187#ifdef __linux__
188 inject_vue_resize_workaround(m_browser);
189
190 auto cookiesPath = boost::filesystem::path(data_dir() + "/cache/cookies.db");
191 auto wv = static_cast<WebKitWebView*>(m_browser->GetNativeBackend());
192 auto wv_ctx = webkit_web_view_get_context(wv);
193 auto cookieManager = webkit_web_context_get_cookie_manager(wv_ctx);
194 webkit_cookie_manager_set_persistent_storage(cookieManager, cookiesPath.c_str(), WEBKIT_COOKIE_PERSISTENT_STORAGE_SQLITE);
195#endif
196
197 m_browser->Bind(wxEVT_WEBVIEW_ERROR, &PrinterWebView::OnError, this);
198 m_browser->Bind(wxEVT_WEBVIEW_LOADED, &PrinterWebView::OnLoaded, this);
199 m_browser->Bind(wxEVT_WEBVIEW_NEWWINDOW, &PrinterWebView::OnNewWindow, this);
200 m_browser->Bind(wxEVT_WEBVIEW_SCRIPT_MESSAGE_RECEIVED, &PrinterWebView::OnScriptMessage, this);
201 update_mode();
202}
void OnNewWindow(wxWebViewEvent &evt)
Definition PrinterWebView.cpp:364
void OnError(wxWebViewEvent &evt)
Definition PrinterWebView.cpp:316
void update_mode()
Definition PrinterWebView.cpp:269
void OnScriptMessage(wxWebViewEvent &evt)
Definition PrinterWebView.cpp:372
void OnLoaded(wxWebViewEvent &evt)
Definition PrinterWebView.cpp:348
static wxWebView * CreateWebView(wxWindow *parent, wxString const &url)
Definition WebView.cpp:313
static void add_page_strings(wxWebView *webView)
Definition PrinterWebView.cpp:122
const std::string & data_dir()
Definition utils.cpp:365

References Slic3r::GUI::add_page_strings(), WebView::CreateWebView(), Slic3r::data_dir(), m_browser, OnError(), OnLoaded(), OnNewWindow(), OnScriptMessage(), and update_mode().

Referenced by PrinterWebView(), and reset_browser().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ensure()

PrinterWebView * Slic3r::GUI::LazyInstance< PrinterWebView >::ensure ( )
inlinestaticinherited
186{ return s_lazy ? s_lazy->ensure() : nullptr; }
Definition Lazy.hpp:180
static Self * ensure()
Definition Lazy.hpp:186

◆ if_built()

PrinterWebView * Slic3r::GUI::LazyInstance< PrinterWebView >::if_built ( )
inlinestaticinherited
183{ return s_lazy ? s_lazy->get() : nullptr; }

Referenced by Slic3r::GUI::MainFrame::init_tabpanel(), Slic3r::GUI::Plater::priv::on_tab_selection_changing(), Slic3r::GUI::GUI_App::update_internal_development(), and Slic3r::GUI::GUI_App::update_mode().

Here is the caller graph for this function:

◆ load_url()

void Slic3r::GUI::PrinterWebView::load_url ( wxString & url,
wxString apikey = "" )
226{
227// this->Show();
228// this->Raise();
229 const PrintHostType host_type = active_host_type();
230 // Selecting the tab requests the same page again; navigating would reload it and drop its state.
231 if (m_url_loaded && url == m_url && apikey == m_apikey && host_type == m_host_type)
232 return;
233
234 m_url = url;
235 m_apikey = apikey;
236 m_host_type = host_type;
237 m_apikey_sent = false;
238 m_url_loaded = false;
240
241 if (this->IsShown()) {
242 //ORCA: m_url_deferred will be cleared on load success
243 //m_url_deferred.clear();
244 m_browser->LoadURL(url);
245 } else {
246 m_url_deferred = url;
247 }
248 //m_browser->SetFocus();
249 UpdateState();
250}
bool m_url_loaded
Definition PrinterWebView.hpp:75
PrintHostType m_host_type
Definition PrinterWebView.hpp:73
void UpdateState()
Definition PrinterWebView.cpp:278
wxString m_url
Definition PrinterWebView.hpp:70
static PrintHostType active_host_type()
Definition PrinterWebView.cpp:218
std::unique_ptr< PrinterWebViewHandler > create_printer_webview_handler(PrinterWebView &owner)
Definition PrinterWebViewHandler.cpp:317
PrintHostType
Definition PrintConfig.hpp:118

References Slic3r::GUI::active_host_type(), Slic3r::GUI::create_printer_webview_handler(), m_apikey, m_apikey_sent, m_browser, m_handler, m_host_type, m_url, m_url_deferred, m_url_loaded, and UpdateState().

Here is the call graph for this function:

◆ OnClose()

void Slic3r::GUI::PrinterWebView::OnClose ( wxCloseEvent & evt)
284{
285 this->Hide();
286}

Referenced by PrinterWebView().

Here is the caller graph for this function:

◆ OnError()

void Slic3r::GUI::PrinterWebView::OnError ( wxWebViewEvent & evt)
327{
328 auto e = "unknown error";
329 switch (evt.GetInt()) {
330 case wxWEBVIEW_NAV_ERR_CONNECTION:
331 e = "wxWEBVIEW_NAV_ERR_CONNECTION";
332 break;
333 case wxWEBVIEW_NAV_ERR_CERTIFICATE:
334 e = "wxWEBVIEW_NAV_ERR_CERTIFICATE";
335 break;
336 case wxWEBVIEW_NAV_ERR_AUTH:
337 e = "wxWEBVIEW_NAV_ERR_AUTH";
338 break;
339 case wxWEBVIEW_NAV_ERR_SECURITY:
340 e = "wxWEBVIEW_NAV_ERR_SECURITY";
341 break;
342 case wxWEBVIEW_NAV_ERR_NOT_FOUND:
343 e = "wxWEBVIEW_NAV_ERR_NOT_FOUND";
344 break;
345 case wxWEBVIEW_NAV_ERR_REQUEST:
346 e = "wxWEBVIEW_NAV_ERR_REQUEST";

References m_browser.

Referenced by create_browser().

Here is the caller graph for this function:

◆ OnLoaded()

void Slic3r::GUI::PrinterWebView::OnLoaded ( wxWebViewEvent & evt)
348 :
349 e = "wxWEBVIEW_NAV_ERR_USER_CANCELLED";
350 break;
351 case wxWEBVIEW_NAV_ERR_OTHER:
352 e = "wxWEBVIEW_NAV_ERR_OTHER";
353 break;
354 }
355 BOOST_LOG_TRIVIAL(info) << __FUNCTION__<< boost::format(": error loading page %1% %2% %3% %4%") %evt.GetURL() %evt.GetTarget() %e %evt.GetString();
356}
357
358void PrinterWebView::OnLoaded(wxWebViewEvent& evt)
359{
360 // The web view's initial empty document (about:blank on WebKit) is not the requested page.
361 if (evt.GetURL().IsEmpty() || evt.GetURL() == "about:blank")
362 return;

Referenced by create_browser().

Here is the caller graph for this function:

◆ OnNewWindow()

void Slic3r::GUI::PrinterWebView::OnNewWindow ( wxWebViewEvent & evt)
368 {
369 m_handler->on_loaded(evt);
370 return;

References m_handler, m_url_deferred, and m_url_loaded.

Referenced by create_browser().

Here is the caller graph for this function:

◆ OnScriptMessage()

void Slic3r::GUI::PrinterWebView::OnScriptMessage ( wxWebViewEvent & evt)
375{
376 const wxString url = evt.GetURL();

Referenced by create_browser().

Here is the caller graph for this function:

◆ reload()

void Slic3r::GUI::PrinterWebView::reload ( )
265{
266 m_browser->Reload();
267}

References m_browser.

◆ reset_browser()

void Slic3r::GUI::PrinterWebView::reset_browser ( )
private
205{
206 m_browser->Destroy(); // also removes it from the sizer
208 GetSizer()->Add(m_browser, wxSizerFlags().Expand().Proportion(1));
209 Layout();
210
211 // OnLoaded may have cleared m_url_deferred already, so requeue the last url for Show().
212 m_apikey_sent = false;
213 m_url_loaded = false;
215}

References create_browser(), m_apikey_sent, m_browser, m_url, m_url_deferred, and m_url_loaded.

Referenced by Show().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SendAPIKey()

void Slic3r::GUI::PrinterWebView::SendAPIKey ( )
private
289{
290 if (m_apikey_sent || m_apikey.IsEmpty())
291 return;
292 m_apikey_sent = true;
293 wxString script = wxString::Format(R"(
294 // Check if window.fetch exists before overriding
295 if (window.fetch) {
296 const originalFetch = window.fetch;
297 window.fetch = function(input, init = {}) {
298 init.headers = init.headers || {};
299 init.headers['X-API-Key'] = '%s';
300 return originalFetch(input, init);
301 };
302 }
303)",
304 m_apikey);
305 m_browser->RemoveAllUserScripts();
306
307 // RemoveAllUserScripts causes WebView to forget about our script message handler,
308 // so re-add it here.
309 m_browser->RemoveScriptMessageHandler("wx");
310 // Mark before adding: on WKWebView the add yields in RunScript() after registering "wx",
311 // and CreateWebView()'s deferred add, if it runs in that yield, would register it again.
313 if (!m_browser->AddScriptMessageHandler("wx"))
314 wxLogError("Could not add script message handler");
static void MarkScriptMessageHandlerAdded(wxWebView *webView)
Definition WebView.cpp:418

References m_apikey, m_apikey_sent, m_browser, and WebView::MarkScriptMessageHandlerAdded().

Here is the call graph for this function:

◆ Show()

bool Slic3r::GUI::PrinterWebView::Show ( bool show = true)
override
253{
254 if (show && std::exchange(m_reset_on_show, false))
256 if (show && !m_url_deferred.empty()) {
257 m_browser->LoadURL(m_url_deferred);
258 //ORCA: m_url_deferred will be cleared on load success
259 //m_url_deferred.clear();
260 }
261 return wxPanel::Show(show);
262}
void reset_browser()
Definition PrinterWebView.cpp:204

References m_browser, m_reset_on_show, m_url_deferred, and reset_browser().

Here is the call graph for this function:

◆ update_mode()

void Slic3r::GUI::PrinterWebView::update_mode ( )
270{
271 m_browser->EnableAccessToDevTools(wxGetApp().app_config->get_bool("developer_mode"));
272}

References m_browser.

Referenced by create_browser().

Here is the caller graph for this function:

◆ UpdateState()

void Slic3r::GUI::PrinterWebView::UpdateState ( )

Method that retrieves the current state from the web control and updates the GUI the reflect this current state.

278 {
279 // SetTitle(m_browser->GetCurrentTitle());
280
281}

Referenced by load_url().

Here is the caller graph for this function:

◆ when_built()

void Slic3r::GUI::LazyInstance< PrinterWebView >::when_built ( std::function< void(PrinterWebView &)> fn)
inlinestaticinherited
189 {
190 if (s_lazy)
192 }
static void when_built(std::function< void(Self &)> fn)
Definition Lazy.hpp:188

◆ PrinterWebViewHandler

friend class PrinterWebViewHandler
friend

Member Data Documentation

◆ m_apikey

wxString Slic3r::GUI::PrinterWebView::m_apikey
private

◆ m_apikey_sent

bool Slic3r::GUI::PrinterWebView::m_apikey_sent
private

◆ m_browser

wxWebView* Slic3r::GUI::PrinterWebView::m_browser
private

◆ m_handler

std::unique_ptr<PrinterWebViewHandler> Slic3r::GUI::PrinterWebView::m_handler
private

◆ m_host_type

PrintHostType Slic3r::GUI::PrinterWebView::m_host_type {htOctoPrint}
private
@ htOctoPrint
Definition PrintConfig.hpp:119

Referenced by load_url().

◆ m_reset_on_show

bool Slic3r::GUI::PrinterWebView::m_reset_on_show {false}
private
77{false};

Referenced by PrinterWebView(), and Show().

◆ m_url

wxString Slic3r::GUI::PrinterWebView::m_url
private

Referenced by load_url(), and reset_browser().

◆ m_url_deferred

wxString Slic3r::GUI::PrinterWebView::m_url_deferred
private

◆ m_url_loaded

bool Slic3r::GUI::PrinterWebView::m_url_loaded {false}
private
75{false};

Referenced by load_url(), OnNewWindow(), and reset_browser().

◆ m_zoomFactor

long Slic3r::GUI::PrinterWebView::m_zoomFactor
private

Referenced by PrinterWebView().

◆ s_lazy

Lazy<PrinterWebView>* Slic3r::GUI::LazyInstance< PrinterWebView >::s_lazy
inlinestaticprivateinherited
196{ nullptr };

The documentation for this class was generated from the following files: