39
33
#include "base/logging.h"
40
34
#include "base/macros.h"
41
#include "base/memory/ref_counted.h"
42
#include "base/memory/scoped_vector.h"
43
35
#include "base/pickle.h"
44
36
#include "base/strings/utf_string_conversions.h"
45
37
#include "cc/output/compositor_frame_metadata.h"
46
#include "content/common/cursors/webcursor.h"
47
38
#include "content/public/browser/native_web_keyboard_event.h"
48
39
#include "content/public/browser/navigation_controller.h"
49
40
#include "content/browser/web_contents/web_contents_impl.h"
50
41
#include "net/base/net_errors.h"
51
#include "third_party/WebKit/public/platform/WebCursorInfo.h"
52
42
#include "third_party/WebKit/public/platform/WebTopControlsState.h"
53
43
#include "third_party/WebKit/public/web/WebDragOperation.h"
54
#include "ui/events/event.h"
55
44
#include "ui/gfx/geometry/point.h"
56
45
#include "ui/gfx/geometry/rect.h"
57
#include "ui/gfx/geometry/rect_f.h"
58
46
#include "ui/gfx/geometry/size.h"
59
#include "ui/touch_selection/touch_selection_controller.h"
60
47
#include "url/gurl.h"
62
49
#include "qt/core/api/oxideqdownloadrequest.h"
152
135
return OxideQLoadEvent::ErrorDomainInternal;
155
inline QCursor QCursorFromWebCursor(blink::WebCursorInfo::Type type) {
156
Qt::CursorShape cs = Qt::ArrowCursor;
158
case blink::WebCursorInfo::TypeCross:
159
cs = Qt::CrossCursor;
162
case blink::WebCursorInfo::TypeHand:
163
cs = Qt::PointingHandCursor;
166
case blink::WebCursorInfo::TypeCell:
167
case blink::WebCursorInfo::TypeIBeam:
168
cs = Qt::IBeamCursor;
171
case blink::WebCursorInfo::TypeWait:
175
case blink::WebCursorInfo::TypeHelp:
176
cs = Qt::WhatsThisCursor;
179
case blink::WebCursorInfo::TypeEastResize:
180
case blink::WebCursorInfo::TypeWestResize:
181
case blink::WebCursorInfo::TypeEastWestResize:
182
cs = Qt::SizeHorCursor;
185
case blink::WebCursorInfo::TypeNorthResize:
186
case blink::WebCursorInfo::TypeSouthResize:
187
case blink::WebCursorInfo::TypeNorthSouthResize:
188
cs = Qt::SizeVerCursor;
191
case blink::WebCursorInfo::TypeNorthEastResize:
192
case blink::WebCursorInfo::TypeSouthWestResize:
193
cs = Qt::SizeBDiagCursor;
196
case blink::WebCursorInfo::TypeNorthWestResize:
197
case blink::WebCursorInfo::TypeSouthEastResize:
198
cs = Qt::SizeFDiagCursor;
201
case blink::WebCursorInfo::TypeNorthEastSouthWestResize:
202
case blink::WebCursorInfo::TypeNorthWestSouthEastResize:
203
case blink::WebCursorInfo::TypeMove:
204
cs = Qt::SizeAllCursor;
207
case blink::WebCursorInfo::TypeColumnResize:
208
cs = Qt::SplitHCursor;
211
case blink::WebCursorInfo::TypeRowResize:
212
cs = Qt::SplitVCursor;
215
case blink::WebCursorInfo::TypeMiddlePanning:
216
case blink::WebCursorInfo::TypeEastPanning:
217
case blink::WebCursorInfo::TypeNorthPanning:
218
case blink::WebCursorInfo::TypeNorthEastPanning:
219
case blink::WebCursorInfo::TypeNorthWestPanning:
220
case blink::WebCursorInfo::TypeSouthPanning:
221
case blink::WebCursorInfo::TypeSouthEastPanning:
222
case blink::WebCursorInfo::TypeSouthWestPanning:
223
case blink::WebCursorInfo::TypeWestPanning:
224
case blink::WebCursorInfo::TypeGrab:
225
case blink::WebCursorInfo::TypeGrabbing:
226
cs = Qt::ClosedHandCursor;
229
case blink::WebCursorInfo::TypeProgress:
233
case blink::WebCursorInfo::TypeNoDrop:
234
case blink::WebCursorInfo::TypeNotAllowed:
235
cs = Qt::ForbiddenCursor;
238
case blink::WebCursorInfo::TypeCopy:
239
case blink::WebCursorInfo::TypeContextMenu:
240
case blink::WebCursorInfo::TypeVerticalText:
241
case blink::WebCursorInfo::TypeAlias:
242
case blink::WebCursorInfo::TypeZoomIn:
243
case blink::WebCursorInfo::TypeZoomOut:
244
case blink::WebCursorInfo::TypeCustom:
245
case blink::WebCursorInfo::TypePointer:
246
case blink::WebCursorInfo::TypeNone:
254
138
static const char* STATE_SERIALIZER_MAGIC_NUMBER = "oxide";
255
139
static uint16_t STATE_SERIALIZER_VERSION = 1;
353
class CompositorFrameHandleImpl : public CompositorFrameHandle {
355
CompositorFrameHandleImpl(oxide::CompositorFrameHandle* frame,
356
int location_bar_content_offset)
359
rect_ = QRect(0, location_bar_content_offset,
360
frame_->data()->size_in_pixels.width(),
361
frame_->data()->size_in_pixels.height());
365
virtual ~CompositorFrameHandleImpl() {}
367
CompositorFrameHandle::Type GetType() final {
369
return CompositorFrameHandle::TYPE_INVALID;
371
if (frame_->data()->gl_frame_data) {
372
DCHECK_NE(frame_->data()->gl_frame_data->type,
373
oxide::GLFrameData::Type::INVALID);
374
if (frame_->data()->gl_frame_data->type ==
375
oxide::GLFrameData::Type::TEXTURE) {
376
return CompositorFrameHandle::TYPE_ACCELERATED;
378
return CompositorFrameHandle::TYPE_IMAGE;
380
if (frame_->data()->software_frame_data) {
381
return CompositorFrameHandle::TYPE_SOFTWARE;
385
return CompositorFrameHandle::TYPE_INVALID;
388
const QRect& GetRect() const final {
392
QImage GetSoftwareFrame() final {
393
DCHECK_EQ(GetType(), CompositorFrameHandle::TYPE_SOFTWARE);
395
static_cast<uchar *>(frame_->data()->software_frame_data->pixels),
396
frame_->data()->size_in_pixels.width(),
397
frame_->data()->size_in_pixels.height(),
398
QImage::Format_ARGB32);
401
unsigned int GetAcceleratedFrameTexture() final {
402
DCHECK_EQ(GetType(), CompositorFrameHandle::TYPE_ACCELERATED);
403
return frame_->data()->gl_frame_data->resource.texture;
406
EGLImageKHR GetImageFrame() final {
407
return frame_->data()->gl_frame_data->resource.egl_image;
411
scoped_refptr<oxide::CompositorFrameHandle> frame_;
415
237
WebView::WebView(WebViewProxyClient* client,
238
ContentsViewProxyClient* view_client,
416
240
OxideQSecurityStatus* security_status)
417
: input_method_context_(new InputMethodContext(this)),
241
: contents_view_(new ContentsView(view_client, handle)),
419
243
security_status_(security_status),
420
frame_tree_torn_down_(false) {}
244
frame_tree_torn_down_(false) {
422
251
float WebView::GetDeviceScaleFactor() const {
423
QScreen* screen = client_->GetScreen();
252
QScreen* screen = contents_view_->client()->GetScreen();
425
254
screen = QGuiApplication::primaryScreen();
445
281
WebFrameTreeObserver::Observe(WebFrameTree::FromWebContents(contents));
447
ContentsNativeViewData::CreateForWebContents(contents, native_view);
449
CHECK_EQ(view_->GetRootFrame()->GetChildFrames().size(), 0U);
450
WebFrame* root_frame = new WebFrame(view_->GetRootFrame());
451
view_->GetRootFrame()->set_script_message_target_delegate(root_frame);
283
CHECK_EQ(web_view_->GetRootFrame()->GetChildFrames().size(), 0U);
284
WebFrame* root_frame = new WebFrame(web_view_->GetRootFrame());
285
web_view_->GetRootFrame()->set_script_message_target_delegate(root_frame);
452
286
client_->CreateWebFrame(root_frame);
455
289
void WebView::EnsurePreferences() {
456
if (view_->GetWebPreferences()) {
290
if (web_view_->GetWebPreferences()) {
460
OxideQWebPreferences* p = new OxideQWebPreferences(client_->GetApiHandle());
461
view_->SetWebPreferences(
294
OxideQWebPreferences* p = new OxideQWebPreferences(handle());
295
web_view_->SetWebPreferences(
462
296
OxideQWebPreferencesPrivate::get(p)->preferences());
465
void WebView::SetInputMethodEnabled(bool enabled) {
466
client_->SetInputMethodEnabled(enabled);
469
blink::WebScreenInfo WebView::GetScreenInfo() const {
470
QScreen* screen = client_->GetScreen();
472
screen = QGuiApplication::primaryScreen();
475
return GetWebScreenInfoFromQScreen(screen);
478
gfx::Rect WebView::GetViewBoundsPix() const {
479
QRect bounds = client_->GetViewBoundsPix();
480
return gfx::Rect(bounds.x(),
486
bool WebView::IsVisible() const {
487
return client_->IsVisible();
490
bool WebView::HasFocus() const {
491
return client_->HasFocus();
494
299
oxide::JavaScriptDialog* WebView::CreateJavaScriptDialog(
495
300
content::JavaScriptMessageType javascript_message_type) {
496
301
JavaScriptDialogProxyClient::Type type;
637
442
void WebView::WebPreferencesDestroyed() {
638
OxideQWebPreferences* p = new OxideQWebPreferences(client_->GetApiHandle());
639
view_->SetWebPreferences(
443
OxideQWebPreferences* p = new OxideQWebPreferences(handle());
444
web_view_->SetWebPreferences(
640
445
OxideQWebPreferencesPrivate::get(p)->preferences());
641
446
client_->WebPreferencesReplaced();
644
void WebView::UnhandledKeyboardEvent(
645
const content::NativeWebKeyboardEvent& event) {
646
if (event.skip_in_browser) {
650
if (event.type != blink::WebInputEvent::RawKeyDown &&
651
event.type != blink::WebInputEvent::KeyUp) {
655
if (!event.os_event) {
659
DCHECK(!event.os_event->isAccepted());
661
client_->HandleUnhandledKeyboardEvent(event.os_event);
664
449
OXIDE_MAKE_ENUM_BITWISE_OPERATORS(FrameMetadataChangeFlags)
666
451
void WebView::FrameMetadataUpdated(const cc::CompositorFrameMetadata& old) {
667
452
FrameMetadataChangeFlags flags = FRAME_METADATA_CHANGE_NONE;
669
454
if (old.root_scroll_offset.x() !=
670
view_->compositor_frame_metadata().root_scroll_offset.x() ||
455
web_view_->compositor_frame_metadata().root_scroll_offset.x() ||
671
456
old.root_scroll_offset.y() !=
672
view_->compositor_frame_metadata().root_scroll_offset.y()) {
457
web_view_->compositor_frame_metadata().root_scroll_offset.y()) {
673
458
flags |= FRAME_METADATA_CHANGE_SCROLL_OFFSET;
675
460
if (old.root_layer_size.width() !=
676
view_->compositor_frame_metadata().root_layer_size.width() ||
461
web_view_->compositor_frame_metadata().root_layer_size.width() ||
677
462
old.root_layer_size.height() !=
678
view_->compositor_frame_metadata().root_layer_size.height()) {
463
web_view_->compositor_frame_metadata().root_layer_size.height()) {
679
464
flags |= FRAME_METADATA_CHANGE_CONTENT;
681
466
if (old.scrollable_viewport_size.width() !=
682
view_->compositor_frame_metadata().scrollable_viewport_size.width() ||
467
web_view_->compositor_frame_metadata().scrollable_viewport_size.width() ||
683
468
old.scrollable_viewport_size.height() !=
684
view_->compositor_frame_metadata().scrollable_viewport_size.height()) {
469
web_view_->compositor_frame_metadata().scrollable_viewport_size.height()) {
685
470
flags |= FRAME_METADATA_CHANGE_VIEWPORT;
687
472
if (old.location_bar_offset.y() !=
688
view_->compositor_frame_metadata().location_bar_offset.y()) {
473
web_view_->compositor_frame_metadata().location_bar_offset.y()) {
689
474
flags |= FRAME_METADATA_CHANGE_CONTROLS_OFFSET;
691
476
if (old.location_bar_content_translation.y() !=
692
view_->compositor_frame_metadata().location_bar_content_translation.y()) {
477
web_view_->compositor_frame_metadata().location_bar_content_translation.y()) {
693
478
flags |= FRAME_METADATA_CHANGE_CONTENT_OFFSET;
695
480
if (old.device_scale_factor !=
696
view_->compositor_frame_metadata().device_scale_factor ||
481
web_view_->compositor_frame_metadata().device_scale_factor ||
697
482
old.page_scale_factor !=
698
view_->compositor_frame_metadata().page_scale_factor) {
483
web_view_->compositor_frame_metadata().page_scale_factor) {
699
484
flags |= FRAME_METADATA_CHANGE_SCROLL_OFFSET;
700
485
flags |= FRAME_METADATA_CHANGE_CONTENT;
701
486
flags |= FRAME_METADATA_CHANGE_VIEWPORT;
840
ui::TouchHandleDrawable* WebView::CreateTouchHandleDrawable() const {
841
TouchHandleDrawable* drawable = new TouchHandleDrawable(this);
842
drawable->SetProxy(client_->CreateTouchHandleDrawable());
846
OXIDE_MAKE_ENUM_BITWISE_OPERATORS(EditCapabilityFlags)
848
void WebView::TouchSelectionChanged(bool active,
849
const gfx::RectF& bounds) const {
850
const float dpr = GetDeviceScaleFactor();
851
QRectF rect(bounds.x() * dpr, bounds.y() * dpr,
852
bounds.width() * dpr, bounds.height() * dpr);
853
client_->TouchSelectionChanged(active, rect);
856
void WebView::SwapCompositorFrame() {
857
compositor_frame_.reset();
858
client_->ScheduleUpdate();
861
void WebView::EvictCurrentFrame() {
862
compositor_frame_.reset();
863
client_->EvictCurrentFrame();
866
oxide::InputMethodContext* WebView::GetInputMethodContext() const {
867
return input_method_context_.get();
870
void WebView::UpdateCursor(const content::WebCursor& cursor) {
871
content::WebCursor::CursorInfo cursor_info;
873
cursor.GetCursorInfo(&cursor_info);
874
if (cursor.IsCustom()) {
875
QImage cursor_image = QImageFromSkBitmap(cursor_info.custom_image);
876
if (cursor_image.isNull()) {
880
QPixmap cursor_pixmap = QPixmap::fromImage(cursor_image);
881
client_->UpdateCursor(QCursor(cursor_pixmap));
883
client_->UpdateCursor(QCursorFromWebCursor(cursor_info.type));
887
611
void WebView::SecurityStatusChanged(const oxide::SecurityStatus& old) {
888
612
OxideQSecurityStatusPrivate::get(security_status_)->Update(old);
1002
728
QUrl WebView::url() const {
1003
return QUrl(QString::fromStdString(view_->GetURL().spec()));
729
return QUrl(QString::fromStdString(web_view_->GetURL().spec()));
1006
732
void WebView::setUrl(const QUrl& url) {
1007
view_->SetURL(GURL(url.toString().toStdString()));
733
web_view_->SetURL(GURL(url.toString().toStdString()));
1010
736
QString WebView::title() const {
1011
return QString::fromStdString(view_->GetTitle());
737
return QString::fromStdString(web_view_->GetTitle());
1014
740
QUrl WebView::favIconUrl() const {
1015
return QUrl(QString::fromStdString(view_->GetFaviconURL().spec()));
741
return QUrl(QString::fromStdString(web_view_->GetFaviconURL().spec()));
1018
744
bool WebView::canGoBack() const {
1019
return view_->CanGoBack();
745
return web_view_->CanGoBack();
1022
748
bool WebView::canGoForward() const {
1023
return view_->CanGoForward();
749
return web_view_->CanGoForward();
1026
752
bool WebView::incognito() const {
1027
return view_->IsIncognito();
753
return web_view_->IsIncognito();
1030
756
bool WebView::loading() const {
1031
return view_->IsLoading();
757
return web_view_->IsLoading();
1034
760
bool WebView::fullscreen() const {
1035
761
return FullscreenHelper::FromWebContents(
1036
view_->GetWebContents())->fullscreen_granted();
762
web_view_->GetWebContents())->fullscreen_granted();
1039
765
void WebView::setFullscreen(bool fullscreen) {
1040
FullscreenHelper::FromWebContents(view_->GetWebContents())
766
FullscreenHelper::FromWebContents(web_view_->GetWebContents())
1041
767
->SetFullscreenGranted(fullscreen);
1044
WebFrameProxyHandle* WebView::rootFrame() const {
1045
WebFrame* f = WebFrame::FromSharedWebFrame(view_->GetRootFrame());
770
QObject* WebView::rootFrame() const {
771
WebFrame* f = WebFrame::FromSharedWebFrame(web_view_->GetRootFrame());
1059
785
return c->handle();
1062
void WebView::wasResized() {
1063
view_->WasResized();
1066
void WebView::screenUpdated() {
1067
view_->ScreenUpdated();
1070
void WebView::visibilityChanged() {
1071
view_->VisibilityChanged();
1074
void WebView::handleFocusEvent(QFocusEvent* event) {
1075
input_method_context_->FocusChanged(event);
1076
view_->FocusChanged();
1081
void WebView::handleHoverEvent(QHoverEvent* event,
1082
const QPoint& window_pos,
1083
const QPoint& global_pos) {
1084
view_->HandleMouseEvent(
1085
MakeWebMouseEvent(event,
1088
GetDeviceScaleFactor(),
1089
view_->GetLocationBarContentOffsetDip()));
1093
void WebView::handleInputMethodEvent(QInputMethodEvent* event) {
1094
input_method_context_->HandleEvent(event);
1098
void WebView::handleKeyEvent(QKeyEvent* event) {
1099
content::NativeWebKeyboardEvent e(MakeNativeWebKeyboardEvent(event, false));
1100
view_->HandleKeyEvent(e);
1102
// If the event is a printable character, send a corresponding Char event
1103
if (event->type() == QEvent::KeyPress && e.text[0] != 0) {
1104
view_->HandleKeyEvent(MakeNativeWebKeyboardEvent(event, true));
1110
void WebView::handleMouseEvent(QMouseEvent* event) {
1111
if (!(event->button() == Qt::LeftButton ||
1112
event->button() == Qt::MidButton ||
1113
event->button() == Qt::RightButton ||
1114
event->button() == Qt::NoButton)) {
1119
view_->HandleMouseEvent(
1120
MakeWebMouseEvent(event,
1121
GetDeviceScaleFactor(),
1122
view_->GetLocationBarContentOffsetDip()));
1126
void WebView::handleTouchEvent(QTouchEvent* event) {
1127
ScopedVector<ui::TouchEvent> events;
1128
touch_event_factory_.MakeEvents(event,
1129
GetDeviceScaleFactor(),
1130
view_->GetLocationBarContentOffsetDip(),
1133
for (size_t i = 0; i < events.size(); ++i) {
1134
view_->HandleTouchEvent(*events[i]);
1140
void WebView::handleTouchUngrabEvent() {
1141
scoped_ptr<ui::TouchEvent> cancel_event(touch_event_factory_.Cancel());
1142
view_->HandleTouchEvent(*cancel_event.get());
1145
void WebView::handleWheelEvent(QWheelEvent* event,
1146
const QPoint& window_pos) {
1147
view_->HandleWheelEvent(
1148
MakeWebMouseWheelEvent(event,
1150
GetDeviceScaleFactor(),
1151
view_->GetLocationBarContentOffsetDip()));
1155
void WebView::handleDragEnterEvent(QDragEnterEvent* event) {
1156
content::DropData drop_data;
1157
gfx::Point location;
1158
blink::WebDragOperationsMask allowed_ops = blink::WebDragOperationNone;
1159
int key_modifiers = 0;
1161
GetDragEnterEventParams(event,
1162
GetDeviceScaleFactor(),
1168
WebContentsView::FromWebContents(view_->GetWebContents())
1169
->HandleDragEnter(drop_data, location, allowed_ops, key_modifiers);
1174
void WebView::handleDragMoveEvent(QDragMoveEvent* event) {
1175
gfx::Point location;
1176
int key_modifiers = 0;
1178
GetDropEventParams(event, GetDeviceScaleFactor(), &location, &key_modifiers);
1180
blink::WebDragOperation op =
1181
WebContentsView::FromWebContents(view_->GetWebContents())
1182
->HandleDragMove(location, key_modifiers);
1184
Qt::DropAction action;
1185
if ((action = ToQtDropAction(op)) != Qt::IgnoreAction) {
1186
event->setDropAction(action);
1193
void WebView::handleDragLeaveEvent(QDragLeaveEvent* event) {
1194
WebContentsView::FromWebContents(view_->GetWebContents())->HandleDragLeave();
1197
void WebView::handleDropEvent(QDropEvent* event) {
1198
gfx::Point location;
1199
int key_modifiers = 0;
1201
GetDropEventParams(event, GetDeviceScaleFactor(), &location, &key_modifiers);
1203
blink::WebDragOperation op =
1204
WebContentsView::FromWebContents(view_->GetWebContents())
1205
->HandleDrop(location, key_modifiers);
1207
Qt::DropAction action;
1208
if ((action = ToQtDropAction(op)) != Qt::IgnoreAction) {
1209
event->setDropAction(action);
1216
QVariant WebView::inputMethodQuery(Qt::InputMethodQuery query) const {
1217
return input_method_context_->Query(query);
1220
788
void WebView::goBack() {
1224
792
void WebView::goForward() {
793
web_view_->GoForward();
1228
796
void WebView::stop() {
1232
800
void WebView::reload() {
1236
804
void WebView::loadHtml(const QString& html, const QUrl& base_url) {
1237
805
QByteArray encoded_data = html.toUtf8().toPercentEncoding();
1238
view_->LoadData(std::string(encoded_data.constData(), encoded_data.length()),
806
web_view_->LoadData(std::string(encoded_data.constData(), encoded_data.length()),
1239
807
"text/html;charset=UTF-8",
1240
808
GURL(base_url.toString().toStdString()));
1243
QList<ScriptMessageHandlerProxyHandle*>& WebView::messageHandlers() {
811
QList<QObject*>& WebView::messageHandlers() {
1244
812
return message_handlers_;
1247
815
int WebView::getNavigationEntryCount() const {
1248
return view_->GetNavigationEntryCount();
816
return web_view_->GetNavigationEntryCount();
1251
819
int WebView::getNavigationCurrentEntryIndex() const {
1252
return view_->GetNavigationCurrentEntryIndex();
820
return web_view_->GetNavigationCurrentEntryIndex();
1255
823
void WebView::setNavigationCurrentEntryIndex(int index) {
1256
view_->SetNavigationCurrentEntryIndex(index);
824
web_view_->SetNavigationCurrentEntryIndex(index);
1259
827
int WebView::getNavigationEntryUniqueID(int index) const {
1260
return view_->GetNavigationEntryUniqueID(index);
828
return web_view_->GetNavigationEntryUniqueID(index);
1263
831
QUrl WebView::getNavigationEntryUrl(int index) const {
1264
832
return QUrl(QString::fromStdString(
1265
view_->GetNavigationEntryUrl(index).spec()));
833
web_view_->GetNavigationEntryUrl(index).spec()));
1268
836
QString WebView::getNavigationEntryTitle(int index) const {
1269
return QString::fromStdString(view_->GetNavigationEntryTitle(index));
837
return QString::fromStdString(web_view_->GetNavigationEntryTitle(index));
1272
840
QDateTime WebView::getNavigationEntryTimestamp(int index) const {
1273
841
return QDateTime::fromMSecsSinceEpoch(
1274
view_->GetNavigationEntryTimestamp(index).ToJsTime());
842
web_view_->GetNavigationEntryTimestamp(index).ToJsTime());
1277
845
QByteArray WebView::currentState() const {
1278
846
// XXX(chrisccoulson): Move the pickling in to oxide::WebView
1279
std::vector<sessions::SerializedNavigationEntry> entries = view_->GetState();
847
std::vector<sessions::SerializedNavigationEntry> entries = web_view_->GetState();
1280
848
if (entries.size() == 0) {
1281
849
return QByteArray();
1290
858
for (i = entries.begin(); i != entries.end(); ++i) {
1291
859
i->WriteToPickle(max_state_size, &pickle);
1293
pickle.WriteInt(view_->GetNavigationCurrentEntryIndex());
861
pickle.WriteInt(web_view_->GetNavigationCurrentEntryIndex());
1294
862
return QByteArray(static_cast<const char*>(pickle.data()), pickle.size());
1297
865
OxideQWebPreferences* WebView::preferences() {
1298
866
EnsurePreferences();
1299
return static_cast<WebPreferences*>(view_->GetWebPreferences())->api_handle();
867
return static_cast<WebPreferences*>(web_view_->GetWebPreferences())->api_handle();
1302
870
void WebView::setPreferences(OxideQWebPreferences* prefs) {
1303
871
OxideQWebPreferences* old = nullptr;
1304
if (WebPreferences* o = static_cast<WebPreferences *>(view_->GetWebPreferences())) {
872
if (WebPreferences* o = static_cast<WebPreferences *>(web_view_->GetWebPreferences())) {
1305
873
old = o->api_handle();
1309
prefs = new OxideQWebPreferences(client_->GetApiHandle());
877
prefs = new OxideQWebPreferences(handle());
1310
878
} else if (!prefs->parent()) {
1311
prefs->setParent(client_->GetApiHandle());
879
prefs->setParent(handle());
1314
view_->SetWebPreferences(
882
web_view_->SetWebPreferences(
1315
883
OxideQWebPreferencesPrivate::get(prefs)->preferences());
1321
if (old->parent() == client_->GetApiHandle()) {
889
if (old->parent() == handle()) {
1326
894
void WebView::updateWebPreferences() {
1327
view_->UpdateWebPreferences();
895
web_view_->UpdateWebPreferences();
1330
898
QPoint WebView::compositorFrameScrollOffsetPix() {
1331
gfx::Point offset = view_->GetCompositorFrameScrollOffsetPix();
899
gfx::Point offset = web_view_->GetCompositorFrameScrollOffsetPix();
1332
900
return QPoint(offset.x(), offset.y());
1335
903
QSize WebView::compositorFrameContentSizePix() {
1336
gfx::Size size = view_->GetCompositorFrameContentSizePix();
904
gfx::Size size = web_view_->GetCompositorFrameContentSizePix();
1337
905
return QSize(size.width(), size.height());
1340
908
QSize WebView::compositorFrameViewportSizePix() {
1341
gfx::Size size = view_->GetCompositorFrameViewportSizePix();
909
gfx::Size size = web_view_->GetCompositorFrameViewportSizePix();
1342
910
return QSize(size.width(), size.height());
1345
QSharedPointer<CompositorFrameHandle> WebView::compositorFrameHandle() {
1346
if (!compositor_frame_) {
1348
QSharedPointer<CompositorFrameHandle>(new CompositorFrameHandleImpl(
1349
view_->GetCompositorFrameHandle(),
1350
view_->compositor_frame_metadata().device_scale_factor *
1351
view_->compositor_frame_metadata().location_bar_content_translation.y()));
1354
return compositor_frame_;
1357
void WebView::didCommitCompositorFrame() {
1358
view_->DidCommitCompositorFrame();
1361
913
void WebView::setCanTemporarilyDisplayInsecureContent(bool allow) {
1362
view_->SetCanTemporarilyDisplayInsecureContent(allow);
914
web_view_->SetCanTemporarilyDisplayInsecureContent(allow);
1365
917
void WebView::setCanTemporarilyRunInsecureContent(bool allow) {
1366
view_->SetCanTemporarilyRunInsecureContent(allow);
918
web_view_->SetCanTemporarilyRunInsecureContent(allow);
1369
921
ContentTypeFlags WebView::blockedContent() const {
1383
935
"ContentTypeFlags and oxide::ContentType enums don't match: "
1384
936
"CONTENT_TYPE_MIXED_SCRIPT");
1386
return static_cast<ContentTypeFlags>(view_->blocked_content());
938
return static_cast<ContentTypeFlags>(web_view_->blocked_content());
1389
941
void WebView::prepareToClose() {
1390
view_->PrepareToClose();
942
web_view_->PrepareToClose();
1393
945
int WebView::locationBarHeight() const {
1394
return view_->GetLocationBarHeightPix();
946
return web_view_->GetLocationBarHeightPix();
1397
949
void WebView::setLocationBarHeight(int height) {
1398
view_->SetLocationBarHeightPix(height);
950
web_view_->SetLocationBarHeightPix(height);
1401
953
int WebView::locationBarOffsetPix() const {
1402
return view_->GetLocationBarOffsetPix();
954
return web_view_->GetLocationBarOffsetPix();
1405
957
int WebView::locationBarContentOffsetPix() const {
1406
return view_->GetLocationBarContentOffsetPix();
958
return web_view_->GetLocationBarContentOffsetPix();
1409
961
LocationBarMode WebView::locationBarMode() const {
1410
switch (view_->location_bar_constraints()) {
962
switch (web_view_->location_bar_constraints()) {
1411
963
case blink::WebTopControlsShown:
1412
964
return LOCATION_BAR_MODE_SHOWN;
1413
965
case blink::WebTopControlsHidden:
1423
975
void WebView::setLocationBarMode(LocationBarMode mode) {
1424
view_->SetLocationBarConstraints(
976
web_view_->SetLocationBarConstraints(
1425
977
LocationBarModeToBlinkTopControlsState(mode));
1428
980
bool WebView::locationBarAnimated() const {
1429
return view_->location_bar_animated();
981
return web_view_->location_bar_animated();
1432
984
void WebView::setLocationBarAnimated(bool animated) {
1433
view_->set_location_bar_animated(animated);
985
web_view_->set_location_bar_animated(animated);
1436
988
void WebView::locationBarShow(bool animate) {
1437
view_->ShowLocationBar(animate);
989
web_view_->ShowLocationBar(animate);
1440
992
void WebView::locationBarHide(bool animate) {
1441
view_->HideLocationBar(animate);
993
web_view_->HideLocationBar(animate);
1444
996
WebProcessStatus WebView::webProcessStatus() const {
1445
base::TerminationStatus status = view_->GetWebContents()->GetCrashedStatus();
997
base::TerminationStatus status = web_view_->GetWebContents()->GetCrashedStatus();
1446
998
if (status == base::TERMINATION_STATUS_STILL_RUNNING) {
1447
999
return WEB_PROCESS_RUNNING;
1448
1000
} else if (status == base::TERMINATION_STATUS_PROCESS_WAS_KILLED) {
1529
1081
WebView::WebView(WebViewProxyClient* client,
1530
QObject* native_view,
1082
ContentsViewProxyClient* view_client,
1531
1084
OxideQFindController* find_controller,
1532
1085
OxideQSecurityStatus* security_status,
1533
1086
WebContext* context,
1534
1087
bool incognito,
1535
1088
const QByteArray& restore_state,
1536
1089
RestoreType restore_type)
1537
: WebView(client, security_status) {
1538
oxide::WebView::Params params;
1539
params.client = this;
1540
params.context = context->GetContext();
1541
params.incognito = incognito;
1090
: WebView(client, view_client, handle, security_status) {
1091
oxide::WebView::CommonParams common_params;
1092
common_params.client = this;
1093
common_params.view_client = contents_view_.get();
1095
oxide::WebView::CreateParams create_params;
1096
create_params.context = context->GetContext();
1097
create_params.incognito = incognito;
1543
1099
if (!restore_state.isEmpty()) {
1544
1100
CreateRestoreEntriesFromRestoreState(restore_state,
1545
¶ms.restore_entries,
1546
¶ms.restore_index);
1547
params.restore_type = ToNavigationControllerRestoreType(restore_type);
1101
&create_params.restore_entries,
1102
&create_params.restore_index);
1103
create_params.restore_type =
1104
ToNavigationControllerRestoreType(restore_type);
1550
1107
if (oxide::BrowserProcessMain::GetInstance()->GetProcessModel() ==
1573
1131
return nullptr;
1576
WebView* new_view = new WebView(client, security_status);
1577
new_view->view_.reset(new oxide::WebView(std::move(rd->contents), new_view));
1578
rd->view = new_view->view_->AsWeakPtr();
1580
new_view->CommonInit(find_controller, native_view);
1134
WebView* new_view = new WebView(client, view_client, handle, security_status);
1136
oxide::WebView::CommonParams params;
1137
params.client = new_view;
1138
params.view_client = new_view->contents_view_.get();
1139
new_view->web_view_.reset(new oxide::WebView(params, std::move(rd->contents)));
1141
rd->view = new_view->web_view_->AsWeakPtr();
1143
new_view->CommonInit(find_controller);
1582
1145
OxideQWebPreferences* p =
1583
1146
static_cast<WebPreferences*>(
1584
new_view->view_->GetWebPreferences())->api_handle();
1147
new_view->web_view_->GetWebPreferences())->api_handle();
1585
1148
if (!p->parent()) {
1586
p->setParent(new_view->client_->GetApiHandle());
1149
p->setParent(new_view->handle());
1589
1152
return new_view;
1592
1155
WebView::~WebView() {
1593
content::WebContents* contents = view_->GetWebContents();
1156
content::WebContents* contents = web_view_->GetWebContents();
1594
1157
CertificateErrorDispatcher::FromWebContents(contents)->set_client(nullptr);
1595
1158
FullscreenHelper::FromWebContents(contents)->set_client(nullptr);
1596
1159
DCHECK(frame_tree_torn_down_);
1598
input_method_context_->DetachClient();
1600
1161
oxide::PermissionRequestDispatcher::FromWebContents(
1601
1162
contents)->set_client(nullptr);
1605
WebView* WebView::FromProxyHandle(WebViewProxyHandle* handle) {
1606
return static_cast<WebView*>(handle->proxy_.data());
1610
1166
WebView* WebView::FromView(oxide::WebView* view) {
1611
1167
return static_cast<WebView*>(view->client());
1614
1170
WebContext* WebView::GetContext() const {
1615
return WebContext::FromBrowserContext(view_->GetBrowserContext());
1171
return WebContext::FromBrowserContext(web_view_->GetBrowserContext());
1618
1174
const oxide::SecurityStatus& WebView::GetSecurityStatus() const {
1619
return view_->security_status();
1175
return web_view_->security_status();
1622
1178
} // namespace qt