From 7c8be94a6e7af35e9a043f6c6130fb76b565d3ce Mon Sep 17 00:00:00 2001 From: Samuel Attard Date: Mon, 18 Dec 2017 18:54:44 +1100 Subject: [PATCH] IPC fixes for WebContents --- atom/browser/api/atom_api_web_contents.cc | 47 ++++++++++++++++------- atom/browser/api/atom_api_web_contents.h | 3 ++ 2 files changed, 36 insertions(+), 14 deletions(-) diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index 21b8024f2966..93c65e448f6d 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -896,6 +896,7 @@ void WebContents::DidFinishNavigation( void WebContents::TitleWasSet(content::NavigationEntry* entry) { auto title = entry ? entry->GetTitle() : base::string16(); bool explicit_set; + base::string16 final_title; if (entry && entry->GetURL().SchemeIsFile() && title.empty()) { final_title = base::UTF8ToUTF16(entry->GetURL().ExtractFileName()); explicit_set = false; @@ -903,7 +904,7 @@ void WebContents::TitleWasSet(content::NavigationEntry* entry) { base::TrimWhitespace(title, base::TRIM_ALL, &final_title); explicit_set = true; } - Emit("page-title-updated", title, explicit_set); + Emit("page-title-updated", final_title, explicit_set); } void WebContents::DidUpdateFaviconURL( @@ -967,6 +968,15 @@ void WebContents::ShowAutofillPopup(content::RenderFrameHost* frame_host, } } +// Should only be used for IPC message maps +bool WebContents::Send(IPC::Message* message) { + auto host = web_contents()->GetRenderViewHost(); + + if (host) + return host->Send(message); + return false; +} + bool WebContents::OnMessageReceived(const IPC::Message& message) { bool handled = true; IPC_BEGIN_MESSAGE_MAP(WebContents, message) @@ -1275,14 +1285,20 @@ void WebContents::EnableDeviceEmulation( if (type_ == REMOTE) return; - Send(new ViewMsg_EnableDeviceEmulation(routing_id(), params)); + auto host = web_contents()->GetRenderViewHost(); + + if (host) + host->Send(new ViewMsg_EnableDeviceEmulation(host->GetRoutingID(), params)); } void WebContents::DisableDeviceEmulation() { if (type_ == REMOTE) return; - Send(new ViewMsg_DisableDeviceEmulation(routing_id())); + auto host = web_contents()->GetRenderViewHost(); + + if (host) + host->Send(new ViewMsg_DisableDeviceEmulation(host->GetRoutingID())); } void WebContents::ToggleDevTools() { @@ -1524,10 +1540,10 @@ void WebContents::TabTraverse(bool reverse) { bool WebContents::SendIPCMessage(bool all_frames, const base::string16& channel, const base::ListValue& args) { - auto frame_host = web_contents()->GetMainFrame(); - if (frame_host) { - return frame_host->Send(new AtomFrameMsg_Message( - frame_host->GetRoutingID(), all_frames, channel, args)); + auto host = web_contents()->GetRenderViewHost(); + if (host) { + return host->Send(new AtomViewMsg_Message(host->GetRoutingID(), + all_frames, channel, args)); } return false; } @@ -1818,15 +1834,18 @@ void WebContents::OnSetTemporaryZoomLevel(content::RenderFrameHost* rfh, IPC::Message* reply_msg) { zoom_controller_->SetTemporaryZoomLevel(level); double new_level = zoom_controller_->GetZoomLevel(); - AtomFrameHostMsg_SetTemporaryZoomLevel::WriteReplyParams(reply_msg, - new_level); - rfh->Send(reply_msg); + AtomViewHostMsg_SetTemporaryZoomLevel::WriteReplyParams(reply_msg, new_level); + + auto host = web_contents()->GetRenderViewHost(); + if (host) + host->Send(reply_msg); } -void WebContents::OnGetZoomLevel(content::RenderFrameHost* rfh, - IPC::Message* reply_msg) { - AtomFrameHostMsg_GetZoomLevel::WriteReplyParams(reply_msg, GetZoomLevel()); - rfh->Send(reply_msg); +void WebContents::OnGetZoomLevel(IPC::Message* reply_msg) { + AtomViewHostMsg_GetZoomLevel::WriteReplyParams(reply_msg, GetZoomLevel()); + auto host = web_contents()->GetRenderViewHost(); + if (host) + host->Send(reply_msg); } v8::Local WebContents::GetWebPreferences(v8::Isolate* isolate) { diff --git a/atom/browser/api/atom_api_web_contents.h b/atom/browser/api/atom_api_web_contents.h index 00e4b5a84a13..96bbd4265041 100644 --- a/atom/browser/api/atom_api_web_contents.h +++ b/atom/browser/api/atom_api_web_contents.h @@ -149,6 +149,9 @@ class WebContents : public mate::TrackableObject, void AddWorkSpace(mate::Arguments* args, const base::FilePath& path); void RemoveWorkSpace(mate::Arguments* args, const base::FilePath& path); + // IPC + bool Send(IPC::Message* message); + // Editing commands. void Undo(); void Redo();