2017-03-31 13:01:33 +00:00
|
|
|
// Copyright (c) 2017 GitHub, Inc.
|
|
|
|
// Use of this source code is governed by the MIT license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#ifndef ATOM_RENDERER_ATOM_RENDER_FRAME_OBSERVER_H_
|
|
|
|
#define ATOM_RENDERER_ATOM_RENDER_FRAME_OBSERVER_H_
|
|
|
|
|
2018-08-24 15:30:37 +00:00
|
|
|
#include <string>
|
|
|
|
|
2017-04-08 14:27:19 +00:00
|
|
|
#include "atom/renderer/renderer_client_base.h"
|
2018-03-09 09:31:09 +00:00
|
|
|
#include "base/strings/string16.h"
|
2017-03-31 13:01:33 +00:00
|
|
|
#include "content/public/renderer/render_frame_observer.h"
|
2018-09-18 18:00:31 +00:00
|
|
|
#include "ipc/ipc_platform_file.h"
|
2019-03-11 23:27:57 +00:00
|
|
|
#include "third_party/blink/public/platform/web_isolated_world_ids.h"
|
2018-07-20 16:08:18 +00:00
|
|
|
#include "third_party/blink/public/web/web_local_frame.h"
|
2018-03-09 09:31:09 +00:00
|
|
|
|
|
|
|
namespace base {
|
|
|
|
class ListValue;
|
|
|
|
}
|
2017-03-31 13:01:33 +00:00
|
|
|
|
|
|
|
namespace atom {
|
|
|
|
|
|
|
|
enum World {
|
|
|
|
MAIN_WORLD = 0,
|
2019-03-11 23:27:57 +00:00
|
|
|
|
2017-03-31 13:01:33 +00:00
|
|
|
// Use a high number far away from 0 to not collide with any other world
|
|
|
|
// IDs created internally by Chrome.
|
2019-03-11 23:27:57 +00:00
|
|
|
ISOLATED_WORLD = 999,
|
|
|
|
|
|
|
|
// Numbers for isolated worlds for extensions are set in
|
|
|
|
// lib/renderer/content-script-injector.ts, and are greater than or equal to
|
|
|
|
// this number, up to ISOLATED_WORLD_EXTENSIONS_END.
|
|
|
|
ISOLATED_WORLD_EXTENSIONS = 1 << 20,
|
|
|
|
|
|
|
|
// Last valid isolated world ID.
|
|
|
|
ISOLATED_WORLD_EXTENSIONS_END =
|
|
|
|
blink::IsolatedWorldId::kEmbedderWorldIdLimit - 1
|
2017-03-31 13:01:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Helper class to forward the messages to the client.
|
|
|
|
class AtomRenderFrameObserver : public content::RenderFrameObserver {
|
|
|
|
public:
|
|
|
|
AtomRenderFrameObserver(content::RenderFrame* frame,
|
2017-04-08 14:27:19 +00:00
|
|
|
RendererClientBase* renderer_client);
|
2017-03-31 13:01:33 +00:00
|
|
|
|
|
|
|
// content::RenderFrameObserver:
|
|
|
|
void DidClearWindowObject() override;
|
|
|
|
void DidCreateScriptContext(v8::Handle<v8::Context> context,
|
|
|
|
int world_id) override;
|
2017-08-31 16:51:40 +00:00
|
|
|
void DraggableRegionsChanged() override;
|
2017-03-31 13:01:33 +00:00
|
|
|
void WillReleaseScriptContext(v8::Local<v8::Context> context,
|
|
|
|
int world_id) override;
|
|
|
|
void OnDestruct() override;
|
2018-03-09 03:22:44 +00:00
|
|
|
bool OnMessageReceived(const IPC::Message& message) override;
|
|
|
|
void DidCreateDocumentElement() override;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual void EmitIPCEvent(blink::WebLocalFrame* frame,
|
2018-10-06 11:48:00 +00:00
|
|
|
bool internal,
|
2018-08-24 15:30:37 +00:00
|
|
|
const std::string& channel,
|
2018-09-01 01:13:51 +00:00
|
|
|
const base::ListValue& args,
|
|
|
|
int32_t sender_id);
|
2017-03-31 13:01:33 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
bool ShouldNotifyClient(int world_id);
|
|
|
|
void CreateIsolatedWorldContext();
|
|
|
|
bool IsMainWorld(int world_id);
|
|
|
|
bool IsIsolatedWorld(int world_id);
|
2018-10-06 11:48:00 +00:00
|
|
|
void OnBrowserMessage(bool internal,
|
|
|
|
bool send_to_all,
|
2018-08-24 15:30:37 +00:00
|
|
|
const std::string& channel,
|
2018-09-01 01:13:51 +00:00
|
|
|
const base::ListValue& args,
|
|
|
|
int32_t sender_id);
|
2018-09-18 18:00:31 +00:00
|
|
|
void OnTakeHeapSnapshot(IPC::PlatformFileForTransit file_handle,
|
|
|
|
const std::string& channel);
|
2018-03-09 03:22:44 +00:00
|
|
|
|
2017-03-31 13:01:33 +00:00
|
|
|
content::RenderFrame* render_frame_;
|
2017-04-08 14:27:19 +00:00
|
|
|
RendererClientBase* renderer_client_;
|
2018-05-21 22:18:38 +00:00
|
|
|
bool document_created_ = false;
|
2017-03-31 13:01:33 +00:00
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(AtomRenderFrameObserver);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace atom
|
|
|
|
|
|
|
|
#endif // ATOM_RENDERER_ATOM_RENDER_FRAME_OBSERVER_H_
|