summaryrefslogtreecommitdiff
path: root/chromium/services/content/public/cpp/navigable_contents.cc
blob: 3f1c8dd1ced23f968a0f8b9b73b2a3e6cdab00f1 (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
// Copyright 2018 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 "services/content/public/cpp/navigable_contents.h"

#include "base/memory/ptr_util.h"
#include "services/content/public/cpp/navigable_contents_view.h"

namespace content {

NavigableContents::NavigableContents(mojom::NavigableContentsFactory* factory)
    : client_binding_(this) {
  mojom::NavigableContentsClientPtr client;
  client_binding_.Bind(mojo::MakeRequest(&client));
  factory->CreateContents(mojom::NavigableContentsParams::New(),
                          mojo::MakeRequest(&contents_), std::move(client));
}

NavigableContents::~NavigableContents() = default;

NavigableContentsView* NavigableContents::GetView() {
  if (!view_) {
    view_ = base::WrapUnique(new NavigableContentsView);
    contents_->CreateView(
        NavigableContentsView::IsClientRunningInServiceProcess(),
        base::BindOnce(&NavigableContents::OnEmbedTokenReceived,
                       base::Unretained(this)));
  }
  return view_.get();
}

void NavigableContents::Navigate(const GURL& url) {
  contents_->Navigate(url);
}

void NavigableContents::DidStopLoading() {
  if (did_stop_loading_callback_)
    did_stop_loading_callback_.Run();
}

void NavigableContents::OnEmbedTokenReceived(
    const base::UnguessableToken& token) {
  DCHECK(view_);
  view_->EmbedUsingToken(token);
}

}  // namespace content