Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(14)

Unified Diff: chrome/utility/sandboxed_shell_handler_win.cc

Issue 431343002: Experimentally isolate OpenItemViaShell in a utility process. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add a comment. Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/common/chrome_utility_messages.h ('k') | chrome/utility/shell_handler_win.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/utility/sandboxed_shell_handler_win.cc
diff --git a/chrome/utility/sandboxed_shell_handler_win.cc b/chrome/utility/sandboxed_shell_handler_win.cc
new file mode 100644
index 0000000000000000000000000000000000000000..1e1b3ada72fde911687829360132e2348bc02602
--- /dev/null
+++ b/chrome/utility/sandboxed_shell_handler_win.cc
@@ -0,0 +1,105 @@
+// Copyright (c) 2014 The Chromium Authors. All rights reserved.
jochen (gone - plz use gerrit) 2014/08/04 09:13:41 why this file? Where's the header and the gyp/gn c
erikwright (departed) 2014/08/12 18:34:31 Sorry, this was somehow left over from an earlier
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/utility/sandboxed_shell_handler_win.h"
+
+#include <commdlg.h>
+
+#include "base/files/file_path.h"
+#include "base/memory/scoped_ptr.h"
+#include "chrome/common/chrome_utility_messages.h"
+#include "content/public/utility/utility_thread.h"
+#include "ui/base/win/shell.h"
+
+SandboxedShellHandler::SandboxedShellHandler() {}
+SandboxedShellHandler::~SandboxedShellHandler() {}
+
+bool SandboxedShellHandler::OnMessageReceived(const IPC::Message& message) {
+ bool handled = true;
+ IPC_BEGIN_MESSAGE_MAP(SandboxedShellHandler, message)
+ IPC_MESSAGE_HANDLER(ChromeUtilityMsg_OpenItemViaShell,
+ OnOpenItemViaShell)
+ IPC_MESSAGE_HANDLER(ChromeUtilityMsg_GetOpenFileName,
+ OnGetOpenFileName)
+ IPC_MESSAGE_UNHANDLED(handled = false)
+ IPC_END_MESSAGE_MAP()
+ return handled;
+}
+
+void SandboxedShellHandler::OnOpenItemViaShell(
+ const base::FilePath& full_path) {
+ ui::win::OpenItemViaShell(full_path);
+}
+
+void SandboxedShellHandler::OnGetOpenFileName(
+ HWND owner,
+ DWORD flags,
+ const GetOpenFileNameFilter& filter,
+ const base::FilePath& initial_directory,
+ const base::FilePath& filename) {
+ OPENFILENAME ofn;
+ // We must do this otherwise the ofn's FlagsEx may be initialized to random
+ // junk in release builds which can cause the Places Bar not to show up!
+ ZeroMemory(&ofn, sizeof(ofn));
+ ofn.lStructSize = sizeof(ofn);
+ ofn.hwndOwner = owner;
+ scoped_ptr<wchar_t[]> filename_buffer(new wchar_t[UNICODE_STRING_MAX_CHARS]);
+ // According to http://support.microsoft.com/?scid=kb;en-us;222003&x=8&y=12,
+ // The lpstrFile Buffer MUST be NULL Terminated.
+ filename_buffer[0] = 0;
+ if (!initial_directory.empty()) {
+ ofn.lpstrInitialDir = initial_directory.value().c_str();
+ if (!filename.empty()) {
+ base::wcslcpy(filename_buffer.get(),
+ filename.value().c_str(),
+ UNICODE_STRING_MAX_CHARS);
+ }
+ }
+ ofn.lpstrFile = filename_buffer.get();
+ ofn.nMaxFile = UNICODE_STRING_MAX_CHARS;
+ ofn.Flags = flags;
+ base::string16 filter_buffer;
+ if (!filter.empty()) {
+ for (GetOpenFileNameFilter::const_iterator it = filter.begin();
+ it != filter.end();
+ ++it) {
+ filter_buffer.append(it->a);
+ filter_buffer.push_back(0);
+ filter_buffer.append(it->b);
+ filter_buffer.push_back(0);
+ }
+ filter_buffer.push_back(0);
+ ofn.lpstrFilter = filter_buffer.c_str();
+ }
+
+ base::FilePath directory;
+ std::vector<base::FilePath> filenames;
+
+ if (::GetOpenFileName(&ofn)) {
+ const wchar_t* selection = ofn.lpstrFile;
+ while (*selection) { // Empty string indicates end of list.
+ filenames.push_back(base::FilePath(selection));
+ // Skip over filename and null-terminator.
+ selection += filenames.back().value().length() + 1;
+ }
+ if (filenames.size() == 1) {
+ // When there is one file, it contains the path and filename.
+ directory = filenames[0].DirName();
+ filenames[0] = filenames[0].BaseName();
+ } else if (filenames.size() > 1) {
+ // Otherwise, the first string is the path, and the remainder are
+ // filenames.
+ directory = filenames[0];
+ filenames.erase(filenames.begin());
+ }
+ }
+
+ if (filenames.size()) {
+ content::UtilityThread::Get()->Send(
+ new ChromeUtilityHostMsg_GetOpenFileName_Result(directory, filenames));
+ } else {
+ content::UtilityThread::Get()->Send(
+ new ChromeUtilityHostMsg_GetOpenFileName_Failed());
+ }
+}
« no previous file with comments | « chrome/common/chrome_utility_messages.h ('k') | chrome/utility/shell_handler_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698