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

Make Print API work on Windows. #1532

Merged
merged 3 commits into from
May 10, 2015
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Make Print API work on Windows.
  • Loading branch information
hokein committed Apr 30, 2015
commit ff87592722e6a508d55871cfc88ab2e7d08a2a10
8 changes: 8 additions & 0 deletions atom/app/atom_main_delegate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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();
}
Expand Down
2 changes: 2 additions & 0 deletions atom/app/atom_main_delegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
};
Expand Down
76 changes: 76 additions & 0 deletions atom/utility/atom_content_utility_client.cc
Original file line number Diff line number Diff line change
@@ -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 changes: 57 additions & 0 deletions atom/utility/atom_content_utility_client.h
Original file line number Diff line number Diff line change
@@ -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