2011-05-20 16:42:25 +02:00
|
|
|
// Copyright (c) 2011 The Chromium Embedded Framework Authors. All rights
|
|
|
|
// reserved. Use of this source code is governed by a BSD-style license that
|
|
|
|
// can be found in the LICENSE file.
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
#include "cefclient/client_handler.h"
|
|
|
|
#include <string>
|
2011-12-23 18:36:30 +01:00
|
|
|
#include "include/cef_browser.h"
|
|
|
|
#include "include/cef_frame.h"
|
2012-10-26 22:39:24 +02:00
|
|
|
#include "cefclient/performance_test.h"
|
2012-01-10 00:46:23 +01:00
|
|
|
#include "cefclient/resource.h"
|
|
|
|
#include "cefclient/resource_util.h"
|
|
|
|
#include "cefclient/string_util.h"
|
2011-05-20 16:42:25 +02:00
|
|
|
|
|
|
|
#ifdef TEST_REDIRECT_POPUP_URLS
|
2012-01-10 00:46:23 +01:00
|
|
|
#include "cefclient/client_popup_handler.h"
|
2011-05-20 16:42:25 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
bool ClientHandler::OnBeforePopup(CefRefPtr<CefBrowser> parentBrowser,
|
|
|
|
const CefPopupFeatures& popupFeatures,
|
|
|
|
CefWindowInfo& windowInfo,
|
|
|
|
const CefString& url,
|
|
|
|
CefRefPtr<CefClient>& client,
|
2012-01-10 00:46:23 +01:00
|
|
|
CefBrowserSettings& settings) {
|
2011-05-20 16:42:25 +02:00
|
|
|
REQUIRE_UI_THREAD();
|
|
|
|
|
|
|
|
#ifdef TEST_REDIRECT_POPUP_URLS
|
|
|
|
std::string urlStr = url;
|
2012-01-10 00:46:23 +01:00
|
|
|
if (urlStr.find("chrome-devtools:") == std::string::npos) {
|
2011-05-20 16:42:25 +02:00
|
|
|
// Show all popup windows excluding DevTools in the current window.
|
|
|
|
windowInfo.m_dwStyle &= ~WS_VISIBLE;
|
|
|
|
client = new ClientPopupHandler(m_Browser);
|
|
|
|
}
|
2012-01-10 00:46:23 +01:00
|
|
|
#endif // TEST_REDIRECT_POPUP_URLS
|
2011-05-20 16:42:25 +02:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ClientHandler::OnBeforeResourceLoad(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefRequest> request,
|
|
|
|
CefString& redirectUrl,
|
|
|
|
CefRefPtr<CefStreamReader>& resourceStream,
|
|
|
|
CefRefPtr<CefResponse> response,
|
2012-01-10 00:46:23 +01:00
|
|
|
int loadFlags) {
|
2011-05-20 16:42:25 +02:00
|
|
|
REQUIRE_IO_THREAD();
|
|
|
|
|
|
|
|
std::string url = request->GetURL();
|
2012-01-10 00:46:23 +01:00
|
|
|
if (url == "http://tests/request") {
|
2011-05-20 16:42:25 +02:00
|
|
|
// Show the request contents
|
|
|
|
std::string dump;
|
|
|
|
DumpRequestContents(request, dump);
|
2012-01-10 00:46:23 +01:00
|
|
|
resourceStream = CefStreamReader::CreateForData(
|
|
|
|
static_cast<void*>(const_cast<char*>(dump.c_str())),
|
|
|
|
dump.size());
|
2011-05-20 16:42:25 +02:00
|
|
|
response->SetMimeType("text/plain");
|
|
|
|
response->SetStatus(200);
|
2012-01-10 00:46:23 +01:00
|
|
|
} else if (strstr(url.c_str(), "/ps_logo2.png") != NULL) {
|
2011-05-20 16:42:25 +02:00
|
|
|
// Any time we find "ps_logo2.png" in the URL substitute in our own image
|
|
|
|
resourceStream = GetBinaryResourceReader(IDS_LOGO);
|
|
|
|
response->SetMimeType("image/png");
|
|
|
|
response->SetStatus(200);
|
2012-01-10 00:46:23 +01:00
|
|
|
} else if (url == "http://tests/uiapp") {
|
2011-05-20 16:42:25 +02:00
|
|
|
// Show the uiapp contents
|
|
|
|
resourceStream = GetBinaryResourceReader(IDS_UIPLUGIN);
|
|
|
|
response->SetMimeType("text/html");
|
|
|
|
response->SetStatus(200);
|
2012-01-10 00:46:23 +01:00
|
|
|
} else if (url == "http://tests/osrapp") {
|
2011-05-20 16:42:25 +02:00
|
|
|
// Show the osrapp contents
|
|
|
|
resourceStream = GetBinaryResourceReader(IDS_OSRPLUGIN);
|
|
|
|
response->SetMimeType("text/html");
|
|
|
|
response->SetStatus(200);
|
2012-01-10 00:46:23 +01:00
|
|
|
} else if (url == "http://tests/localstorage") {
|
2011-05-20 16:42:25 +02:00
|
|
|
// Show the localstorage contents
|
|
|
|
resourceStream = GetBinaryResourceReader(IDS_LOCALSTORAGE);
|
|
|
|
response->SetMimeType("text/html");
|
|
|
|
response->SetStatus(200);
|
2012-01-10 00:46:23 +01:00
|
|
|
} else if (url == "http://tests/xmlhttprequest") {
|
2011-05-20 16:42:25 +02:00
|
|
|
// Show the xmlhttprequest HTML contents
|
|
|
|
resourceStream = GetBinaryResourceReader(IDS_XMLHTTPREQUEST);
|
|
|
|
response->SetMimeType("text/html");
|
|
|
|
response->SetStatus(200);
|
2012-01-10 00:46:23 +01:00
|
|
|
} else if (url == "http://tests/domaccess") {
|
2011-05-20 16:42:25 +02:00
|
|
|
// Show the domaccess HTML contents
|
|
|
|
resourceStream = GetBinaryResourceReader(IDS_DOMACCESS);
|
|
|
|
response->SetMimeType("text/html");
|
|
|
|
response->SetStatus(200);
|
2012-01-10 00:46:23 +01:00
|
|
|
} else if (strstr(url.c_str(), "/logoball.png") != NULL) {
|
2011-05-20 16:42:25 +02:00
|
|
|
// Load the "logoball.png" image resource.
|
|
|
|
resourceStream = GetBinaryResourceReader(IDS_LOGOBALL);
|
|
|
|
response->SetMimeType("image/png");
|
|
|
|
response->SetStatus(200);
|
2012-01-10 00:46:23 +01:00
|
|
|
} else if (url == "http://tests/modalmain") {
|
2011-06-14 17:09:55 +02:00
|
|
|
resourceStream = GetBinaryResourceReader(IDS_MODALMAIN);
|
|
|
|
response->SetMimeType("text/html");
|
|
|
|
response->SetStatus(200);
|
2012-01-10 00:46:23 +01:00
|
|
|
} else if (url == "http://tests/modaldialog") {
|
2011-06-14 17:09:55 +02:00
|
|
|
resourceStream = GetBinaryResourceReader(IDS_MODALDIALOG);
|
|
|
|
response->SetMimeType("text/html");
|
|
|
|
response->SetStatus(200);
|
2012-01-10 00:46:23 +01:00
|
|
|
} else if (url == "http://tests/transparency") {
|
2011-10-21 21:35:19 +02:00
|
|
|
resourceStream = GetBinaryResourceReader(IDS_TRANSPARENCY);
|
|
|
|
response->SetMimeType("text/html");
|
|
|
|
response->SetStatus(200);
|
2012-01-10 00:46:23 +01:00
|
|
|
} else if (url == "http://tests/plugin") {
|
2011-11-01 17:04:57 +01:00
|
|
|
std::string html =
|
|
|
|
"<html><body>\n"
|
|
|
|
"Client Plugin loaded by Mime Type:<br>\n"
|
|
|
|
"<embed type=\"application/x-client-plugin\" width=600 height=40>\n"
|
|
|
|
"<br><br>Client Plugin loaded by File Extension:<br>\n"
|
|
|
|
"<embed src=\"test.xcp\" width=600 height=40>\n"
|
|
|
|
// Add some extra space below the plugin to allow scrolling.
|
|
|
|
"<div style=\"height:1000px;\"> </div>\n"
|
|
|
|
"</body></html>";
|
2012-01-10 00:46:23 +01:00
|
|
|
|
|
|
|
resourceStream = CefStreamReader::CreateForData(
|
|
|
|
static_cast<void*>(const_cast<char*>(html.c_str())),
|
|
|
|
html.size());
|
2011-11-01 17:04:57 +01:00
|
|
|
response->SetMimeType("text/html");
|
|
|
|
response->SetStatus(200);
|
2012-10-26 22:39:24 +02:00
|
|
|
} else if (url == performance_test::kTestUrl) {
|
|
|
|
resourceStream = GetBinaryResourceReader(IDS_PERFORMANCE);
|
|
|
|
response->SetMimeType("text/html");
|
|
|
|
response->SetStatus(200);
|
2011-05-20 16:42:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClientHandler::OnAddressChange(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
2012-01-10 00:46:23 +01:00
|
|
|
const CefString& url) {
|
2011-05-20 16:42:25 +02:00
|
|
|
REQUIRE_UI_THREAD();
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
if (m_BrowserHwnd == browser->GetWindowHandle() && frame->IsMain()) {
|
2011-05-20 16:42:25 +02:00
|
|
|
// Set the edit window text
|
|
|
|
SetWindowText(m_EditHwnd, std::wstring(url).c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClientHandler::OnTitleChange(CefRefPtr<CefBrowser> browser,
|
2012-01-10 00:46:23 +01:00
|
|
|
const CefString& title) {
|
2011-05-20 16:42:25 +02:00
|
|
|
REQUIRE_UI_THREAD();
|
|
|
|
|
|
|
|
// Set the frame window title bar
|
|
|
|
CefWindowHandle hwnd = browser->GetWindowHandle();
|
2012-01-10 00:46:23 +01:00
|
|
|
if (m_BrowserHwnd == hwnd) {
|
2011-05-20 16:42:25 +02:00
|
|
|
// The frame window will be the parent of the browser window
|
|
|
|
hwnd = GetParent(hwnd);
|
|
|
|
}
|
|
|
|
SetWindowText(hwnd, std::wstring(title).c_str());
|
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
void ClientHandler::SendNotification(NotificationType type) {
|
2011-05-20 16:42:25 +02:00
|
|
|
UINT id;
|
2012-01-10 00:46:23 +01:00
|
|
|
switch (type) {
|
2011-05-20 16:42:25 +02:00
|
|
|
case NOTIFY_CONSOLE_MESSAGE:
|
|
|
|
id = ID_WARN_CONSOLEMESSAGE;
|
|
|
|
break;
|
|
|
|
case NOTIFY_DOWNLOAD_COMPLETE:
|
|
|
|
id = ID_WARN_DOWNLOADCOMPLETE;
|
|
|
|
break;
|
|
|
|
case NOTIFY_DOWNLOAD_ERROR:
|
|
|
|
id = ID_WARN_DOWNLOADERROR;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
PostMessage(m_MainHwnd, WM_COMMAND, id, 0);
|
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
void ClientHandler::SetLoading(bool isLoading) {
|
2011-05-20 16:42:25 +02:00
|
|
|
ASSERT(m_EditHwnd != NULL && m_ReloadHwnd != NULL && m_StopHwnd != NULL);
|
|
|
|
EnableWindow(m_EditHwnd, TRUE);
|
|
|
|
EnableWindow(m_ReloadHwnd, !isLoading);
|
|
|
|
EnableWindow(m_StopHwnd, isLoading);
|
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
void ClientHandler::SetNavState(bool canGoBack, bool canGoForward) {
|
2011-05-20 16:42:25 +02:00
|
|
|
ASSERT(m_BackHwnd != NULL && m_ForwardHwnd != NULL);
|
|
|
|
EnableWindow(m_BackHwnd, canGoBack);
|
|
|
|
EnableWindow(m_ForwardHwnd, canGoForward);
|
|
|
|
}
|
2011-08-03 17:35:51 +02:00
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
void ClientHandler::CloseMainWindow() {
|
2011-08-03 17:35:51 +02:00
|
|
|
::PostMessage(m_MainHwnd, WM_CLOSE, 0, 0);
|
|
|
|
}
|