~oxide-developers/oxide/1.2

« back to all changes in this revision

Viewing changes to oxide/browser/oxide_web_view_host.cc

  • Committer: Chris Coulson
  • Date: 2013-07-23 11:40:24 UTC
  • Revision ID: chris.coulson@canonical.com-20130723114024-p7z00cs9p0s5te6e
Initial import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// vim:expandtab:shiftwidth=2:tabstop=2:
 
2
// Copyright (C) 2013 Canonical Ltd.
 
3
 
 
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.
 
8
 
 
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.
 
13
 
 
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
 
17
 
 
18
#include "oxide_web_view_host.h"
 
19
 
 
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"
 
27
 
 
28
#include "oxide_browser_context.h"
 
29
#include "oxide_browser_process_main.h"
 
30
 
 
31
namespace oxide {
 
32
 
 
33
void WebViewHost::NavigationStateChanged(const content::WebContents* source,
 
34
                                         unsigned changed_flags) {
 
35
  DCHECK_EQ(source, web_contents_.get());
 
36
 
 
37
  if (changed_flags & content::INVALIDATE_TYPE_URL) {
 
38
    OnURLChanged();
 
39
  }
 
40
 
 
41
  if (changed_flags & content::INVALIDATE_TYPE_TITLE) {
 
42
    OnTitleChanged();
 
43
  }
 
44
 
 
45
  if (changed_flags & content::INVALIDATE_TYPE_LOAD) {
 
46
    OnLoadingChanged();
 
47
  }
 
48
 
 
49
  if (changed_flags & (content::INVALIDATE_TYPE_URL |
 
50
                       content::INVALIDATE_TYPE_LOAD)) {
 
51
    OnCommandsUpdated();
 
52
  }
 
53
}
 
54
 
 
55
void WebViewHost::OnURLChanged() {}
 
56
void WebViewHost::OnTitleChanged() {}
 
57
void WebViewHost::OnLoadingChanged() {}
 
58
void WebViewHost::OnCommandsUpdated() {}
 
59
 
 
60
WebViewHost::WebViewHost() {}
 
61
 
 
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!";
 
65
    return false;
 
66
  }
 
67
 
 
68
  content::WebContents::CreateParams params(
 
69
      incognito ?
 
70
        BrowserContext::GetInstance()->GetOffTheRecordContext() :
 
71
        BrowserContext::GetInstance());
 
72
  params.initial_size = initial_size;
 
73
  web_contents_.reset(content::WebContents::Create(params));
 
74
  if (!web_contents_) {
 
75
    LOG(ERROR) << "Failed to create WebContents";
 
76
    return false;
 
77
  }
 
78
 
 
79
  web_contents_->SetDelegate(this);
 
80
  Observe(web_contents_.get());
 
81
 
 
82
  return true;
 
83
}
 
84
 
 
85
WebViewHost::~WebViewHost() {
 
86
  if (web_contents_) {
 
87
    web_contents_->SetDelegate(NULL);
 
88
  }
 
89
}
 
90
 
 
91
const GURL& WebViewHost::GetURL() const {
 
92
  return web_contents_->GetActiveURL();
 
93
}
 
94
 
 
95
void WebViewHost::SetURL(const GURL& url) {
 
96
  content::NavigationController::LoadURLParams params(url);
 
97
  web_contents_->GetController().LoadURLWithParams(params);
 
98
}
 
99
 
 
100
std::string WebViewHost::GetTitle() const {
 
101
  return base::UTF16ToUTF8(web_contents_->GetTitle());
 
102
}
 
103
 
 
104
bool WebViewHost::CanGoBack() const {
 
105
  return web_contents_->GetController().CanGoBack();
 
106
}
 
107
 
 
108
bool WebViewHost::CanGoForward() const {
 
109
  return web_contents_->GetController().CanGoForward();
 
110
}
 
111
 
 
112
void WebViewHost::GoBack() {
 
113
  web_contents_->GetController().GoBack();
 
114
}
 
115
 
 
116
void WebViewHost::GoForward() {
 
117
  web_contents_->GetController().GoForward();
 
118
}
 
119
 
 
120
void WebViewHost::Stop() {
 
121
  web_contents_->Stop();
 
122
}
 
123
 
 
124
void WebViewHost::Reload() {
 
125
  web_contents_->GetController().Reload(true);
 
126
}
 
127
 
 
128
bool WebViewHost::IsIncognito() const {
 
129
  return web_contents_->GetBrowserContext()->IsOffTheRecord();
 
130
}
 
131
 
 
132
bool WebViewHost::IsLoading() const {
 
133
  return web_contents_->IsLoading();
 
134
}
 
135
 
 
136
void WebViewHost::UpdateSize(const gfx::Size& size) {
 
137
  web_contents_->GetView()->SizeContents(size);
 
138
}
 
139
 
 
140
void WebViewHost::WasShown() {
 
141
  web_contents_->WasShown();
 
142
}
 
143
 
 
144
void WebViewHost::WasHidden() {
 
145
  web_contents_->WasHidden();
 
146
}
 
147
 
 
148
} // namespace oxide