Index: chrome/renderer/media/media_iph_impl.cc |
diff --git a/chrome/renderer/media/media_iph_impl.cc b/chrome/renderer/media/media_iph_impl.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..85457dbf688930d8fb2cdc2b4d198442e39ceb39 |
--- /dev/null |
+++ b/chrome/renderer/media/media_iph_impl.cc |
@@ -0,0 +1,71 @@ |
+// Copyright 2017 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 "chrome/renderer/media/media_iph_impl.h" |
+ |
+#include "content/public/renderer/render_frame.h" |
+#include "mojo/public/cpp/bindings/strong_binding.h" |
+#include "services/service_manager/public/cpp/binder_registry.h" |
+#include "services/service_manager/public/cpp/interface_provider.h" |
+#include "third_party/WebKit/public/platform/WebRect.h" |
+ |
+class MediaIPHImpl::MediaIPHDelegateService |
+ : public chrome::mojom::MediaIPHDelegateService { |
+ public: |
+ explicit MediaIPHDelegateService(MediaIPHImpl* media_iph_impl) |
+ : media_iph_impl_(media_iph_impl) { |
+ DCHECK(media_iph_impl_); |
+ } |
+ ~MediaIPHDelegateService() override = default; |
+ |
+ // chrome::MediaIPHDelegateService implementation. |
+ void WidgetDismissed() override { media_iph_impl_->IPHWidgetDismissed(); } |
+ |
+ private: |
+ MediaIPHImpl* media_iph_impl_; |
+}; |
+ |
+MediaIPHImpl::MediaIPHImpl(content::RenderFrame* render_frame) |
+ : render_frame_(render_frame), weak_factory_(this) { |
+ render_frame_->GetInterfaceRegistry()->AddInterface(base::Bind( |
+ &MediaIPHImpl::CreateDelegateService, weak_factory_.GetWeakPtr())); |
+} |
+ |
+MediaIPHImpl::~MediaIPHImpl() { |
+ if (client_) |
+ client_->DidHideMediaIPHWidget(); |
+} |
+ |
+void MediaIPHImpl::BindToClient(blink::WebMediaIPHClient* client) { |
+ DCHECK(!client_); |
+ client_ = client; |
+} |
+ |
+void MediaIPHImpl::ShowMediaDownloadIPH(const blink::WebRect& rect) { |
+ bool new_request = !iph_active_; |
+ iph_active_ = true; |
+ |
+ chrome::mojom::MediaIPHServicePtr iph_service; |
+ render_frame_->GetRemoteInterfaces()->GetInterface(&iph_service); |
+ iph_service->ShowIPHWidget(rect, new_request); |
+} |
+ |
+void MediaIPHImpl::HideMediaDownloadIPH() { |
+ chrome::mojom::MediaIPHServicePtr iph_service; |
+ render_frame_->GetRemoteInterfaces()->GetInterface(&iph_service); |
+ iph_service->HideIPHWidget(); |
+} |
+ |
+void MediaIPHImpl::CreateDelegateService( |
+ const service_manager::BindSourceInfo& source_info, |
+ chrome::mojom::MediaIPHDelegateServiceRequest request) { |
+ mojo::MakeStrongBinding(base::MakeUnique<MediaIPHDelegateService>(this), |
+ std::move(request)); |
+} |
+ |
+void MediaIPHImpl::IPHWidgetDismissed() { |
+ DCHECK(client_); |
+ iph_active_ = false; |
+ client_->DidHideMediaIPHWidget(); |
+} |