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