summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorMichael BrĂ¼ning <michael.bruning@digia.com>2013-08-02 13:12:08 +0200
committerPierre Rossi <pierre.rossi@gmail.com>2013-08-02 14:53:28 +0200
commitd7dd93cf6e3540855055ba08639161104a77bc3a (patch)
tree1777bb2722cb67ce9b06590aee131b792e8f1210 /lib
parentd1e168102555e903d41394484f5a8a0c13f1548f (diff)
Implement more detailed load information handling.
Add WebContentsObserver as a base class of WebContentsDelegateQt to be able to get more information about the WebContents (loading state etc.). Also implements load finished with a success value to be able to show when a load has failed. Change-Id: Ic2ad698d180b395cf3d9fb6cd49b12c9cb4fb493 Reviewed-by: Pierre Rossi <pierre.rossi@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/quick/qquickwebcontentsview.cpp7
-rw-r--r--lib/quick/qquickwebcontentsview_p_p.h1
-rw-r--r--lib/web_contents_adapter_client.h1
-rw-r--r--lib/web_contents_delegate_qt.cpp14
-rw-r--r--lib/web_contents_delegate_qt.h5
-rw-r--r--lib/widgets/Api/qwebcontentsview.cpp9
-rw-r--r--lib/widgets/Api/qwebcontentsview_p.h1
7 files changed, 36 insertions, 2 deletions
diff --git a/lib/quick/qquickwebcontentsview.cpp b/lib/quick/qquickwebcontentsview.cpp
index 16e73e679..806a75dbb 100644
--- a/lib/quick/qquickwebcontentsview.cpp
+++ b/lib/quick/qquickwebcontentsview.cpp
@@ -87,6 +87,13 @@ QRectF QQuickWebContentsViewPrivate::viewportRect() const
return QRectF(q->x(), q->y(), q->width(), q->height());
}
+void QQuickWebContentsViewPrivate::loadFinished(bool success)
+{
+ Q_Q(QQuickWebContentsView);
+ Q_UNUSED(success);
+ Q_EMIT q->loadingStateChanged();
+}
+
QQuickWebContentsView::QQuickWebContentsView()
: d_ptr(new QQuickWebContentsViewPrivate)
{
diff --git a/lib/quick/qquickwebcontentsview_p_p.h b/lib/quick/qquickwebcontentsview_p_p.h
index a9c5b00c0..462a5b4f2 100644
--- a/lib/quick/qquickwebcontentsview_p_p.h
+++ b/lib/quick/qquickwebcontentsview_p_p.h
@@ -62,6 +62,7 @@ public:
virtual void urlChanged(const QUrl&) Q_DECL_OVERRIDE;
virtual void loadingStateChanged() Q_DECL_OVERRIDE;
virtual QRectF viewportRect() const Q_DECL_OVERRIDE;
+ virtual void loadFinished(bool success) Q_DECL_OVERRIDE;
QScopedPointer<WebContentsAdapter> adapter;
};
diff --git a/lib/web_contents_adapter_client.h b/lib/web_contents_adapter_client.h
index 02cbbaf0d..cc54c3fd6 100644
--- a/lib/web_contents_adapter_client.h
+++ b/lib/web_contents_adapter_client.h
@@ -61,6 +61,7 @@ public:
virtual void urlChanged(const QUrl&) = 0;
virtual void loadingStateChanged() = 0;
virtual QRectF viewportRect() const = 0;
+ virtual void loadFinished(bool success) = 0;
};
#endif // WEB_CONTENTS_ADAPTER_CLIENT_H
diff --git a/lib/web_contents_delegate_qt.cpp b/lib/web_contents_delegate_qt.cpp
index 72a50ac1d..9cadf4b60 100644
--- a/lib/web_contents_delegate_qt.cpp
+++ b/lib/web_contents_delegate_qt.cpp
@@ -80,6 +80,7 @@ WebContentsDelegateQt::WebContentsDelegateQt(content::BrowserContext* browser_co
m_webContents->GetRenderViewHost()->SyncRendererPrefs();
m_webContents->SetDelegate(this);
+ this->Observe(m_webContents.get());
}
void WebContentsDelegateQt::NavigationStateChanged(const content::WebContents* source, unsigned changed_flags)
@@ -97,6 +98,19 @@ void WebContentsDelegateQt::LoadingStateChanged(content::WebContents* source)
m_viewClient->loadingStateChanged();
}
+void WebContentsDelegateQt::DidFailLoad(int64 frame_id, const GURL &validated_url, bool is_main_frame, int error_code, const string16 &error_description, content::RenderViewHost *render_view_host)
+{
+ if (is_main_frame)
+ m_viewClient->loadFinished(false);
+}
+
+void WebContentsDelegateQt::DidFinishLoad(int64 frame_id, const GURL &validated_url, bool is_main_frame, content::RenderViewHost *render_view_host)
+{
+ if (is_main_frame)
+ m_viewClient->loadFinished(true);
+}
+
+
content::WebContents* WebContentsDelegateQt::web_contents()
{
return m_webContents.get();
diff --git a/lib/web_contents_delegate_qt.h b/lib/web_contents_delegate_qt.h
index 85fffcba9..826230c91 100644
--- a/lib/web_contents_delegate_qt.h
+++ b/lib/web_contents_delegate_qt.h
@@ -43,6 +43,7 @@
#define WEB_CONTENTS_DELEGATE_QT
#include "content/public/browser/web_contents_delegate.h"
+#include "content/public/browser/web_contents_observer.h"
#include "content/public/browser/web_contents.h"
#include <QObject>
@@ -51,10 +52,12 @@
namespace content {
class BrowserContext;
class SiteInstance;
+ class RenderViewHost;
}
class WebContentsAdapterClient;
class WebContentsDelegateQt : public content::WebContentsDelegate
+ , public content::WebContentsObserver
{
public:
WebContentsDelegateQt(content::BrowserContext*, content::SiteInstance*, int routing_id, const gfx::Size& initial_size);
@@ -62,6 +65,8 @@ public:
virtual void NavigationStateChanged(const content::WebContents* source, unsigned changed_flags);
virtual void LoadingStateChanged(content::WebContents* source);
+ virtual void DidFailLoad(int64 frame_id, const GURL &validated_url, bool is_main_frame, int error_code, const string16 &error_description, content::RenderViewHost *render_view_host);
+ virtual void DidFinishLoad(int64 frame_id, const GURL &validated_url, bool is_main_frame, content::RenderViewHost *render_view_host);
private:
scoped_ptr<content::WebContents> m_webContents;
diff --git a/lib/widgets/Api/qwebcontentsview.cpp b/lib/widgets/Api/qwebcontentsview.cpp
index c1e182b3b..1479a17be 100644
--- a/lib/widgets/Api/qwebcontentsview.cpp
+++ b/lib/widgets/Api/qwebcontentsview.cpp
@@ -72,8 +72,6 @@ void QWebContentsViewPrivate::loadingStateChanged()
if (m_isLoading != wasLoading) {
if (m_isLoading)
Q_EMIT q->loadStarted();
- else
- Q_EMIT q->loadFinished(true);
}
}
@@ -83,6 +81,13 @@ QRectF QWebContentsViewPrivate::viewportRect() const
return q->geometry();
}
+void QWebContentsViewPrivate::loadFinished(bool success)
+{
+ Q_Q(QWebContentsView);
+ m_isLoading = adapter->isLoading();
+ Q_EMIT q->loadFinished(success);
+}
+
RenderWidgetHostViewQtDelegate *QWebContentsViewPrivate::CreateRenderWidgetHostViewQtDelegate()
{
Q_Q(QWebContentsView);
diff --git a/lib/widgets/Api/qwebcontentsview_p.h b/lib/widgets/Api/qwebcontentsview_p.h
index badf72673..eade6c245 100644
--- a/lib/widgets/Api/qwebcontentsview_p.h
+++ b/lib/widgets/Api/qwebcontentsview_p.h
@@ -63,6 +63,7 @@ public:
virtual void urlChanged(const QUrl&) Q_DECL_OVERRIDE;
virtual void loadingStateChanged() Q_DECL_OVERRIDE;
virtual QRectF viewportRect() const Q_DECL_OVERRIDE;
+ virtual void loadFinished(bool success) Q_DECL_OVERRIDE;
bool m_isLoading;
QScopedPointer<WebContentsAdapter> adapter;