]> khamidou — GitHub mirrors - electron.git/commitdiff
Move some APIs from Window to WebContents.
authorCheng Zhao <zcbenz@gmail.com>
Thu, 24 Apr 2014 09:00:41 +0000 (17:00 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Thu, 24 Apr 2014 09:00:41 +0000 (17:00 +0800)
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/lib/browser-window.coffee

index 47925db1f1316911bec6b4851f5fec330aa1b2e8..37b81f4e4115e18107dd3cdc8b5af3a8b02ae606 100644 (file)
@@ -4,6 +4,9 @@
 
 #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"
 
@@ -18,9 +21,49 @@ WebContents::WebContents(content::WebContents* web_contents)
 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
index 5cad17da77729b7eb3dd808c61474b530c249937..8b8a5266d3d2951c23046df34c6d61bad6a31bea 100644 (file)
@@ -8,6 +8,8 @@
 #include "atom/browser/api/event_emitter.h"
 #include "native_mate/handle.h"
 
+class GURL;
+
 namespace content {
 class WebContents;
 }
@@ -21,6 +23,15 @@ class WebContents : public mate::EventEmitter {
   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();
index e17e3b3e7b22ac903eb118e4b191d80756123dce..ceb300b448bad371b45c06d589bb349a064ce9ca 100644 (file)
@@ -336,34 +336,6 @@ mate::Handle<WebContents> Window::GetDevToolsWebContents(
   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();
@@ -385,13 +357,6 @@ void Window::LoadURL(const GURL& url) {
   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();
 }
@@ -474,18 +439,10 @@ void Window::BuildPrototype(v8::Isolate* isolate,
       .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)
index cd3b13e86a36eacbd4e4420bc51ce8ed9c28bc8d..5c3927926bfeb820000165b6869c9dd83c0c2ad9 100644 (file)
@@ -105,13 +105,6 @@ class Window : public mate::EventEmitter,
   // 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);
@@ -119,7 +112,6 @@ class Window : public mate::EventEmitter,
 
   // APIs for NavigationController.
   void LoadURL(const GURL& url);
-  GURL GetURL();
   bool CanGoBack();
   bool CanGoForward();
   bool CanGoToOffset(int offset);
index 18dacbf2e6e7ef2eb66e30e01f30a493315bcfdf..eb3d01e73eda076a498c3ecae2d7a91b316274c2 100644 (file)
@@ -14,6 +14,8 @@ BrowserWindow::_init = ->
     menu = app.getApplicationMenu()
     @setMenu menu if menu?
 
+  @webContents = @getWebContents()
+
   # Remember the window.
   id = BrowserWindow.windows.add this
 
@@ -62,4 +64,14 @@ BrowserWindow.fromDevTools = (processId, routingId) ->
     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