Make Print API work on Windows.
This commit is contained in:
parent
ca5ee0fc81
commit
ff87592722
15 changed files with 1294 additions and 0 deletions
|
@ -14,6 +14,7 @@
|
|||
#include "base/debug/stack_trace.h"
|
||||
#include "base/environment.h"
|
||||
#include "base/logging.h"
|
||||
#include "chrome/utility/chrome_content_utility_client.h"
|
||||
#include "content/public/common/content_switches.h"
|
||||
#include "ui/base/resource/resource_bundle.h"
|
||||
|
||||
|
@ -94,6 +95,13 @@ content::ContentRendererClient*
|
|||
return renderer_client_.get();
|
||||
}
|
||||
|
||||
content::ContentUtilityClient* AtomMainDelegate::CreateContentUtilityClient() {
|
||||
#if defined(OS_WIN)
|
||||
utility_client_.reset(new AtomContentUtilityClient);
|
||||
return utility_client_.get();
|
||||
#endif
|
||||
}
|
||||
|
||||
scoped_ptr<brightray::ContentClient> AtomMainDelegate::CreateContentClient() {
|
||||
return scoped_ptr<brightray::ContentClient>(new AtomContentClient).Pass();
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ class AtomMainDelegate : public brightray::MainDelegate {
|
|||
void PreSandboxStartup() override;
|
||||
content::ContentBrowserClient* CreateContentBrowserClient() override;
|
||||
content::ContentRendererClient* CreateContentRendererClient() override;
|
||||
content::ContentUtilityClient* CreateContentUtilityClient() override;
|
||||
|
||||
// brightray::MainDelegate:
|
||||
scoped_ptr<brightray::ContentClient> CreateContentClient() override;
|
||||
|
@ -35,6 +36,7 @@ class AtomMainDelegate : public brightray::MainDelegate {
|
|||
brightray::ContentClient content_client_;
|
||||
scoped_ptr<content::ContentBrowserClient> browser_client_;
|
||||
scoped_ptr<content::ContentRendererClient> renderer_client_;
|
||||
scoped_ptr<content::ContentUtilityClient> utility_client_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(AtomMainDelegate);
|
||||
};
|
||||
|
|
76
atom/utility/atom_content_utility_client.cc
Normal file
76
atom/utility/atom_content_utility_client.cc
Normal file
|
@ -0,0 +1,76 @@
|
|||
// Copyright (c) 2015 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "atom/utility/atom_content_utility_client.h"
|
||||
|
||||
#include "base/command_line.h"
|
||||
#include "base/files/file_path.h"
|
||||
#include "base/memory/ref_counted.h"
|
||||
#include "base/time/time.h"
|
||||
#include "chrome/common/chrome_utility_messages.h"
|
||||
#include "chrome/utility/utility_message_handler.h"
|
||||
#include "content/public/common/content_switches.h"
|
||||
#include "content/public/utility/utility_thread.h"
|
||||
#include "ipc/ipc_channel.h"
|
||||
#include "ipc/ipc_message_macros.h"
|
||||
|
||||
|
||||
#if defined(OS_WIN)
|
||||
#include "chrome/utility/printing_handler.h"
|
||||
#endif
|
||||
|
||||
|
||||
namespace {
|
||||
|
||||
bool Send(IPC::Message* message) {
|
||||
return content::UtilityThread::Get()->Send(message);
|
||||
}
|
||||
|
||||
void ReleaseProcessIfNeeded() {
|
||||
content::UtilityThread::Get()->ReleaseProcessIfNeeded();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace atom {
|
||||
|
||||
int64_t AtomContentUtilityClient::max_ipc_message_size_ =
|
||||
IPC::Channel::kMaximumMessageSize;
|
||||
|
||||
AtomContentUtilityClient::AtomContentUtilityClient()
|
||||
: filter_messages_(false) {
|
||||
handlers_.push_back(new PrintingHandler());
|
||||
}
|
||||
|
||||
AtomContentUtilityClient::~AtomContentUtilityClient() {
|
||||
}
|
||||
|
||||
void AtomContentUtilityClient::UtilityThreadStarted() {
|
||||
}
|
||||
|
||||
bool AtomContentUtilityClient::OnMessageReceived(
|
||||
const IPC::Message& message) {
|
||||
if (filter_messages_ && !ContainsKey(message_id_whitelist_, message.type()))
|
||||
return false;
|
||||
|
||||
bool handled = true;
|
||||
IPC_BEGIN_MESSAGE_MAP(AtomContentUtilityClient, message)
|
||||
IPC_MESSAGE_HANDLER(ChromeUtilityMsg_StartupPing, OnStartupPing)
|
||||
IPC_MESSAGE_UNHANDLED(handled = false)
|
||||
IPC_END_MESSAGE_MAP()
|
||||
|
||||
for (Handlers::iterator it = handlers_.begin();
|
||||
!handled && it != handlers_.end(); ++it) {
|
||||
handled = (*it)->OnMessageReceived(message);
|
||||
}
|
||||
|
||||
return handled;
|
||||
}
|
||||
|
||||
void AtomContentUtilityClient::OnStartupPing() {
|
||||
Send(new ChromeUtilityHostMsg_ProcessStarted);
|
||||
// Don't release the process, we assume further messages are on the way.
|
||||
}
|
||||
|
||||
} // namespace atom
|
57
atom/utility/atom_content_utility_client.h
Normal file
57
atom/utility/atom_content_utility_client.h
Normal file
|
@ -0,0 +1,57 @@
|
|||
// Copyright (c) 2015 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef ATOM_UTILITY_ATOM_CONTENT_UTILITY_CLIENT_H_
|
||||
#define ATOM_UTILITY_ATOM_CONTENT_UTILITY_CLIENT_H_
|
||||
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "base/compiler_specific.h"
|
||||
#include "base/memory/scoped_vector.h"
|
||||
#include "content/public/utility/content_utility_client.h"
|
||||
#include "ipc/ipc_platform_file.h"
|
||||
|
||||
namespace base {
|
||||
class FilePath;
|
||||
struct FileDescriptor;
|
||||
}
|
||||
|
||||
class UtilityMessageHandler;
|
||||
|
||||
namespace atom {
|
||||
|
||||
class AtomContentUtilityClient : public content::ContentUtilityClient {
|
||||
public:
|
||||
AtomContentUtilityClient();
|
||||
~AtomContentUtilityClient() override;
|
||||
|
||||
void UtilityThreadStarted() override;
|
||||
bool OnMessageReceived(const IPC::Message& message) override;
|
||||
|
||||
|
||||
static void set_max_ipc_message_size_for_test(int64_t max_message_size) {
|
||||
max_ipc_message_size_ = max_message_size;
|
||||
}
|
||||
|
||||
private:
|
||||
void OnStartupPing();
|
||||
|
||||
typedef ScopedVector<UtilityMessageHandler> Handlers;
|
||||
Handlers handlers_;
|
||||
|
||||
// Flag to enable whitelisting.
|
||||
bool filter_messages_;
|
||||
// A list of message_ids to filter.
|
||||
std::set<int> message_id_whitelist_;
|
||||
// Maximum IPC msg size (default to kMaximumMessageSize; override for testing)
|
||||
static int64_t max_ipc_message_size_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(AtomContentUtilityClient);
|
||||
};
|
||||
|
||||
} // namespace atom
|
||||
|
||||
#endif // ATOM_UTILITY_ATOM_CONTENT_UTILITY_CLIENT_H_
|
Loading…
Add table
Add a link
Reference in a new issue