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

Pipeline to generate and apply whistium patches #7498

Open
wants to merge 6 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions mandelboxes/browsers/whistium/apply_patches.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash

set -Eeuo pipefail

WHISTIUM_INSTANCE_IP=$1
WHISTIUM_INSTANCE_SSH_KEY=$2
WHISTIUM_INSTANCE_CHROMIUM_PATH=$3
CHROMIUM_BASE_VERSION=$4
MONOREPO_PATH=$(git rev-parse --show-toplevel)

# Check for confirmation
read -r -e -p "If you have any local changes you want to save before applying patches, remember to git stash in your Chromium repository first because they will be lost! Continue? [y/N] " choice
[[ "$choice" == [Yy]* ]] && echo "Beginning patch application process!" || exit

# Reset Chromium repo to base version
echo "Resetting Chromium to version $CHROMIUM_BASE_VERSION..."
ssh -i "$WHISTIUM_INSTANCE_SSH_KEY" ubuntu@"$WHISTIUM_INSTANCE_IP" "cd $WHISTIUM_INSTANCE_CHROMIUM_PATH && git checkout -f $CHROMIUM_BASE_VERSION && git clean -df"

# Apply patches
echo "Applying patches..."
# The following two commands remove and create the temporary patches directory and store the patches in that directory
ssh -i "$WHISTIUM_INSTANCE_SSH_KEY" ubuntu@"$WHISTIUM_INSTANCE_IP" "rm -rf /tmp/patches && mkdir /tmp/patches"
scp -i "$WHISTIUM_INSTANCE_SSH_KEY" "$MONOREPO_PATH"/mandelboxes/browsers/whistium/patches/* ubuntu@"$WHISTIUM_INSTANCE_IP":/tmp/patches
ssh -i "$WHISTIUM_INSTANCE_SSH_KEY" ubuntu@"$WHISTIUM_INSTANCE_IP" "cd $WHISTIUM_INSTANCE_CHROMIUM_PATH && git apply /tmp/patches/*"

# Commit changes locally to allow easy diff-checking
echo "Committing applied changes..."
ssh -i "$WHISTIUM_INSTANCE_SSH_KEY" ubuntu@"$WHISTIUM_INSTANCE_IP" "cd $WHISTIUM_INSTANCE_CHROMIUM_PATH && git add . && git commit -m 'applied monorepo patches'"
800 changes: 0 additions & 800 deletions mandelboxes/browsers/whistium/chromium.patch

This file was deleted.

28 changes: 28 additions & 0 deletions mandelboxes/browsers/whistium/generate_patches.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash

set -Eeuo pipefail

WHISTIUM_INSTANCE_IP=$1
WHISTIUM_INSTANCE_SSH_KEY=$2
WHISTIUM_INSTANCE_CHROMIUM_PATH=$3
CHROMIUM_BASE_VERSION=$4
MONOREPO_PATH=$(git rev-parse --show-toplevel)

# Check for confirmation
read -r -e -p "This script will delete all patches and re-generate them. Interrupting this script may yield undesired results. Continue? [y/N] " choice
[[ "$choice" == [Yy]* ]] && echo "Beginning patch generation process!" || exit

# Delete and recreate patch folder
PATCH_FOLDER="$MONOREPO_PATH"/mandelboxes/browsers/whistium/patches
echo "Deleting and recreating local patch directory..."
rm -rf "$PATCH_FOLDER"
mkdir -p "$PATCH_FOLDER"

# Create patches
echo "Creating patch files..."
# This command does the following:
# - Remove and recreate temporary patches directory
# - Declare "intent to add" untracked files to make them tracked
# - Generate diffs for all modified and added files into the temporary patches directory
ssh -i "$WHISTIUM_INSTANCE_SSH_KEY" ubuntu@"$WHISTIUM_INSTANCE_IP" "cd $WHISTIUM_INSTANCE_CHROMIUM_PATH && rm -rf /tmp/patches && mkdir /tmp/patches && git add -N . && for filepath in \$(git diff $CHROMIUM_BASE_VERSION --name-only) ; do git diff -p $CHROMIUM_BASE_VERSION \$filepath > /tmp/patches/\$(echo \$filepath | tr \"/\" \"-\").patch ; done"
scp -i "$WHISTIUM_INSTANCE_SSH_KEY" ubuntu@"$WHISTIUM_INSTANCE_IP":/tmp/patches/* "$PATCH_FOLDER"
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
diff --git a/chrome/browser/devtools/devtools_window.cc b/chrome/browser/devtools/devtools_window.cc
index a945456d4d15f..14b43c5bb4fd8 100644
--- a/chrome/browser/devtools/devtools_window.cc
+++ b/chrome/browser/devtools/devtools_window.cc
@@ -1090,10 +1090,12 @@ DevToolsWindow::DevToolsWindow(FrontendType frontend_type,
// static
bool DevToolsWindow::AllowDevToolsFor(Profile* profile,
content::WebContents* web_contents) {
+ /* We want DevTools UI in kiosk mode on Whist
// Don't allow DevTools UI in kiosk mode, because the DevTools UI would be
// broken there. See https://crbug.com/514551 for context.
if (base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode))
return false;
+ */

return ChromeDevToolsManagerDelegate::AllowInspection(profile, web_contents);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
diff --git a/chrome/browser/renderer_context_menu/render_view_context_menu.cc b/chrome/browser/renderer_context_menu/render_view_context_menu.cc
index e6efbf1e457ae..aba8b15bec745 100644
--- a/chrome/browser/renderer_context_menu/render_view_context_menu.cc
+++ b/chrome/browser/renderer_context_menu/render_view_context_menu.cc
@@ -1366,14 +1366,6 @@ void RenderViewContextMenu::AppendLinkItems() {
AppendProtocolHandlerSubMenu();
}

- // Links to system web app can't be opened in incognito / off-the-record.
- if (!link_system_app_type) {
- menu_model_.AddItemWithStringId(
- IDC_CONTENT_CONTEXT_OPENLINKOFFTHERECORD,
- in_app ? IDS_CONTENT_CONTEXT_OPENLINKOFFTHERECORD_INAPP
- : IDS_CONTENT_CONTEXT_OPENLINKOFFTHERECORD);
- }
-
AppendOpenInWebAppLinkItems();
AppendOpenWithLinkItems();

@@ -1755,6 +1747,10 @@ void RenderViewContextMenu::AppendExitFullscreenItem() {
if (!browser)
return;

+ // If kiosk mode, Whist has enabled the context menu so we must remove this option.
+ if (base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode))
+ return;
+
// Only show item if in fullscreen mode.
if (!browser->exclusive_access_manager()
->fullscreen_controller()
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
diff --git a/chrome/browser/ui/views/bookmarks/bookmark_context_menu.cc b/chrome/browser/ui/views/bookmarks/bookmark_context_menu.cc
index 116e2b842fcb7..238fa1cb005c6 100644
--- a/chrome/browser/ui/views/bookmarks/bookmark_context_menu.cc
+++ b/chrome/browser/ui/views/bookmarks/bookmark_context_menu.cc
@@ -81,9 +81,6 @@ void BookmarkContextMenu::InstallPreRunCallback(base::OnceClosure callback) {

void BookmarkContextMenu::RunMenuAt(const gfx::Point& point,
ui::MenuSourceType source_type) {
- if (base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode))
- return;
-
if (!PreRunCallback().is_null())
std::move(PreRunCallback()).Run();

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
diff --git a/chrome/browser/ui/views/page_action/zoom_view.cc b/chrome/browser/ui/views/page_action/zoom_view.cc
index fba0a8ce686d1..a256348e4ce9f 100644
--- a/chrome/browser/ui/views/page_action/zoom_view.cc
+++ b/chrome/browser/ui/views/page_action/zoom_view.cc
@@ -34,6 +34,9 @@ void ZoomView::UpdateImpl() {
}

bool ZoomView::ShouldBeVisible(bool can_show_bubble) const {
+ // We don't want the server to ever show the zoom bubble view
+ return false;
+ /*
if (delegate()->ShouldHidePageActionIcons())
return false;

@@ -47,6 +50,7 @@ bool ZoomView::ShouldBeVisible(bool can_show_bubble) const {
zoom::ZoomController* zoom_controller =
zoom::ZoomController::FromWebContents(GetWebContents());
return zoom_controller && !zoom_controller->IsAtDefaultZoom();
+ */
}

bool ZoomView::HasAssociatedBubble() const {
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
diff --git a/chrome/browser/ui/views/renderer_context_menu/render_view_context_menu_views.cc b/chrome/browser/ui/views/renderer_context_menu/render_view_context_menu_views.cc
index dd729e8186d03..aeed067f3f4f6 100644
--- a/chrome/browser/ui/views/renderer_context_menu/render_view_context_menu_views.cc
+++ b/chrome/browser/ui/views/renderer_context_menu/render_view_context_menu_views.cc
@@ -362,9 +362,6 @@ void RenderViewContextMenuViews::ExecOpenInReadAnything() {
}

void RenderViewContextMenuViews::Show() {
- if (base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode))
- return;
-
// Menus need a Widget to work. If we're not the active tab we won't
// necessarily be in a widget.
views::Widget* top_level_widget = GetTopLevelWidget();
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
diff --git a/content/browser/renderer_host/render_process_host_impl.cc b/content/browser/renderer_host/render_process_host_impl.cc
index b74b4c2028ccb..1e61c0718d691 100644
--- a/content/browser/renderer_host/render_process_host_impl.cc
+++ b/content/browser/renderer_host/render_process_host_impl.cc
@@ -3281,6 +3281,7 @@ void RenderProcessHostImpl::PropagateBrowserCommandLineToRenderer(
switches::kEnableTouchDragDrop,
switches::kEnableUnsafeFastJSCalls,
switches::kEnableUnsafeWebGPU,
+ switches::kEnableGpuCommandStreaming,
switches::kEnableViewport,
switches::kEnableVtune,
switches::kEnableWebGLDeveloperExtensions,
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
diff --git a/gpu/command_buffer/client/client_transfer_cache.cc b/gpu/command_buffer/client/client_transfer_cache.cc
index 00d7a7058340d..3dc5d937f7e25 100644
--- a/gpu/command_buffer/client/client_transfer_cache.cc
+++ b/gpu/command_buffer/client/client_transfer_cache.cc
@@ -3,6 +3,7 @@
// found in the LICENSE file.

#include "gpu/command_buffer/client/client_transfer_cache.h"
+#include "gpu/command_buffer/client/cmd_buffer_helper.h"

namespace gpu {

@@ -51,12 +52,16 @@ void ClientTransferCache::UnmapAndCreateEntry(uint32_t type, uint32_t id) {

if (mapped_ptr_) {
DCHECK(!transfer_buffer_ptr_);
+ client_->cmd_buffer_helper()->SendBufferToWhist(CommandBufferType::TRANSFER_CACHE,
+ mapped_ptr_->address(), mapped_ptr_->size());
client_->IssueCreateTransferCacheEntry(
type, id, handle.shm_id(), handle.byte_offset(), mapped_ptr_->shm_id(),
mapped_ptr_->offset(), mapped_ptr_->size());
mapped_ptr_ = absl::nullopt;
} else {
DCHECK(!mapped_ptr_);
+ client_->cmd_buffer_helper()->SendBufferToWhist(CommandBufferType::TRANSFER_CACHE,
+ transfer_buffer_ptr_->address(), transfer_buffer_ptr_->size());
client_->IssueCreateTransferCacheEntry(
type, id, handle.shm_id(), handle.byte_offset(),
transfer_buffer_ptr_->shm_id(), transfer_buffer_ptr_->offset(),
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
diff --git a/gpu/command_buffer/client/cmd_buffer_helper.cc b/gpu/command_buffer/client/cmd_buffer_helper.cc
index 8813dac7f22d0..200e00f2f46a4 100644
--- a/gpu/command_buffer/client/cmd_buffer_helper.cc
+++ b/gpu/command_buffer/client/cmd_buffer_helper.cc
@@ -7,8 +7,13 @@
#include "gpu/command_buffer/client/cmd_buffer_helper.h"

#include <stdint.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/un.h>

#include <algorithm>
+#include "base/command_line.h"
#include "base/logging.h"
#include "base/strings/stringprintf.h"
#include "base/threading/thread_task_runner_handle.h"
@@ -19,10 +24,14 @@
#include "base/trace_event/trace_event.h"
#include "gpu/command_buffer/common/buffer.h"
#include "gpu/command_buffer/common/command_buffer.h"
+#include "gpu/command_buffer/service/common_decoder.h"
#include "gpu/command_buffer/common/constants.h"
+#include "gpu/config/gpu_switches.h"

namespace gpu {

+#define IPC_FILE "/home/whist/gpu_commands"
+
CommandBufferHelper::CommandBufferHelper(CommandBuffer* command_buffer)
: command_buffer_(command_buffer) {}

@@ -104,6 +113,32 @@ bool CommandBufferHelper::AllocateRingBuffer() {

void CommandBufferHelper::SetGetBuffer(int32_t id,
scoped_refptr<Buffer> buffer) {
+ is_renderer_process_ = base::trace_event::TraceLog::GetInstance()->process_name() == "Renderer";
+ const base::CommandLine& command_line = *base::CommandLine::ForCurrentProcess();
+
+ if (is_renderer_process_ && command_line.HasSwitch(switches::kEnableGpuCommandStreaming) &&
+ GetCommandBufferType() == CommandBufferType::RASTER && sock_fd_ == -1) {
+ if ((sock_fd_ = socket (AF_UNIX, SOCK_SEQPACKET, 0)) == -1) {
+ int err_socket = errno;
+ LOG(ERROR) << "Could not open the socket for GPU command streaming, error=" << strerror(err_socket);
+ return;
+ }
+ LOG(INFO) << "Successfully opened the socket for GPU command streaming";
+
+ struct sockaddr_un socket_address;
+ memset (&socket_address, 0, sizeof (struct sockaddr_un));
+ socket_address.sun_family = AF_UNIX;
+ strncpy (socket_address.sun_path, IPC_FILE, sizeof (socket_address.sun_path) - 1);
+
+ if (connect (sock_fd_, (const struct sockaddr *) &socket_address, sizeof (struct sockaddr_un)) == -1) {
+ sock_fd_ = -1;
+ int err_socket = errno;
+ LOG(ERROR) << "Could not connect to the socket for GPU command streaming, error=" << strerror(err_socket);
+ return;
+ }
+ LOG(INFO) << "Successfully connected the socket for GPU command streaming";
+ }
+
command_buffer_->SetGetBuffer(id);
ring_buffer_ = std::move(buffer);
ring_buffer_id_ = id;
@@ -117,6 +152,7 @@ void CommandBufferHelper::SetGetBuffer(int32_t id,
// No need to query it through IPC.
put_ = 0;
last_flush_put_ = 0;
+ last_whist_put_ = 0;
last_ordering_barrier_put_ = 0;
cached_get_offset_ = 0;
service_on_old_buffer_ = true;
@@ -135,6 +171,9 @@ void CommandBufferHelper::FreeRingBuffer() {

gpu::ContextResult CommandBufferHelper::Initialize(uint32_t ring_buffer_size) {
ring_buffer_size_ = ring_buffer_size;
+ if (socket_buffer != NULL)
+ free(socket_buffer);
+ socket_buffer = (char *)malloc(ring_buffer_size_);
if (!AllocateRingBuffer()) {
// This would fail if CreateTransferBuffer fails, which will not fail for
// transient reasons such as context loss. See http://crrev.com/c/720269
@@ -147,6 +186,8 @@ gpu::ContextResult CommandBufferHelper::Initialize(uint32_t ring_buffer_size) {

CommandBufferHelper::~CommandBufferHelper() {
FreeRingBuffer();
+ if (socket_buffer != NULL)
+ free(socket_buffer);
}

void CommandBufferHelper::UpdateCachedState(const CommandBuffer::State& state) {
@@ -169,6 +210,34 @@ bool CommandBufferHelper::WaitForGetOffsetInRange(int32_t start, int32_t end) {
return !context_lost_;
}

+void CommandBufferHelper::SendBufferToWhist(CommandBufferType type, void* buffer,
+ int32_t shm_size) {
+ if (sock_fd_ == -1)
+ return;
+ if (shm_size <= 0)
+ return;
+ socket_buffer[0] = static_cast<char>(type);
+ memcpy(socket_buffer + 1, buffer, shm_size);
+ if (write(sock_fd_, socket_buffer, shm_size + 1) == -1) {
+ DLOG(ERROR) << "Could not send the command data to Whist";
+ }
+}
+
+void CommandBufferHelper::SendCommandsToWhist() {
+ if (sock_fd_ == -1)
+ return;
+ DCHECK(put_ >= last_whist_put_);
+ if (put_ == last_whist_put_)
+ return;
+ socket_buffer[0] = static_cast<char>(GetCommandBufferType());
+ int size = (put_ - last_whist_put_) * sizeof (CommandBufferEntry);
+ memcpy(socket_buffer + 1, &entries_[last_whist_put_], size);
+ if (write(sock_fd_, socket_buffer, size + 1) == -1) {
+ DLOG(ERROR) << "Could not send the command buffer to Whist";
+ }
+ last_whist_put_ = put_;
+}
+
void CommandBufferHelper::Flush() {
TRACE_EVENT0("gpu", "CommandBufferHelper::Flush");
// Wrap put_ before flush.
@@ -177,6 +246,15 @@ void CommandBufferHelper::Flush() {

if (HaveRingBuffer()) {
last_flush_time_ = base::TimeTicks::Now();
+ SendCommandsToWhist();
+ if (sock_fd_ != -1) {
+ // Flush is sent as a separate packet type, so that CommandBufferHelper::Flush()
+ // can be called at the appropriate time on the client-side browser.
+ socket_buffer[0] = static_cast<char>(CommandBufferType::FLUSH);
+ if (write(sock_fd_, socket_buffer, 1) == -1) {
+ DLOG(ERROR) << "Could not send the command buffer to Whist";
+ }
+ }
last_flush_put_ = put_;
last_ordering_barrier_put_ = put_;
command_buffer_->Flush(put_);
@@ -244,6 +322,10 @@ int32_t CommandBufferHelper::InsertToken() {
if (cmd) {
token_ = (token_ + 1) & 0x7FFFFFFF;
cmd->Init(token_);
+ // SetToken command is immediately, so that the corresponding
+ // shared memory buffers can be freed on the client side before
+ // the next shared memory buffer packet is sent from the server.
+ SendCommandsToWhist();
if (token_ == 0) {
TRACE_EVENT0("gpu", "CommandBufferHelper::InsertToken(wrapped)");
bool finished = Finish(); // we wrapped
Loading