]> khamidou — GitHub mirrors - electron.git/commitdiff
Initial empty api_web_contents.
authorCheng Zhao <zcbenz@gmail.com>
Thu, 24 Apr 2014 08:45:25 +0000 (16:45 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Thu, 24 Apr 2014 08:45:25 +0000 (16:45 +0800)
atom.gyp
atom/browser/api/atom_api_web_contents.cc [new file with mode: 0644]
atom/browser/api/atom_api_web_contents.h [new file with mode: 0644]
atom/browser/api/atom_api_window.cc
atom/browser/api/atom_api_window.h

index a56ae6139a4c5992876981c93ff1f2d2bb46af89..fb1b7e79ff4de4bd7a0c04d7592e24e4dbc85cba 100644 (file)
--- 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 (file)
index 0000000..47925db
--- /dev/null
@@ -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
diff --git a/atom/browser/api/atom_api_web_contents.h b/atom/browser/api/atom_api_web_contents.h
new file mode 100644 (file)
index 0000000..5cad17d
--- /dev/null
@@ -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_
index c30db210593d02076d4957cf515614446c167942..e17e3b3e7b22ac903eb118e4b191d80756123dce 100644 (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)
index d9663231a9e0a9abef06234836cf3bf47047d7e1..cd3b13e86a36eacbd4e4420bc51ce8ed9c28bc8d 100644 (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();