summaryrefslogtreecommitdiffstats
path: root/ppapi
diff options
context:
space:
mode:
authorraymes@chromium.org <raymes@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-09-27 23:30:41 +0000
committerraymes@chromium.org <raymes@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-09-27 23:30:41 +0000
commit234c139a2b9e49ebc4fa568de69c1a5c8248538b (patch)
tree7f2bbff8a839ac6f7e82c849d146928ea9cd6303 /ppapi
parent8a6702b4c40143058d6750e198641a7e172db611 (diff)
downloadchromium_src-234c139a2b9e49ebc4fa568de69c1a5c8248538b.zip
chromium_src-234c139a2b9e49ebc4fa568de69c1a5c8248538b.tar.gz
chromium_src-234c139a2b9e49ebc4fa568de69c1a5c8248538b.tar.bz2
Implement browser side of PPB_Printing resource.
This adds the browser side implementation of PPB_Printing as well as a unittest for PepperPrintingHost and a PPAPI browser_test for PPB_Printing::GetDefaultPrintSettings. BUG=138333 TEST=content_unittests/browser_tests Review URL: https://chromiumcodereview.appspot.com/10826072 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@159150 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi')
-rw-r--r--ppapi/cpp/dev/printing_dev.cc36
-rw-r--r--ppapi/cpp/dev/printing_dev.h11
-rw-r--r--ppapi/host/dispatch_host_message.h2
-rw-r--r--ppapi/ppapi_sources.gypi2
-rw-r--r--ppapi/proxy/plugin_dispatcher.cc4
-rw-r--r--ppapi/proxy/printing_resource.cc2
-rw-r--r--ppapi/tests/test_printing.cc64
-rw-r--r--ppapi/tests/test_printing.h35
-rw-r--r--ppapi/thunk/enter.cc3
9 files changed, 142 insertions, 17 deletions
diff --git a/ppapi/cpp/dev/printing_dev.cc b/ppapi/cpp/dev/printing_dev.cc
index 8c30725..00bb15b 100644
--- a/ppapi/cpp/dev/printing_dev.cc
+++ b/ppapi/cpp/dev/printing_dev.cc
@@ -16,6 +16,10 @@ namespace {
static const char kPPPPrintingInterface[] = PPP_PRINTING_DEV_INTERFACE;
+template <> const char* interface_name<PPB_Printing_Dev_0_7>() {
+ return PPB_PRINTING_DEV_INTERFACE_0_7;
+}
+
template <> const char* interface_name<PPB_Printing_Dev_0_6>() {
return PPB_PRINTING_DEV_INTERFACE_0_6;
}
@@ -76,9 +80,14 @@ const PPP_Printing_Dev ppp_printing = {
} // namespace
Printing_Dev::Printing_Dev(Instance* instance)
- : associated_instance_(instance) {
+ : associated_instance_(instance) {
Module::Get()->AddPluginInterface(kPPPPrintingInterface, &ppp_printing);
- instance->AddPerInstanceObject(kPPPPrintingInterface, this);
+ instance->AddPerInstanceObject(
+ kPPPPrintingInterface, this);
+ if (has_interface<PPB_Printing_Dev_0_7>()) {
+ PassRefFromConstructor(get_interface<PPB_Printing_Dev_0_7>()->Create(
+ associated_instance_.pp_instance()));
+ }
}
Printing_Dev::~Printing_Dev() {
@@ -88,16 +97,23 @@ Printing_Dev::~Printing_Dev() {
// static
bool Printing_Dev::IsAvailable() {
- return has_interface<PPB_Printing_Dev_0_6>();
+ return has_interface<PPB_Printing_Dev_0_7>() ||
+ has_interface<PPB_Printing_Dev_0_6>();
+
}
-bool Printing_Dev::GetDefaultPrintSettings(
- PP_PrintSettings_Dev* print_settings) const {
- if (!has_interface<PPB_Printing_Dev_0_6>())
- return false;
- return PP_ToBool(
- get_interface<PPB_Printing_Dev_0_6>()->GetDefaultPrintSettings(
- associated_instance_.pp_instance(), print_settings));
+void Printing_Dev::GetDefaultPrintSettings(
+ const CompletionCallbackWithOutput<PP_PrintSettings_Dev>& callback) const {
+ if (has_interface<PPB_Printing_Dev_0_7>()) {
+ get_interface<PPB_Printing_Dev_0_7>()->GetDefaultPrintSettings(
+ pp_resource(), callback.output(), callback.pp_completion_callback());
+ } else if (has_interface<PPB_Printing_Dev_0_6>()) {
+ bool success = PP_ToBool(get_interface<PPB_Printing_Dev_0_6>()->
+ GetDefaultPrintSettings(associated_instance_.pp_instance(),
+ callback.output()));
+ Module::Get()->core()->CallOnMainThread(0, callback,
+ success ? PP_OK : PP_ERROR_FAILED);
+ }
}
} // namespace pp
diff --git a/ppapi/cpp/dev/printing_dev.h b/ppapi/cpp/dev/printing_dev.h
index eb20e56..9d5a7db 100644
--- a/ppapi/cpp/dev/printing_dev.h
+++ b/ppapi/cpp/dev/printing_dev.h
@@ -6,6 +6,7 @@
#define PPAPI_CPP_DEV_PRINTING_DEV_H_
#include "ppapi/c/dev/ppp_printing_dev.h"
+#include "ppapi/cpp/completion_callback.h"
#include "ppapi/cpp/instance_handle.h"
#include "ppapi/cpp/resource.h"
@@ -15,7 +16,7 @@ class Instance;
// You would typically use this either via inheritance on your instance or
// by composition: see find_dev.h for an example.
-class Printing_Dev {
+class Printing_Dev : public Resource {
public:
// The instance parameter must outlive this class.
explicit Printing_Dev(Instance* instance);
@@ -35,9 +36,11 @@ class Printing_Dev {
// interface.
static bool IsAvailable();
- // Outputs the default print settings for the default printer into
- // |print_settings|. Returns false on error.
- bool GetDefaultPrintSettings(PP_PrintSettings_Dev* print_settings) const;
+ // Get the default print settings and store them in the output of |callback|.
+ // This method always runs asynchronously and the callback will always be
+ // triggered.
+ void GetDefaultPrintSettings(
+ const CompletionCallbackWithOutput<PP_PrintSettings_Dev>& callback) const;
private:
InstanceHandle associated_instance_;
diff --git a/ppapi/host/dispatch_host_message.h b/ppapi/host/dispatch_host_message.h
index b01a0ed..f891851 100644
--- a/ppapi/host/dispatch_host_message.h
+++ b/ppapi/host/dispatch_host_message.h
@@ -63,7 +63,7 @@ inline int32_t DispatchResourceCall(ObjT* obj, Method method,
// Note that this only works for message with 1 or more parameters. For
// 0-parameter messages you need to use the _0 version below (since there are
-// no Params in the message).
+// no params in the message).
#define PPAPI_DISPATCH_HOST_RESOURCE_CALL(msg_class, member_func) \
case msg_class::ID: { \
TRACK_RUN_IN_IPC_HANDLER(member_func); \
diff --git a/ppapi/ppapi_sources.gypi b/ppapi/ppapi_sources.gypi
index e939b79..79ca558 100644
--- a/ppapi/ppapi_sources.gypi
+++ b/ppapi/ppapi_sources.gypi
@@ -379,6 +379,8 @@
'tests/test_paint_aggregator.h',
'tests/test_post_message.cc',
'tests/test_post_message.h',
+ 'tests/test_printing.cc',
+ 'tests/test_printing.h',
'tests/test_scrollbar.cc',
'tests/test_scrollbar.h',
'tests/test_tcp_server_socket_private.cc',
diff --git a/ppapi/proxy/plugin_dispatcher.cc b/ppapi/proxy/plugin_dispatcher.cc
index d48dbfb..8dbca8d 100644
--- a/ppapi/proxy/plugin_dispatcher.cc
+++ b/ppapi/proxy/plugin_dispatcher.cc
@@ -102,6 +102,10 @@ PluginDispatcher* PluginDispatcher::GetForResource(const Resource* resource) {
// static
const void* PluginDispatcher::GetBrowserInterface(const char* interface_name) {
+ DCHECK(interface_name) << "|interface_name| is null. Did you forget to add "
+ "the |interface_name()| template function to the interface's C++ "
+ "wrapper?";
+
return InterfaceList::GetInstance()->GetInterfaceForPPB(interface_name);
}
diff --git a/ppapi/proxy/printing_resource.cc b/ppapi/proxy/printing_resource.cc
index 4d55db0..9fd8fde 100644
--- a/ppapi/proxy/printing_resource.cc
+++ b/ppapi/proxy/printing_resource.cc
@@ -34,7 +34,7 @@ int32_t PrintingResource::GetDefaultPrintSettings(
if (TrackedCallback::IsPending(callback_))
return PP_ERROR_INPROGRESS;
- if (!sent_create_to_renderer())
+ if (!sent_create_to_browser())
SendCreateToBrowser(PpapiHostMsg_Printing_Create());
DCHECK(!print_settings_);
diff --git a/ppapi/tests/test_printing.cc b/ppapi/tests/test_printing.cc
new file mode 100644
index 0000000..6a82ebb
--- /dev/null
+++ b/ppapi/tests/test_printing.cc
@@ -0,0 +1,64 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ppapi/tests/test_printing.h"
+
+#include "ppapi/cpp/dev/printing_dev.h"
+#include "ppapi/cpp/instance.h"
+#include "ppapi/tests/testing_instance.h"
+
+namespace {
+ bool g_callback_triggered;
+ int32_t g_callback_result;
+} // namespace
+
+REGISTER_TEST_CASE(Printing);
+
+class TestPrinting_Dev : public pp::Printing_Dev {
+ public:
+ explicit TestPrinting_Dev(pp::Instance* instance) :
+ pp::Printing_Dev(instance) {}
+ virtual ~TestPrinting_Dev() {}
+ virtual uint32_t QuerySupportedPrintOutputFormats() { return 0; }
+ virtual int32_t PrintBegin(
+ const PP_PrintSettings_Dev& print_settings) { return 0; }
+ virtual pp::Resource PrintPages(
+ const PP_PrintPageNumberRange_Dev* page_ranges,
+ uint32_t page_range_count) {
+ return pp::Resource();
+ }
+ virtual void PrintEnd() {}
+ virtual bool IsPrintScalingDisabled() { return false; }
+};
+
+TestPrinting::TestPrinting(TestingInstance* instance)
+ : TestCase(instance),
+ nested_event_(instance->pp_instance()) {
+ callback_factory_.Initialize(this);
+}
+
+void TestPrinting::RunTests(const std::string& filter) {
+ RUN_TEST(GetDefaultPrintSettings, filter);
+}
+
+std::string TestPrinting::TestGetDefaultPrintSettings() {
+ g_callback_triggered = false;
+ TestPrinting_Dev test_printing(instance_);
+ pp::CompletionCallbackWithOutput<PP_PrintSettings_Dev> cb =
+ callback_factory_.NewCallbackWithOutput(&TestPrinting::Callback);
+ test_printing.GetDefaultPrintSettings(cb);
+ nested_event_.Wait();
+
+ ASSERT_EQ(PP_OK, g_callback_result);
+ ASSERT_TRUE(g_callback_triggered);
+
+ PASS();
+}
+
+void TestPrinting::Callback(int32_t result,
+ PP_PrintSettings_Dev& /* unused */) {
+ g_callback_triggered = true;
+ g_callback_result = result;
+ nested_event_.Signal();
+}
diff --git a/ppapi/tests/test_printing.h b/ppapi/tests/test_printing.h
new file mode 100644
index 0000000..ceb0983
--- /dev/null
+++ b/ppapi/tests/test_printing.h
@@ -0,0 +1,35 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef PPAPI_TESTS_TEST_PRINTING_H_
+#define PPAPI_TESTS_TEST_PRINTING_H_
+
+#include <string>
+
+#include "ppapi/tests/test_case.h"
+#include "ppapi/tests/test_utils.h"
+#include "ppapi/utility/completion_callback_factory.h"
+
+struct PP_PrintSettings_Dev;
+
+class TestPrinting : public TestCase {
+ public:
+ explicit TestPrinting(TestingInstance* instance);
+
+ // TestCase implementation.
+ virtual void RunTests(const std::string& filter);
+
+ private:
+ // Tests.
+ std::string TestGetDefaultPrintSettings();
+
+ void Callback(int32_t result,
+ PP_PrintSettings_Dev&);
+
+ NestedEvent nested_event_;
+
+ pp::CompletionCallbackFactory<TestPrinting> callback_factory_;
+};
+
+#endif // PPAPI_TESTS_TEST_PRINTING_H_
diff --git a/ppapi/thunk/enter.cc b/ppapi/thunk/enter.cc
index d5d822b..c89c969 100644
--- a/ppapi/thunk/enter.cc
+++ b/ppapi/thunk/enter.cc
@@ -62,7 +62,8 @@ EnterBase::~EnterBase() {
// callback_ is cleared any time it is run, scheduled to be run, or once we
// know it will be completed asynchronously. So by this point it should be
// NULL.
- DCHECK(!callback_);
+ DCHECK(!callback_) << "|callback_| is not NULL. Did you forget to call "
+ "|EnterBase::SetResult| in the interface's thunk?";
}
int32_t EnterBase::SetResult(int32_t result) {