From 30d205d5663ab0baeb571d80f1e4d27981d5b4a1 Mon Sep 17 00:00:00 2001
From: Jocelyn Turcotte <jocelyn.turcotte@digia.com>
Date: Wed, 12 Jun 2013 17:34:38 +0200
Subject: [PATCH] Quick cleanup.

---
 example/quickwindow.qml               |  1 +
 example/widgetwindow.cpp              |  2 +
 lib/browser_context_qt.h              |  3 --
 lib/content_browser_client_qt.cpp     | 20 ----------
 lib/qquickwebcontentsview.cpp         |  4 +-
 lib/qwebcontentsview.cpp              |  5 +--
 lib/web_contents_delegate_qt.cpp      | 56 ++-------------------------
 lib/web_contents_delegate_qt.h        | 12 +-----
 lib/web_engine_context.cpp            |  5 +--
 shared/render_widget_host_view_qt.cpp | 10 -----
 shared/render_widget_host_view_qt.h   |  2 -
 11 files changed, 10 insertions(+), 110 deletions(-)

diff --git a/example/quickwindow.qml b/example/quickwindow.qml
index 9c90e7241..54b82d6c7 100644
--- a/example/quickwindow.qml
+++ b/example/quickwindow.qml
@@ -84,6 +84,7 @@ Item {
         anchors.bottom: parent.bottom
         anchors.left: parent.left
         anchors.right: parent.right
+        url: "http://qt-project.org/"
 
         Binding {
             target: webContentsView.children[0]
diff --git a/example/widgetwindow.cpp b/example/widgetwindow.cpp
index 89982e509..159952715 100644
--- a/example/widgetwindow.cpp
+++ b/example/widgetwindow.cpp
@@ -84,6 +84,8 @@ WidgetWindow::WidgetWindow()
     connect(reloadButton, SIGNAL(clicked()), m_webView.data(), SLOT(reload()));
     connect(m_webView.data(), SIGNAL(titleChanged(const QString&)), SLOT(setWindowTitle(const QString&)));
     connect(m_webView.data(), SIGNAL(urlChanged(const QUrl&)), SLOT(setAddressBarUrl(const QUrl&)));
+
+    m_webView->load(QUrl(QStringLiteral("http://qt-project.org/")));
 }
 
 WidgetWindow::~WidgetWindow()
diff --git a/lib/browser_context_qt.h b/lib/browser_context_qt.h
index dc667cd48..33e236044 100644
--- a/lib/browser_context_qt.h
+++ b/lib/browser_context_qt.h
@@ -47,7 +47,6 @@
 #include "base/files/scoped_temp_dir.h"
 
 #include "base/time.h"
-#include "content/public/browser/browser_thread.h"
 #include "content/public/browser/content_browser_client.h"
 #include "content/public/browser/resource_context.h"
 #include "content/public/browser/storage_partition.h"
@@ -60,8 +59,6 @@
 #include "resource_context_qt.h"
 #include "url_request_context_getter_qt.h"
 
-
-
 class BrowserContextQt : public content::BrowserContext
 {
 public:
diff --git a/lib/content_browser_client_qt.cpp b/lib/content_browser_client_qt.cpp
index d974e8e79..68eab7f65 100644
--- a/lib/content_browser_client_qt.cpp
+++ b/lib/content_browser_client_qt.cpp
@@ -42,31 +42,11 @@
 #include "content_browser_client_qt.h"
 
 #include "content/public/browser/browser_main_parts.h"
-#include "content/public/browser/notification_source.h"
-#include "content/public/browser/notification_types.h"
-#include "content/public/browser/render_process_host.h"
 #include "content/public/common/main_function_params.h"
-#include "net/base/net_module.h"
-#include "net/base/net_util.h"
 
 #include "browser_context_qt.h"
 #include "web_contents_view_qt.h"
 
-static GURL GetStartupURL() {
-  CommandLine* command_line = CommandLine::ForCurrentProcess();
-  const CommandLine::StringVector& args = command_line->GetArgs();
-
-  if (args.empty())
-    return GURL("http://www.google.com/");
-
-  GURL url(args[0]);
-  if (url.is_valid() && url.has_scheme())
-    return url;
-
-  return net::FilePathToFileURL(base::FilePath(args[0]));
-}
-
-
 class BrowserMainPartsQt : public content::BrowserMainParts
 {
 public:
diff --git a/lib/qquickwebcontentsview.cpp b/lib/qquickwebcontentsview.cpp
index 154f4ea5e..dec521183 100644
--- a/lib/qquickwebcontentsview.cpp
+++ b/lib/qquickwebcontentsview.cpp
@@ -45,8 +45,6 @@
 #define CONTENT_IMPLEMENTATION
 
 #include "content/public/browser/web_contents.h"
-#include "content/public/browser/web_contents_view.h"
-#include "ipc/ipc_message.h"
 
 #include "browser_context_qt.h"
 #include "content_browser_client_qt.h"
@@ -76,7 +74,7 @@ QQuickWebContentsView::QQuickWebContentsView()
     d->context = WebEngineContext::current();
 
     content::BrowserContext* browser_context = static_cast<ContentBrowserClientQt*>(content::GetContentClient()->browser())->browser_context();
-    d->webContentsDelegate.reset(WebContentsDelegateQt::CreateNewWindow(browser_context, GURL(std::string("http://qt-project.org/")), NULL, MSG_ROUTING_NONE, gfx::Size()));
+    d->webContentsDelegate.reset(WebContentsDelegateQt::CreateNewWindow(browser_context, NULL, MSG_ROUTING_NONE, gfx::Size()));
     WebContentsViewQt* content_view = static_cast<WebContentsViewQt*>(d->webContentsDelegate->web_contents()->GetView());
     QQuickItem* windowContainer = content_view->windowContainer()->qQuickItem();
     windowContainer->setParentItem(this);
diff --git a/lib/qwebcontentsview.cpp b/lib/qwebcontentsview.cpp
index 35eed1823..5cff52ad4 100644
--- a/lib/qwebcontentsview.cpp
+++ b/lib/qwebcontentsview.cpp
@@ -45,8 +45,6 @@
 #define CONTENT_IMPLEMENTATION
 
 #include "content/public/browser/web_contents.h"
-#include "content/public/browser/web_contents_view.h"
-#include "ipc/ipc_message.h"
 
 #include "browser_context_qt.h"
 #include "content_browser_client_qt.h"
@@ -55,7 +53,6 @@
 #include "web_engine_context.h"
 
 #include <QVBoxLayout>
-#include <QWidget>
 #include <QUrl>
 
 class QWebContentsViewPrivate
@@ -72,7 +69,7 @@ QWebContentsView::QWebContentsView()
     d->context = WebEngineContext::current();
 
     content::BrowserContext* browser_context = static_cast<ContentBrowserClientQt*>(content::GetContentClient()->browser())->browser_context();
-    d->webContentsDelegate.reset(WebContentsDelegateQt::CreateNewWindow(browser_context, GURL(std::string("http://qt-project.org/")), NULL, MSG_ROUTING_NONE, gfx::Size()));
+    d->webContentsDelegate.reset(WebContentsDelegateQt::CreateNewWindow(browser_context, NULL, MSG_ROUTING_NONE, gfx::Size()));
     QVBoxLayout *layout = new QVBoxLayout;
     setLayout(layout);
 
diff --git a/lib/web_contents_delegate_qt.cpp b/lib/web_contents_delegate_qt.cpp
index db470c7e4..71f3e6d9c 100644
--- a/lib/web_contents_delegate_qt.cpp
+++ b/lib/web_contents_delegate_qt.cpp
@@ -41,42 +41,23 @@
 
 #include "web_contents_delegate_qt.h"
 
+#include "content/public/browser/render_view_host.h"
 #include "content/public/browser/web_contents.h"
-#include "content/public/browser/navigation_controller.h"
+#include "content/public/common/renderer_preferences.h"
 
-#include "web_contents_view_qt.h"
-#include "qwebcontentsview.h"
-#include "qquickwebcontentsview.h"
-
-#include <QWidget>
-#include <QVBoxLayout>
-#include <QToolButton>
-#include <QLineEdit>
-#include <QQuickView>
 #include <QGuiApplication>
 #include <QStyleHints>
 
 static const int kTestWindowWidth = 800;
 static const int kTestWindowHeight = 600;
 
-std::vector<WebContentsDelegateQt*> WebContentsDelegateQt::m_windows;
-
 WebContentsDelegateQt::WebContentsDelegateQt(content::WebContents* web_contents)
     : m_webContents(web_contents)
 {
     m_webContents->SetDelegate(this);
-	// const CommandLine& command_line = *CommandLine::ForCurrentProcess();
-	// registrar_.Add(this, NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
-	// Source<WebContents>(web_contents));
-	m_windows.push_back(this);
-
-	// if (!shell_created_callback_.is_null()) {
-	// 	shell_created_callback_.Run(this);
-	// 	shell_created_callback_.Reset();
-	// }
 }
 
-WebContentsDelegateQt* WebContentsDelegateQt::CreateNewWindow(content::BrowserContext* browser_context, const GURL& url, content::SiteInstance* site_instance, int routing_id, const gfx::Size& initial_size)
+WebContentsDelegateQt* WebContentsDelegateQt::CreateNewWindow(content::BrowserContext* browser_context, content::SiteInstance* site_instance, int routing_id, const gfx::Size& initial_size)
 {
     content::WebContents::CreateParams create_params(browser_context, site_instance);
     create_params.routing_id = routing_id;
@@ -95,8 +76,6 @@ WebContentsDelegateQt* WebContentsDelegateQt::CreateNewWindow(content::BrowserCo
     rendererPrefs->caret_blink_interval = 0.5 * static_cast<double>(qtCursorFlashTime) / 1000;
     delegate->m_webContents->GetRenderViewHost()->SyncRendererPrefs();
 
-    if (!url.is_empty())
-        delegate->LoadURL(url);
     return delegate;
 }
 
@@ -105,35 +84,6 @@ content::WebContents* WebContentsDelegateQt::web_contents()
     return m_webContents.get();
 }
 
-
-void WebContentsDelegateQt::GoBackOrForward(int offset) {
-  m_webContents->GetController().GoToOffset(offset);
-  m_webContents->GetView()->Focus();
-}
-
-void WebContentsDelegateQt::Reload() {
-  m_webContents->GetController().Reload(false);
-  m_webContents->GetView()->Focus();
-}
-
-void WebContentsDelegateQt::Stop() {
-  m_webContents->Stop();
-  m_webContents->GetView()->Focus();
-}
-
-void WebContentsDelegateQt::LoadURL(const GURL& url)
-{
-  	LoadURLForFrame(url, std::string());
-}
-
-void WebContentsDelegateQt::LoadURLForFrame(const GURL& url, const std::string& frame_name) {
-  content::NavigationController::LoadURLParams params(url);
-  params.transition_type = content::PageTransitionFromInt(content::PAGE_TRANSITION_TYPED | content::PAGE_TRANSITION_FROM_ADDRESS_BAR);
-  params.frame_name = frame_name;
-  m_webContents->GetController().LoadURLWithParams(params);
-  m_webContents->GetView()->Focus();
-}
-
 void WebContentsDelegateQt::Observe(int, const content::NotificationSource&, const content::NotificationDetails&)
 {
 	// IMPLEMENT THIS!!!!
diff --git a/lib/web_contents_delegate_qt.h b/lib/web_contents_delegate_qt.h
index 4f289269e..6e4a16ff4 100644
--- a/lib/web_contents_delegate_qt.h
+++ b/lib/web_contents_delegate_qt.h
@@ -51,20 +51,12 @@ namespace content {
     class SiteInstance;
 }
 
-class QWebContentsView;
-class QQuickWebContentsView;
-
 class WebContentsDelegateQt : public content::WebContentsDelegate
                             , public content::NotificationObserver
 {
 public:
-    static WebContentsDelegateQt* CreateNewWindow(content::BrowserContext*, const GURL&, content::SiteInstance*, int routing_id, const gfx::Size& initial_size);
+    static WebContentsDelegateQt* CreateNewWindow(content::BrowserContext*, content::SiteInstance*, int routing_id, const gfx::Size& initial_size);
     content::WebContents* web_contents();
-    void LoadURL(const GURL&);
-    void LoadURLForFrame(const GURL&, const std::string& frame_name);
-    void GoBackOrForward(int offset);
-    void Reload();
-    void Stop();
 
     virtual void Observe(int, const content::NotificationSource&, const content::NotificationDetails&);
 
@@ -72,8 +64,6 @@ private:
     WebContentsDelegateQt(content::WebContents*);
 
     scoped_ptr<content::WebContents> m_webContents;
-
-    static std::vector<WebContentsDelegateQt*> m_windows;
 };
 
 #endif
diff --git a/lib/web_engine_context.cpp b/lib/web_engine_context.cpp
index 2f34c24b4..03cbae051 100644
--- a/lib/web_engine_context.cpp
+++ b/lib/web_engine_context.cpp
@@ -118,7 +118,7 @@ int GetTimeIntervalMilliseconds(const base::TimeTicks& from) {
 }
 
 class MessagePumpForUIQt : public QObject,
-                    public base::MessagePump
+                           public base::MessagePump
 {
 public:
     MessagePumpForUIQt()
@@ -245,10 +245,7 @@ WebEngineContext::WebEngineContext()
 
     static content::BrowserMainRunner *browserRunner = 0;
     if (!browserRunner) {
-        //CommandLine::Init(0, 0);
-
         browserRunner = content::BrowserMainRunner::Create();
-
         browserRunner->Initialize(content::MainFunctionParams(*CommandLine::ForCurrentProcess()));
     }
 
diff --git a/shared/render_widget_host_view_qt.cpp b/shared/render_widget_host_view_qt.cpp
index 4fcdcbf00..46a710591 100644
--- a/shared/render_widget_host_view_qt.cpp
+++ b/shared/render_widget_host_view_qt.cpp
@@ -133,11 +133,6 @@ content::BackingStore *RenderWidgetHostViewQt::AllocBackingStore(const gfx::Size
     return 0;
 }
 
-RenderWidgetHostView* RenderWidgetHostViewQt::CreateViewForWidget(content::RenderWidgetHost* widget)
-{
-    return new RenderWidgetHostViewQt(widget);
-}
-
 void RenderWidgetHostViewQt::InitAsChild(gfx::NativeView parent_view)
 {
     NativeViewContainerQt* container = reinterpret_cast<NativeViewContainerQt*>(parent_view);
@@ -194,11 +189,6 @@ gfx::NativeView RenderWidgetHostViewQt::GetNativeView() const
     return gfx::NativeView();
 }
 
-NativeViewQt* RenderWidgetHostViewQt::GetNativeViewQt() const
-{
-    return m_view;
-}
-
 gfx::NativeViewId RenderWidgetHostViewQt::GetNativeViewId() const
 {
     QT_NOT_YET_IMPLEMENTED
diff --git a/shared/render_widget_host_view_qt.h b/shared/render_widget_host_view_qt.h
index d21cbf051..493d89b92 100644
--- a/shared/render_widget_host_view_qt.h
+++ b/shared/render_widget_host_view_qt.h
@@ -65,7 +65,6 @@ public:
     bool handleEvent(QEvent* event);
 
     virtual content::BackingStore *AllocBackingStore(const gfx::Size &size);
-    static RenderWidgetHostView* CreateViewForWidget(content::RenderWidgetHost* widget);
 
     virtual void InitAsChild(gfx::NativeView parent_view);
     virtual void InitAsPopup(content::RenderWidgetHostView*, const gfx::Rect&);
@@ -74,7 +73,6 @@ public:
     virtual void SetSize(const gfx::Size& size);
     virtual void SetBounds(const gfx::Rect& rect);
     virtual gfx::NativeView GetNativeView() const;
-    virtual NativeViewQt* GetNativeViewQt() const OVERRIDE;
     virtual gfx::NativeViewId GetNativeViewId() const;
     virtual gfx::NativeViewAccessible GetNativeViewAccessible();
     virtual void Focus();
-- 
GitLab