Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(385)

Unified Diff: third_party/WebKit/Source/core/frame/LocalFrame.cpp

Issue 2943983003: chrome/blink: Add functionality for in-product help for media elements. (Closed)
Patch Set: addressed comments Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/frame/LocalFrame.cpp
diff --git a/third_party/WebKit/Source/core/frame/LocalFrame.cpp b/third_party/WebKit/Source/core/frame/LocalFrame.cpp
index 68560d692093b4bbe2ab1ab902a56aa743f1ff3b..ada7d248ee7ddfcb5a9dd447e493fe8b1451be68 100644
--- a/third_party/WebKit/Source/core/frame/LocalFrame.cpp
+++ b/third_party/WebKit/Source/core/frame/LocalFrame.cpp
@@ -54,6 +54,7 @@
#include "core/frame/Settings.h"
#include "core/frame/VisualViewport.h"
#include "core/html/HTMLFrameElementBase.h"
+#include "core/html/HTMLMediaElement.h"
#include "core/html/HTMLPlugInElement.h"
#include "core/html/PluginDocument.h"
#include "core/input/EventHandler.h"
@@ -79,6 +80,7 @@
#include "core/probe/CoreProbes.h"
#include "core/svg/SVGDocumentExtensions.h"
#include "core/timing/Performance.h"
+#include "mojo/public/cpp/bindings/strong_binding.h"
#include "platform/DragImage.h"
#include "platform/Histogram.h"
#include "platform/PluginScriptForbiddenScope.h"
@@ -106,6 +108,9 @@
#include "public/platform/InterfaceRegistry.h"
#include "public/platform/WebScreenInfo.h"
#include "public/platform/WebURLRequest.h"
+#include "public/platform/media_in_product_help.mojom-blink.h"
+#include "services/service_manager/public/cpp/bind_source_info.h"
+#include "services/service_manager/public/cpp/interface_provider.h"
#include "third_party/skia/include/core/SkImage.h"
#include "third_party/skia/include/core/SkSurface.h"
@@ -272,6 +277,30 @@ FrameInitCallbackVector& GetInitializationVector() {
return initialization_vector;
}
+class MediaInProductHelpDelegate
+ : public mojom::blink::MediaInProductHelpDelegate {
+ public:
+ explicit MediaInProductHelpDelegate(LocalFrame& frame) : frame_(&frame) {}
+ ~MediaInProductHelpDelegate() override = default;
+
+ // chrome::MediaInProductHelpDelegate implementation.
+ void WidgetDismissed() override {
+ if (frame_)
+ frame_->NotifyInProductHelpDismissed();
+ }
+
+ private:
+ WeakPersistent<LocalFrame> frame_;
+};
+
+void CreateMediaInProductHelpDelegate(
+ LocalFrame* frame,
+ mojom::blink::MediaInProductHelpDelegateRequest request) {
+ mojo::MakeStrongBinding(
+ WTF::WrapUnique(new MediaInProductHelpDelegate(*frame)),
+ std::move(request));
+}
+
} // namespace
template class CORE_TEMPLATE_EXPORT Supplement<LocalFrame>;
@@ -382,6 +411,7 @@ DEFINE_TRACE(LocalFrame) {
visitor->Trace(console_);
visitor->Trace(input_method_controller_);
visitor->Trace(frame_resource_coordinator_);
+ visitor->Trace(element_with_active_in_product_help_);
Frame::Trace(visitor);
Supplementable<LocalFrame>::Trace(visitor);
}
@@ -1245,4 +1275,56 @@ void LocalFrame::SetViewportIntersectionFromParent(
}
}
+void LocalFrame::ShowDownloadMediaInProductHelp(HTMLMediaElement& elem) {
+ if (!GetSettings() || !GetSettings()->GetMediaDownloadInProductHelpEnabled())
+ return;
+
+ if (element_with_active_in_product_help_ ||
+ media_in_product_help_shown_for_frame_)
+ return;
+
+ if (!Client())
+ return;
+
+ // Add the service to know when this widget is dismissed.
+ GetInterfaceRegistry()->AddInterface(
+ WTF::Bind(&CreateMediaInProductHelpDelegate, WrapWeakPersistent(this)));
+
+ element_with_active_in_product_help_ = &elem;
+ media_in_product_help_shown_for_frame_ = true;
+}
+
+bool LocalFrame::IsDownloadMediaInProductHelpVisibleForElement(
+ HTMLMediaElement& elem) {
+ return element_with_active_in_product_help_ &&
+ *element_with_active_in_product_help_ == elem;
+}
+
+void LocalFrame::LayoutUpdated() {
+ if (!element_with_active_in_product_help_ || !Client())
+ return;
+
+ IntRect button_rect;
+ if (!element_with_active_in_product_help_->GetMediaControls()
+ ->GetDownloadButtonRect(button_rect)) {
+ mojom::blink::MediaInProductHelpPtr service;
+ Client()->GetInterfaceProvider()->GetInterface(mojo::MakeRequest(&service));
+ service->HideInProductHelpWidget();
+ return;
+ }
+
+ mojom::blink::MediaInProductHelpPtr service;
+ Client()->GetInterfaceProvider()->GetInterface(mojo::MakeRequest(&service));
+ service->ShowInProductHelpWidget(button_rect);
+}
+
+void LocalFrame::NotifyInProductHelpDismissed() {
+ if (element_with_active_in_product_help_ &&
+ element_with_active_in_product_help_->GetMediaControls()) {
+ element_with_active_in_product_help_->GetMediaControls()
+ ->InProductHelpDisabled();
+ }
+ element_with_active_in_product_help_ = nullptr;
+}
+
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698