]> khamidou — GitHub mirrors - electron.git/commitdiff
Move navigator related APIs to webContents.
authorCheng Zhao <zcbenz@gmail.com>
Fri, 25 Apr 2014 04:52:30 +0000 (12:52 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Fri, 25 Apr 2014 04:52:30 +0000 (12:52 +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 26fd3eee418ed832cd944c0c35cecfebc8b5ae8a..1548cf3e0954957a386072570b5a7bfbcb984b61 100644 (file)
@@ -62,6 +62,13 @@ bool WebContents::IsAlive() const {
   return web_contents_ != NULL;
 }
 
+void WebContents::LoadURL(const GURL& url) {
+  content::NavigationController::LoadURLParams params(url);
+  params.transition_type = content::PAGE_TRANSITION_TYPED;
+  params.override_user_agent = content::NavigationController::UA_OVERRIDE_TRUE;
+  web_contents_->GetController().LoadURLWithParams(params);
+}
+
 GURL WebContents::GetURL() const {
   return web_contents_->GetURL();
 }
@@ -82,6 +89,42 @@ void WebContents::Stop() {
   web_contents_->Stop();
 }
 
+void WebContents::Reload() {
+  web_contents_->GetController().Reload(false);
+}
+
+void WebContents::ReloadIgnoringCache() {
+  web_contents_->GetController().ReloadIgnoringCache(false);
+}
+
+bool WebContents::CanGoBack() const {
+  return web_contents_->GetController().CanGoBack();
+}
+
+bool WebContents::CanGoForward() const {
+  return web_contents_->GetController().CanGoForward();
+}
+
+bool WebContents::CanGoToOffset(int offset) const {
+  return web_contents_->GetController().CanGoToOffset(offset);
+}
+
+void WebContents::GoBack() {
+  web_contents_->GetController().GoBack();
+}
+
+void WebContents::GoForward() {
+  web_contents_->GetController().GoForward();
+}
+
+void WebContents::GoToIndex(int index) {
+  web_contents_->GetController().GoToIndex(index);
+}
+
+void WebContents::GoToOffset(int offset) {
+  web_contents_->GetController().GoToOffset(offset);
+}
+
 int WebContents::GetRoutingID() const {
   return web_contents_->GetRoutingID();
 }
@@ -103,11 +146,21 @@ mate::ObjectTemplateBuilder WebContents::GetObjectTemplateBuilder(
     v8::Isolate* isolate) {
   return mate::ObjectTemplateBuilder(isolate)
       .SetMethod("isAlive", &WebContents::IsAlive)
+      .SetMethod("loadUrl", &WebContents::LoadURL)
       .SetMethod("getUrl", &WebContents::GetURL)
       .SetMethod("getTitle", &WebContents::GetTitle)
       .SetMethod("isLoading", &WebContents::IsLoading)
       .SetMethod("isWaitingForResponse", &WebContents::IsWaitingForResponse)
       .SetMethod("stop", &WebContents::Stop)
+      .SetMethod("reload", &WebContents::Reload)
+      .SetMethod("reloadIgnoringCache", &WebContents::ReloadIgnoringCache)
+      .SetMethod("canGoBack", &WebContents::CanGoBack)
+      .SetMethod("canGoForward", &WebContents::CanGoForward)
+      .SetMethod("canGoToOffset", &WebContents::CanGoToOffset)
+      .SetMethod("goBack", &WebContents::GoBack)
+      .SetMethod("goForward", &WebContents::GoForward)
+      .SetMethod("goToIndex", &WebContents::GoToIndex)
+      .SetMethod("goToOffset", &WebContents::GoToOffset)
       .SetMethod("getRoutingId", &WebContents::GetRoutingID)
       .SetMethod("getProcessId", &WebContents::GetProcessID)
       .SetMethod("isCrashed", &WebContents::IsCrashed)
index 5bdf3c0d645c11c231135ad43249644279c4b710..13e229db123fa04c38d2c866f5d1ed326d7d97c8 100644 (file)
@@ -20,11 +20,21 @@ class WebContents : public mate::EventEmitter,
                                           content::WebContents* web_contents);
 
   bool IsAlive() const;
+  void LoadURL(const GURL& url);
   GURL GetURL() const;
   string16 GetTitle() const;
   bool IsLoading() const;
   bool IsWaitingForResponse() const;
   void Stop();
+  void Reload();
+  void ReloadIgnoringCache();
+  bool CanGoBack() const;
+  bool CanGoForward() const;
+  bool CanGoToOffset(int offset) const;
+  void GoBack();
+  void GoForward();
+  void GoToIndex(int index);
+  void GoToOffset(int offset);
   int GetRoutingID() const;
   int GetProcessID() const;
   bool IsCrashed() const;
index 482382f230fcf3092e61c9f846e5925bc705e164..dae2abb93ebf9a76eab7a22bfb7675f990c730f8 100644 (file)
@@ -7,13 +7,9 @@
 #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"
-#include "atom/common/native_mate_converters/string16_converter.h"
 #include "atom/common/native_mate_converters/value_converter.h"
 #include "base/bind.h"
 #include "base/callback.h"
-#include "content/public/browser/navigation_entry.h"
-#include "content/public/browser/web_contents.h"
 #include "content/public/browser/render_process_host.h"
 #include "native_mate/constructor.h"
 #include "native_mate/dictionary.h"
@@ -23,8 +19,6 @@
 
 #include "atom/common/node_includes.h"
 
-using content::NavigationController;
-
 namespace mate {
 
 template<>
@@ -319,51 +313,6 @@ mate::Handle<WebContents> Window::GetDevToolsWebContents(
   return WebContents::Create(isolate, window_->GetDevToolsWebContents());
 }
 
-void Window::LoadURL(const GURL& url) {
-  NavigationController& controller = window_->GetWebContents()->GetController();
-
-  content::NavigationController::LoadURLParams params(url);
-  params.transition_type = content::PAGE_TRANSITION_TYPED;
-  params.override_user_agent = content::NavigationController::UA_OVERRIDE_TRUE;
-  controller.LoadURLWithParams(params);
-}
-
-bool Window::CanGoBack() {
-  return window_->GetWebContents()->GetController().CanGoBack();
-}
-
-bool Window::CanGoForward() {
-  return window_->GetWebContents()->GetController().CanGoForward();
-}
-
-bool Window::CanGoToOffset(int offset) {
-  return window_->GetWebContents()->GetController().CanGoToOffset(offset);
-}
-
-void Window::GoBack() {
-  window_->GetWebContents()->GetController().GoBack();
-}
-
-void Window::GoForward() {
-  window_->GetWebContents()->GetController().GoForward();
-}
-
-void Window::GoToIndex(int index) {
-  window_->GetWebContents()->GetController().GoToIndex(index);
-}
-
-void Window::GoToOffset(int offset) {
-  window_->GetWebContents()->GetController().GoToOffset(offset);
-}
-
-void Window::Reload() {
-  window_->GetWebContents()->GetController().Reload(false);
-}
-
-void Window::ReloadIgnoringCache() {
-  window_->GetWebContents()->GetController().ReloadIgnoringCache(false);
-}
-
 // static
 void Window::BuildPrototype(v8::Isolate* isolate,
                             v8::Handle<v8::ObjectTemplate> prototype) {
@@ -409,17 +358,7 @@ void Window::BuildPrototype(v8::Isolate* isolate,
       .SetMethod("isWebViewFocused", &Window::IsWebViewFocused)
       .SetMethod("capturePage", &Window::CapturePage)
       .SetMethod("_getWebContents", &Window::GetWebContents)
-      .SetMethod("_getDevToolsWebContents", &Window::GetDevToolsWebContents)
-      .SetMethod("loadUrl", &Window::LoadURL)
-      .SetMethod("canGoBack", &Window::CanGoBack)
-      .SetMethod("canGoForward", &Window::CanGoForward)
-      .SetMethod("canGoToOffset", &Window::CanGoToOffset)
-      .SetMethod("goBack", &Window::GoBack)
-      .SetMethod("goForward", &Window::GoForward)
-      .SetMethod("goToIndex", &Window::GoToIndex)
-      .SetMethod("goToOffset", &Window::GoToOffset)
-      .SetMethod("reload", &Window::Reload)
-      .SetMethod("reloadIgnoringCache", &Window::ReloadIgnoringCache);
+      .SetMethod("_getDevToolsWebContents", &Window::GetDevToolsWebContents);
 }
 
 }  // namespace api
index e406e83c0a7374fcfb4d0c450188b3db0594bd4e..4d762bee90b353efd1e384eb71a2545844dd2f8e 100644 (file)
@@ -103,18 +103,6 @@ class Window : public mate::EventEmitter,
   mate::Handle<WebContents> GetWebContents(v8::Isolate* isolate) const;
   mate::Handle<WebContents> GetDevToolsWebContents(v8::Isolate* isolate) const;
 
-  // APIs for NavigationController.
-  void LoadURL(const GURL& url);
-  bool CanGoBack();
-  bool CanGoForward();
-  bool CanGoToOffset(int offset);
-  void GoBack();
-  void GoForward();
-  void GoToIndex(int index);
-  void GoToOffset(int offset);
-  void Reload();
-  void ReloadIgnoringCache();
-
   scoped_ptr<NativeWindow> window_;
 
   DISALLOW_COPY_AND_ASSIGN(Window);
index c357078a9c104da64fa2553231d026f01caae835..df2c5393d13146cacbc49fa800e029d68376a900 100644 (file)
@@ -88,7 +88,10 @@ BrowserWindow.fromDevTools = (processId, routingId) ->
                      devtools.routingId == routingId
 
 # Be compatible with old API.
+BrowserWindow::loadUrl = (url) -> @webContents.loadUrl(url)
 BrowserWindow::getUrl = -> @webContents.getUrl()
+BrowserWindow::reload = -> @webContents.reload()
+BrowserWindow::reloadIgnoringCache = -> @webContents.reloadIgnoringCache()
 BrowserWindow::getPageTitle = -> @webContents.getTitle()
 BrowserWindow::isLoading = -> @webContents.isLoading()
 BrowserWindow::isWaitingForResponse = -> @webContents.isWaitingForResponse()