diff options
author | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-26 17:22:54 +0000 |
---|---|---|
committer | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-26 17:22:54 +0000 |
commit | e99ca5111f19b5401f0e18e52a0ebbddc8a36f78 (patch) | |
tree | 783c4faacbaf48e2bdfd40aa4bbb6ee38079bbb9 | |
parent | 30fcaa494a7c2fd728821d603816d19f764857f6 (diff) | |
download | chromium_src-e99ca5111f19b5401f0e18e52a0ebbddc8a36f78.zip chromium_src-e99ca5111f19b5401f0e18e52a0ebbddc8a36f78.tar.gz chromium_src-e99ca5111f19b5401f0e18e52a0ebbddc8a36f78.tar.bz2 |
A few improvements to content_shell:
-support multiple windows, this allows window.open to work
-add menu to create new windows-update buttons and url bar
-ensure we destruct ResourceContext on the right thread
-ensure we destruct BrowserContext while all the threads are still alive
-add http:// to the url if the user forgot to enter it
BUG= 90445
Review URL: http://codereview.chromium.org/8043011
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@102749 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | content/browser/mock_content_browser_client.cc | 2 | ||||
-rw-r--r-- | content/browser/tab_contents/tab_contents_view_win.cc | 26 | ||||
-rw-r--r-- | content/browser/tab_contents/tab_contents_view_win.h | 12 | ||||
-rw-r--r-- | content/browser/tab_contents/tab_contents_view_win_delegate.h | 32 | ||||
-rw-r--r-- | content/content_shell.gypi | 1 | ||||
-rw-r--r-- | content/shell/resource.h | 2 | ||||
-rw-r--r-- | content/shell/shell.cc | 44 | ||||
-rw-r--r-- | content/shell/shell.h | 33 | ||||
-rw-r--r-- | content/shell/shell.rc | 2 | ||||
-rw-r--r-- | content/shell/shell_browser_context.cc | 26 | ||||
-rw-r--r-- | content/shell/shell_browser_context.h | 2 | ||||
-rw-r--r-- | content/shell/shell_browser_main.cc | 8 | ||||
-rw-r--r-- | content/shell/shell_content_browser_client.cc | 22 | ||||
-rw-r--r-- | content/shell/shell_content_browser_client.h | 18 | ||||
-rw-r--r-- | content/shell/shell_gtk.cc | 3 | ||||
-rw-r--r-- | content/shell/shell_mac.mm | 3 | ||||
-rw-r--r-- | content/shell/shell_win.cc | 29 |
17 files changed, 227 insertions, 38 deletions
diff --git a/content/browser/mock_content_browser_client.cc b/content/browser/mock_content_browser_client.cc index be23fd8..7544246 100644 --- a/content/browser/mock_content_browser_client.cc +++ b/content/browser/mock_content_browser_client.cc @@ -188,7 +188,7 @@ bool MockContentBrowserClient::CanCreateWindow( const GURL& source_url, WindowContainerType container_type, const content::ResourceContext& context) { - return false; + return true; } std::string MockContentBrowserClient::GetWorkerProcessTitle( diff --git a/content/browser/tab_contents/tab_contents_view_win.cc b/content/browser/tab_contents/tab_contents_view_win.cc index ffcc837..692b04f 100644 --- a/content/browser/tab_contents/tab_contents_view_win.cc +++ b/content/browser/tab_contents/tab_contents_view_win.cc @@ -4,15 +4,19 @@ #include "content/browser/tab_contents/tab_contents_view_win.h" +#include "content/browser/renderer_host/render_view_host.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" +#include "content/browser/tab_contents/tab_contents_view_win_delegate.h" -TabContentsViewWin::TabContentsViewWin(TabContents* tab_contents) +TabContentsViewWin::TabContentsViewWin(TabContents* tab_contents, + TabContentsViewWinDelegate* delegate) : parent_(NULL), tab_contents_(tab_contents), + delegate_(delegate), view_(NULL) { } @@ -40,6 +44,7 @@ RenderWidgetHostView* TabContentsViewWin::CreateViewForWidget( view_ = new RenderWidgetHostViewWin(render_widget_host); view_->CreateWnd(GetNativeView()); view_->ShowWindow(SW_SHOW); + view_->SetSize(initial_size_); return view_; } @@ -152,9 +157,13 @@ void TabContentsViewWin::GetViewBounds(gfx::Rect* out) const { void TabContentsViewWin::CreateNewWindow( int route_id, const ViewHostMsg_CreateWindow_Params& params) { - NOTIMPLEMENTED(); -} + TabContents* tab = delegate_->CreateNewWindow(this, route_id, params); + // Copy logic from RenderViewHostDelegateViewHelper. + TabContentsView* new_view = tab->view(); + new_view->CreateViewForWidget(tab->render_view_host()); + pending_contents_[route_id] = tab->render_view_host(); +} void TabContentsViewWin::CreateNewWidget(int route_id, WebKit::WebPopupType popup_type) { @@ -169,7 +178,16 @@ void TabContentsViewWin::ShowCreatedWindow(int route_id, WindowOpenDisposition disposition, const gfx::Rect& initial_pos, bool user_gesture) { - NOTIMPLEMENTED(); + PendingContents::iterator iter = pending_contents_.find(route_id); + if (iter == pending_contents_.end()) + return; + + RenderViewHost* new_rvh = iter->second; + pending_contents_.erase(route_id); + if (!new_rvh->process()->HasConnection() || + (new_rvh->delegate()->GetAsTabContents() && !new_rvh->view())) + return; + new_rvh->Init(); } void TabContentsViewWin::ShowCreatedWidget(int route_id, diff --git a/content/browser/tab_contents/tab_contents_view_win.h b/content/browser/tab_contents/tab_contents_view_win.h index c647406..6903979 100644 --- a/content/browser/tab_contents/tab_contents_view_win.h +++ b/content/browser/tab_contents/tab_contents_view_win.h @@ -6,16 +6,20 @@ #define CONTENT_BROWSER_TAB_CONTENTS_TAB_CONTENTS_VIEW_WIN_H_ #pragma once +#include <map> + #include "content/browser/tab_contents/tab_contents_view.h" #include "ui/base/win/window_impl.h" class RenderWidgetHostViewWin; +class TabContentsViewWinDelegate; // An implementation of TabContentsView for Windows. class TabContentsViewWin : public TabContentsView, public ui::WindowImpl { public: - explicit TabContentsViewWin(TabContents* tab_contents); + TabContentsViewWin(TabContents* tab_contents, + TabContentsViewWinDelegate* delegate); virtual ~TabContentsViewWin(); void SetParent(HWND parent); @@ -76,6 +80,8 @@ class TabContentsViewWin : public TabContentsView, virtual void GotFocus() OVERRIDE; virtual void TakeFocus(bool reverse) OVERRIDE; + TabContents* tab_contents() const { return tab_contents_; } + private: LRESULT OnWindowPosChanged( UINT message, WPARAM wparam, LPARAM lparam, BOOL& handled); @@ -86,9 +92,13 @@ class TabContentsViewWin : public TabContentsView, // The TabContents whose contents we display. TabContents* tab_contents_; + TabContentsViewWinDelegate* delegate_; RenderWidgetHostViewWin* view_; + typedef std::map<int, RenderViewHost*> PendingContents; + PendingContents pending_contents_; + DISALLOW_COPY_AND_ASSIGN(TabContentsViewWin); }; diff --git a/content/browser/tab_contents/tab_contents_view_win_delegate.h b/content/browser/tab_contents/tab_contents_view_win_delegate.h new file mode 100644 index 0000000..76d7fc2 --- /dev/null +++ b/content/browser/tab_contents/tab_contents_view_win_delegate.h @@ -0,0 +1,32 @@ +// 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_DELEGATE_H_ +#define CONTENT_BROWSER_TAB_CONTENTS_TAB_CONTENTS_VIEW_WIN_DELEGATE_H_ +#pragma once + +#include "base/basictypes.h" + +class TabContents; +class TabContentsViewWin; +struct ViewHostMsg_CreateWindow_Params; + +// A delegate interface for TabContentsViewWin. +class TabContentsViewWinDelegate { + public: + virtual ~TabContentsViewWinDelegate() {} + + // These match the TabContentsView methods. + virtual TabContents* CreateNewWindow( + TabContentsViewWin* tab_contents_view, + int route_id, + const ViewHostMsg_CreateWindow_Params& params) = 0; + + protected: + TabContentsViewWinDelegate() {} + + DISALLOW_COPY_AND_ASSIGN(TabContentsViewWinDelegate); +}; + +#endif // CONTENT_BROWSER_TAB_CONTENTS_TAB_CONTENTS_VIEW_WIN_DELEGATE_H_ diff --git a/content/content_shell.gypi b/content/content_shell.gypi index 9b61b84..840c926 100644 --- a/content/content_shell.gypi +++ b/content/content_shell.gypi @@ -31,6 +31,7 @@ 'browser/download/mock_download_manager_delegate.cc', 'browser/tab_contents/tab_contents_view_win.cc', 'browser/tab_contents/tab_contents_view_win.h', + 'browser/tab_contents/tab_contents_view_win_delegate.h', 'shell/shell.cc', 'shell/shell.h', 'shell/shell_gtk.cc', diff --git a/content/shell/resource.h b/content/shell/resource.h index 6a0d6c7..291f3f4 100644 --- a/content/shell/resource.h +++ b/content/shell/resource.h @@ -10,6 +10,8 @@ #define IDR_MAINFRAME 128 #define IDM_EXIT 105 +#define IDM_CLOSE_WINDOW 106 +#define IDM_NEW_WINDOW 107 #define IDC_CONTENTSHELL 109 #define IDC_NAV_BACK 1001 #define IDC_NAV_FORWARD 1002 diff --git a/content/shell/shell.cc b/content/shell/shell.cc index a41c91c..a6d276c 100644 --- a/content/shell/shell.cc +++ b/content/shell/shell.cc @@ -9,7 +9,6 @@ #include "base/string_util.h" #include "content/browser/tab_contents/navigation_controller.h" #include "content/browser/tab_contents/tab_contents.h" -#include "content/shell/shell_browser_context.h" #include "ui/gfx/size.h" #if defined(OS_WIN) @@ -22,7 +21,7 @@ static const int kTestWindowHeight = 600; namespace content { -int Shell::shell_count_; +std::vector<Shell*> Shell::windows_; Shell::Shell() : main_window_(NULL), @@ -31,15 +30,25 @@ Shell::Shell() , default_edit_wnd_proc_(0) #endif { - shell_count_++; + windows_.push_back(this); } Shell::~Shell() { PlatformCleanUp(); - --shell_count_; + + for (size_t i = 0; i < windows_.size(); ++i) { + if (windows_[i] == this) { + windows_.erase(windows_.begin() + i); + break; + } + } } -Shell* Shell::CreateNewWindow(ShellBrowserContext* browser_context) { +Shell* Shell::CreateNewWindow(content::BrowserContext* browser_context, + const GURL& url, + SiteInstance* site_instance, + int routing_id, + TabContents* base_tab_contents) { Shell* shell = new Shell(); shell->PlatformCreateWindow(); @@ -47,10 +56,11 @@ Shell* Shell::CreateNewWindow(ShellBrowserContext* browser_context) { shell->tab_contents_.reset(new TabContents( browser_context, - NULL, - MSG_ROUTING_NONE, - NULL, + site_instance, + routing_id, + base_tab_contents, NULL)); + shell->tab_contents_->set_delegate(shell); #if defined (OS_WIN) TabContentsViewWin* view = @@ -60,7 +70,8 @@ Shell* Shell::CreateNewWindow(ShellBrowserContext* browser_context) { shell->PlatformResizeSubViews(); - shell->LoadURL(GURL("http://www.google.com")); + if (!url.is_empty()) + shell->LoadURL(url); return shell; } @@ -90,7 +101,7 @@ void Shell::UpdateNavigationControls() { PlatformEnableUIControl(BACK_BUTTON, current_index > 0); PlatformEnableUIControl(FORWARD_BUTTON, current_index < max_index); - PlatformEnableUIControl(STOP_BUTTON, true);//is_loading_); + PlatformEnableUIControl(STOP_BUTTON, tab_contents_->IsLoading()); } gfx::NativeView Shell::GetContentView() { @@ -99,4 +110,17 @@ gfx::NativeView Shell::GetContentView() { return tab_contents_->GetNativeView(); } +void Shell::LoadingStateChanged(TabContents* source) { + UpdateNavigationControls(); +} + +void Shell::DidNavigateMainFramePostCommit(TabContents* tab) { + PlatformSetAddressBarURL(tab->GetURL()); +} + +void Shell::UpdatePreferredSize(TabContents* source, + const gfx::Size& pref_size) { + PlatformSizeTo(pref_size.width(), pref_size.height()); +} + } // namespace content diff --git a/content/shell/shell.h b/content/shell/shell.h index ac53ac5..bea9814 100644 --- a/content/shell/shell.h +++ b/content/shell/shell.h @@ -7,11 +7,15 @@ #pragma once +#include <vector> + #include "base/basictypes.h" #include "base/memory/scoped_ptr.h" +#include "content/browser/tab_contents/tab_contents_delegate.h" #include "ui/gfx/native_widget_types.h" class GURL; +class SiteInstance; class TabContents; namespace base { @@ -20,13 +24,13 @@ class StringPiece; namespace content { -class ShellBrowserContext; +class BrowserContext; // This represents one window of the Content Shell, i.e. all the UI including // buttons and url bar, as well as the web content area. -class Shell { +class Shell : public TabContentsDelegate { public: - ~Shell(); + virtual ~Shell(); void LoadURL(const GURL& url); void GoBackOrForward(int offset); @@ -40,7 +44,16 @@ class Shell { // This is called indirectly by the modules that need access resources. static base::StringPiece PlatformResourceProvider(int key); - static Shell* CreateNewWindow(ShellBrowserContext* browser_context); + static Shell* CreateNewWindow(content::BrowserContext* browser_context, + const GURL& url, + SiteInstance* site_instance, + int routing_id, + TabContents* base_tab_contents); + + // Closes all windows and exits. + static void PlatformExit(); + + TabContents* tab_contents() const { return tab_contents_.get(); } private: enum UIControl { @@ -63,9 +76,17 @@ class Shell { void PlatformResizeSubViews(); // Enable/disable a button. void PlatformEnableUIControl(UIControl control, bool is_enabled); + // Updates the url in the url bar. + void PlatformSetAddressBarURL(const GURL& url); gfx::NativeView GetContentView(); + // TabContentsDelegate + virtual void LoadingStateChanged(TabContents* source) OVERRIDE; + virtual void DidNavigateMainFramePostCommit(TabContents* tab) OVERRIDE; + virtual void UpdatePreferredSize(TabContents* source, + const gfx::Size& pref_size) OVERRIDE; + #if defined(OS_WIN) static ATOM RegisterWindowClass(); static LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); @@ -82,7 +103,9 @@ class Shell { static HINSTANCE instance_handle_; #endif - static int shell_count_; + // A container of all the open windows. We use a vector so we can keep track + // of ordering. + static std::vector<Shell*> windows_; }; } // namespace content diff --git a/content/shell/shell.rc b/content/shell/shell.rc index 6d34fb8..e85ec17 100644 --- a/content/shell/shell.rc +++ b/content/shell/shell.rc @@ -26,6 +26,8 @@ IDC_CONTENTSHELL MENU BEGIN
POPUP "&File"
BEGIN
+ MENUITEM "&New Window", IDM_NEW_WINDOW
+ MENUITEM "&Close Window", IDM_CLOSE_WINDOW
MENUITEM "E&xit", IDM_EXIT
END
END
diff --git a/content/shell/shell_browser_context.cc b/content/shell/shell_browser_context.cc index fed9fba..b49f758 100644 --- a/content/shell/shell_browser_context.cc +++ b/content/shell/shell_browser_context.cc @@ -80,15 +80,15 @@ class ShellURLRequestContextGetter : public net::URLRequestContextGetter { dnsrr_resolver_.reset(new net::DnsRRResolver()); - proxy_config_service_.reset( + net::ProxyConfigService* proxy_config_service = net::ProxyService::CreateSystemProxyConfigService( io_loop_, - file_loop_)); + file_loop_); // TODO(jam): use v8 if possible, look at chrome code. proxy_service_.reset( net::ProxyService::CreateUsingSystemProxyResolver( - proxy_config_service_.get(), + proxy_config_service, 0, net_log)); @@ -163,7 +163,6 @@ class ShellURLRequestContextGetter : public net::URLRequestContextGetter { scoped_ptr<net::CertVerifier> cert_verifier_; scoped_ptr<net::OriginBoundCertService> origin_bound_cert_service_; scoped_ptr<net::DnsRRResolver> dnsrr_resolver_; - scoped_ptr<net::ProxyConfigService> proxy_config_service_; scoped_ptr<net::ProxyService> proxy_service_; scoped_ptr<net::HttpAuthHandlerFactory> http_auth_handler_factory_; scoped_ptr<net::URLSecurityManager> url_security_manager_; @@ -228,22 +227,27 @@ ShellBrowserContext::ShellBrowserContext( } ShellBrowserContext::~ShellBrowserContext() { + if (resource_context_.get()) { + BrowserThread::DeleteSoon( + BrowserThread::IO, FROM_HERE, resource_context_.release()); + } } FilePath ShellBrowserContext::GetPath() { - FilePath result; + if (!path_.empty()) + return path_; #if defined(OS_WIN) - CHECK(PathService::Get(base::DIR_LOCAL_APP_DATA, &result)); - result.Append(std::wstring(L"content_shell")); + CHECK(PathService::Get(base::DIR_LOCAL_APP_DATA, &path_)); + path_ = path_.Append(std::wstring(L"content_shell")); #else NOTIMPLEMENTED(); #endif - if (!file_util::PathExists(result)) - file_util::CreateDirectory(result); + if (!file_util::PathExists(path_)) + file_util::CreateDirectory(path_); - return result; + return path_; } bool ShellBrowserContext::IsOffTheRecord() { @@ -359,6 +363,8 @@ fileapi::FileSystemContext* ShellBrowserContext::GetFileSystemContext() { } void ShellBrowserContext::CreateQuotaManagerAndClients() { + if (quota_manager_.get()) + return; quota_manager_ = new quota::QuotaManager( IsOffTheRecord(), GetPath(), diff --git a/content/shell/shell_browser_context.h b/content/shell/shell_browser_context.h index feed65d..b5806c5 100644 --- a/content/shell/shell_browser_context.h +++ b/content/shell/shell_browser_context.h @@ -7,6 +7,7 @@ #pragma once #include "base/compiler_specific.h" +#include "base/file_path.h" #include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" #include "content/browser/browser_context.h" @@ -53,6 +54,7 @@ class ShellBrowserContext : public BrowserContext { private: void CreateQuotaManagerAndClients(); + FilePath path_; scoped_ptr<ResourceContext> resource_context_; scoped_ptr<SSLHostState> ssl_host_state_; scoped_ptr<DownloadStatusUpdater> download_status_updater_; diff --git a/content/shell/shell_browser_main.cc b/content/shell/shell_browser_main.cc index dabfa13..73176a8 100644 --- a/content/shell/shell_browser_main.cc +++ b/content/shell/shell_browser_main.cc @@ -33,6 +33,8 @@ ShellBrowserMainParts::~ShellBrowserMainParts() { FROM_HERE, NewRunnableFunction(&base::ThreadRestrictions::SetIOAllowed, true)); + browser_context_.reset(); + resource_dispatcher_host_->Shutdown(); io_thread_.reset(); cache_thread_.reset(); @@ -64,7 +66,11 @@ void ShellBrowserMainParts::PreMainMessageLoopRun() { Shell::PlatformInitialize(); net::NetModule::SetResourceProvider(Shell::PlatformResourceProvider); - Shell::CreateNewWindow(browser_context_.get()); + Shell::CreateNewWindow(browser_context_.get(), + GURL("http://www.google.com"), + NULL, + MSG_ROUTING_NONE, + NULL); } ResourceDispatcherHost* ShellBrowserMainParts::GetResourceDispatcherHost() { diff --git a/content/shell/shell_content_browser_client.cc b/content/shell/shell_content_browser_client.cc index 41a89ce..9452759 100644 --- a/content/shell/shell_content_browser_client.cc +++ b/content/shell/shell_content_browser_client.cc @@ -6,13 +6,16 @@ #include "base/file_path.h" #include "content/browser/webui/empty_web_ui_factory.h" +#include "content/shell/shell.h" #include "content/shell/shell_browser_main.h" #include "googleurl/src/gurl.h" #include "third_party/skia/include/core/SkBitmap.h" #include "webkit/glue/webpreferences.h" #if defined(OS_WIN) +#include "content/browser/tab_contents/tab_contents.h" #include "content/browser/tab_contents/tab_contents_view_win.h" +#include "content/common/view_messages.h" #endif namespace content { @@ -32,7 +35,7 @@ BrowserMainParts* ShellContentBrowserClient::CreateBrowserMainParts( TabContentsView* ShellContentBrowserClient::CreateTabContentsView( TabContents* tab_contents) { #if defined(OS_WIN) - return new TabContentsViewWin(tab_contents); + return new TabContentsViewWin(tab_contents, this); #else return NULL; #endif @@ -194,7 +197,7 @@ bool ShellContentBrowserClient::CanCreateWindow( const GURL& source_url, WindowContainerType container_type, const content::ResourceContext& context) { - return false; + return true; } std::string ShellContentBrowserClient::GetWorkerProcessTitle( @@ -292,4 +295,19 @@ crypto::CryptoModuleBlockingPasswordDelegate* } #endif +#if defined(OS_WIN) +TabContents* ShellContentBrowserClient::CreateNewWindow( + TabContentsViewWin* tab_contents_view, + int route_id, + const ViewHostMsg_CreateWindow_Params& params) { + Shell* shell = Shell::CreateNewWindow( + tab_contents_view->tab_contents()->browser_context(), + GURL(), + tab_contents_view->tab_contents()->GetSiteInstance(), + route_id, + tab_contents_view->tab_contents()); + return shell->tab_contents(); +} +#endif + } // namespace content diff --git a/content/shell/shell_content_browser_client.h b/content/shell/shell_content_browser_client.h index e61e54c..6c2ce10 100644 --- a/content/shell/shell_content_browser_client.h +++ b/content/shell/shell_content_browser_client.h @@ -12,11 +12,19 @@ #include "base/memory/scoped_ptr.h" #include "content/browser/content_browser_client.h" +#if defined(OS_WIN) +#include "content/browser/tab_contents/tab_contents_view_win_delegate.h" +#endif + namespace content { class ShellBrowserMainParts; -class ShellContentBrowserClient : public ContentBrowserClient { +class ShellContentBrowserClient : public ContentBrowserClient +#if defined(OS_WIN) + , public TabContentsViewWinDelegate +#endif + { public: ShellContentBrowserClient(); virtual ~ShellContentBrowserClient(); @@ -145,6 +153,14 @@ class ShellContentBrowserClient : public ContentBrowserClient { const GURL& url) OVERRIDE; #endif +#if defined(OS_WIN) + // TabContentsViewWinDelegate implementation. + virtual TabContents* CreateNewWindow( + TabContentsViewWin* tab_contents_view, + int route_id, + const ViewHostMsg_CreateWindow_Params& params) OVERRIDE; +#endif + private: ShellBrowserMainParts* shell_browser_main_parts_; }; diff --git a/content/shell/shell_gtk.cc b/content/shell/shell_gtk.cc index 23084fa..12ac1d8 100644 --- a/content/shell/shell_gtk.cc +++ b/content/shell/shell_gtk.cc @@ -26,6 +26,9 @@ void Shell::PlatformEnableUIControl(UIControl control, bool is_enabled) { NOTIMPLEMENTED(); } +void Shell::PlatformSetAddressBarURL(const GURL& url) { +} + void Shell::PlatformCreateWindow() { NOTIMPLEMENTED(); } diff --git a/content/shell/shell_mac.mm b/content/shell/shell_mac.mm index 23084fa..12ac1d8 100644 --- a/content/shell/shell_mac.mm +++ b/content/shell/shell_mac.mm @@ -26,6 +26,9 @@ void Shell::PlatformEnableUIControl(UIControl control, bool is_enabled) { NOTIMPLEMENTED(); } +void Shell::PlatformSetAddressBarURL(const GURL& url) { +} + void Shell::PlatformCreateWindow() { NOTIMPLEMENTED(); } diff --git a/content/shell/shell_win.cc b/content/shell/shell_win.cc index f2647c1..98d08c2 100644 --- a/content/shell/shell_win.cc +++ b/content/shell/shell_win.cc @@ -9,11 +9,14 @@ #include "base/message_loop.h" #include "base/string_piece.h" +#include "base/utf_string_conversions.h" #include "base/win/resource_util.h" +#include "content/browser/tab_contents/tab_contents.h" #include "content/shell/resource.h" #include "googleurl/src/gurl.h" #include "grit/webkit_resources.h" #include "grit/webkit_chromium_resources.h" +#include "ipc/ipc_message.h" #include "net/base/net_module.h" #include "ui/base/win/hwnd_util.h" @@ -56,6 +59,9 @@ base::StringPiece Shell::PlatformResourceProvider(int key) { return GetRawDataResource(::GetModuleHandle(NULL), key); } +void Shell::PlatformExit() { +} + void Shell::PlatformCleanUp() { // When the window is destroyed, tell the Edit field to forget about us, // otherwise we will crash. @@ -82,6 +88,12 @@ void Shell::PlatformEnableUIControl(UIControl control, bool is_enabled) { EnableWindow(GetDlgItem(main_window_, id), is_enabled); } +void Shell::PlatformSetAddressBarURL(const GURL& url) { + std::wstring url_string = UTF8ToWide(url.spec()); + SendMessage(edit_window_, WM_SETTEXT, 0, + reinterpret_cast<LPARAM>(url_string.c_str())); +} + void Shell::PlatformCreateWindow() { main_window_ = CreateWindow(kWindowClass, kWindowTitle, WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN, @@ -187,9 +199,17 @@ LRESULT CALLBACK Shell::WndProc(HWND hwnd, UINT message, WPARAM wParam, case WM_COMMAND: { int id = LOWORD(wParam); switch (id) { - case IDM_EXIT: + case IDM_NEW_WINDOW: + CreateNewWindow( + shell->tab_contents()->browser_context(), + GURL(), NULL, MSG_ROUTING_NONE, NULL); + break; + case IDM_CLOSE_WINDOW: DestroyWindow(hwnd); break; + case IDM_EXIT: + PlatformExit(); + break; case IDC_NAV_BACK: shell->GoBackOrForward(-1); break; @@ -211,7 +231,7 @@ LRESULT CALLBACK Shell::WndProc(HWND hwnd, UINT message, WPARAM wParam, } case WM_DESTROY: { delete shell; - if (!shell_count_) + if (windows_.empty()) MessageLoop::current()->Quit(); return 0; } @@ -238,7 +258,10 @@ LRESULT CALLBACK Shell::EditWndProc(HWND hwnd, UINT message, LRESULT str_len = SendMessage(hwnd, EM_GETLINE, 0, (LPARAM)str); if (str_len > 0) { str[str_len] = 0; // EM_GETLINE doesn't NULL terminate. - shell->LoadURL(GURL(str)); + GURL url(str); + if (!url.has_scheme()) + url = GURL(std::wstring(L"http://") + std::wstring(str)); + shell->LoadURL(url); } return 0; |