diff options
Diffstat (limited to 'content/shell')
-rw-r--r-- | content/shell/shell.cc | 12 | ||||
-rw-r--r-- | content/shell/shell.h | 26 | ||||
-rw-r--r-- | content/shell/shell_browser_context.cc | 16 | ||||
-rw-r--r-- | content/shell/shell_content_browser_client.cc | 6 | ||||
-rw-r--r-- | content/shell/shell_gtk.cc | 146 | ||||
-rw-r--r-- | content/shell/shell_mac.mm | 6 | ||||
-rw-r--r-- | content/shell/shell_url_request_context_getter.cc | 21 | ||||
-rw-r--r-- | content/shell/shell_url_request_context_getter.h | 7 | ||||
-rw-r--r-- | content/shell/shell_win.cc | 9 |
9 files changed, 219 insertions, 30 deletions
diff --git a/content/shell/shell.cc b/content/shell/shell.cc index c837d5a..8211667 100644 --- a/content/shell/shell.cc +++ b/content/shell/shell.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -11,10 +11,6 @@ #include "content/browser/tab_contents/tab_contents.h" #include "ui/gfx/size.h" -#if defined(OS_WIN) -#include "content/browser/tab_contents/tab_contents_view_win.h" -#endif - // Content area size for newly created windows. static const int kTestWindowWidth = 800; static const int kTestWindowHeight = 600; @@ -51,11 +47,7 @@ Shell* Shell::CreateShell(TabContents* tab_contents) { shell->tab_contents_.reset(tab_contents); tab_contents->SetDelegate(shell); -#if defined(OS_WIN) - TabContentsViewWin* view = - static_cast<TabContentsViewWin*>(tab_contents->GetView()); - view->SetParent(shell->window_); -#endif + shell->PlatformSetContents(); shell->PlatformResizeSubViews(); return shell; diff --git a/content/shell/shell.h b/content/shell/shell.h index 9e161e0..8365507 100644 --- a/content/shell/shell.h +++ b/content/shell/shell.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -15,6 +15,12 @@ #include "content/public/browser/web_contents_delegate.h" #include "ui/gfx/native_widget_types.h" +#if defined(OS_LINUX) +#include "ui/base/gtk/gtk_signal.h" + +typedef struct _GtkToolItem GtkToolItem; +#endif + class GURL; class SiteInstance; class TabContents; @@ -76,6 +82,8 @@ class Shell : public WebContentsDelegate { void PlatformCleanUp(); // Creates the main window GUI. void PlatformCreateWindow(int width, int height); + // Links the TabContents into the newly created window. + void PlatformSetContents(); // Resizes the main window to the given dimensions. void PlatformSizeTo(int width, int height); // Resize the content area and GUI. @@ -101,6 +109,12 @@ class Shell : public WebContentsDelegate { static ATOM RegisterWindowClass(); static LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); static LRESULT CALLBACK EditWndProc(HWND, UINT, WPARAM, LPARAM); +#elif defined(OS_LINUX) + CHROMEGTK_CALLBACK_0(Shell, void, OnBackButtonClicked); + CHROMEGTK_CALLBACK_0(Shell, void, OnForwardButtonClicked); + CHROMEGTK_CALLBACK_0(Shell, void, OnReloadButtonClicked); + CHROMEGTK_CALLBACK_0(Shell, void, OnStopButtonClicked); + CHROMEGTK_CALLBACK_0(Shell, void, OnURLEntryActivate); #endif scoped_ptr<TabContents> tab_contents_; @@ -111,6 +125,16 @@ class Shell : public WebContentsDelegate { #if defined(OS_WIN) WNDPROC default_edit_wnd_proc_; static HINSTANCE instance_handle_; +#elif defined(OS_LINUX) + GtkWidget* vbox_; + + GtkToolItem* back_button_; + GtkToolItem* forward_button_; + GtkToolItem* reload_button_; + GtkToolItem* stop_button_; + + int content_width_; + int content_height_; #endif // A container of all the open windows. We use a vector so we can keep track diff --git a/content/shell/shell_browser_context.cc b/content/shell/shell_browser_context.cc index a5ae692..f8d4961 100644 --- a/content/shell/shell_browser_context.cc +++ b/content/shell/shell_browser_context.cc @@ -1,10 +1,11 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "content/shell/shell_browser_context.h" #include "base/bind.h" +#include "base/environment.h" #include "base/file_util.h" #include "base/logging.h" #include "base/path_service.h" @@ -30,12 +31,19 @@ #if defined(OS_WIN) #include "base/base_paths_win.h" +#elif defined(OS_LINUX) +#include "base/nix/xdg_util.h" #endif using content::BrowserThread; namespace { +#if defined(OS_LINUX) +const char kDotConfigDir[] = ".config"; +const char kXdgConfigHomeEnvVar[] = "XDG_CONFIG_HOME"; +#endif + class ShellGeolocationPermissionContext : public GeolocationPermissionContext { public: ShellGeolocationPermissionContext() { @@ -104,6 +112,12 @@ FilePath ShellBrowserContext::GetPath() { #if defined(OS_WIN) CHECK(PathService::Get(base::DIR_LOCAL_APP_DATA, &path_)); path_ = path_.Append(std::wstring(L"content_shell")); +#elif defined(OS_LINUX) + scoped_ptr<base::Environment> env(base::Environment::Create()); + FilePath config_dir(base::nix::GetXDGDirectory(env.get(), + kXdgConfigHomeEnvVar, + kDotConfigDir)); + path_ = config_dir.Append("content_shell"); #else NOTIMPLEMENTED(); #endif diff --git a/content/shell/shell_content_browser_client.cc b/content/shell/shell_content_browser_client.cc index 99e665c..0f2131a 100644 --- a/content/shell/shell_content_browser_client.cc +++ b/content/shell/shell_content_browser_client.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -16,6 +16,8 @@ #include "content/browser/tab_contents/tab_contents.h" #include "content/browser/tab_contents/tab_contents_view_win.h" #include "content/common/view_messages.h" +#elif defined(OS_LINUX) +#include "content/browser/tab_contents/tab_contents_view_gtk.h" #endif namespace content { @@ -36,6 +38,8 @@ TabContentsView* ShellContentBrowserClient::CreateTabContentsView( TabContents* tab_contents) { #if defined(OS_WIN) return new TabContentsViewWin(tab_contents); +#elif defined(OS_LINUX) + return new TabContentsViewGtk(tab_contents, NULL); #else return NULL; #endif diff --git a/content/shell/shell_gtk.cc b/content/shell/shell_gtk.cc index a08202f..7eda59f 100644 --- a/content/shell/shell_gtk.cc +++ b/content/shell/shell_gtk.cc @@ -1,16 +1,36 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "content/shell/shell.h" +#include <gtk/gtk.h> + #include "base/logging.h" +#include "base/message_loop.h" #include "base/string_piece.h" +#include "content/public/browser/browser_context.h" +#include "content/browser/tab_contents/tab_contents.h" +#include "content/browser/tab_contents/tab_contents_view_gtk.h" +#include "third_party/skia/include/core/SkColor.h" + +namespace { + +// Callback for when the main window is destroyed. +gboolean MainWindowDestroyed(GtkWindow* window) { + // TODO(erg): Only shut down when there are multiple windows. + MessageLoop::current()->PostTask(FROM_HERE, + MessageLoop::QuitClosure()); + + return FALSE; // Don't stop this message. +} + +} // namespace namespace content { void Shell::PlatformInitialize() { - NOTIMPLEMENTED(); + gtk_init(NULL, NULL); } base::StringPiece Shell::PlatformResourceProvider(int key) { @@ -23,22 +43,136 @@ void Shell::PlatformCleanUp() { } void Shell::PlatformEnableUIControl(UIControl control, bool is_enabled) { - NOTIMPLEMENTED(); + GtkToolItem* item = NULL; + switch (control) { + case BACK_BUTTON: + item = back_button_; + break; + case FORWARD_BUTTON: + item = forward_button_; + break; + case STOP_BUTTON: + item = stop_button_; + break; + default: + NOTREACHED() << "Unknown UI control"; + return; + } + gtk_widget_set_sensitive(GTK_WIDGET(item), is_enabled); } void Shell::PlatformSetAddressBarURL(const GURL& url) { } void Shell::PlatformCreateWindow(int width, int height) { - NOTIMPLEMENTED(); + window_ = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL)); + gtk_window_set_title(window_, "Content Shell"); + // Null out window_ when it is destroyed so we don't destroy it twice. + g_signal_connect(G_OBJECT(window_), "destroy", + G_CALLBACK(gtk_widget_destroyed), &window_); + g_signal_connect(G_OBJECT(window_), "destroy", + G_CALLBACK(MainWindowDestroyed), this); + + // TODO(erg): The test shell closes popup windows when the main window goes + // out. + // g_signal_connect(G_OBJECT(window_), "focus-out-event", + // G_CALLBACK(MainWindowLostFocus), this); + + vbox_ = gtk_vbox_new(FALSE, 0); + + GtkWidget* toolbar = gtk_toolbar_new(); + // Turn off the labels on the toolbar buttons. + gtk_toolbar_set_style(GTK_TOOLBAR(toolbar), GTK_TOOLBAR_ICONS); + + back_button_ = gtk_tool_button_new_from_stock(GTK_STOCK_GO_BACK); + g_signal_connect(back_button_, "clicked", + G_CALLBACK(&OnBackButtonClickedThunk), this); + gtk_toolbar_insert(GTK_TOOLBAR(toolbar), back_button_, -1 /* append */); + + forward_button_ = gtk_tool_button_new_from_stock(GTK_STOCK_GO_FORWARD); + g_signal_connect(forward_button_, "clicked", + G_CALLBACK(&OnForwardButtonClickedThunk), this); + gtk_toolbar_insert(GTK_TOOLBAR(toolbar), forward_button_, -1 /* append */); + + reload_button_ = gtk_tool_button_new_from_stock(GTK_STOCK_REFRESH); + g_signal_connect(reload_button_, "clicked", + G_CALLBACK(&OnReloadButtonClickedThunk), this); + gtk_toolbar_insert(GTK_TOOLBAR(toolbar), reload_button_, -1 /* append */); + + stop_button_ = gtk_tool_button_new_from_stock(GTK_STOCK_STOP); + g_signal_connect(stop_button_, "clicked", + G_CALLBACK(&OnStopButtonClickedThunk), this); + gtk_toolbar_insert(GTK_TOOLBAR(toolbar), stop_button_, -1 /* append */); + + url_edit_view_ = gtk_entry_new(); + g_signal_connect(G_OBJECT(url_edit_view_), "activate", + G_CALLBACK(&OnURLEntryActivateThunk), this); + // gtk_entry_set_text(GTK_ENTRY(url_edit_view_), starting_url.spec().c_str()); + + GtkToolItem* tool_item = gtk_tool_item_new(); + gtk_container_add(GTK_CONTAINER(tool_item), url_edit_view_); + gtk_tool_item_set_expand(tool_item, TRUE); + gtk_toolbar_insert(GTK_TOOLBAR(toolbar), tool_item, -1 /* append */); + + gtk_box_pack_start(GTK_BOX(vbox_), toolbar, FALSE, FALSE, 0); + + gtk_container_add(GTK_CONTAINER(window_), vbox_); + gtk_widget_show_all(GTK_WIDGET(window_)); + + PlatformSizeTo(width, height); +} + +void Shell::PlatformSetContents() { + TabContentsViewGtk* content_view = + static_cast<TabContentsViewGtk*>(tab_contents_->GetView()); + gtk_container_add(GTK_CONTAINER(vbox_), content_view->GetNativeView()); + + // As an additional requirement on Linux, we must set the colors for the + // render widgets in webkit. + content::RendererPreferences* prefs = + tab_contents_->GetMutableRendererPrefs(); + prefs->focus_ring_color = SkColorSetARGB(255, 229, 151, 0); + prefs->thumb_active_color = SkColorSetRGB(244, 244, 244); + prefs->thumb_inactive_color = SkColorSetRGB(234, 234, 234); + prefs->track_color = SkColorSetRGB(211, 211, 211); + + prefs->active_selection_bg_color = SkColorSetRGB(30, 144, 255); + prefs->active_selection_fg_color = SK_ColorWHITE; + prefs->inactive_selection_bg_color = SkColorSetRGB(200, 200, 200); + prefs->inactive_selection_fg_color = SkColorSetRGB(50, 50, 50); } void Shell::PlatformSizeTo(int width, int height) { - NOTIMPLEMENTED(); + content_width_ = width; + content_height_ = height; + if (tab_contents_.get()) { + gtk_widget_set_size_request(tab_contents_->GetNativeView(), width, height); + } } void Shell::PlatformResizeSubViews() { - NOTIMPLEMENTED(); + PlatformSizeTo(content_width_, content_height_); +} + +void Shell::OnBackButtonClicked(GtkWidget* widget) { + GoBackOrForward(-1); +} + +void Shell::OnForwardButtonClicked(GtkWidget* widget) { + GoBackOrForward(1); +} + +void Shell::OnReloadButtonClicked(GtkWidget* widget) { + Reload(); +} + +void Shell::OnStopButtonClicked(GtkWidget* widget) { + Stop(); +} + +void Shell::OnURLEntryActivate(GtkWidget* entry) { + const gchar* url = gtk_entry_get_text(GTK_ENTRY(entry)); + LoadURL(GURL(url)); } } // namespace content diff --git a/content/shell/shell_mac.mm b/content/shell/shell_mac.mm index f3f4ba8..bbb993f 100644 --- a/content/shell/shell_mac.mm +++ b/content/shell/shell_mac.mm @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -179,6 +179,10 @@ void Shell::PlatformCreateWindow(int width, int height) { [window_ makeKeyAndOrderFront:nil]; } +void Shell::PlatformSetContents() { + // TODO(erg): I don't know what goes here. +} + void Shell::PlatformSizeTo(int width, int height) { NSRect frame = [window_ frame]; frame.size = NSMakeSize(width, height); diff --git a/content/shell/shell_url_request_context_getter.cc b/content/shell/shell_url_request_context_getter.cc index 05e4893..b21c9b3 100644 --- a/content/shell/shell_url_request_context_getter.cc +++ b/content/shell/shell_url_request_context_getter.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -24,11 +24,21 @@ namespace content { ShellURLRequestContextGetter::ShellURLRequestContextGetter( - const FilePath& base_path_, + const FilePath& base_path, MessageLoop* io_loop, MessageLoop* file_loop) - : io_loop_(io_loop), + : base_path_(base_path), + io_loop_(io_loop), file_loop_(file_loop) { + // Must first be created on the UI thread. + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + + // We must create the proxy config service on the UI loop on Linux because it + // must synchronously run on the glib message loop. This will be passed to + // the URLRequestContextStorage on the IO thread in GetURLRequestContext(). + proxy_config_service_.reset( + net::ProxyService::CreateSystemProxyConfigService( + io_loop_, file_loop_)); } ShellURLRequestContextGetter::~ShellURLRequestContextGetter() { @@ -47,9 +57,6 @@ net::URLRequestContext* ShellURLRequestContextGetter::GetURLRequestContext() { url_request_context_->set_accept_language("en-us,en"); url_request_context_->set_accept_charset("iso-8859-1,*,utf-8"); - scoped_ptr<net::ProxyConfigService> proxy_config_service( - net::ProxyService::CreateSystemProxyConfigService( - io_loop_, file_loop_)); storage_->set_host_resolver( net::CreateSystemHostResolver(net::HostResolver::kDefaultParallelism, net::HostResolver::kDefaultRetryAttempts, @@ -58,7 +65,7 @@ net::URLRequestContext* ShellURLRequestContextGetter::GetURLRequestContext() { // TODO(jam): use v8 if possible, look at chrome code. storage_->set_proxy_service( net::ProxyService::CreateUsingSystemProxyResolver( - proxy_config_service.release(), + proxy_config_service_.release(), 0, NULL)); storage_->set_ssl_config_service(new net::SSLConfigServiceDefaults); diff --git a/content/shell/shell_url_request_context_getter.h b/content/shell/shell_url_request_context_getter.h index 7db1dbe..4e2b0f4 100644 --- a/content/shell/shell_url_request_context_getter.h +++ b/content/shell/shell_url_request_context_getter.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -16,6 +16,7 @@ class MessageLoop; namespace net { class HostResolver; +class ProxyConfigService; class URLRequestContextStorage; } @@ -24,7 +25,7 @@ namespace content { class ShellURLRequestContextGetter : public net::URLRequestContextGetter { public: ShellURLRequestContextGetter( - const FilePath& base_path_, + const FilePath& base_path, MessageLoop* io_loop, MessageLoop* file_loop); virtual ~ShellURLRequestContextGetter(); @@ -42,6 +43,8 @@ class ShellURLRequestContextGetter : public net::URLRequestContextGetter { MessageLoop* io_loop_; MessageLoop* file_loop_; + scoped_ptr<net::ProxyConfigService> proxy_config_service_; + scoped_refptr<net::URLRequestContext> url_request_context_; scoped_ptr<net::URLRequestContextStorage> storage_; diff --git a/content/shell/shell_win.cc b/content/shell/shell_win.cc index 70adb9d..e274b66 100644 --- a/content/shell/shell_win.cc +++ b/content/shell/shell_win.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -12,6 +12,7 @@ #include "base/utf_string_conversions.h" #include "base/win/resource_util.h" #include "content/browser/tab_contents/tab_contents.h" +#include "content/browser/tab_contents/tab_contents_view_win.h" #include "content/shell/resource.h" #include "googleurl/src/gurl.h" #include "grit/webkit_resources.h" @@ -143,6 +144,12 @@ void Shell::PlatformCreateWindow(int width, int height) { PlatformSizeTo(width, height); } +void Shell::PlatformSetContents() { + TabContentsViewWin* view = + static_cast<TabContentsViewWin*>(tab_contents_->GetView()); + view->SetParent(window_); +} + void Shell::PlatformSizeTo(int width, int height) { RECT rc, rw; GetClientRect(window_, &rc); |