glass_browser_frame_view.cc revision f2477e01787aa58f445919b809d89e252beef54f
1// Copyright (c) 2012 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "chrome/browser/ui/views/frame/glass_browser_frame_view.h"
6
7#include "base/command_line.h"
8#include "base/prefs/pref_service.h"
9#include "base/strings/utf_string_conversions.h"
10#include "chrome/app/chrome_command_ids.h"
11#include "chrome/app/chrome_dll_resource.h"
12#include "chrome/browser/chrome_notification_types.h"
13#include "chrome/browser/profiles/profile.h"
14#include "chrome/browser/profiles/profiles_state.h"
15#include "chrome/browser/themes/theme_properties.h"
16#include "chrome/browser/ui/views/avatar_menu_button.h"
17#include "chrome/browser/ui/views/frame/browser_view.h"
18#include "chrome/browser/ui/views/new_avatar_button.h"
19#include "chrome/browser/ui/views/tabs/tab.h"
20#include "chrome/browser/ui/views/tabs/tab_strip.h"
21#include "chrome/browser/ui/views/toolbar/toolbar_view.h"
22#include "chrome/common/chrome_switches.h"
23#include "chrome/common/pref_names.h"
24#include "content/public/browser/notification_service.h"
25#include "grit/generated_resources.h"
26#include "grit/theme_resources.h"
27#include "grit/ui_resources.h"
28#include "ui/base/l10n/l10n_util.h"
29#include "ui/base/resource/resource_bundle_win.h"
30#include "ui/base/theme_provider.h"
31#include "ui/gfx/canvas.h"
32#include "ui/gfx/icon_util.h"
33#include "ui/gfx/image/image.h"
34#include "ui/gfx/win/dpi.h"
35#include "ui/views/controls/label.h"
36#include "ui/views/layout/layout_constants.h"
37#include "ui/views/win/hwnd_util.h"
38#include "ui/views/window/client_view.h"
39
40HICON GlassBrowserFrameView::throbber_icons_[
41    GlassBrowserFrameView::kThrobberIconCount];
42
43namespace {
44// There are 3 px of client edge drawn inside the outer frame borders.
45const int kNonClientBorderThickness = 3;
46// Besides the frame border, there's another 9 px of empty space atop the
47// window in restored mode, to use to drag the window around.
48const int kNonClientRestoredExtraThickness = 9;
49// In the window corners, the resize areas don't actually expand bigger, but the
50// 16 px at the end of the top and bottom edges triggers diagonal resizing.
51const int kResizeAreaCornerSize = 16;
52// The avatar ends 2 px above the bottom of the tabstrip (which, given the
53// way the tabstrip draws its bottom edge, will appear like a 1 px gap to the
54// user).
55const int kAvatarBottomSpacing = 2;
56// Space between the frame border and the left edge of the avatar.
57const int kAvatarLeftSpacing = 2;
58// Space between the right edge of the avatar and the tabstrip.
59const int kAvatarRightSpacing = -2;
60// How far the new avatar button is from the left of the minimize button.
61const int kNewAvatarButtonOffset = 5;
62// The content left/right images have a shadow built into them.
63const int kContentEdgeShadowThickness = 2;
64// The top 3 px of the tabstrip is shadow; in maximized mode we push this off
65// the top of the screen so the tabs appear flush against the screen edge.
66const int kTabstripTopShadowThickness = 3;
67// In restored mode, the New Tab button isn't at the same height as the caption
68// buttons, but the space will look cluttered if it actually slides under them,
69// so we stop it when the gap between the two is down to 5 px.
70const int kNewTabCaptionRestoredSpacing = 5;
71// In maximized mode, where the New Tab button and the caption buttons are at
72// similar vertical coordinates, we need to reserve a larger, 16 px gap to avoid
73// looking too cluttered.
74const int kNewTabCaptionMaximizedSpacing = 16;
75// How far to indent the tabstrip from the left side of the screen when there
76// is no avatar icon.
77const int kTabStripIndent = -6;
78
79}  // namespace
80
81///////////////////////////////////////////////////////////////////////////////
82// GlassBrowserFrameView, public:
83
84GlassBrowserFrameView::GlassBrowserFrameView(BrowserFrame* frame,
85                                             BrowserView* browser_view)
86    : BrowserNonClientFrameView(frame, browser_view),
87      throbber_running_(false),
88      throbber_frame_(0) {
89  if (browser_view->ShouldShowWindowIcon())
90    InitThrobberIcons();
91
92  if (browser_view->IsRegularOrGuestSession() &&
93      profiles::IsNewProfileManagementEnabled())
94    UpdateNewStyleAvatarInfo(this, NewAvatarButton::NATIVE_BUTTON);
95  else
96    UpdateAvatarInfo();
97
98  if (!browser_view->IsOffTheRecord()) {
99    registrar_.Add(this, chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED,
100                   content::NotificationService::AllSources());
101  }
102}
103
104GlassBrowserFrameView::~GlassBrowserFrameView() {
105}
106
107///////////////////////////////////////////////////////////////////////////////
108// GlassBrowserFrameView, BrowserNonClientFrameView implementation:
109
110gfx::Rect GlassBrowserFrameView::GetBoundsForTabStrip(
111    views::View* tabstrip) const {
112  int minimize_button_offset =
113      std::min(frame()->GetMinimizeButtonOffset(), width());
114
115  // The new avatar button is optionally displayed to the left of the
116  // minimize button.
117  if (new_avatar_button()) {
118    DCHECK(profiles::IsNewProfileManagementEnabled());
119    minimize_button_offset -= new_avatar_button()->width();
120  }
121
122  int tabstrip_x = browser_view()->ShouldShowAvatar() ?
123      (avatar_bounds_.right() + kAvatarRightSpacing) :
124      NonClientBorderThickness() + kTabStripIndent;
125  // In RTL languages, we have moved an avatar icon left by the size of window
126  // controls to prevent it from being rendered over them. So, we use its x
127  // position to move this tab strip left when maximized. Also, we can render
128  // a tab strip until the left end of this window without considering the size
129  // of window controls in RTL languages.
130  if (base::i18n::IsRTL()) {
131    if (!browser_view()->ShouldShowAvatar() && frame()->IsMaximized())
132      tabstrip_x += avatar_bounds_.x();
133    else if (browser_view()->IsRegularOrGuestSession() &&
134        profiles::IsNewProfileManagementEnabled())
135      tabstrip_x = width() - minimize_button_offset;
136
137    minimize_button_offset = width();
138  }
139  int tabstrip_width = minimize_button_offset - tabstrip_x -
140      (frame()->IsMaximized() ?
141          kNewTabCaptionMaximizedSpacing : kNewTabCaptionRestoredSpacing);
142  return gfx::Rect(tabstrip_x, NonClientTopBorderHeight(),
143                   std::max(0, tabstrip_width),
144                   tabstrip->GetPreferredSize().height());
145}
146
147int GlassBrowserFrameView::GetTopInset() const {
148  return GetClientAreaInsets().top();
149}
150
151int GlassBrowserFrameView::GetThemeBackgroundXInset() const {
152  return 0;
153}
154
155void GlassBrowserFrameView::UpdateThrobber(bool running) {
156  if (throbber_running_) {
157    if (running) {
158      DisplayNextThrobberFrame();
159    } else {
160      StopThrobber();
161    }
162  } else if (running) {
163    StartThrobber();
164  }
165}
166
167gfx::Size GlassBrowserFrameView::GetMinimumSize() {
168  gfx::Size min_size(browser_view()->GetMinimumSize());
169
170  // Account for the client area insets.
171  gfx::Insets insets = GetClientAreaInsets();
172  min_size.Enlarge(insets.width(), insets.height());
173  // Client area insets do not include the shadow thickness.
174  min_size.Enlarge(2 * kContentEdgeShadowThickness, 0);
175
176  // Ensure that the minimum width is enough to hold a tab strip with minimum
177  // width at its usual insets.
178  if (browser_view()->IsTabStripVisible()) {
179    TabStrip* tabstrip = browser_view()->tabstrip();
180    int min_tabstrip_width = tabstrip->GetMinimumSize().width();
181    int min_tabstrip_area_width =
182        width() - GetBoundsForTabStrip(tabstrip).width() + min_tabstrip_width;
183    min_size.set_width(std::max(min_tabstrip_area_width, min_size.width()));
184  }
185
186  return min_size;
187}
188
189///////////////////////////////////////////////////////////////////////////////
190// GlassBrowserFrameView, views::NonClientFrameView implementation:
191
192gfx::Rect GlassBrowserFrameView::GetBoundsForClientView() const {
193  return client_view_bounds_;
194}
195
196gfx::Rect GlassBrowserFrameView::GetWindowBoundsForClientBounds(
197    const gfx::Rect& client_bounds) const {
198  HWND hwnd = views::HWNDForWidget(frame());
199  if (!browser_view()->IsTabStripVisible() && hwnd) {
200    // If we don't have a tabstrip, we're either a popup or an app window, in
201    // which case we have a standard size non-client area and can just use
202    // AdjustWindowRectEx to obtain it. We check for a non-NULL window handle in
203    // case this gets called before the window is actually created.
204    RECT rect = client_bounds.ToRECT();
205    AdjustWindowRectEx(&rect, GetWindowLong(hwnd, GWL_STYLE), FALSE,
206                       GetWindowLong(hwnd, GWL_EXSTYLE));
207    return gfx::Rect(rect);
208  }
209
210  gfx::Insets insets = GetClientAreaInsets();
211  return gfx::Rect(std::max(0, client_bounds.x() - insets.left()),
212                   std::max(0, client_bounds.y() - insets.top()),
213                   client_bounds.width() + insets.width(),
214                   client_bounds.height() + insets.height());
215}
216
217int GlassBrowserFrameView::NonClientHitTest(const gfx::Point& point) {
218  // If the browser isn't in normal mode, we haven't customized the frame, so
219  // Windows can figure this out.  If the point isn't within our bounds, then
220  // it's in the native portion of the frame, so again Windows can figure it
221  // out.
222  if (!browser_view()->IsBrowserTypeNormal() || !bounds().Contains(point))
223    return HTNOWHERE;
224
225  // See if the point is within the avatar menu button or within the avatar
226  // label.
227  if (avatar_button() && avatar_button()->GetMirroredBounds().Contains(point))
228    return HTCLIENT;
229
230  if (new_avatar_button() &&
231     new_avatar_button()->GetMirroredBounds().Contains(point))
232   return HTCLIENT;
233
234  int frame_component = frame()->client_view()->NonClientHitTest(point);
235
236  // See if we're in the sysmenu region.  We still have to check the tabstrip
237  // first so that clicks in a tab don't get treated as sysmenu clicks.
238  int nonclient_border_thickness = NonClientBorderThickness();
239  if (gfx::Rect(nonclient_border_thickness, GetSystemMetrics(SM_CXSIZEFRAME),
240                GetSystemMetrics(SM_CXSMICON),
241                GetSystemMetrics(SM_CYSMICON)).Contains(point))
242    return (frame_component == HTCLIENT) ? HTCLIENT : HTSYSMENU;
243
244  if (frame_component != HTNOWHERE)
245    return frame_component;
246
247  int frame_border_thickness = FrameBorderThickness();
248  int window_component = GetHTComponentForFrame(point, frame_border_thickness,
249      nonclient_border_thickness, frame_border_thickness,
250      kResizeAreaCornerSize - frame_border_thickness,
251      frame()->widget_delegate()->CanResize());
252  // Fall back to the caption if no other component matches.
253  return (window_component == HTNOWHERE) ? HTCAPTION : window_component;
254}
255
256///////////////////////////////////////////////////////////////////////////////
257// GlassBrowserFrameView, views::View overrides:
258
259void GlassBrowserFrameView::OnPaint(gfx::Canvas* canvas) {
260  if (browser_view()->IsToolbarVisible() &&
261      browser_view()->toolbar()->ShouldPaintBackground())
262    PaintToolbarBackground(canvas);
263  if (!frame()->IsMaximized())
264    PaintRestoredClientEdge(canvas);
265}
266
267void GlassBrowserFrameView::Layout() {
268  if (browser_view()->IsRegularOrGuestSession() &&
269      profiles::IsNewProfileManagementEnabled())
270    LayoutNewStyleAvatar();
271  else
272    LayoutAvatar();
273
274  LayoutClientView();
275}
276
277bool GlassBrowserFrameView::HitTestRect(const gfx::Rect& rect) const {
278  bool hit_avatar_button = avatar_button() &&
279      avatar_button()->GetMirroredBounds().Intersects(rect);
280  bool hit_new_avatar_button = new_avatar_button() &&
281      new_avatar_button()->GetMirroredBounds().Intersects(rect);
282  return hit_avatar_button || hit_new_avatar_button ||
283         !frame()->client_view()->bounds().Intersects(rect);
284}
285
286///////////////////////////////////////////////////////////////////////////////
287// GlassBrowserFrameView, views::ButtonListener overrides:
288void GlassBrowserFrameView::ButtonPressed(views::Button* sender,
289                                          const ui::Event& event) {
290  if (sender == new_avatar_button())
291    browser_view()->ShowAvatarBubbleFromAvatarButton();
292}
293
294///////////////////////////////////////////////////////////////////////////////
295// GlassBrowserFrameView, private:
296
297int GlassBrowserFrameView::FrameBorderThickness() const {
298  return (frame()->IsMaximized() || frame()->IsFullscreen()) ?
299      0 : GetSystemMetrics(SM_CXSIZEFRAME);
300}
301
302int GlassBrowserFrameView::NonClientBorderThickness() const {
303  if (frame()->IsMaximized() || frame()->IsFullscreen())
304    return 0;
305
306  return kNonClientBorderThickness;
307}
308
309int GlassBrowserFrameView::NonClientTopBorderHeight() const {
310  if (frame()->IsFullscreen())
311    return 0;
312
313  // We'd like to use FrameBorderThickness() here, but the maximized Aero glass
314  // frame has a 0 frame border around most edges and a CYSIZEFRAME-thick border
315  // at the top (see AeroGlassFrame::OnGetMinMaxInfo()).
316  return gfx::win::GetSystemMetricsInDIP(SM_CYSIZEFRAME) +
317      (!frame()->ShouldLeaveOffsetNearTopBorder() ?
318      -kTabstripTopShadowThickness : kNonClientRestoredExtraThickness);
319}
320
321void GlassBrowserFrameView::PaintToolbarBackground(gfx::Canvas* canvas) {
322  ui::ThemeProvider* tp = GetThemeProvider();
323
324  gfx::Rect toolbar_bounds(browser_view()->GetToolbarBounds());
325  gfx::Point toolbar_origin(toolbar_bounds.origin());
326  View::ConvertPointToTarget(browser_view(), this, &toolbar_origin);
327  toolbar_bounds.set_origin(toolbar_origin);
328  int x = toolbar_bounds.x();
329  int w = toolbar_bounds.width();
330  int left_x = x - kContentEdgeShadowThickness;
331
332  gfx::ImageSkia* theme_toolbar = tp->GetImageSkiaNamed(IDR_THEME_TOOLBAR);
333  gfx::ImageSkia* toolbar_left = tp->GetImageSkiaNamed(
334      IDR_CONTENT_TOP_LEFT_CORNER);
335  gfx::ImageSkia* toolbar_center = tp->GetImageSkiaNamed(
336      IDR_CONTENT_TOP_CENTER);
337
338  // Tile the toolbar image starting at the frame edge on the left and where
339  // the tabstrip is on the top.
340  int y = toolbar_bounds.y();
341  int dest_y = browser_view()->IsTabStripVisible()
342                   ? y + (kFrameShadowThickness * 2)
343                   : y;
344  canvas->TileImageInt(*theme_toolbar,
345                       x + GetThemeBackgroundXInset(),
346                       dest_y - GetTopInset(), x,
347                       dest_y, w, theme_toolbar->height());
348
349  if (browser_view()->IsTabStripVisible()) {
350    // Draw rounded corners for the tab.
351    gfx::ImageSkia* toolbar_left_mask =
352        tp->GetImageSkiaNamed(IDR_CONTENT_TOP_LEFT_CORNER_MASK);
353    gfx::ImageSkia* toolbar_right_mask =
354        tp->GetImageSkiaNamed(IDR_CONTENT_TOP_RIGHT_CORNER_MASK);
355
356    // We mask out the corners by using the DestinationIn transfer mode,
357    // which keeps the RGB pixels from the destination and the alpha from
358    // the source.
359    SkPaint paint;
360    paint.setXfermodeMode(SkXfermode::kDstIn_Mode);
361
362    // Mask out the top left corner.
363    canvas->DrawImageInt(*toolbar_left_mask, left_x, y, paint);
364
365    // Mask out the top right corner.
366    int right_x =
367        x + w + kContentEdgeShadowThickness - toolbar_right_mask->width();
368    canvas->DrawImageInt(*toolbar_right_mask, right_x, y, paint);
369
370    // Draw left edge.
371    canvas->DrawImageInt(*toolbar_left, left_x, y);
372
373    // Draw center edge.
374    canvas->TileImageInt(*toolbar_center, left_x + toolbar_left->width(), y,
375        right_x - (left_x + toolbar_left->width()), toolbar_center->height());
376
377    // Right edge.
378    canvas->DrawImageInt(*tp->GetImageSkiaNamed(IDR_CONTENT_TOP_RIGHT_CORNER),
379                         right_x, y);
380  }
381
382  // Draw the content/toolbar separator.
383  canvas->FillRect(
384      gfx::Rect(x + kClientEdgeThickness,
385                toolbar_bounds.bottom() - kClientEdgeThickness,
386                w - (2 * kClientEdgeThickness),
387                kClientEdgeThickness),
388      ThemeProperties::GetDefaultColor(
389          ThemeProperties::COLOR_TOOLBAR_SEPARATOR));
390}
391
392void GlassBrowserFrameView::PaintRestoredClientEdge(gfx::Canvas* canvas) {
393  ui::ThemeProvider* tp = GetThemeProvider();
394  gfx::Rect client_area_bounds = CalculateClientAreaBounds(width(), height());
395
396  // The client edges start below the toolbar upper corner images regardless
397  // of how tall the toolbar itself is.
398  int client_area_top = frame()->client_view()->y() +
399      browser_view()->GetToolbarBounds().y() +
400      tp->GetImageSkiaNamed(IDR_CONTENT_TOP_LEFT_CORNER)->height();
401  int client_area_bottom =
402      std::max(client_area_top, height() - NonClientBorderThickness());
403  int client_area_height = client_area_bottom - client_area_top;
404
405  // Draw the client edge images.
406  gfx::ImageSkia* right = tp->GetImageSkiaNamed(IDR_CONTENT_RIGHT_SIDE);
407  canvas->TileImageInt(*right, client_area_bounds.right(), client_area_top,
408                       right->width(), client_area_height);
409  canvas->DrawImageInt(
410      *tp->GetImageSkiaNamed(IDR_CONTENT_BOTTOM_RIGHT_CORNER),
411      client_area_bounds.right(), client_area_bottom);
412  gfx::ImageSkia* bottom = tp->GetImageSkiaNamed(IDR_CONTENT_BOTTOM_CENTER);
413  canvas->TileImageInt(*bottom, client_area_bounds.x(),
414      client_area_bottom, client_area_bounds.width(),
415      bottom->height());
416  gfx::ImageSkia* bottom_left =
417      tp->GetImageSkiaNamed(IDR_CONTENT_BOTTOM_LEFT_CORNER);
418  canvas->DrawImageInt(*bottom_left,
419      client_area_bounds.x() - bottom_left->width(), client_area_bottom);
420  gfx::ImageSkia* left = tp->GetImageSkiaNamed(IDR_CONTENT_LEFT_SIDE);
421  canvas->TileImageInt(*left, client_area_bounds.x() - left->width(),
422      client_area_top, left->width(), client_area_height);
423
424  // Draw the toolbar color so that the client edges show the right color even
425  // where not covered by the toolbar image.  NOTE: We do this after drawing the
426  // images because the images are meant to alpha-blend atop the frame whereas
427  // these rects are meant to be fully opaque, without anything overlaid.
428  SkColor toolbar_color = tp->GetColor(ThemeProperties::COLOR_TOOLBAR);
429  canvas->FillRect(gfx::Rect(client_area_bounds.x() - kClientEdgeThickness,
430      client_area_top, kClientEdgeThickness,
431      client_area_bottom + kClientEdgeThickness - client_area_top),
432      toolbar_color);
433  canvas->FillRect(gfx::Rect(client_area_bounds.x(), client_area_bottom,
434                             client_area_bounds.width(), kClientEdgeThickness),
435                   toolbar_color);
436  canvas->FillRect(gfx::Rect(client_area_bounds.right(), client_area_top,
437       kClientEdgeThickness,
438       client_area_bottom + kClientEdgeThickness - client_area_top),
439       toolbar_color);
440}
441
442void GlassBrowserFrameView::LayoutNewStyleAvatar() {
443  DCHECK(profiles::IsNewProfileManagementEnabled());
444  if (!new_avatar_button())
445    return;
446
447  gfx::Size label_size = new_avatar_button()->GetPreferredSize();
448  int button_size_with_offset = kNewAvatarButtonOffset + label_size.width();
449
450  int button_x = frame()->GetMinimizeButtonOffset() -
451      kNewAvatarButtonOffset - label_size.width();
452
453  if (base::i18n::IsRTL())
454    button_x = width() - frame()->GetMinimizeButtonOffset() +
455        kNewAvatarButtonOffset;
456
457  int button_y = frame()->IsMaximized() ? NonClientTopBorderHeight() : 1;
458  new_avatar_button()->SetBounds(
459      button_x,
460      button_y,
461      label_size.width(),
462      button_y + gfx::win::GetSystemMetricsInDIP(SM_CXMENUSIZE));
463}
464
465void GlassBrowserFrameView::LayoutAvatar() {
466  // Even though the avatar is used for both incognito and profiles we always
467  // use the incognito icon to layout the avatar button. The profile icon
468  // can be customized so we can't depend on its size to perform layout.
469  gfx::ImageSkia incognito_icon = browser_view()->GetOTRAvatarIcon();
470
471  int avatar_x = NonClientBorderThickness() + kAvatarLeftSpacing;
472  // Move this avatar icon by the size of window controls to prevent it from
473  // being rendered over them in RTL languages. This code also needs to adjust
474  // the width of a tab strip to avoid decreasing this size twice. (See the
475  // comment in GetBoundsForTabStrip().)
476  if (base::i18n::IsRTL())
477    avatar_x += width() - frame()->GetMinimizeButtonOffset();
478
479  int avatar_bottom = GetTopInset() +
480      browser_view()->GetTabStripHeight() - kAvatarBottomSpacing;
481  int avatar_restored_y = avatar_bottom - incognito_icon.height();
482  int avatar_y = frame()->IsMaximized() ?
483      (NonClientTopBorderHeight() + kTabstripTopShadowThickness) :
484      avatar_restored_y;
485  avatar_bounds_.SetRect(avatar_x, avatar_y, incognito_icon.width(),
486      browser_view()->ShouldShowAvatar() ? (avatar_bottom - avatar_y) : 0);
487  if (avatar_button())
488    avatar_button()->SetBoundsRect(avatar_bounds_);
489}
490
491void GlassBrowserFrameView::LayoutClientView() {
492  client_view_bounds_ = CalculateClientAreaBounds(width(), height());
493}
494
495gfx::Insets GlassBrowserFrameView::GetClientAreaInsets() const {
496  if (!browser_view()->IsTabStripVisible())
497    return gfx::Insets();
498
499  const int top_height = NonClientTopBorderHeight();
500  const int border_thickness = NonClientBorderThickness();
501  return gfx::Insets(top_height,
502                     border_thickness,
503                     border_thickness,
504                     border_thickness);
505}
506
507gfx::Rect GlassBrowserFrameView::CalculateClientAreaBounds(int width,
508                                                           int height) const {
509  gfx::Rect bounds(0, 0, width, height);
510  bounds.Inset(GetClientAreaInsets());
511  return bounds;
512}
513
514void GlassBrowserFrameView::StartThrobber() {
515  if (!throbber_running_) {
516    throbber_running_ = true;
517    throbber_frame_ = 0;
518    InitThrobberIcons();
519    SendMessage(views::HWNDForWidget(frame()), WM_SETICON,
520                static_cast<WPARAM>(ICON_SMALL),
521                reinterpret_cast<LPARAM>(throbber_icons_[throbber_frame_]));
522  }
523}
524
525void GlassBrowserFrameView::StopThrobber() {
526  if (throbber_running_) {
527    throbber_running_ = false;
528
529    HICON frame_icon = NULL;
530
531    // Check if hosted BrowserView has a window icon to use.
532    if (browser_view()->ShouldShowWindowIcon()) {
533      gfx::ImageSkia icon = browser_view()->GetWindowIcon();
534      if (!icon.isNull())
535        frame_icon = IconUtil::CreateHICONFromSkBitmap(*icon.bitmap());
536    }
537
538    // Fallback to class icon.
539    if (!frame_icon) {
540      frame_icon = reinterpret_cast<HICON>(GetClassLongPtr(
541          views::HWNDForWidget(frame()), GCLP_HICONSM));
542    }
543
544    // This will reset the small icon which we set in the throbber code.
545    // WM_SETICON with NULL icon restores the icon for title bar but not
546    // for taskbar. See http://crbug.com/29996
547    SendMessage(views::HWNDForWidget(frame()), WM_SETICON,
548                static_cast<WPARAM>(ICON_SMALL),
549                reinterpret_cast<LPARAM>(frame_icon));
550  }
551}
552
553void GlassBrowserFrameView::DisplayNextThrobberFrame() {
554  throbber_frame_ = (throbber_frame_ + 1) % kThrobberIconCount;
555  SendMessage(views::HWNDForWidget(frame()), WM_SETICON,
556              static_cast<WPARAM>(ICON_SMALL),
557              reinterpret_cast<LPARAM>(throbber_icons_[throbber_frame_]));
558}
559
560void GlassBrowserFrameView::Observe(
561    int type,
562    const content::NotificationSource& source,
563    const content::NotificationDetails& details) {
564  switch (type) {
565    case chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED:
566      if (browser_view()->IsRegularOrGuestSession() &&
567          profiles::IsNewProfileManagementEnabled())
568        UpdateNewStyleAvatarInfo(this, NewAvatarButton::NATIVE_BUTTON);
569      else
570        UpdateAvatarInfo();
571      break;
572    default:
573      NOTREACHED() << "Got a notification we didn't register for!";
574      break;
575  }
576}
577
578// static
579void GlassBrowserFrameView::InitThrobberIcons() {
580  static bool initialized = false;
581  if (!initialized) {
582    for (int i = 0; i < kThrobberIconCount; ++i) {
583      throbber_icons_[i] =
584          ui::LoadThemeIconFromResourcesDataDLL(IDI_THROBBER_01 + i);
585      DCHECK(throbber_icons_[i]);
586    }
587    initialized = true;
588  }
589}
590