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

Side by Side Diff: chrome/browser/ui/gtk/location_bar_view_gtk.cc

Issue 10533046: TabContentsWrapper -> TabContents, part 4. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: compiling is good Created 8 years, 6 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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/ui/gtk/location_bar_view_gtk.h" 5 #include "chrome/browser/ui/gtk/location_bar_view_gtk.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 #include "chrome/browser/ui/gtk/content_setting_bubble_gtk.h" 49 #include "chrome/browser/ui/gtk/content_setting_bubble_gtk.h"
50 #include "chrome/browser/ui/gtk/extensions/extension_popup_gtk.h" 50 #include "chrome/browser/ui/gtk/extensions/extension_popup_gtk.h"
51 #include "chrome/browser/ui/gtk/first_run_bubble.h" 51 #include "chrome/browser/ui/gtk/first_run_bubble.h"
52 #include "chrome/browser/ui/gtk/gtk_theme_service.h" 52 #include "chrome/browser/ui/gtk/gtk_theme_service.h"
53 #include "chrome/browser/ui/gtk/gtk_util.h" 53 #include "chrome/browser/ui/gtk/gtk_util.h"
54 #include "chrome/browser/ui/gtk/nine_box.h" 54 #include "chrome/browser/ui/gtk/nine_box.h"
55 #include "chrome/browser/ui/gtk/omnibox/omnibox_view_gtk.h" 55 #include "chrome/browser/ui/gtk/omnibox/omnibox_view_gtk.h"
56 #include "chrome/browser/ui/gtk/rounded_window.h" 56 #include "chrome/browser/ui/gtk/rounded_window.h"
57 #include "chrome/browser/ui/gtk/view_id_util.h" 57 #include "chrome/browser/ui/gtk/view_id_util.h"
58 #include "chrome/browser/ui/omnibox/location_bar_util.h" 58 #include "chrome/browser/ui/omnibox/location_bar_util.h"
59 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 59 #include "chrome/browser/ui/tab_contents/tab_contents.h"
60 #include "chrome/common/chrome_notification_types.h" 60 #include "chrome/common/chrome_notification_types.h"
61 #include "chrome/common/extensions/extension.h" 61 #include "chrome/common/extensions/extension.h"
62 #include "chrome/common/extensions/extension_action.h" 62 #include "chrome/common/extensions/extension_action.h"
63 #include "chrome/common/extensions/extension_manifest_constants.h" 63 #include "chrome/common/extensions/extension_manifest_constants.h"
64 #include "chrome/common/extensions/extension_resource.h" 64 #include "chrome/common/extensions/extension_resource.h"
65 #include "chrome/common/pref_names.h" 65 #include "chrome/common/pref_names.h"
66 #include "content/public/browser/navigation_entry.h" 66 #include "content/public/browser/navigation_entry.h"
67 #include "content/public/browser/notification_service.h" 67 #include "content/public/browser/notification_service.h"
68 #include "content/public/browser/web_contents.h" 68 #include "content/public/browser/web_contents.h"
69 #include "grit/generated_resources.h" 69 #include "grit/generated_resources.h"
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 435
436 gtk_drag_source_set(site_type_event_box_, GDK_BUTTON1_MASK, 436 gtk_drag_source_set(site_type_event_box_, GDK_BUTTON1_MASK,
437 NULL, 0, GDK_ACTION_COPY); 437 NULL, 0, GDK_ACTION_COPY);
438 ui::SetSourceTargetListFromCodeMask(site_type_event_box_, 438 ui::SetSourceTargetListFromCodeMask(site_type_event_box_,
439 ui::TEXT_PLAIN | 439 ui::TEXT_PLAIN |
440 ui::TEXT_URI_LIST | 440 ui::TEXT_URI_LIST |
441 ui::CHROME_NAMED_URL); 441 ui::CHROME_NAMED_URL);
442 } 442 }
443 443
444 WebContents* LocationBarViewGtk::GetWebContents() const { 444 WebContents* LocationBarViewGtk::GetWebContents() const {
445 return browser_->GetSelectedWebContents(); 445 return browser_->GetActiveWebContents();
446 } 446 }
447 447
448 void LocationBarViewGtk::SetPreviewEnabledPageAction( 448 void LocationBarViewGtk::SetPreviewEnabledPageAction(
449 ExtensionAction *page_action, 449 ExtensionAction *page_action,
450 bool preview_enabled) { 450 bool preview_enabled) {
451 DCHECK(page_action); 451 DCHECK(page_action);
452 UpdatePageActions(); 452 UpdatePageActions();
453 for (ScopedVector<PageActionViewGtk>::iterator iter = 453 for (ScopedVector<PageActionViewGtk>::iterator iter =
454 page_action_views_.begin(); iter != page_action_views_.end(); 454 page_action_views_.begin(); iter != page_action_views_.end();
455 ++iter) { 455 ++iter) {
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
610 content::NotificationService::current()->Notify( 610 content::NotificationService::current()->Notify(
611 chrome::NOTIFICATION_ACCESSIBILITY_CONTROL_FOCUSED, 611 chrome::NOTIFICATION_ACCESSIBILITY_CONTROL_FOCUSED,
612 content::Source<Profile>(profile), 612 content::Source<Profile>(profile),
613 content::Details<AccessibilityTextBoxInfo>(&info)); 613 content::Details<AccessibilityTextBoxInfo>(&info));
614 614
615 // Update the keyword and search hint states. 615 // Update the keyword and search hint states.
616 OnChanged(); 616 OnChanged();
617 } 617 }
618 618
619 SkBitmap LocationBarViewGtk::GetFavicon() const { 619 SkBitmap LocationBarViewGtk::GetFavicon() const {
620 return GetTabContentsWrapper()->favicon_tab_helper()->GetFavicon(); 620 return GetTabContents()->favicon_tab_helper()->GetFavicon();
621 } 621 }
622 622
623 string16 LocationBarViewGtk::GetTitle() const { 623 string16 LocationBarViewGtk::GetTitle() const {
624 return GetWebContents()->GetTitle(); 624 return GetWebContents()->GetTitle();
625 } 625 }
626 626
627 InstantController* LocationBarViewGtk::GetInstant() { 627 InstantController* LocationBarViewGtk::GetInstant() {
628 return browser_->instant(); 628 return browser_->instant();
629 } 629 }
630 630
631 TabContentsWrapper* LocationBarViewGtk::GetTabContentsWrapper() const { 631 TabContents* LocationBarViewGtk::GetTabContents() const {
632 return browser_->GetSelectedTabContentsWrapper(); 632 return browser_->GetActiveTabContents();
633 } 633 }
634 634
635 void LocationBarViewGtk::ShowFirstRunBubble() { 635 void LocationBarViewGtk::ShowFirstRunBubble() {
636 // We need the browser window to be shown before we can show the bubble, but 636 // We need the browser window to be shown before we can show the bubble, but
637 // we get called before that's happened. 637 // we get called before that's happened.
638 MessageLoop::current()->PostTask( 638 MessageLoop::current()->PostTask(
639 FROM_HERE, 639 FROM_HERE,
640 base::Bind(&LocationBarViewGtk::ShowFirstRunBubbleInternal, 640 base::Bind(&LocationBarViewGtk::ShowFirstRunBubbleInternal,
641 weak_ptr_factory_.GetWeakPtr())); 641 weak_ptr_factory_.GetWeakPtr()));
642 } 642 }
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
685 } 685 }
686 686
687 // If there are no visible content things, hide the top level box so it 687 // If there are no visible content things, hide the top level box so it
688 // doesn't mess with padding. 688 // doesn't mess with padding.
689 gtk_widget_set_visible(content_setting_hbox_.get(), any_visible); 689 gtk_widget_set_visible(content_setting_hbox_.get(), any_visible);
690 } 690 }
691 691
692 void LocationBarViewGtk::UpdatePageActions() { 692 void LocationBarViewGtk::UpdatePageActions() {
693 std::vector<ExtensionAction*> page_actions; 693 std::vector<ExtensionAction*> page_actions;
694 694
695 TabContentsWrapper* tab_contents = GetTabContentsWrapper(); 695 TabContents* tab_contents = GetTabContents();
696 if (tab_contents) { 696 if (tab_contents) {
697 LocationBarController* controller = 697 LocationBarController* controller =
698 tab_contents->extension_tab_helper()->location_bar_controller(); 698 tab_contents->extension_tab_helper()->location_bar_controller();
699 page_actions.swap(*controller->GetCurrentActions()); 699 page_actions.swap(*controller->GetCurrentActions());
700 } 700 }
701 701
702 // Initialize on the first call, or re-inialize if more extensions have been 702 // Initialize on the first call, or re-inialize if more extensions have been
703 // loaded or added after startup. 703 // loaded or added after startup.
704 if (page_actions.size() != page_action_views_.size()) { 704 if (page_actions.size() != page_action_views_.size()) {
705 page_action_views_.reset(); // Delete the old views (if any). 705 page_action_views_.reset(); // Delete the old views (if any).
706 706
707 for (size_t i = 0; i < page_actions.size(); ++i) { 707 for (size_t i = 0; i < page_actions.size(); ++i) {
708 page_action_views_.push_back( 708 page_action_views_.push_back(
709 new PageActionViewGtk(this, page_actions[i])); 709 new PageActionViewGtk(this, page_actions[i]));
710 gtk_box_pack_end(GTK_BOX(page_action_hbox_.get()), 710 gtk_box_pack_end(GTK_BOX(page_action_hbox_.get()),
711 page_action_views_[i]->widget(), FALSE, FALSE, 0); 711 page_action_views_[i]->widget(), FALSE, FALSE, 0);
712 } 712 }
713 content::NotificationService::current()->Notify( 713 content::NotificationService::current()->Notify(
714 chrome::NOTIFICATION_EXTENSION_PAGE_ACTION_COUNT_CHANGED, 714 chrome::NOTIFICATION_EXTENSION_PAGE_ACTION_COUNT_CHANGED,
715 content::Source<LocationBar>(this), 715 content::Source<LocationBar>(this),
716 content::NotificationService::NoDetails()); 716 content::NotificationService::NoDetails());
717 } 717 }
718 718
719 WebContents* contents = GetWebContents(); 719 WebContents* contents = GetWebContents();
720 if (!page_action_views_.empty() && contents) { 720 if (!page_action_views_.empty() && contents) {
721 GURL url = browser()->GetSelectedWebContents()->GetURL(); 721 GURL url = browser()->GetActiveWebContents()->GetURL();
722 722
723 for (size_t i = 0; i < page_action_views_.size(); i++) { 723 for (size_t i = 0; i < page_action_views_.size(); i++) {
724 page_action_views_[i]->UpdateVisibility( 724 page_action_views_[i]->UpdateVisibility(
725 toolbar_model_->input_in_progress() ? NULL : contents, url); 725 toolbar_model_->input_in_progress() ? NULL : contents, url);
726 } 726 }
727 } 727 }
728 728
729 // If there are no visible page actions, hide the hbox too, so that it does 729 // If there are no visible page actions, hide the hbox too, so that it does
730 // not affect the padding in the location bar. 730 // not affect the padding in the location bar.
731 gtk_widget_set_visible(page_action_hbox_.get(), 731 gtk_widget_set_visible(page_action_hbox_.get(),
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
809 const content::NotificationSource& source, 809 const content::NotificationSource& source,
810 const content::NotificationDetails& details) { 810 const content::NotificationDetails& details) {
811 if (type == chrome::NOTIFICATION_PREF_CHANGED) { 811 if (type == chrome::NOTIFICATION_PREF_CHANGED) {
812 UpdateStarIcon(); 812 UpdateStarIcon();
813 UpdateChromeToMobileIcon(); 813 UpdateChromeToMobileIcon();
814 return; 814 return;
815 } 815 }
816 816
817 if (type == chrome::NOTIFICATION_EXTENSION_LOCATION_BAR_UPDATED) { 817 if (type == chrome::NOTIFICATION_EXTENSION_LOCATION_BAR_UPDATED) {
818 // Only update if the updated action box was for the active tab contents. 818 // Only update if the updated action box was for the active tab contents.
819 TabContentsWrapper* target_tab = 819 TabContents* target_tab = content::Details<TabContents>(details).ptr();
820 content::Details<TabContentsWrapper>(details).ptr(); 820 if (target_tab == GetTabContents())
821 if (target_tab == GetTabContentsWrapper())
822 UpdatePageActions(); 821 UpdatePageActions();
823 return; 822 return;
824 } 823 }
825 824
826 DCHECK_EQ(type, chrome::NOTIFICATION_BROWSER_THEME_CHANGED); 825 DCHECK_EQ(type, chrome::NOTIFICATION_BROWSER_THEME_CHANGED);
827 826
828 if (theme_service_->UsingNativeTheme()) { 827 if (theme_service_->UsingNativeTheme()) {
829 gtk_widget_modify_bg(tab_to_search_box_, GTK_STATE_NORMAL, NULL); 828 gtk_widget_modify_bg(tab_to_search_box_, GTK_STATE_NORMAL, NULL);
830 829
831 GdkColor border_color = theme_service_->GetGdkColor( 830 GdkColor border_color = theme_service_->GetGdkColor(
(...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after
1371 gtk_image_set_from_pixbuf(GTK_IMAGE(image_.get()), 1370 gtk_image_set_from_pixbuf(GTK_IMAGE(image_.get()),
1372 GtkThemeService::GetFrom(parent_->browser()->profile())->GetImageNamed( 1371 GtkThemeService::GetFrom(parent_->browser()->profile())->GetImageNamed(
1373 content_setting_image_model_->get_icon())->ToGdkPixbuf()); 1372 content_setting_image_model_->get_icon())->ToGdkPixbuf());
1374 1373
1375 gtk_widget_set_tooltip_text(widget(), 1374 gtk_widget_set_tooltip_text(widget(),
1376 content_setting_image_model_->get_tooltip().c_str()); 1375 content_setting_image_model_->get_tooltip().c_str());
1377 gtk_widget_show_all(widget()); 1376 gtk_widget_show_all(widget());
1378 1377
1379 TabSpecificContentSettings* content_settings = NULL; 1378 TabSpecificContentSettings* content_settings = NULL;
1380 if (web_contents) { 1379 if (web_contents) {
1381 content_settings = TabContentsWrapper::GetCurrentWrapperForContents( 1380 content_settings = TabContents::GetOwningTabContentsForWebContents(
1382 web_contents)->content_settings(); 1381 web_contents)->content_settings();
1383 } 1382 }
1384 if (!content_settings || content_settings->IsBlockageIndicated( 1383 if (!content_settings || content_settings->IsBlockageIndicated(
1385 content_setting_image_model_->get_content_settings_type())) 1384 content_setting_image_model_->get_content_settings_type()))
1386 return; 1385 return;
1387 1386
1388 // The content blockage was not yet indicated to the user. Start indication 1387 // The content blockage was not yet indicated to the user. Start indication
1389 // animation and clear "not yet shown" flag. 1388 // animation and clear "not yet shown" flag.
1390 content_settings->SetBlockageHasBeenIndicated( 1389 content_settings->SetBlockageHasBeenIndicated(
1391 content_setting_image_model_->get_content_settings_type()); 1390 content_setting_image_model_->get_content_settings_type());
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1444 gtk_event_box_set_visible_window(GTK_EVENT_BOX(event_box_.get()), FALSE); 1443 gtk_event_box_set_visible_window(GTK_EVENT_BOX(event_box_.get()), FALSE);
1445 } 1444 }
1446 } 1445 }
1447 1446
1448 void LocationBarViewGtk::ContentSettingImageViewGtk::AnimationCanceled( 1447 void LocationBarViewGtk::ContentSettingImageViewGtk::AnimationCanceled(
1449 const ui::Animation* animation) { 1448 const ui::Animation* animation) {
1450 } 1449 }
1451 1450
1452 gboolean LocationBarViewGtk::ContentSettingImageViewGtk::OnButtonPressed( 1451 gboolean LocationBarViewGtk::ContentSettingImageViewGtk::OnButtonPressed(
1453 GtkWidget* sender, GdkEvent* event) { 1452 GtkWidget* sender, GdkEvent* event) {
1454 TabContentsWrapper* tab_contents = parent_->GetTabContentsWrapper(); 1453 TabContents* tab_contents = parent_->GetTabContents();
1455 if (!tab_contents) 1454 if (!tab_contents)
1456 return TRUE; 1455 return TRUE;
1457 Profile* profile = parent_->browser()->profile(); 1456 Profile* profile = parent_->browser()->profile();
1458 content_setting_bubble_ = new ContentSettingBubbleGtk( 1457 content_setting_bubble_ = new ContentSettingBubbleGtk(
1459 sender, this, 1458 sender, this,
1460 ContentSettingBubbleModel::CreateContentSettingBubbleModel( 1459 ContentSettingBubbleModel::CreateContentSettingBubbleModel(
1461 parent_->browser()->content_setting_bubble_model_delegate(), 1460 parent_->browser()->content_setting_bubble_model_delegate(),
1462 tab_contents, 1461 tab_contents,
1463 profile, 1462 profile,
1464 content_setting_image_model_->get_content_settings_type()), 1463 content_setting_image_model_->get_content_settings_type()),
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
1743 gtk_window_remove_accel_group(window_, accel_group_); 1742 gtk_window_remove_accel_group(window_, accel_group_);
1744 g_object_unref(accel_group_); 1743 g_object_unref(accel_group_);
1745 accel_group_ = NULL; 1744 accel_group_ = NULL;
1746 keybinding_.reset(NULL); 1745 keybinding_.reset(NULL);
1747 } 1746 }
1748 } 1747 }
1749 1748
1750 gboolean LocationBarViewGtk::PageActionViewGtk::OnButtonPressed( 1749 gboolean LocationBarViewGtk::PageActionViewGtk::OnButtonPressed(
1751 GtkWidget* sender, 1750 GtkWidget* sender,
1752 GdkEventButton* event) { 1751 GdkEventButton* event) {
1753 TabContentsWrapper* tab_contents = owner_->GetTabContentsWrapper(); 1752 TabContents* tab_contents = owner_->GetTabContents();
1754 if (!tab_contents) 1753 if (!tab_contents)
1755 return TRUE; 1754 return TRUE;
1756 1755
1757 ExtensionService* extension_service = 1756 ExtensionService* extension_service =
1758 owner_->browser()->profile()->GetExtensionService(); 1757 owner_->browser()->profile()->GetExtensionService();
1759 if (!extension_service) 1758 if (!extension_service)
1760 return TRUE; 1759 return TRUE;
1761 1760
1762 const Extension* extension = 1761 const Extension* extension =
1763 extension_service->extensions()->GetByID(page_action()->extension_id()); 1762 extension_service->extensions()->GetByID(page_action()->extension_id());
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
1825 GdkModifierType modifier, 1824 GdkModifierType modifier,
1826 void* user_data) { 1825 void* user_data) {
1827 PageActionViewGtk* view = static_cast<PageActionViewGtk*>(user_data); 1826 PageActionViewGtk* view = static_cast<PageActionViewGtk*>(user_data);
1828 if (!gtk_widget_get_visible(view->widget())) 1827 if (!gtk_widget_get_visible(view->widget()))
1829 return FALSE; 1828 return FALSE;
1830 1829
1831 GdkEventButton event = {}; 1830 GdkEventButton event = {};
1832 event.button = 1; 1831 event.button = 1;
1833 return view->OnButtonPressed(view->widget(), &event); 1832 return view->OnButtonPressed(view->widget(), &event);
1834 } 1833 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/gtk/location_bar_view_gtk.h ('k') | chrome/browser/ui/views/location_bar/click_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698