summaryrefslogtreecommitdiffstats
path: root/components/html_viewer/replicated_frame_state.cc
blob: c514ad2673a64178b93a698bab98b9fd46297c24 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Copyright 2015 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 "components/html_viewer/replicated_frame_state.h"

#include "components/html_viewer/html_frame_properties.h"

namespace html_viewer {

ReplicatedFrameState::ReplicatedFrameState()
    : sandbox_flags(blink::WebSandboxFlags::None),
      tree_scope(blink::WebTreeScopeType::Document) {}

ReplicatedFrameState::~ReplicatedFrameState() {}

void SetReplicatedFrameStateFromClientProperties(
    const mojo::Map<mojo::String, mojo::Array<uint8_t>>& properties,
    ReplicatedFrameState* state) {
  state->name = FrameNameFromClientProperty(
      GetValueFromClientProperties(kPropertyFrameName, properties));
  state->origin = FrameOriginFromClientProperty(
      GetValueFromClientProperties(kPropertyFrameOrigin, properties));
  if (!FrameSandboxFlagsFromClientProperty(
          GetValueFromClientProperties(kPropertyFrameSandboxFlags, properties),
          &(state->sandbox_flags))) {
    state->sandbox_flags = blink::WebSandboxFlags::None;
  }
  if (!FrameTreeScopeFromClientProperty(
          GetValueFromClientProperties(kPropertyFrameTreeScope, properties),
          &(state->tree_scope))) {
    state->tree_scope = blink::WebTreeScopeType::Document;
  }
}

void ClientPropertiesFromReplicatedFrameState(
    const ReplicatedFrameState& state,
    mojo::Map<mojo::String, mojo::Array<uint8_t>>* properties) {
  AddToClientPropertiesIfValid(kPropertyFrameName,
                               FrameNameToClientProperty(state.name).Pass(),
                               properties);
  AddToClientPropertiesIfValid(
      kPropertyFrameTreeScope,
      FrameTreeScopeToClientProperty(state.tree_scope).Pass(), properties);
  AddToClientPropertiesIfValid(
      kPropertyFrameSandboxFlags,
      FrameSandboxFlagsToClientProperty(state.sandbox_flags).Pass(),
      properties);
}

}  // namespace html_viewer