From e94980027dc5cd1fb34950cddc18c629328a7e5b Mon Sep 17 00:00:00 2001 From: "pinkerton@chromium.org" Date: Tue, 3 Feb 2009 01:09:53 +0000 Subject: first stab at scaffolding WebContents. Review URL: http://codereview.chromium.org/19757 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@9055 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/browser/browser.cc | 8 +- chrome/browser/browser.h | 2 +- chrome/browser/browser.scons | 1 - chrome/browser/browser_prefs.cc | 10 +-- .../renderer_host/render_view_host_delegate.h | 5 +- chrome/browser/tab_contents/web_contents.cc | 85 ++++++++++++++-------- chrome/browser/tab_contents/web_contents.h | 32 +++++++- 7 files changed, 96 insertions(+), 47 deletions(-) (limited to 'chrome/browser') diff --git a/chrome/browser/browser.cc b/chrome/browser/browser.cc index d3b2d67..96d088c 100644 --- a/chrome/browser/browser.cc +++ b/chrome/browser/browser.cc @@ -12,6 +12,7 @@ #include "chrome/browser/metrics/user_metrics.h" #include "chrome/browser/profile.h" #include "chrome/browser/tab_contents/tab_contents_type.h" +#include "chrome/browser/tab_contents/web_contents.h" #include "chrome/common/chrome_constants.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/notification_service.h" @@ -187,12 +188,8 @@ Browser::Browser(Type type, Profile* profile) InitCommandState(); BrowserList::AddBrowser(this); -#if defined(OS_WIN) - // TODO(port): turn this back on when prefs are fleshed out. This asserts - // because the pref hasn't yet been registered. encoding_auto_detect_.Init(prefs::kWebKitUsesUniversalDetector, profile_->GetPrefs(), NULL); -#endif // Trim browser memory on idle for low & medium memory models. if (g_browser_process->memory_model() < BrowserProcess::HIGH_MEMORY_MODEL) @@ -999,6 +996,7 @@ void Browser::OpenHelpTab() { NULL); } +#endif /////////////////////////////////////////////////////////////////////////////// // static @@ -1043,8 +1041,6 @@ Browser* Browser::GetBrowserForController( return NULL; } -#endif // OS_WIN - /////////////////////////////////////////////////////////////////////////////// // Browser, CommandUpdater::CommandUpdaterDelegate implementation: diff --git a/chrome/browser/browser.h b/chrome/browser/browser.h index ce81f5c..d16a6b8 100644 --- a/chrome/browser/browser.h +++ b/chrome/browser/browser.h @@ -302,6 +302,7 @@ class Browser : public TabStripModelDelegate, void OpenPasswordManager(); void OpenAboutChromeDialog(); void OpenHelpTab(); +#endif ///////////////////////////////////////////////////////////////////////////// @@ -317,7 +318,6 @@ class Browser : public TabStripModelDelegate, const NavigationController* controller, int* index); // Interface implementations //////////////////////////////////////////////// -#endif // Overridden from CommandUpdater::CommandUpdaterDelegate: virtual void ExecuteCommand(int id); diff --git a/chrome/browser/browser.scons b/chrome/browser/browser.scons index c82db3b..14b33e9 100644 --- a/chrome/browser/browser.scons +++ b/chrome/browser/browser.scons @@ -797,7 +797,6 @@ if not env.Bit('windows'): 'tab_contents/tab_contents_factory.cc', 'tab_contents/tab_util.cc', 'tab_contents/view_source_contents.cc', - 'tab_contents/web_contents.cc', 'tab_contents/web_contents_view.cc', 'tab_contents/web_drag_source.cc', 'tab_contents/web_drop_target.cc', diff --git a/chrome/browser/browser_prefs.cc b/chrome/browser/browser_prefs.cc index da18c3f..faf0408 100644 --- a/chrome/browser/browser_prefs.cc +++ b/chrome/browser/browser_prefs.cc @@ -5,8 +5,9 @@ #include "chrome/browser/browser_prefs.h" #include "chrome/browser/browser.h" -#include "chrome/browser/session_startup_pref.h" #include "chrome/browser/google_url_tracker.h" +#include "chrome/browser/session_startup_pref.h" +#include "chrome/browser/tab_contents/web_contents.h" #if defined(OS_WIN) #include "chrome/browser/browser_shutdown.h" @@ -28,7 +29,6 @@ #include "chrome/browser/views/frame/browser_view.h" #include "chrome/browser/views/keyword_editor_view.h" #include "chrome/browser/views/page_info_window.h" -#include "chrome/browser/tab_contents/web_contents.h" #endif namespace browser { @@ -36,9 +36,9 @@ namespace browser { void RegisterAllPrefs(PrefService* user_prefs, PrefService* local_state) { // Prefs in Local State GoogleURLTracker::RegisterPrefs(local_state); + Browser::RegisterPrefs(local_state); #if defined(OS_WIN) BookmarkManagerView::RegisterPrefs(local_state); - Browser::RegisterPrefs(local_state); BrowserView::RegisterBrowserViewPrefs(local_state); browser_shutdown::RegisterPrefs(local_state); CacheManagerHost::RegisterPrefs(local_state); @@ -54,18 +54,18 @@ void RegisterAllPrefs(PrefService* user_prefs, PrefService* local_state) { // User prefs SessionStartupPref::RegisterUserPrefs(user_prefs); + Browser::RegisterUserPrefs(user_prefs); #if defined(OS_WIN) BookmarkBarView::RegisterUserPrefs(user_prefs); BookmarkTableView::RegisterUserPrefs(user_prefs); - Browser::RegisterUserPrefs(user_prefs); chrome_browser_net::RegisterUserPrefs(user_prefs); DownloadManager::RegisterUserPrefs(user_prefs); PasswordManager::RegisterUserPrefs(user_prefs); SSLManager::RegisterUserPrefs(user_prefs); TabContents::RegisterUserPrefs(user_prefs); TemplateURLPrepopulateData::RegisterUserPrefs(user_prefs); - WebContents::RegisterUserPrefs(user_prefs); #endif + WebContents::RegisterUserPrefs(user_prefs); } } // namespace browser diff --git a/chrome/browser/renderer_host/render_view_host_delegate.h b/chrome/browser/renderer_host/render_view_host_delegate.h index 764e8ca..5a39b91 100644 --- a/chrome/browser/renderer_host/render_view_host_delegate.h +++ b/chrome/browser/renderer_host/render_view_host_delegate.h @@ -11,6 +11,7 @@ #include "base/basictypes.h" #include "chrome/browser/autofill_manager.h" #include "chrome/common/render_messages.h" +#include "net/base/load_states.h" #include "webkit/glue/webpreferences.h" class NavigationEntry; @@ -34,10 +35,6 @@ namespace gfx { class Rect; } -namespace net { -enum LoadState; -} - // // RenderViewHostDelegate // diff --git a/chrome/browser/tab_contents/web_contents.cc b/chrome/browser/tab_contents/web_contents.cc index 039ddc2..849ba2a 100644 --- a/chrome/browser/tab_contents/web_contents.cc +++ b/chrome/browser/tab_contents/web_contents.cc @@ -8,20 +8,36 @@ #include "base/compiler_specific.h" #include "base/file_version_info.h" #include "base/process_util.h" +#include "base/string_util.h" #include "chrome/app/locales/locale_settings.h" +#include "chrome/browser/browser.h" +#include "chrome/browser/dom_operation_notification_details.h" +#include "chrome/browser/google_util.h" +#include "chrome/browser/js_before_unload_handler.h" +#include "chrome/browser/jsmessage_box_handler.h" +#include "chrome/browser/load_from_memory_cache_details.h" +#include "chrome/browser/profile.h" +#include "chrome/browser/renderer_host/render_process_host.h" +#include "chrome/browser/tab_contents/provisional_load_details.h" +#include "chrome/common/chrome_switches.h" +#include "chrome/common/l10n_util.h" +#include "chrome/common/notification_service.h" +#include "chrome/common/pref_names.h" +#include "chrome/common/pref_service.h" +#include "net/base/mime_util.h" +#include "net/base/net_errors.h" +#include "net/base/registry_controlled_domain.h" +#include "webkit/glue/webkit_glue.h" + +#if defined(OS_WIN) +// TODO(port): fill these in as we flesh out the implementation of this class #include "chrome/browser/autofill_manager.h" #include "chrome/browser/bookmarks/bookmark_model.h" -#include "chrome/browser/browser.h" #include "chrome/browser/cache_manager_host.h" #include "chrome/browser/character_encoding.h" -#include "chrome/browser/dom_operation_notification_details.h" #include "chrome/browser/download/download_manager.h" #include "chrome/browser/download/download_request_manager.h" #include "chrome/browser/gears_integration.h" -#include "chrome/browser/google_util.h" -#include "chrome/browser/js_before_unload_handler.h" -#include "chrome/browser/jsmessage_box_handler.h" -#include "chrome/browser/load_from_memory_cache_details.h" #include "chrome/browser/load_notification_details.h" #include "chrome/browser/modal_html_dialog_delegate.h" #include "chrome/browser/password_manager/password_manager.h" @@ -35,13 +51,8 @@ #include "chrome/browser/tab_contents/navigation_entry.h" #include "chrome/browser/tab_contents/web_contents_view.h" #include "chrome/browser/views/hung_renderer_view.h" // TODO(brettw) delete me. -#include "chrome/common/chrome_switches.h" -#include "chrome/common/l10n_util.h" -#include "chrome/common/notification_service.h" -#include "chrome/common/pref_names.h" -#include "chrome/common/pref_service.h" #include "chrome/common/resource_bundle.h" -#include "net/base/registry_controlled_domain.h" +#endif #include "generated_resources.h" @@ -105,8 +116,8 @@ const int kJavascriptMessageExpectedDelay = 1000; // shown for us to hide it when navigating away from the current page. const int kDownloadShelfHideDelay = 5000; -const wchar_t kLinkDoctorBaseURL[] = - L"http://linkhelp.clients.google.com/tbproxy/lh/fixurl"; +const char kLinkDoctorBaseURL[] = + "http://linkhelp.clients.google.com/tbproxy/lh/fixurl"; // The printer icon in shell32.dll. That's a standard icon user will quickly // recognize. @@ -138,14 +149,6 @@ const int kPrefsToObserveLength = arraysize(kPrefsToObserve); // text input element in a form. const int kMaxAutofillMenuItems = 6; -void InitWebContentsClass() { - static bool web_contents_class_initialized = false; - if (!web_contents_class_initialized) { - ResourceBundle& rb = ResourceBundle::GetSharedInstance(); - web_contents_class_initialized = true; - } -} - // Returns true if the entry's transition type is FORM_SUBMIT. bool IsFormSubmit(const NavigationEntry* entry) { return (PageTransition::StripQualifier(entry->transition_type()) == @@ -182,15 +185,16 @@ WebContents::WebContents(Profile* profile, ALLOW_THIS_IN_INITIALIZER_LIST( render_manager_(render_view_factory, this, this)), render_view_factory_(render_view_factory), - received_page_title_(false), - is_starred_(false), printing_(*this), notify_disconnection_(false), + received_page_title_(false), + is_starred_(false), +#if defined(OS_WIN) message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)), +#endif ALLOW_THIS_IN_INITIALIZER_LIST(fav_icon_helper_(this)), suppress_javascript_messages_(false), load_state_(net::LOAD_STATE_IDLE) { - InitWebContentsClass(); pending_install_.page_id = 0; pending_install_.callback_functor = NULL; @@ -344,9 +348,15 @@ std::wstring WebContents::GetStatusText() const { case net::LOAD_STATE_SENDING_REQUEST: return l10n_util::GetString(IDS_LOAD_STATE_SENDING_REQUEST); case net::LOAD_STATE_WAITING_FOR_RESPONSE: +#if defined(OS_WIN) + // TODO(port): GetStringF() is currently disabled for non-win platforms. return l10n_util::GetStringF(IDS_LOAD_STATE_WAITING_FOR_RESPONSE, load_state_host_); +#endif // Ignore net::LOAD_STATE_READING_RESPONSE and net::LOAD_STATE_IDLE + case net::LOAD_STATE_IDLE: + case net::LOAD_STATE_READING_RESPONSE: + break; } return std::wstring(); @@ -475,6 +485,7 @@ void WebContents::PopupNotificationVisibilityChanged(bool visible) { render_view_host()->PopupNotificationVisibilityChanged(visible); } +#if defined(OS_WIN) // Stupid view pass-throughs void WebContents::CreateView() { view_->CreateView(); @@ -488,6 +499,7 @@ HWND WebContents::GetContentHWND() { void WebContents::GetContainerBounds(gfx::Rect *out) const { view_->GetContainerBounds(out); } +#endif void WebContents::CreateShortcut() { NavigationEntry* entry = controller()->GetLastCommittedEntry(); @@ -726,7 +738,6 @@ void WebContents::UpdateTitle(RenderViewHost* rvh, NotifyNavigationStateChanged(INVALIDATE_TITLE); } - void WebContents::UpdateEncoding(RenderViewHost* render_view_host, const std::wstring& encoding) { set_encoding(encoding); @@ -827,7 +838,7 @@ void WebContents::DidLoadResourceFromMemoryCache( return; // Send out a notification that we loaded a resource from our memory cache. - int cert_id, cert_status, security_bits; + int cert_id = 0, cert_status = 0, security_bits = 0; SSLManager::DeserializeSecurityInfo(security_info, &cert_id, &cert_status, &security_bits); @@ -1095,11 +1106,16 @@ void WebContents::PageHasOSDD(RenderViewHost* render_view_host, // Download the OpenSearch description document. If this is successful a // new keyword will be created when done. +#if defined(OS_WIN) + gfx::NativeView ancestor = GetAncestor(view_->GetNativeView(), GA_ROOT); +#else + gfx::NativeView ancestor = NULL; +#endif profile()->GetTemplateURLFetcher()->ScheduleDownload( keyword, url, base_entry->favicon().url(), - GetAncestor(view_->GetNativeView(), GA_ROOT), + ancestor, autodetected); } @@ -1215,10 +1231,15 @@ WebPreferences WebContents::GetWebkitPrefs() { } void WebContents::OnMissingPluginStatus(int status) { +#if defined(OS_WIN) +// TODO(PORT): pull in when plug-ins work GetPluginInstaller()->OnMissingPluginStatus(status); +#endif } void WebContents::OnCrashedPlugin(const FilePath& plugin_path) { +#if defined(OS_WIN) +// TODO(PORT): pull in when plug-ins work DCHECK(!plugin_path.value().empty()); std::wstring plugin_name = plugin_path.ToWStringHack(); @@ -1232,6 +1253,7 @@ void WebContents::OnCrashedPlugin(const FilePath& plugin_path) { AddInfoBar(new SimpleAlertInfoBarDelegate( this, l10n_util::GetStringF(IDS_PLUGIN_CRASHED_PROMPT, plugin_name), NULL)); +#endif } void WebContents::OnJSOutOfMemory() { @@ -1286,19 +1308,25 @@ void WebContents::OnDidGetApplicationInfo( if (pending_install_.page_id != page_id) return; // The user clicked create on a separate page. Ignore this. +#if defined(OS_WIN) + // TODO(port): include when gears integration is ported pending_install_.callback_functor = new GearsCreateShortcutCallbackFunctor(this); GearsCreateShortcut( info, pending_install_.title, pending_install_.url, pending_install_.icon, NewCallback(pending_install_.callback_functor, &GearsCreateShortcutCallbackFunctor::Run)); +#endif } void WebContents::OnEnterOrSpace() { // See comment in RenderViewHostDelegate::OnEnterOrSpace as to why we do this. +#if defined(OS_WIN) + // TODO(port): this is stubbed in BrowserProcess DownloadRequestManager* drm = g_browser_process->download_request_manager(); if (drm) drm->OnUserGesture(this); +#endif } bool WebContents::CanTerminate() const { @@ -1317,7 +1345,6 @@ void WebContents::MultiFilesSelected(const std::vector& files, render_view_host()->MultiFilesSelected(files); } - void WebContents::FileSelectionCanceled(void* params) { // If the user cancels choosing a file to upload we pass back an // empty vector. diff --git a/chrome/browser/tab_contents/web_contents.h b/chrome/browser/tab_contents/web_contents.h index 39bf2c6..99f3c8c 100644 --- a/chrome/browser/tab_contents/web_contents.h +++ b/chrome/browser/tab_contents/web_contents.h @@ -5,28 +5,54 @@ #ifndef CHROME_BROWSER_TAB_CONTENTS_WEB_CONTENTS_H_ #define CHROME_BROWSER_TAB_CONTENTS_WEB_CONTENTS_H_ +#include "base/basictypes.h" +#include "base/hash_tables.h" +#include "chrome/browser/cancelable_request.h" +#include "net/base/load_states.h" +#include "webkit/glue/password_form.h" +#include "webkit/glue/webpreferences.h" + +#if defined(OS_MACOSX) || defined(OS_LINUX) +// Remove when we've finished porting the supporting classes. +#include "chrome/common/temp_scaffolding_stubs.h" +#elif defined(OS_WIN) #include "chrome/browser/download/save_package.h" #include "chrome/browser/fav_icon_helper.h" #include "chrome/browser/printing/print_view_manager.h" #include "chrome/browser/renderer_host/render_view_host_delegate.h" -#include "chrome/browser/tab_contents/render_view_host_manager.h" #include "chrome/browser/shell_dialogs.h" +#include "chrome/browser/tab_contents/render_view_host_manager.h" #include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/common/gears_api.h" +#endif +class AutofillForm; class AutofillManager; class InterstitialPageDelegate; +class LoadNotificationDetails; class PasswordManager; class PluginInstaller; +class RenderProcessHost; class RenderViewHost; class RenderViewHostFactory; class RenderWidgetHost; +struct ThumbnailScore; +struct ViewHostMsg_FrameNavigate_Params; +struct ViewHostMsg_DidPrintPage_Params; class WebContentsView; namespace base { class WaitableEvent; } +namespace webkit_glue { +struct WebApplicationInfo; +} + +namespace IPC { +class Message; +} + // WebContents represents the contents of a tab that shows web pages. It embeds // a RenderViewHost (via RenderViewHostManager) to actually display the page. class WebContents : public TabContents, @@ -101,6 +127,7 @@ class WebContents : public TabContents, virtual void SetDownloadShelfVisible(bool visible); virtual void PopupNotificationVisibilityChanged(bool visible); +#if defined(OS_WIN) // Retarded pass-throughs to the view. // TODO(brettw) fix this, tab contents shouldn't have these methods, probably // it should be killed altogether. @@ -108,6 +135,7 @@ class WebContents : public TabContents, virtual HWND GetContainerHWND() const; virtual HWND GetContentHWND(); virtual void GetContainerBounds(gfx::Rect *out) const; +#endif // Web apps ------------------------------------------------------------------ @@ -503,10 +531,12 @@ class WebContents : public TabContents, // Whether the current URL is starred bool is_starred_; +#if defined(OS_WIN) // Handle to an event that's set when the page is showing a message box (or // equivalent constrained window). Plugin processes check this to know if // they should pump messages then. ScopedHandle message_box_active_; +#endif // AutofillManager, lazily created. scoped_ptr autofill_manager_; -- cgit v1.1