+2017-06-07 Carlos Garcia Campos <cgarcia@igalia.com>
+
+ Remove legacy INSPECTOR_SERVER implementation
+ https://bugs.webkit.org/show_bug.cgi?id=172966
+
+ Reviewed by Žan Doberšek.
+
+ * Source/PlatformWin.cmake:
+
2017-06-07 Loïc Yhuel <loic.yhuel@softathome.com>
[CMake] Only force response files for Ninja with CMake < 3.2 on Linux
COMMAND ${CMAKE_COMMAND} -E copy_directory ${WEBINSPECTORUI_DIR}/UserInterface ${WEB_INSPECTOR_DIR}
COMMAND ${CMAKE_COMMAND} -E copy ${DERIVED_SOURCES_JAVASCRIPTCORE_DIR}/inspector/InspectorBackendCommands.js ${WEB_INSPECTOR_DIR}/Protocol
COMMAND ${CMAKE_COMMAND} -E copy ${WEBINSPECTORUI_DIR}/Localizations/en.lproj/localizedStrings.js ${WEB_INSPECTOR_DIR}
- COMMAND ${CMAKE_COMMAND} -E copy ${WEBKIT2_DIR}/UIProcess/InspectorServer/front-end/inspectorPageIndex.html ${WEB_INSPECTOR_DIR}
DEPENDS JavaScriptCore WebCore
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
+2017-06-07 Carlos Garcia Campos <cgarcia@igalia.com>
+
+ Remove legacy INSPECTOR_SERVER implementation
+ https://bugs.webkit.org/show_bug.cgi?id=172966
+
+ Reviewed by Žan Doberšek.
+
+ Remove InspectorFrontendHostStub and thr web sockets initialization.
+
+ * UserInterface/Base/InspectorFrontendHostStub.js: Removed.
+ * UserInterface/Base/Main.js:
+ (WebInspector.loaded):
+ * UserInterface/Main.html:
+ * UserInterface/Test.html:
+ * WebInspectorUI.vcxproj/WebInspectorUI.vcxproj:
+ * WebInspectorUI.vcxproj/WebInspectorUI.vcxproj.filters:
+
2017-06-07 Devin Rousso <drousso@apple.com>
Web Inspector: Add ContextMenu item to log WebSocket object to console
+++ /dev/null
-/*
- * Copyright (C) 2009 Google Inc. All rights reserved.
- * Copyright (C) 2013 Seokju Kwon (seokju.kwon@gmail.com)
- * Copyright (C) 2013 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- * * Neither the name of Google Inc. nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-if (!window.InspectorFrontendHost) {
- WebInspector.InspectorFrontendHostStub = function()
- {
- };
-
- WebInspector.InspectorFrontendHostStub.prototype = {
- // Public
-
- initializeWebSocket: function(url)
- {
- var socket = new WebSocket(url);
- socket.addEventListener("open", socketReady.bind(this));
-
- function socketReady()
- {
- this._socket = socket;
-
- this._socket.addEventListener("message", function(message) { InspectorBackend.dispatch(message.data); });
- this._socket.addEventListener("error", function(error) { console.error(error); });
-
- this._sendPendingMessagesToBackendIfNeeded();
- }
- },
-
- bringToFront: function()
- {
- this._windowVisible = true;
- },
-
- closeWindow: function()
- {
- this._windowVisible = false;
- },
-
- userInterfaceLayoutDirection: function()
- {
- return "ltr";
- },
-
- requestSetDockSide: function(side)
- {
- InspectorFrontendAPI.setDockSide(side);
- },
-
- setAttachedWindowHeight: function(height)
- {
- },
-
- setAttachedWindowWidth: function(width)
- {
- },
-
- startWindowDrag: function()
- {
- },
-
- moveWindowBy: function(x, y)
- {
- },
-
- loaded: function()
- {
- },
-
- localizedStringsURL: function()
- {
- return undefined;
- },
-
- backendCommandsURL: function()
- {
- return undefined;
- },
-
- debuggableType: function()
- {
- return "web";
- },
-
- inspectionLevel: function()
- {
- return 1;
- },
-
- inspectedURLChanged: function(title)
- {
- document.title = title;
- },
-
- copyText: function(text)
- {
- let textarea = document.createElement("textarea");
- textarea.textContent = text;
- document.body.appendChild(textarea);
- textarea.select();
-
- if (!document.execCommand("copy"))
- console.error("Could not copy to clipboard.");
-
- document.body.removeChild(textarea);
- },
-
- killText: function(text, shouldStartNewSequence)
- {
- },
-
- openInNewTab: function(url)
- {
- window.open(url, "_blank");
- },
-
- save: function(url, content, base64Encoded, forceSaveAs)
- {
- },
-
- sendMessageToBackend: function(message)
- {
- if (!this._socket) {
- if (!this._pendingMessages)
- this._pendingMessages = [];
- this._pendingMessages.push(message);
- return;
- }
-
- this._sendPendingMessagesToBackendIfNeeded();
-
- this._socket.send(message);
- },
-
- platform: function()
- {
- return (navigator.platform.match(/mac|win|linux/i) || ["other"])[0].toLowerCase();
- },
-
- beep: function()
- {
- },
-
- showContextMenu: function(event, menuObject)
- {
- new WebInspector.SoftContextMenu(menuObject).show(event);
- },
-
- unbufferedLog: function()
- {
- console.log.apply(console, arguments);
- },
-
- setZoomFactor: function(zoom)
- {
- },
-
- zoomFactor: function()
- {
- return 1;
- },
-
- // Private
-
- _sendPendingMessagesToBackendIfNeeded: function()
- {
- if (!this._pendingMessages)
- return;
-
- for (var i = 0; i < this._pendingMessages.length; ++i)
- this._socket.send(this._pendingMessages[i]);
-
- delete this._pendingMessages;
- }
- };
-
- InspectorFrontendHost = new WebInspector.InspectorFrontendHostStub;
-
- WebInspector.dontLocalizeUserInterface = true;
-}
WebInspector.loaded = function()
{
- // Initialize WebSocket to communication.
- this._initializeWebSocketIfNeeded();
-
this.debuggableType = InspectorFrontendHost.debuggableType() === "web" ? WebInspector.DebuggableType.Web : WebInspector.DebuggableType.JavaScript;
this.hasExtraDomains = false;
this.quickConsole.consoleLogVisibilityChanged(this.isShowingConsoleTab());
};
-WebInspector._initializeWebSocketIfNeeded = function()
-{
- if (!InspectorFrontendHost.initializeWebSocket)
- return;
-
- var queryParams = parseLocationQueryParameters();
-
- if ("ws" in queryParams)
- var url = "ws://" + queryParams.ws;
- else if ("page" in queryParams) {
- var page = queryParams.page;
- var host = "host" in queryParams ? queryParams.host : window.location.host;
- var url = "ws://" + host + "/devtools/page/" + page;
- }
-
- if (!url)
- return;
-
- InspectorFrontendHost.initializeWebSocket(url);
-};
-
WebInspector._updateSplitConsoleHeight = function(height)
{
const minimumHeight = 64;
<script src="External/Esprima/esprima.js"></script>
<script src="Base/WebInspector.js"></script>
- <script src="Base/InspectorFrontendHostStub.js"></script>
<script src="Base/Platform.js"></script>
<script src="Base/LinkedList.js"></script>
<script src="Base/ListMultimap.js"></script>
<script src="External/Esprima/esprima.js"></script>
<script src="Base/WebInspector.js"></script>
- <script src="Base/InspectorFrontendHostStub.js"></script>
<script src="Base/Platform.js"></script>
<script src="Base/LinkedList.js"></script>
<script src="Base/ListMultimap.js"></script>
-<?xml version="1.0" encoding="utf-8"?>
+<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="DebugSuffix|Win32">
<None Include="..\UserInterface\IndeterminateProgressSpinner.js" />
<None Include="..\UserInterface\InspectorBackend.js" />
<None Include="..\UserInterface\InspectorFrontendAPI.js" />
- <None Include="..\UserInterface\InspectorFrontendHostStub.js" />
<None Include="..\UserInterface\InspectorObserver.js" />
<None Include="..\UserInterface\InstrumentIcons.css" />
<None Include="..\UserInterface\InstrumentSidebarPanel.css" />
<None Include="..\UserInterface\InspectorFrontendAPI.js">
<Filter>UserInterface</Filter>
</None>
- <None Include="..\UserInterface\InspectorFrontendHostStub.js">
- <Filter>UserInterface</Filter>
- </None>
<None Include="..\UserInterface\InspectorObserver.js">
<Filter>UserInterface</Filter>
</None>
"${WEBKIT2_DIR}/UIProcess/Databases"
"${WEBKIT2_DIR}/UIProcess/Downloads"
"${WEBKIT2_DIR}/UIProcess/Gamepad"
- "${WEBKIT2_DIR}/UIProcess/InspectorServer"
"${WEBKIT2_DIR}/UIProcess/Launcher"
"${WEBKIT2_DIR}/UIProcess/Network"
"${WEBKIT2_DIR}/UIProcess/Network/CustomProtocols"
UIProcess/Gamepad/UIGamepad.cpp
UIProcess/Gamepad/UIGamepadProvider.cpp
- UIProcess/InspectorServer/HTTPRequest.cpp
- UIProcess/InspectorServer/WebInspectorServer.cpp
- UIProcess/InspectorServer/WebSocketServer.cpp
- UIProcess/InspectorServer/WebSocketServerConnection.cpp
-
UIProcess/Launcher/ProcessLauncher.cpp
UIProcess/Network/CustomProtocols/LegacyCustomProtocolManagerProxy.cpp
+2017-06-07 Carlos Garcia Campos <cgarcia@igalia.com>
+
+ Remove legacy INSPECTOR_SERVER implementation
+ https://bugs.webkit.org/show_bug.cgi?id=172966
+
+ Reviewed by Žan Doberšek.
+
+ * CMakeLists.txt:
+ * Platform/Logging.h:
+ * PlatformWPE.cmake:
+ * UIProcess/InspectorServer/HTTPRequest.cpp: Removed.
+ * UIProcess/InspectorServer/HTTPRequest.h: Removed.
+ * UIProcess/InspectorServer/WebInspectorServer.cpp: Removed.
+ * UIProcess/InspectorServer/WebInspectorServer.h: Removed.
+ * UIProcess/InspectorServer/WebSocketServer.cpp: Removed.
+ * UIProcess/InspectorServer/WebSocketServer.h: Removed.
+ * UIProcess/InspectorServer/WebSocketServerClient.h: Removed.
+ * UIProcess/InspectorServer/WebSocketServerConnection.cpp: Removed.
+ * UIProcess/InspectorServer/WebSocketServerConnection.h: Removed.
+ * UIProcess/InspectorServer/front-end/inspectorPageIndex.html: Removed.
+ * UIProcess/InspectorServer/soup/WebSocketServerSoup.cpp: Removed.
+ * UIProcess/WebInspectorProxy.cpp:
+ (WebKit::WebInspectorProxy::invalidate):
+ * UIProcess/WebInspectorProxy.h:
+ * UIProcess/WebInspectorProxy.messages.in:
+ * UIProcess/WebPageProxy.cpp:
+ (WebKit::WebPageProxy::initializeWebPage):
+ (WebKit::WebPageProxy::preferencesDidChange):
+ * UIProcess/wpe/WebProcessPoolWPE.cpp:
+ * WebProcess/WebPage/WebInspector.cpp:
+ (WebKit::WebInspector::sendMessageToFrontend):
+ * WebProcess/WebPage/WebInspector.h:
+ * WebProcess/WebPage/WebInspector.messages.in:
+
2017-06-07 Dan Bernstein <mitz@apple.com>
[Cocoa] additionalReadAccessAllowedURLs doesn’t preserve non-Latin-1 paths
M(IconDatabase) \
M(IDB) \
M(IndexedDB) \
- M(InspectorServer) \
M(IPC) \
M(KeyHandling) \
M(Layers) \
UIProcess/API/wpe/WPEView.cpp
UIProcess/API/wpe/WPEViewClient.cpp
- UIProcess/InspectorServer/soup/WebSocketServerSoup.cpp
-
UIProcess/Launcher/wpe/ProcessLauncherWPE.cpp
UIProcess/Plugins/unix/PluginInfoStoreUnix.cpp
VERBATIM
)
-add_custom_command(
- OUTPUT ${DERIVED_SOURCES_WEBINSPECTORUI_DIR}/WebKit2InspectorGResourceBundle.c
- DEPENDS ${WEBKIT2_DIR}/UIProcess/API/wpe/WebKit2InspectorGResourceBundle.xml
- ${WEBKIT2_DIR}/UIProcess/InspectorServer/front-end/inspectorPageIndex.html
- COMMAND glib-compile-resources --generate --sourcedir=${WEBKIT2_DIR}/UIProcess/InspectorServer/front-end --target=${DERIVED_SOURCES_WEBINSPECTORUI_DIR}/WebKit2InspectorGResourceBundle.c ${WEBKIT2_DIR}/UIProcess/API/wpe/WebKit2InspectorGResourceBundle.xml
- VERBATIM
-)
-
list(APPEND WPEWebInspectorResources_DERIVED_SOURCES
${DERIVED_SOURCES_WEBINSPECTORUI_DIR}/InspectorGResourceBundle.c
- ${DERIVED_SOURCES_WEBINSPECTORUI_DIR}/WebKit2InspectorGResourceBundle.c
)
list(APPEND WPEWebInspectorResources_LIBRARIES
+++ /dev/null
-/*
- * Copyright (C) 2011 Apple Inc. All Rights Reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "config.h"
-#include "HTTPRequest.h"
-
-#if ENABLE(INSPECTOR_SERVER)
-
-#include <wtf/text/CString.h>
-#include <wtf/text/StringView.h>
-
-using namespace WebCore;
-
-namespace WebKit {
-
-RefPtr<HTTPRequest> HTTPRequest::parseHTTPRequestFromBuffer(const char* data, size_t length, String& failureReason)
-{
- if (!length) {
- failureReason = "No data to parse.";
- return nullptr;
- }
-
- // Request we will be building.
- auto request = HTTPRequest::create();
-
- // Advance a pointer through the data as needed.
- const char* pos = data;
- size_t remainingLength = length;
-
- // 1. Parse Method + URL.
- size_t requestLineLength = request->parseRequestLine(pos, remainingLength, failureReason);
- if (!requestLineLength)
- return nullptr;
- pos += requestLineLength;
- remainingLength -= requestLineLength;
-
- // 2. Parse HTTP Headers.
- size_t headersLength = request->parseHeaders(pos, remainingLength, failureReason);
- if (!headersLength)
- return nullptr;
- pos += headersLength;
- remainingLength -= headersLength;
-
- // 3. Parse HTTP Data.
- size_t dataLength = request->parseRequestBody(pos, remainingLength);
- pos += dataLength;
- remainingLength -= dataLength;
-
- // We should have processed the entire input.
- ASSERT(!remainingLength);
- return WTFMove(request);
-}
-
-size_t HTTPRequest::parseRequestLine(const char* data, size_t length, String& failureReason)
-{
- String url;
- size_t result = parseHTTPRequestLine(data, length, failureReason, m_requestMethod, url, m_httpVersion);
- m_url = URL(URL(), url);
- return result;
-}
-
-size_t HTTPRequest::parseHeaders(const char* data, size_t length, String& failureReason)
-{
- const char* p = data;
- const char* end = data + length;
- StringView name;
- String value;
- for (; p < data + length; p++) {
- size_t consumedLength = parseHTTPHeader(p, end - p, failureReason, name, value);
- if (!consumedLength)
- return 0;
- p += consumedLength;
- if (name.isEmpty())
- break;
- m_headerFields.add(name.toString(), value);
- }
-
- // If we got here and "name" is empty, it means the headers are valid and ended with a
- // blank line (parseHTTPHeader returns "name" as empty if parsing a blank line), otherwise
- // the headers didn't end with a blank line and we have an invalid request.
- // See also http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html
- if (!name.isEmpty())
- return 0;
- return p - data;
-}
-
-size_t HTTPRequest::parseRequestBody(const char* data, size_t length)
-{
- return parseHTTPRequestBody(data, length, m_body);
-}
-
-HTTPRequest::HTTPRequest()
- : m_httpVersion(WebCore::Unknown)
-{
-}
-
-HTTPRequest::HTTPRequest(const String& requestMethod, const URL& url, HTTPVersion version)
- : m_url(url)
- , m_httpVersion(version)
- , m_requestMethod(requestMethod)
-{
-}
-
-HTTPRequest::~HTTPRequest()
-{
-}
-
-} // namespace WebCore
-
-#endif // ENABLE(INSPECTOR_SERVER)
+++ /dev/null
-/*
- * Copyright (C) 2010 Google Inc. All rights reserved.
- * Copyright (C) 2011 Apple Inc. All Rights Reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- * * Neither the name of Google Inc. nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef HTTPRequest_h
-#define HTTPRequest_h
-
-#if ENABLE(INSPECTOR_SERVER)
-
-#include <WebCore/HTTPHeaderMap.h>
-#include <WebCore/HTTPParsers.h>
-#include <WebCore/URL.h>
-#include <wtf/RefCounted.h>
-#include <wtf/RefPtr.h>
-#include <wtf/text/WTFString.h>
-
-namespace WebKit {
-
-class HTTPRequest : public RefCounted<HTTPRequest> {
-public:
- static Ref<HTTPRequest> create() { return adoptRef(*new HTTPRequest()); }
- static Ref<HTTPRequest> create(const String& requestMethod, const WebCore::URL& url, WebCore::HTTPVersion version) { return adoptRef(*new HTTPRequest(requestMethod, url, version)); }
- static RefPtr<HTTPRequest> parseHTTPRequestFromBuffer(const char* data, size_t length, String& failureReason);
- virtual ~HTTPRequest();
-
- String requestMethod() const { return m_requestMethod; }
- void setRequestMethod(const String& method) { m_requestMethod = method; }
-
- WebCore::URL url() const { return m_url; }
- void setURL(const WebCore::URL& url) { m_url = url; }
-
- const Vector<unsigned char>& body() const { return m_body; }
-
- const WebCore::HTTPHeaderMap& headerFields() const { return m_headerFields; }
- void addHeaderField(const AtomicString& name, const String& value) { m_headerFields.add(name, value); }
- void addHeaderField(const char* name, const String& value) { m_headerFields.add(name, value); }
-
-protected:
- HTTPRequest();
- HTTPRequest(const String& requestMethod, const WebCore::URL&, WebCore::HTTPVersion);
-
- // Parsing helpers.
- size_t parseRequestLine(const char* data, size_t length, String& failureReason);
- size_t parseHeaders(const char* data, size_t length, String& failureReason);
- size_t parseRequestBody(const char* data, size_t length);
-
- WebCore::URL m_url;
- WebCore::HTTPVersion m_httpVersion;
- String m_requestMethod;
- WebCore::HTTPHeaderMap m_headerFields;
- Vector<unsigned char> m_body;
-};
-
-} // namespace WebKit
-
-#endif // ENABLE(INSPECTOR_SERVER)
-
-#endif // HTTPRequest_h
+++ /dev/null
-/*
- * Copyright (C) 2011 Apple Inc. All Rights Reserved.
- * Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies)
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "config.h"
-
-#if ENABLE(INSPECTOR_SERVER)
-
-#include "WebInspectorServer.h"
-
-#include "HTTPHeaderNames.h"
-#include "HTTPRequest.h"
-#include "WebInspectorProxy.h"
-#include "WebSocketServerConnection.h"
-
-using namespace WebCore;
-
-namespace WebKit {
-
-static unsigned pageIdFromRequestPath(const String& path)
-{
- size_t start = path.reverseFind('/');
- String numberString = path.substring(start + 1, path.length() - start - 1);
-
- bool ok = false;
- unsigned number = numberString.toUIntStrict(&ok);
- if (!ok)
- return 0;
- return number;
-}
-
-WebInspectorServer& WebInspectorServer::singleton()
-{
- static WebInspectorServer& server = *new WebInspectorServer;
- return server;
-}
-
-WebInspectorServer::WebInspectorServer()
- : WebSocketServer(this)
- , m_nextAvailablePageId(1)
-{
-}
-
-WebInspectorServer::~WebInspectorServer()
-{
- // Close any remaining open connections.
- HashMap<unsigned, WebSocketServerConnection*>::iterator end = m_connectionMap.end();
- for (HashMap<unsigned, WebSocketServerConnection*>::iterator it = m_connectionMap.begin(); it != end; ++it) {
- WebSocketServerConnection* connection = it->value;
- WebInspectorProxy* client = m_clientMap.get(connection->identifier());
- closeConnection(client, connection);
- }
-}
-
-int WebInspectorServer::registerPage(WebInspectorProxy* client)
-{
-#ifndef ASSERT_DISABLED
- ClientMap::iterator end = m_clientMap.end();
- for (ClientMap::iterator it = m_clientMap.begin(); it != end; ++it)
- ASSERT(it->value != client);
-#endif
-
- int pageId = m_nextAvailablePageId++;
- m_clientMap.set(pageId, client);
- return pageId;
-}
-
-void WebInspectorServer::unregisterPage(int pageId)
-{
- m_clientMap.remove(pageId);
- WebSocketServerConnection* connection = m_connectionMap.get(pageId);
- if (connection)
- closeConnection(0, connection);
-}
-
-String WebInspectorServer::inspectorUrlForPageID(int)
-{
- return String();
-}
-
-void WebInspectorServer::sendMessageOverConnection(unsigned pageIdForConnection, const String& message)
-{
- WebSocketServerConnection* connection = m_connectionMap.get(pageIdForConnection);
- if (connection)
- connection->sendWebSocketMessage(message);
-}
-
-void WebInspectorServer::didReceiveUnrecognizedHTTPRequest(WebSocketServerConnection* connection, Ref<HTTPRequest>&& request)
-{
- // request->url() contains only the path extracted from the HTTP request line
- // and URL is poor at parsing incomplete URLs, so extract the interesting parts manually.
- String path = request->url();
- size_t pathEnd = path.find('?');
- if (pathEnd == notFound)
- pathEnd = path.find('#');
- if (pathEnd != notFound)
- path.truncate(pathEnd);
-
- // Ask for the complete payload in memory for the sake of simplicity. A more efficient way would be
- // to ask for header data and then let the platform abstraction write the payload straight on the connection.
- Vector<char> body;
- String contentType;
- bool found = platformResourceForPath(path, body, contentType);
-
- HTTPHeaderMap headerFields;
- headerFields.set(HTTPHeaderName::Connection, "close");
- headerFields.set(HTTPHeaderName::ContentLength, String::number(body.size()));
- if (found)
- headerFields.set(HTTPHeaderName::ContentType, contentType);
-
- // Send when ready and close immediately afterwards.
- connection->sendHTTPResponseHeader(found ? 200 : 404, found ? "OK" : "Not Found", headerFields);
- connection->sendRawData(body.data(), body.size());
- connection->shutdownAfterSendOrNow();
-}
-
-bool WebInspectorServer::didReceiveWebSocketUpgradeHTTPRequest(WebSocketServerConnection*, Ref<HTTPRequest>&& request)
-{
- String path = request->url();
-
- // NOTE: Keep this in sync with WebCore/inspector/front-end/inspector.js.
- DEPRECATED_DEFINE_STATIC_LOCAL(const String, inspectorWebSocketConnectionPathPrefix, (ASCIILiteral("/devtools/page/")));
-
- // Unknown path requested.
- if (!path.startsWith(inspectorWebSocketConnectionPathPrefix))
- return false;
-
- int pageId = pageIdFromRequestPath(path);
- // Invalid page id.
- if (!pageId)
- return false;
-
- // There is no client for that page id.
- WebInspectorProxy* client = m_clientMap.get(pageId);
- if (!client)
- return false;
-
- return true;
-}
-
-void WebInspectorServer::didEstablishWebSocketConnection(WebSocketServerConnection* connection, Ref<HTTPRequest>&& request)
-{
- String path = request->url();
- unsigned pageId = pageIdFromRequestPath(path);
- ASSERT(pageId);
-
- // Ignore connections to a page that already have a remote inspector connected.
- if (m_connectionMap.contains(pageId)) {
- LOG_ERROR("A remote inspector connection already exist for page ID %d. Ignoring.", pageId);
- connection->shutdownNow();
- return;
- }
-
- // Map the pageId to the connection in case we need to close the connection locally.
- connection->setIdentifier(pageId);
- m_connectionMap.set(pageId, connection);
-
- WebInspectorProxy* client = m_clientMap.get(pageId);
- client->remoteFrontendConnected();
-}
-
-void WebInspectorServer::didReceiveWebSocketMessage(WebSocketServerConnection* connection, const String& message)
-{
- // Dispatch incoming remote message locally.
- unsigned pageId = connection->identifier();
- ASSERT(pageId);
- WebInspectorProxy* client = m_clientMap.get(pageId);
- client->dispatchMessageFromRemoteFrontend(message);
-}
-
-void WebInspectorServer::didCloseWebSocketConnection(WebSocketServerConnection* connection)
-{
- // Connection has already shut down.
- unsigned pageId = connection->identifier();
- if (!pageId)
- return;
-
- // The socket closing means the remote side has caused the close.
- WebInspectorProxy* client = m_clientMap.get(pageId);
- closeConnection(client, connection);
-}
-
-void WebInspectorServer::closeConnection(WebInspectorProxy* client, WebSocketServerConnection* connection)
-{
- // Local side cleanup.
- if (client)
- client->remoteFrontendDisconnected();
-
- // Remote side cleanup.
- m_connectionMap.remove(connection->identifier());
- connection->setIdentifier(0);
- connection->shutdownNow();
-}
-
-}
-
-#endif // ENABLE(INSPECTOR_SERVER)
+++ /dev/null
-/*
- * Copyright (C) 2011 Apple Inc. All Rights Reserved.
- * Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies)
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#pragma once
-
-#if ENABLE(INSPECTOR_SERVER)
-
-#include "WebSocketServer.h"
-#include "WebSocketServerClient.h"
-#include <wtf/HashMap.h>
-#include <wtf/text/WTFString.h>
-
-namespace WebKit {
-
-class WebInspectorProxy;
-
-class WebInspectorServer final : public WebSocketServer, public WebSocketServerClient {
-public:
- typedef HashMap<unsigned, WebInspectorProxy*> ClientMap;
- static WebInspectorServer& singleton();
-
- // Page registry to manage known pages.
- int registerPage(WebInspectorProxy* client);
- void unregisterPage(int pageId);
- String inspectorUrlForPageID(int pageId);
- void sendMessageOverConnection(unsigned pageIdForConnection, const String& message);
-
-private:
- WebInspectorServer();
- ~WebInspectorServer();
-
- // WebSocketServerClient implementation. Events coming from remote connections.
- void didReceiveUnrecognizedHTTPRequest(WebSocketServerConnection*, Ref<HTTPRequest>&&) final;
- bool didReceiveWebSocketUpgradeHTTPRequest(WebSocketServerConnection*, Ref<HTTPRequest>&&) final;
- void didEstablishWebSocketConnection(WebSocketServerConnection*, Ref<HTTPRequest>&&) final;
- void didReceiveWebSocketMessage(WebSocketServerConnection*, const String& message) final;
- void didCloseWebSocketConnection(WebSocketServerConnection*) final;
-
- bool platformResourceForPath(const String& path, Vector<char>& data, String& contentType);
-
- void closeConnection(WebInspectorProxy*, WebSocketServerConnection*);
-
- unsigned m_nextAvailablePageId;
- ClientMap m_clientMap;
- HashMap<unsigned, WebSocketServerConnection*> m_connectionMap;
-};
-
-}
-
-#endif // ENABLE(INSPECTOR_SERVER)
+++ /dev/null
-/*
- * Copyright (C) 2011 Apple Inc. All Rights Reserved.
- * Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies)
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "config.h"
-
-#if ENABLE(INSPECTOR_SERVER)
-
-#include "WebSocketServer.h"
-
-#include "WebSocketServerConnection.h"
-#include <WebCore/SocketStreamHandle.h>
-
-using namespace WebCore;
-
-namespace WebKit {
-
-WebSocketServer::WebSocketServer(WebSocketServerClient* client)
- : m_state(Closed)
- , m_client(client)
- , m_port(0)
-{
- platformInitialize();
-}
-
-WebSocketServer::~WebSocketServer()
-{
- close();
-}
-
-bool WebSocketServer::listen(const String& bindAddress, unsigned short port)
-{
- ASSERT(port);
-
- if (m_state == Listening)
- return false;
-
- bool isNowListening = platformListen(bindAddress, port);
- if (isNowListening) {
- m_bindAddress = bindAddress;
- m_port = port;
- m_state = Listening;
- }
- return isNowListening;
-}
-
-void WebSocketServer::close()
-{
- if (m_state == Closed)
- return;
-
- platformClose();
-
- m_port = 0;
- m_bindAddress = String();
-}
-
-void WebSocketServer::didAcceptConnection(std::unique_ptr<WebSocketServerConnection> connection)
-{
- m_connections.append(WTFMove(connection));
-}
-
-void WebSocketServer::didCloseWebSocketServerConnection(WebSocketServerConnection* connection)
-{
- for (auto it = m_connections.begin(), end = m_connections.end(); it != end; ++it) {
- if (it->get() == connection) {
- m_connections.remove(it);
- return;
- }
- }
-
- ASSERT_NOT_REACHED();
-}
-
-}
-
-#endif // ENABLE(INSPECTOR_SERVER)
+++ /dev/null
-/*
- * Copyright (C) 2011 Apple Inc. All Rights Reserved.
- * Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies)
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef WebSocketServer_h
-#define WebSocketServer_h
-
-#if ENABLE(INSPECTOR_SERVER)
-
-#include <memory>
-#include <wtf/Deque.h>
-#include <wtf/text/WTFString.h>
-
-#if USE(SOUP)
-#include <gio/gio.h>
-#include <wtf/glib/GRefPtr.h>
-#endif
-
-namespace WebCore {
-class SocketStreamHandle;
-}
-
-namespace WebKit {
-
-class WebSocketServerClient;
-class WebSocketServerConnection;
-
-class WebSocketServer {
-public:
- enum ServerState { Closed, Listening };
- explicit WebSocketServer(WebSocketServerClient*);
- virtual ~WebSocketServer();
-
- // Server operations.
- bool listen(const String& bindAddress, unsigned short port);
- String bindAddress() const { return m_bindAddress; };
- unsigned short port() const { return m_port; };
- ServerState serverState() const { return m_state; };
- void close();
-
- WebSocketServerClient* client() const { return m_client; }
- void didAcceptConnection(std::unique_ptr<WebSocketServerConnection>);
-
-private:
- void didCloseWebSocketServerConnection(WebSocketServerConnection*);
-
- void platformInitialize();
- bool platformListen(const String& bindAddress, unsigned short port);
- void platformClose();
-
- ServerState m_state;
- Deque<std::unique_ptr<WebSocketServerConnection>> m_connections;
- WebSocketServerClient* m_client;
- String m_bindAddress;
- unsigned short m_port;
-#if USE(SOUP)
- GRefPtr<GSocketService> m_socketService;
-#endif
- friend class WebSocketServerConnection;
-};
-
-}
-
-#endif // ENABLE(INSPECTOR_SERVER)
-
-#endif // WebSocketServer_h
+++ /dev/null
-/*
- * Copyright (C) 2011 Apple Inc. All Rights Reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef WebSocketServerClient_h
-#define WebSocketServerClient_h
-
-#if ENABLE(INSPECTOR_SERVER)
-
-#include "HTTPRequest.h"
-#include <wtf/Ref.h>
-#include <wtf/text/WTFString.h>
-
-namespace WebKit {
-
-class WebSocketServerConnection;
-
-class WebSocketServerClient {
-public:
- virtual ~WebSocketServerClient() { }
-
- // Received an HTTP request but didn't know what to do with it.
- virtual void didReceiveUnrecognizedHTTPRequest(WebSocketServerConnection*, Ref<HTTPRequest>&&) { }
-
- // Received a WebSocket Upgrade HTTP request. Ask if we should handle it and upgrade.
- virtual bool didReceiveWebSocketUpgradeHTTPRequest(WebSocketServerConnection*, Ref<HTTPRequest>&&) { return true; }
-
- // Established a WebSocket Connection.
- virtual void didEstablishWebSocketConnection(WebSocketServerConnection*, Ref<HTTPRequest>&&) { }
-
- // Received a WebSocket message.
- virtual void didReceiveWebSocketMessage(WebSocketServerConnection*, const String&) { }
-
- // WebSocket Connection closed.
- virtual void didCloseWebSocketConnection(WebSocketServerConnection*) { }
-};
-
-}
-
-#endif // ENABLE(INSPECTOR_SERVER)
-
-#endif // WebSocketServerClient_h
+++ /dev/null
-/*
- * Copyright (C) 2011 Apple Inc. All Rights Reserved.
- * Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies)
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "config.h"
-
-#if ENABLE(INSPECTOR_SERVER)
-
-#include "WebSocketServerConnection.h"
-
-#include "HTTPHeaderNames.h"
-#include "HTTPRequest.h"
-#include "WebSocketServer.h"
-#include "WebSocketServerClient.h"
-#include <WebCore/NotImplemented.h>
-#include <WebCore/SocketStreamError.h>
-#include <WebCore/SocketStreamHandle.h>
-#include <WebCore/WebSocketChannel.h>
-#include <WebCore/WebSocketHandshake.h>
-#include <wtf/Function.h>
-#include <wtf/text/CString.h>
-#include <wtf/text/StringBuilder.h>
-
-using namespace WebCore;
-
-namespace WebKit {
-
-WebSocketServerConnection::WebSocketServerConnection(WebSocketServerClient* client, WebSocketServer* server)
- : m_server(server)
- , m_client(client)
-{
-}
-
-WebSocketServerConnection::~WebSocketServerConnection()
-{
- shutdownNow();
-}
-
-void WebSocketServerConnection::setSocketHandle(Ref<SocketStreamHandle>&& socket)
-{
- ASSERT(!m_socket);
- m_socket = WTFMove(socket);
-}
-
-void WebSocketServerConnection::shutdownNow()
-{
- if (!m_socket)
- return;
- auto socket = WTFMove(m_socket);
- socket->close();
- m_shutdownAfterSend = false;
-}
-
-void WebSocketServerConnection::shutdownAfterSendOrNow()
-{
- if (m_socket->bufferedAmount()) {
- m_shutdownAfterSend = true;
- return;
- }
-
- shutdownNow();
-}
-
-void WebSocketServerConnection::sendWebSocketMessage(const String& message)
-{
- CString payload = message.utf8();
- const bool final = true, compress = false, masked = false;
- WebSocketFrame frame(WebSocketFrame::OpCodeText, final, compress, masked, payload.data(), payload.length());
-
- Vector<char> frameData;
- frame.makeFrameData(frameData);
-
- m_socket->sendData(frameData.data(), frameData.size(), [](bool) { });
-}
-
-void WebSocketServerConnection::sendHTTPResponseHeader(int statusCode, const String& statusText, const HTTPHeaderMap& headerFields)
-{
- StringBuilder builder;
- builder.appendLiteral("HTTP/1.1 ");
- builder.appendNumber(statusCode);
- builder.append(' ');
- builder.append(statusText);
- builder.appendLiteral("\r\n");
- HTTPHeaderMap::const_iterator end = headerFields.end();
- for (HTTPHeaderMap::const_iterator it = headerFields.begin(); it != end; ++it) {
- builder.append(it->key);
- builder.appendLiteral(": ");
- builder.append(it->value);
- builder.appendLiteral("\r\n");
- }
- builder.appendLiteral("\r\n");
-
- CString header = builder.toString().latin1();
- m_socket->sendData(header.data(), header.length(), [](bool) { });
-}
-
-void WebSocketServerConnection::sendRawData(const char* data, size_t length)
-{
- m_socket->sendData(data, length, [](bool) { });
-}
-
-void WebSocketServerConnection::didCloseSocketStream(SocketStreamHandle&)
-{
- // Destroy the SocketStreamHandle now to prevent closing an already closed socket later.
- m_socket = nullptr;
-
- // Web Socket Mode.
- if (m_mode == WebSocket)
- m_client->didCloseWebSocketConnection(this);
-
- // Tell the server to get rid of this.
- m_server->didCloseWebSocketServerConnection(this);
-}
-
-void WebSocketServerConnection::didReceiveSocketStreamData(SocketStreamHandle&, const char* data, size_t length)
-{
- // Each didReceiveData call adds more data to our buffer.
- // We clear the buffer when we have handled data from it.
- m_bufferedData.append(data, length);
-
- switch (m_mode) {
- case HTTP:
- readHTTPMessage();
- break;
- case WebSocket:
- readWebSocketFrames();
- break;
- default:
- // For any new modes added in the future.
- ASSERT_NOT_REACHED();
- }
-}
-
-void WebSocketServerConnection::didUpdateBufferedAmount(SocketStreamHandle&, size_t)
-{
- if (m_shutdownAfterSend && !m_socket->bufferedAmount())
- shutdownNow();
-}
-
-void WebSocketServerConnection::readHTTPMessage()
-{
- String failureReason;
- RefPtr<HTTPRequest> request = HTTPRequest::parseHTTPRequestFromBuffer(m_bufferedData.data(), m_bufferedData.size(), failureReason);
- if (!request)
- return;
-
- // Assume all the input has been read if we are reading an HTTP Request.
- m_bufferedData.clear();
-
- // If this is a WebSocket request, perform the WebSocket Handshake.
- const HTTPHeaderMap& headers = request->headerFields();
- String upgradeHeaderValue = headers.get(HTTPHeaderName::Upgrade);
- if (upgradeHeaderValue == "websocket") {
- upgradeToWebSocketServerConnection(request.releaseNonNull());
- return;
- }
- if (upgradeHeaderValue == "WebSocket") {
- LOG_ERROR("WebSocket protocol version < Hybi-10 not supported. Upgrade your client.");
- return;
- }
-
- // Otherwise, this is an HTTP Request we don't know how to deal with.
- m_client->didReceiveUnrecognizedHTTPRequest(this, request.releaseNonNull());
-}
-
-void WebSocketServerConnection::upgradeToWebSocketServerConnection(Ref<HTTPRequest>&& request)
-{
- ASSERT(m_mode == HTTP);
- m_mode = WebSocket;
- // Ask the client if we should upgrade for this or not.
- if (!m_client->didReceiveWebSocketUpgradeHTTPRequest(this, request.copyRef())) {
- shutdownNow();
- return;
- }
-
- // Build and send the WebSocket handshake response.
- const HTTPHeaderMap& requestHeaders = request->headerFields();
- String accept = WebSocketHandshake::getExpectedWebSocketAccept(requestHeaders.get(HTTPHeaderName::SecWebSocketKey));
- HTTPHeaderMap responseHeaders;
- responseHeaders.add("Upgrade", requestHeaders.get(HTTPHeaderName::Upgrade));
- responseHeaders.add("Connection", requestHeaders.get(HTTPHeaderName::Connection));
- responseHeaders.add("Sec-WebSocket-Accept", accept);
-
- sendHTTPResponseHeader(101, "WebSocket Protocol Handshake", responseHeaders);
-
- m_client->didEstablishWebSocketConnection(this, WTFMove(request));
-}
-
-void WebSocketServerConnection::readWebSocketFrames()
-{
- while (true) {
- bool didReadOneFrame = readWebSocketFrame();
- if (!didReadOneFrame)
- break;
- if (m_bufferedData.isEmpty())
- break;
- }
-}
-
-bool WebSocketServerConnection::readWebSocketFrame()
-{
- WebSocketFrame frame;
- const char* frameEnd;
- String errorString;
- WebSocketFrame::ParseFrameResult result = WebSocketFrame::parseFrame(m_bufferedData.data(), m_bufferedData.size(), frame, frameEnd, errorString);
-
- // Incomplete frame. Wait to receive more data.
- if (result == WebSocketFrame::FrameIncomplete)
- return false;
-
- if (result == WebSocketFrame::FrameError) {
- shutdownNow();
- } else if (frame.opCode == WebSocketFrame::OpCodeText) {
- // Delegate Text frames to our client.
- String msg = String::fromUTF8(frame.payload, frame.payloadLength);
- m_client->didReceiveWebSocketMessage(this, msg);
- } else
- notImplemented();
-
- // Remove the frame from our buffer.
- m_bufferedData.remove(0, frameEnd - m_bufferedData.data());
-
- return true;
-}
-
-}
-
-#endif // ENABLE(INSPECTOR_SERVER)
+++ /dev/null
-/*
- * Copyright (C) 2011 Apple Inc. All Rights Reserved.
- * Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies)
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#pragma once
-
-#if ENABLE(INSPECTOR_SERVER)
-
-#include <WebCore/SocketStreamHandleClient.h>
-#include <wtf/Ref.h>
-#include <wtf/RefPtr.h>
-#include <wtf/Vector.h>
-#include <wtf/text/WTFString.h>
-
-namespace WebCore {
-class HTTPHeaderMap;
-class SocketStreamError;
-class SocketStreamHandle;
-}
-
-namespace WebKit {
-
-class HTTPRequest;
-class WebSocketServer;
-class WebSocketServerClient;
-
-class WebSocketServerConnection final : public WebCore::SocketStreamHandleClient {
-public:
- enum WebSocketServerMode { HTTP, WebSocket };
- WebSocketServerConnection(WebSocketServerClient*, WebSocketServer*);
- virtual ~WebSocketServerConnection();
-
- unsigned identifier() const { return m_identifier; }
- void setIdentifier(unsigned id) { m_identifier = id; }
- void setSocketHandle(Ref<WebCore::SocketStreamHandle>&&);
-
- // Sending data over the connection.
- void sendWebSocketMessage(const String& message);
- void sendHTTPResponseHeader(int statusCode, const String& statusText, const WebCore::HTTPHeaderMap& headerFields);
- void sendRawData(const char* data, size_t length);
-
- // Terminating the connection.
- void shutdownNow();
- void shutdownAfterSendOrNow();
-
-private:
- // SocketStreamHandleClient implementation.
- void didOpenSocketStream(WebCore::SocketStreamHandle&) final { }
- void didCloseSocketStream(WebCore::SocketStreamHandle&) final;
- void didReceiveSocketStreamData(WebCore::SocketStreamHandle&, const char*, size_t) final;
- void didFailToReceiveSocketStreamData(WebCore::SocketStreamHandle&) final { }
- void didUpdateBufferedAmount(WebCore::SocketStreamHandle&, size_t bufferedAmount) final;
- void didFailSocketStream(WebCore::SocketStreamHandle&, const WebCore::SocketStreamError&) final { }
-
- // HTTP Mode.
- void readHTTPMessage();
-
- // WebSocket Mode.
- void upgradeToWebSocketServerConnection(Ref<HTTPRequest>&&);
- void readWebSocketFrames();
- bool readWebSocketFrame();
-
- unsigned m_identifier { 0 };
- Vector<char> m_bufferedData;
- WebSocketServerMode m_mode { HTTP };
- RefPtr<WebCore::SocketStreamHandle> m_socket;
- WebSocketServer* m_server { nullptr };
- WebSocketServerClient* m_client { nullptr };
- bool m_shutdownAfterSend { false };
-};
-
-}
-
-#endif // ENABLE(INSPECTOR_SERVER)
+++ /dev/null
-<!DOCTYPE html>
-<html><head>
-<script type="text/javascript">
-function createPageList() {
- var xhr = new XMLHttpRequest;
- xhr.open("GET", "/pagelist.json");
- xhr.onload = function(e) {
- if (xhr.status == 200) {
- var pages = JSON.parse(xhr.responseText);
- if (pages.length)
- document.getElementById("noPageNotice").style.display = "none";
-
- var pageList = document.createElement("ol");
- for (var i in pages) {
- var link = document.createElement("a");
- var title = pages[i].title ? pages[i].title : ("Page " + (Number(pages[i].id)));
- var url = pages[i].url;
- link.appendChild(document.createTextNode(title + (url ? (" [" + url + "]") : "" )));
- link.setAttribute("href", pages[i].inspectorUrl);
- var pageListItem = document.createElement("li");
- pageListItem.appendChild(link);
- pageList.appendChild(pageListItem);
- }
- document.body.appendChild(pageList);
- }
- };
- xhr.send();
-}
-
-document.addEventListener("DOMContentLoaded", createPageList, false);
-</script>
-</head><body>
-<h1>Inspectable web views</h1>
-<p id="noPageNotice" style="color:grey">None found, make sure that you have set the developerExtrasEnabled preference property on your WebView.</p>
-</body></html>
+++ /dev/null
-/*
- * Copyright (C) 2012 Samsung Electronics Ltd. All Rights Reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "config.h"
-#if ENABLE(INSPECTOR_SERVER)
-#include "WebSocketServer.h"
-
-#include "Logging.h"
-#include "WebSocketServerConnection.h"
-#include <WebCore/SocketStreamHandleImpl.h>
-#include <gio/gio.h>
-#include <glib.h>
-#include <wtf/glib/GUniquePtr.h>
-#include <wtf/text/CString.h>
-
-using namespace WebCore;
-
-namespace WebKit {
-
-static gboolean connectionCallback(GSocketService* /*service*/, GSocketConnection* connection, GObject* /*sourceObject*/, WebSocketServer* server)
-{
-#if !LOG_DISABLED
- GRefPtr<GSocketAddress> socketAddress = adoptGRef(g_socket_connection_get_remote_address(connection, 0));
- GUniquePtr<gchar> addressString(g_inet_address_to_string(g_inet_socket_address_get_address(G_INET_SOCKET_ADDRESS(socketAddress.get()))));
- LOG(InspectorServer, "New Connection from %s:%d.", addressString.get(), g_inet_socket_address_get_port(G_INET_SOCKET_ADDRESS(socketAddress.get())));
-#endif
-
- auto webSocketConnection = std::make_unique<WebSocketServerConnection>(server->client(), server);
- webSocketConnection->setSocketHandle(SocketStreamHandleImpl::create(connection, *webSocketConnection));
- server->didAcceptConnection(WTFMove(webSocketConnection));
-
- return TRUE;
-}
-
-void WebSocketServer::platformInitialize()
-{
- m_socketService = adoptGRef(g_socket_service_new());
- g_signal_connect(m_socketService.get(), "incoming", G_CALLBACK(connectionCallback), this);
- g_socket_service_start(m_socketService.get());
-}
-
-bool WebSocketServer::platformListen(const String& bindAddress, unsigned short port)
-{
- LOG(InspectorServer, "Listen to address=%s, port=%d.", bindAddress.utf8().data(), port);
- GRefPtr<GInetAddress> address = adoptGRef(g_inet_address_new_from_string(bindAddress.utf8().data()));
- GRefPtr<GSocketAddress> socketAddress = adoptGRef(g_inet_socket_address_new(address.get(), port));
- return g_socket_listener_add_address(G_SOCKET_LISTENER(m_socketService.get()), socketAddress.get(), G_SOCKET_TYPE_STREAM, G_SOCKET_PROTOCOL_TCP, 0, 0, 0);
-}
-
-void WebSocketServer::platformClose()
-{
- g_socket_service_stop(m_socketService.get());
-}
-
-}
-
-#endif // ENABLE(INSPECTOR_SERVER)
#include <WebCore/NotImplemented.h>
#include <wtf/NeverDestroyed.h>
-#if ENABLE(INSPECTOR_SERVER)
-#include "WebInspectorServer.h"
-#endif
-
using namespace WebCore;
namespace WebKit {
void WebInspectorProxy::invalidate()
{
-#if ENABLE(INSPECTOR_SERVER)
- if (m_remoteInspectionPageId)
- WebInspectorServer::singleton().unregisterPage(m_remoteInspectionPageId);
-#endif
-
m_inspectedPage->process().removeMessageReceiver(Messages::WebInspectorProxy::messageReceiverName(), m_inspectedPage->pageID());
didClose();
*newMenuRef = menuItems;
}
-#if ENABLE(INSPECTOR_SERVER)
-void WebInspectorProxy::enableRemoteInspection()
-{
- if (!m_remoteInspectionPageId)
- m_remoteInspectionPageId = WebInspectorServer::singleton().registerPage(this);
-}
-
-void WebInspectorProxy::remoteFrontendConnected()
-{
- m_inspectedPage->process().send(Messages::WebInspector::RemoteFrontendConnected(), m_inspectedPage->pageID());
-}
-
-void WebInspectorProxy::remoteFrontendDisconnected()
-{
- m_inspectedPage->process().send(Messages::WebInspector::RemoteFrontendDisconnected(), m_inspectedPage->pageID());
-}
-
-void WebInspectorProxy::dispatchMessageFromRemoteFrontend(const String& message)
-{
- m_inspectedPage->process().send(Messages::WebInspector::SendMessageToBackend(message), m_inspectedPage->pageID());
-}
-#endif
-
void WebInspectorProxy::eagerlyCreateInspectorPage()
{
if (m_inspectorPage)
return inspectorPagePreferences().inspectorStartsAttached() && canAttach();
}
-#if ENABLE(INSPECTOR_SERVER)
-void WebInspectorProxy::sendMessageToRemoteFrontend(const String& message)
-{
- ASSERT(m_remoteInspectionPageId);
- WebInspectorServer::singleton().sendMessageOverConnection(m_remoteInspectionPageId, message);
-}
-#endif
-
// Unsupported configurations can use the stubs provided here.
#if PLATFORM(IOS) || (PLATFORM(MAC) && !WK_API_ENABLED)
static String inspectorBaseURL();
static bool isMainOrTestInspectorPage(const WebCore::URL&);
-#if ENABLE(INSPECTOR_SERVER)
- void enableRemoteInspection();
- void remoteFrontendConnected();
- void remoteFrontendDisconnected();
- void dispatchMessageFromRemoteFrontend(const String& message);
- int remoteInspectionPageID() const { return m_remoteInspectionPageId; }
-#endif
-
static const unsigned minimumWindowWidth;
static const unsigned minimumWindowHeight;
void save(const String& filename, const String& content, bool base64Encoded, bool forceSaveAs);
void append(const String& filename, const String& content);
-#if ENABLE(INSPECTOR_SERVER)
- void sendMessageToRemoteFrontend(const String& message);
-#endif
-
bool canAttach() const { return m_canAttach; }
bool shouldOpenAttached();
GtkWidget* m_headerBar { nullptr };
String m_inspectedURLString;
#endif
-#if ENABLE(INSPECTOR_SERVER)
- int m_remoteInspectionPageId { 0 };
-#endif
};
} // namespace WebKit
SetAttachedWindowWidth(unsigned width)
StartWindowDrag()
-
-#if ENABLE(INSPECTOR_SERVER)
- SendMessageToRemoteFrontend(String message)
-#endif
}
}
#endif
-#if ENABLE(INSPECTOR_SERVER)
- if (m_preferences->developerExtrasEnabled())
- inspector()->enableRemoteInspection();
-#endif
-
process().send(Messages::WebProcess::CreateWebPage(m_pageID, creationParameters()), 0);
m_needsToFinishInitializingWebPageAfterProcessLaunch = true;
if (!isValid())
return;
-#if ENABLE(INSPECTOR_SERVER)
- if (m_preferences->developerExtrasEnabled())
- inspector()->enableRemoteInspection();
-#endif
-
updateThrottleState();
updateHiddenPageThrottlingAutoIncreases();
#include "Logging.h"
#include "NetworkProcessMessages.h"
#include "WebCookieManagerProxy.h"
-#include "WebInspectorServer.h"
#include "WebProcessCreationParameters.h"
#include "WebProcessMessages.h"
#include <JavaScriptCore/RemoteInspectorServer.h>
void WebInspector::sendMessageToFrontend(const String& message)
{
-#if ENABLE(INSPECTOR_SERVER)
- if (m_remoteFrontendConnected)
- WebProcess::singleton().parentProcessConnection()->send(Messages::WebInspectorProxy::SendMessageToRemoteFrontend(message), m_page->pageID());
- else
-#endif
- m_frontendConnection->send(Messages::WebInspectorUI::SendMessageToFrontend(message), 0);
-}
-
-#if ENABLE(INSPECTOR_SERVER)
-void WebInspector::remoteFrontendConnected()
-{
- if (m_page->corePage()) {
- m_remoteFrontendConnected = true;
- m_page->corePage()->inspectorController().connectFrontend(this);
- }
+ m_frontendConnection->send(Messages::WebInspectorUI::SendMessageToFrontend(message), 0);
}
-void WebInspector::remoteFrontendDisconnected()
-{
- m_remoteFrontendConnected = false;
-
- if (m_page->corePage())
- m_page->corePage()->inspectorController().disconnectFrontend(this);
-}
-#endif
-
} // namespace WebKit
void sendMessageToBackend(const String&);
-#if ENABLE(INSPECTOR_SERVER)
- void remoteFrontendConnected();
- void remoteFrontendDisconnected();
-#endif
-
void disconnectFromPage() { close(); }
private:
bool m_attached { false };
bool m_previousCanAttach { false };
-#if ENABLE(INSPECTOR_SERVER)
- bool m_remoteFrontendConnected { false };
-#endif
};
} // namespace WebKit
StopElementSelection()
SendMessageToBackend(String message)
-
-#if ENABLE(INSPECTOR_SERVER)
- RemoteFrontendConnected()
- RemoteFrontendDisconnected()
-#endif
}