summaryrefslogtreecommitdiffstats
path: root/mandoline
diff options
context:
space:
mode:
authorsky <sky@chromium.org>2015-08-04 14:31:52 -0700
committerCommit bot <commit-bot@chromium.org>2015-08-04 21:35:16 +0000
commit49f1a80cf78b7b78b0c941acbde59e2a22610beb (patch)
treea5170877c806a2e258551c4f662662bd04fa943f /mandoline
parent871b0d6a142b9af9316fd20dee1b7e0e2516efcf (diff)
downloadchromium_src-49f1a80cf78b7b78b0c941acbde59e2a22610beb.zip
chromium_src-49f1a80cf78b7b78b0c941acbde59e2a22610beb.tar.gz
chromium_src-49f1a80cf78b7b78b0c941acbde59e2a22610beb.tar.bz2
Adds client properties to Frame
Client properties are used as a way for renderers to share state among the frames. This is used by html viewer to communicate html specific state: name, origin... BUG=479172,490221 TEST=covered by tests R=fsamuel@chromium.org Review URL: https://codereview.chromium.org/1256783008 Cr-Commit-Position: refs/heads/master@{#341803}
Diffstat (limited to 'mandoline')
-rw-r--r--mandoline/tab/frame.cc54
-rw-r--r--mandoline/tab/frame.h30
-rw-r--r--mandoline/tab/frame_apptest.cc5
-rw-r--r--mandoline/tab/frame_tree.cc33
-rw-r--r--mandoline/tab/frame_tree.h25
-rw-r--r--mandoline/tab/public/interfaces/frame_tree.mojom29
6 files changed, 119 insertions, 57 deletions
diff --git a/mandoline/tab/frame.cc b/mandoline/tab/frame.cc
index 070361c..3598a8b 100644
--- a/mandoline/tab/frame.cc
+++ b/mandoline/tab/frame.cc
@@ -30,9 +30,9 @@ FrameDataPtr FrameToFrameData(const Frame* frame) {
FrameDataPtr frame_data(FrameData::New());
frame_data->frame_id = frame->id();
frame_data->parent_id = frame->parent() ? frame->parent()->id() : kNoParentId;
- frame_data->name = frame->name();
- // TODO(sky): implement me.
- frame_data->origin = std::string();
+ frame_data->client_properties =
+ mojo::Map<mojo::String, mojo::Array<uint8_t>>::From(
+ frame->client_properties());
return frame_data.Pass();
}
@@ -43,7 +43,8 @@ Frame::Frame(FrameTree* tree,
uint32_t id,
ViewOwnership view_ownership,
FrameTreeClient* frame_tree_client,
- scoped_ptr<FrameUserData> user_data)
+ scoped_ptr<FrameUserData> user_data,
+ const ClientPropertyMap& client_properties)
: tree_(tree),
view_(nullptr),
id_(id),
@@ -53,6 +54,7 @@ Frame::Frame(FrameTree* tree,
frame_tree_client_(frame_tree_client),
loading_(false),
progress_(0.f),
+ client_properties_(client_properties),
frame_tree_server_binding_(this) {
if (view)
SetView(view);
@@ -202,12 +204,21 @@ void Frame::ProgressChangedImpl(double progress) {
tree_->ProgressChanged();
}
-void Frame::SetFrameNameImpl(const mojo::String& name) {
- if (name_ == name)
- return;
-
- name_ = name;
- tree_->FrameNameChanged(this);
+void Frame::SetClientPropertyImpl(const mojo::String& name,
+ mojo::Array<uint8_t> value) {
+ auto iter = client_properties_.find(name);
+ const bool already_in_map = (iter != client_properties_.end());
+ if (value.is_null()) {
+ if (!already_in_map)
+ return;
+ client_properties_.erase(iter);
+ } else {
+ std::vector<uint8_t> as_vector(value.To<std::vector<uint8_t>>());
+ if (already_in_map && iter->second == as_vector)
+ return;
+ client_properties_[name] = as_vector;
+ }
+ tree_->ClientPropertyChanged(this, name, value);
}
Frame* Frame::FindTargetFrame(uint32_t frame_id) {
@@ -250,12 +261,15 @@ void Frame::NotifyRemoved(const Frame* source, const Frame* removed_node) {
child->NotifyRemoved(source, removed_node);
}
-void Frame::NotifyFrameNameChanged(const Frame* source) {
+void Frame::NotifyClientPropertyChanged(const Frame* source,
+ const mojo::String& name,
+ const mojo::Array<uint8_t>& value) {
if (this != source && frame_tree_client_)
- frame_tree_client_->OnFrameNameChanged(source->id(), source->name_);
+ frame_tree_client_->OnFrameClientPropertyChanged(source->id(), name,
+ value.Clone());
for (Frame* child : children_)
- child->NotifyFrameNameChanged(source);
+ child->NotifyClientPropertyChanged(source, name, value);
}
void Frame::OnTreeChanged(const TreeChangeParams& params) {
@@ -311,13 +325,18 @@ void Frame::ProgressChanged(uint32_t frame_id, double progress) {
target_frame->ProgressChangedImpl(progress);
}
-void Frame::SetFrameName(uint32_t frame_id, const mojo::String& name) {
+void Frame::SetClientProperty(uint32_t frame_id,
+ const mojo::String& name,
+ mojo::Array<uint8_t> value) {
Frame* target_frame = FindTargetFrame(frame_id);
if (target_frame)
- target_frame->SetFrameNameImpl(name);
+ target_frame->SetClientPropertyImpl(name, value.Pass());
}
-void Frame::OnCreatedFrame(uint32_t parent_id, uint32_t frame_id) {
+void Frame::OnCreatedFrame(
+ uint32_t parent_id,
+ uint32_t frame_id,
+ mojo::Map<mojo::String, mojo::Array<uint8_t>> client_properties) {
// TODO(sky): I need a way to verify the id. Unfortunately the code here
// doesn't know the connection id of the embedder, so it's not possible to
// do it.
@@ -339,7 +358,8 @@ void Frame::OnCreatedFrame(uint32_t parent_id, uint32_t frame_id) {
return;
}
- tree_->CreateSharedFrame(parent_frame, frame_id);
+ tree_->CreateSharedFrame(parent_frame, frame_id,
+ client_properties.To<ClientPropertyMap>());
}
void Frame::RequestNavigate(uint32_t frame_id,
diff --git a/mandoline/tab/frame.h b/mandoline/tab/frame.h
index 5b87f6b..5e8d1e8 100644
--- a/mandoline/tab/frame.h
+++ b/mandoline/tab/frame.h
@@ -5,6 +5,7 @@
#ifndef MANDOLINE_TAB_FRAME_H_
#define MANDOLINE_TAB_FRAME_H_
+#include <map>
#include <vector>
#include "base/basictypes.h"
@@ -38,12 +39,15 @@ enum class ViewOwnership {
// FrameTreeClient for the child Frame.
class Frame : public mojo::ViewObserver, public FrameTreeServer {
public:
+ using ClientPropertyMap = std::map<std::string, std::vector<uint8_t>>;
+
Frame(FrameTree* tree,
mojo::View* view,
uint32_t id,
ViewOwnership view_ownership,
FrameTreeClient* frame_tree_client,
- scoped_ptr<FrameUserData> user_data);
+ scoped_ptr<FrameUserData> user_data,
+ const ClientPropertyMap& client_properties);
~Frame() override;
void Init(Frame* parent);
@@ -68,6 +72,10 @@ class Frame : public mojo::ViewObserver, public FrameTreeServer {
uint32_t id() const { return id_; }
+ const ClientPropertyMap& client_properties() const {
+ return client_properties_;
+ }
+
// Finds the descendant with the specified id.
Frame* FindFrame(uint32_t id) {
return const_cast<Frame*>(const_cast<const Frame*>(this)->FindFrame(id));
@@ -80,8 +88,6 @@ class Frame : public mojo::ViewObserver, public FrameTreeServer {
const std::vector<Frame*>& children() { return children_; }
- const mojo::String& name() const { return name_; }
-
// Returns true if this Frame or any child Frame is loading.
bool IsLoading() const;
@@ -109,7 +115,8 @@ class Frame : public mojo::ViewObserver, public FrameTreeServer {
void LoadingStartedImpl();
void LoadingStoppedImpl();
void ProgressChangedImpl(double progress);
- void SetFrameNameImpl(const mojo::String& name);
+ void SetClientPropertyImpl(const mojo::String& name,
+ mojo::Array<uint8_t> value);
// Returns the Frame whose id is |frame_id|. Returns nullptr if |frame_id| is
// not from the same connection as this.
@@ -118,7 +125,9 @@ class Frame : public mojo::ViewObserver, public FrameTreeServer {
// Notifies the client and all descendants as appropriate.
void NotifyAdded(const Frame* source, const Frame* added_node);
void NotifyRemoved(const Frame* source, const Frame* removed_node);
- void NotifyFrameNameChanged(const Frame* source);
+ void NotifyClientPropertyChanged(const Frame* source,
+ const mojo::String& name,
+ const mojo::Array<uint8_t>& value);
// mojo::ViewObserver:
void OnTreeChanged(const TreeChangeParams& params) override;
@@ -130,8 +139,13 @@ class Frame : public mojo::ViewObserver, public FrameTreeServer {
void LoadingStarted(uint32_t frame_id) override;
void LoadingStopped(uint32_t frame_id) override;
void ProgressChanged(uint32_t frame_id, double progress) override;
- void SetFrameName(uint32_t frame_id, const mojo::String& name) override;
- void OnCreatedFrame(uint32_t parent_id, uint32_t frame_id) override;
+ void SetClientProperty(uint32_t frame_id,
+ const mojo::String& name,
+ mojo::Array<uint8_t> value) override;
+ void OnCreatedFrame(
+ uint32_t parent_id,
+ uint32_t frame_id,
+ mojo::Map<mojo::String, mojo::Array<uint8_t>> client_properties) override;
void RequestNavigate(uint32_t frame_id,
NavigationTarget target,
mojo::URLRequestPtr request) override;
@@ -152,7 +166,7 @@ class Frame : public mojo::ViewObserver, public FrameTreeServer {
bool loading_;
double progress_;
- mojo::String name_;
+ ClientPropertyMap client_properties_;
mojo::Binding<FrameTreeServer> frame_tree_server_binding_;
diff --git a/mandoline/tab/frame_apptest.cc b/mandoline/tab/frame_apptest.cc
index 93de09f..9f5acd3 100644
--- a/mandoline/tab/frame_apptest.cc
+++ b/mandoline/tab/frame_apptest.cc
@@ -169,8 +169,9 @@ class TestFrameTreeClient : public FrameTreeClient {
adds_.push_back(frame.Pass());
}
void OnFrameRemoved(uint32_t frame_id) override {}
- void OnFrameNameChanged(uint32_t frame_id,
- const mojo::String& name) override {}
+ void OnFrameClientPropertyChanged(uint32_t frame_id,
+ const mojo::String& name,
+ mojo::Array<uint8_t> new_data) override {}
private:
int connect_count_;
diff --git a/mandoline/tab/frame_tree.cc b/mandoline/tab/frame_tree.cc
index 0ebbb4e..a6da90c 100644
--- a/mandoline/tab/frame_tree.cc
+++ b/mandoline/tab/frame_tree.cc
@@ -20,7 +20,8 @@ FrameTree::FrameTree(mojo::View* view,
view->id(),
ViewOwnership::DOESNT_OWN_VIEW,
root_client,
- user_data.Pass()),
+ user_data.Pass(),
+ Frame::ClientPropertyMap()),
progress_(0.f) {
root_.Init(nullptr);
}
@@ -33,7 +34,7 @@ Frame* FrameTree::CreateAndAddFrame(mojo::View* view,
FrameTreeClient* client,
scoped_ptr<FrameUserData> user_data) {
return CreateAndAddFrameImpl(view, view->id(), parent, client,
- user_data.Pass());
+ user_data.Pass(), Frame::ClientPropertyMap());
}
Frame* FrameTree::CreateOrReplaceFrame(Frame* frame,
@@ -54,20 +55,26 @@ Frame* FrameTree::CreateOrReplaceFrame(Frame* frame,
return CreateAndAddFrame(view, frame, frame_tree_client, user_data.Pass());
}
-void FrameTree::CreateSharedFrame(Frame* parent, uint32_t frame_id) {
+void FrameTree::CreateSharedFrame(
+ Frame* parent,
+ uint32_t frame_id,
+ const Frame::ClientPropertyMap& client_properties) {
mojo::View* frame_view = root_.view()->GetChildById(frame_id);
// |frame_view| may be null if the View hasn't been created yet. If this is
// the case the View will be connected to the Frame in Frame::OnTreeChanged.
- CreateAndAddFrameImpl(frame_view, frame_id, parent, nullptr, nullptr);
+ CreateAndAddFrameImpl(frame_view, frame_id, parent, nullptr, nullptr,
+ client_properties);
}
-Frame* FrameTree::CreateAndAddFrameImpl(mojo::View* view,
- uint32_t frame_id,
- Frame* parent,
- FrameTreeClient* client,
- scoped_ptr<FrameUserData> user_data) {
+Frame* FrameTree::CreateAndAddFrameImpl(
+ mojo::View* view,
+ uint32_t frame_id,
+ Frame* parent,
+ FrameTreeClient* client,
+ scoped_ptr<FrameUserData> user_data,
+ const Frame::ClientPropertyMap& client_properties) {
Frame* frame = new Frame(this, view, frame_id, ViewOwnership::OWNS_VIEW,
- client, user_data.Pass());
+ client, user_data.Pass(), client_properties);
frame->Init(parent);
return frame;
}
@@ -88,8 +95,10 @@ void FrameTree::ProgressChanged() {
delegate_->ProgressChanged(progress_);
}
-void FrameTree::FrameNameChanged(Frame* frame) {
- root_.NotifyFrameNameChanged(frame);
+void FrameTree::ClientPropertyChanged(const Frame* source,
+ const mojo::String& name,
+ const mojo::Array<uint8_t>& value) {
+ root_.NotifyClientPropertyChanged(source, name, value);
}
} // namespace mandoline
diff --git a/mandoline/tab/frame_tree.h b/mandoline/tab/frame_tree.h
index 91d5fa7..b4bd590 100644
--- a/mandoline/tab/frame_tree.h
+++ b/mandoline/tab/frame_tree.h
@@ -6,6 +6,11 @@
#define MANDOLINE_TAB_FRAME_TREE_H_
#include "mandoline/tab/frame.h"
+#include "third_party/mojo/src/mojo/public/cpp/bindings/array.h"
+
+namespace mojo {
+class String;
+}
namespace mandoline {
@@ -48,20 +53,26 @@ class FrameTree {
// that it is sharing the FrameTreeClient/FrameTreeServer of |parent|. There
// may or may not be a View identified by |frame_id| yet. See Frame for
// details.
- void CreateSharedFrame(Frame* parent, uint32_t frame_id);
+ void CreateSharedFrame(Frame* parent,
+ uint32_t frame_id,
+ const Frame::ClientPropertyMap& client_properties);
private:
friend class Frame;
- Frame* CreateAndAddFrameImpl(mojo::View* view,
- uint32_t frame_id,
- Frame* parent,
- FrameTreeClient* client,
- scoped_ptr<FrameUserData> user_data);
+ Frame* CreateAndAddFrameImpl(
+ mojo::View* view,
+ uint32_t frame_id,
+ Frame* parent,
+ FrameTreeClient* client,
+ scoped_ptr<FrameUserData> user_data,
+ const Frame::ClientPropertyMap& client_properties);
void LoadingStateChanged();
void ProgressChanged();
- void FrameNameChanged(Frame* frame);
+ void ClientPropertyChanged(const Frame* source,
+ const mojo::String& name,
+ const mojo::Array<uint8_t>& value);
mojo::View* view_;
diff --git a/mandoline/tab/public/interfaces/frame_tree.mojom b/mandoline/tab/public/interfaces/frame_tree.mojom
index 4ab2531..92c47a3 100644
--- a/mandoline/tab/public/interfaces/frame_tree.mojom
+++ b/mandoline/tab/public/interfaces/frame_tree.mojom
@@ -38,11 +38,10 @@ struct FrameData {
uint32 parent_id;
uint32 frame_id;
- string? name;
- // TODO(sky): this is not being propagated correctly. It needs to be updated
- // along with deciding if we want to keep NavigatorHost.
- string origin;
- uint32 sandbox_flags;
+ // A map of the properties supplied by the client. The server does not
+ // intepret these values in anyway, the meaning and usage is left up to
+ // clients.
+ map<string, array<uint8>>? client_properties;
};
struct MessageEvent {
@@ -63,12 +62,19 @@ interface FrameTreeServer {
// a load is in progress.
ProgressChanged(uint32 frame_id, double progress);
- SetFrameName(uint32 frame_id, string? name);
+ // Sets the value of the specified client property, notifying clients if the
+ // value changed. If |value| is null the property is removed.
+ SetClientProperty(uint32 frame_id,
+ string name,
+ array<uint8>? value);
// Called when the client creates a new frame. |frame_id| corresponds to
// the id of the view hosting the frame, and |parent_id| the id of the
- // parent.
- OnCreatedFrame(uint32 parent_id, uint32 frame_id);
+ // parent. See FrameData::client_properties for details of
+ // |client_properties|.
+ OnCreatedFrame(uint32 parent_id,
+ uint32 frame_id,
+ map<string, array<uint8>> client_properties);
// The specified frame is requesting a navigation.
RequestNavigate(uint32 frame_id,
@@ -92,7 +98,8 @@ interface FrameTreeClient {
// originator of the change.
OnFrameRemoved(uint32 frame_id);
- // Called when the name of a frame changes. This is not called on the
- // originator of the change.
- OnFrameNameChanged(uint32 frame_id, string name);
+ // Called when a client property changes.
+ OnFrameClientPropertyChanged(uint32 frame_id,
+ string name,
+ array<uint8>? new_value);
};