This source file includes following definitions.
- PaintDetachedBookmarkBar
- PaintAttachedBookmarkBar
- ShouldSaveOrRestoreWindowPos
- GetContentsWebView
- GetWindowSwitcherButton
- DownloadShelfNeedsLayout
- IsTabStripVisible
- GetBoundsForTabStripInBrowserView
- GetTopInsetInBrowserView
- GetThemeBackgroundXInset
- IsToolbarVisible
- IsBookmarkBarVisible
- GetFullscreenExitBubble
- browser_
- Paint
- activate_modal_dialog_factory_
- Init
- GetBrowserViewForNativeWindow
- GetBrowserViewForBrowser
- InitStatusBubble
- InitPermissionBubbleView
- GetToolbarBounds
- GetFindBarBoundingBox
- GetTabStripHeight
- OffsetPointForToolbarBackgroundImage
- IsTabStripVisible
- IsOffTheRecord
- IsGuestSession
- IsRegularOrGuestSession
- GetOTRIconResourceID
- GetGuestIconResourceID
- ShouldShowAvatar
- GetAccelerator
- IsAcceleratorRegistered
- GetActiveWebContents
- GetOTRAvatarIcon
- Show
- ShowInactive
- Hide
- SetBounds
- Close
- Activate
- Deactivate
- IsActive
- FlashFrame
- IsAlwaysOnTop
- SetAlwaysOnTop
- GetNativeWindow
- GetBrowserWindowTesting
- GetStatusBubble
- UpdateTitleBar
- BookmarkBarStateChanged
- UpdateDevTools
- UpdateLoadingAnimations
- SetStarredState
- SetTranslateIconToggled
- OnActiveTabChanged
- ZoomChangedForActiveTab
- GetRestoredBounds
- GetRestoredState
- GetBounds
- IsMaximized
- IsMinimized
- Maximize
- Minimize
- Restore
- EnterFullscreen
- ExitFullscreen
- UpdateFullscreenExitBubbleContent
- ShouldHideUIForFullscreen
- IsFullscreen
- IsFullscreenBubbleVisible
- SetMetroSnapMode
- IsInMetroSnapMode
- RestoreFocus
- SetWindowSwitcherButton
- FullscreenStateChanged
- ToolbarSizeChanged
- GetLocationBar
- SetFocusToLocationBar
- UpdateReloadStopState
- UpdateToolbar
- FocusToolbar
- FocusBookmarksToolbar
- FocusInfobars
- FocusAppMenu
- RotatePaneFocus
- DestroyBrowser
- IsBookmarkBarVisible
- IsBookmarkBarAnimating
- IsTabStripEditable
- IsToolbarVisible
- GetRootWindowResizerRect
- ConfirmAddSearchProvider
- ShowUpdateChromeDialog
- ShowBookmarkBubble
- ShowBookmarkAppBubble
- ShowBookmarkPrompt
- ShowTranslateBubble
- ShowOneClickSigninBubble
- SetDownloadShelfVisible
- IsDownloadShelfVisible
- GetDownloadShelf
- ConfirmBrowserCloseWithPendingDownloads
- UserChangedTheme
- GetExtraRenderViewHeight
- WebContentsFocused
- ShowWebsiteSettings
- ShowAppMenu
- PreHandleKeyboardEvent
- HandleKeyboardEvent
- Cut
- Copy
- Paste
- GetDispositionForPopupBounds
- CreateFindBar
- GetWebContentsModalDialogHost
- GetBookmarkBarView
- GetLocationBarView
- GetTabContentsContainerView
- GetToolbarView
- TabInsertedAt
- TabDetachedAt
- TabDeactivated
- TabStripEmpty
- GetAcceleratorForCommandId
- CanResize
- CanMaximize
- CanActivate
- GetWindowTitle
- GetAccessibleWindowTitle
- GetInitiallyFocusedView
- ShouldShowWindowTitle
- GetWindowAppIcon
- GetWindowIcon
- ShouldShowWindowIcon
- ExecuteWindowsCommand
- GetWindowName
- SaveWindowPlacement
- GetSavedWindowPlacement
- GetContentsView
- CreateClientView
- OnWidgetActivationChanged
- OnWindowBeginUserBoundsChange
- OnWidgetMove
- GetWidget
- GetWidget
- GetAccessiblePanes
- CanClose
- NonClientHitTest
- GetMinimumSize
- GetClassName
- Layout
- PaintChildren
- ViewHierarchyChanged
- ChildPreferredSizeChanged
- GetAccessibleState
- AcceleratorPressed
- OnOmniboxPopupShownOrHidden
- GetInfoBarSeparatorColor
- InfoBarContainerStateChanged
- DrawInfoBarArrows
- OnSysColorChange
- InitViews
- LoadingAnimationCallback
- OnLoadCompleted
- GetBrowserViewLayout
- GetContentsLayoutManager
- MaybeShowBookmarkBar
- SetBookmarkBarParent
- MaybeShowInfoBar
- UpdateDevToolsForContents
- UpdateUIForContents
- ProcessFullscreen
- ShouldUseImmersiveFullscreenForUrl
- LoadAccelerators
- GetCommandIDForAppCommandID
- InitHangMonitor
- UpdateAcceleratorMetrics
- CreateBrowserWindow
- AdjustHostDesktopType
- ShowAvatarBubble
- ShowAvatarBubbleFromAvatarButton
- ShowPasswordGenerationBubble
- OverscrollUpdate
- GetRenderViewHeightInsetWithDetachedBookmarkBar
- ExecuteExtensionCommand
- ShowPageActionPopup
- ShowBrowserActionPopup
- DoCutCopyPaste
- DoCutCopyPasteForWebContents
- ActivateAppModalDialog
- GetMaxTopInfoBarArrowHeight
#include "chrome/browser/ui/views/frame/browser_view.h"
#include <algorithm>
#include "base/auto_reset.h"
#include "base/command_line.h"
#include "base/i18n/rtl.h"
#include "base/memory/scoped_ptr.h"
#include "base/metrics/histogram.h"
#include "base/prefs/pref_service.h"
#include "base/strings/string_number_conversions.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/app/chrome_dll_resource.h"
#include "chrome/browser/app_mode/app_mode_utils.h"
#include "chrome/browser/bookmarks/bookmark_stats.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/extensions/tab_helper.h"
#include "chrome/browser/infobars/infobar_service.h"
#include "chrome/browser/native_window_notification_source.h"
#include "chrome/browser/password_manager/chrome_password_manager_client.h"
#include "chrome/browser/profiles/avatar_menu.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_info_cache.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/profiles/profiles_state.h"
#include "chrome/browser/search/search.h"
#include "chrome/browser/sessions/tab_restore_service.h"
#include "chrome/browser/sessions/tab_restore_service_factory.h"
#include "chrome/browser/speech/tts_controller.h"
#include "chrome/browser/themes/theme_properties.h"
#include "chrome/browser/themes/theme_service_factory.h"
#include "chrome/browser/translate/translate_tab_helper.h"
#include "chrome/browser/ui/app_modal_dialogs/app_modal_dialog.h"
#include "chrome/browser/ui/app_modal_dialogs/app_modal_dialog_queue.h"
#include "chrome/browser/ui/bookmarks/bookmark_bar_constants.h"
#include "chrome/browser/ui/bookmarks/bookmark_bubble_delegate.h"
#include "chrome/browser/ui/bookmarks/bookmark_bubble_sign_in_delegate.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_command_controller.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/browser_dialogs.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/browser_window_state.h"
#include "chrome/browser/ui/ntp_background_util.h"
#include "chrome/browser/ui/omnibox/omnibox_popup_model.h"
#include "chrome/browser/ui/omnibox/omnibox_popup_view.h"
#include "chrome/browser/ui/omnibox/omnibox_view.h"
#include "chrome/browser/ui/search/search_delegate.h"
#include "chrome/browser/ui/search/search_model.h"
#include "chrome/browser/ui/search/search_ui.h"
#include "chrome/browser/ui/tabs/tab_menu_model.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/ui/view_ids.h"
#include "chrome/browser/ui/views/accelerator_table.h"
#include "chrome/browser/ui/views/accessibility/invert_bubble_view.h"
#include "chrome/browser/ui/views/avatar_menu_bubble_view.h"
#include "chrome/browser/ui/views/avatar_menu_button.h"
#include "chrome/browser/ui/views/bookmarks/bookmark_bar_view.h"
#include "chrome/browser/ui/views/bookmarks/bookmark_bubble_view.h"
#include "chrome/browser/ui/views/browser_dialogs.h"
#include "chrome/browser/ui/views/download/download_in_progress_dialog_view.h"
#include "chrome/browser/ui/views/download/download_shelf_view.h"
#include "chrome/browser/ui/views/extensions/bookmark_app_bubble_view.h"
#include "chrome/browser/ui/views/frame/browser_view_layout.h"
#include "chrome/browser/ui/views/frame/browser_view_layout_delegate.h"
#include "chrome/browser/ui/views/frame/contents_layout_manager.h"
#include "chrome/browser/ui/views/frame/immersive_mode_controller.h"
#include "chrome/browser/ui/views/frame/native_browser_frame_factory.h"
#include "chrome/browser/ui/views/frame/top_container_view.h"
#include "chrome/browser/ui/views/fullscreen_exit_bubble_views.h"
#include "chrome/browser/ui/views/infobars/infobar_container_view.h"
#include "chrome/browser/ui/views/location_bar/location_bar_view.h"
#include "chrome/browser/ui/views/location_bar/location_icon_view.h"
#include "chrome/browser/ui/views/omnibox/omnibox_view_views.h"
#include "chrome/browser/ui/views/password_generation_bubble_view.h"
#include "chrome/browser/ui/views/profile_chooser_view.h"
#include "chrome/browser/ui/views/status_bubble_views.h"
#include "chrome/browser/ui/views/tabs/browser_tab_strip_controller.h"
#include "chrome/browser/ui/views/tabs/tab.h"
#include "chrome/browser/ui/views/tabs/tab_strip.h"
#include "chrome/browser/ui/views/toolbar/reload_button.h"
#include "chrome/browser/ui/views/toolbar/toolbar_view.h"
#include "chrome/browser/ui/views/translate/translate_bubble_view.h"
#include "chrome/browser/ui/views/update_recommended_message_box.h"
#include "chrome/browser/ui/views/website_settings/permissions_bubble_view.h"
#include "chrome/browser/ui/views/website_settings/website_settings_popup_view.h"
#include "chrome/browser/ui/website_settings/permission_bubble_manager.h"
#include "chrome/browser/ui/window_sizer/window_sizer.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/profile_management_switches.h"
#include "chrome/common/url_constants.h"
#include "components/password_manager/core/browser/password_manager.h"
#include "content/public/browser/download_manager.h"
#include "content/public/browser/native_web_keyboard_event.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/user_metrics.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_view.h"
#include "content/public/common/content_switches.h"
#include "grit/chromium_strings.h"
#include "grit/generated_resources.h"
#include "grit/locale_settings.h"
#include "grit/theme_resources.h"
#include "grit/ui_resources.h"
#include "grit/ui_strings.h"
#include "grit/webkit_resources.h"
#include "ui/accessibility/ax_view_state.h"
#include "ui/base/accelerators/accelerator.h"
#include "ui/base/hit_test.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/base/theme_provider.h"
#include "ui/events/event_utils.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/color_utils.h"
#include "ui/gfx/rect_conversions.h"
#include "ui/gfx/sys_color_change_listener.h"
#include "ui/views/controls/button/menu_button.h"
#include "ui/views/controls/textfield/textfield.h"
#include "ui/views/controls/webview/webview.h"
#include "ui/views/focus/external_focus_tracker.h"
#include "ui/views/focus/view_storage.h"
#include "ui/views/layout/grid_layout.h"
#include "ui/views/widget/native_widget.h"
#include "ui/views/widget/root_view.h"
#include "ui/views/widget/widget.h"
#include "ui/views/window/dialog_delegate.h"
#if defined(USE_ASH)
#include "ash/ash_switches.h"
#include "ash/shelf/shelf.h"
#include "ash/shelf/shelf_model.h"
#include "ash/shell.h"
#include "chrome/browser/ui/ash/ash_util.h"
#endif
#if defined(USE_AURA)
#include "ui/aura/client/window_tree_client.h"
#include "ui/aura/window.h"
#include "ui/aura/window_tree_host.h"
#include "ui/gfx/screen.h"
#endif
#if defined(OS_WIN)
#include "base/win/windows_version.h"
#include "chrome/browser/jumplist_win.h"
#include "ui/views/win/scoped_fullscreen_visibility.h"
#include "win8/util/win8_util.h"
#endif
#if defined(ENABLE_ONE_CLICK_SIGNIN)
#include "chrome/browser/ui/sync/one_click_signin_bubble_delegate.h"
#include "chrome/browser/ui/sync/one_click_signin_bubble_links_delegate.h"
#include "chrome/browser/ui/views/sync/one_click_signin_bubble_view.h"
#endif
#if defined(OS_CHROMEOS)
#include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h"
#endif
using base::TimeDelta;
using base::UserMetricsAction;
using content::NativeWebKeyboardEvent;
using content::SSLStatus;
using content::WebContents;
using views::ColumnSet;
using views::GridLayout;
using web_modal::WebContentsModalDialogHost;
namespace {
const char* const kBrowserViewKey = "__BROWSER_VIEW__";
const int kLoadingAnimationFrameTimeMs = 30;
void PaintDetachedBookmarkBar(gfx::Canvas* canvas,
DetachableToolbarView* view,
ThemeService* theme_service) {
canvas->DrawColor(
chrome::GetDetachedBookmarkBarBackgroundColor(theme_service));
SkColor separator_color =
chrome::GetDetachedBookmarkBarSeparatorColor(theme_service);
DetachableToolbarView::PaintHorizontalBorder(canvas, view, true,
separator_color);
SkPaint paint;
paint.setAntiAlias(false);
paint.setStrokeWidth(0);
paint.setColor(SkColorSetA(separator_color,
SkColorGetA(separator_color) / 2));
float thickness = views::NonClientFrameView::kClientEdgeThickness /
canvas->image_scale();
SkScalar y = SkIntToScalar(view->height()) - SkFloatToScalar(thickness);
canvas->sk_canvas()->drawLine(SkIntToScalar(0), y,
SkIntToScalar(view->width()), y, paint);
}
void PaintAttachedBookmarkBar(gfx::Canvas* canvas,
DetachableToolbarView* view,
BrowserView* browser_view,
chrome::HostDesktopType host_desktop_type,
int toolbar_overlap) {
gfx::Point background_image_offset =
browser_view->OffsetPointForToolbarBackgroundImage(
gfx::Point(view->GetMirroredX(), view->y()));
DetachableToolbarView::PaintBackgroundAttachedMode(canvas,
view->GetThemeProvider(), view->GetLocalBounds(),
background_image_offset, host_desktop_type);
if (view->height() >= toolbar_overlap) {
DetachableToolbarView::PaintHorizontalBorder(canvas, view, false,
ThemeProperties::GetDefaultColor(
ThemeProperties::COLOR_TOOLBAR_SEPARATOR));
}
}
}
const char BrowserView::kViewClassName[] = "BrowserView";
namespace {
bool ShouldSaveOrRestoreWindowPos() {
#if defined(OS_WIN)
if (win8::IsSingleWindowMetroMode())
return false;
#endif
return true;
}
}
class BrowserViewLayoutDelegateImpl : public BrowserViewLayoutDelegate {
public:
explicit BrowserViewLayoutDelegateImpl(BrowserView* browser_view)
: browser_view_(browser_view) {}
virtual ~BrowserViewLayoutDelegateImpl() {}
virtual views::View* GetContentsWebView() const OVERRIDE {
return browser_view_->contents_web_view_;
}
virtual views::View* GetWindowSwitcherButton() const OVERRIDE {
return browser_view_->window_switcher_button();
}
virtual bool DownloadShelfNeedsLayout() const OVERRIDE {
DownloadShelfView* download_shelf = browser_view_->download_shelf_.get();
return download_shelf &&
(download_shelf->IsShowing() || download_shelf->IsClosing());
}
virtual bool IsTabStripVisible() const OVERRIDE {
return browser_view_->IsTabStripVisible();
}
virtual gfx::Rect GetBoundsForTabStripInBrowserView() const OVERRIDE {
gfx::RectF bounds_f(browser_view_->frame()->GetBoundsForTabStrip(
browser_view_->tabstrip()));
views::View::ConvertRectToTarget(browser_view_->parent(), browser_view_,
&bounds_f);
return gfx::ToEnclosingRect(bounds_f);
}
virtual int GetTopInsetInBrowserView() const OVERRIDE {
return browser_view_->frame()->GetTopInset() -
browser_view_->y();
}
virtual int GetThemeBackgroundXInset() const OVERRIDE {
return browser_view_->frame()->GetThemeBackgroundXInset();
}
virtual bool IsToolbarVisible() const OVERRIDE {
return browser_view_->IsToolbarVisible();
}
virtual bool IsBookmarkBarVisible() const OVERRIDE {
return browser_view_->IsBookmarkBarVisible();
}
virtual FullscreenExitBubbleViews* GetFullscreenExitBubble() const OVERRIDE {
return browser_view_->fullscreen_exit_bubble();
}
private:
BrowserView* browser_view_;
DISALLOW_COPY_AND_ASSIGN(BrowserViewLayoutDelegateImpl);
};
class BookmarkExtensionBackground : public views::Background {
public:
BookmarkExtensionBackground(BrowserView* browser_view,
DetachableToolbarView* host_view,
Browser* browser);
virtual void Paint(gfx::Canvas* canvas, views::View* view) const OVERRIDE;
private:
BrowserView* browser_view_;
DetachableToolbarView* host_view_;
Browser* browser_;
DISALLOW_COPY_AND_ASSIGN(BookmarkExtensionBackground);
};
BookmarkExtensionBackground::BookmarkExtensionBackground(
BrowserView* browser_view,
DetachableToolbarView* host_view,
Browser* browser)
: browser_view_(browser_view),
host_view_(host_view),
browser_(browser) {
}
void BookmarkExtensionBackground::Paint(gfx::Canvas* canvas,
views::View* view) const {
int toolbar_overlap = host_view_->GetToolbarOverlap();
if (!host_view_->IsDetached()) {
PaintAttachedBookmarkBar(canvas, host_view_, browser_view_,
browser_->host_desktop_type(), toolbar_overlap);
return;
}
double current_state = 1 - host_view_->GetAnimationValue();
ThemeService* ts =
ThemeServiceFactory::GetForProfile(browser_->profile());
if (current_state == 0.0 || current_state == 1.0) {
PaintDetachedBookmarkBar(canvas, host_view_, ts);
return;
}
int detached_alpha = static_cast<uint8>(current_state * 255);
int attached_alpha = 255 - detached_alpha;
if (browser_->bookmark_bar_state() == BookmarkBar::DETACHED) {
canvas->SaveLayerAlpha(attached_alpha);
PaintAttachedBookmarkBar(canvas, host_view_, browser_view_,
browser_->host_desktop_type(),
toolbar_overlap);
canvas->Restore();
canvas->SaveLayerAlpha(detached_alpha);
PaintDetachedBookmarkBar(canvas, host_view_, ts);
} else {
canvas->SaveLayerAlpha(detached_alpha);
PaintDetachedBookmarkBar(canvas, host_view_, ts);
canvas->Restore();
canvas->SaveLayerAlpha(attached_alpha);
PaintAttachedBookmarkBar(canvas, host_view_, browser_view_,
browser_->host_desktop_type(),
toolbar_overlap);
}
canvas->Restore();
}
BrowserView::BrowserView()
: views::ClientView(NULL, NULL),
last_focused_view_storage_id_(
views::ViewStorage::GetInstance()->CreateStorageID()),
frame_(NULL),
top_container_(NULL),
tabstrip_(NULL),
toolbar_(NULL),
window_switcher_button_(NULL),
find_bar_host_view_(NULL),
infobar_container_(NULL),
contents_web_view_(NULL),
contents_container_(NULL),
devtools_window_(NULL),
initialized_(false),
in_process_fullscreen_(false),
#if defined(OS_WIN)
hung_window_detector_(&hung_plugin_action_),
ticker_(0),
#endif
force_location_bar_focus_(false),
immersive_mode_controller_(chrome::CreateImmersiveModeController()),
#if defined(OS_CHROMEOS)
scroll_end_effect_controller_(ScrollEndEffectController::Create()),
#endif
color_change_listener_(this),
activate_modal_dialog_factory_(this) {
}
BrowserView::~BrowserView() {
DCHECK_EQ(0, browser_->tab_strip_model()->count());
immersive_mode_controller_.reset();
browser_->tab_strip_model()->RemoveObserver(this);
#if defined(OS_WIN)
ticker_.Stop();
ticker_.UnregisterTickHandler(&hung_window_detector_);
if (jumplist_) {
jumplist_->Terminate();
}
#endif
BrowserViewLayout* browser_view_layout = GetBrowserViewLayout();
if (browser_view_layout)
browser_view_layout->set_download_shelf(NULL);
download_shelf_.reset();
if (tabstrip_) {
tabstrip_->parent()->RemoveChildView(tabstrip_);
if (browser_view_layout)
browser_view_layout->set_tab_strip(NULL);
delete tabstrip_;
tabstrip_ = NULL;
}
RemoveAllChildViews(true);
toolbar_ = NULL;
browser_.reset();
}
void BrowserView::Init(Browser* browser) {
browser_.reset(browser);
browser_->tab_strip_model()->AddObserver(this);
}
BrowserView* BrowserView::GetBrowserViewForNativeWindow(
gfx::NativeWindow window) {
views::Widget* widget = views::Widget::GetWidgetForNativeWindow(window);
return widget ?
reinterpret_cast<BrowserView*>(widget->GetNativeWindowProperty(
kBrowserViewKey)) : NULL;
}
BrowserView* BrowserView::GetBrowserViewForBrowser(const Browser* browser) {
return static_cast<BrowserView*>(browser->window());
}
void BrowserView::InitStatusBubble() {
status_bubble_.reset(new StatusBubbleViews(contents_web_view_));
contents_web_view_->SetStatusBubble(status_bubble_.get());
}
void BrowserView::InitPermissionBubbleView() {
permission_bubble_view_.reset(new PermissionBubbleViewViews(
GetLocationBarView()->GetLocationIconView()));
}
gfx::Rect BrowserView::GetToolbarBounds() const {
gfx::Rect toolbar_bounds(toolbar_->bounds());
if (toolbar_bounds.IsEmpty())
return toolbar_bounds;
toolbar_bounds.Inset(-views::NonClientFrameView::kClientEdgeThickness, 0);
return toolbar_bounds;
}
gfx::Rect BrowserView::GetFindBarBoundingBox() const {
return GetBrowserViewLayout()->GetFindBarBoundingBox();
}
int BrowserView::GetTabStripHeight() const {
return IsTabStripVisible() ? tabstrip_->GetPreferredSize().height() : 0;
}
gfx::Point BrowserView::OffsetPointForToolbarBackgroundImage(
const gfx::Point& point) const {
gfx::Point window_point(point + GetMirroredPosition().OffsetFromOrigin());
window_point.Offset(frame_->GetThemeBackgroundXInset(),
-frame_->GetTopInset());
return window_point;
}
bool BrowserView::IsTabStripVisible() const {
if (immersive_mode_controller_->ShouldHideTopViews() &&
immersive_mode_controller_->ShouldHideTabIndicators())
return false;
return browser_->SupportsWindowFeature(Browser::FEATURE_TABSTRIP);
}
bool BrowserView::IsOffTheRecord() const {
return browser_->profile()->IsOffTheRecord();
}
bool BrowserView::IsGuestSession() const {
return browser_->profile()->IsGuestSession();
}
bool BrowserView::IsRegularOrGuestSession() const {
return profiles::IsRegularOrGuestSession(browser_.get());
}
int BrowserView::GetOTRIconResourceID() const {
int otr_resource_id = IDR_OTR_ICON;
if (ui::GetDisplayLayout() == ui::LAYOUT_TOUCH) {
if (IsFullscreen())
otr_resource_id = IDR_OTR_ICON_FULLSCREEN;
#if defined(OS_WIN)
if (win8::IsSingleWindowMetroMode())
otr_resource_id = IDR_OTR_ICON_FULLSCREEN;
#endif
}
return otr_resource_id;
}
int BrowserView::GetGuestIconResourceID() const {
return IDR_LOGIN_GUEST;
}
bool BrowserView::ShouldShowAvatar() const {
#if defined(OS_CHROMEOS)
if (!browser_->is_type_tabbed() && !browser_->is_app())
return false;
if (IsOffTheRecord() && !IsGuestSession())
return true;
if (!browser_->window())
return false;
return chrome::MultiUserWindowManager::ShouldShowAvatar(
browser_->window()->GetNativeWindow());
#else
if (!IsBrowserTypeNormal())
return false;
if (IsOffTheRecord())
return true;
if (!g_browser_process->profile_manager())
return false;
ProfileInfoCache& cache =
g_browser_process->profile_manager()->GetProfileInfoCache();
if (cache.GetIndexOfProfileWithPath(browser_->profile()->GetPath()) ==
std::string::npos) {
return false;
}
return AvatarMenu::ShouldShowAvatarMenu();
#endif
}
bool BrowserView::GetAccelerator(int cmd_id, ui::Accelerator* accelerator) {
if (chrome::GetStandardAcceleratorForCommandId(cmd_id, accelerator))
return true;
for (std::map<ui::Accelerator, int>::const_iterator it =
accelerator_table_.begin(); it != accelerator_table_.end(); ++it) {
if (it->second == cmd_id) {
*accelerator = it->first;
return true;
}
}
return chrome::GetAshAcceleratorForCommandId(
cmd_id, browser_->host_desktop_type(), accelerator);
}
bool BrowserView::IsAcceleratorRegistered(const ui::Accelerator& accelerator) {
return accelerator_table_.find(accelerator) != accelerator_table_.end();
}
WebContents* BrowserView::GetActiveWebContents() const {
return browser_->tab_strip_model()->GetActiveWebContents();
}
gfx::ImageSkia BrowserView::GetOTRAvatarIcon() const {
return *GetThemeProvider()->GetImageSkiaNamed(GetOTRIconResourceID());
}
void BrowserView::Show() {
if (frame_->IsVisible()) {
frame_->Activate();
return;
}
force_location_bar_focus_ = true;
RestoreFocus();
frame_->Show();
force_location_bar_focus_ = false;
browser()->OnWindowDidShow();
chrome::MaybeShowInvertBubbleView(this);
}
void BrowserView::ShowInactive() {
if (!frame_->IsVisible())
frame_->ShowInactive();
}
void BrowserView::Hide() {
}
void BrowserView::SetBounds(const gfx::Rect& bounds) {
ExitFullscreen();
GetWidget()->SetBounds(bounds);
}
void BrowserView::Close() {
frame_->Close();
}
void BrowserView::Activate() {
frame_->Activate();
}
void BrowserView::Deactivate() {
frame_->Deactivate();
}
bool BrowserView::IsActive() const {
return frame_->IsActive();
}
void BrowserView::FlashFrame(bool flash) {
frame_->FlashFrame(flash);
}
bool BrowserView::IsAlwaysOnTop() const {
return false;
}
void BrowserView::SetAlwaysOnTop(bool always_on_top) {
NOTIMPLEMENTED();
}
gfx::NativeWindow BrowserView::GetNativeWindow() {
if (!GetWidget())
return NULL;
return GetWidget()->GetTopLevelWidget()->GetNativeWindow();
}
BrowserWindowTesting* BrowserView::GetBrowserWindowTesting() {
return this;
}
StatusBubble* BrowserView::GetStatusBubble() {
return status_bubble_.get();
}
namespace {
enum CallState { NORMAL, REENTRANT, REENTRANT_FORCE_FAST_RESIZE };
}
void BrowserView::UpdateTitleBar() {
frame_->UpdateWindowTitle();
if (ShouldShowWindowIcon() && !loading_animation_timer_.IsRunning())
frame_->UpdateWindowIcon();
}
void BrowserView::BookmarkBarStateChanged(
BookmarkBar::AnimateChangeType change_type) {
if (bookmark_bar_view_.get()) {
BookmarkBar::State new_state = browser_->bookmark_bar_state();
bool detached_changed = (new_state == BookmarkBar::DETACHED) ||
bookmark_bar_view_->IsDetached();
if (detached_changed && immersive_mode_controller_->IsEnabled())
change_type = BookmarkBar::DONT_ANIMATE_STATE_CHANGE;
bookmark_bar_view_->SetBookmarkBarState(new_state, change_type);
}
if (MaybeShowBookmarkBar(GetActiveWebContents()))
Layout();
}
void BrowserView::UpdateDevTools() {
UpdateDevToolsForContents(GetActiveWebContents(), true);
Layout();
}
void BrowserView::UpdateLoadingAnimations(bool should_animate) {
if (should_animate) {
if (!loading_animation_timer_.IsRunning()) {
last_animation_time_ = base::TimeTicks::Now();
loading_animation_timer_.Start(FROM_HERE,
TimeDelta::FromMilliseconds(kLoadingAnimationFrameTimeMs), this,
&BrowserView::LoadingAnimationCallback);
}
} else {
if (loading_animation_timer_.IsRunning()) {
last_animation_time_ = base::TimeTicks();
loading_animation_timer_.Stop();
LoadingAnimationCallback();
}
}
}
void BrowserView::SetStarredState(bool is_starred) {
GetLocationBarView()->SetStarToggled(is_starred);
}
void BrowserView::SetTranslateIconToggled(bool is_lit) {
GetLocationBarView()->SetTranslateIconToggled(is_lit);
}
void BrowserView::OnActiveTabChanged(content::WebContents* old_contents,
content::WebContents* new_contents,
int index,
int reason) {
DCHECK(new_contents);
bool change_tab_contents =
contents_web_view_->web_contents() != new_contents;
if (change_tab_contents) {
contents_web_view_->SetWebContents(NULL);
devtools_web_view_->SetWebContents(NULL);
}
InfoBarManager* infobar_manager =
InfoBarService::InfoBarManagerFromWebContents(new_contents);
infobar_container_->ChangeInfoBarManager(infobar_manager);
if (old_contents && PermissionBubbleManager::FromWebContents(old_contents))
PermissionBubbleManager::FromWebContents(old_contents)->SetView(NULL);
if (new_contents && PermissionBubbleManager::FromWebContents(new_contents)) {
PermissionBubbleManager::FromWebContents(new_contents)->SetView(
permission_bubble_view_.get());
}
if (bookmark_bar_view_.get()) {
bookmark_bar_view_->SetBookmarkBarState(
browser_->bookmark_bar_state(),
BookmarkBar::DONT_ANIMATE_STATE_CHANGE);
}
UpdateUIForContents(new_contents);
UpdateDevToolsForContents(new_contents, !change_tab_contents);
if (change_tab_contents) {
contents_web_view_->SetWebContents(new_contents);
UpdateDevToolsForContents(new_contents, true);
}
if (!browser_->tab_strip_model()->closing_all() && GetWidget()->IsActive() &&
GetWidget()->IsVisible()) {
new_contents->GetView()->RestoreFocus();
}
UpdateTitleBar();
}
void BrowserView::ZoomChangedForActiveTab(bool can_show_bubble) {
GetLocationBarView()->ZoomChangedForActiveTab(
can_show_bubble && !toolbar_->IsWrenchMenuShowing());
}
gfx::Rect BrowserView::GetRestoredBounds() const {
return frame_->GetRestoredBounds();
}
ui::WindowShowState BrowserView::GetRestoredState() const {
if (IsMaximized())
return ui::SHOW_STATE_MAXIMIZED;
if (IsMinimized())
return ui::SHOW_STATE_MINIMIZED;
return ui::SHOW_STATE_NORMAL;
}
gfx::Rect BrowserView::GetBounds() const {
return frame_->GetWindowBoundsInScreen();
}
bool BrowserView::IsMaximized() const {
return frame_->IsMaximized();
}
bool BrowserView::IsMinimized() const {
return frame_->IsMinimized();
}
void BrowserView::Maximize() {
frame_->Maximize();
}
void BrowserView::Minimize() {
frame_->Minimize();
}
void BrowserView::Restore() {
frame_->Restore();
}
void BrowserView::EnterFullscreen(
const GURL& url, FullscreenExitBubbleType bubble_type) {
if (IsFullscreen())
return;
ProcessFullscreen(true, FOR_DESKTOP, url, bubble_type);
}
void BrowserView::ExitFullscreen() {
if (!IsFullscreen())
return;
ProcessFullscreen(false, FOR_DESKTOP, GURL(), FEB_TYPE_NONE);
}
void BrowserView::UpdateFullscreenExitBubbleContent(
const GURL& url,
FullscreenExitBubbleType bubble_type) {
if (bubble_type == FEB_TYPE_NONE || ShouldUseImmersiveFullscreenForUrl(url)) {
fullscreen_bubble_.reset();
} else if (fullscreen_bubble_.get()) {
fullscreen_bubble_->UpdateContent(url, bubble_type);
} else {
fullscreen_bubble_.reset(new FullscreenExitBubbleViews(
this, url, bubble_type));
}
}
bool BrowserView::ShouldHideUIForFullscreen() const {
#if defined(USE_ASH)
if (immersive_mode_controller_->IsEnabled())
return false;
#endif
return IsFullscreen();
}
bool BrowserView::IsFullscreen() const {
return frame_->IsFullscreen();
}
bool BrowserView::IsFullscreenBubbleVisible() const {
return fullscreen_bubble_ != NULL;
}
#if defined(OS_WIN)
void BrowserView::SetMetroSnapMode(bool enable) {
HISTOGRAM_COUNTS("Metro.SnapModeToggle", enable);
ProcessFullscreen(enable, FOR_METRO, GURL(), FEB_TYPE_NONE);
}
bool BrowserView::IsInMetroSnapMode() const {
return false;
}
#endif
void BrowserView::RestoreFocus() {
WebContents* selected_web_contents = GetActiveWebContents();
if (selected_web_contents)
selected_web_contents->GetView()->RestoreFocus();
}
void BrowserView::SetWindowSwitcherButton(views::Button* button) {
if (window_switcher_button_)
RemoveChildView(window_switcher_button_);
window_switcher_button_ = button;
}
void BrowserView::FullscreenStateChanged() {
CHECK(!IsFullscreen());
ProcessFullscreen(false, FOR_DESKTOP, GURL(), FEB_TYPE_NONE);
}
void BrowserView::ToolbarSizeChanged(bool is_animating) {
static CallState call_state = NORMAL;
bool use_fast_resize =
is_animating || (call_state == REENTRANT_FORCE_FAST_RESIZE);
if (use_fast_resize)
contents_web_view_->SetFastResize(true);
UpdateUIForContents(GetActiveWebContents());
if (use_fast_resize)
contents_web_view_->SetFastResize(false);
{
base::AutoReset<CallState> resetter(&call_state,
is_animating ? REENTRANT_FORCE_FAST_RESIZE : REENTRANT);
infobar_container_->SetMaxTopArrowHeight(GetMaxTopInfoBarArrowHeight());
}
if ((call_state == NORMAL) && !is_animating) {
contents_web_view_->InvalidateLayout();
contents_container_->Layout();
}
}
LocationBar* BrowserView::GetLocationBar() const {
return GetLocationBarView();
}
void BrowserView::SetFocusToLocationBar(bool select_all) {
if (!force_location_bar_focus_ && !IsActive())
return;
scoped_ptr<ImmersiveRevealedLock> focus_reveal_lock(
immersive_mode_controller_->GetRevealedLock(
ImmersiveModeController::ANIMATE_REVEAL_YES));
LocationBarView* location_bar = GetLocationBarView();
if (location_bar->omnibox_view()->IsFocusable()) {
if (select_all &&
location_bar->GetToolbarModel()->WouldOmitURLDueToOriginChip())
location_bar->ShowURL();
else
location_bar->FocusLocation(select_all);
} else {
views::FocusManager* focus_manager = GetFocusManager();
DCHECK(focus_manager);
focus_manager->ClearFocus();
}
}
void BrowserView::UpdateReloadStopState(bool is_loading, bool force) {
toolbar_->reload_button()->ChangeMode(
is_loading ? ReloadButton::MODE_STOP : ReloadButton::MODE_RELOAD, force);
}
void BrowserView::UpdateToolbar(content::WebContents* contents) {
if (toolbar_)
toolbar_->Update(contents);
}
void BrowserView::FocusToolbar() {
scoped_ptr<ImmersiveRevealedLock> focus_reveal_lock(
immersive_mode_controller_->GetRevealedLock(
ImmersiveModeController::ANIMATE_REVEAL_YES));
toolbar_->SetPaneFocus(NULL);
}
void BrowserView::FocusBookmarksToolbar() {
DCHECK(!immersive_mode_controller_->IsEnabled());
if (bookmark_bar_view_.get() &&
bookmark_bar_view_->visible() &&
bookmark_bar_view_->GetPreferredSize().height() != 0) {
bookmark_bar_view_->SetPaneFocusAndFocusDefault();
}
}
void BrowserView::FocusInfobars() {
if (infobar_container_->child_count() > 0)
infobar_container_->SetPaneFocusAndFocusDefault();
}
void BrowserView::FocusAppMenu() {
if (toolbar_->IsAppMenuFocused()) {
RestoreFocus();
} else {
DCHECK(!immersive_mode_controller_->IsEnabled());
toolbar_->SetPaneFocusAndFocusAppMenu();
}
}
void BrowserView::RotatePaneFocus(bool forwards) {
GetWidget()->GetFocusManager()->RotatePaneFocus(
forwards ?
views::FocusManager::kForward : views::FocusManager::kBackward,
views::FocusManager::kWrap);
}
void BrowserView::DestroyBrowser() {
GetWidget()->RemoveObserver(this);
GetLocationBar()->GetOmniboxView()->model()->popup_model()->RemoveObserver(
this);
frame_->CloseNow();
}
bool BrowserView::IsBookmarkBarVisible() const {
if (!browser_->SupportsWindowFeature(Browser::FEATURE_BOOKMARKBAR))
return false;
if (!bookmark_bar_view_.get())
return false;
if (bookmark_bar_view_->GetPreferredSize().height() == 0)
return false;
if (immersive_mode_controller_->ShouldHideTopViews() &&
!bookmark_bar_view_->IsDetached())
return false;
return true;
}
bool BrowserView::IsBookmarkBarAnimating() const {
return bookmark_bar_view_.get() && bookmark_bar_view_->is_animating();
}
bool BrowserView::IsTabStripEditable() const {
return tabstrip_->IsTabStripEditable();
}
bool BrowserView::IsToolbarVisible() const {
if (immersive_mode_controller_->ShouldHideTopViews())
return false;
return browser_->SupportsWindowFeature(Browser::FEATURE_TOOLBAR) ||
browser_->SupportsWindowFeature(Browser::FEATURE_LOCATIONBAR);
}
gfx::Rect BrowserView::GetRootWindowResizerRect() const {
return gfx::Rect();
}
void BrowserView::ConfirmAddSearchProvider(TemplateURL* template_url,
Profile* profile) {
chrome::EditSearchEngine(GetWidget()->GetNativeWindow(), template_url, NULL,
profile);
}
void BrowserView::ShowUpdateChromeDialog() {
UpdateRecommendedMessageBox::Show(GetWidget()->GetNativeWindow());
}
void BrowserView::ShowBookmarkBubble(const GURL& url, bool already_bookmarked) {
scoped_ptr<BookmarkBubbleDelegate> delegate;
delegate.reset(new BookmarkBubbleSignInDelegate(browser_.get()));
BookmarkBubbleView::ShowBubble(GetToolbarView()->GetBookmarkBubbleAnchor(),
bookmark_bar_view_.get(),
delegate.Pass(),
browser_->profile(),
url,
!already_bookmarked);
}
void BrowserView::ShowBookmarkAppBubble(
const WebApplicationInfo& web_app_info,
const std::string& extension_id) {
BookmarkAppBubbleView::ShowBubble(GetToolbarView(),
browser_->profile(),
web_app_info,
extension_id);
}
void BrowserView::ShowBookmarkPrompt() {
GetLocationBarView()->ShowBookmarkPrompt();
}
void BrowserView::ShowTranslateBubble(content::WebContents* web_contents,
TranslateTabHelper::TranslateStep step,
TranslateErrors::Type error_type) {
TranslateTabHelper* translate_tab_helper =
TranslateTabHelper::FromWebContents(web_contents);
LanguageState& language_state = translate_tab_helper->GetLanguageState();
language_state.SetTranslateEnabled(true);
TranslateBubbleView::ShowBubble(
GetToolbarView()->GetTranslateBubbleAnchor(), web_contents, step,
error_type);
}
#if defined(ENABLE_ONE_CLICK_SIGNIN)
void BrowserView::ShowOneClickSigninBubble(
OneClickSigninBubbleType type,
const base::string16& email,
const base::string16& error_message,
const StartSyncCallback& start_sync_callback) {
scoped_ptr<OneClickSigninBubbleDelegate> delegate;
delegate.reset(new OneClickSigninBubbleLinksDelegate(browser()));
views::View* anchor_view;
if (type == BrowserWindow::ONE_CLICK_SIGNIN_BUBBLE_TYPE_BUBBLE)
anchor_view = toolbar_->app_menu();
else
anchor_view = toolbar_->location_bar();
OneClickSigninBubbleView::ShowBubble(type, email, error_message,
delegate.Pass(), anchor_view,
start_sync_callback);
}
#endif
void BrowserView::SetDownloadShelfVisible(bool visible) {
if (browser_ == NULL)
return;
if (visible && IsDownloadShelfVisible() != visible) {
GetDownloadShelf();
}
if (browser_ != NULL)
browser_->UpdateDownloadShelfVisibility(visible);
ToolbarSizeChanged(false);
}
bool BrowserView::IsDownloadShelfVisible() const {
return download_shelf_.get() && download_shelf_->IsShowing();
}
DownloadShelf* BrowserView::GetDownloadShelf() {
if (!download_shelf_.get()) {
download_shelf_.reset(new DownloadShelfView(browser_.get(), this));
download_shelf_->set_owned_by_client();
GetBrowserViewLayout()->set_download_shelf(download_shelf_.get());
}
return download_shelf_.get();
}
void BrowserView::ConfirmBrowserCloseWithPendingDownloads(
int download_count,
Browser::DownloadClosePreventionType dialog_type,
bool app_modal,
const base::Callback<void(bool)>& callback) {
DownloadInProgressDialogView::Show(
GetNativeWindow(), download_count, dialog_type, app_modal, callback);
}
void BrowserView::UserChangedTheme() {
frame_->FrameTypeChanged();
}
int BrowserView::GetExtraRenderViewHeight() const {
return 0;
}
void BrowserView::WebContentsFocused(WebContents* contents) {
if (contents_web_view_->GetWebContents() == contents)
contents_web_view_->OnWebContentsFocused(contents);
else
devtools_web_view_->OnWebContentsFocused(contents);
}
void BrowserView::ShowWebsiteSettings(Profile* profile,
content::WebContents* web_contents,
const GURL& url,
const content::SSLStatus& ssl) {
WebsiteSettingsPopupView::ShowPopup(
GetLocationBarView()->GetLocationIconView(), profile,
web_contents, url, ssl, browser_.get());
}
void BrowserView::ShowAppMenu() {
scoped_ptr<ImmersiveRevealedLock> revealed_lock(
immersive_mode_controller_->GetRevealedLock(
ImmersiveModeController::ANIMATE_REVEAL_NO));
toolbar_->app_menu()->Activate();
}
bool BrowserView::PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event,
bool* is_keyboard_shortcut) {
*is_keyboard_shortcut = false;
if ((event.type != blink::WebInputEvent::RawKeyDown) &&
(event.type != blink::WebInputEvent::KeyUp)) {
return false;
}
views::FocusManager* focus_manager = GetFocusManager();
DCHECK(focus_manager);
if (focus_manager->shortcut_handling_suspended())
return false;
ui::Accelerator accelerator(
static_cast<ui::KeyboardCode>(event.windowsKeyCode),
content::GetModifiersFromNativeWebKeyboardEvent(event));
if (event.type == blink::WebInputEvent::KeyUp)
accelerator.set_type(ui::ET_KEY_RELEASED);
if (browser_->is_app()) {
return false;
}
chrome::BrowserCommandController* controller = browser_->command_controller();
bool original_block_command_state = controller->block_command_execution();
controller->SetBlockCommandExecution(true);
const bool processed = focus_manager->ProcessAccelerator(accelerator);
const int id = controller->GetLastBlockedCommand(NULL);
controller->SetBlockCommandExecution(original_block_command_state);
if (controller->IsReservedCommandOrKey(id, event)) {
UpdateAcceleratorMetrics(accelerator, id);
return chrome::ExecuteCommand(browser_.get(), id);
}
if (id != -1) {
if (event.type == blink::WebInputEvent::RawKeyDown)
*is_keyboard_shortcut = true;
} else if (processed) {
return true;
}
return false;
}
void BrowserView::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
unhandled_keyboard_event_handler_.HandleKeyboardEvent(event,
GetFocusManager());
}
void BrowserView::Cut() {
DoCutCopyPaste(&content::RenderFrameHost::Cut, IDS_APP_CUT);
}
void BrowserView::Copy() {
DoCutCopyPaste(&content::RenderFrameHost::Copy, IDS_APP_COPY);
}
void BrowserView::Paste() {
DoCutCopyPaste(&content::RenderFrameHost::Paste, IDS_APP_PASTE);
}
WindowOpenDisposition BrowserView::GetDispositionForPopupBounds(
const gfx::Rect& bounds) {
#if defined(OS_WIN)
return win8::IsSingleWindowMetroMode() ? NEW_BACKGROUND_TAB : NEW_POPUP;
#else
return NEW_POPUP;
#endif
}
FindBar* BrowserView::CreateFindBar() {
return chrome::CreateFindBar(this);
}
WebContentsModalDialogHost* BrowserView::GetWebContentsModalDialogHost() {
return GetBrowserViewLayout()->GetWebContentsModalDialogHost();
}
BookmarkBarView* BrowserView::GetBookmarkBarView() const {
return bookmark_bar_view_.get();
}
LocationBarView* BrowserView::GetLocationBarView() const {
return toolbar_ ? toolbar_->location_bar() : NULL;
}
views::View* BrowserView::GetTabContentsContainerView() const {
return contents_web_view_;
}
ToolbarView* BrowserView::GetToolbarView() const {
return toolbar_;
}
void BrowserView::TabInsertedAt(WebContents* contents,
int index,
bool foreground) {
if (!contents->GetView()->GetNativeView()->GetRootWindow()) {
aura::Window* window = contents->GetView()->GetNativeView();
aura::Window* root_window = GetNativeWindow()->GetRootWindow();
aura::client::ParentWindowWithContext(
window, root_window, root_window->GetBoundsInScreen());
DCHECK(contents->GetView()->GetNativeView()->GetRootWindow());
}
}
void BrowserView::TabDetachedAt(WebContents* contents, int index) {
if (PermissionBubbleManager::FromWebContents(contents))
PermissionBubbleManager::FromWebContents(contents)->SetView(NULL);
if (index == browser_->tab_strip_model()->active_index()) {
contents_web_view_->SetWebContents(NULL);
infobar_container_->ChangeInfoBarManager(NULL);
UpdateDevToolsForContents(NULL, true);
}
}
void BrowserView::TabDeactivated(WebContents* contents) {
if (PermissionBubbleManager::FromWebContents(contents))
PermissionBubbleManager::FromWebContents(contents)->SetView(NULL);
if (!contents->IsBeingDestroyed())
contents->GetView()->StoreFocus();
}
void BrowserView::TabStripEmpty() {
UpdateUIForContents(NULL);
}
bool BrowserView::GetAcceleratorForCommandId(int command_id,
ui::Accelerator* accelerator) {
return toolbar_->GetAcceleratorForCommandId(command_id, accelerator);
}
bool BrowserView::CanResize() const {
return true;
}
bool BrowserView::CanMaximize() const {
return true;
}
bool BrowserView::CanActivate() const {
if (!AppModalDialogQueue::GetInstance()->active_dialog() ||
!AppModalDialogQueue::GetInstance()->active_dialog()->native_dialog())
return true;
#if defined(USE_AURA) && defined(OS_CHROMEOS)
AppModalDialogQueue::GetInstance()->ActivateModalDialog();
#else
base::MessageLoop::current()->PostTask(
FROM_HERE,
base::Bind(&BrowserView::ActivateAppModalDialog,
activate_modal_dialog_factory_.GetWeakPtr()));
#endif
return false;
}
base::string16 BrowserView::GetWindowTitle() const {
return browser_->GetWindowTitleForCurrentTab();
}
base::string16 BrowserView::GetAccessibleWindowTitle() const {
if (IsOffTheRecord()) {
return l10n_util::GetStringFUTF16(
IDS_ACCESSIBLE_INCOGNITO_WINDOW_TITLE_FORMAT,
GetWindowTitle());
}
return GetWindowTitle();
}
views::View* BrowserView::GetInitiallyFocusedView() {
return NULL;
}
bool BrowserView::ShouldShowWindowTitle() const {
if (browser_->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH &&
browser_->is_app() && browser_->app_type() == Browser::APP_TYPE_HOST)
return false;
return browser_->SupportsWindowFeature(Browser::FEATURE_TITLEBAR);
}
gfx::ImageSkia BrowserView::GetWindowAppIcon() {
if (browser_->is_app()) {
WebContents* contents = browser_->tab_strip_model()->GetActiveWebContents();
extensions::TabHelper* extensions_tab_helper =
contents ? extensions::TabHelper::FromWebContents(contents) : NULL;
if (extensions_tab_helper && extensions_tab_helper->GetExtensionAppIcon())
return gfx::ImageSkia::CreateFrom1xBitmap(
*extensions_tab_helper->GetExtensionAppIcon());
}
return GetWindowIcon();
}
gfx::ImageSkia BrowserView::GetWindowIcon() {
if (browser_->is_app() || browser_->is_type_popup())
return browser_->GetCurrentPageIcon().AsImageSkia();
return gfx::ImageSkia();
}
bool BrowserView::ShouldShowWindowIcon() const {
if (browser_->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH &&
browser_->is_app() && browser_->app_type() == Browser::APP_TYPE_HOST)
return false;
return browser_->SupportsWindowFeature(Browser::FEATURE_TITLEBAR);
}
bool BrowserView::ExecuteWindowsCommand(int command_id) {
#if defined(OS_WIN)
if (command_id == IDC_DEBUG_FRAME_TOGGLE)
GetWidget()->DebugToggleFrameType();
if (win8::IsSingleWindowMetroMode()) {
static const int sc_mask = 0xFFF0;
if (((command_id & sc_mask) == SC_MOVE) ||
((command_id & sc_mask) == SC_SIZE) ||
((command_id & sc_mask) == SC_MAXIMIZE))
return true;
}
#endif
int command_id_from_app_command = GetCommandIDForAppCommandID(command_id);
if (command_id_from_app_command != -1)
command_id = command_id_from_app_command;
return chrome::ExecuteCommand(browser_.get(), command_id);
}
std::string BrowserView::GetWindowName() const {
return chrome::GetWindowPlacementKey(browser_.get());
}
void BrowserView::SaveWindowPlacement(const gfx::Rect& bounds,
ui::WindowShowState show_state) {
if (!ShouldSaveOrRestoreWindowPos())
return;
if (!IsFullscreen() && chrome::ShouldSaveWindowPlacement(browser_.get())) {
WidgetDelegate::SaveWindowPlacement(bounds, show_state);
chrome::SaveWindowPlacement(browser_.get(), bounds, show_state);
}
}
bool BrowserView::GetSavedWindowPlacement(
const views::Widget* widget,
gfx::Rect* bounds,
ui::WindowShowState* show_state) const {
if (!ShouldSaveOrRestoreWindowPos())
return false;
chrome::GetSavedWindowBoundsAndShowState(browser_.get(), bounds, show_state);
if (browser_->is_type_popup() &&
!browser_->is_app() &&
!browser_->is_devtools()) {
if (IsToolbarVisible()) {
bounds->set_height(
bounds->height() + toolbar_->GetPreferredSize().height());
}
gfx::Rect window_rect = frame_->non_client_view()->
GetWindowBoundsForClientBounds(*bounds);
window_rect.set_origin(bounds->origin());
if (window_rect.x() == 0 && window_rect.y() == 0) {
gfx::Size size = window_rect.size();
window_rect.set_origin(
WindowSizer::GetDefaultPopupOrigin(size,
browser_->host_desktop_type()));
}
*bounds = window_rect;
*show_state = ui::SHOW_STATE_NORMAL;
}
return true;
}
views::View* BrowserView::GetContentsView() {
return contents_web_view_;
}
views::ClientView* BrowserView::CreateClientView(views::Widget* widget) {
return this;
}
void BrowserView::OnWidgetActivationChanged(views::Widget* widget,
bool active) {
if (active)
BrowserList::SetLastActive(browser_.get());
}
void BrowserView::OnWindowBeginUserBoundsChange() {
WebContents* web_contents = GetActiveWebContents();
if (!web_contents)
return;
web_contents->GetRenderViewHost()->NotifyMoveOrResizeStarted();
}
void BrowserView::OnWidgetMove() {
if (!initialized_) {
return;
}
if (status_bubble_.get())
status_bubble_->Reposition();
BookmarkBubbleView::Hide();
LocationBarView* location_bar_view = GetLocationBarView();
if (location_bar_view)
location_bar_view->GetOmniboxView()->CloseOmniboxPopup();
}
views::Widget* BrowserView::GetWidget() {
return View::GetWidget();
}
const views::Widget* BrowserView::GetWidget() const {
return View::GetWidget();
}
void BrowserView::GetAccessiblePanes(std::vector<views::View*>* panes) {
panes->push_back(toolbar_);
if (bookmark_bar_view_.get())
panes->push_back(bookmark_bar_view_.get());
if (infobar_container_)
panes->push_back(infobar_container_);
if (download_shelf_.get())
panes->push_back(download_shelf_.get());
panes->push_back(GetTabContentsContainerView());
if (devtools_web_view_->visible())
panes->push_back(devtools_web_view_);
}
bool BrowserView::CanClose() {
if (tabstrip_ && !tabstrip_->IsTabStripCloseable())
return false;
if (!browser_->ShouldCloseWindow())
return false;
bool fast_tab_closing_enabled =
CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableFastUnload);
if (!browser_->tab_strip_model()->empty()) {
frame_->Hide();
browser_->OnWindowClosing();
if (fast_tab_closing_enabled)
browser_->tab_strip_model()->CloseAllTabs();
return false;
} else if (fast_tab_closing_enabled &&
!browser_->HasCompletedUnloadProcessing()) {
frame_->Hide();
return false;
}
content::NotificationService::current()->Notify(
chrome::NOTIFICATION_WINDOW_CLOSED,
content::Source<gfx::NativeWindow>(frame_->GetNativeWindow()),
content::NotificationService::NoDetails());
return true;
}
int BrowserView::NonClientHitTest(const gfx::Point& point) {
return GetBrowserViewLayout()->NonClientHitTest(point);
}
gfx::Size BrowserView::GetMinimumSize() {
return GetBrowserViewLayout()->GetMinimumSize();
}
const char* BrowserView::GetClassName() const {
return kViewClassName;
}
void BrowserView::Layout() {
if (!initialized_ || in_process_fullscreen_)
return;
views::View::Layout();
toolbar_->location_bar()->omnibox_view()->SetFocusable(IsToolbarVisible());
}
void BrowserView::PaintChildren(gfx::Canvas* canvas) {
for (int i = 0; i < child_count(); ++i) {
View* child = child_at(i);
if (child != infobar_container_ && !child->layer())
child->Paint(canvas);
}
infobar_container_->Paint(canvas);
}
void BrowserView::ViewHierarchyChanged(
const ViewHierarchyChangedDetails& details) {
if (!initialized_ && details.is_add && details.child == this && GetWidget()) {
InitViews();
initialized_ = true;
}
}
void BrowserView::ChildPreferredSizeChanged(View* child) {
Layout();
}
void BrowserView::GetAccessibleState(ui::AXViewState* state) {
state->role = ui::AX_ROLE_CLIENT;
}
bool BrowserView::AcceleratorPressed(const ui::Accelerator& accelerator) {
#if defined(OS_CHROMEOS)
if (accelerator.key_code() == ui::VKEY_LWIN &&
g_browser_process->local_state()->GetBoolean(
prefs::kSpokenFeedbackEnabled)) {
TtsController::GetInstance()->Stop();
return false;
}
#endif
std::map<ui::Accelerator, int>::const_iterator iter =
accelerator_table_.find(accelerator);
DCHECK(iter != accelerator_table_.end());
int command_id = iter->second;
chrome::BrowserCommandController* controller = browser_->command_controller();
if (!controller->block_command_execution())
UpdateAcceleratorMetrics(accelerator, command_id);
return chrome::ExecuteCommand(browser_.get(), command_id);
}
void BrowserView::OnOmniboxPopupShownOrHidden() {
infobar_container_->SetMaxTopArrowHeight(GetMaxTopInfoBarArrowHeight());
}
SkColor BrowserView::GetInfoBarSeparatorColor() const {
return (IsTabStripVisible() || !frame_->ShouldUseNativeFrame()) ?
ThemeProperties::GetDefaultColor(
ThemeProperties::COLOR_TOOLBAR_SEPARATOR) :
SK_ColorBLACK;
}
void BrowserView::InfoBarContainerStateChanged(bool is_animating) {
ToolbarSizeChanged(is_animating);
}
bool BrowserView::DrawInfoBarArrows(int* x) const {
if (x) {
gfx::Point anchor(toolbar_->location_bar()->GetLocationBarAnchorPoint());
ConvertPointToTarget(toolbar_->location_bar(), this, &anchor);
*x = anchor.x();
}
return true;
}
void BrowserView::OnSysColorChange() {
chrome::MaybeShowInvertBubbleView(this);
}
void BrowserView::InitViews() {
GetWidget()->AddObserver(this);
GetWidget()->SetNativeWindowProperty(kBrowserViewKey, this);
GetWidget()->SetNativeWindowProperty(Profile::kProfileKey,
browser_->profile());
if (!CommandLine::ForCurrentProcess()->HasSwitch(
switches::kDisableHangMonitor)) {
InitHangMonitor();
}
LoadAccelerators();
infobar_container_ = new InfoBarContainerView(this);
AddChildView(infobar_container_);
contents_web_view_ = new ContentsWebView(browser_->profile());
contents_web_view_->set_id(VIEW_ID_TAB_CONTAINER);
contents_web_view_->SetEmbedFullscreenWidgetMode(
implicit_cast<content::WebContentsDelegate*>(browser_.get())->
EmbedsFullscreenWidget());
devtools_web_view_ = new views::WebView(browser_->profile());
devtools_web_view_->set_id(VIEW_ID_DEV_TOOLS_DOCKED);
devtools_web_view_->SetVisible(false);
contents_container_ = new views::View();
contents_container_->set_background(views::Background::CreateSolidBackground(
ThemeProperties::GetDefaultColor(
ThemeProperties::COLOR_CONTROL_BACKGROUND)));
contents_container_->AddChildView(devtools_web_view_);
contents_container_->AddChildView(contents_web_view_);
contents_container_->SetLayoutManager(new ContentsLayoutManager(
devtools_web_view_, contents_web_view_));
AddChildView(contents_container_);
set_contents_view(contents_container_);
top_container_ = new TopContainerView(this);
AddChildView(top_container_);
BrowserTabStripController* tabstrip_controller =
new BrowserTabStripController(browser_.get(),
browser_->tab_strip_model());
tabstrip_ = new TabStrip(tabstrip_controller);
top_container_->AddChildView(tabstrip_);
tabstrip_controller->InitFromModel(tabstrip_);
toolbar_ = new ToolbarView(browser_.get());
top_container_->AddChildView(toolbar_);
toolbar_->Init();
InitStatusBubble();
InitPermissionBubbleView();
find_bar_host_view_ = new View();
AddChildView(find_bar_host_view_);
if (window_switcher_button_)
AddChildView(window_switcher_button_);
immersive_mode_controller_->Init(this);
BrowserViewLayout* browser_view_layout = new BrowserViewLayout;
browser_view_layout->Init(new BrowserViewLayoutDelegateImpl(this),
browser(),
this,
top_container_,
tabstrip_,
toolbar_,
infobar_container_,
contents_container_,
GetContentsLayoutManager(),
immersive_mode_controller_.get());
SetLayoutManager(browser_view_layout);
#if defined(OS_WIN)
if (JumpList::Enabled()) {
load_complete_listener_.reset(new LoadCompleteListener(this));
}
#endif
GetLocationBar()->GetOmniboxView()->model()->popup_model()->AddObserver(this);
}
void BrowserView::LoadingAnimationCallback() {
base::TimeTicks now = base::TimeTicks::Now();
if (!last_animation_time_.is_null()) {
UMA_HISTOGRAM_TIMES(
"Tabs.LoadingAnimationTime",
now - last_animation_time_);
}
last_animation_time_ = now;
if (browser_->is_type_tabbed()) {
tabstrip_->UpdateLoadingAnimations();
} else if (ShouldShowWindowIcon()) {
WebContents* web_contents =
browser_->tab_strip_model()->GetActiveWebContents();
frame_->UpdateThrobber(web_contents && web_contents->IsLoading());
}
}
void BrowserView::OnLoadCompleted() {
#if defined(OS_WIN)
DCHECK(!jumplist_);
jumplist_ = new JumpList();
jumplist_->AddObserver(browser_->profile());
#endif
}
BrowserViewLayout* BrowserView::GetBrowserViewLayout() const {
return static_cast<BrowserViewLayout*>(GetLayoutManager());
}
ContentsLayoutManager* BrowserView::GetContentsLayoutManager() const {
return static_cast<ContentsLayoutManager*>(
contents_container_->GetLayoutManager());
}
bool BrowserView::MaybeShowBookmarkBar(WebContents* contents) {
bool show_bookmark_bar = contents &&
browser_->SupportsWindowFeature(Browser::FEATURE_BOOKMARKBAR);
if (!show_bookmark_bar && !bookmark_bar_view_.get())
return false;
if (!bookmark_bar_view_.get()) {
bookmark_bar_view_.reset(new BookmarkBarView(browser_.get(), this));
bookmark_bar_view_->set_owned_by_client();
bookmark_bar_view_->set_background(
new BookmarkExtensionBackground(this,
bookmark_bar_view_.get(),
browser_.get()));
bookmark_bar_view_->SetBookmarkBarState(
browser_->bookmark_bar_state(),
BookmarkBar::DONT_ANIMATE_STATE_CHANGE);
GetBrowserViewLayout()->set_bookmark_bar(bookmark_bar_view_.get());
}
bookmark_bar_view_->SetVisible(show_bookmark_bar);
bookmark_bar_view_->SetPageNavigator(contents);
bool needs_layout = false;
views::View* new_parent = NULL;
if (show_bookmark_bar) {
if (bookmark_bar_view_->IsDetached())
new_parent = this;
else
new_parent = top_container_;
}
if (new_parent != bookmark_bar_view_->parent()) {
SetBookmarkBarParent(new_parent);
needs_layout = true;
}
if (bookmark_bar_view_->GetPreferredSize().height() !=
bookmark_bar_view_->height())
needs_layout = true;
return needs_layout;
}
void BrowserView::SetBookmarkBarParent(views::View* new_parent) {
if (new_parent == this) {
int top_container_index = GetIndexOf(top_container_);
if (top_container_index >= 0)
AddChildViewAt(bookmark_bar_view_.get(), top_container_index);
else
AddChildView(bookmark_bar_view_.get());
} else if (new_parent) {
new_parent->AddChildView(bookmark_bar_view_.get());
} else {
bookmark_bar_view_->parent()->RemoveChildView(bookmark_bar_view_.get());
}
}
bool BrowserView::MaybeShowInfoBar(WebContents* contents) {
return true;
}
void BrowserView::UpdateDevToolsForContents(
WebContents* web_contents, bool update_devtools_web_contents) {
DevToolsWindow* new_devtools_window = web_contents ?
DevToolsWindow::GetDockedInstanceForInspectedTab(web_contents) : NULL;
WebContents* new_contents = new_devtools_window ?
new_devtools_window->web_contents() : NULL;
if (devtools_web_view_->web_contents() != new_contents &&
update_devtools_web_contents) {
devtools_web_view_->SetWebContents(new_contents);
}
if (!devtools_window_ && new_devtools_window &&
!devtools_focus_tracker_.get()) {
devtools_focus_tracker_.reset(
new views::ExternalFocusTracker(devtools_web_view_,
GetFocusManager()));
}
if (devtools_window_ && !new_devtools_window &&
devtools_focus_tracker_.get()) {
devtools_focus_tracker_->FocusLastFocusedExternalView();
devtools_focus_tracker_.reset();
}
devtools_window_ = new_devtools_window;
if (devtools_window_) {
devtools_web_view_->SetPreferredSize(devtools_window_->GetMinimumSize());
devtools_web_view_->SetVisible(true);
GetContentsLayoutManager()->SetContentsResizingStrategy(
devtools_window_->GetContentsResizingStrategy());
} else {
devtools_web_view_->SetVisible(false);
GetContentsLayoutManager()->SetContentsResizingStrategy(
DevToolsContentsResizingStrategy());
}
contents_container_->Layout();
}
void BrowserView::UpdateUIForContents(WebContents* contents) {
bool needs_layout = MaybeShowBookmarkBar(contents);
needs_layout |= MaybeShowInfoBar(contents);
if (needs_layout)
Layout();
}
void BrowserView::ProcessFullscreen(bool fullscreen,
FullscreenType type,
const GURL& url,
FullscreenExitBubbleType bubble_type) {
if (in_process_fullscreen_)
return;
in_process_fullscreen_ = true;
LocationBarView* location_bar = GetLocationBarView();
if (type == FOR_METRO || !fullscreen) {
fullscreen_bubble_.reset();
}
if (fullscreen) {
views::FocusManager* focus_manager = GetFocusManager();
DCHECK(focus_manager);
if (location_bar->Contains(focus_manager->GetFocusedView()))
focus_manager->ClearFocus();
}
frame_->SetFullscreen(fullscreen);
if (ShouldUseImmersiveFullscreenForUrl(url))
immersive_mode_controller_->SetEnabled(fullscreen);
browser_->WindowFullscreenStateChanged();
if (fullscreen && !chrome::IsRunningInAppMode() && type != FOR_METRO)
UpdateFullscreenExitBubbleContent(url, bubble_type);
in_process_fullscreen_ = false;
ToolbarSizeChanged(false);
}
bool BrowserView::ShouldUseImmersiveFullscreenForUrl(const GURL& url) const {
#if defined(OS_CHROMEOS)
if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode))
return false;
bool is_browser_fullscreen = url.is_empty();
return is_browser_fullscreen;
#else
return false;
#endif
}
void BrowserView::LoadAccelerators() {
views::FocusManager* focus_manager = GetFocusManager();
DCHECK(focus_manager);
const bool is_app_mode = chrome::IsRunningInForcedAppMode();
const std::vector<chrome::AcceleratorMapping> accelerator_list(
chrome::GetAcceleratorList());
for (std::vector<chrome::AcceleratorMapping>::const_iterator it =
accelerator_list.begin(); it != accelerator_list.end(); ++it) {
if (is_app_mode && !chrome::IsCommandAllowedInAppMode(it->command_id))
continue;
ui::Accelerator accelerator(it->keycode, it->modifiers);
accelerator_table_[accelerator] = it->command_id;
focus_manager->RegisterAccelerator(
accelerator, ui::AcceleratorManager::kNormalPriority, this);
}
}
int BrowserView::GetCommandIDForAppCommandID(int app_command_id) const {
#if defined(OS_WIN)
switch (app_command_id) {
case APPCOMMAND_BROWSER_BACKWARD: return IDC_BACK;
case APPCOMMAND_BROWSER_FORWARD: return IDC_FORWARD;
case APPCOMMAND_BROWSER_REFRESH: return IDC_RELOAD;
case APPCOMMAND_BROWSER_HOME: return IDC_HOME;
case APPCOMMAND_BROWSER_STOP: return IDC_STOP;
case APPCOMMAND_BROWSER_SEARCH: return IDC_FOCUS_SEARCH;
case APPCOMMAND_HELP: return IDC_HELP_PAGE_VIA_KEYBOARD;
case APPCOMMAND_NEW: return IDC_NEW_TAB;
case APPCOMMAND_OPEN: return IDC_OPEN_FILE;
case APPCOMMAND_CLOSE: return IDC_CLOSE_TAB;
case APPCOMMAND_SAVE: return IDC_SAVE_PAGE;
case APPCOMMAND_PRINT: return IDC_PRINT;
case APPCOMMAND_COPY: return IDC_COPY;
case APPCOMMAND_CUT: return IDC_CUT;
case APPCOMMAND_PASTE: return IDC_PASTE;
case APPCOMMAND_UNDO:
case APPCOMMAND_REDO:
case APPCOMMAND_SPELL_CHECK:
default: return -1;
}
#else
return -1;
#endif
}
void BrowserView::InitHangMonitor() {
#if defined(OS_WIN)
PrefService* pref_service = g_browser_process->local_state();
if (!pref_service)
return;
int plugin_message_response_timeout =
pref_service->GetInteger(prefs::kPluginMessageResponseTimeout);
int hung_plugin_detect_freq =
pref_service->GetInteger(prefs::kHungPluginDetectFrequency);
#if defined(USE_AURA)
HWND window = GetWidget()->GetNativeView()->GetHost()->
GetAcceleratedWidget();
#else
HWND window = GetWidget()->GetNativeView();
#endif
if ((hung_plugin_detect_freq > 0) &&
hung_window_detector_.Initialize(window,
plugin_message_response_timeout)) {
ticker_.set_tick_interval(hung_plugin_detect_freq);
ticker_.RegisterTickHandler(&hung_window_detector_);
ticker_.Start();
pref_service->SetInteger(prefs::kPluginMessageResponseTimeout,
plugin_message_response_timeout);
pref_service->SetInteger(prefs::kHungPluginDetectFrequency,
hung_plugin_detect_freq);
}
#endif
}
void BrowserView::UpdateAcceleratorMetrics(const ui::Accelerator& accelerator,
int command_id) {
const ui::KeyboardCode key_code = accelerator.key_code();
if (command_id == IDC_HELP_PAGE_VIA_KEYBOARD && key_code == ui::VKEY_F1)
content::RecordAction(UserMetricsAction("ShowHelpTabViaF1"));
if (command_id == IDC_BOOKMARK_PAGE)
UMA_HISTOGRAM_ENUMERATION("Bookmarks.EntryPoint",
BOOKMARK_ENTRY_POINT_ACCELERATOR,
BOOKMARK_ENTRY_POINT_LIMIT);
#if defined(OS_CHROMEOS)
switch (command_id) {
case IDC_BACK:
if (key_code == ui::VKEY_BACK)
content::RecordAction(UserMetricsAction("Accel_Back_Backspace"));
else if (key_code == ui::VKEY_BROWSER_BACK)
content::RecordAction(UserMetricsAction("Accel_Back_F1"));
else if (key_code == ui::VKEY_LEFT)
content::RecordAction(UserMetricsAction("Accel_Back_Left"));
break;
case IDC_FORWARD:
if (key_code == ui::VKEY_BACK)
content::RecordAction(UserMetricsAction("Accel_Forward_Backspace"));
else if (key_code == ui::VKEY_BROWSER_FORWARD)
content::RecordAction(UserMetricsAction("Accel_Forward_F2"));
else if (key_code == ui::VKEY_RIGHT)
content::RecordAction(UserMetricsAction("Accel_Forward_Right"));
break;
case IDC_RELOAD:
case IDC_RELOAD_IGNORING_CACHE:
if (key_code == ui::VKEY_R)
content::RecordAction(UserMetricsAction("Accel_Reload_R"));
else if (key_code == ui::VKEY_BROWSER_REFRESH)
content::RecordAction(UserMetricsAction("Accel_Reload_F3"));
break;
case IDC_FOCUS_LOCATION:
if (key_code == ui::VKEY_D)
content::RecordAction(UserMetricsAction("Accel_FocusLocation_D"));
else if (key_code == ui::VKEY_L)
content::RecordAction(UserMetricsAction("Accel_FocusLocation_L"));
break;
case IDC_FOCUS_SEARCH:
if (key_code == ui::VKEY_E)
content::RecordAction(UserMetricsAction("Accel_FocusSearch_E"));
else if (key_code == ui::VKEY_K)
content::RecordAction(UserMetricsAction("Accel_FocusSearch_K"));
break;
default:
break;
}
#endif
}
BrowserWindow* BrowserWindow::CreateBrowserWindow(Browser* browser) {
BrowserView* view = new BrowserView();
view->Init(browser);
(new BrowserFrame(view))->InitBrowserFrame();
view->GetWidget()->non_client_view()->SetAccessibleName(
l10n_util::GetStringUTF16(IDS_PRODUCT_NAME));
return view;
}
chrome::HostDesktopType BrowserWindow::AdjustHostDesktopType(
chrome::HostDesktopType desktop_type) {
return NativeBrowserFrameFactory::AdjustHostDesktopType(desktop_type);
}
void BrowserView::ShowAvatarBubble(WebContents* web_contents,
const gfx::Rect& rect) {
gfx::Point origin(rect.origin());
views::View::ConvertPointToScreen(GetTabContentsContainerView(), &origin);
gfx::Rect bounds(origin, rect.size());
AvatarMenuBubbleView::ShowBubble(this, views::BubbleBorder::TOP_RIGHT,
views::BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE, bounds, browser_.get());
}
void BrowserView::ShowAvatarBubbleFromAvatarButton(AvatarBubbleMode mode) {
if (switches::IsNewProfileManagement()) {
NewAvatarButton* button = frame_->GetNewAvatarMenuButton();
if (button) {
gfx::Point origin;
views::View::ConvertPointToScreen(button, &origin);
gfx::Rect bounds(origin, size());
ProfileChooserView::BubbleViewMode view_mode =
mode == BrowserWindow::AVATAR_BUBBLE_MODE_DEFAULT ?
ProfileChooserView::BUBBLE_VIEW_MODE_PROFILE_CHOOSER :
ProfileChooserView::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT;
ProfileChooserView::ShowBubble(
view_mode, button, views::BubbleBorder::TOP_RIGHT,
views::BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE, bounds, browser());
}
} else {
AvatarMenuButton* button = frame_->GetAvatarMenuButton();
if (button)
button->ShowAvatarBubble();
}
}
void BrowserView::ShowPasswordGenerationBubble(
const gfx::Rect& rect,
const autofill::PasswordForm& form,
autofill::PasswordGenerator* password_generator) {
gfx::Point origin(rect.origin());
views::View::ConvertPointToScreen(GetTabContentsContainerView(), &origin);
gfx::Rect bounds(origin, rect.size());
WebContents* web_contents = GetActiveWebContents();
if (!web_contents)
return;
PasswordGenerationBubbleView* bubble = new PasswordGenerationBubbleView(
form,
bounds,
this,
web_contents->GetRenderViewHost(),
ChromePasswordManagerClient::GetManagerFromWebContents(web_contents),
password_generator,
browser_.get(),
GetWidget()->GetThemeProvider());
views::BubbleDelegateView::CreateBubble(bubble);
bubble->SetAlignment(views::BubbleBorder::ALIGN_ARROW_TO_MID_ANCHOR);
bubble->GetWidget()->Show();
}
void BrowserView::OverscrollUpdate(int delta_y) {
if (scroll_end_effect_controller_)
scroll_end_effect_controller_->OverscrollUpdate(delta_y);
}
int BrowserView::GetRenderViewHeightInsetWithDetachedBookmarkBar() {
if (browser_->bookmark_bar_state() != BookmarkBar::DETACHED ||
!bookmark_bar_view_.get() || !bookmark_bar_view_->IsDetached()) {
return 0;
}
return chrome::kNTPBookmarkBarHeight -
bookmark_bar_view_->GetFullyDetachedToolbarOverlap();
}
void BrowserView::ExecuteExtensionCommand(
const extensions::Extension* extension,
const extensions::Command& command) {
toolbar_->ExecuteExtensionCommand(extension, command);
}
void BrowserView::ShowPageActionPopup(
const extensions::Extension* extension) {
toolbar_->ShowPageActionPopup(extension);
}
void BrowserView::ShowBrowserActionPopup(
const extensions::Extension* extension) {
toolbar_->ShowBrowserActionPopup(extension);
}
void BrowserView::DoCutCopyPaste(void (content::RenderFrameHost::*method)(),
int command_id) {
WebContents* contents = browser_->tab_strip_model()->GetActiveWebContents();
if (!contents)
return;
if (DoCutCopyPasteForWebContents(contents, method))
return;
DevToolsWindow* devtools_window =
DevToolsWindow::GetDockedInstanceForInspectedTab(contents);
if (devtools_window &&
DoCutCopyPasteForWebContents(devtools_window->web_contents(), method)) {
return;
}
views::FocusManager* focus_manager = GetFocusManager();
views::View* focused = focus_manager->GetFocusedView();
if (focused &&
(!strcmp(focused->GetClassName(), views::Textfield::kViewClassName) ||
!strcmp(focused->GetClassName(), OmniboxViewViews::kViewClassName))) {
views::Textfield* textfield = static_cast<views::Textfield*>(focused);
textfield->ExecuteCommand(command_id);
}
}
bool BrowserView::DoCutCopyPasteForWebContents(
WebContents* contents,
void (content::RenderFrameHost::*method)()) {
gfx::NativeView native_view = contents->GetView()->GetContentNativeView();
if (!native_view)
return false;
#if defined(USE_AURA)
if (native_view->HasFocus()) {
#elif defined(OS_WIN)
if (native_view == ::GetFocus()) {
#endif
content::RenderFrameHost* frame = contents->GetFocusedFrame();
if (frame)
(frame->*method)();
return true;
}
return false;
}
void BrowserView::ActivateAppModalDialog() const {
AppModalDialog* active_dialog =
AppModalDialogQueue::GetInstance()->active_dialog();
if (!active_dialog)
return;
Browser* modal_browser =
chrome::FindBrowserWithWebContents(active_dialog->web_contents());
if (modal_browser && (browser_ != modal_browser)) {
modal_browser->window()->FlashFrame(true);
modal_browser->window()->Activate();
}
AppModalDialogQueue::GetInstance()->ActivateModalDialog();
}
int BrowserView::GetMaxTopInfoBarArrowHeight() {
int top_arrow_height = 0;
if (!IsFullscreen() &&
!GetLocationBar()->GetOmniboxView()->model()->popup_model()->IsOpen()) {
gfx::Point icon_bottom(
toolbar_->location_bar()->GetLocationBarAnchorPoint());
ConvertPointToTarget(toolbar_->location_bar(), this, &icon_bottom);
gfx::Point infobar_top(0, infobar_container_->GetVerticalOverlap(NULL));
ConvertPointToTarget(infobar_container_, this, &infobar_top);
top_arrow_height = infobar_top.y() - icon_bottom.y();
}
return top_arrow_height;
}