Move navigator related APIs to webContents.
This commit is contained in:
parent
e70d195cde
commit
c8a82e6e50
5 changed files with 67 additions and 74 deletions
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in a new issue