Initial empty api_web_contents.

This commit is contained in:
Cheng Zhao 2014-04-24 16:45:25 +08:00
parent 486dd9edfa
commit 26e93e8798
5 changed files with 95 additions and 0 deletions

View file

@ -62,6 +62,8 @@
'atom/browser/api/atom_api_power_monitor.h',
'atom/browser/api/atom_api_protocol.cc',
'atom/browser/api/atom_api_protocol.h',
'atom/browser/api/atom_api_web_contents.cc',
'atom/browser/api/atom_api_web_contents.h',
'atom/browser/api/atom_api_window.cc',
'atom/browser/api/atom_api_window.h',
'atom/browser/api/atom_browser_bindings.cc',

View file

@ -0,0 +1,34 @@
// Copyright (c) 2014 GitHub, Inc. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "atom/browser/api/atom_api_web_contents.h"
#include "content/public/browser/web_contents.h"
#include "native_mate/object_template_builder.h"
namespace atom {
namespace api {
WebContents::WebContents(content::WebContents* web_contents)
: web_contents_(web_contents) {
}
WebContents::~WebContents() {
}
mate::ObjectTemplateBuilder WebContents::GetObjectTemplateBuilder(
v8::Isolate* isolate) {
return mate::ObjectTemplateBuilder(isolate);
}
// static
mate::Handle<WebContents> WebContents::Create(
v8::Isolate* isolate, content::WebContents* web_contents) {
return CreateHandle(isolate, new WebContents(web_contents));
}
} // namespace api
} // namespace atom

View file

@ -0,0 +1,42 @@
// Copyright (c) 2014 GitHub, Inc. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// 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"
#include "native_mate/handle.h"
namespace content {
class WebContents;
}
namespace atom {
namespace api {
class WebContents : public mate::EventEmitter {
public:
static mate::Handle<WebContents> Create(v8::Isolate* isolate,
content::WebContents* web_contents);
protected:
explicit WebContents(content::WebContents* web_contents);
virtual ~WebContents();
// mate::Wrappable implementations:
virtual mate::ObjectTemplateBuilder GetObjectTemplateBuilder(
v8::Isolate* isolate);
private:
content::WebContents* web_contents_; // Weak.
DISALLOW_COPY_AND_ASSIGN(WebContents);
};
} // namespace api
} // namespace atom
#endif // ATOM_BROWSER_API_ATOM_API_WEB_CONTENTS_H_

View file

@ -4,6 +4,7 @@
#include "atom/browser/api/atom_api_window.h"
#include "atom/browser/api/atom_api_web_contents.h"
#include "atom/browser/native_window.h"
#include "atom/common/native_mate_converters/function_converter.h"
#include "atom/common/native_mate_converters/gurl_converter.h"
@ -326,6 +327,15 @@ void Window::CapturePage(mate::Arguments* args) {
window_->CapturePage(rect, base::Bind(&OnCapturePageDone, callback));
}
mate::Handle<WebContents> Window::GetWebContents(v8::Isolate* isolate) const {
return WebContents::Create(isolate, window_->GetWebContents());
}
mate::Handle<WebContents> Window::GetDevToolsWebContents(
v8::Isolate* isolate) const {
return WebContents::Create(isolate, window_->GetDevToolsWebContents());
}
string16 Window::GetPageTitle() {
return window_->GetWebContents()->GetTitle();
}
@ -462,6 +472,8 @@ void Window::BuildPrototype(v8::Isolate* isolate,
.SetMethod("blurWebView", &Window::BlurWebView)
.SetMethod("isWebViewFocused", &Window::IsWebViewFocused)
.SetMethod("capturePage", &Window::CapturePage)
.SetMethod("getWebContents", &Window::GetWebContents)
.SetMethod("getDevToolsWebContents", &Window::GetDevToolsWebContents)
.SetMethod("getPageTitle", &Window::GetPageTitle)
.SetMethod("isLoading", &Window::IsLoading)
.SetMethod("isWaitingForResponse", &Window::IsWaitingForResponse)

View file

@ -11,6 +11,7 @@
#include "base/memory/scoped_ptr.h"
#include "atom/browser/native_window_observer.h"
#include "atom/browser/api/event_emitter.h"
#include "native_mate/handle.h"
class GURL;
@ -29,6 +30,8 @@ class NativeWindow;
namespace api {
class WebContents;
class Window : public mate::EventEmitter,
public NativeWindowObserver {
public:
@ -100,6 +103,8 @@ class Window : public mate::EventEmitter,
void CapturePage(mate::Arguments* args);
// 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();