summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoraa <aa@chromium.org>2014-10-24 19:20:46 -0700
committerCommit bot <commit-bot@chromium.org>2014-10-25 02:21:04 +0000
commitfa2c4704220d8d8e124816b694e8549ee322809b (patch)
tree6f4e95173508fd446f390fb350c1a40fffc73672
parentdce6f5129b13fad0a595027b6eb34474d951263f (diff)
downloadchromium_src-fa2c4704220d8d8e124816b694e8549ee322809b.zip
chromium_src-fa2c4704220d8d8e124816b694e8549ee322809b.tar.gz
chromium_src-fa2c4704220d8d8e124816b694e8549ee322809b.tar.bz2
Update mojo sdk to rev e0416d1cfdcc669756d29802aa8644586273f5c7
Review URL: https://codereview.chromium.org/644883004 Cr-Commit-Position: refs/heads/master@{#301265}
-rw-r--r--mojo/edk/system/channel.cc38
-rw-r--r--mojo/edk/system/channel.h6
-rw-r--r--mojo/edk/system/channel_endpoint_id.h2
-rw-r--r--mojo/edk/system/channel_unittest.cc13
-rw-r--r--mojo/edk/system/remote_message_pipe_unittest.cc100
-rw-r--r--mojo/public/BUILD.gn1
-rw-r--r--mojo/public/VERSION2
-rw-r--r--mojo/public/cpp/application/application_impl.h8
-rw-r--r--mojo/public/cpp/bindings/tests/connector_unittest.cc4
-rw-r--r--mojo/public/cpp/bindings/tests/router_unittest.cc4
-rw-r--r--mojo/public/tools/bindings/generators/cpp_templates/wrapper_class_declaration.tmpl5
-rw-r--r--mojo/services/html_viewer/html_document_view.cc13
-rw-r--r--mojo/services/html_viewer/html_document_view.h4
-rw-r--r--mojo/services/public/cpp/network/udp_socket_wrapper.cc51
-rw-r--r--mojo/services/public/cpp/view_manager/BUILD.gn3
-rw-r--r--mojo/services/public/cpp/view_manager/lib/view.cc46
-rw-r--r--mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.cc40
-rw-r--r--mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.h11
-rw-r--r--mojo/services/public/cpp/view_manager/lib/view_private.h8
-rw-r--r--mojo/services/public/cpp/view_manager/tests/view_manager_unittest.cc29
-rw-r--r--mojo/services/public/cpp/view_manager/tests/view_unittest.cc103
-rw-r--r--mojo/services/public/cpp/view_manager/view.h18
-rw-r--r--mojo/services/public/cpp/view_manager/view_observer.h17
-rw-r--r--mojo/services/public/interfaces/view_manager/view_manager.mojom14
24 files changed, 365 insertions, 175 deletions
diff --git a/mojo/edk/system/channel.cc b/mojo/edk/system/channel.cc
index f008bec..b63aaeb 100644
--- a/mojo/edk/system/channel.cc
+++ b/mojo/edk/system/channel.cc
@@ -86,44 +86,6 @@ void Channel::WillShutdownSoon() {
// keeps the endpoint alive even after the lock is released. Otherwise, there's
// the temptation to simply pass the result of |new ChannelEndpoint(...)|
// directly to this function, which wouldn't be sufficient for safety.
-ChannelEndpointId Channel::AttachEndpoint(
- scoped_refptr<ChannelEndpoint> endpoint) {
- DCHECK(endpoint.get());
-
- ChannelEndpointId local_id;
- {
- base::AutoLock locker(lock_);
-
- DLOG_IF(WARNING, is_shutting_down_)
- << "AttachEndpoint() while shutting down";
-
- do {
- local_id = local_id_generator_.GetNext();
- } while (local_id_to_endpoint_map_.find(local_id) !=
- local_id_to_endpoint_map_.end());
- local_id_to_endpoint_map_[local_id] = endpoint;
- }
-
- endpoint->AttachToChannel(this, local_id);
- return local_id;
-}
-
-// TODO(vtl): This function is currently slightly absurd, but we'll eventually
-// get rid of it and merge it with |AttachEndpoint()|.
-void Channel::RunEndpoint(scoped_refptr<ChannelEndpoint> endpoint,
- ChannelEndpointId remote_id) {
- {
- base::AutoLock locker(lock_);
-
- DLOG_IF(WARNING, is_shutting_down_)
- << "RunMessagePipeEndpoint() while shutting down";
- }
-
- // TODO(vtl): FIXME -- We need to handle the case that message pipe is already
- // running when we're here due to |kSubtypeChannelRunMessagePipeEndpoint|).
- endpoint->Run(remote_id);
-}
-
ChannelEndpointId Channel::AttachAndRunEndpoint(
scoped_refptr<ChannelEndpoint> endpoint,
bool is_bootstrap) {
diff --git a/mojo/edk/system/channel.h b/mojo/edk/system/channel.h
index fd718e5..6697965 100644
--- a/mojo/edk/system/channel.h
+++ b/mojo/edk/system/channel.h
@@ -71,12 +71,6 @@ class MOJO_SYSTEM_IMPL_EXPORT Channel
// may be called multiple times, or not at all.)
void WillShutdownSoon();
- // TODO(vtl): Remove these once |AttachAndRunEndpoint()| is fully implemented
- // and everything is converted to use it.
- ChannelEndpointId AttachEndpoint(scoped_refptr<ChannelEndpoint> endpoint);
- void RunEndpoint(scoped_refptr<ChannelEndpoint> endpoint,
- ChannelEndpointId remote_id);
-
// Attaches the given endpoint to this channel and runs it. |is_bootstrap|
// should be set if and only if it is the first endpoint on the channel. This
// assigns the endpoint both local and remote IDs. If |is_bootstrap| is set,
diff --git a/mojo/edk/system/channel_endpoint_id.h b/mojo/edk/system/channel_endpoint_id.h
index 3636af7..c673258 100644
--- a/mojo/edk/system/channel_endpoint_id.h
+++ b/mojo/edk/system/channel_endpoint_id.h
@@ -57,7 +57,7 @@ class MOJO_SYSTEM_IMPL_EXPORT ChannelEndpointId {
bool is_valid() const { return !!value_; }
bool is_remote() const { return !!(value_ & kRemoteFlag); }
- uint32_t value() const { return value_; }
+ const uint32_t& value() const { return value_; }
// Flag set in |value()| if this is a remote ID.
static const uint32_t kRemoteFlag = 0x80000000u;
diff --git a/mojo/edk/system/channel_unittest.cc b/mojo/edk/system/channel_unittest.cc
index 7d45f6e..f6cf896 100644
--- a/mojo/edk/system/channel_unittest.cc
+++ b/mojo/edk/system/channel_unittest.cc
@@ -181,7 +181,7 @@ TEST_F(ChannelTest, InitFails) {
*mutable_channel() = nullptr;
}
-// ChannelTest.CloseBeforeRun --------------------------------------------------
+// ChannelTest.CloseBeforeAttachAndRun -----------------------------------------
TEST_F(ChannelTest, CloseBeforeRun) {
io_thread()->PostTaskAndWait(FROM_HERE,
@@ -198,18 +198,9 @@ TEST_F(ChannelTest, CloseBeforeRun) {
scoped_refptr<MessagePipe> mp(
MessagePipe::CreateLocalProxy(&channel_endpoint));
- ChannelEndpointId local_id = channel()->AttachEndpoint(channel_endpoint);
- EXPECT_EQ(ChannelEndpointId::GetBootstrap(), local_id);
-
mp->Close(0);
- // TODO(vtl): Currently, the |Close()| above won't detach (since it thinks
- // we're still expecting a "run" message from the other side), so the
- // |RunMessagePipeEndpoint()| below will return true. We need to refactor
- // |AttachEndpoint()| to indicate whether |Run...()| will necessarily be
- // called or not. (Then, in the case that it may not be called, this will
- // return false.)
- channel()->RunEndpoint(channel_endpoint, ChannelEndpointId::GetBootstrap());
+ channel()->AttachAndRunEndpoint(channel_endpoint, true);
io_thread()->PostTaskAndWait(
FROM_HERE,
diff --git a/mojo/edk/system/remote_message_pipe_unittest.cc b/mojo/edk/system/remote_message_pipe_unittest.cc
index 6e0b991..6f653d9 100644
--- a/mojo/edk/system/remote_message_pipe_unittest.cc
+++ b/mojo/edk/system/remote_message_pipe_unittest.cc
@@ -61,21 +61,22 @@ class RemoteMessagePipeTest : public testing::Test {
}
protected:
- // This connects the two given |ChannelEndpoint|s.
- void ConnectChannelEndpoints(scoped_refptr<ChannelEndpoint> ep0,
- scoped_refptr<ChannelEndpoint> ep1) {
+ // This connects the two given |ChannelEndpoint|s. It assumes/requires that
+ // this is the bootstrap case (i.e., no other message pipes have ever been
+ // hosted on the channel).
+ void BootstrapChannelEndpoints(scoped_refptr<ChannelEndpoint> ep0,
+ scoped_refptr<ChannelEndpoint> ep1) {
io_thread_.PostTaskAndWait(
FROM_HERE,
- base::Bind(&RemoteMessagePipeTest::ConnectChannelEndpointsOnIOThread,
+ base::Bind(&RemoteMessagePipeTest::BootstrapChannelEndpointsOnIOThread,
base::Unretained(this),
ep0,
ep1));
}
// This bootstraps |ep| on |channels_[channel_index]|. It assumes/requires
- // that this is the bootstrap case, i.e., that the endpoint IDs are both/will
- // both be |ChannelEndpointId::GetBootstrap()|. This returns *without* waiting
- // for it to finish connecting.
+ // that this is the bootstrap case (i.e., no message pipes have ever been
+ // hosted on the channel). This returns *without* waiting.
void BootstrapChannelEndpointNoWait(unsigned channel_index,
scoped_refptr<ChannelEndpoint> ep) {
io_thread_.PostTask(
@@ -95,6 +96,9 @@ class RemoteMessagePipeTest : public testing::Test {
embedder::PlatformSupport* platform_support() { return &platform_support_; }
base::TestIOThread* io_thread() { return &io_thread_; }
+ // Warning: It's up to the caller to ensure that the returned channel
+ // is/remains valid.
+ Channel* channels(size_t i) { return channels_[i].get(); }
private:
void SetUpOnIOThread() {
@@ -128,8 +132,8 @@ class RemoteMessagePipeTest : public testing::Test {
RawChannel::Create(platform_handles_[channel_index].Pass())));
}
- void ConnectChannelEndpointsOnIOThread(scoped_refptr<ChannelEndpoint> ep0,
- scoped_refptr<ChannelEndpoint> ep1) {
+ void BootstrapChannelEndpointsOnIOThread(scoped_refptr<ChannelEndpoint> ep0,
+ scoped_refptr<ChannelEndpoint> ep1) {
CHECK_EQ(base::MessageLoop::current(), io_thread()->message_loop());
if (!channels_[0].get())
@@ -137,11 +141,8 @@ class RemoteMessagePipeTest : public testing::Test {
if (!channels_[1].get())
CreateAndInitChannel(1);
- ChannelEndpointId local_id0 = channels_[0]->AttachEndpoint(ep0);
- ChannelEndpointId local_id1 = channels_[1]->AttachEndpoint(ep1);
-
- channels_[0]->RunEndpoint(ep0, local_id1);
- channels_[1]->RunEndpoint(ep1, local_id0);
+ channels_[0]->AttachAndRunEndpoint(ep0, true);
+ channels_[1]->AttachAndRunEndpoint(ep1, true);
}
void BootstrapChannelEndpointOnIOThread(unsigned channel_index,
@@ -185,7 +186,7 @@ TEST_F(RemoteMessagePipeTest, Basic) {
scoped_refptr<MessagePipe> mp0(MessagePipe::CreateLocalProxy(&ep0));
scoped_refptr<ChannelEndpoint> ep1;
scoped_refptr<MessagePipe> mp1(MessagePipe::CreateProxyLocal(&ep1));
- ConnectChannelEndpoints(ep0, ep1);
+ BootstrapChannelEndpoints(ep0, ep1);
// Write in one direction: MP 0, port 0 -> ... -> MP 1, port 1.
@@ -298,22 +299,65 @@ TEST_F(RemoteMessagePipeTest, Multiplex) {
scoped_refptr<MessagePipe> mp0(MessagePipe::CreateLocalProxy(&ep0));
scoped_refptr<ChannelEndpoint> ep1;
scoped_refptr<MessagePipe> mp1(MessagePipe::CreateProxyLocal(&ep1));
- ConnectChannelEndpoints(ep0, ep1);
+ BootstrapChannelEndpoints(ep0, ep1);
// Now put another message pipe on the channel.
+ // Do this by creating a message pipe (for the |channels(0)| side) and
+ // attaching and running it, yielding the remote ID. A message is then sent
+ // via |ep0| (i.e., sent using |mp0|, port 0) with this remote ID. Upon
+ // receiving this message, |PassIncomingMessagePipe()| is used to obtain the
+ // message pipe on the other side.
scoped_refptr<ChannelEndpoint> ep2;
scoped_refptr<MessagePipe> mp2(MessagePipe::CreateLocalProxy(&ep2));
- scoped_refptr<ChannelEndpoint> ep3;
- scoped_refptr<MessagePipe> mp3(MessagePipe::CreateProxyLocal(&ep3));
- ConnectChannelEndpoints(ep2, ep3);
+ ASSERT_TRUE(channels(0));
+ ChannelEndpointId remote_id = channels(0)->AttachAndRunEndpoint(ep2, false);
+ EXPECT_TRUE(remote_id.is_remote());
+
+ waiter.Init();
+ ASSERT_EQ(
+ MOJO_RESULT_OK,
+ mp1->AddWaiter(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 123, nullptr));
+
+ EXPECT_EQ(MOJO_RESULT_OK,
+ mp0->WriteMessage(0,
+ UserPointer<const void>(&remote_id),
+ sizeof(remote_id),
+ nullptr,
+ MOJO_WRITE_MESSAGE_FLAG_NONE));
+
+ EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context));
+ EXPECT_EQ(123u, context);
+ hss = HandleSignalsState();
+ mp1->RemoveWaiter(1, &waiter, &hss);
+ EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
+ hss.satisfied_signals);
+ EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
+ hss.satisfiable_signals);
+
+ ChannelEndpointId received_id;
+ buffer_size = static_cast<uint32_t>(sizeof(received_id));
+ EXPECT_EQ(MOJO_RESULT_OK,
+ mp1->ReadMessage(1,
+ UserPointer<void>(&received_id),
+ MakeUserPointer(&buffer_size),
+ nullptr,
+ nullptr,
+ MOJO_READ_MESSAGE_FLAG_NONE));
+ EXPECT_EQ(sizeof(received_id), static_cast<size_t>(buffer_size));
+ EXPECT_EQ(remote_id, received_id);
+
+ // Warning: The local side of mp3 is port 0, not port 1.
+ scoped_refptr<MessagePipe> mp3 =
+ channels(1)->PassIncomingMessagePipe(received_id);
+ ASSERT_TRUE(mp3.get());
// Write: MP 2, port 0 -> MP 3, port 1.
waiter.Init();
ASSERT_EQ(
MOJO_RESULT_OK,
- mp3->AddWaiter(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 789, nullptr));
+ mp3->AddWaiter(0, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 789, nullptr));
EXPECT_EQ(MOJO_RESULT_OK,
mp2->WriteMessage(0,
@@ -325,7 +369,7 @@ TEST_F(RemoteMessagePipeTest, Multiplex) {
EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context));
EXPECT_EQ(789u, context);
hss = HandleSignalsState();
- mp3->RemoveWaiter(1, &waiter, &hss);
+ mp3->RemoveWaiter(0, &waiter, &hss);
EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
hss.satisfied_signals);
EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
@@ -360,7 +404,7 @@ TEST_F(RemoteMessagePipeTest, Multiplex) {
// Read from MP 3, port 1.
buffer_size = static_cast<uint32_t>(sizeof(buffer));
EXPECT_EQ(MOJO_RESULT_OK,
- mp3->ReadMessage(1,
+ mp3->ReadMessage(0,
UserPointer<void>(buffer),
MakeUserPointer(&buffer_size),
nullptr,
@@ -411,7 +455,7 @@ TEST_F(RemoteMessagePipeTest, Multiplex) {
MOJO_READ_MESSAGE_FLAG_NONE));
buffer_size = static_cast<uint32_t>(sizeof(buffer));
EXPECT_EQ(MOJO_RESULT_SHOULD_WAIT,
- mp3->ReadMessage(1,
+ mp3->ReadMessage(0,
UserPointer<void>(buffer),
MakeUserPointer(&buffer_size),
nullptr,
@@ -432,7 +476,7 @@ TEST_F(RemoteMessagePipeTest, Multiplex) {
mp0->Close(0);
mp1->Close(1);
mp2->Close(0);
- mp3->Close(1);
+ mp3->Close(0);
}
TEST_F(RemoteMessagePipeTest, CloseBeforeConnect) {
@@ -512,7 +556,7 @@ TEST_F(RemoteMessagePipeTest, HandlePassing) {
scoped_refptr<MessagePipe> mp0(MessagePipe::CreateLocalProxy(&ep0));
scoped_refptr<ChannelEndpoint> ep1;
scoped_refptr<MessagePipe> mp1(MessagePipe::CreateProxyLocal(&ep1));
- ConnectChannelEndpoints(ep0, ep1);
+ BootstrapChannelEndpoints(ep0, ep1);
// We'll try to pass this dispatcher.
scoped_refptr<MessagePipeDispatcher> dispatcher(
@@ -683,7 +727,7 @@ TEST_F(RemoteMessagePipeTest, MAYBE_SharedBufferPassing) {
scoped_refptr<MessagePipe> mp0(MessagePipe::CreateLocalProxy(&ep0));
scoped_refptr<ChannelEndpoint> ep1;
scoped_refptr<MessagePipe> mp1(MessagePipe::CreateProxyLocal(&ep1));
- ConnectChannelEndpoints(ep0, ep1);
+ BootstrapChannelEndpoints(ep0, ep1);
// We'll try to pass this dispatcher.
scoped_refptr<SharedBufferDispatcher> dispatcher;
@@ -820,7 +864,7 @@ TEST_F(RemoteMessagePipeTest, MAYBE_PlatformHandlePassing) {
scoped_refptr<MessagePipe> mp0(MessagePipe::CreateLocalProxy(&ep0));
scoped_refptr<ChannelEndpoint> ep1;
scoped_refptr<MessagePipe> mp1(MessagePipe::CreateProxyLocal(&ep1));
- ConnectChannelEndpoints(ep0, ep1);
+ BootstrapChannelEndpoints(ep0, ep1);
base::FilePath unused;
base::ScopedFILE fp(
@@ -966,7 +1010,7 @@ TEST_F(RemoteMessagePipeTest, PassMessagePipeHandleAcrossAndBack) {
scoped_refptr<MessagePipe> mp0(MessagePipe::CreateLocalProxy(&ep0));
scoped_refptr<ChannelEndpoint> ep1;
scoped_refptr<MessagePipe> mp1(MessagePipe::CreateProxyLocal(&ep1));
- ConnectChannelEndpoints(ep0, ep1);
+ BootstrapChannelEndpoints(ep0, ep1);
// We'll try to pass this dispatcher.
scoped_refptr<MessagePipeDispatcher> dispatcher(
diff --git a/mojo/public/BUILD.gn b/mojo/public/BUILD.gn
index b661383..5aa0de2 100644
--- a/mojo/public/BUILD.gn
+++ b/mojo/public/BUILD.gn
@@ -38,7 +38,6 @@ group("sdk") {
"//mojo/public/cpp/environment:standalone",
"//mojo/public/cpp/utility",
"//mojo/public/interfaces/application",
- "//mojo/public/js/bindings",
]
}
diff --git a/mojo/public/VERSION b/mojo/public/VERSION
index 9e33d22..e43242f 100644
--- a/mojo/public/VERSION
+++ b/mojo/public/VERSION
@@ -1 +1 @@
-3b54eded8dadb36548934c09c5100e9e645ec328 \ No newline at end of file
+e0416d1cfdcc669756d29802aa8644586273f5c7 \ No newline at end of file
diff --git a/mojo/public/cpp/application/application_impl.h b/mojo/public/cpp/application/application_impl.h
index 9e7cfd6..f4febd5 100644
--- a/mojo/public/cpp/application/application_impl.h
+++ b/mojo/public/cpp/application/application_impl.h
@@ -82,6 +82,9 @@ class ApplicationImpl : public InterfaceImpl<Application> {
// Application implementation.
void Initialize(Array<String> args) override;
+ // Quits the main run loop for this application.
+ static void Terminate();
+
private:
class ShellPtrWatcher;
@@ -90,10 +93,7 @@ class ApplicationImpl : public InterfaceImpl<Application> {
void OnShellError() {
ClearConnections();
Terminate();
- };
-
- // Quits the main run loop for this application.
- static void Terminate();
+ }
// Application implementation.
void AcceptConnection(const String& requestor_url,
diff --git a/mojo/public/cpp/bindings/tests/connector_unittest.cc b/mojo/public/cpp/bindings/tests/connector_unittest.cc
index f8df1a6..3e00a67 100644
--- a/mojo/public/cpp/bindings/tests/connector_unittest.cc
+++ b/mojo/public/cpp/bindings/tests/connector_unittest.cc
@@ -75,7 +75,9 @@ class ConnectorTest : public testing::Test {
public:
ConnectorTest() {}
- void SetUp() override { CreateMessagePipe(nullptr, &handle0_, &handle1_); }
+ void SetUp() override {
+ CreateMessagePipe(nullptr, &handle0_, &handle1_);
+ }
void TearDown() override {}
diff --git a/mojo/public/cpp/bindings/tests/router_unittest.cc b/mojo/public/cpp/bindings/tests/router_unittest.cc
index e8521e8..c4efdb0 100644
--- a/mojo/public/cpp/bindings/tests/router_unittest.cc
+++ b/mojo/public/cpp/bindings/tests/router_unittest.cc
@@ -103,7 +103,9 @@ class RouterTest : public testing::Test {
public:
RouterTest() {}
- void SetUp() override { CreateMessagePipe(nullptr, &handle0_, &handle1_); }
+ void SetUp() override {
+ CreateMessagePipe(nullptr, &handle0_, &handle1_);
+ }
void TearDown() override {}
diff --git a/mojo/public/tools/bindings/generators/cpp_templates/wrapper_class_declaration.tmpl b/mojo/public/tools/bindings/generators/cpp_templates/wrapper_class_declaration.tmpl
index f6bea2c..25b39b3 100644
--- a/mojo/public/tools/bindings/generators/cpp_templates/wrapper_class_declaration.tmpl
+++ b/mojo/public/tools/bindings/generators/cpp_templates/wrapper_class_declaration.tmpl
@@ -19,6 +19,11 @@ class {{struct.name}} {
return mojo::TypeConverter<{{struct.name}}Ptr, U>::Convert(u);
}
+ template <typename U>
+ U To() const {
+ return mojo::TypeConverter<U, {{struct.name}}>::Convert(*this);
+ }
+
{{struct.name}}();
~{{struct.name}}();
diff --git a/mojo/services/html_viewer/html_document_view.cc b/mojo/services/html_viewer/html_document_view.cc
index a7d3c95..9b24350 100644
--- a/mojo/services/html_viewer/html_document_view.cc
+++ b/mojo/services/html_viewer/html_document_view.cc
@@ -25,6 +25,7 @@
#include "skia/ext/refptr.h"
#include "third_party/WebKit/public/platform/Platform.h"
#include "third_party/WebKit/public/platform/WebHTTPHeaderVisitor.h"
+#include "third_party/WebKit/public/platform/WebSize.h"
#include "third_party/WebKit/public/web/WebConsoleMessage.h"
#include "third_party/WebKit/public/web/WebDocument.h"
#include "third_party/WebKit/public/web/WebElement.h"
@@ -119,8 +120,9 @@ void HTMLDocumentView::OnEmbed(
embedder_service_provider_ = embedder_service_provider.Pass();
navigator_host_.set_service_provider(embedder_service_provider_.get());
- web_view_->resize(root_->bounds().size());
- web_layer_tree_view_impl_->setViewportSize(root_->bounds().size());
+ blink::WebSize root_size(root_->bounds().width, root_->bounds().height);
+ web_view_->resize(root_size);
+ web_layer_tree_view_impl_->setViewportSize(root_size);
web_layer_tree_view_impl_->set_view(root_);
root_->AddObserver(this);
}
@@ -239,10 +241,11 @@ void HTMLDocumentView::didNavigateWithinPage(
}
void HTMLDocumentView::OnViewBoundsChanged(View* view,
- const gfx::Rect& old_bounds,
- const gfx::Rect& new_bounds) {
+ const Rect& old_bounds,
+ const Rect& new_bounds) {
DCHECK_EQ(view, root_);
- web_view_->resize(view->bounds().size());
+ web_view_->resize(
+ blink::WebSize(view->bounds().width, view->bounds().height));
}
void HTMLDocumentView::OnViewDestroyed(View* view) {
diff --git a/mojo/services/html_viewer/html_document_view.h b/mojo/services/html_viewer/html_document_view.h
index b43b374..831a729 100644
--- a/mojo/services/html_viewer/html_document_view.h
+++ b/mojo/services/html_viewer/html_document_view.h
@@ -94,8 +94,8 @@ class HTMLDocumentView : public blink::WebViewClient,
// ViewObserver methods:
void OnViewBoundsChanged(View* view,
- const gfx::Rect& old_bounds,
- const gfx::Rect& new_bounds) override;
+ const Rect& old_bounds,
+ const Rect& new_bounds) override;
void OnViewDestroyed(View* view) override;
void OnViewInputEvent(View* view, const EventPtr& event) override;
diff --git a/mojo/services/public/cpp/network/udp_socket_wrapper.cc b/mojo/services/public/cpp/network/udp_socket_wrapper.cc
index f5a7564..3a7f39b 100644
--- a/mojo/services/public/cpp/network/udp_socket_wrapper.cc
+++ b/mojo/services/public/cpp/network/udp_socket_wrapper.cc
@@ -20,8 +20,7 @@ UDPSocketWrapper::NegotiateCallbackHandler::NegotiateCallbackHandler(
: delegate_(delegate) {
}
-UDPSocketWrapper::NegotiateCallbackHandler::~NegotiateCallbackHandler() {
-}
+UDPSocketWrapper::NegotiateCallbackHandler::~NegotiateCallbackHandler() {}
void UDPSocketWrapper::NegotiateCallbackHandler::Run(
uint32_t actual_size) const {
@@ -31,41 +30,37 @@ void UDPSocketWrapper::NegotiateCallbackHandler::Run(
UDPSocketWrapper::SendCallbackHandler::SendCallbackHandler(
UDPSocketWrapper* delegate,
const ErrorCallback& forward_callback)
- : delegate_(delegate), forward_callback_(forward_callback) {
+ : delegate_(delegate),
+ forward_callback_(forward_callback) {
}
-UDPSocketWrapper::SendCallbackHandler::~SendCallbackHandler() {
-}
+UDPSocketWrapper::SendCallbackHandler::~SendCallbackHandler() {}
void UDPSocketWrapper::SendCallbackHandler::Run(NetworkErrorPtr result) const {
delegate_->OnSendToCompleted(result.Pass(), forward_callback_);
}
-UDPSocketWrapper::ReceivedData::ReceivedData() {
-}
-UDPSocketWrapper::ReceivedData::~ReceivedData() {
-}
+UDPSocketWrapper::ReceivedData::ReceivedData() {}
+UDPSocketWrapper::ReceivedData::~ReceivedData() {}
-UDPSocketWrapper::SendRequest::SendRequest() {
-}
-UDPSocketWrapper::SendRequest::~SendRequest() {
-}
+UDPSocketWrapper::SendRequest::SendRequest() {}
+UDPSocketWrapper::SendRequest::~SendRequest() {}
UDPSocketWrapper::UDPSocketWrapper(UDPSocketPtr socket)
- : socket_(socket.Pass()),
- max_receive_queue_size_(kDefaultReceiveQueueSlots),
- max_pending_sends_(1),
- current_pending_sends_(0) {
+ : socket_(socket.Pass()),
+ max_receive_queue_size_(kDefaultReceiveQueueSlots),
+ max_pending_sends_(1),
+ current_pending_sends_(0) {
Initialize(0);
}
UDPSocketWrapper::UDPSocketWrapper(UDPSocketPtr socket,
uint32_t receive_queue_slots,
uint32_t requested_max_pending_sends)
- : socket_(socket.Pass()),
- max_receive_queue_size_(receive_queue_slots),
- max_pending_sends_(1),
- current_pending_sends_(0) {
+ : socket_(socket.Pass()),
+ max_receive_queue_size_(receive_queue_slots),
+ max_pending_sends_(1),
+ current_pending_sends_(0) {
Initialize(requested_max_pending_sends);
}
@@ -128,8 +123,7 @@ void UDPSocketWrapper::SendTo(NetAddressPtr dest_addr,
MOJO_DCHECK(send_requests_.empty());
current_pending_sends_++;
- socket_->SendTo(dest_addr.Pass(),
- data.Pass(),
+ socket_->SendTo(dest_addr.Pass(), data.Pass(),
ErrorCallback(static_cast<typename ErrorCallback::Runnable*>(
new SendCallbackHandler(this, callback))));
}
@@ -179,8 +173,7 @@ void UDPSocketWrapper::OnNegotiateMaxPendingSendRequestsCompleted(
max_pending_sends_ = actual_size;
- while (ProcessNextSendRequest())
- ;
+ while (ProcessNextSendRequest());
}
void UDPSocketWrapper::OnSendToCompleted(
@@ -201,10 +194,10 @@ bool UDPSocketWrapper::ProcessNextSendRequest() {
current_pending_sends_++;
- socket_->SendTo(request->dest_addr.Pass(),
- request->data.Pass(),
- ErrorCallback(static_cast<typename ErrorCallback::Runnable*>(
- new SendCallbackHandler(this, request->callback))));
+ socket_->SendTo(
+ request->dest_addr.Pass(), request->data.Pass(),
+ ErrorCallback(static_cast<typename ErrorCallback::Runnable*>(
+ new SendCallbackHandler(this, request->callback))));
delete request;
diff --git a/mojo/services/public/cpp/view_manager/BUILD.gn b/mojo/services/public/cpp/view_manager/BUILD.gn
index 1b38771..55fc3f8 100644
--- a/mojo/services/public/cpp/view_manager/BUILD.gn
+++ b/mojo/services/public/cpp/view_manager/BUILD.gn
@@ -27,8 +27,6 @@ source_set("view_manager") {
]
deps = [
"//base",
- "//mojo/converters/geometry",
- "//mojo/converters/surfaces",
"//mojo/public/c/gles2",
"//mojo/public/cpp/bindings:bindings",
"//mojo/public/interfaces/application",
@@ -38,7 +36,6 @@ source_set("view_manager") {
"//mojo/services/public/interfaces/view_manager",
"//mojo/services/public/interfaces/window_manager",
"//mojo/services/public/interfaces/window_manager2",
- "//ui/gfx/geometry",
]
}
diff --git a/mojo/services/public/cpp/view_manager/lib/view.cc b/mojo/services/public/cpp/view_manager/lib/view.cc
index d0c86e0..84a0455 100644
--- a/mojo/services/public/cpp/view_manager/lib/view.cc
+++ b/mojo/services/public/cpp/view_manager/lib/view.cc
@@ -144,8 +144,8 @@ bool ReorderImpl(View::Children* children,
class ScopedSetBoundsNotifier {
public:
ScopedSetBoundsNotifier(View* view,
- const gfx::Rect& old_bounds,
- const gfx::Rect& new_bounds)
+ const Rect& old_bounds,
+ const Rect& new_bounds)
: view_(view),
old_bounds_(old_bounds),
new_bounds_(new_bounds) {
@@ -161,8 +161,8 @@ class ScopedSetBoundsNotifier {
private:
View* view_;
- const gfx::Rect old_bounds_;
- const gfx::Rect new_bounds_;
+ const Rect old_bounds_;
+ const Rect new_bounds_;
DISALLOW_COPY_AND_ASSIGN(ScopedSetBoundsNotifier);
};
@@ -205,7 +205,7 @@ void View::Destroy() {
LocalDestroy();
}
-void View::SetBounds(const gfx::Rect& bounds) {
+void View::SetBounds(const Rect& bounds) {
if (!OwnsView(manager_, this))
return;
@@ -225,6 +225,33 @@ void View::SetVisible(bool value) {
FOR_EACH_OBSERVER(ViewObserver, observers_, OnViewVisibilityChanged(this));
}
+void View::SetProperty(const std::string& name,
+ const std::vector<uint8_t>* value) {
+ std::vector<uint8_t> old_value;
+ std::vector<uint8_t>* old_value_ptr = nullptr;
+ auto it = properties_.find(name);
+ if (it != properties_.end()) {
+ old_value = it->second;
+ old_value_ptr = &old_value;
+
+ if (value && old_value == *value)
+ return;
+ } else if (!value) {
+ // This property isn't set in |properties_| and |value| is NULL, so there's
+ // no change.
+ return;
+ }
+
+ if (value) {
+ properties_[name] = *value;
+ } else if (it != properties_.end()) {
+ properties_.erase(it);
+ }
+
+ FOR_EACH_OBSERVER(ViewObserver, observers_,
+ OnViewPropertyChanged(this, name, old_value_ptr, value));
+}
+
bool View::IsDrawn() const {
if (!visible_)
return false;
@@ -391,9 +418,12 @@ bool View::LocalReorder(View* relative, OrderDirection direction) {
return ReorderImpl(&parent_->children_, this, relative, direction);
}
-void View::LocalSetBounds(const gfx::Rect& old_bounds,
- const gfx::Rect& new_bounds) {
- DCHECK(old_bounds == bounds_);
+void View::LocalSetBounds(const Rect& old_bounds,
+ const Rect& new_bounds) {
+ DCHECK(old_bounds.x == bounds_.x);
+ DCHECK(old_bounds.y == bounds_.y);
+ DCHECK(old_bounds.width == bounds_.width);
+ DCHECK(old_bounds.height == bounds_.height);
ScopedSetBoundsNotifier notifier(this, old_bounds, new_bounds);
bounds_ = new_bounds;
}
diff --git a/mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.cc b/mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.cc
index 8004d29..896da9d 100644
--- a/mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.cc
+++ b/mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.cc
@@ -36,8 +36,10 @@ View* AddViewToViewManager(ViewManagerClientImpl* client,
private_view.set_id(view_data->view_id);
private_view.set_visible(view_data->visible);
private_view.set_drawn(view_data->drawn);
+ private_view.set_properties(
+ view_data->properties.To<std::map<std::string, std::vector<uint8_t>>>());
client->AddView(view);
- private_view.LocalSetBounds(gfx::Rect(), view_data->bounds.To<gfx::Rect>());
+ private_view.LocalSetBounds(Rect(), *view_data->bounds);
if (parent)
ViewPrivate(parent).LocalAddChild(view);
return view;
@@ -154,10 +156,9 @@ bool ViewManagerClientImpl::OwnsView(Id id) const {
return HiWord(id) == connection_id_;
}
-void ViewManagerClientImpl::SetBounds(Id view_id, const gfx::Rect& bounds) {
+void ViewManagerClientImpl::SetBounds(Id view_id, const Rect& bounds) {
DCHECK(connected_);
- service_->SetViewBounds(view_id, Rect::From(bounds),
- ActionCompletedCallback());
+ service_->SetViewBounds(view_id, bounds.Clone(), ActionCompletedCallback());
}
void ViewManagerClientImpl::SetSurfaceId(Id view_id, SurfaceIdPtr surface_id) {
@@ -177,6 +178,17 @@ void ViewManagerClientImpl::SetVisible(Id view_id, bool visible) {
service_->SetViewVisibility(view_id, visible, ActionCompletedCallback());
}
+void ViewManagerClientImpl::SetProperty(
+ Id view_id,
+ const std::string& name,
+ const std::vector<uint8_t>& data) {
+ DCHECK(connected_);
+ service_->SetViewProperty(view_id,
+ String(name),
+ Array<uint8_t>::From(data),
+ ActionCompletedCallback());
+}
+
void ViewManagerClientImpl::Embed(const String& url, Id view_id) {
ServiceProviderPtr sp;
BindToProxy(new ServiceProviderImpl, &sp);
@@ -265,8 +277,7 @@ void ViewManagerClientImpl::OnViewBoundsChanged(Id view_id,
RectPtr old_bounds,
RectPtr new_bounds) {
View* view = GetViewById(view_id);
- ViewPrivate(view).LocalSetBounds(old_bounds.To<gfx::Rect>(),
- new_bounds.To<gfx::Rect>());
+ ViewPrivate(view).LocalSetBounds(*old_bounds, *new_bounds);
}
void ViewManagerClientImpl::OnViewHierarchyChanged(
@@ -318,6 +329,23 @@ void ViewManagerClientImpl::OnViewDrawnStateChanged(Id view_id, bool drawn) {
ViewPrivate(view).LocalSetDrawn(drawn);
}
+void ViewManagerClientImpl::OnViewPropertyChanged(
+ Id view_id,
+ const String& name,
+ Array<uint8_t> new_data) {
+ View* view = GetViewById(view_id);
+ if (view) {
+ std::vector<uint8_t> data;
+ std::vector<uint8_t>* data_ptr = NULL;
+ if (!new_data.is_null()) {
+ data = new_data.To<std::vector<uint8_t>>();
+ data_ptr = &data;
+ }
+
+ view->SetProperty(name, data_ptr);
+ }
+}
+
void ViewManagerClientImpl::OnViewInputEvent(
Id view_id,
EventPtr event,
diff --git a/mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.h b/mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.h
index c9a4af4..bfbe5fc 100644
--- a/mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.h
+++ b/mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.h
@@ -9,7 +9,6 @@
#include "base/callback.h"
#include "base/memory/scoped_vector.h"
#include "base/memory/weak_ptr.h"
-#include "mojo/converters/geometry/geometry_type_converters.h"
#include "mojo/services/public/cpp/view_manager/types.h"
#include "mojo/services/public/cpp/view_manager/view.h"
#include "mojo/services/public/cpp/view_manager/view_manager.h"
@@ -49,10 +48,13 @@ class ViewManagerClientImpl : public ViewManager,
// Returns true if the specified view was created by this connection.
bool OwnsView(Id id) const;
- void SetBounds(Id view_id, const gfx::Rect& bounds);
+ void SetBounds(Id view_id, const Rect& bounds);
void SetSurfaceId(Id view_id, SurfaceIdPtr surface_id);
void SetFocus(Id view_id);
void SetVisible(Id view_id, bool visible);
+ void SetProperty(Id view_id,
+ const std::string& name,
+ const std::vector<uint8_t>& data);
void Embed(const String& url, Id view_id);
void Embed(const String& url,
@@ -102,11 +104,14 @@ class ViewManagerClientImpl : public ViewManager,
void OnViewDeleted(Id view_id) override;
void OnViewVisibilityChanged(Id view_id, bool visible) override;
void OnViewDrawnStateChanged(Id view_id, bool drawn) override;
+ void OnViewPropertyChanged(Id view_id,
+ const String& name,
+ Array<uint8_t> new_data) override;
void OnViewInputEvent(Id view_id,
EventPtr event,
const Callback<void()>& callback) override;
- // Overridden from WindowManagerClient2:
+ // Overridden from WindowManagerClient2:
void OnWindowManagerReady() override;
void OnCaptureChanged(Id old_capture_view_id,
Id new_capture_view_id) override;
diff --git a/mojo/services/public/cpp/view_manager/lib/view_private.h b/mojo/services/public/cpp/view_manager/lib/view_private.h
index 73138e2..a27a963 100644
--- a/mojo/services/public/cpp/view_manager/lib/view_private.h
+++ b/mojo/services/public/cpp/view_manager/lib/view_private.h
@@ -36,6 +36,10 @@ class ViewPrivate {
view_->manager_ = manager;
}
+ void set_properties(const std::map<std::string, std::vector<uint8_t>>& data) {
+ view_->properties_ = data;
+ }
+
void LocalDestroy() {
view_->LocalDestroy();
}
@@ -48,8 +52,8 @@ class ViewPrivate {
void LocalReorder(View* relative, OrderDirection direction) {
view_->LocalReorder(relative, direction);
}
- void LocalSetBounds(const gfx::Rect& old_bounds,
- const gfx::Rect& new_bounds) {
+ void LocalSetBounds(const Rect& old_bounds,
+ const Rect& new_bounds) {
view_->LocalSetBounds(old_bounds, new_bounds);
}
void LocalSetDrawn(bool drawn) { view_->LocalSetDrawn(drawn); }
diff --git a/mojo/services/public/cpp/view_manager/tests/view_manager_unittest.cc b/mojo/services/public/cpp/view_manager/tests/view_manager_unittest.cc
index eafc3b9..83a1ce0 100644
--- a/mojo/services/public/cpp/view_manager/tests/view_manager_unittest.cc
+++ b/mojo/services/public/cpp/view_manager/tests/view_manager_unittest.cc
@@ -23,6 +23,18 @@
#include "testing/gtest/include/gtest/gtest.h"
namespace mojo {
+
+// TODO(jam): move these somewhere else so they can be shared?
+
+inline bool operator==(const Rect& lhs, const Rect& rhs) {
+ return lhs.x == rhs.x && lhs.y == rhs.y && lhs.width == rhs.width &&
+ lhs.height == lhs.height;
+}
+
+inline bool operator!=(const Rect& lhs, const Rect& rhs) {
+ return !(lhs == rhs);
+}
+
namespace {
const char kWindowManagerURL[] = "mojo:window_manager";
@@ -102,8 +114,8 @@ class BoundsChangeObserver : public ViewObserver {
private:
// Overridden from ViewObserver:
void OnViewBoundsChanged(View* view,
- const gfx::Rect& old_bounds,
- const gfx::Rect& new_bounds) override {
+ const Rect& old_bounds,
+ const Rect& new_bounds) override {
DCHECK_EQ(view, view_);
QuitRunLoop();
}
@@ -410,7 +422,9 @@ TEST_F(ViewManagerTest, DISABLED_SetBounds) {
View* view_in_embedded = embedded->GetViewById(view->id());
EXPECT_EQ(view->bounds(), view_in_embedded->bounds());
- view->SetBounds(gfx::Rect(100, 100));
+ Rect rect;
+ rect.width = rect.height = 100;
+ view->SetBounds(rect);
EXPECT_NE(view->bounds(), view_in_embedded->bounds());
WaitForBoundsToChange(view_in_embedded);
EXPECT_EQ(view->bounds(), view_in_embedded->bounds());
@@ -424,10 +438,15 @@ TEST_F(ViewManagerTest, DISABLED_SetBoundsSecurity) {
ViewManager* embedded = Embed(window_manager(), view);
View* view_in_embedded = embedded->GetViewById(view->id());
- view->SetBounds(gfx::Rect(800, 600));
+ Rect rect;
+ rect.width = 800;
+ rect.height = 600;
+ view->SetBounds(rect);
WaitForBoundsToChange(view_in_embedded);
- view_in_embedded->SetBounds(gfx::Rect(1024, 768));
+ rect.width = 1024;
+ rect.height = 768;
+ view_in_embedded->SetBounds(rect);
// Bounds change should have been rejected.
EXPECT_EQ(view->bounds(), view_in_embedded->bounds());
}
diff --git a/mojo/services/public/cpp/view_manager/tests/view_unittest.cc b/mojo/services/public/cpp/view_manager/tests/view_unittest.cc
index 2fb5bfc..eb7276c 100644
--- a/mojo/services/public/cpp/view_manager/tests/view_unittest.cc
+++ b/mojo/services/public/cpp/view_manager/tests/view_unittest.cc
@@ -486,9 +486,9 @@ std::string ViewIdToString(Id id) {
base::StringPrintf("%d,%d", HiWord(id), LoWord(id));
}
-std::string RectToString(const gfx::Rect& rect) {
+std::string RectToString(const Rect& rect) {
return base::StringPrintf("%d,%d %dx%d",
- rect.x(), rect.y(), rect.width(), rect.height());
+ rect.x, rect.y, rect.width, rect.height);
}
class BoundsChangeObserver : public ViewObserver {
@@ -507,8 +507,8 @@ class BoundsChangeObserver : public ViewObserver {
private:
// Overridden from ViewObserver:
void OnViewBoundsChanging(View* view,
- const gfx::Rect& old_bounds,
- const gfx::Rect& new_bounds) override {
+ const Rect& old_bounds,
+ const Rect& new_bounds) override {
changes_.push_back(
base::StringPrintf(
"view=%s old_bounds=%s new_bounds=%s phase=changing",
@@ -517,8 +517,8 @@ class BoundsChangeObserver : public ViewObserver {
RectToString(new_bounds).c_str()));
}
void OnViewBoundsChanged(View* view,
- const gfx::Rect& old_bounds,
- const gfx::Rect& new_bounds) override {
+ const Rect& old_bounds,
+ const Rect& new_bounds) override {
changes_.push_back(
base::StringPrintf(
"view=%s old_bounds=%s new_bounds=%s phase=changed",
@@ -539,7 +539,9 @@ TEST_F(ViewObserverTest, SetBounds) {
TestView v1;
{
BoundsChangeObserver observer(&v1);
- v1.SetBounds(gfx::Rect(0, 0, 100, 100));
+ Rect rect;
+ rect.width = rect.height = 100;
+ v1.SetBounds(rect);
Changes changes = observer.GetAndClearChanges();
ASSERT_EQ(2U, changes.size());
@@ -610,4 +612,91 @@ TEST_F(ViewObserverTest, SetVisible) {
}
}
+namespace {
+
+class PropertyChangeObserver : public ViewObserver {
+ public:
+ explicit PropertyChangeObserver(View* view) : view_(view) {
+ view_->AddObserver(this);
+ }
+ virtual ~PropertyChangeObserver() { view_->RemoveObserver(this); }
+
+ Changes GetAndClearChanges() {
+ Changes changes;
+ changes.swap(changes_);
+ return changes;
+ }
+
+ private:
+ // Overridden from ViewObserver:
+ void OnViewPropertyChanged(View* view,
+ const std::string& name,
+ const std::vector<uint8_t>* old_data,
+ const std::vector<uint8_t>* new_data) override {
+ changes_.push_back(base::StringPrintf(
+ "view=%s property changed key=%s old_value=%s new_value=%s",
+ ViewIdToString(view->id()).c_str(),
+ name.c_str(),
+ VectorToString(old_data).c_str(),
+ VectorToString(new_data).c_str()));
+ }
+
+ std::string VectorToString(const std::vector<uint8_t>* data) {
+ if (!data)
+ return "NULL";
+ std::string s;
+ for (char c : *data)
+ s += c;
+ return s;
+ }
+
+ View* view_;
+ Changes changes_;
+
+ DISALLOW_COPY_AND_ASSIGN(PropertyChangeObserver);
+};
+
+} // namespace
+
+TEST_F(ViewObserverTest, SetProperty) {
+ TestView v1;
+ std::vector<uint8_t> one(1, '1');
+
+ {
+ // Change visibility from true to false and make sure we get notifications.
+ PropertyChangeObserver observer(&v1);
+ v1.SetProperty("one", &one);
+ Changes changes = observer.GetAndClearChanges();
+ ASSERT_EQ(1U, changes.size());
+ EXPECT_EQ("view=0,1 property changed key=one old_value=NULL new_value=1",
+ changes[0]);
+ EXPECT_EQ(1U, v1.properties().size());
+ }
+ {
+ // Set visible to existing value and verify no notifications.
+ PropertyChangeObserver observer(&v1);
+ v1.SetProperty("one", &one);
+ EXPECT_TRUE(observer.GetAndClearChanges().empty());
+ EXPECT_EQ(1U, v1.properties().size());
+ }
+ {
+ // Set the value to NULL to delete it.
+ // Change visibility from true to false and make sure we get notifications.
+ PropertyChangeObserver observer(&v1);
+ v1.SetProperty("one", NULL);
+ Changes changes = observer.GetAndClearChanges();
+ ASSERT_EQ(1U, changes.size());
+ EXPECT_EQ("view=0,1 property changed key=one old_value=1 new_value=NULL",
+ changes[0]);
+ EXPECT_EQ(0U, v1.properties().size());
+ }
+ {
+ // Setting a null property to null shouldn't update us.
+ PropertyChangeObserver observer(&v1);
+ v1.SetProperty("one", NULL);
+ EXPECT_TRUE(observer.GetAndClearChanges().empty());
+ EXPECT_EQ(0U, v1.properties().size());
+ }
+}
+
} // namespace mojo
diff --git a/mojo/services/public/cpp/view_manager/view.h b/mojo/services/public/cpp/view_manager/view.h
index a7161ea..72f044c 100644
--- a/mojo/services/public/cpp/view_manager/view.h
+++ b/mojo/services/public/cpp/view_manager/view.h
@@ -12,9 +12,9 @@
#include "mojo/public/cpp/bindings/array.h"
#include "mojo/public/interfaces/application/service_provider.mojom.h"
#include "mojo/services/public/cpp/view_manager/types.h"
+#include "mojo/services/public/interfaces/geometry/geometry.mojom.h"
#include "mojo/services/public/interfaces/surfaces/surface_id.mojom.h"
#include "mojo/services/public/interfaces/view_manager/view_manager_constants.mojom.h"
-#include "ui/gfx/geometry/rect.h"
namespace mojo {
@@ -42,13 +42,19 @@ class View {
Id id() const { return id_; }
// Geometric disposition.
- const gfx::Rect& bounds() const { return bounds_; }
- void SetBounds(const gfx::Rect& bounds);
+ const Rect& bounds() const { return bounds_; }
+ void SetBounds(const Rect& bounds);
// Visibility (also see IsDrawn()).
bool visible() const { return visible_; }
void SetVisible(bool value);
+ const std::map<std::string, std::vector<uint8_t>>& properties() const {
+ return properties_;
+ }
+ // Sets a property. If |data| is null, this property is deleted.
+ void SetProperty(const std::string& name, const std::vector<uint8_t>* data);
+
// A View is drawn if the View and all its ancestors are visible and the
// View is attached to the root.
bool IsDrawn() const;
@@ -100,7 +106,7 @@ class View {
void LocalRemoveChild(View* child);
// Returns true if the order actually changed.
bool LocalReorder(View* relative, OrderDirection direction);
- void LocalSetBounds(const gfx::Rect& old_bounds, const gfx::Rect& new_bounds);
+ void LocalSetBounds(const Rect& old_bounds, const Rect& new_bounds);
void LocalSetDrawn(bool drawn);
ViewManager* manager_;
@@ -110,10 +116,12 @@ class View {
ObserverList<ViewObserver> observers_;
- gfx::Rect bounds_;
+ Rect bounds_;
bool visible_;
+ std::map<std::string, std::vector<uint8_t>> properties_;
+
// Drawn state is derived from the visible state and the parent's visible
// state. This field is only used if the view has no parent (eg it's a root).
bool drawn_;
diff --git a/mojo/services/public/cpp/view_manager/view_observer.h b/mojo/services/public/cpp/view_manager/view_observer.h
index 1a2ab7e2..ec4e79d 100644
--- a/mojo/services/public/cpp/view_manager/view_observer.h
+++ b/mojo/services/public/cpp/view_manager/view_observer.h
@@ -12,10 +12,6 @@
#include "mojo/services/public/cpp/view_manager/view.h"
#include "mojo/services/public/interfaces/input_events/input_events.mojom.h"
-namespace gfx {
-class Rect;
-}
-
namespace mojo {
class View;
@@ -54,11 +50,11 @@ class ViewObserver {
virtual void OnViewDestroyed(View* view) {}
virtual void OnViewBoundsChanging(View* view,
- const gfx::Rect& old_bounds,
- const gfx::Rect& new_bounds) {}
+ const Rect& old_bounds,
+ const Rect& new_bounds) {}
virtual void OnViewBoundsChanged(View* view,
- const gfx::Rect& old_bounds,
- const gfx::Rect& new_bounds) {}
+ const Rect& old_bounds,
+ const Rect& new_bounds) {}
virtual void OnViewFocusChanged(View* gained_focus, View* lost_focus) {}
@@ -67,6 +63,11 @@ class ViewObserver {
virtual void OnViewVisibilityChanging(View* view) {}
virtual void OnViewVisibilityChanged(View* view) {}
+ virtual void OnViewPropertyChanged(View* view,
+ const std::string& name,
+ const std::vector<uint8_t>* old_data,
+ const std::vector<uint8_t>* new_data) {}
+
// Sent when the drawn state changes. This is only sent for the root nodes
// when embedded.
virtual void OnViewDrawnChanging(View* view) {}
diff --git a/mojo/services/public/interfaces/view_manager/view_manager.mojom b/mojo/services/public/interfaces/view_manager/view_manager.mojom
index 7019f150..e76996e 100644
--- a/mojo/services/public/interfaces/view_manager/view_manager.mojom
+++ b/mojo/services/public/interfaces/view_manager/view_manager.mojom
@@ -14,6 +14,7 @@ struct ViewData {
uint32 parent_id;
uint32 view_id;
mojo.Rect bounds;
+ map<string, array<uint8>> properties;
// True if this view is visible. The view may not be drawn on screen (see
// drawn for specifics).
bool visible;
@@ -42,6 +43,9 @@ interface ViewManagerService {
// ERROR_CODE_VALUE_IN_USE: a view already exists with the specified id.
// ERROR_CODE_ILLEGAL_ARGUMENT: The connection part of |view_id| does not
// match the connection id of the client.
+ //
+ // TODO(erg): Once we have default values in mojo, make this take a map of
+ // properties.
CreateView(uint32 view_id) => (ErrorCode error_code);
// Deletes a view. This does not recurse. No hierarchy change notifications
@@ -57,6 +61,12 @@ interface ViewManagerService {
// any of their roots.
SetViewVisibility(uint32 view_id, bool visible) => (bool success);
+ // Sets an individual named property. Setting an individual property to null
+ // deletes the property.
+ SetViewProperty(uint32 view_id,
+ string name,
+ array<uint8>? value) => (bool success);
+
// Reparents a view.
// This fails for any of the following reasons:
// . |parent| or |child| does not identify a valid view.
@@ -171,6 +181,10 @@ interface ViewManagerClient {
// NOTE: This is not invoked if OnViewVisibilityChanged() is invoked.
OnViewDrawnStateChanged(uint32 view, bool drawn);
+ // Invoked when a view property is changed. If this change is a removal,
+ // |new_data| is null.
+ OnViewPropertyChanged(uint32 view, string name, array<uint8>? new_data);
+
// Invoked when an event is targeted at the specified view.
OnViewInputEvent(uint32 view, mojo.Event event) => ();
};