1
// vim:expandtab:shiftwidth=2:tabstop=2:
2
// Copyright (C) 2013 Canonical Ltd.
4
// This library is free software; you can redistribute it and/or
5
// modify it under the terms of the GNU Lesser General Public
6
// License as published by the Free Software Foundation; either
7
// version 2.1 of the License, or (at your option) any later version.
9
// This library is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
// Lesser General Public License for more details.
14
// You should have received a copy of the GNU Lesser General Public
15
// License along with this library; if not, write to the Free Software
16
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
#include "oxide_web_view_host.h"
20
#include "base/logging.h"
21
#include "base/strings/utf_string_conversions.h"
22
#include "content/public/browser/invalidate_type.h"
23
#include "content/public/browser/browser_context.h"
24
#include "content/public/browser/navigation_controller.h"
25
#include "content/public/browser/web_contents.h"
26
#include "content/public/browser/web_contents_view.h"
28
#include "oxide_browser_context.h"
29
#include "oxide_browser_process_main.h"
33
void WebViewHost::NavigationStateChanged(const content::WebContents* source,
34
unsigned changed_flags) {
35
DCHECK_EQ(source, web_contents_.get());
37
if (changed_flags & content::INVALIDATE_TYPE_URL) {
41
if (changed_flags & content::INVALIDATE_TYPE_TITLE) {
45
if (changed_flags & content::INVALIDATE_TYPE_LOAD) {
49
if (changed_flags & (content::INVALIDATE_TYPE_URL |
50
content::INVALIDATE_TYPE_LOAD)) {
55
void WebViewHost::OnURLChanged() {}
56
void WebViewHost::OnTitleChanged() {}
57
void WebViewHost::OnLoadingChanged() {}
58
void WebViewHost::OnCommandsUpdated() {}
60
WebViewHost::WebViewHost() {}
62
bool WebViewHost::Init(bool incognito, const gfx::Size& initial_size) {
63
if (!BrowserProcessMain::Exists()) {
64
LOG(ERROR) << "Implementation needs to start the browser components first!";
68
content::WebContents::CreateParams params(
70
BrowserContext::GetInstance()->GetOffTheRecordContext() :
71
BrowserContext::GetInstance());
72
params.initial_size = initial_size;
73
web_contents_.reset(content::WebContents::Create(params));
75
LOG(ERROR) << "Failed to create WebContents";
79
web_contents_->SetDelegate(this);
80
Observe(web_contents_.get());
85
WebViewHost::~WebViewHost() {
87
web_contents_->SetDelegate(NULL);
91
const GURL& WebViewHost::GetURL() const {
92
return web_contents_->GetActiveURL();
95
void WebViewHost::SetURL(const GURL& url) {
96
content::NavigationController::LoadURLParams params(url);
97
web_contents_->GetController().LoadURLWithParams(params);
100
std::string WebViewHost::GetTitle() const {
101
return base::UTF16ToUTF8(web_contents_->GetTitle());
104
bool WebViewHost::CanGoBack() const {
105
return web_contents_->GetController().CanGoBack();
108
bool WebViewHost::CanGoForward() const {
109
return web_contents_->GetController().CanGoForward();
112
void WebViewHost::GoBack() {
113
web_contents_->GetController().GoBack();
116
void WebViewHost::GoForward() {
117
web_contents_->GetController().GoForward();
120
void WebViewHost::Stop() {
121
web_contents_->Stop();
124
void WebViewHost::Reload() {
125
web_contents_->GetController().Reload(true);
128
bool WebViewHost::IsIncognito() const {
129
return web_contents_->GetBrowserContext()->IsOffTheRecord();
132
bool WebViewHost::IsLoading() const {
133
return web_contents_->IsLoading();
136
void WebViewHost::UpdateSize(const gfx::Size& size) {
137
web_contents_->GetView()->SizeContents(size);
140
void WebViewHost::WasShown() {
141
web_contents_->WasShown();
144
void WebViewHost::WasHidden() {
145
web_contents_->WasHidden();