diff options
author | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-15 22:14:25 +0000 |
---|---|---|
committer | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-15 22:14:25 +0000 |
commit | b0f146ff51b2b37a2e3549c875fb42365ded7a21 (patch) | |
tree | fc4ee794e7feacbc3d73dfb763b5a90bb11f1041 /content/browser | |
parent | 190efec7b7523f42c0f7e9a5ad80c79c3f68a7d1 (diff) | |
download | chromium_src-b0f146ff51b2b37a2e3549c875fb42365ded7a21.zip chromium_src-b0f146ff51b2b37a2e3549c875fb42365ded7a21.tar.gz chromium_src-b0f146ff51b2b37a2e3549c875fb42365ded7a21.tar.bz2 |
Create a very simple TabContentsView (and not fully implemented yet) and add more supporting code to be able to load a page. Right now it's not rendering, but I suspect it's something small, and the patch has gotten large so I figure it's time to send it for review.
BUG=90445
Review URL: http://codereview.chromium.org/7906008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@101395 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/browser')
-rw-r--r-- | content/browser/browser_main.cc | 4 | ||||
-rw-r--r-- | content/browser/browser_main.h | 6 | ||||
-rw-r--r-- | content/browser/browser_process_sub_thread.cc | 41 | ||||
-rw-r--r-- | content/browser/browser_process_sub_thread.h | 41 | ||||
-rw-r--r-- | content/browser/download/download_manager_delegate.h | 3 | ||||
-rw-r--r-- | content/browser/tab_contents/tab_contents_view_win.cc | 219 | ||||
-rw-r--r-- | content/browser/tab_contents/tab_contents_view_win.h | 89 |
7 files changed, 395 insertions, 8 deletions
diff --git a/content/browser/browser_main.cc b/content/browser/browser_main.cc index cd5fe0a..639e901 100644 --- a/content/browser/browser_main.cc +++ b/content/browser/browser_main.cc @@ -17,6 +17,7 @@ #include "content/common/content_switches.h" #include "content/common/hi_res_timer_manager.h" #include "content/common/main_function_params.h" +#include "content/common/notification_service.h" #include "content/common/result_codes.h" #include "content/common/sandbox_policy.h" #include "crypto/nss_util.h" @@ -346,6 +347,8 @@ void BrowserMainParts::ToolkitInitialized() { int BrowserMain(const MainFunctionParams& parameters) { TRACE_EVENT_BEGIN_ETW("BrowserMain", 0, ""); + NotificationService main_notification_service; + scoped_ptr<content::BrowserMainParts> parts( content::GetContentClient()->browser()->CreateBrowserMainParts( parameters)); @@ -401,7 +404,6 @@ int BrowserMain(const MainFunctionParams& parameters) { base::win::ScopedCOMInitializer com_initializer; #endif // OS_WIN - // Initialize histogram statistics gathering system. base::StatisticsRecorder statistics; parts->RunMainMessageLoopParts(); diff --git a/content/browser/browser_main.h b/content/browser/browser_main.h index bab45a0..f3d9234 100644 --- a/content/browser/browser_main.h +++ b/content/browser/browser_main.h @@ -124,12 +124,6 @@ class BrowserMainParts { DISALLOW_COPY_AND_ASSIGN(BrowserMainParts); }; -// Perform platform-specific work that needs to be done after the main event -// loop has ended. The embedder must be sure to call this. -// TODO(jam): change this so that content calls it so that we don't depend on -// the embedder. -void DidEndMainMessageLoop(); - } // namespace content #endif // CONTENT_BROWSER_BROWSER_MAIN_H_ diff --git a/content/browser/browser_process_sub_thread.cc b/content/browser/browser_process_sub_thread.cc new file mode 100644 index 0000000..ed904a3 --- /dev/null +++ b/content/browser/browser_process_sub_thread.cc @@ -0,0 +1,41 @@ +// Copyright (c) 2011 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/browser/browser_process_sub_thread.h" + +#include "build/build_config.h" +#include "content/common/notification_service.h" + +#if defined(OS_WIN) +#include <Objbase.h> +#endif + +BrowserProcessSubThread::BrowserProcessSubThread(BrowserThread::ID identifier) + : BrowserThread(identifier) {} + +BrowserProcessSubThread::~BrowserProcessSubThread() { + // We cannot rely on our base class to stop the thread since we want our + // CleanUp function to run. + Stop(); +} + +void BrowserProcessSubThread::Init() { +#if defined(OS_WIN) + // Initializes the COM library on the current thread. + CoInitialize(NULL); +#endif + + notification_service_ = new NotificationService; +} + +void BrowserProcessSubThread::CleanUp() { + delete notification_service_; + notification_service_ = NULL; + +#if defined(OS_WIN) + // Closes the COM library on the current thread. CoInitialize must + // be balanced by a corresponding call to CoUninitialize. + CoUninitialize(); +#endif +} diff --git a/content/browser/browser_process_sub_thread.h b/content/browser/browser_process_sub_thread.h new file mode 100644 index 0000000..55978e6 --- /dev/null +++ b/content/browser/browser_process_sub_thread.h @@ -0,0 +1,41 @@ +// Copyright (c) 2010 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. + +#ifndef CONTENT_BROWSER_BROWSER_PROCESS_SUB_THREAD_H_ +#define CONTENT_BROWSER_BROWSER_PROCESS_SUB_THREAD_H_ +#pragma once + +#include "base/basictypes.h" +#include "content/browser/browser_thread.h" + +class NotificationService; + +// ---------------------------------------------------------------------------- +// BrowserProcessSubThread +// +// This simple thread object is used for the specialized threads that the +// BrowserProcess spins up. +// +// Applications must initialize the COM library before they can call +// COM library functions other than CoGetMalloc and memory allocation +// functions, so this class initializes COM for those users. +class BrowserProcessSubThread : public BrowserThread { + public: + explicit BrowserProcessSubThread(BrowserThread::ID identifier); + virtual ~BrowserProcessSubThread(); + + protected: + virtual void Init(); + virtual void CleanUp(); + + private: + // Each specialized thread has its own notification service. + // Note: We don't use scoped_ptr because the destructor runs on the wrong + // thread. + NotificationService* notification_service_; + + DISALLOW_COPY_AND_ASSIGN(BrowserProcessSubThread); +}; + +#endif // CONTENT_BROWSER_BROWSER_PROCESS_SUB_THREAD_H_ diff --git a/content/browser/download/download_manager_delegate.h b/content/browser/download/download_manager_delegate.h index 1094bd1..55d25f6 100644 --- a/content/browser/download/download_manager_delegate.h +++ b/content/browser/download/download_manager_delegate.h @@ -18,6 +18,8 @@ class SavePackage; // Browser's download manager: manages all downloads and destination view. class DownloadManagerDelegate { public: + virtual ~DownloadManagerDelegate() {} + // Lets the delegate know that the download manager is shutting down. virtual void Shutdown() = 0; @@ -105,7 +107,6 @@ class DownloadManagerDelegate { protected: DownloadManagerDelegate() {} - virtual ~DownloadManagerDelegate() {} DISALLOW_COPY_AND_ASSIGN(DownloadManagerDelegate); }; diff --git a/content/browser/tab_contents/tab_contents_view_win.cc b/content/browser/tab_contents/tab_contents_view_win.cc new file mode 100644 index 0000000..9382321 --- /dev/null +++ b/content/browser/tab_contents/tab_contents_view_win.cc @@ -0,0 +1,219 @@ +// Copyright (c) 2011 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/browser/tab_contents/tab_contents_view_win.h" + +#include "content/browser/renderer_host/render_widget_host_view_win.h" +#include "content/browser/tab_contents/constrained_window.h" +#include "content/browser/tab_contents/interstitial_page.h" +#include "content/browser/tab_contents/tab_contents.h" +#include "content/browser/tab_contents/tab_contents_delegate.h" + +TabContentsViewWin::TabContentsViewWin(TabContents* tab_contents) + : tab_contents_(tab_contents), + view_(NULL) { +} + +TabContentsViewWin::~TabContentsViewWin() { +} + +void TabContentsViewWin::CreateView(const gfx::Size& initial_size) { + // temporary until we specify parent + set_window_style(WS_CAPTION | WS_VISIBLE | WS_SYSMENU); + set_window_ex_style(WS_EX_APPWINDOW); + + // TODO(jam): specify a correct parent! + Init(NULL, gfx::Rect(initial_size)); +} + +RenderWidgetHostView* TabContentsViewWin::CreateViewForWidget( + RenderWidgetHost* render_widget_host) { + if (view_) + delete view_; // TODO(jam): need to do anything else? + + view_ = new RenderWidgetHostViewWin(render_widget_host); + view_->Show(); + return view_; +} + +gfx::NativeView TabContentsViewWin::GetNativeView() const { + return hwnd(); +} + +gfx::NativeView TabContentsViewWin::GetContentNativeView() const { + RenderWidgetHostView* rwhv = tab_contents_->GetRenderWidgetHostView(); + return rwhv ? rwhv->GetNativeView() : NULL; +} + +gfx::NativeWindow TabContentsViewWin::GetTopLevelNativeWindow() const { + // TODO(jam): return parent! + return NULL; +} + +void TabContentsViewWin::GetContainerBounds(gfx::Rect *out) const { + // Copied from NativeWidgetWin::GetClientAreaScreenBounds(). + RECT r; + GetClientRect(hwnd(), &r); + POINT point = { r.left, r.top }; + ClientToScreen(hwnd(), &point); + *out = gfx::Rect(point.x, point.y, r.right - r.left, r.bottom - r.top); +} + +void TabContentsViewWin::SetPageTitle(const std::wstring& title) { +} + +void TabContentsViewWin::OnTabCrashed(base::TerminationStatus status, + int error_code) { +} + +void TabContentsViewWin::SizeContents(const gfx::Size& size) { + gfx::Rect bounds; + GetContainerBounds(&bounds); + if (bounds.size() != size) { + SetWindowPos(hwnd(), NULL, 0, 0, size.width(), size.height(), + SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOMOVE); + } else { + // Our size matches what we want but the renderers size may not match. + // Pretend we were resized so that the renderers size is updated too. + if (tab_contents_->interstitial_page()) + tab_contents_->interstitial_page()->SetSize(size); + RenderWidgetHostView* rwhv = tab_contents_->GetRenderWidgetHostView(); + if (rwhv) + rwhv->SetSize(size); + } +} + +void TabContentsViewWin::RenderViewCreated(RenderViewHost* host) { +} + +void TabContentsViewWin::Focus() { + if (tab_contents_->interstitial_page()) { + tab_contents_->interstitial_page()->Focus(); + return; + } + + if (tab_contents_->constrained_window_count() > 0) { + ConstrainedWindow* window = *tab_contents_->constrained_window_begin(); + DCHECK(window); + window->FocusConstrainedWindow(); + return; + } + + RenderWidgetHostView* rwhv = tab_contents_->GetRenderWidgetHostView(); + if (rwhv) { + rwhv->Focus(); + } else { + SetFocus(hwnd()); + } +} + +void TabContentsViewWin::SetInitialFocus() { + if (tab_contents_->FocusLocationBarByDefault()) + tab_contents_->SetFocusToLocationBar(false); + else + Focus(); +} + +void TabContentsViewWin::StoreFocus() { + // TODO(jam): why is this on TabContentsView? + NOTREACHED(); +} + +void TabContentsViewWin::RestoreFocus() { + NOTREACHED(); +} + +bool TabContentsViewWin::IsDoingDrag() const { + return false; +} + +void TabContentsViewWin::CancelDragAndCloseTab() { +} + +bool TabContentsViewWin::IsEventTracking() const { + return false; +} + +void TabContentsViewWin::CloseTabAfterEventTracking() { +} + +void TabContentsViewWin::GetViewBounds(gfx::Rect* out) const { + RECT r; + GetWindowRect(hwnd(), &r); + *out = gfx::Rect(r); +} + +void TabContentsViewWin::CreateNewWindow( + int route_id, + const ViewHostMsg_CreateWindow_Params& params) { + NOTIMPLEMENTED(); +} + + +void TabContentsViewWin::CreateNewWidget(int route_id, + WebKit::WebPopupType popup_type) { + NOTIMPLEMENTED(); +} + +void TabContentsViewWin::CreateNewFullscreenWidget(int route_id) { + NOTIMPLEMENTED(); +} + +void TabContentsViewWin::ShowCreatedWindow(int route_id, + WindowOpenDisposition disposition, + const gfx::Rect& initial_pos, + bool user_gesture) { + NOTIMPLEMENTED(); +} + +void TabContentsViewWin::ShowCreatedWidget(int route_id, + const gfx::Rect& initial_pos) { + NOTIMPLEMENTED(); +} + +void TabContentsViewWin::ShowCreatedFullscreenWidget(int route_id) { + NOTIMPLEMENTED(); +} + +void TabContentsViewWin::ShowContextMenu(const ContextMenuParams& params) { + NOTIMPLEMENTED(); +} + +void TabContentsViewWin::ShowPopupMenu(const gfx::Rect& bounds, + int item_height, + double item_font_size, + int selected_item, + const std::vector<WebMenuItem>& items, + bool right_aligned) { + NOTIMPLEMENTED(); +} + +void TabContentsViewWin::StartDragging(const WebDropData& drop_data, + WebKit::WebDragOperationsMask operations, + const SkBitmap& image, + const gfx::Point& image_offset) { + NOTIMPLEMENTED(); +} + +void TabContentsViewWin::UpdateDragCursor(WebKit::WebDragOperation operation) { + NOTIMPLEMENTED(); +} + +void TabContentsViewWin::GotFocus() { + if (tab_contents_->delegate()) + tab_contents_->delegate()->TabContentsFocused(tab_contents_); +} + +void TabContentsViewWin::TakeFocus(bool reverse) { + if (tab_contents_->delegate()) + tab_contents_->delegate()->TakeFocus(reverse); +} + +LRESULT TabContentsViewWin::OnClose(UINT message, + WPARAM wparam, + LPARAM lparam, + BOOL& handled) { + MessageLoop::current()->Quit(); + return 0; +} diff --git a/content/browser/tab_contents/tab_contents_view_win.h b/content/browser/tab_contents/tab_contents_view_win.h new file mode 100644 index 0000000..4ec5719 --- /dev/null +++ b/content/browser/tab_contents/tab_contents_view_win.h @@ -0,0 +1,89 @@ +// Copyright (c) 2011 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. + +#ifndef CONTENT_BROWSER_TAB_CONTENTS_TAB_CONTENTS_VIEW_WIN_H_ +#define CONTENT_BROWSER_TAB_CONTENTS_TAB_CONTENTS_VIEW_WIN_H_ +#pragma once + +#include "content/browser/tab_contents/tab_contents_view.h" +#include "ui/base/win/window_impl.h" + +class RenderWidgetHostViewWin; + +// An implementation of TabContentsView for Windows. +class TabContentsViewWin : public TabContentsView, + public ui::WindowImpl { + public: + explicit TabContentsViewWin(TabContents* tab_contents); + virtual ~TabContentsViewWin(); + + BEGIN_MSG_MAP_EX(TabContentsViewWin) + MESSAGE_HANDLER(WM_CLOSE, OnClose) + END_MSG_MAP() + + // Overridden from TabContentsView: + virtual void CreateView(const gfx::Size& initial_size) OVERRIDE; + virtual RenderWidgetHostView* CreateViewForWidget( + RenderWidgetHost* render_widget_host) OVERRIDE; + virtual gfx::NativeView GetNativeView() const OVERRIDE; + virtual gfx::NativeView GetContentNativeView() const OVERRIDE; + virtual gfx::NativeWindow GetTopLevelNativeWindow() const OVERRIDE; + virtual void GetContainerBounds(gfx::Rect *out) const OVERRIDE; + virtual void SetPageTitle(const std::wstring& title) OVERRIDE; + virtual void OnTabCrashed(base::TerminationStatus status, + int error_code) OVERRIDE; + virtual void SizeContents(const gfx::Size& size) OVERRIDE; + virtual void RenderViewCreated(RenderViewHost* host) OVERRIDE; + virtual void Focus() OVERRIDE; + virtual void SetInitialFocus() OVERRIDE; + virtual void StoreFocus() OVERRIDE; + virtual void RestoreFocus() OVERRIDE; + virtual bool IsDoingDrag() const OVERRIDE; + virtual void CancelDragAndCloseTab() OVERRIDE; + virtual bool IsEventTracking() const OVERRIDE; + virtual void CloseTabAfterEventTracking() OVERRIDE; + virtual void GetViewBounds(gfx::Rect* out) const OVERRIDE; + + // Implementation of RenderViewHostDelegate::View. + virtual void CreateNewWindow( + int route_id, + const ViewHostMsg_CreateWindow_Params& params) OVERRIDE; + virtual void CreateNewWidget(int route_id, + WebKit::WebPopupType popup_type) OVERRIDE; + virtual void CreateNewFullscreenWidget(int route_id) OVERRIDE; + virtual void ShowCreatedWindow(int route_id, + WindowOpenDisposition disposition, + const gfx::Rect& initial_pos, + bool user_gesture) OVERRIDE; + virtual void ShowCreatedWidget(int route_id, + const gfx::Rect& initial_pos) OVERRIDE; + virtual void ShowCreatedFullscreenWidget(int route_id) OVERRIDE; + virtual void ShowContextMenu(const ContextMenuParams& params) OVERRIDE; + virtual void ShowPopupMenu(const gfx::Rect& bounds, + int item_height, + double item_font_size, + int selected_item, + const std::vector<WebMenuItem>& items, + bool right_aligned) OVERRIDE; + virtual void StartDragging(const WebDropData& drop_data, + WebKit::WebDragOperationsMask operations, + const SkBitmap& image, + const gfx::Point& image_offset) OVERRIDE; + virtual void UpdateDragCursor(WebKit::WebDragOperation operation) OVERRIDE; + virtual void GotFocus() OVERRIDE; + virtual void TakeFocus(bool reverse) OVERRIDE; + + private: + // Window message handlers. + LRESULT OnClose(UINT message, WPARAM wparam, LPARAM lparam, BOOL& handled); + + // The TabContents whose contents we display. + TabContents* tab_contents_; + + RenderWidgetHostViewWin* view_; + + DISALLOW_COPY_AND_ASSIGN(TabContentsViewWin); +}; + +#endif // CONTENT_BROWSER_TAB_CONTENTS_TAB_CONTENTS_VIEW_WIN_H_ |