Commit d4500763 authored by Tao Bai's avatar Tao Bai Committed by Commit Bot

Add WebContentCaptureClient

WebContentCaptureClient is an interface that is used by ContentCapture
to communicate with chromium's components peer, it provides methods to
- Check if ContentCapture enabled.
- Send the captured content to chromium peer.

This patch replaced ContentCaptureClient with WebContentCaptureClient
to avoid the unnecessary wrapper.

Bug: 924681

Change-Id: Icf22bfb416843888dfc3e63ed9a5b39103573fe4
Reviewed-on: https://chromium-review.googlesource.com/c/1468598Reviewed-by: default avatardanakj <danakj@chromium.org>
Reviewed-by: default avatarPhilip Rogers <pdr@chromium.org>
Reviewed-by: default avatarXianzhu Wang <wangxianzhu@chromium.org>
Commit-Queue: Tao Bai <michaelbai@chromium.org>
Cr-Commit-Position: refs/heads/master@{#635619}
parent f82f4c7e
......@@ -403,6 +403,8 @@ source_set("blink_headers") {
"web/web_ax_object.h",
"web/web_blob.h",
"web/web_console_message.h",
"web/web_content_capture_client.h",
"web/web_content_holder.h",
"web/web_context_features.h",
"web/web_context_menu_data.h",
"web/web_crypto_normalize.h",
......
......@@ -9,6 +9,7 @@ include_rules = [
"+base/strings",
"+base/time/time.h",
"+cc/input/browser_controls_state.h",
"+cc/paint/node_holder.h",
"+cc/paint/paint_canvas.h",
"+cc/paint/paint_flags.h",
"+cc/trees/element_id.h",
......
// Copyright 2019 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 THIRD_PARTY_BLINK_PUBLIC_WEB_WEB_CONTENT_CAPTURE_CLIENT_H_
#define THIRD_PARTY_BLINK_PUBLIC_WEB_WEB_CONTENT_CAPTURE_CLIENT_H_
#include <vector>
#include "base/memory/scoped_refptr.h"
#include "cc/paint/node_holder.h"
namespace blink {
class WebContentHolder;
// This interface is called by ContentCaptureManager to talk to the embedder,
// the ContentCapture is disabled without implementation of this interface.
class WebContentCaptureClient {
public:
virtual cc::NodeHolder::Type GetNodeHolderType() const = 0;
// Invoked when a list of |content| is captured, |first_content| indicates if
// this is first captured content in the current document.
virtual void DidCaptureContent(
const std::vector<scoped_refptr<WebContentHolder>>& content,
bool first_data) = 0;
// Invoked when the previously captured content is removed, |content_ids| is a
// list of removed content id.
virtual void DidRemoveContent(const std::vector<int64_t>& content_ids) = 0;
protected:
virtual ~WebContentCaptureClient() = default;
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_PUBLIC_WEB_WEB_CONTENT_CAPTURE_CLIENT_H_
// Copyright 2019 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 THIRD_PARTY_BLINK_PUBLIC_WEB_WEB_CONTENT_HOLDER_H_
#define THIRD_PARTY_BLINK_PUBLIC_WEB_WEB_CONTENT_HOLDER_H_
#include "base/memory/ref_counted.h"
#include "third_party/blink/public/platform/web_common.h"
#include "third_party/blink/public/platform/web_rect.h"
#include "third_party/blink/public/platform/web_string.h"
#include "third_party/blink/public/platform/web_vector.h"
namespace blink {
class ContentHolder;
// The class to represent the captured content.
class BLINK_EXPORT WebContentHolder
: public base::RefCounted<WebContentHolder> {
public:
WebString GetValue() const;
WebRect GetBoundingBox() const;
uint64_t GetId() const;
#if INSIDE_BLINK
WebContentHolder(scoped_refptr<ContentHolder> content_holder);
#endif
private:
friend class base::RefCounted<WebContentHolder>;
virtual ~WebContentHolder();
scoped_refptr<ContentHolder> private_;
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_PUBLIC_WEB_WEB_CONTENT_HOLDER_H_
......@@ -36,6 +36,7 @@ class FrameScheduler;
class InterfaceRegistry;
class WebAssociatedURLLoader;
class WebAutofillClient;
class WebContentCaptureClient;
class WebContentSettingsClient;
class WebDocument;
class WebDoubleSize;
......@@ -140,6 +141,9 @@ class WebLocalFrame : public WebFrame {
virtual void SetAutofillClient(WebAutofillClient*) = 0;
virtual WebAutofillClient* AutofillClient() = 0;
virtual void SetContentCaptureClient(WebContentCaptureClient*) = 0;
virtual WebContentCaptureClient* ContentCaptureClient() const = 0;
// Closing -------------------------------------------------------------
// Runs unload handlers for this frame.
......
......@@ -6,7 +6,6 @@ import("//third_party/blink/renderer/core/core.gni")
blink_core_sources("content_capture") {
sources = [
"content_capture_client.h",
"content_capture_manager.cc",
"content_capture_manager.h",
"content_capture_task.cc",
......
// Copyright 2019 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 THIRD_PARTY_BLINK_RENDERER_CORE_CONTENT_CAPTURE_CONTENT_CAPTURE_CLIENT_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_CONTENT_CAPTURE_CONTENT_CAPTURE_CLIENT_H_
#include <vector>
#include "third_party/blink/renderer/core/content_capture/content_holder.h"
#include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/platform/heap/handle.h"
namespace blink {
class ContentHolder;
// The interface ContentCapture client should be implemented.
class CORE_EXPORT ContentCaptureClient
: public GarbageCollectedFinalized<ContentCaptureClient> {
public:
virtual ~ContentCaptureClient() = default;
// Returns if ContentCapture should be enable.
virtual bool IsContentCaptureEnabled() = 0;
// Returns the NodeHolder::Type should be used in ContentCapture.
virtual NodeHolder::Type GetNodeHolderType() const = 0;
// Invoked when a list of |content| is captured, |first_content| indicates if
// this is first captured content.
virtual void DidCaptureContent(
const std::vector<scoped_refptr<ContentHolder>>& content,
bool first_content) = 0;
// Invoked when the content is removed, |content_ids| is a list of id of
// removed content.
virtual void DidRemoveContent(const std::vector<int64_t>& content_ids) = 0;
virtual void Trace(blink::Visitor* visitor) {}
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_CORE_CONTENT_CAPTURE_CONTENT_CAPTURE_CLIENT_H_
......@@ -6,7 +6,8 @@
#include "base/auto_reset.h"
#include "cc/trees/layer_tree_host.h"
#include "third_party/blink/renderer/core/content_capture/content_capture_client.h"
#include "third_party/blink/public/web/web_content_capture_client.h"
#include "third_party/blink/public/web/web_content_holder.h"
#include "third_party/blink/renderer/core/content_capture/content_holder.h"
#include "third_party/blink/renderer/core/dom/dom_node_ids.h"
#include "third_party/blink/renderer/core/frame/local_frame_client.h"
......@@ -62,7 +63,7 @@ bool ContentCaptureTask::CaptureContent() {
void ContentCaptureTask::SendContent() {
DCHECK(session_);
std::vector<scoped_refptr<ContentHolder>> content_batch;
std::vector<scoped_refptr<WebContentHolder>> content_batch;
content_batch.reserve(kBatchSize);
for (; session_->unsent != session_->captured_content.end() &&
content_batch.size() < kBatchSize;
......@@ -73,7 +74,8 @@ void ContentCaptureTask::SendContent() {
if (node && node->GetLayoutObject() && !delegate_->HasSent(*node)) {
content_holder = base::MakeRefCounted<ContentHolder>(*node);
delegate_->OnSent(*node);
content_batch.push_back(content_holder);
content_batch.push_back(
base::MakeRefCounted<WebContentHolder>(content_holder));
}
} else if (session_->unsent->type == cc::NodeHolder::Type::kTextHolder &&
session_->unsent->text_holder) {
......@@ -82,20 +84,21 @@ void ContentCaptureTask::SendContent() {
if (content_holder && content_holder->IsValid() &&
!content_holder->HasSent()) {
content_holder->SetHasSent();
content_batch.push_back(content_holder);
content_batch.push_back(
base::MakeRefCounted<WebContentHolder>(content_holder));
}
}
}
if (!content_batch.empty()) {
GetContentCaptureClient()->DidCaptureContent(content_batch,
!has_first_data_sent_);
GetWebContentCaptureClient()->DidCaptureContent(content_batch,
!has_first_data_sent_);
has_first_data_sent_ = true;
}
if (session_->unsent == session_->captured_content.end())
session_->captured_content.clear();
}
ContentCaptureClient* ContentCaptureTask::GetContentCaptureClient() {
WebContentCaptureClient* ContentCaptureTask::GetWebContentCaptureClient() {
// TODO(michaelbai): Enable this after integrate with document.
// return document_->GetFrame()->Client()->GetContentCaptureClient();
return nullptr;
......@@ -112,7 +115,7 @@ bool ContentCaptureTask::ProcessSession() {
}
// Sent the detached nodes.
if (!session_->detached_nodes.empty()) {
GetContentCaptureClient()->DidRemoveContent(session_->detached_nodes);
GetWebContentCaptureClient()->DidRemoveContent(session_->detached_nodes);
session_->detached_nodes.clear();
}
session_.reset();
......@@ -122,7 +125,7 @@ bool ContentCaptureTask::ProcessSession() {
bool ContentCaptureTask::RunInternal() {
base::AutoReset<TaskState> state(&task_state_, TaskState::kProcessRetryTask);
// Already shutdown.
if (!document_ || !GetContentCaptureClient())
if (!document_ || !GetWebContentCaptureClient())
return true;
do {
......
......@@ -15,12 +15,12 @@
namespace blink {
class ContentCaptureClient;
class WebContentCaptureClient;
class Document;
class Node;
// This class is used to capture the on-screen content and send them out
// through ContentCaptureClient.
// through WebContentCaptureClient.
class CORE_EXPORT ContentCaptureTask : public RefCounted<ContentCaptureTask> {
USING_FAST_MALLOC(ContentCaptureTask);
......@@ -76,7 +76,7 @@ class CORE_EXPORT ContentCaptureTask : public RefCounted<ContentCaptureTask> {
// Return true if the task should pause.
virtual bool ShouldPause();
virtual bool CaptureContent(std::vector<cc::NodeHolder>& data);
virtual ContentCaptureClient* GetContentCaptureClient();
virtual WebContentCaptureClient* GetWebContentCaptureClient();
private:
struct Session {
......
......@@ -12,6 +12,7 @@ blink_core_sources("exported") {
"web_associated_url_loader_impl.cc",
"web_associated_url_loader_impl.h",
"web_blob.cc",
"web_content_holder.cc",
"web_context_features.cc",
"web_css_parser.cc",
"web_custom_element.cc",
......
......@@ -188,6 +188,11 @@ WebLocalFrameImpl* LocalFrameClientImpl::GetWebFrame() const {
return web_frame_.Get();
}
WebContentCaptureClient* LocalFrameClientImpl::GetWebContentCaptureClient()
const {
return web_frame_->ContentCaptureClient();
}
void LocalFrameClientImpl::DidCreateNewDocument() {
if (web_frame_->Client())
web_frame_->Client()->DidCreateNewDocument();
......
......@@ -63,7 +63,7 @@ class LocalFrameClientImpl final : public LocalFrameClient {
WebLocalFrameImpl* GetWebFrame() const override;
// LocalFrameClient ----------------------------------------------
WebContentCaptureClient* GetWebContentCaptureClient() const override;
void DidCreateNewDocument() override;
// Notifies the WebView delegate that the JS window object has been cleared,
// giving it a chance to bind native objects to the window before script
......
// Copyright 2019 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 "third_party/blink/public/web/web_content_holder.h"
#include "third_party/blink/renderer/core/content_capture/content_holder.h"
namespace blink {
WebContentHolder::~WebContentHolder() = default;
WebString WebContentHolder::GetValue() const {
return private_->GetValue();
}
WebRect WebContentHolder::GetBoundingBox() const {
return private_->GetBoundingBox();
}
uint64_t WebContentHolder::GetId() const {
return private_->GetId();
}
WebContentHolder::WebContentHolder(scoped_refptr<ContentHolder> content_holder)
: private_(std::move(content_holder)) {}
} // namespace blink
......@@ -101,6 +101,7 @@ class ResourceResponse;
class SecurityOrigin;
class WebApplicationCacheHost;
class WebApplicationCacheHostClient;
class WebContentCaptureClient;
class WebCookieJar;
class WebLayerTreeView;
class WebLocalFrame;
......@@ -123,6 +124,10 @@ class CORE_EXPORT LocalFrameClient : public FrameClient {
public:
~LocalFrameClient() override = default;
virtual WebContentCaptureClient* GetWebContentCaptureClient() const {
return nullptr;
}
virtual WebLocalFrame* GetWebFrame() const { return nullptr; }
virtual bool HasWebView() const = 0; // mainly for assertions
......
......@@ -112,6 +112,7 @@
#include "third_party/blink/public/web/web_associated_url_loader_options.h"
#include "third_party/blink/public/web/web_autofill_client.h"
#include "third_party/blink/public/web/web_console_message.h"
#include "third_party/blink/public/web/web_content_capture_client.h"
#include "third_party/blink/public/web/web_document.h"
#include "third_party/blink/public/web/web_dom_event.h"
#include "third_party/blink/public/web/web_form_element.h"
......@@ -1996,6 +1997,15 @@ WebAutofillClient* WebLocalFrameImpl::AutofillClient() {
return autofill_client_;
}
void WebLocalFrameImpl::SetContentCaptureClient(
WebContentCaptureClient* content_capture_client) {
content_capture_client_ = content_capture_client;
}
WebContentCaptureClient* WebLocalFrameImpl::ContentCaptureClient() const {
return content_capture_client_;
}
bool WebLocalFrameImpl::IsLocalRoot() const {
return frame_->IsLocalRoot();
}
......
......@@ -253,6 +253,8 @@ class CORE_EXPORT WebLocalFrameImpl final
mojo::ScopedMessagePipeHandle) override;
void SetAutofillClient(WebAutofillClient*) override;
WebAutofillClient* AutofillClient() override;
void SetContentCaptureClient(WebContentCaptureClient*) override;
WebContentCaptureClient* ContentCaptureClient() const override;
bool IsLocalRoot() const override;
bool IsProvisional() const override;
WebLocalFrameImpl* LocalRoot() override;
......@@ -482,6 +484,9 @@ class CORE_EXPORT WebLocalFrameImpl final
Member<WebDevToolsAgentImpl> dev_tools_agent_;
WebAutofillClient* autofill_client_;
WebContentCaptureClient* content_capture_client_ = nullptr;
WebContentSettingsClient* content_settings_client_ = nullptr;
Member<FindInPage> find_in_page_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment