summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorajwong@chromium.org <ajwong@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-30 04:24:19 +0000
committerajwong@chromium.org <ajwong@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-30 04:24:19 +0000
commit152379498a36d2c6e2a56b3e509a7ca588de4f40 (patch)
treee3850c3683a3ded2907f2d8bac7533dbf907b84d
parent64b66889137bd35e1b8bb5151143362c4403623a (diff)
downloadchromium_src-152379498a36d2c6e2a56b3e509a7ca588de4f40.zip
chromium_src-152379498a36d2c6e2a56b3e509a7ca588de4f40.tar.gz
chromium_src-152379498a36d2c6e2a56b3e509a7ca588de4f40.tar.bz2
PPAPI interface for reading the enterprise policy as a big JSON blob.
This includes an implementation that pipes up through PluginDelegate, but stops short of connecting to the actual policy code. BUG=90213 TEST=new unittests + manual testing Review URL: http://codereview.chromium.org/7483019 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@94824 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/test/ui/ppapi_uitest.cc3
-rw-r--r--content/renderer/pepper_plugin_delegate_impl.cc32
-rw-r--r--content/renderer/pepper_plugin_delegate_impl.h113
-rw-r--r--ppapi/c/dev/ppb_query_policy_dev.h30
-rw-r--r--ppapi/c/dev/ppp_policy_update_dev.h27
-rw-r--r--ppapi/ppapi_cpp.gypi4
-rw-r--r--ppapi/ppapi_shared.gypi1
-rw-r--r--ppapi/ppapi_tests.gypi2
-rw-r--r--ppapi/proxy/ppb_instance_proxy.cc5
-rw-r--r--ppapi/proxy/ppb_instance_proxy.h1
-rw-r--r--ppapi/tests/all_c_includes.h2
-rw-r--r--ppapi/tests/test_query_policy.cc56
-rw-r--r--ppapi/tests/test_query_policy.h30
-rw-r--r--ppapi/thunk/ppb_instance_api.h5
-rw-r--r--ppapi/thunk/ppb_query_policy_thunk.cc33
-rw-r--r--ppapi/thunk/thunk.h2
-rw-r--r--webkit/plugins/ppapi/mock_plugin_delegate.cc6
-rw-r--r--webkit/plugins/ppapi/mock_plugin_delegate.h2
-rw-r--r--webkit/plugins/ppapi/plugin_delegate.h10
-rw-r--r--webkit/plugins/ppapi/plugin_module.cc3
-rw-r--r--webkit/plugins/ppapi/ppapi_plugin_instance.cc36
-rw-r--r--webkit/plugins/ppapi/ppapi_plugin_instance.h7
22 files changed, 355 insertions, 55 deletions
diff --git a/chrome/test/ui/ppapi_uitest.cc b/chrome/test/ui/ppapi_uitest.cc
index 0a955e8..4887b2d 100644
--- a/chrome/test/ui/ppapi_uitest.cc
+++ b/chrome/test/ui/ppapi_uitest.cc
@@ -209,6 +209,9 @@ TEST_PPAPI_IN_PROCESS(PostMessage)
TEST_PPAPI_IN_PROCESS(Memory)
TEST_PPAPI_OUT_OF_PROCESS(Memory)
+TEST_PPAPI_IN_PROCESS(QueryPolicy)
+//TEST_PPAPI_OUT_OF_PROCESS(QueryPolicy)
+
// http://crbug.com/90039 and http://crbug.com/83443 (Mac)
TEST_F(PPAPITest, FAILS_FileIO) {
RunTestViaHTTP("FileIO");
diff --git a/content/renderer/pepper_plugin_delegate_impl.cc b/content/renderer/pepper_plugin_delegate_impl.cc
index 3edf654..9b3516d 100644
--- a/content/renderer/pepper_plugin_delegate_impl.cc
+++ b/content/renderer/pepper_plugin_delegate_impl.cc
@@ -7,6 +7,7 @@
#include <cmath>
#include <queue>
+#include "base/bind.h"
#include "base/callback.h"
#include "base/command_line.h"
#include "base/file_path.h"
@@ -755,6 +756,7 @@ void PepperPluginDelegateImpl::PluginFocusChanged(bool focused) {
void PepperPluginDelegateImpl::PluginCrashed(
webkit::ppapi::PluginInstance* instance) {
+ subscribed_to_policy_updates_.erase(instance);
render_view_->PluginCrashed(instance->module()->path());
}
@@ -769,6 +771,7 @@ void PepperPluginDelegateImpl::InstanceCreated(
void PepperPluginDelegateImpl::InstanceDeleted(
webkit::ppapi::PluginInstance* instance) {
active_instances_.erase(instance);
+ subscribed_to_policy_updates_.erase(instance);
}
SkBitmap* PepperPluginDelegateImpl::GetSadPluginBitmap() {
@@ -997,6 +1000,13 @@ bool PepperPluginDelegateImpl::ReadDirectory(
return file_system_dispatcher->ReadDirectory(directory_path, dispatcher);
}
+void PepperPluginDelegateImpl::PublishPolicy(const std::string& policy_json) {
+ for (std::set<webkit::ppapi::PluginInstance*>::iterator i =
+ subscribed_to_policy_updates_.begin();
+ i != subscribed_to_policy_updates_.end(); ++i)
+ (*i)->HandlePolicyUpdate(policy_json);
+}
+
class AsyncOpenFileSystemURLCallbackTranslator
: public fileapi::FileSystemCallbackDispatcher {
public:
@@ -1276,6 +1286,22 @@ void PepperPluginDelegateImpl::ZoomLimitsChanged(double minimum_factor,
render_view_->webview()->zoomLimitsChanged(minimum_level, maximum_level);
}
+void PepperPluginDelegateImpl::SubscribeToPolicyUpdates(
+ webkit::ppapi::PluginInstance* instance) {
+ subscribed_to_policy_updates_.insert(instance);
+
+ // Call by the PPP interface via continuation to avoid reentry issues
+ // with being in the call chain that includes SubscribeToPolicyUpdates().
+ //
+ // TODO(ajwong): Hook this up into something that gets a real policy.
+ MessageLoop::current()->PostTask(
+ FROM_HERE,
+ base::Bind(&PepperPluginDelegateImpl::PublishInitialPolicy,
+ AsWeakPtr(),
+ make_scoped_refptr(instance),
+ "{\"test_policy\": \"i like bananas\"}"));
+}
+
std::string PepperPluginDelegateImpl::ResolveProxy(const GURL& url) {
int net_error;
std::string proxy_result;
@@ -1351,3 +1377,9 @@ base::SharedMemory* PepperPluginDelegateImpl::CreateAnonymousSharedMemory(
ppapi::Preferences PepperPluginDelegateImpl::GetPreferences() {
return ppapi::Preferences(render_view_->webkit_preferences());
}
+
+void PepperPluginDelegateImpl::PublishInitialPolicy(
+ scoped_refptr<webkit::ppapi::PluginInstance> instance,
+ const std::string& policy) {
+ instance->HandlePolicyUpdate(policy);
+}
diff --git a/content/renderer/pepper_plugin_delegate_impl.h b/content/renderer/pepper_plugin_delegate_impl.h
index 6e35152..20cb7f82 100644
--- a/content/renderer/pepper_plugin_delegate_impl.h
+++ b/content/renderer/pepper_plugin_delegate_impl.h
@@ -193,56 +193,65 @@ class PepperPluginDelegateImpl
virtual bool AsyncOpenFile(const FilePath& path,
int flags,
AsyncOpenFileCallback* callback);
- virtual bool AsyncOpenFileSystemURL(const GURL& path,
- int flags,
- AsyncOpenFileCallback* callback);
+ virtual bool AsyncOpenFileSystemURL(
+ const GURL& path,
+ int flags,
+ AsyncOpenFileCallback* callback) OVERRIDE;
virtual bool OpenFileSystem(
const GURL& url,
fileapi::FileSystemType type,
long long size,
- fileapi::FileSystemCallbackDispatcher* dispatcher);
- virtual bool MakeDirectory(const GURL& path,
- bool recursive,
- fileapi::FileSystemCallbackDispatcher* dispatcher);
- virtual bool Query(const GURL& path,
- fileapi::FileSystemCallbackDispatcher* dispatcher);
- virtual bool Touch(const GURL& path,
- const base::Time& last_access_time,
- const base::Time& last_modified_time,
- fileapi::FileSystemCallbackDispatcher* dispatcher);
- virtual bool Delete(const GURL& path,
- fileapi::FileSystemCallbackDispatcher* dispatcher);
- virtual bool Rename(const GURL& file_path,
- const GURL& new_file_path,
- fileapi::FileSystemCallbackDispatcher* dispatcher);
- virtual bool ReadDirectory(const GURL& directory_path,
- fileapi::FileSystemCallbackDispatcher* dispatcher);
+ fileapi::FileSystemCallbackDispatcher* dispatcher) OVERRIDE;
+ virtual bool MakeDirectory(
+ const GURL& path,
+ bool recursive,
+ fileapi::FileSystemCallbackDispatcher* dispatcher) OVERRIDE;
+ virtual bool Query(
+ const GURL& path,
+ fileapi::FileSystemCallbackDispatcher* dispatcher) OVERRIDE;
+ virtual bool Touch(
+ const GURL& path,
+ const base::Time& last_access_time,
+ const base::Time& last_modified_time,
+ fileapi::FileSystemCallbackDispatcher* dispatcher) OVERRIDE;
+ virtual bool Delete(
+ const GURL& path,
+ fileapi::FileSystemCallbackDispatcher* dispatcher) OVERRIDE;
+ virtual bool Rename(
+ const GURL& file_path,
+ const GURL& new_file_path,
+ fileapi::FileSystemCallbackDispatcher* dispatcher) OVERRIDE;
+ virtual bool ReadDirectory(
+ const GURL& directory_path,
+ fileapi::FileSystemCallbackDispatcher* dispatcher) OVERRIDE;
+ virtual void PublishPolicy(const std::string& policy_json) OVERRIDE;
virtual base::PlatformFileError OpenFile(
const webkit::ppapi::PepperFilePath& path,
int flags,
- base::PlatformFile* file);
+ base::PlatformFile* file) OVERRIDE;
virtual base::PlatformFileError RenameFile(
const webkit::ppapi::PepperFilePath& from_path,
- const webkit::ppapi::PepperFilePath& to_path);
+ const webkit::ppapi::PepperFilePath& to_path) OVERRIDE;
virtual base::PlatformFileError DeleteFileOrDir(
const webkit::ppapi::PepperFilePath& path,
- bool recursive);
+ bool recursive) OVERRIDE;
virtual base::PlatformFileError CreateDir(
- const webkit::ppapi::PepperFilePath& path);
+ const webkit::ppapi::PepperFilePath& path) OVERRIDE;
virtual base::PlatformFileError QueryFile(
const webkit::ppapi::PepperFilePath& path,
- base::PlatformFileInfo* info);
+ base::PlatformFileInfo* info) OVERRIDE;
virtual base::PlatformFileError GetDirContents(
const webkit::ppapi::PepperFilePath& path,
- webkit::ppapi::DirContents* contents);
- virtual scoped_refptr<base::MessageLoopProxy> GetFileThreadMessageLoopProxy();
+ webkit::ppapi::DirContents* contents) OVERRIDE;
+ virtual scoped_refptr<base::MessageLoopProxy>
+ GetFileThreadMessageLoopProxy() OVERRIDE;
virtual int32_t ConnectTcp(
webkit::ppapi::PPB_Flash_NetConnector_Impl* connector,
const char* host,
- uint16_t port);
+ uint16_t port) OVERRIDE;
virtual int32_t ConnectTcpAddress(
webkit::ppapi::PPB_Flash_NetConnector_Impl* connector,
- const struct PP_Flash_NetAddress* addr);
+ const struct PP_Flash_NetAddress* addr) OVERRIDE;
// This is the completion for both |ConnectTcp()| and |ConnectTcpAddress()|.
void OnConnectTcpACK(
int request_id,
@@ -252,7 +261,7 @@ class PepperPluginDelegateImpl
virtual int32_t ShowContextMenu(
webkit::ppapi::PluginInstance* instance,
webkit::ppapi::PPB_Flash_Menu_Impl* menu,
- const gfx::Point& position);
+ const gfx::Point& position) OVERRIDE;
void OnContextMenuClosed(
const webkit_glue::CustomContextMenuContext& custom_context);
void OnCustomContextMenuAction(
@@ -263,24 +272,32 @@ class PepperPluginDelegateImpl
unsigned action);
virtual webkit::ppapi::FullscreenContainer*
CreateFullscreenContainer(
- webkit::ppapi::PluginInstance* instance);
- virtual gfx::Size GetScreenSize();
- virtual std::string GetDefaultEncoding();
- virtual void ZoomLimitsChanged(double minimum_factor, double maximum_factor);
- virtual std::string ResolveProxy(const GURL& url);
- virtual void DidStartLoading();
- virtual void DidStopLoading();
- virtual void SetContentRestriction(int restrictions);
- virtual void HasUnsupportedFeature();
- virtual void SaveURLAs(const GURL& url);
- virtual P2PSocketDispatcher* GetP2PSocketDispatcher();
- virtual webkit_glue::P2PTransport* CreateP2PTransport();
- virtual double GetLocalTimeZoneOffset(base::Time t);
- virtual std::string GetFlashCommandLineArgs();
- virtual base::SharedMemory* CreateAnonymousSharedMemory(uint32_t size);
- virtual ::ppapi::Preferences GetPreferences();
+ webkit::ppapi::PluginInstance* instance) OVERRIDE;
+ virtual gfx::Size GetScreenSize() OVERRIDE;
+ virtual std::string GetDefaultEncoding() OVERRIDE;
+ virtual void ZoomLimitsChanged(double minimum_factor, double maximum_factor)
+ OVERRIDE;
+ virtual void SubscribeToPolicyUpdates(
+ webkit::ppapi::PluginInstance* instance) OVERRIDE;
+ virtual std::string ResolveProxy(const GURL& url) OVERRIDE;
+ virtual void DidStartLoading() OVERRIDE;
+ virtual void DidStopLoading() OVERRIDE;
+ virtual void SetContentRestriction(int restrictions) OVERRIDE;
+ virtual void HasUnsupportedFeature() OVERRIDE;
+ virtual void SaveURLAs(const GURL& url) OVERRIDE;
+ virtual P2PSocketDispatcher* GetP2PSocketDispatcher() OVERRIDE;
+ virtual webkit_glue::P2PTransport* CreateP2PTransport() OVERRIDE;
+ virtual double GetLocalTimeZoneOffset(base::Time t) OVERRIDE;
+ virtual std::string GetFlashCommandLineArgs() OVERRIDE;
+ virtual base::SharedMemory* CreateAnonymousSharedMemory(uint32_t size)
+ OVERRIDE;
+ virtual ::ppapi::Preferences GetPreferences() OVERRIDE;
private:
+ void PublishInitialPolicy(
+ scoped_refptr<webkit::ppapi::PluginInstance> instance,
+ const std::string& policy);
+
// Asynchronously attempts to create a PPAPI broker for the given plugin.
scoped_refptr<PpapiBrokerImpl> CreatePpapiBroker(
webkit::ppapi::PluginModule* plugin_module);
@@ -311,6 +328,10 @@ class PepperPluginDelegateImpl
// Whether or not the focus is on a PPAPI plugin
bool is_pepper_plugin_focused_;
+ // Set of instances to receive a notification when the enterprise policy has
+ // been updated.
+ std::set<webkit::ppapi::PluginInstance*> subscribed_to_policy_updates_;
+
DISALLOW_COPY_AND_ASSIGN(PepperPluginDelegateImpl);
};
diff --git a/ppapi/c/dev/ppb_query_policy_dev.h b/ppapi/c/dev/ppb_query_policy_dev.h
new file mode 100644
index 0000000..8d732a5
--- /dev/null
+++ b/ppapi/c/dev/ppb_query_policy_dev.h
@@ -0,0 +1,30 @@
+/* Copyright (c) 2011 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_C_PPB_QUERY_POLICY_DEV_H_
+#define PPAPI_C_PPB_QUERY_POLICY_DEV_H_
+
+#include "ppapi/c/pp_instance.h"
+#include "ppapi/c/pp_var.h"
+
+#define PPB_QUERY_POLICY_DEV_INTERFACE_0_1 "PPB_QueryPolicy;0.1"
+#define PPB_QUERY_POLICY_DEV_INTERFACE PPB_QUERY_POLICY_DEV_INTERFACE_0_1
+
+struct PPB_QueryPolicy_Dev {
+ /**
+ * Subscribes the instance to receive updates via the
+ * <code>PPP_PolicyUpdate_Dev</code> interface.
+ *
+ * The plugin is guaranteed to get one update immediately via the
+ * <code>PP_PolicyUpdate_Dev</code> interface. This allows the plugin to
+ * retrieve the current policy when subscribing for the first time.
+ *
+ * @param[in] instance A <code>PP_Instance</code> indentifying one instance
+ * of a module.
+ */
+ void (*SubscribeToPolicyUpdates)(PP_Instance instance);
+
+};
+
+#endif /* PPAPI_C_PPB_QUERY_POLICY_DEV_H_ */
diff --git a/ppapi/c/dev/ppp_policy_update_dev.h b/ppapi/c/dev/ppp_policy_update_dev.h
new file mode 100644
index 0000000..69c26b6
--- /dev/null
+++ b/ppapi/c/dev/ppp_policy_update_dev.h
@@ -0,0 +1,27 @@
+/* Copyright (c) 2011 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_C_PPP_POLICY_UPDATE_DEV_H_
+#define PPAPI_C_PPP_POLICY_UPDATE_DEV_H_
+
+#include "ppapi/c/pp_instance.h"
+#include "ppapi/c/pp_var.h"
+
+#define PPP_POLICY_UPDATE_DEV_INTERFACE_0_1 "PPB_PolicyUpdate;0.1"
+#define PPP_POLICY_UPDATE_DEV_INTERFACE PPP_POLICY_UPDATE_DEV_INTERFACE_0_1
+
+struct PPP_PolicyUpdate_Dev {
+ /**
+ * Signals that the policy has been updated, and provides it via a JSON
+ * string.
+ *
+ * @param[in] instance A <code>PP_Instance</code> indentifying one instance
+ * of a module.
+ * @param[in] A <code>PP_Var</code> with a JSON string representing the
+ * encoded policy.
+ */
+ void (*PolicyUpdated)(PP_Instance instance, struct PP_Var policy_json);
+};
+
+#endif /* PPAPI_C_PPP_POLICY_UPDATE_DEV_H_ */
diff --git a/ppapi/ppapi_cpp.gypi b/ppapi/ppapi_cpp.gypi
index f62732a..829fbe1 100644
--- a/ppapi/ppapi_cpp.gypi
+++ b/ppapi/ppapi_cpp.gypi
@@ -68,6 +68,7 @@
'c/dev/ppb_graphics_3d_trusted_dev.h',
'c/dev/ppb_memory_dev.h',
'c/dev/ppb_opengles_dev.h',
+ 'c/dev/ppb_query_policy_dev.h',
'c/dev/ppb_scrollbar_dev.h',
'c/dev/ppb_surface_3d_dev.h',
'c/dev/ppb_testing_dev.h',
@@ -79,9 +80,10 @@
'c/dev/ppp_find_dev.h',
'c/dev/ppp_graphics_3d_dev.h',
'c/dev/ppp_network_state_dev.h',
+ 'c/dev/ppp_policy_update_dev.h',
+ 'c/dev/ppp_printing_dev.h',
'c/dev/ppp_scrollbar_dev.h',
'c/dev/ppp_selection_dev.h',
- 'c/dev/ppp_printing_dev.h',
'c/dev/ppp_video_decoder_dev.h',
'c/dev/ppp_widget_dev.h',
'c/dev/ppp_zoom_dev.h',
diff --git a/ppapi/ppapi_shared.gypi b/ppapi/ppapi_shared.gypi
index f24bc7e..496a9dd 100644
--- a/ppapi/ppapi_shared.gypi
+++ b/ppapi/ppapi_shared.gypi
@@ -122,6 +122,7 @@
'thunk/ppb_layer_compositor_thunk.cc',
'thunk/ppb_messaging_thunk.cc',
'thunk/ppb_pdf_api.h',
+ 'thunk/ppb_query_policy_thunk.cc',
'thunk/ppb_scrollbar_api.h',
'thunk/ppb_scrollbar_thunk.cc',
'thunk/ppb_surface_3d_api.h',
diff --git a/ppapi/ppapi_tests.gypi b/ppapi/ppapi_tests.gypi
index 93f9c88..be8795c 100644
--- a/ppapi/ppapi_tests.gypi
+++ b/ppapi/ppapi_tests.gypi
@@ -102,6 +102,8 @@
'tests/test_paint_aggregator.h',
'tests/test_post_message.cc',
'tests/test_post_message.h',
+ 'tests/test_query_policy.cc',
+ 'tests/test_query_policy.h',
'tests/test_scrollbar.cc',
'tests/test_scrollbar.h',
'tests/test_struct_sizes.c',
diff --git a/ppapi/proxy/ppb_instance_proxy.cc b/ppapi/proxy/ppb_instance_proxy.cc
index 7bb6ba1..a936688 100644
--- a/ppapi/proxy/ppb_instance_proxy.cc
+++ b/ppapi/proxy/ppb_instance_proxy.cc
@@ -259,6 +259,11 @@ void PPB_Instance_Proxy::ZoomLimitsChanged(PP_Instance instance,
NOTIMPLEMENTED();
}
+void PPB_Instance_Proxy::SubscribeToPolicyUpdates(PP_Instance instance) {
+ // Not proxied yet.
+ NOTIMPLEMENTED();
+}
+
void PPB_Instance_Proxy::PostMessage(PP_Instance instance,
PP_Var message) {
dispatcher()->Send(new PpapiHostMsg_PPBInstance_PostMessage(
diff --git a/ppapi/proxy/ppb_instance_proxy.h b/ppapi/proxy/ppb_instance_proxy.h
index fc2dac3..282f4a9 100644
--- a/ppapi/proxy/ppb_instance_proxy.h
+++ b/ppapi/proxy/ppb_instance_proxy.h
@@ -64,6 +64,7 @@ class PPB_Instance_Proxy : public InterfaceProxy,
virtual void ZoomLimitsChanged(PP_Instance instance,
double minimum_factor,
double maximium_factor) OVERRIDE;
+ virtual void SubscribeToPolicyUpdates(PP_Instance instance) OVERRIDE;
virtual void PostMessage(PP_Instance instance, PP_Var message) OVERRIDE;
private:
diff --git a/ppapi/tests/all_c_includes.h b/ppapi/tests/all_c_includes.h
index eae0b86..bd538aa 100644
--- a/ppapi/tests/all_c_includes.h
+++ b/ppapi/tests/all_c_includes.h
@@ -29,6 +29,7 @@
#include "ppapi/c/dev/ppb_layer_compositor_dev.h"
#include "ppapi/c/dev/ppb_memory_dev.h"
#include "ppapi/c/dev/ppb_opengles_dev.h"
+#include "ppapi/c/dev/ppb_query_policy_dev.h"
#include "ppapi/c/dev/ppb_scrollbar_dev.h"
#include "ppapi/c/dev/ppb_surface_3d_dev.h"
#include "ppapi/c/dev/ppb_testing_dev.h"
@@ -43,6 +44,7 @@
#include "ppapi/c/dev/ppp_cursor_control_dev.h"
#include "ppapi/c/dev/ppp_find_dev.h"
#include "ppapi/c/dev/ppp_graphics_3d_dev.h"
+#include "ppapi/c/dev/ppp_policy_update_dev.h"
#include "ppapi/c/dev/ppp_printing_dev.h"
#include "ppapi/c/dev/ppp_scrollbar_dev.h"
#include "ppapi/c/dev/ppp_selection_dev.h"
diff --git a/ppapi/tests/test_query_policy.cc b/ppapi/tests/test_query_policy.cc
new file mode 100644
index 0000000..269a57c
--- /dev/null
+++ b/ppapi/tests/test_query_policy.cc
@@ -0,0 +1,56 @@
+// Copyright (c) 2011 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_query_policy.h"
+
+#include "ppapi/c/dev/ppb_query_policy_dev.h"
+#include "ppapi/c/dev/ppp_policy_update_dev.h"
+#include "ppapi/cpp/instance.h"
+#include "ppapi/cpp/module.h"
+#include "ppapi/cpp/var.h"
+#include "ppapi/tests/test_utils.h"
+#include "ppapi/tests/testing_instance.h"
+
+REGISTER_TEST_CASE(QueryPolicy);
+
+namespace {
+
+// Since this is a unittest, we don't care about a global string.
+std::string g_received_policy;
+
+void PolicyUpdated(PP_Instance instance, PP_Var pp_policy_json) {
+ g_received_policy = pp::Var(pp::Var::DontManage(), pp_policy_json).AsString();
+ GetTestingInterface()->QuitMessageLoop(instance);
+}
+
+static PPP_PolicyUpdate_Dev policy_updated_interface = {
+ &PolicyUpdated,
+};
+
+} // namespace
+
+bool TestQueryPolicy::Init() {
+ query_policy_interface_ = static_cast<PPB_QueryPolicy_Dev const*>(
+ pp::Module::Get()->GetBrowserInterface(PPB_QUERY_POLICY_DEV_INTERFACE));
+ pp::Module::Get()->AddPluginInterface(PPP_POLICY_UPDATE_DEV_INTERFACE,
+ &policy_updated_interface);
+
+ return query_policy_interface_ && InitTestingInterface();
+}
+
+void TestQueryPolicy::RunTest() {
+ RUN_TEST(SubscribeToPolicyUpdates);
+}
+
+std::string TestQueryPolicy::TestSubscribeToPolicyUpdates() {
+ query_policy_interface_->SubscribeToPolicyUpdates(
+ instance_->pp_instance());
+
+ // Wait for a response on PPP_PolicyUpdate_Dev.
+ GetTestingInterface()->RunMessageLoop(instance_->pp_instance());
+
+ ASSERT_TRUE(g_received_policy == "{\"test_policy\": \"i like bananas\"}");
+
+ PASS();
+}
diff --git a/ppapi/tests/test_query_policy.h b/ppapi/tests/test_query_policy.h
new file mode 100644
index 0000000..436ae19
--- /dev/null
+++ b/ppapi/tests/test_query_policy.h
@@ -0,0 +1,30 @@
+// Copyright (c) 2011 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 PAPPI_TESTS_TEST_QUERY_POLICY_H_
+#define PAPPI_TESTS_TEST_QUERY_POLICY_H_
+
+#include <string>
+
+#include "ppapi/tests/test_case.h"
+
+struct PPB_QueryPolicy_Dev;
+
+class TestQueryPolicy : public TestCase {
+ public:
+ explicit TestQueryPolicy(TestingInstance* instance) : TestCase(instance) {}
+
+ // TestCase implementation.
+ virtual bool Init();
+ virtual void RunTest();
+
+ private:
+ std::string TestGetFullPolicy();
+ std::string TestSubscribeToPolicyUpdates();
+
+ // Used by the tests that access the C API directly.
+ const PPB_QueryPolicy_Dev* query_policy_interface_;
+};
+
+#endif // PAPPI_TESTS_TEST_BUFFER_H_
diff --git a/ppapi/thunk/ppb_instance_api.h b/ppapi/thunk/ppb_instance_api.h
index f06a759..4b5e78d 100644
--- a/ppapi/thunk/ppb_instance_api.h
+++ b/ppapi/thunk/ppb_instance_api.h
@@ -44,12 +44,15 @@ class PPB_Instance_FunctionAPI {
// Messaging.
virtual void PostMessage(PP_Instance instance, PP_Var message) = 0;
- // Zoom
+ // Zoom.
virtual void ZoomChanged(PP_Instance instance, double factor) = 0;
virtual void ZoomLimitsChanged(PP_Instance instance,
double minimum_factor,
double maximium_factor) = 0;
+ // QueryPolicy.
+ virtual void SubscribeToPolicyUpdates(PP_Instance instance) = 0;
+
static const ::pp::proxy::InterfaceID interface_id =
::pp::proxy::INTERFACE_ID_PPB_INSTANCE;
};
diff --git a/ppapi/thunk/ppb_query_policy_thunk.cc b/ppapi/thunk/ppb_query_policy_thunk.cc
new file mode 100644
index 0000000..468704b
--- /dev/null
+++ b/ppapi/thunk/ppb_query_policy_thunk.cc
@@ -0,0 +1,33 @@
+// Copyright (c) 2011 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/c/dev/ppb_query_policy_dev.h"
+#include "ppapi/thunk/thunk.h"
+#include "ppapi/thunk/enter.h"
+#include "ppapi/thunk/ppb_instance_api.h"
+
+namespace ppapi {
+namespace thunk {
+
+namespace {
+
+void SubscribeToPolicyUpdates(PP_Instance instance) {
+ EnterFunction<PPB_Instance_FunctionAPI> enter(instance, true);
+ if (enter.failed())
+ return;
+ enter.functions()->SubscribeToPolicyUpdates(instance);
+}
+
+const PPB_QueryPolicy_Dev g_ppb_querypolicy_thunk = {
+ &SubscribeToPolicyUpdates,
+};
+
+} // namespace
+
+const PPB_QueryPolicy_Dev* GetPPB_QueryPolicy_Thunk() {
+ return &g_ppb_querypolicy_thunk;
+}
+
+} // namespace thunk
+} // namespace ppapi
diff --git a/ppapi/thunk/thunk.h b/ppapi/thunk/thunk.h
index 91484e1..46544cc 100644
--- a/ppapi/thunk/thunk.h
+++ b/ppapi/thunk/thunk.h
@@ -39,6 +39,7 @@ struct PPB_KeyboardInputEvent;
struct PPB_LayerCompositor_Dev;
struct PPB_Messaging;
struct PPB_MouseInputEvent;
+struct PPB_QueryPolicy_Dev;
struct PPB_Scrollbar_0_4_Dev;
struct PPB_Surface3D_Dev;
struct PPB_Transport_Dev;
@@ -90,6 +91,7 @@ const PPB_Instance_1_0* GetPPB_Instance_1_0_Thunk();
const PPB_Instance_Private* GetPPB_Instance_Private_Thunk();
const PPB_KeyboardInputEvent* GetPPB_KeyboardInputEvent_Thunk();
const PPB_LayerCompositor_Dev* GetPPB_LayerCompositor_Thunk();
+const PPB_QueryPolicy_Dev* GetPPB_QueryPolicy_Thunk();
const PPB_Messaging* GetPPB_Messaging_Thunk();
const PPB_MouseInputEvent* GetPPB_MouseInputEvent_Thunk();
const PPB_Scrollbar_0_4_Dev* GetPPB_Scrollbar_Thunk();
diff --git a/webkit/plugins/ppapi/mock_plugin_delegate.cc b/webkit/plugins/ppapi/mock_plugin_delegate.cc
index 9fe11e6..d5db46fa 100644
--- a/webkit/plugins/ppapi/mock_plugin_delegate.cc
+++ b/webkit/plugins/ppapi/mock_plugin_delegate.cc
@@ -171,6 +171,9 @@ base::PlatformFileError MockPluginDelegate::GetDirContents(
return base::PLATFORM_FILE_ERROR_FAILED;
}
+void MockPluginDelegate::PublishPolicy(const std::string& policy_json) {
+}
+
scoped_refptr<base::MessageLoopProxy>
MockPluginDelegate::GetFileThreadMessageLoopProxy() {
return scoped_refptr<base::MessageLoopProxy>();
@@ -213,6 +216,9 @@ void MockPluginDelegate::ZoomLimitsChanged(double minimum_factor,
double maximum_factor) {
}
+void MockPluginDelegate::SubscribeToPolicyUpdates(PluginInstance* instance) {
+}
+
std::string MockPluginDelegate::ResolveProxy(const GURL& url) {
return std::string();
}
diff --git a/webkit/plugins/ppapi/mock_plugin_delegate.h b/webkit/plugins/ppapi/mock_plugin_delegate.h
index 5a6c9f8..f74443e 100644
--- a/webkit/plugins/ppapi/mock_plugin_delegate.h
+++ b/webkit/plugins/ppapi/mock_plugin_delegate.h
@@ -77,6 +77,7 @@ class MockPluginDelegate : public PluginDelegate {
base::PlatformFileInfo* info);
virtual base::PlatformFileError GetDirContents(const PepperFilePath& path,
DirContents* contents);
+ virtual void PublishPolicy(const std::string& policy_json);
virtual scoped_refptr<base::MessageLoopProxy>
GetFileThreadMessageLoopProxy();
virtual int32_t ConnectTcp(
@@ -96,6 +97,7 @@ class MockPluginDelegate : public PluginDelegate {
virtual std::string GetDefaultEncoding();
virtual void ZoomLimitsChanged(double minimum_factor,
double maximum_factor);
+ virtual void SubscribeToPolicyUpdates(PluginInstance* instance);
virtual std::string ResolveProxy(const GURL& url);
virtual void DidStartLoading();
virtual void DidStopLoading();
diff --git a/webkit/plugins/ppapi/plugin_delegate.h b/webkit/plugins/ppapi/plugin_delegate.h
index 7c2ad18..bb3301f 100644
--- a/webkit/plugins/ppapi/plugin_delegate.h
+++ b/webkit/plugins/ppapi/plugin_delegate.h
@@ -325,6 +325,12 @@ class PluginDelegate {
const GURL& directory_path,
fileapi::FileSystemCallbackDispatcher* dispatcher) = 0;
+ // Takes a UTF-8 string representing the enterprise policy, and pushes it to
+ // every plugin instance that has called SubscribeToPolicyUpdates().
+ //
+ // This should be called when the enterprise policy is updated.
+ virtual void PublishPolicy(const std::string& policy_json) = 0;
+
virtual base::PlatformFileError OpenFile(const PepperFilePath& path,
int flags,
base::PlatformFile* file) = 0;
@@ -374,6 +380,10 @@ class PluginDelegate {
virtual void ZoomLimitsChanged(double minimum_factor,
double maximum_factor) = 0;
+ // Subscribes the instances to notifications that the policy has been
+ // updated.
+ virtual void SubscribeToPolicyUpdates(PluginInstance* instance) = 0;
+
// Retrieves the proxy information for the given URL in PAC format. On error,
// this will return an empty string.
virtual std::string ResolveProxy(const GURL& url) = 0;
diff --git a/webkit/plugins/ppapi/plugin_module.cc b/webkit/plugins/ppapi/plugin_module.cc
index bff83f1..3c77a6e 100644
--- a/webkit/plugins/ppapi/plugin_module.cc
+++ b/webkit/plugins/ppapi/plugin_module.cc
@@ -29,6 +29,7 @@
#include "ppapi/c/dev/ppb_layer_compositor_dev.h"
#include "ppapi/c/dev/ppb_memory_dev.h"
#include "ppapi/c/dev/ppb_opengles_dev.h"
+#include "ppapi/c/dev/ppb_query_policy_dev.h"
#include "ppapi/c/dev/ppb_scrollbar_dev.h"
#include "ppapi/c/dev/ppb_surface_3d_dev.h"
#include "ppapi/c/dev/ppb_testing_dev.h"
@@ -306,6 +307,8 @@ const void* GetInterface(const char* name) {
return ::ppapi::thunk::GetPPB_MouseInputEvent_Thunk();
if (strcmp(name, PPB_PROXY_PRIVATE_INTERFACE) == 0)
return PPB_Proxy_Impl::GetInterface();
+ if (strcmp(name, PPB_QUERY_POLICY_DEV_INTERFACE_0_1) == 0)
+ return ::ppapi::thunk::GetPPB_QueryPolicy_Thunk();
if (strcmp(name, PPB_SCROLLBAR_DEV_INTERFACE_0_4) == 0)
return ::ppapi::thunk::GetPPB_Scrollbar_Thunk();
if (strcmp(name, PPB_SCROLLBAR_DEV_INTERFACE_0_3) == 0)
diff --git a/webkit/plugins/ppapi/ppapi_plugin_instance.cc b/webkit/plugins/ppapi/ppapi_plugin_instance.cc
index 44c908f..08b1d16 100644
--- a/webkit/plugins/ppapi/ppapi_plugin_instance.cc
+++ b/webkit/plugins/ppapi/ppapi_plugin_instance.cc
@@ -14,6 +14,7 @@
#include "ppapi/c/dev/ppb_memory_dev.h"
#include "ppapi/c/dev/ppb_zoom_dev.h"
#include "ppapi/c/dev/ppp_find_dev.h"
+#include "ppapi/c/dev/ppp_policy_update_dev.h"
#include "ppapi/c/dev/ppp_selection_dev.h"
#include "ppapi/c/dev/ppp_zoom_dev.h"
#include "ppapi/c/pp_input_event.h"
@@ -219,6 +220,7 @@ PluginInstance::PluginInstance(
plugin_input_event_interface_(NULL),
plugin_private_interface_(NULL),
plugin_pdf_interface_(NULL),
+ plugin_policy_updated_interface_(NULL),
plugin_selection_interface_(NULL),
plugin_zoom_interface_(NULL),
checked_for_plugin_input_event_interface_(false),
@@ -474,6 +476,14 @@ bool PluginInstance::HandleInputEvent(const WebKit::WebInputEvent& event,
return rv;
}
+void PluginInstance::HandlePolicyUpdate(const std::string& policy_json) {
+ if (!LoadPolicyUpdateInterface())
+ return;
+ plugin_policy_updated_interface_->PolicyUpdated(
+ pp_instance(),
+ StringVar::StringToPPVar(module()->pp_module(), policy_json));
+}
+
void PluginInstance::HandleMessage(PP_Var message) {
// Keep a reference on the stack. See NOTE above.
scoped_refptr<PluginInstance> ref(this);
@@ -700,14 +710,14 @@ bool PluginInstance::LoadPdfInterface() {
return !!plugin_pdf_interface_;
}
-bool PluginInstance::LoadSelectionInterface() {
- if (!plugin_selection_interface_) {
- plugin_selection_interface_ =
- static_cast<const PPP_Selection_Dev*>(module_->GetPluginInterface(
- PPP_SELECTION_DEV_INTERFACE));
+bool PluginInstance::LoadPolicyUpdateInterface() {
+ if (!plugin_policy_updated_interface_) {
+ plugin_policy_updated_interface_ =
+ static_cast<const PPP_PolicyUpdate_Dev*>(module_->GetPluginInterface(
+ PPP_POLICY_UPDATE_DEV_INTERFACE));
}
- return !!plugin_selection_interface_;
+ return !!plugin_policy_updated_interface_;
}
bool PluginInstance::LoadPrintInterface() {
@@ -740,6 +750,16 @@ bool PluginInstance::LoadPrivateInterface() {
return !!plugin_private_interface_;
}
+bool PluginInstance::LoadSelectionInterface() {
+ if (!plugin_selection_interface_) {
+ plugin_selection_interface_ =
+ static_cast<const PPP_Selection_Dev*>(module_->GetPluginInterface(
+ PPP_SELECTION_DEV_INTERFACE));
+ }
+
+ return !!plugin_selection_interface_;
+}
+
bool PluginInstance::LoadZoomInterface() {
if (!plugin_zoom_interface_) {
plugin_zoom_interface_ =
@@ -1517,5 +1537,9 @@ void PluginInstance::PostMessage(PP_Instance instance, PP_Var message) {
message_channel_->PostMessageToJavaScript(message);
}
+void PluginInstance::SubscribeToPolicyUpdates(PP_Instance instance) {
+ delegate()->SubscribeToPolicyUpdates(this);
+}
+
} // namespace ppapi
} // namespace webkit
diff --git a/webkit/plugins/ppapi/ppapi_plugin_instance.h b/webkit/plugins/ppapi/ppapi_plugin_instance.h
index 1380039..6fbc367 100644
--- a/webkit/plugins/ppapi/ppapi_plugin_instance.h
+++ b/webkit/plugins/ppapi/ppapi_plugin_instance.h
@@ -39,6 +39,7 @@ struct PPP_InputEvent;
struct PPP_Instance_Private;
struct PPP_Messaging;
struct PPP_Pdf;
+struct PPP_PolicyUpdate_Dev;
struct PPP_Selection_Dev;
struct PPP_Zoom_Dev;
@@ -162,6 +163,7 @@ class PluginInstance : public base::RefCounted<PluginInstance>,
bool HandleDocumentLoad(PPB_URLLoader_Impl* loader);
bool HandleInputEvent(const WebKit::WebInputEvent& event,
WebKit::WebCursorInfo* cursor_info);
+ void HandlePolicyUpdate(const std::string& policy_json);
PP_Var GetInstanceObject();
void ViewChanged(const gfx::Rect& position, const gfx::Rect& clip);
@@ -272,6 +274,7 @@ class PluginInstance : public base::RefCounted<PluginInstance>,
double minimum_factor,
double maximium_factor) OVERRIDE;
virtual void PostMessage(PP_Instance instance, PP_Var message) OVERRIDE;
+ virtual void SubscribeToPolicyUpdates(PP_Instance instance) OVERRIDE;
private:
// See the static Create functions above for creating PluginInstance objects.
@@ -286,9 +289,10 @@ class PluginInstance : public base::RefCounted<PluginInstance>,
bool LoadInputEventInterface();
bool LoadMessagingInterface();
bool LoadPdfInterface();
- bool LoadSelectionInterface();
+ bool LoadPolicyUpdateInterface();
bool LoadPrintInterface();
bool LoadPrivateInterface();
+ bool LoadSelectionInterface();
bool LoadZoomInterface();
// Determines if we think the plugin has focus, both content area and webkit
@@ -384,6 +388,7 @@ class PluginInstance : public base::RefCounted<PluginInstance>,
const PPP_InputEvent* plugin_input_event_interface_;
const PPP_Instance_Private* plugin_private_interface_;
const PPP_Pdf* plugin_pdf_interface_;
+ const PPP_PolicyUpdate_Dev* plugin_policy_updated_interface_;
const PPP_Selection_Dev* plugin_selection_interface_;
const PPP_Zoom_Dev* plugin_zoom_interface_;