diff --git a/atom.gyp b/atom.gyp index a56ae6139a4c..fb1b7e79ff4d 100644 --- a/atom.gyp +++ b/atom.gyp @@ -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', diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc new file mode 100644 index 000000000000..47925db1f131 --- /dev/null +++ b/atom/browser/api/atom_api_web_contents.cc @@ -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::Create( + v8::Isolate* isolate, content::WebContents* web_contents) { + return CreateHandle(isolate, new WebContents(web_contents)); +} + +} // namespace api + +} // namespace atom diff --git a/atom/browser/api/atom_api_web_contents.h b/atom/browser/api/atom_api_web_contents.h new file mode 100644 index 000000000000..5cad17da7772 --- /dev/null +++ b/atom/browser/api/atom_api_web_contents.h @@ -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 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_ diff --git a/atom/browser/api/atom_api_window.cc b/atom/browser/api/atom_api_window.cc index c30db210593d..e17e3b3e7b22 100644 --- a/atom/browser/api/atom_api_window.cc +++ b/atom/browser/api/atom_api_window.cc @@ -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 Window::GetWebContents(v8::Isolate* isolate) const { + return WebContents::Create(isolate, window_->GetWebContents()); +} + +mate::Handle 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) diff --git a/atom/browser/api/atom_api_window.h b/atom/browser/api/atom_api_window.h index d9663231a9e0..cd3b13e86a36 100644 --- a/atom/browser/api/atom_api_window.h +++ b/atom/browser/api/atom_api_window.h @@ -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 GetWebContents(v8::Isolate* isolate) const; + mate::Handle GetDevToolsWebContents(v8::Isolate* isolate) const; string16 GetPageTitle(); bool IsLoading(); bool IsWaitingForResponse();