#include "atom/browser/api/atom_api_web_contents.h"
+#include "atom/common/native_mate_converters/gurl_converter.h"
+#include "atom/common/native_mate_converters/string16_converter.h"
+#include "content/public/browser/render_process_host.h"
#include "content/public/browser/web_contents.h"
#include "native_mate/object_template_builder.h"
WebContents::~WebContents() {
}
+GURL WebContents::GetURL() const {
+ return web_contents_->GetURL();
+}
+
+string16 WebContents::GetTitle() const {
+ return web_contents_->GetTitle();
+}
+
+bool WebContents::IsLoading() const {
+ return web_contents_->IsLoading();
+}
+
+bool WebContents::IsWaitingForResponse() const {
+ return web_contents_->IsWaitingForResponse();
+}
+
+void WebContents::Stop() {
+ web_contents_->Stop();
+}
+
+int WebContents::GetRoutingID() const {
+ return web_contents_->GetRoutingID();
+}
+
+int WebContents::GetProcessID() const {
+ return web_contents_->GetRenderProcessHost()->GetID();
+}
+
+bool WebContents::IsCrashed() const {
+ return web_contents_->IsCrashed();
+}
+
mate::ObjectTemplateBuilder WebContents::GetObjectTemplateBuilder(
v8::Isolate* isolate) {
- return mate::ObjectTemplateBuilder(isolate);
+ return mate::ObjectTemplateBuilder(isolate)
+ .SetMethod("getUrl", &WebContents::GetURL)
+ .SetMethod("getTitle", &WebContents::GetTitle)
+ .SetMethod("isLoading", &WebContents::IsLoading)
+ .SetMethod("isWaitingForResponse", &WebContents::IsWaitingForResponse)
+ .SetMethod("stop", &WebContents::Stop)
+ .SetMethod("getRoutingId", &WebContents::GetRoutingID)
+ .SetMethod("getProcessId", &WebContents::GetProcessID)
+ .SetMethod("isCrashed", &WebContents::IsCrashed);
}
// static
#include "atom/browser/api/event_emitter.h"
#include "native_mate/handle.h"
+class GURL;
+
namespace content {
class WebContents;
}
static mate::Handle<WebContents> Create(v8::Isolate* isolate,
content::WebContents* web_contents);
+ GURL GetURL() const;
+ string16 GetTitle() const;
+ bool IsLoading() const;
+ bool IsWaitingForResponse() const;
+ void Stop();
+ int GetRoutingID() const;
+ int GetProcessID() const;
+ bool IsCrashed() const;
+
protected:
explicit WebContents(content::WebContents* web_contents);
virtual ~WebContents();
return WebContents::Create(isolate, window_->GetDevToolsWebContents());
}
-string16 Window::GetPageTitle() {
- return window_->GetWebContents()->GetTitle();
-}
-
-bool Window::IsLoading() {
- return window_->GetWebContents()->IsLoading();
-}
-
-bool Window::IsWaitingForResponse() {
- return window_->GetWebContents()->IsWaitingForResponse();
-}
-
-void Window::Stop() {
- window_->GetWebContents()->Stop();
-}
-
-int Window::GetRoutingID() {
- return window_->GetWebContents()->GetRoutingID();
-}
-
-int Window::GetProcessID() {
- return window_->GetWebContents()->GetRenderProcessHost()->GetID();
-}
-
-bool Window::IsCrashed() {
- return window_->GetWebContents()->IsCrashed();
-}
-
mate::Dictionary Window::GetDevTools(v8::Isolate* isolate) {
mate::Dictionary dict(mate::Dictionary::CreateEmpty(isolate));
content::WebContents* web_contents = window_->GetDevToolsWebContents();
controller.LoadURLWithParams(params);
}
-GURL Window::GetURL() {
- NavigationController& controller = window_->GetWebContents()->GetController();
- if (!controller.GetActiveEntry())
- return GURL();
- return controller.GetActiveEntry()->GetVirtualURL();
-}
-
bool Window::CanGoBack() {
return window_->GetWebContents()->GetController().CanGoBack();
}
.SetMethod("capturePage", &Window::CapturePage)
.SetMethod("getWebContents", &Window::GetWebContents)
.SetMethod("getDevToolsWebContents", &Window::GetDevToolsWebContents)
- .SetMethod("getPageTitle", &Window::GetPageTitle)
- .SetMethod("isLoading", &Window::IsLoading)
- .SetMethod("isWaitingForResponse", &Window::IsWaitingForResponse)
- .SetMethod("stop", &Window::Stop)
- .SetMethod("getRoutingId", &Window::GetRoutingID)
- .SetMethod("getProcessId", &Window::GetProcessID)
- .SetMethod("isCrashed", &Window::IsCrashed)
.SetMethod("getDevTools", &Window::GetDevTools)
.SetMethod("executeJavaScriptInDevTools",
&Window::ExecuteJavaScriptInDevTools)
.SetMethod("loadUrl", &Window::LoadURL)
- .SetMethod("getUrl", &Window::GetURL)
.SetMethod("canGoBack", &Window::CanGoBack)
.SetMethod("canGoForward", &Window::CanGoForward)
.SetMethod("canGoToOffset", &Window::CanGoToOffset)
// APIs for WebContents.
mate::Handle<WebContents> GetWebContents(v8::Isolate* isolate) const;
mate::Handle<WebContents> GetDevToolsWebContents(v8::Isolate* isolate) const;
- string16 GetPageTitle();
- bool IsLoading();
- bool IsWaitingForResponse();
- void Stop();
- int GetRoutingID();
- int GetProcessID();
- bool IsCrashed();
// APIs for devtools.
mate::Dictionary GetDevTools(v8::Isolate* isolate);
// APIs for NavigationController.
void LoadURL(const GURL& url);
- GURL GetURL();
bool CanGoBack();
bool CanGoForward();
bool CanGoToOffset(int offset);
menu = app.getApplicationMenu()
@setMenu menu if menu?
+ @webContents = @getWebContents()
+
# Remember the window.
id = BrowserWindow.windows.add this
return window if devtools.processId == processId and
devtools.routingId == routingId
+# Be compatible with old API.
+BrowserWindow::getUrl = -> @webContents.getUrl()
+BrowserWindow::getPageTitle = -> @webContents.getTitle()
+BrowserWindow::isLoading = -> @webContents.isLoading()
+BrowserWindow::isWaitingForResponse = -> @webContents.isWaitingForResponse()
+BrowserWindow::stop = -> @webContents.stop()
+BrowserWindow::getRoutingId = -> @webContents.getRoutingId()
+BrowserWindow::getProcessId = -> @webContents.getProcessId()
+BrowserWindow::isCrashed = -> @webContents.isCrashed()
+
module.exports = BrowserWindow