summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authorbrettw@google.com <brettw@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-10-14 16:42:25 +0000
committerbrettw@google.com <brettw@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-10-14 16:42:25 +0000
commit807bfceada33743cad3308af48c538d7d7515495 (patch)
tree19953eac8d00695cfbb8c00137d8eb192e0aedc7 /chrome/browser
parent7b7965f2391594e6a3944ffee8fcdaaf18683fc3 (diff)
downloadchromium_src-807bfceada33743cad3308af48c538d7d7515495.zip
chromium_src-807bfceada33743cad3308af48c538d7d7515495.tar.gz
chromium_src-807bfceada33743cad3308af48c538d7d7515495.tar.bz2
Move more view stuff out of WebContents. This moves context menus and info
bars. I removed the associated functions on TabContents, and have callers call directly through to the view when the care about mucking with the info bar (which is busted, IMO). Review URL: http://codereview.chromium.org/7245 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@3346 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/alternate_nav_url_fetcher.cc5
-rw-r--r--chrome/browser/browser.cc10
-rw-r--r--chrome/browser/browser_init.cc7
-rw-r--r--chrome/browser/password_manager.cc4
-rw-r--r--chrome/browser/plugin_installer.cc8
-rw-r--r--chrome/browser/ssl_manager.cc40
-rw-r--r--chrome/browser/tab_contents.h8
-rw-r--r--chrome/browser/views/frame/browser_view2.cc7
-rw-r--r--chrome/browser/views/info_bar_view.cc10
-rw-r--r--chrome/browser/views/old_frames/vista_frame.cc7
-rw-r--r--chrome/browser/views/old_frames/xp_frame.cc7
-rw-r--r--chrome/browser/web_contents.cc124
-rw-r--r--chrome/browser/web_contents.h38
-rw-r--r--chrome/browser/web_contents_view.h22
-rw-r--r--chrome/browser/web_contents_view_win.cc102
-rw-r--r--chrome/browser/web_contents_view_win.h11
16 files changed, 229 insertions, 181 deletions
diff --git a/chrome/browser/alternate_nav_url_fetcher.cc b/chrome/browser/alternate_nav_url_fetcher.cc
index 9560d9b..d20e999 100644
--- a/chrome/browser/alternate_nav_url_fetcher.cc
+++ b/chrome/browser/alternate_nav_url_fetcher.cc
@@ -8,6 +8,7 @@
#include "chrome/browser/navigation_entry.h"
#include "chrome/browser/views/info_bar_alternate_nav_url_view.h"
#include "chrome/browser/web_contents.h"
+#include "chrome/browser/web_contents_view.h"
AlternateNavURLFetcher::AlternateNavURLFetcher(
const std::wstring& alternate_nav_url)
@@ -99,8 +100,8 @@ void AlternateNavURLFetcher::ShowInfobarIfPossible() {
WebContents* web_contents = tab_contents->AsWebContents();
// The infobar will auto-expire this view on the next user-initiated
// navigation, so we don't need to keep track of it.
- web_contents->GetInfoBarView()->AddChildView(new InfoBarAlternateNavURLView(
- alternate_nav_url_));
+ web_contents->view()->GetInfoBarView()->AddChildView(
+ new InfoBarAlternateNavURLView(alternate_nav_url_));
// Now we're no longer referencing the navigation controller or the url fetch,
// so our job is done.
diff --git a/chrome/browser/browser.cc b/chrome/browser/browser.cc
index 2f1e4f3..3f3ebe3 100644
--- a/chrome/browser/browser.cc
+++ b/chrome/browser/browser.cc
@@ -40,6 +40,7 @@
#include "chrome/browser/views/status_bubble.h"
#include "chrome/browser/views/tabs/tab_strip.h"
#include "chrome/browser/views/toolbar_star_toggle.h"
+#include "chrome/browser/web_contents_view.h"
#include "chrome/browser/window_sizer.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_switches.h"
@@ -1538,9 +1539,12 @@ void Browser::RemoveShelvesForTabContents(TabContents* contents) {
if (shelf && shelf->GetParent() != NULL)
shelf->GetParent()->RemoveChildView(shelf);
- ChromeViews::View* info_bar = contents->GetInfoBarView();
- if (info_bar && info_bar->GetParent() != NULL)
- info_bar->GetParent()->RemoveChildView(info_bar);
+ if (contents->AsWebContents()) {
+ ChromeViews::View* info_bar =
+ contents->AsWebContents()->view()->GetInfoBarView();
+ if (info_bar && info_bar->GetParent() != NULL)
+ info_bar->GetParent()->RemoveChildView(info_bar);
+ }
}
BrowserType::Type Browser::GetType() const {
diff --git a/chrome/browser/browser_init.cc b/chrome/browser/browser_init.cc
index a9e0134..ff4b22a 100644
--- a/chrome/browser/browser_init.cc
+++ b/chrome/browser/browser_init.cc
@@ -29,6 +29,7 @@
#include "chrome/browser/tabs/tab_strip_model.h"
#include "chrome/browser/url_fixer_upper.h"
#include "chrome/browser/web_app_launcher.h"
+#include "chrome/browser/web_contents_view.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_switches.h"
@@ -554,9 +555,11 @@ void BrowserInit::LaunchWithProfile::AddCrashedInfoBarIfNecessary(
if (!profile_->DidLastSessionExitCleanly() && web_contents) {
// The last session didn't exit cleanly. Show an infobar to the user
// so that they can restore if they want.
- web_contents->GetInfoBarView()->
+ // TODO(brettw) this should be done more cleanly, by adding a message to
+ // the view and not getting the info bar from inside it directly.
+ web_contents->view()->GetInfoBarView()->
AddChildView(new SessionCrashedView(profile_));
- web_contents->SetInfoBarVisible(true);
+ web_contents->view()->SetInfoBarVisible(true);
}
}
diff --git a/chrome/browser/password_manager.cc b/chrome/browser/password_manager.cc
index 38c50d9..cd99f82 100644
--- a/chrome/browser/password_manager.cc
+++ b/chrome/browser/password_manager.cc
@@ -8,6 +8,7 @@
#include "chrome/app/theme/theme_resources.h"
#include "chrome/browser/profile.h"
#include "chrome/browser/web_contents.h"
+#include "chrome/browser/web_contents_view.h"
#include "chrome/common/l10n_util.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/pref_service.h"
@@ -188,8 +189,9 @@ void PasswordManager::CloseBars() {
}
void PasswordManager::ReplaceInfoBar(InfoBarItemView* bar) {
+ // TODO(brettw) The password manager should not have to know about info bars.
CloseBars();
- InfoBarView* view = web_contents_->GetInfoBarView();
+ InfoBarView* view = web_contents_->view()->GetInfoBarView();
view->AddChildView(bar);
current_bar_ = bar;
}
diff --git a/chrome/browser/plugin_installer.cc b/chrome/browser/plugin_installer.cc
index 9ccaad8..1d42d80 100644
--- a/chrome/browser/plugin_installer.cc
+++ b/chrome/browser/plugin_installer.cc
@@ -2,8 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chrome/app/theme/theme_resources.h"
#include "chrome/browser/plugin_installer.h"
+
+#include "chrome/app/theme/theme_resources.h"
+#include "chrome/browser/web_contents_view.h"
#include "base/string_util.h"
#include "chrome/common/l10n_util.h"
#include "chrome/common/resource_bundle.h"
@@ -28,7 +30,9 @@ void PluginInstaller::OnMissingPluginStatus(int status) {
if (current_bar_)
return;
- InfoBarView* view = web_contents_->GetInfoBarView();
+ // TODO(brettw) have a more general way to add to the info bar rather
+ // than mucking with it directly.
+ InfoBarView* view = web_contents_->view()->GetInfoBarView();
current_bar_ = new PluginInstallerBar(this);
view->AddChildView(current_bar_);
break;
diff --git a/chrome/browser/ssl_manager.cc b/chrome/browser/ssl_manager.cc
index 4575e5f..d30dfc3 100644
--- a/chrome/browser/ssl_manager.cc
+++ b/chrome/browser/ssl_manager.cc
@@ -19,9 +19,10 @@
#include "chrome/browser/ssl_policy.h"
#include "chrome/browser/tab_contents.h"
#include "chrome/browser/tab_util.h"
-#include "chrome/browser/web_contents.h"
#include "chrome/browser/views/info_bar_view.h"
#include "chrome/browser/views/standard_layout.h"
+#include "chrome/browser/web_contents.h"
+#include "chrome/browser/web_contents_view.h"
#include "chrome/common/l10n_util.h"
#include "chrome/common/notification_service.h"
#include "chrome/common/pref_names.h"
@@ -148,27 +149,30 @@ void SSLManager::ShowMessageWithLink(const std::wstring& msg,
if (entry->ssl().security_style() <= SECURITY_STYLE_UNAUTHENTICATED)
return;
- InfoBarView* info_bar_view =
- controller_->active_contents()->GetInfoBarView();
- DCHECK(info_bar_view);
-
- if (!info_bar_view)
- return;
+ // TODO(brettw) have a more general way to deal with info bars.
+ if (controller_->active_contents()->AsWebContents()) {
+ InfoBarView* info_bar_view = controller_->active_contents()->
+ AsWebContents()->view()->GetInfoBarView();
+ DCHECK(info_bar_view);
- // Check if we are already displaying this message.
- ObserverList<SSLInfoBar>::Iterator it(visible_info_bars_);
- SSLInfoBar* info_bar;
- while (info_bar = it.GetNext()) {
- if (info_bar->GetMessageText() == msg)
+ if (!info_bar_view)
return;
- }
- // Show the message.
- info_bar = new SSLInfoBar(this, msg, link_text, task);
- visible_info_bars_.AddObserver(info_bar);
+ // Check if we are already displaying this message.
+ ObserverList<SSLInfoBar>::Iterator it(visible_info_bars_);
+ SSLInfoBar* info_bar;
+ while (info_bar = it.GetNext()) {
+ if (info_bar->GetMessageText() == msg)
+ return;
+ }
+
+ // Show the message.
+ info_bar = new SSLInfoBar(this, msg, link_text, task);
+ visible_info_bars_.AddObserver(info_bar);
- // false indicates info_bar is not automatically removed.
- info_bar_view->AppendInfoBarItem(info_bar, false);
+ // false indicates info_bar is not automatically removed.
+ info_bar_view->AppendInfoBarItem(info_bar, false);
+ }
}
// Delegate API method.
diff --git a/chrome/browser/tab_contents.h b/chrome/browser/tab_contents.h
index 187822b..583358f 100644
--- a/chrome/browser/tab_contents.h
+++ b/chrome/browser/tab_contents.h
@@ -411,14 +411,6 @@ class TabContents : public PageNavigator,
// Returns whether the bookmark bar should be visible.
virtual bool IsBookmarkBarAlwaysVisible() { return false; }
- // Returns the View to display at the top of the tab.
- virtual InfoBarView* GetInfoBarView() { return NULL; }
-
- // Returns whether the info bar is visible.
- // If the visibility dynamically changes, invoke ToolbarSizeChanged
- // on the delegate. Which forces the frame to layout if size has changed.
- virtual bool IsInfoBarVisible() { return false; }
-
// Whether or not the shelf view is visible.
virtual void SetDownloadShelfVisible(bool visible);
bool IsDownloadShelfVisible() { return shelf_visible_; }
diff --git a/chrome/browser/views/frame/browser_view2.cc b/chrome/browser/views/frame/browser_view2.cc
index 87397a6..e4a81c1 100644
--- a/chrome/browser/views/frame/browser_view2.cc
+++ b/chrome/browser/views/frame/browser_view2.cc
@@ -20,6 +20,8 @@
#include "chrome/browser/views/tab_contents_container_view.h"
#include "chrome/browser/views/tabs/tab_strip.h"
#include "chrome/browser/views/toolbar_view.h"
+#include "chrome/browser/web_contents.h"
+#include "chrome/browser/web_contents_view.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/drag_drop_types.h"
#include "chrome/common/l10n_util.h"
@@ -999,8 +1001,9 @@ bool BrowserView2::MaybeShowBookmarkBar(TabContents* contents) {
bool BrowserView2::MaybeShowInfoBar(TabContents* contents) {
ChromeViews::View* new_info_bar = NULL;
- if (contents && contents->IsInfoBarVisible())
- new_info_bar = contents->GetInfoBarView();
+ if (contents && contents->AsWebContents() &&
+ contents->AsWebContents()->view()->IsInfoBarVisible())
+ new_info_bar = contents->AsWebContents()->view()->GetInfoBarView();
return UpdateChildViewAndLayout(new_info_bar, &active_info_bar_);
}
diff --git a/chrome/browser/views/info_bar_view.cc b/chrome/browser/views/info_bar_view.cc
index 00a704f9..17d4a2a 100644
--- a/chrome/browser/views/info_bar_view.cc
+++ b/chrome/browser/views/info_bar_view.cc
@@ -9,6 +9,7 @@
#include "chrome/browser/navigation_entry.h"
#include "chrome/browser/tab_contents_delegate.h"
#include "chrome/browser/web_contents.h"
+#include "chrome/browser/web_contents_view.h"
#include "chrome/common/gfx/chrome_canvas.h"
#include "chrome/common/l10n_util.h"
#include "chrome/common/resource_bundle.h"
@@ -128,10 +129,13 @@ void InfoBarView::ViewHierarchyChanged(bool is_add, View *parent,
expire_map_[child] = GetActiveID();
}
- if (web_contents_->IsInfoBarVisible()) {
+ // TODO(brettw) clean up the ownership of this info bar. It should be owned
+ // by the web contents view instead. In the meantime, we assume we're owned
+ // by a WebContents.
+ if (web_contents_->AsWebContents()->view()->IsInfoBarVisible()) {
web_contents_->ToolbarSizeChanged(false);
} else {
- web_contents_->SetInfoBarVisible(true);
+ web_contents_->view()->SetInfoBarVisible(true);
}
}
}
@@ -231,7 +235,7 @@ void InfoBarView::Observe(NotificationType type,
if (GetChildViewCount() == 0) {
// All our views have been removed, no need to stay visible.
- web_contents_->SetInfoBarVisible(false);
+ web_contents_->view()->SetInfoBarVisible(false);
} else if (web_contents_) {
// This triggers a layout.
web_contents_->ToolbarSizeChanged(false);
diff --git a/chrome/browser/views/old_frames/vista_frame.cc b/chrome/browser/views/old_frames/vista_frame.cc
index 3c25943..592237a 100644
--- a/chrome/browser/views/old_frames/vista_frame.cc
+++ b/chrome/browser/views/old_frames/vista_frame.cc
@@ -26,6 +26,8 @@
#include "chrome/browser/views/frame/browser_view.h"
#include "chrome/browser/views/tab_contents_container_view.h"
#include "chrome/browser/views/tabs/tab_strip.h"
+#include "chrome/browser/web_contents.h"
+#include "chrome/browser/web_contents_view.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/gfx/chrome_canvas.h"
#include "chrome/common/l10n_util.h"
@@ -1616,8 +1618,9 @@ void VistaFrame::ShelfVisibilityChangedImpl(TabContents* current_tab) {
changed |= UpdateChildViewAndLayout(new_shelf, &shelf_view_);
ChromeViews::View* new_info_bar = NULL;
- if (current_tab && current_tab->IsInfoBarVisible())
- new_info_bar = current_tab->GetInfoBarView();
+ WebContents* web_contents = current_tab ? current_tab->AsWebContents() : NULL;
+ if (web_contents && web_contents->view()->IsInfoBarVisible())
+ new_info_bar = web_contents->view()->GetInfoBarView();
changed |= UpdateChildViewAndLayout(new_info_bar, &info_bar_view_);
ChromeViews::View* new_bookmark_bar_view = NULL;
diff --git a/chrome/browser/views/old_frames/xp_frame.cc b/chrome/browser/views/old_frames/xp_frame.cc
index cb0220c..5672ec2 100644
--- a/chrome/browser/views/old_frames/xp_frame.cc
+++ b/chrome/browser/views/old_frames/xp_frame.cc
@@ -23,6 +23,8 @@
#include "chrome/browser/views/old_frames/point_buffer.h"
#include "chrome/browser/views/tab_contents_container_view.h"
#include "chrome/browser/views/tabs/tab_strip.h"
+#include "chrome/browser/web_contents.h"
+#include "chrome/browser/web_contents_view.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/gfx/chrome_canvas.h"
@@ -2494,8 +2496,9 @@ void XPFrame::ShelfVisibilityChangedImpl(TabContents* current_tab) {
changed |= UpdateChildViewAndLayout(new_shelf, &shelf_view_);
ChromeViews::View* new_info_bar = NULL;
- if (current_tab && current_tab->IsInfoBarVisible())
- new_info_bar = current_tab->GetInfoBarView();
+ WebContents* web_contents = current_tab ? current_tab->AsWebContents() : NULL;
+ if (web_contents && web_contents->view()->IsInfoBarVisible())
+ new_info_bar = web_contents->view()->GetInfoBarView();
changed |= UpdateChildViewAndLayout(new_info_bar, &info_bar_view_);
ChromeViews::View* new_bookmark_bar_view = NULL;
diff --git a/chrome/browser/web_contents.cc b/chrome/browser/web_contents.cc
index 4f2d259..3b8e5086 100644
--- a/chrome/browser/web_contents.cc
+++ b/chrome/browser/web_contents.cc
@@ -28,8 +28,6 @@
#include "chrome/browser/plugin_installer.h"
#include "chrome/browser/plugin_service.h"
#include "chrome/browser/printing/print_job.h"
-#include "chrome/browser/render_view_context_menu.h"
-#include "chrome/browser/render_view_context_menu_controller.h"
#include "chrome/browser/render_view_host.h"
#include "chrome/browser/render_widget_host_hwnd.h"
#include "chrome/browser/template_url_fetcher.h"
@@ -184,7 +182,6 @@ WebContents::WebContents(Profile* profile,
notify_disconnection_(false),
message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)),
ALLOW_THIS_IN_INITIALIZER_LIST(fav_icon_helper_(this)),
- crashed_plugin_info_bar_(NULL),
suppress_javascript_messages_(false),
load_state_(net::LOAD_STATE_IDLE) {
InitWebContentsClass();
@@ -418,8 +415,8 @@ void WebContents::Paste() {
void WebContents::DidBecomeSelected() {
TabContents::DidBecomeSelected();
- if (view())
- view()->DidBecomeSelected();
+ if (render_widget_host_view())
+ render_widget_host_view()->DidBecomeSelected();
CacheManagerHost::GetInstance()->ObserveActivity(process()->host_id());
}
@@ -431,8 +428,8 @@ void WebContents::WasHidden() {
// is because closing the tab calls WebContents::Destroy(), which removes
// the |render_view_host()|; then when we actually destroy the window,
// OnWindowPosChanged() notices and calls HideContents() (which calls us).
- if (view())
- view()->WasHidden();
+ if (render_widget_host_view())
+ render_widget_host_view()->WasHidden();
// Loop through children and send WasHidden to them, too.
int count = static_cast<int>(child_windows_.size());
@@ -450,8 +447,8 @@ void WebContents::WasHidden() {
}
void WebContents::ShowContents() {
- if (view())
- view()->DidBecomeSelected();
+ if (render_widget_host_view())
+ render_widget_host_view()->DidBecomeSelected();
// Loop through children and send DidBecomeSelected to them, too.
int count = static_cast<int>(child_windows_.size());
@@ -476,8 +473,8 @@ void WebContents::HideContents() {
}
void WebContents::SizeContents(const gfx::Size& size) {
- if (view())
- view()->SetSize(size);
+ if (render_widget_host_view())
+ render_widget_host_view()->SetSize(size);
if (find_in_page_controller_.get())
find_in_page_controller_->RespondToResize(size);
RepositionSupressedPopupsToFit(size);
@@ -503,12 +500,6 @@ HWND WebContents::GetContainerHWND() const {
HWND WebContents::GetContentHWND() {
return view_->GetContentHWND();
}
-bool WebContents::IsInfoBarVisible() {
- return view_->IsInfoBarVisible();
-}
-InfoBarView* WebContents::GetInfoBarView() {
- return view_->GetInfoBarView();
-}
void WebContents::GetContainerBounds(gfx::Rect *out) const {
view_->GetContainerBounds(out);
}
@@ -623,10 +614,6 @@ void WebContents::OnJavaScriptMessageBoxClosed(IPC::Message* reply_msg,
render_manager_.OnJavaScriptMessageBoxClosed(reply_msg, success, prompt);
}
-void WebContents::SetInfoBarVisible(bool visible) {
- view_->SetInfoBarVisible(visible);
-}
-
void WebContents::OnSavePage() {
// If we can not save the page, try to download it.
if (!SavePackage::IsSavableContents(contents_mime_type())) {
@@ -756,7 +743,7 @@ void WebContents::CreateWidget(int route_id) {
// We set the parent HWDN explicitly as pop-up HWNDs are parented and owned by
// the first non-child HWND of the HWND that was specified to the CreateWindow
// call.
- widget_view->set_parent_hwnd(view()->GetPluginHWND());
+ widget_view->set_parent_hwnd(render_widget_host_view()->GetPluginHWND());
widget_view->set_close_on_deactivate(true);
// Don't show the widget until we get its position in ShowWidget.
@@ -773,18 +760,18 @@ void WebContents::ShowView(int route_id,
return;
}
- WebContents* new_view = iter->second;
+ WebContents* new_web_contents = iter->second;
pending_views_.erase(route_id);
- if (!new_view->view() ||
- !new_view->process()->channel()) {
+ if (!new_web_contents->render_widget_host_view() ||
+ !new_web_contents->process()->channel()) {
// The view has gone away or the renderer crashed. Nothing to do.
return;
}
// TODO(brettw) this seems bogus to reach into here and initialize the host.
- new_view->render_view_host()->Init();
- AddNewContents(new_view, disposition, initial_pos, user_gesture);
+ new_web_contents->render_view_host()->Init();
+ AddNewContents(new_web_contents, disposition, initial_pos, user_gesture);
}
void WebContents::ShowWidget(int route_id, const gfx::Rect& initial_pos) {
@@ -980,7 +967,7 @@ void WebContents::UpdateState(RenderViewHost* rvh,
if (view_->GetContainerHWND()) {
// It's possible to get this after the hwnd has been destroyed.
::SetWindowText(view_->GetContainerHWND(), title.c_str());
- ::SetWindowText(view()->GetPluginHWND(), title.c_str());
+ ::SetWindowText(render_widget_host_view()->GetPluginHWND(), title.c_str());
}
// Update the state (forms, etc.).
@@ -1223,24 +1210,7 @@ void WebContents::DidDownloadImage(
void WebContents::ShowContextMenu(
const ViewHostMsg_ContextMenu_Params& params) {
- // TODO(brettw) move this to the view.
- RenderViewContextMenuController menu_controller(this, params);
- RenderViewContextMenu menu(&menu_controller,
- view_->GetContainerHWND(),
- params.type,
- params.misspelled_word,
- params.dictionary_suggestions,
- profile());
-
- POINT screen_pt = { params.x, params.y };
- MapWindowPoints(view_->GetContainerHWND(), HWND_DESKTOP, &screen_pt, 1);
-
- // Enable recursive tasks on the message loop so we can get updates while
- // the context menu is being displayed.
- bool old_state = MessageLoop::current()->NestableTasksAllowed();
- MessageLoop::current()->SetNestableTasksAllowed(true);
- menu.RunMenuAt(screen_pt.x, screen_pt.y);
- MessageLoop::current()->SetNestableTasksAllowed(old_state);
+ view_->ShowContextMenu(params);
}
void WebContents::StartDragging(const WebDropData& drop_data) {
@@ -1450,38 +1420,6 @@ void WebContents::DidPrintPage(const ViewHostMsg_DidPrintPage_Params& params) {
printing_.DidPrintPage(params);
}
-// The renderer sends back to the browser the key events it did not process.
-void WebContents::HandleKeyboardEvent(const WebKeyboardEvent& event) {
- // TODO(brettw) move this to the view.
-
- // The renderer returned a keyboard event it did not process. This may be
- // a keyboard shortcut that we have to process.
- if (event.type == WebInputEvent::KEY_DOWN) {
- ChromeViews::FocusManager* focus_manager =
- ChromeViews::FocusManager::GetFocusManager(view_->GetContainerHWND());
- // We may not have a focus_manager at this point (if the tab has been
- // switched by the time this message returned).
- if (focus_manager) {
- ChromeViews::Accelerator accelerator(event.key_code,
- (event.modifiers & WebInputEvent::SHIFT_KEY) ==
- WebInputEvent::SHIFT_KEY,
- (event.modifiers & WebInputEvent::CTRL_KEY) ==
- WebInputEvent::CTRL_KEY,
- (event.modifiers & WebInputEvent::ALT_KEY) ==
- WebInputEvent::ALT_KEY);
- if (focus_manager->ProcessAccelerator(accelerator, false))
- return;
- }
- }
-
- // Any unhandled keyboard/character messages should be defproced.
- // This allows stuff like Alt+F4, etc to work correctly.
- DefWindowProc(event.actual_message.hwnd,
- event.actual_message.message,
- event.actual_message.wParam,
- event.actual_message.lParam);
-}
-
GURL WebContents::GetAlternateErrorPageURL() const {
GURL url;
PrefService* prefs = profile()->GetPrefs();
@@ -1588,30 +1526,13 @@ void WebContents::OnCrashedPlugin(const std::wstring& plugin_path) {
if (!product_name.empty())
plugin_name = product_name;
}
-
- std::wstring info_bar_message =
- l10n_util::GetStringF(IDS_PLUGIN_CRASHED_PROMPT, plugin_name);
-
- InfoBarView* view = GetInfoBarView();
- if (-1 == view->GetChildIndex(crashed_plugin_info_bar_)) {
- crashed_plugin_info_bar_ = new InfoBarMessageView(info_bar_message);
- view->AddChildView(crashed_plugin_info_bar_);
- } else {
- crashed_plugin_info_bar_->SetMessageText(info_bar_message);
- }
+ view_->DisplayErrorInInfoBar(
+ l10n_util::GetStringF(IDS_PLUGIN_CRASHED_PROMPT, plugin_name));
}
void WebContents::OnJSOutOfMemory() {
- std::wstring info_bar_message =
- l10n_util::GetString(IDS_JS_OUT_OF_MEMORY_PROMPT);
-
- InfoBarView* view = GetInfoBarView();
- if (-1 == view->GetChildIndex(crashed_plugin_info_bar_)) {
- crashed_plugin_info_bar_ = new InfoBarMessageView(info_bar_message);
- view->AddChildView(crashed_plugin_info_bar_);
- } else {
- crashed_plugin_info_bar_->SetMessageText(info_bar_message);
- }
+ view_->DisplayErrorInInfoBar(
+ l10n_util::GetString(IDS_JS_OUT_OF_MEMORY_PROMPT));
}
bool WebContents::CanBlur() const {
@@ -1651,6 +1572,11 @@ void WebContents::OnDidGetApplicationInfo(
&GearsCreateShortcutCallbackFunctor::Run));
}
+// Stupid pass-through for RenderViewHostDelegate.
+void WebContents::HandleKeyboardEvent(const WebKeyboardEvent& event) {
+ view_->HandleKeyboardEvent(event);
+}
+
void WebContents::FileSelected(const std::wstring& path, void* params) {
render_view_host()->FileSelected(path);
}
diff --git a/chrome/browser/web_contents.h b/chrome/browser/web_contents.h
index 2b9bdee..d11457b 100644
--- a/chrome/browser/web_contents.h
+++ b/chrome/browser/web_contents.h
@@ -59,21 +59,18 @@ class WebContents : public TabContents,
// Returns the SavePackage which manages the page saving job. May be NULL.
SavePackage* save_package() const { return save_package_.get(); }
- // Return the currently active RenderProcessHost, RenderViewHost, and
- // SiteInstance, respectively. Each of these may change over time. Callers
- // should be aware that the SiteInstance could be deleted if its ref count
- // drops to zero (i.e., if all RenderViewHosts and NavigationEntries that
- // use it are deleted).
+ // Return the currently active RenderProcessHost and RenderViewHost. Each of
+ // these may change over time.
RenderProcessHost* process() const {
return render_manager_.current_host()->process();
}
RenderViewHost* render_view_host() const {
return render_manager_.current_host();
}
- // TODO(brettw) rename this to render_widget_host_view soon, and make this go
- // away entirely in the long run.
- RenderWidgetHostView* view() const {
- return render_manager_.current_view();
+
+ // The WebContentsView will never change and is guaranteed non-NULL.
+ WebContentsView* view() const {
+ return view_.get();
}
bool is_starred() const { return is_starred_; }
@@ -103,14 +100,12 @@ class WebContents : public TabContents,
virtual void SizeContents(const gfx::Size& size);
virtual void SetDownloadShelfVisible(bool visible);
- // Retarded pass-throughs to the view. See also below under misc state.
+ // Retarded pass-throughs to the view.
// TODO(brettw) fix this, tab contents shouldn't have these methods, probably
// it should be killed altogether.
virtual void CreateView(HWND parent_hwnd, const gfx::Rect& initial_bounds);
virtual HWND GetContainerHWND() const;
virtual HWND GetContentHWND();
- virtual bool IsInfoBarVisible();
- virtual InfoBarView* GetInfoBarView();
virtual void GetContainerBounds(gfx::Rect *out) const;
// Find in page --------------------------------------------------------------
@@ -171,13 +166,9 @@ class WebContents : public TabContents,
// Misc state & callbacks ----------------------------------------------------
- // More retarded pass-throughs (see also above under TabContents overrides).
- void SetInfoBarVisible(bool visible);
-
// Set whether the contents should block javascript message boxes or not.
// Default is not to block any message boxes.
- void set_suppress_javascript_messages(
- bool suppress_javascript_messages) {
+ void set_suppress_javascript_messages(bool suppress_javascript_messages) {
suppress_javascript_messages_ = suppress_javascript_messages;
}
@@ -220,6 +211,10 @@ class WebContents : public TabContents,
// Should be deleted via CloseContents.
virtual ~WebContents();
+ RenderWidgetHostView* render_widget_host_view() const {
+ return render_manager_.current_view();
+ }
+
// TabContents (private overrides) -------------------------------------------
virtual void SetInitialFocus(bool reverse);
@@ -309,7 +304,6 @@ class WebContents : public TabContents,
virtual void InspectElementReply(int num_resources);
virtual void DidGetPrintedPagesCount(int cookie, int number_pages);
virtual void DidPrintPage(const ViewHostMsg_DidPrintPage_Params& params);
- virtual void HandleKeyboardEvent(const WebKeyboardEvent& event);
virtual GURL GetAlternateErrorPageURL() const;
virtual WebPreferences GetWebkitPrefs();
virtual void OnMissingPluginStatus(int status);
@@ -334,6 +328,9 @@ class WebContents : public TabContents,
int32 page_id,
const webkit_glue::WebApplicationInfo& info);
+ // Stupid render view host view pass-throughs.
+ virtual void HandleKeyboardEvent(const WebKeyboardEvent& event);
+
// SelectFileDialog::Listener ------------------------------------------------
virtual void FileSelected(const std::wstring& path, void* params);
@@ -542,11 +539,6 @@ class WebContents : public TabContents,
// Dialog box used for choosing files to upload from file form fields.
scoped_refptr<SelectFileDialog> select_file_dialog_;
- // Info bar for crashed plugin message.
- // IMPORTANT: This instance is owned by the InfoBarView. It is valid
- // only if InfoBarView::GetChildIndex for this view is valid.
- InfoBarMessageView* crashed_plugin_info_bar_;
-
// The time that the last javascript message was dismissed.
TimeTicks last_javascript_message_dismissal_;
diff --git a/chrome/browser/web_contents_view.h b/chrome/browser/web_contents_view.h
index bb28438..29b9368 100644
--- a/chrome/browser/web_contents_view.h
+++ b/chrome/browser/web_contents_view.h
@@ -14,8 +14,10 @@
class InfoBarView;
class RenderViewHost;
class RenderWidgetHostHWND;
+struct ViewHostMsg_ContextMenu_Params;
class WebContents;
struct WebDropData;
+class WebKeyboardEvent;
// The WebContentsView is an interface that is implemented by the platform-
// dependent web contents views. The WebContents uses this interface to talk to
@@ -61,6 +63,15 @@ class WebContentsView {
// Enumerate and 'un-parent' any plugin windows that are children of us.
virtual void DetachPluginWindows() = 0;
+ // Displays the given error in the info bar. A new info bar will be shown if
+ // one is not shown already. The new error text will replace any existing
+ // text shown by this same function.
+ //
+ // Note: this replacement behavior is historical; crashed plugin and out of
+ // JS memory used the same message. This seems reasonable, but it may not be
+ // the best thing for all error messages.
+ virtual void DisplayErrorInInfoBar(const std::wstring& text) = 0;
+
// Set/get whether or not the info bar is visible. See also the ChromeFrame
// method InfoBarVisibilityChanged and TabContents::IsInfoBarVisible.
virtual void SetInfoBarVisible(bool visible) = 0;
@@ -68,12 +79,23 @@ class WebContentsView {
// Create the InfoBarView and returns it if none has been created.
// Just returns existing InfoBarView if it is already created.
+ // TODO(brettw) this probably shouldn't be here. There should be methods to
+ // tell us what we need to display instead.
virtual InfoBarView* GetInfoBarView() = 0;
// The page wants to update the mouse cursor during a drag & drop operation.
// |is_drop_target| is true if the mouse is over a valid drop target.
virtual void UpdateDragCursor(bool is_drop_target) = 0;
+ // Runs a context menu with the given parameters from the renderer.
+ virtual void ShowContextMenu(
+ const ViewHostMsg_ContextMenu_Params& params) = 0;
+
+ // Posts the given keyboard message and handles it in the native way. This
+ // is called when the renderer reflects a keyboard message back up to us for
+ // default handling.
+ virtual void HandleKeyboardEvent(const WebKeyboardEvent& event) = 0;
+
protected:
WebContentsView() {} // Abstract interface.
diff --git a/chrome/browser/web_contents_view_win.cc b/chrome/browser/web_contents_view_win.cc
index 6078b94..c576bb0 100644
--- a/chrome/browser/web_contents_view_win.cc
+++ b/chrome/browser/web_contents_view_win.cc
@@ -7,9 +7,13 @@
#include <windows.h>
#include "chrome/browser/find_in_page_controller.h"
+#include "chrome/browser/render_view_context_menu.h"
+#include "chrome/browser/render_view_context_menu_controller.h"
#include "chrome/browser/render_view_host.h"
#include "chrome/browser/render_widget_host_hwnd.h"
#include "chrome/browser/tab_contents_delegate.h"
+#include "chrome/browser/views/info_bar_message_view.h"
+#include "chrome/browser/views/info_bar_view.h"
#include "chrome/browser/views/sad_tab_view.h"
#include "chrome/browser/web_contents.h"
#include "chrome/browser/web_drag_source.h"
@@ -33,6 +37,7 @@ BOOL CALLBACK EnumPluginWindowsCallback(HWND window, LPARAM param) {
WebContentsViewWin::WebContentsViewWin(WebContents* web_contents)
: web_contents_(web_contents),
+ error_info_bar_message_(NULL),
info_bar_visible_(false) {
}
@@ -65,9 +70,9 @@ HWND WebContentsViewWin::GetContainerHWND() const {
}
HWND WebContentsViewWin::GetContentHWND() const {
- if (!web_contents_->view())
+ if (!web_contents_->render_widget_host_view())
return NULL;
- return web_contents_->view()->GetPluginHWND();
+ return web_contents_->render_widget_host_view()->GetPluginHWND();
}
void WebContentsViewWin::GetContainerBounds(gfx::Rect *out) const {
@@ -115,6 +120,16 @@ void WebContentsViewWin::DetachPluginWindows() {
EnumChildWindows(GetHWND(), EnumPluginWindowsCallback, NULL);
}
+void WebContentsViewWin::DisplayErrorInInfoBar(const std::wstring& text) {
+ InfoBarView* view = GetInfoBarView();
+ if (-1 == view->GetChildIndex(error_info_bar_message_)) {
+ error_info_bar_message_ = new InfoBarMessageView(text);
+ view->AddChildView(error_info_bar_message_);
+ } else {
+ error_info_bar_message_->SetMessageText(text);
+ }
+}
+
void WebContentsViewWin::OnDestroy() {
if (drop_target_.get()) {
RevokeDragDrop(GetHWND());
@@ -139,8 +154,10 @@ bool WebContentsViewWin::IsInfoBarVisible() const {
InfoBarView* WebContentsViewWin::GetInfoBarView() {
if (info_bar_view_.get() == NULL) {
+ // TODO(brettw) currently the InfoBar thinks its owned by the WebContents,
+ // but it should instead think it's owned by us.
info_bar_view_.reset(new InfoBarView(web_contents_));
- // The WebContents owns the info-bar.
+ // We own the info-bar.
info_bar_view_->SetParentOwned(false);
}
return info_bar_view_.get();
@@ -150,7 +167,58 @@ void WebContentsViewWin::UpdateDragCursor(bool is_drop_target) {
drop_target_->set_is_drop_target(is_drop_target);
}
-void WebContentsViewWin::OnHScroll(int scroll_type, short position, HWND scrollbar) {
+void WebContentsViewWin::ShowContextMenu(
+ const ViewHostMsg_ContextMenu_Params& params) {
+ RenderViewContextMenuController menu_controller(web_contents_, params);
+ RenderViewContextMenu menu(&menu_controller,
+ GetHWND(),
+ params.type,
+ params.misspelled_word,
+ params.dictionary_suggestions,
+ web_contents_->profile());
+
+ POINT screen_pt = { params.x, params.y };
+ MapWindowPoints(GetHWND(), HWND_DESKTOP, &screen_pt, 1);
+
+ // Enable recursive tasks on the message loop so we can get updates while
+ // the context menu is being displayed.
+ bool old_state = MessageLoop::current()->NestableTasksAllowed();
+ MessageLoop::current()->SetNestableTasksAllowed(true);
+ menu.RunMenuAt(screen_pt.x, screen_pt.y);
+ MessageLoop::current()->SetNestableTasksAllowed(old_state);
+}
+
+void WebContentsViewWin::HandleKeyboardEvent(const WebKeyboardEvent& event) {
+ // The renderer returned a keyboard event it did not process. This may be
+ // a keyboard shortcut that we have to process.
+ if (event.type == WebInputEvent::KEY_DOWN) {
+ ChromeViews::FocusManager* focus_manager =
+ ChromeViews::FocusManager::GetFocusManager(GetHWND());
+ // We may not have a focus_manager at this point (if the tab has been
+ // switched by the time this message returned).
+ if (focus_manager) {
+ ChromeViews::Accelerator accelerator(event.key_code,
+ (event.modifiers & WebInputEvent::SHIFT_KEY) ==
+ WebInputEvent::SHIFT_KEY,
+ (event.modifiers & WebInputEvent::CTRL_KEY) ==
+ WebInputEvent::CTRL_KEY,
+ (event.modifiers & WebInputEvent::ALT_KEY) ==
+ WebInputEvent::ALT_KEY);
+ if (focus_manager->ProcessAccelerator(accelerator, false))
+ return;
+ }
+ }
+
+ // Any unhandled keyboard/character messages should be defproced.
+ // This allows stuff like Alt+F4, etc to work correctly.
+ DefWindowProc(event.actual_message.hwnd,
+ event.actual_message.message,
+ event.actual_message.wParam,
+ event.actual_message.lParam);
+}
+
+void WebContentsViewWin::OnHScroll(int scroll_type, short position,
+ HWND scrollbar) {
ScrollCommon(WM_HSCROLL, scroll_type, position, scrollbar);
}
@@ -162,7 +230,8 @@ void WebContentsViewWin::OnMouseLeave() {
SetMsgHandled(FALSE);
}
-LRESULT WebContentsViewWin::OnMouseRange(UINT msg, WPARAM w_param, LPARAM l_param) {
+LRESULT WebContentsViewWin::OnMouseRange(UINT msg,
+ WPARAM w_param, LPARAM l_param) {
switch (msg) {
case WM_LBUTTONDOWN:
case WM_MBUTTONDOWN:
@@ -174,8 +243,10 @@ LRESULT WebContentsViewWin::OnMouseRange(UINT msg, WPARAM w_param, LPARAM l_para
case WM_MOUSEMOVE:
// Let our delegate know that the mouse moved (useful for resetting status
// bubble state).
- if (web_contents_->delegate())
- web_contents_->delegate()->ContentsMouseEvent(web_contents_, WM_MOUSEMOVE);
+ if (web_contents_->delegate()) {
+ web_contents_->delegate()->ContentsMouseEvent(web_contents_,
+ WM_MOUSEMOVE);
+ }
break;
default:
break;
@@ -234,14 +305,15 @@ void WebContentsViewWin::OnSetFocus(HWND window) {
// background from properly taking focus.
// We NULL-check the render_view_host_ here because Windows can send us
// messages during the destruction process after it has been destroyed.
- if (web_contents_->view()) {
- HWND inner_hwnd = web_contents_->view()->GetPluginHWND();
+ if (web_contents_->render_widget_host_view()) {
+ HWND inner_hwnd = web_contents_->render_widget_host_view()->GetPluginHWND();
if (::IsWindow(inner_hwnd))
::SetFocus(inner_hwnd);
}
}
-void WebContentsViewWin::OnVScroll(int scroll_type, short position, HWND scrollbar) {
+void WebContentsViewWin::OnVScroll(int scroll_type, short position,
+ HWND scrollbar) {
ScrollCommon(WM_VSCROLL, scroll_type, position, scrollbar);
}
@@ -264,8 +336,10 @@ void WebContentsViewWin::OnWindowPosChanged(WINDOWPOS* window_pos) {
// If we have a FindInPage dialog, notify it that the window changed.
if (web_contents_->find_in_page_controller_.get() &&
- web_contents_->find_in_page_controller_->IsVisible())
- web_contents_->find_in_page_controller_->MoveWindowIfNecessary(gfx::Rect());
+ web_contents_->find_in_page_controller_->IsVisible()) {
+ web_contents_->find_in_page_controller_->MoveWindowIfNecessary(
+ gfx::Rect());
+ }
}
}
@@ -299,8 +373,8 @@ void WebContentsViewWin::OnNCPaint(HRGN rgn) {
// here since the view will draw everything correctly.
}
-void WebContentsViewWin::ScrollCommon(UINT message, int scroll_type, short position,
- HWND scrollbar) {
+void WebContentsViewWin::ScrollCommon(UINT message, int scroll_type,
+ short position, HWND scrollbar) {
// This window can receive scroll events as a result of the ThinkPad's
// Trackpad scroll wheel emulation.
if (!ScrollZoom(scroll_type)) {
diff --git a/chrome/browser/web_contents_view_win.h b/chrome/browser/web_contents_view_win.h
index 09e80ff..75af28b 100644
--- a/chrome/browser/web_contents_view_win.h
+++ b/chrome/browser/web_contents_view_win.h
@@ -8,6 +8,8 @@
#include "chrome/browser/web_contents_view.h"
#include "chrome/views/hwnd_view_container.h"
+class InfoBarView;
+class InfoBarMessageView;
struct WebDropData;
class WebDropTarget;
@@ -35,10 +37,14 @@ class WebContentsViewWin : public WebContentsView,
virtual void GetContainerBounds(gfx::Rect* out) const;
virtual void StartDragging(const WebDropData& drop_data);
virtual void DetachPluginWindows();
+ virtual void DisplayErrorInInfoBar(const std::wstring& text);
virtual void SetInfoBarVisible(bool visible);
virtual bool IsInfoBarVisible() const;
virtual InfoBarView* GetInfoBarView();
virtual void UpdateDragCursor(bool is_drop_target);
+ virtual void ShowContextMenu(
+ const ViewHostMsg_ContextMenu_Params& params);
+ virtual void HandleKeyboardEvent(const WebKeyboardEvent& event);
private:
// Windows events ------------------------------------------------------------
@@ -77,6 +83,11 @@ class WebContentsViewWin : public WebContentsView,
// InfoBarView, lazily created.
scoped_ptr<InfoBarView> info_bar_view_;
+ // Info bar for crashed plugin message.
+ // IMPORTANT: This instance is owned by the InfoBarView. It is valid
+ // only if InfoBarView::GetChildIndex for this view is valid.
+ InfoBarMessageView* error_info_bar_message_;
+
// Whether the info bar view is visible.
bool info_bar_visible_;