Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(44)

Side by Side Diff: chrome/browser/gtk/browser_actions_toolbar_gtk.cc

Issue 567037: Initial work on making extensions work in incognito mode. (Closed)
Patch Set: added experimental requirement Created 10 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/gtk/browser_actions_toolbar_gtk.h" 5 #include "chrome/browser/gtk/browser_actions_toolbar_gtk.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "app/gfx/canvas_paint.h" 9 #include "app/gfx/canvas_paint.h"
10 #include "app/gfx/gtk_util.h" 10 #include "app/gfx/gtk_util.h"
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 325
326 int i = 0; 326 int i = 0;
327 for (ExtensionList::iterator iter = model_->begin(); 327 for (ExtensionList::iterator iter = model_->begin();
328 iter != model_->end(); ++iter) { 328 iter != model_->end(); ++iter) {
329 CreateButtonForExtension(*iter, i++); 329 CreateButtonForExtension(*iter, i++);
330 } 330 }
331 } 331 }
332 332
333 void BrowserActionsToolbarGtk::CreateButtonForExtension(Extension* extension, 333 void BrowserActionsToolbarGtk::CreateButtonForExtension(Extension* extension,
334 int index) { 334 int index) {
335 if (!ShouldDisplayBrowserAction(extension))
336 return;
337
338 if (profile_->IsOffTheRecord())
339 index = model_->OriginalIndexToIncognito(index);
340
335 RemoveButtonForExtension(extension); 341 RemoveButtonForExtension(extension);
336 linked_ptr<BrowserActionButton> button( 342 linked_ptr<BrowserActionButton> button(
337 new BrowserActionButton(this, extension)); 343 new BrowserActionButton(this, extension));
338 gtk_box_pack_start(GTK_BOX(hbox_.get()), button->widget(), FALSE, FALSE, 0); 344 gtk_box_pack_start(GTK_BOX(hbox_.get()), button->widget(), FALSE, FALSE, 0);
339 gtk_box_reorder_child(GTK_BOX(hbox_.get()), button->widget(), index); 345 gtk_box_reorder_child(GTK_BOX(hbox_.get()), button->widget(), index);
340 gtk_widget_show(button->widget()); 346 gtk_widget_show(button->widget());
341 extension_button_map_[extension->id()] = button; 347 extension_button_map_[extension->id()] = button;
342 348
343 GtkTargetEntry drag_target = GetDragTargetEntry(); 349 GtkTargetEntry drag_target = GetDragTargetEntry();
344 gtk_drag_source_set(button->widget(), GDK_BUTTON1_MASK, &drag_target, 1, 350 gtk_drag_source_set(button->widget(), GDK_BUTTON1_MASK, &drag_target, 1,
(...skipping 22 matching lines...) Expand all
367 UpdateVisibility(); 373 UpdateVisibility();
368 } 374 }
369 375
370 void BrowserActionsToolbarGtk::UpdateVisibility() { 376 void BrowserActionsToolbarGtk::UpdateVisibility() {
371 if (button_count() == 0) 377 if (button_count() == 0)
372 gtk_widget_hide(widget()); 378 gtk_widget_hide(widget());
373 else 379 else
374 gtk_widget_show(widget()); 380 gtk_widget_show(widget());
375 } 381 }
376 382
383 bool BrowserActionsToolbarGtk::ShouldDisplayBrowserAction(
384 Extension* extension) {
385 // Only display incognito-enabled extensions while in incognito mode.
386 return (!profile_->IsOffTheRecord() ||
387 profile_->GetExtensionsService()->
388 IsIncognitoEnabled(extension->id()));
389 }
390
377 void BrowserActionsToolbarGtk::HidePopup() { 391 void BrowserActionsToolbarGtk::HidePopup() {
378 ExtensionPopupGtk* popup = ExtensionPopupGtk::get_current_extension_popup(); 392 ExtensionPopupGtk* popup = ExtensionPopupGtk::get_current_extension_popup();
379 if (popup) 393 if (popup)
380 popup->DestroyPopup(); 394 popup->DestroyPopup();
381 } 395 }
382 396
383 void BrowserActionsToolbarGtk::BrowserActionAdded(Extension* extension, 397 void BrowserActionsToolbarGtk::BrowserActionAdded(Extension* extension,
384 int index) { 398 int index) {
385 CreateButtonForExtension(extension, index); 399 CreateButtonForExtension(extension, index);
386 } 400 }
387 401
388 void BrowserActionsToolbarGtk::BrowserActionRemoved(Extension* extension) { 402 void BrowserActionsToolbarGtk::BrowserActionRemoved(Extension* extension) {
389 if (drag_button_ != NULL) { 403 if (drag_button_ != NULL) {
390 // Break the current drag. 404 // Break the current drag.
391 gtk_grab_remove(widget()); 405 gtk_grab_remove(widget());
392 } 406 }
393 407
394 RemoveButtonForExtension(extension); 408 RemoveButtonForExtension(extension);
395 } 409 }
396 410
397 void BrowserActionsToolbarGtk::BrowserActionMoved(Extension* extension, 411 void BrowserActionsToolbarGtk::BrowserActionMoved(Extension* extension,
398 int index) { 412 int index) {
399 // We initiated this move action, and have already moved the button. 413 // We initiated this move action, and have already moved the button.
400 if (drag_button_ != NULL) 414 if (drag_button_ != NULL)
401 return; 415 return;
402 416
403 BrowserActionButton* button = extension_button_map_[extension->id()].get(); 417 BrowserActionButton* button = extension_button_map_[extension->id()].get();
404 if (!button) { 418 if (!button) {
405 NOTREACHED(); 419 if (ShouldDisplayBrowserAction(extension))
420 NOTREACHED();
406 return; 421 return;
407 } 422 }
408 423
424 if (profile_->IsOffTheRecord())
425 index = model_->OriginalIndexToIncognito(index);
426
409 gtk_box_reorder_child(GTK_BOX(hbox_.get()), button->widget(), index); 427 gtk_box_reorder_child(GTK_BOX(hbox_.get()), button->widget(), index);
410 } 428 }
411 429
412 void BrowserActionsToolbarGtk::DragStarted(BrowserActionButton* button, 430 void BrowserActionsToolbarGtk::DragStarted(BrowserActionButton* button,
413 GdkDragContext* drag_context) { 431 GdkDragContext* drag_context) {
414 // No representation of the widget following the cursor. 432 // No representation of the widget following the cursor.
415 GdkPixbuf* pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, 1, 1); 433 GdkPixbuf* pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, 1, 1);
416 gtk_drag_set_icon_pixbuf(drag_context, pixbuf, 0, 0); 434 gtk_drag_set_icon_pixbuf(drag_context, pixbuf, 0, 0);
417 g_object_unref(pixbuf); 435 g_object_unref(pixbuf);
418 436
419 DCHECK(!drag_button_); 437 DCHECK(!drag_button_);
420 drag_button_ = button; 438 drag_button_ = button;
421 } 439 }
422 440
423 gboolean BrowserActionsToolbarGtk::OnDragMotion(GtkWidget* widget, 441 gboolean BrowserActionsToolbarGtk::OnDragMotion(GtkWidget* widget,
424 GdkDragContext* drag_context, 442 GdkDragContext* drag_context,
425 gint x, gint y, guint time) { 443 gint x, gint y, guint time) {
426 // Only handle drags we initiated. 444 // Only handle drags we initiated.
427 if (!drag_button_) 445 if (!drag_button_)
428 return FALSE; 446 return FALSE;
429 447
430 drop_index_ = x < kButtonSize ? 0 : x / (kButtonSize + kButtonPadding); 448 drop_index_ = x < kButtonSize ? 0 : x / (kButtonSize + kButtonPadding);
449 if (profile_->IsOffTheRecord())
450 drop_index_ = model_->IncognitoIndexToOriginal(drop_index_);
451
431 // We will go ahead and reorder the child in order to provide visual feedback 452 // We will go ahead and reorder the child in order to provide visual feedback
432 // to the user. We don't inform the model that it has moved until the drag 453 // to the user. We don't inform the model that it has moved until the drag
433 // ends. 454 // ends.
434 gtk_box_reorder_child(GTK_BOX(hbox_.get()), drag_button_->widget(), 455 gtk_box_reorder_child(GTK_BOX(hbox_.get()), drag_button_->widget(),
435 drop_index_); 456 drop_index_);
436 457
437 gdk_drag_status(drag_context, GDK_ACTION_MOVE, time); 458 gdk_drag_status(drag_context, GDK_ACTION_MOVE, time);
438 return TRUE; 459 return TRUE;
439 } 460 }
440 461
(...skipping 21 matching lines...) Expand all
462 if (!GTK_WIDGET_TOPLEVEL(toplevel)) 483 if (!GTK_WIDGET_TOPLEVEL(toplevel))
463 return; 484 return;
464 485
465 g_signal_connect(toplevel, "set-focus", G_CALLBACK(OnSetFocusThunk), this); 486 g_signal_connect(toplevel, "set-focus", G_CALLBACK(OnSetFocusThunk), this);
466 } 487 }
467 488
468 void BrowserActionsToolbarGtk::OnSetFocus() { 489 void BrowserActionsToolbarGtk::OnSetFocus() {
469 // The focus of the parent window has changed. Close the popup. 490 // The focus of the parent window has changed. Close the popup.
470 HidePopup(); 491 HidePopup();
471 } 492 }
OLDNEW
« no previous file with comments | « chrome/browser/gtk/browser_actions_toolbar_gtk.h ('k') | chrome/browser/net/chrome_url_request_context.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698