2014-04-24 08:45:25 +00:00
|
|
|
// Copyright (c) 2014 GitHub, Inc. All rights reserved.
|
2014-04-25 09:49:37 +00:00
|
|
|
// Use of this source code is governed by the MIT license that can be
|
2014-04-24 08:45:25 +00:00
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#ifndef ATOM_BROWSER_API_ATOM_API_WEB_CONTENTS_H_
|
|
|
|
#define ATOM_BROWSER_API_ATOM_API_WEB_CONTENTS_H_
|
|
|
|
|
|
|
|
#include "atom/browser/api/event_emitter.h"
|
2014-04-25 03:22:51 +00:00
|
|
|
#include "content/public/browser/web_contents_observer.h"
|
2014-04-24 08:45:25 +00:00
|
|
|
#include "native_mate/handle.h"
|
|
|
|
|
|
|
|
namespace atom {
|
|
|
|
|
|
|
|
namespace api {
|
|
|
|
|
2014-04-25 03:22:51 +00:00
|
|
|
class WebContents : public mate::EventEmitter,
|
|
|
|
public content::WebContentsObserver {
|
2014-04-24 08:45:25 +00:00
|
|
|
public:
|
|
|
|
static mate::Handle<WebContents> Create(v8::Isolate* isolate,
|
|
|
|
content::WebContents* web_contents);
|
|
|
|
|
2014-04-25 03:22:51 +00:00
|
|
|
bool IsAlive() const;
|
2014-04-25 04:52:30 +00:00
|
|
|
void LoadURL(const GURL& url);
|
2014-04-24 09:00:41 +00:00
|
|
|
GURL GetURL() const;
|
|
|
|
string16 GetTitle() const;
|
|
|
|
bool IsLoading() const;
|
|
|
|
bool IsWaitingForResponse() const;
|
|
|
|
void Stop();
|
2014-04-25 04:52:30 +00:00
|
|
|
void Reload();
|
|
|
|
void ReloadIgnoringCache();
|
|
|
|
bool CanGoBack() const;
|
|
|
|
bool CanGoForward() const;
|
|
|
|
bool CanGoToOffset(int offset) const;
|
|
|
|
void GoBack();
|
|
|
|
void GoForward();
|
|
|
|
void GoToIndex(int index);
|
|
|
|
void GoToOffset(int offset);
|
2014-04-24 09:00:41 +00:00
|
|
|
int GetRoutingID() const;
|
|
|
|
int GetProcessID() const;
|
|
|
|
bool IsCrashed() const;
|
2014-04-25 02:34:40 +00:00
|
|
|
void ExecuteJavaScript(const string16& code);
|
2014-04-25 05:10:16 +00:00
|
|
|
bool SendIPCMessage(const string16& channel, const base::ListValue& args);
|
2014-04-24 09:00:41 +00:00
|
|
|
|
2014-04-24 08:45:25 +00:00
|
|
|
protected:
|
|
|
|
explicit WebContents(content::WebContents* web_contents);
|
|
|
|
|
|
|
|
// mate::Wrappable implementations:
|
|
|
|
virtual mate::ObjectTemplateBuilder GetObjectTemplateBuilder(
|
2014-04-25 03:22:51 +00:00
|
|
|
v8::Isolate* isolate) OVERRIDE;
|
|
|
|
|
|
|
|
// content::WebContentsObserver implementations:
|
2014-04-25 03:51:05 +00:00
|
|
|
virtual void RenderViewDeleted(content::RenderViewHost*) OVERRIDE;
|
|
|
|
virtual void RenderProcessGone(base::TerminationStatus status) OVERRIDE;
|
2014-04-25 04:22:16 +00:00
|
|
|
virtual void DidFinishLoad(
|
|
|
|
int64 frame_id,
|
|
|
|
const GURL& validated_url,
|
|
|
|
bool is_main_frame,
|
|
|
|
content::RenderViewHost* render_view_host) OVERRIDE;
|
|
|
|
virtual void DidStartLoading(
|
|
|
|
content::RenderViewHost* render_view_host) OVERRIDE;
|
|
|
|
virtual void DidStopLoading(
|
|
|
|
content::RenderViewHost* render_view_host) OVERRIDE;
|
2014-04-25 08:13:16 +00:00
|
|
|
virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
|
2014-04-25 03:22:51 +00:00
|
|
|
virtual void WebContentsDestroyed(content::WebContents*) OVERRIDE;
|
2014-04-24 08:45:25 +00:00
|
|
|
|
|
|
|
private:
|
2014-04-25 08:13:16 +00:00
|
|
|
// Called when received a message from renderer.
|
|
|
|
void OnRendererMessage(const string16& channel, const base::ListValue& args);
|
|
|
|
|
|
|
|
// Called when received a synchronous message from renderer.
|
|
|
|
void OnRendererMessageSync(const string16& channel,
|
|
|
|
const base::ListValue& args,
|
|
|
|
IPC::Message* message);
|
|
|
|
|
2014-04-24 08:45:25 +00:00
|
|
|
content::WebContents* web_contents_; // Weak.
|
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(WebContents);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace api
|
|
|
|
|
|
|
|
} // namespace atom
|
|
|
|
|
|
|
|
#endif // ATOM_BROWSER_API_ATOM_API_WEB_CONTENTS_H_
|