Skip to content

Commit

Permalink
Convert BeforeUnloadControl client to use BrowserInterfaceBroker
Browse files Browse the repository at this point in the history
This change converts BeforeUnloadControl mojom interface client in
components to use BrowserInterfaceBroker.
Since MimeHandlerViewGuest is a WebContentsObserver, a static
helper function is used to register its binder.

Bug: 936482
Change-Id: If7d60be6d20307a11028ef5b682fa373cc8033b6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1895099
Commit-Queue: Miyoung Shin <myid.shin@igalia.com>
Reviewed-by: Kinuko Yasuda <kinuko@chromium.org>
Reviewed-by: Ken Rockot <rockot@google.com>
Reviewed-by: Oksana Zhuravlova <oksamyt@chromium.org>
Cr-Commit-Position: refs/heads/master@{#714425}
  • Loading branch information
MyidShin authored and Commit Bot committed Nov 12, 2019
1 parent 2ef6fce commit edfc764
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 23 deletions.
2 changes: 0 additions & 2 deletions chrome/app/chrome_content_browser_overlay_manifest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@
#endif

#if BUILDFLAG(ENABLE_EXTENSIONS)
#include "extensions/common/api/mime_handler.mojom.h" // nogncheck
#include "extensions/common/mojom/keep_alive.mojom.h" // nogncheck
#endif

Expand Down Expand Up @@ -158,7 +157,6 @@ const service_manager::Manifest& GetChromeContentBrowserOverlayManifest() {
contextual_search::mojom::ContextualSearchJsApiService,
#if BUILDFLAG(ENABLE_EXTENSIONS)
extensions::KeepAlive,
extensions::mime_handler::BeforeUnloadControl,
#endif
media::mojom::MediaEngagementScoreDetailsProvider,
media_router::mojom::MediaRouter,
Expand Down
15 changes: 15 additions & 0 deletions chrome/browser/chrome_browser_interface_binders.cc
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,19 @@ void BindMimeHandlerService(
extensions::MimeHandlerServiceImpl::Create(guest_view->GetStreamWeakPtr(),
std::move(receiver));
}

void BindBeforeUnloadControl(
content::RenderFrameHost* frame_host,
mojo::PendingReceiver<extensions::mime_handler::BeforeUnloadControl>
receiver) {
content::WebContents* contents =
content::WebContents::FromRenderFrameHost(frame_host);
auto* guest_view =
extensions::MimeHandlerViewGuest::FromWebContents(contents);
if (!guest_view)
return;
guest_view->FuseBeforeUnloadControl(std::move(receiver));
}
#endif

void PopulateChromeFrameBinders(
Expand Down Expand Up @@ -219,6 +232,8 @@ void PopulateChromeFrameBinders(
#if BUILDFLAG(ENABLE_EXTENSIONS)
map->Add<extensions::mime_handler::MimeHandlerService>(
base::BindRepeating(&BindMimeHandlerService));
map->Add<extensions::mime_handler::BeforeUnloadControl>(
base::BindRepeating(&BindBeforeUnloadControl));
#endif
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,6 @@ void MimeHandlerViewGuest::CreateWebContents(
params,
owner_web_contents()->GetController().GetSessionStorageNamespaceMap())
.release());

registry_.AddInterface(base::BindRepeating(
&MimeHandlerViewGuest::FuseBeforeUnloadControl, base::Unretained(this)));
}

void MimeHandlerViewGuest::DidAttachToEmbedder() {
Expand Down Expand Up @@ -458,13 +455,6 @@ void MimeHandlerViewGuest::DocumentOnLoadCompletedInMainFrame() {
}
}

void MimeHandlerViewGuest::OnInterfaceRequestFromFrame(
content::RenderFrameHost* render_frame_host,
const std::string& interface_name,
mojo::ScopedMessagePipeHandle* interface_pipe) {
registry_.TryBindInterface(interface_name, interface_pipe);
}

void MimeHandlerViewGuest::ReadyToCommitNavigation(
content::NavigationHandle* navigation_handle) {
navigation_handle->RegisterSubresourceOverride(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#include "extensions/common/api/mime_handler.mojom.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "services/service_manager/public/cpp/binder_registry.h"

namespace content {
class WebContents;
Expand Down Expand Up @@ -94,6 +93,9 @@ class MimeHandlerViewGuest

void SetPluginCanSave(bool can_save) { plugin_can_save_ = can_save; }

void FuseBeforeUnloadControl(
mojo::PendingReceiver<mime_handler::BeforeUnloadControl> receiver);

// Asks the plugin to do save.
bool PluginDoSave();

Expand Down Expand Up @@ -174,25 +176,16 @@ class MimeHandlerViewGuest

// content::WebContentsObserver implementation.
void DocumentOnLoadCompletedInMainFrame() final;
void OnInterfaceRequestFromFrame(
content::RenderFrameHost* render_frame_host,
const std::string& interface_name,
mojo::ScopedMessagePipeHandle* interface_pipe) final;
void ReadyToCommitNavigation(
content::NavigationHandle* navigation_handle) final;

void FuseBeforeUnloadControl(
mojo::PendingReceiver<mime_handler::BeforeUnloadControl> receiver);

std::unique_ptr<MimeHandlerViewGuestDelegate> delegate_;
std::unique_ptr<StreamContainer> stream_;

int embedder_frame_process_id_;
int embedder_frame_routing_id_;
int embedder_widget_routing_id_;

service_manager::BinderRegistry registry_;

bool is_guest_fullscreen_ = false;
bool is_embedder_fullscreen_ = false;
bool plugin_can_save_ = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var beforeUnloadControlPtr =
new extensions.mimeHandler.BeforeUnloadControlPtr;
Mojo.bindInterface(
extensions.mimeHandler.BeforeUnloadControl.name,
mojo.makeRequest(beforeUnloadControlPtr).handle);
mojo.makeRequest(beforeUnloadControlPtr).handle, "context", true);

// Stores a promise to the GetStreamInfo() result to avoid making additional
// calls in response to getStreamInfo() calls.
Expand Down

0 comments on commit edfc764

Please sign in to comment.