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") { ...@@ -403,6 +403,8 @@ source_set("blink_headers") {
"web/web_ax_object.h", "web/web_ax_object.h",
"web/web_blob.h", "web/web_blob.h",
"web/web_console_message.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_features.h",
"web/web_context_menu_data.h", "web/web_context_menu_data.h",
"web/web_crypto_normalize.h", "web/web_crypto_normalize.h",
......
...@@ -9,6 +9,7 @@ include_rules = [ ...@@ -9,6 +9,7 @@ include_rules = [
"+base/strings", "+base/strings",
"+base/time/time.h", "+base/time/time.h",
"+cc/input/browser_controls_state.h", "+cc/input/browser_controls_state.h",
"+cc/paint/node_holder.h",
"+cc/paint/paint_canvas.h", "+cc/paint/paint_canvas.h",
"+cc/paint/paint_flags.h", "+cc/paint/paint_flags.h",
"+cc/trees/element_id.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; ...@@ -36,6 +36,7 @@ class FrameScheduler;
class InterfaceRegistry; class InterfaceRegistry;
class WebAssociatedURLLoader; class WebAssociatedURLLoader;
class WebAutofillClient; class WebAutofillClient;
class WebContentCaptureClient;
class WebContentSettingsClient; class WebContentSettingsClient;
class WebDocument; class WebDocument;
class WebDoubleSize; class WebDoubleSize;
...@@ -140,6 +141,9 @@ class WebLocalFrame : public WebFrame { ...@@ -140,6 +141,9 @@ class WebLocalFrame : public WebFrame {
virtual void SetAutofillClient(WebAutofillClient*) = 0; virtual void SetAutofillClient(WebAutofillClient*) = 0;
virtual WebAutofillClient* AutofillClient() = 0; virtual WebAutofillClient* AutofillClient() = 0;
virtual void SetContentCaptureClient(WebContentCaptureClient*) = 0;
virtual WebContentCaptureClient* ContentCaptureClient() const = 0;
// Closing ------------------------------------------------------------- // Closing -------------------------------------------------------------
// Runs unload handlers for this frame. // Runs unload handlers for this frame.
......
...@@ -6,7 +6,6 @@ import("//third_party/blink/renderer/core/core.gni") ...@@ -6,7 +6,6 @@ import("//third_party/blink/renderer/core/core.gni")
blink_core_sources("content_capture") { blink_core_sources("content_capture") {
sources = [ sources = [
"content_capture_client.h",
"content_capture_manager.cc", "content_capture_manager.cc",
"content_capture_manager.h", "content_capture_manager.h",
"content_capture_task.cc", "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 @@ ...@@ -6,7 +6,8 @@
#include "base/auto_reset.h" #include "base/auto_reset.h"
#include "cc/trees/layer_tree_host.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/content_capture/content_holder.h"
#include "third_party/blink/renderer/core/dom/dom_node_ids.h" #include "third_party/blink/renderer/core/dom/dom_node_ids.h"
#include "third_party/blink/renderer/core/frame/local_frame_client.h" #include "third_party/blink/renderer/core/frame/local_frame_client.h"
...@@ -62,7 +63,7 @@ bool ContentCaptureTask::CaptureContent() { ...@@ -62,7 +63,7 @@ bool ContentCaptureTask::CaptureContent() {
void ContentCaptureTask::SendContent() { void ContentCaptureTask::SendContent() {
DCHECK(session_); DCHECK(session_);
std::vector<scoped_refptr<ContentHolder>> content_batch; std::vector<scoped_refptr<WebContentHolder>> content_batch;
content_batch.reserve(kBatchSize); content_batch.reserve(kBatchSize);
for (; session_->unsent != session_->captured_content.end() && for (; session_->unsent != session_->captured_content.end() &&
content_batch.size() < kBatchSize; content_batch.size() < kBatchSize;
...@@ -73,7 +74,8 @@ void ContentCaptureTask::SendContent() { ...@@ -73,7 +74,8 @@ void ContentCaptureTask::SendContent() {
if (node && node->GetLayoutObject() && !delegate_->HasSent(*node)) { if (node && node->GetLayoutObject() && !delegate_->HasSent(*node)) {
content_holder = base::MakeRefCounted<ContentHolder>(*node); content_holder = base::MakeRefCounted<ContentHolder>(*node);
delegate_->OnSent(*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 && } else if (session_->unsent->type == cc::NodeHolder::Type::kTextHolder &&
session_->unsent->text_holder) { session_->unsent->text_holder) {
...@@ -82,12 +84,13 @@ void ContentCaptureTask::SendContent() { ...@@ -82,12 +84,13 @@ void ContentCaptureTask::SendContent() {
if (content_holder && content_holder->IsValid() && if (content_holder && content_holder->IsValid() &&
!content_holder->HasSent()) { !content_holder->HasSent()) {
content_holder->SetHasSent(); content_holder->SetHasSent();
content_batch.push_back(content_holder); content_batch.push_back(
base::MakeRefCounted<WebContentHolder>(content_holder));
} }
} }
} }
if (!content_batch.empty()) { if (!content_batch.empty()) {
GetContentCaptureClient()->DidCaptureContent(content_batch, GetWebContentCaptureClient()->DidCaptureContent(content_batch,
!has_first_data_sent_); !has_first_data_sent_);
has_first_data_sent_ = true; has_first_data_sent_ = true;
} }
...@@ -95,7 +98,7 @@ void ContentCaptureTask::SendContent() { ...@@ -95,7 +98,7 @@ void ContentCaptureTask::SendContent() {
session_->captured_content.clear(); session_->captured_content.clear();
} }
ContentCaptureClient* ContentCaptureTask::GetContentCaptureClient() { WebContentCaptureClient* ContentCaptureTask::GetWebContentCaptureClient() {
// TODO(michaelbai): Enable this after integrate with document. // TODO(michaelbai): Enable this after integrate with document.
// return document_->GetFrame()->Client()->GetContentCaptureClient(); // return document_->GetFrame()->Client()->GetContentCaptureClient();
return nullptr; return nullptr;
...@@ -112,7 +115,7 @@ bool ContentCaptureTask::ProcessSession() { ...@@ -112,7 +115,7 @@ bool ContentCaptureTask::ProcessSession() {
} }
// Sent the detached nodes. // Sent the detached nodes.
if (!session_->detached_nodes.empty()) { if (!session_->detached_nodes.empty()) {
GetContentCaptureClient()->DidRemoveContent(session_->detached_nodes); GetWebContentCaptureClient()->DidRemoveContent(session_->detached_nodes);
session_->detached_nodes.clear(); session_->detached_nodes.clear();
} }
session_.reset(); session_.reset();
...@@ -122,7 +125,7 @@ bool ContentCaptureTask::ProcessSession() { ...@@ -122,7 +125,7 @@ bool ContentCaptureTask::ProcessSession() {
bool ContentCaptureTask::RunInternal() { bool ContentCaptureTask::RunInternal() {
base::AutoReset<TaskState> state(&task_state_, TaskState::kProcessRetryTask); base::AutoReset<TaskState> state(&task_state_, TaskState::kProcessRetryTask);
// Already shutdown. // Already shutdown.
if (!document_ || !GetContentCaptureClient()) if (!document_ || !GetWebContentCaptureClient())
return true; return true;
do { do {
......
...@@ -15,12 +15,12 @@ ...@@ -15,12 +15,12 @@
namespace blink { namespace blink {
class ContentCaptureClient; class WebContentCaptureClient;
class Document; class Document;
class Node; class Node;
// This class is used to capture the on-screen content and send them out // 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> { class CORE_EXPORT ContentCaptureTask : public RefCounted<ContentCaptureTask> {
USING_FAST_MALLOC(ContentCaptureTask); USING_FAST_MALLOC(ContentCaptureTask);
...@@ -76,7 +76,7 @@ class CORE_EXPORT ContentCaptureTask : public RefCounted<ContentCaptureTask> { ...@@ -76,7 +76,7 @@ class CORE_EXPORT ContentCaptureTask : public RefCounted<ContentCaptureTask> {
// Return true if the task should pause. // Return true if the task should pause.
virtual bool ShouldPause(); virtual bool ShouldPause();
virtual bool CaptureContent(std::vector<cc::NodeHolder>& data); virtual bool CaptureContent(std::vector<cc::NodeHolder>& data);
virtual ContentCaptureClient* GetContentCaptureClient(); virtual WebContentCaptureClient* GetWebContentCaptureClient();
private: private:
struct Session { struct Session {
......
...@@ -12,6 +12,7 @@ blink_core_sources("exported") { ...@@ -12,6 +12,7 @@ blink_core_sources("exported") {
"web_associated_url_loader_impl.cc", "web_associated_url_loader_impl.cc",
"web_associated_url_loader_impl.h", "web_associated_url_loader_impl.h",
"web_blob.cc", "web_blob.cc",
"web_content_holder.cc",
"web_context_features.cc", "web_context_features.cc",
"web_css_parser.cc", "web_css_parser.cc",
"web_custom_element.cc", "web_custom_element.cc",
......
...@@ -188,6 +188,11 @@ WebLocalFrameImpl* LocalFrameClientImpl::GetWebFrame() const { ...@@ -188,6 +188,11 @@ WebLocalFrameImpl* LocalFrameClientImpl::GetWebFrame() const {
return web_frame_.Get(); return web_frame_.Get();
} }
WebContentCaptureClient* LocalFrameClientImpl::GetWebContentCaptureClient()
const {
return web_frame_->ContentCaptureClient();
}
void LocalFrameClientImpl::DidCreateNewDocument() { void LocalFrameClientImpl::DidCreateNewDocument() {
if (web_frame_->Client()) if (web_frame_->Client())
web_frame_->Client()->DidCreateNewDocument(); web_frame_->Client()->DidCreateNewDocument();
......
...@@ -63,7 +63,7 @@ class LocalFrameClientImpl final : public LocalFrameClient { ...@@ -63,7 +63,7 @@ class LocalFrameClientImpl final : public LocalFrameClient {
WebLocalFrameImpl* GetWebFrame() const override; WebLocalFrameImpl* GetWebFrame() const override;
// LocalFrameClient ---------------------------------------------- // LocalFrameClient ----------------------------------------------
WebContentCaptureClient* GetWebContentCaptureClient() const override;
void DidCreateNewDocument() override; void DidCreateNewDocument() override;
// Notifies the WebView delegate that the JS window object has been cleared, // 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 // 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; ...@@ -101,6 +101,7 @@ class ResourceResponse;
class SecurityOrigin; class SecurityOrigin;
class WebApplicationCacheHost; class WebApplicationCacheHost;
class WebApplicationCacheHostClient; class WebApplicationCacheHostClient;
class WebContentCaptureClient;
class WebCookieJar; class WebCookieJar;
class WebLayerTreeView; class WebLayerTreeView;
class WebLocalFrame; class WebLocalFrame;
...@@ -123,6 +124,10 @@ class CORE_EXPORT LocalFrameClient : public FrameClient { ...@@ -123,6 +124,10 @@ class CORE_EXPORT LocalFrameClient : public FrameClient {
public: public:
~LocalFrameClient() override = default; ~LocalFrameClient() override = default;
virtual WebContentCaptureClient* GetWebContentCaptureClient() const {
return nullptr;
}
virtual WebLocalFrame* GetWebFrame() const { return nullptr; } virtual WebLocalFrame* GetWebFrame() const { return nullptr; }
virtual bool HasWebView() const = 0; // mainly for assertions virtual bool HasWebView() const = 0; // mainly for assertions
......
...@@ -112,6 +112,7 @@ ...@@ -112,6 +112,7 @@
#include "third_party/blink/public/web/web_associated_url_loader_options.h" #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_autofill_client.h"
#include "third_party/blink/public/web/web_console_message.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_document.h"
#include "third_party/blink/public/web/web_dom_event.h" #include "third_party/blink/public/web/web_dom_event.h"
#include "third_party/blink/public/web/web_form_element.h" #include "third_party/blink/public/web/web_form_element.h"
...@@ -1996,6 +1997,15 @@ WebAutofillClient* WebLocalFrameImpl::AutofillClient() { ...@@ -1996,6 +1997,15 @@ WebAutofillClient* WebLocalFrameImpl::AutofillClient() {
return autofill_client_; 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 { bool WebLocalFrameImpl::IsLocalRoot() const {
return frame_->IsLocalRoot(); return frame_->IsLocalRoot();
} }
......
...@@ -253,6 +253,8 @@ class CORE_EXPORT WebLocalFrameImpl final ...@@ -253,6 +253,8 @@ class CORE_EXPORT WebLocalFrameImpl final
mojo::ScopedMessagePipeHandle) override; mojo::ScopedMessagePipeHandle) override;
void SetAutofillClient(WebAutofillClient*) override; void SetAutofillClient(WebAutofillClient*) override;
WebAutofillClient* AutofillClient() override; WebAutofillClient* AutofillClient() override;
void SetContentCaptureClient(WebContentCaptureClient*) override;
WebContentCaptureClient* ContentCaptureClient() const override;
bool IsLocalRoot() const override; bool IsLocalRoot() const override;
bool IsProvisional() const override; bool IsProvisional() const override;
WebLocalFrameImpl* LocalRoot() override; WebLocalFrameImpl* LocalRoot() override;
...@@ -482,6 +484,9 @@ class CORE_EXPORT WebLocalFrameImpl final ...@@ -482,6 +484,9 @@ class CORE_EXPORT WebLocalFrameImpl final
Member<WebDevToolsAgentImpl> dev_tools_agent_; Member<WebDevToolsAgentImpl> dev_tools_agent_;
WebAutofillClient* autofill_client_; WebAutofillClient* autofill_client_;
WebContentCaptureClient* content_capture_client_ = nullptr;
WebContentSettingsClient* content_settings_client_ = nullptr; WebContentSettingsClient* content_settings_client_ = nullptr;
Member<FindInPage> find_in_page_; 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