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

Unified Diff: chrome/browser/extensions/api/messaging/native_process_launcher.cc

Issue 22532011: Pass handle of the native view window to the native messaging host. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: - Created 7 years, 4 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
Index: chrome/browser/extensions/api/messaging/native_process_launcher.cc
diff --git a/chrome/browser/extensions/api/messaging/native_process_launcher.cc b/chrome/browser/extensions/api/messaging/native_process_launcher.cc
index 2186e1e1c0083661b28b8ed2e418c8dd1ec7bcf6..0f8992e7c92904cac3fb1da326e1b6cd11de94ec 100644
--- a/chrome/browser/extensions/api/messaging/native_process_launcher.cc
+++ b/chrome/browser/extensions/api/messaging/native_process_launcher.cc
@@ -11,6 +11,7 @@
#include "base/logging.h"
#include "base/memory/ref_counted.h"
#include "base/path_service.h"
+#include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h"
#include "base/threading/sequenced_worker_pool.h"
#include "chrome/browser/extensions/api/messaging/native_messaging_host_manifest.h"
@@ -23,7 +24,9 @@ namespace extensions {
namespace {
-const char kNativeHostsDirectoryName[] = "native_hosts";
+// Name of the command line switch used to pass handle of the native view to
+// the native messaging host.
+const char kParentWindowSwitchName[] = "parent-window";
base::FilePath GetHostManifestPathFromCommandLine(
const std::string& native_host_name) {
@@ -51,7 +54,7 @@ base::FilePath GetHostManifestPathFromCommandLine(
// Default implementation on NativeProcessLauncher interface.
class NativeProcessLauncherImpl : public NativeProcessLauncher {
public:
- NativeProcessLauncherImpl();
+ explicit NativeProcessLauncherImpl(gfx::NativeView native_view);
virtual ~NativeProcessLauncherImpl();
virtual void Launch(const GURL& origin,
@@ -61,7 +64,7 @@ class NativeProcessLauncherImpl : public NativeProcessLauncher {
private:
class Core : public base::RefCountedThreadSafe<Core> {
public:
- Core();
+ explicit Core(gfx::NativeView native_view);
void Launch(const GURL& origin,
const std::string& native_host_name,
LaunchedCallback callback);
@@ -85,6 +88,9 @@ class NativeProcessLauncherImpl : public NativeProcessLauncher {
bool detached_;
+ // Handle of the native view corrsponding to the extension.
+ gfx::NativeView native_view_;
+
DISALLOW_COPY_AND_ASSIGN(Core);
};
@@ -93,8 +99,9 @@ class NativeProcessLauncherImpl : public NativeProcessLauncher {
DISALLOW_COPY_AND_ASSIGN(NativeProcessLauncherImpl);
};
-NativeProcessLauncherImpl::Core::Core()
- : detached_(false) {
+NativeProcessLauncherImpl::Core::Core(gfx::NativeView native_view)
+ : detached_(false),
+ native_view_(native_view) {
}
NativeProcessLauncherImpl::Core::~Core() {
@@ -182,6 +189,14 @@ void NativeProcessLauncherImpl::Core::DoLaunchOnThreadPool(
CommandLine command_line(host_path);
command_line.AppendArg(origin.spec());
+ // Pass handle of the native view window to the native messaging host. This
+ // way the host will be able to create properly focused UI windows.
+#if defined(OS_WIN)
+ int64 window_handle = reinterpret_cast<intptr_t>(native_view_);
+ command_line.AppendSwitchASCII(kParentWindowSwitchName,
+ base::Int64ToString(window_handle));
+#endif // !defined(OS_WIN)
+
base::PlatformFile read_file;
base::PlatformFile write_file;
if (NativeProcessLauncher::LaunchNativeProcess(
@@ -230,8 +245,9 @@ void NativeProcessLauncherImpl::Core::PostResult(
this, callback, RESULT_SUCCESS, read_file, write_file));
}
-NativeProcessLauncherImpl::NativeProcessLauncherImpl()
- : core_(new Core()) {
+NativeProcessLauncherImpl::NativeProcessLauncherImpl(
+ gfx::NativeView native_view)
+ : core_(new Core(native_view)) {
}
NativeProcessLauncherImpl::~NativeProcessLauncherImpl() {
@@ -247,8 +263,10 @@ void NativeProcessLauncherImpl::Launch(const GURL& origin,
} // namespace
// static
-scoped_ptr<NativeProcessLauncher> NativeProcessLauncher::CreateDefault() {
- return scoped_ptr<NativeProcessLauncher>(new NativeProcessLauncherImpl());
+scoped_ptr<NativeProcessLauncher> NativeProcessLauncher::CreateDefault(
+ gfx::NativeView native_view) {
+ return scoped_ptr<NativeProcessLauncher>(
+ new NativeProcessLauncherImpl(native_view));
}
} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698