REVIEW: move ipc use from rvh to rfh

This commit is contained in:
deepak1556 2017-12-30 02:06:11 +05:30 коммит произвёл Aleksei Kuzmin
Родитель b552ad7065
Коммит 5684f8886f
7 изменённых файлов: 62 добавлений и 39 удалений

Просмотреть файл

@ -970,15 +970,6 @@ 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)
@ -1542,10 +1533,10 @@ void WebContents::TabTraverse(bool reverse) {
bool WebContents::SendIPCMessage(bool all_frames,
const base::string16& channel,
const base::ListValue& args) {
auto host = web_contents()->GetRenderViewHost();
if (host) {
return host->Send(new AtomViewMsg_Message(host->GetRoutingID(),
all_frames, channel, args));
auto frame_host = web_contents()->GetMainFrame();
if (frame_host) {
return frame_host->Send(new AtomFrameMsg_Message(
frame_host->GetRoutingID(), all_frames, channel, args));
}
return false;
}
@ -1836,18 +1827,15 @@ void WebContents::OnSetTemporaryZoomLevel(content::RenderFrameHost* rfh,
IPC::Message* reply_msg) {
zoom_controller_->SetTemporaryZoomLevel(level);
double new_level = zoom_controller_->GetZoomLevel();
AtomViewHostMsg_SetTemporaryZoomLevel::WriteReplyParams(reply_msg, new_level);
auto host = web_contents()->GetRenderViewHost();
if (host)
host->Send(reply_msg);
AtomFrameHostMsg_SetTemporaryZoomLevel::WriteReplyParams(reply_msg,
new_level);
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);
void WebContents::OnGetZoomLevel(content::RenderFrameHost* rfh,
IPC::Message* reply_msg) {
AtomFrameHostMsg_GetZoomLevel::WriteReplyParams(reply_msg, GetZoomLevel());
rfh->Send(reply_msg);
}
v8::Local<v8::Value> WebContents::GetWebPreferences(v8::Isolate* isolate) {

Просмотреть файл

@ -149,9 +149,6 @@ class WebContents : public mate::TrackableObject<WebContents>,
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();

Просмотреть файл

@ -6,7 +6,7 @@
#include "atom/common/api/api_messages.h"
#include "atom/common/native_mate_converters/string16_converter.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/web_contents.h"
#include "native_mate/object_template_builder.h"
@ -60,10 +60,8 @@ bool Event::SendReply(const base::string16& json) {
if (message_ == nullptr || sender_ == nullptr)
return false;
AtomViewHostMsg_Message_Sync::WriteReplyParams(message_, json);
auto host = sender_->GetRenderViewHost();
if (!host) return false;
bool success = host->Send(message_);
AtomFrameHostMsg_Message_Sync::WriteReplyParams(message_, json);
bool success = sender_->Send(message_);
message_ = nullptr;
sender_ = nullptr;
return success;

Просмотреть файл

@ -7,7 +7,7 @@
#include "atom/common/api/api_messages.h"
#include "base/strings/utf_string_conversions.h"
#include "base/values.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/web_contents.h"
namespace atom {
@ -37,10 +37,10 @@ void RemoteCallbackFreer::RunDestructor() {
base::ASCIIToUTF16("ELECTRON_RENDERER_RELEASE_CALLBACK");
base::ListValue args;
args.AppendInteger(object_id_);
auto host = web_contents()->GetRenderViewHost();
if (host) {
host->Send(new AtomViewMsg_Message(
host->GetRoutingID(), false, channel, args));
auto frame_host = web_contents()->GetMainFrame();
if (frame_host) {
frame_host->Send(new AtomFrameMsg_Message(frame_host->GetRoutingID(), false,
channel, args));
}
Observe(nullptr);

Просмотреть файл

@ -10,7 +10,6 @@
#include "content/public/renderer/render_frame.h"
#include "native_mate/dictionary.h"
#include "third_party/WebKit/public/web/WebLocalFrame.h"
#include "third_party/WebKit/public/web/WebView.h"
using content::RenderFrame;
using blink::WebLocalFrame;

Просмотреть файл

@ -7,8 +7,8 @@
#include <string>
#include <vector>
// Put this before event_emitter_caller.h to have string16 support.
#include "atom/common/native_mate_converters/string16_converter.h"
#include "atom/common/api/api_messages.h"
#include "atom/common/api/event_emitter_caller.h"
#include "atom/common/native_mate_converters/value_converter.h"
@ -127,6 +127,46 @@ void AtomRenderFrameObserver::OnDestruct() {
delete this;
}
bool AtomRenderFrameObserver::OnMessageReceived(const IPC::Message& message) {
bool handled = true;
IPC_BEGIN_MESSAGE_MAP(AtomRenderFrameObserver, message)
IPC_MESSAGE_HANDLER(AtomFrameMsg_Message, OnBrowserMessage)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
return handled;
}
void AtomRenderFrameObserver::OnBrowserMessage(bool send_to_all,
const base::string16& channel,
const base::ListValue& args) {
blink::WebLocalFrame* frame = render_frame_->GetWebFrame();
if (!frame || !render_frame_->IsMainFrame())
return;
// Don't handle browser messages before document element is created.
// When we receive a message from the browser, we try to transfer it
// to a web page, and when we do that Blink creates an empty
// document element if it hasn't been created yet, and it makes our init
// script to run while `window.location` is still "about:blank".
blink::WebDocument document = frame->GetDocument();
blink::WebElement html_element = document.DocumentElement();
if (html_element.IsNull()) {
return;
}
EmitIPCEvent(frame, channel, args);
// Also send the message to all sub-frames.
if (send_to_all) {
for (blink::WebFrame* child = frame->FirstChild(); child;
child = child->NextSibling())
if (child->IsWebLocalFrame()) {
EmitIPCEvent(child->ToWebLocalFrame(), channel, args);
}
}
}
void AtomRenderFrameObserver::CreateIsolatedWorldContext() {
auto frame = render_frame_->GetWebFrame();

Просмотреть файл

@ -14,7 +14,8 @@ namespace atom {
AtomRenderViewObserver::AtomRenderViewObserver(content::RenderView* render_view)
: content::RenderViewObserver(render_view) {}
AtomRenderViewObserver::~AtomRenderViewObserver() {}
AtomRenderViewObserver::~AtomRenderViewObserver() {
}
bool AtomRenderViewObserver::OnMessageReceived(const IPC::Message& message) {
bool handled = true;