Cros: Paste the HTML into WebContents

Paste the html markup into the WebContents instead of loading it via
a data URL. This ensures the markup is sanitized before rendering it.

Bug: 1148077
Change-Id: I43e6a1607e73602a1d099b087b6db3da27ef2b0b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2523647
Reviewed-by: Matt Falkenhagen <[email protected]>
Reviewed-by: Sadrul Chowdhury <[email protected]>
Reviewed-by: David Black <[email protected]>
Reviewed-by: Xiyuan Xia <[email protected]>
Commit-Queue: Alex Newcomer <[email protected]>
Cr-Commit-Position: refs/heads/master@{#829036}
diff --git a/ash/clipboard/clipboard_history.h b/ash/clipboard/clipboard_history.h
index bb8bb044..e6ffeb0 100644
--- a/ash/clipboard/clipboard_history.h
+++ b/ash/clipboard/clipboard_history.h
@@ -17,6 +17,8 @@
 
 namespace ash {
 
+class ScopedClipboardHistoryPauseImpl;
+
 // Keeps track of the last few things saved in the clipboard.
 class ASH_EXPORT ClipboardHistory : public ui::ClipboardObserver {
  public:
@@ -32,19 +34,6 @@
     virtual void OnClipboardHistoryCleared() {}
   };
 
-  // Prevents clipboard history from being recorded within its scope. If
-  // anything is copied within its scope, history will not be recorded.
-  class ASH_EXPORT ScopedPause {
-   public:
-    explicit ScopedPause(ClipboardHistory* clipboard_history);
-    ScopedPause(const ScopedPause&) = delete;
-    ScopedPause& operator=(const ScopedPause&) = delete;
-    ~ScopedPause();
-
-   private:
-    ClipboardHistory* const clipboard_history_;
-  };
-
   ClipboardHistory();
   ClipboardHistory(const ClipboardHistory&) = delete;
   ClipboardHistory& operator=(const ClipboardHistory&) = delete;
@@ -70,7 +59,13 @@
   // ClipboardMonitor:
   void OnClipboardDataChanged() override;
 
+  base::WeakPtr<ClipboardHistory> GetWeakPtr();
+
  private:
+  // Friended to allow ScopedClipboardHistoryPauseImpl to `Pause()` and
+  // `Resume()`.
+  friend class ScopedClipboardHistoryPauseImpl;
+
   // Adds `data` to the `history_list_` if it's supported. If `data` is not
   // supported by clipboard history, this method no-ops.
   void MaybeCommitData(ui::ClipboardData data);
@@ -91,6 +86,9 @@
 
   // Factory to create WeakPtrs used to debounce calls to CommitData().
   base::WeakPtrFactory<ClipboardHistory> commit_data_weak_factory_{this};
+
+  // Factory to create WeakPtrs for ClipboardHistory.
+  base::WeakPtrFactory<ClipboardHistory> weak_factory_{this};
 };
 
 }  // namespace ash