REVIEW: move ipc use from rvh to rfh
This commit is contained in:
parent
b552ad7065
commit
5684f8886f
7 changed files with 62 additions and 39 deletions
|
@ -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 WebContents::OnMessageReceived(const IPC::Message& message) {
|
||||||
bool handled = true;
|
bool handled = true;
|
||||||
IPC_BEGIN_MESSAGE_MAP(WebContents, message)
|
IPC_BEGIN_MESSAGE_MAP(WebContents, message)
|
||||||
|
@ -1542,10 +1533,10 @@ void WebContents::TabTraverse(bool reverse) {
|
||||||
bool WebContents::SendIPCMessage(bool all_frames,
|
bool WebContents::SendIPCMessage(bool all_frames,
|
||||||
const base::string16& channel,
|
const base::string16& channel,
|
||||||
const base::ListValue& args) {
|
const base::ListValue& args) {
|
||||||
auto host = web_contents()->GetRenderViewHost();
|
auto frame_host = web_contents()->GetMainFrame();
|
||||||
if (host) {
|
if (frame_host) {
|
||||||
return host->Send(new AtomViewMsg_Message(host->GetRoutingID(),
|
return frame_host->Send(new AtomFrameMsg_Message(
|
||||||
all_frames, channel, args));
|
frame_host->GetRoutingID(), all_frames, channel, args));
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -1836,18 +1827,15 @@ void WebContents::OnSetTemporaryZoomLevel(content::RenderFrameHost* rfh,
|
||||||
IPC::Message* reply_msg) {
|
IPC::Message* reply_msg) {
|
||||||
zoom_controller_->SetTemporaryZoomLevel(level);
|
zoom_controller_->SetTemporaryZoomLevel(level);
|
||||||
double new_level = zoom_controller_->GetZoomLevel();
|
double new_level = zoom_controller_->GetZoomLevel();
|
||||||
AtomViewHostMsg_SetTemporaryZoomLevel::WriteReplyParams(reply_msg, new_level);
|
AtomFrameHostMsg_SetTemporaryZoomLevel::WriteReplyParams(reply_msg,
|
||||||
|
new_level);
|
||||||
auto host = web_contents()->GetRenderViewHost();
|
rfh->Send(reply_msg);
|
||||||
if (host)
|
|
||||||
host->Send(reply_msg);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebContents::OnGetZoomLevel(IPC::Message* reply_msg) {
|
void WebContents::OnGetZoomLevel(content::RenderFrameHost* rfh,
|
||||||
AtomViewHostMsg_GetZoomLevel::WriteReplyParams(reply_msg, GetZoomLevel());
|
IPC::Message* reply_msg) {
|
||||||
auto host = web_contents()->GetRenderViewHost();
|
AtomFrameHostMsg_GetZoomLevel::WriteReplyParams(reply_msg, GetZoomLevel());
|
||||||
if (host)
|
rfh->Send(reply_msg);
|
||||||
host->Send(reply_msg);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
v8::Local<v8::Value> WebContents::GetWebPreferences(v8::Isolate* isolate) {
|
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 AddWorkSpace(mate::Arguments* args, const base::FilePath& path);
|
||||||
void RemoveWorkSpace(mate::Arguments* args, const base::FilePath& path);
|
void RemoveWorkSpace(mate::Arguments* args, const base::FilePath& path);
|
||||||
|
|
||||||
// IPC
|
|
||||||
bool Send(IPC::Message* message);
|
|
||||||
|
|
||||||
// Editing commands.
|
// Editing commands.
|
||||||
void Undo();
|
void Undo();
|
||||||
void Redo();
|
void Redo();
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
#include "atom/common/api/api_messages.h"
|
#include "atom/common/api/api_messages.h"
|
||||||
#include "atom/common/native_mate_converters/string16_converter.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 "content/public/browser/web_contents.h"
|
||||||
#include "native_mate/object_template_builder.h"
|
#include "native_mate/object_template_builder.h"
|
||||||
|
|
||||||
|
@ -60,10 +60,8 @@ bool Event::SendReply(const base::string16& json) {
|
||||||
if (message_ == nullptr || sender_ == nullptr)
|
if (message_ == nullptr || sender_ == nullptr)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
AtomViewHostMsg_Message_Sync::WriteReplyParams(message_, json);
|
AtomFrameHostMsg_Message_Sync::WriteReplyParams(message_, json);
|
||||||
auto host = sender_->GetRenderViewHost();
|
bool success = sender_->Send(message_);
|
||||||
if (!host) return false;
|
|
||||||
bool success = host->Send(message_);
|
|
||||||
message_ = nullptr;
|
message_ = nullptr;
|
||||||
sender_ = nullptr;
|
sender_ = nullptr;
|
||||||
return success;
|
return success;
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
#include "atom/common/api/api_messages.h"
|
#include "atom/common/api/api_messages.h"
|
||||||
#include "base/strings/utf_string_conversions.h"
|
#include "base/strings/utf_string_conversions.h"
|
||||||
#include "base/values.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"
|
#include "content/public/browser/web_contents.h"
|
||||||
|
|
||||||
namespace atom {
|
namespace atom {
|
||||||
|
@ -37,10 +37,10 @@ void RemoteCallbackFreer::RunDestructor() {
|
||||||
base::ASCIIToUTF16("ELECTRON_RENDERER_RELEASE_CALLBACK");
|
base::ASCIIToUTF16("ELECTRON_RENDERER_RELEASE_CALLBACK");
|
||||||
base::ListValue args;
|
base::ListValue args;
|
||||||
args.AppendInteger(object_id_);
|
args.AppendInteger(object_id_);
|
||||||
auto host = web_contents()->GetRenderViewHost();
|
auto frame_host = web_contents()->GetMainFrame();
|
||||||
if (host) {
|
if (frame_host) {
|
||||||
host->Send(new AtomViewMsg_Message(
|
frame_host->Send(new AtomFrameMsg_Message(frame_host->GetRoutingID(), false,
|
||||||
host->GetRoutingID(), false, channel, args));
|
channel, args));
|
||||||
}
|
}
|
||||||
|
|
||||||
Observe(nullptr);
|
Observe(nullptr);
|
||||||
|
|
|
@ -10,7 +10,6 @@
|
||||||
#include "content/public/renderer/render_frame.h"
|
#include "content/public/renderer/render_frame.h"
|
||||||
#include "native_mate/dictionary.h"
|
#include "native_mate/dictionary.h"
|
||||||
#include "third_party/WebKit/public/web/WebLocalFrame.h"
|
#include "third_party/WebKit/public/web/WebLocalFrame.h"
|
||||||
#include "third_party/WebKit/public/web/WebView.h"
|
|
||||||
|
|
||||||
using content::RenderFrame;
|
using content::RenderFrame;
|
||||||
using blink::WebLocalFrame;
|
using blink::WebLocalFrame;
|
||||||
|
|
|
@ -7,8 +7,8 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#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/native_mate_converters/string16_converter.h"
|
||||||
|
|
||||||
#include "atom/common/api/api_messages.h"
|
#include "atom/common/api/api_messages.h"
|
||||||
#include "atom/common/api/event_emitter_caller.h"
|
#include "atom/common/api/event_emitter_caller.h"
|
||||||
#include "atom/common/native_mate_converters/value_converter.h"
|
#include "atom/common/native_mate_converters/value_converter.h"
|
||||||
|
@ -127,6 +127,46 @@ void AtomRenderFrameObserver::OnDestruct() {
|
||||||
delete this;
|
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() {
|
void AtomRenderFrameObserver::CreateIsolatedWorldContext() {
|
||||||
auto frame = render_frame_->GetWebFrame();
|
auto frame = render_frame_->GetWebFrame();
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,8 @@ namespace atom {
|
||||||
AtomRenderViewObserver::AtomRenderViewObserver(content::RenderView* render_view)
|
AtomRenderViewObserver::AtomRenderViewObserver(content::RenderView* render_view)
|
||||||
: content::RenderViewObserver(render_view) {}
|
: content::RenderViewObserver(render_view) {}
|
||||||
|
|
||||||
AtomRenderViewObserver::~AtomRenderViewObserver() {}
|
AtomRenderViewObserver::~AtomRenderViewObserver() {
|
||||||
|
}
|
||||||
|
|
||||||
bool AtomRenderViewObserver::OnMessageReceived(const IPC::Message& message) {
|
bool AtomRenderViewObserver::OnMessageReceived(const IPC::Message& message) {
|
||||||
bool handled = true;
|
bool handled = true;
|
||||||
|
|
Loading…
Reference in a new issue