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

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..15d78bebfc61abc10467a3cf8e879d835f338a4a 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,31 @@ FrameInitCallbackVector& GetInitializationVector() {
return initialization_vector;
}
+class MediaInProductHelpDelegateService
+ : public mojom::blink::MediaInProductHelpDelegateService {
+ public:
+ explicit MediaInProductHelpDelegateService(LocalFrame& frame)
+ : frame_(&frame) {}
+ ~MediaInProductHelpDelegateService() override = default;
+
+ // chrome::MediaInProductHelpDelegateService implementation.
+ void WidgetDismissed() override {
+ if (frame_)
+ frame_->NotifyInProductHelpDismissed();
+ }
+
+ private:
+ WeakPersistent<LocalFrame> frame_;
+};
+
+void CreateMediaInProductHelpDelegateService(
+ LocalFrame* frame,
+ mojom::blink::MediaInProductHelpDelegateServiceRequest request) {
+ mojo::MakeStrongBinding(
+ WTF::WrapUnique(new MediaInProductHelpDelegateService(*frame)),
+ std::move(request));
+}
+
} // namespace
template class CORE_TEMPLATE_EXPORT Supplement<LocalFrame>;
@@ -382,6 +412,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 +1276,67 @@ void LocalFrame::SetViewportIntersectionFromParent(
}
}
+void LocalFrame::ShowDownloadMediaInProductHelp(HTMLMediaElement& elem) {
Sam McNally 2017/06/28 09:19:58 Could this be handled within MediaControlDownloadB
Khushal 2017/06/28 22:28:46 The element had to be tracked at some place which
Sam McNally 2017/07/03 09:45:40 MediaControlsImpl should be able to observe layout
Khushal 2017/07/07 04:18:13 The ResizeObserver only hears about size changes i
+ 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(
+ &CreateMediaInProductHelpDelegateService, 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::NotifyMediaControlsHidden(HTMLMediaElement& elem) {
+ if (!element_with_active_in_product_help_ ||
+ *element_with_active_in_product_help_ != elem || !Client())
+ return;
+
+ mojom::blink::MediaInProductHelpServicePtr service;
+ Client()->GetInterfaceProvider()->GetInterface(mojo::MakeRequest(&service));
+ service->HideInProductHelpWidget();
+}
+
+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::MediaInProductHelpServicePtr service;
+ Client()->GetInterfaceProvider()->GetInterface(mojo::MakeRequest(&service));
+ service->HideInProductHelpWidget();
+ return;
+ }
+
+ mojom::blink::MediaInProductHelpServicePtr service;
+ Client()->GetInterfaceProvider()->GetInterface(mojo::MakeRequest(&service));
+ service->ShowInProductHelpWidget(button_rect.X(), button_rect.Y(),
+ button_rect.Width(), button_rect.Height());
+}
+
+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