| OLD | NEW |
| 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 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" | 5 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 #import "chrome/browser/ui/cocoa/location_bar/ev_bubble_decoration.h" | 41 #import "chrome/browser/ui/cocoa/location_bar/ev_bubble_decoration.h" |
| 42 #import "chrome/browser/ui/cocoa/location_bar/keyword_hint_decoration.h" | 42 #import "chrome/browser/ui/cocoa/location_bar/keyword_hint_decoration.h" |
| 43 #import "chrome/browser/ui/cocoa/location_bar/location_icon_decoration.h" | 43 #import "chrome/browser/ui/cocoa/location_bar/location_icon_decoration.h" |
| 44 #import "chrome/browser/ui/cocoa/location_bar/page_action_decoration.h" | 44 #import "chrome/browser/ui/cocoa/location_bar/page_action_decoration.h" |
| 45 #import "chrome/browser/ui/cocoa/location_bar/selected_keyword_decoration.h" | 45 #import "chrome/browser/ui/cocoa/location_bar/selected_keyword_decoration.h" |
| 46 #import "chrome/browser/ui/cocoa/location_bar/star_decoration.h" | 46 #import "chrome/browser/ui/cocoa/location_bar/star_decoration.h" |
| 47 #import "chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h" | 47 #import "chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h" |
| 48 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h" | 48 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h" |
| 49 #include "chrome/browser/ui/content_settings/content_setting_image_model.h" | 49 #include "chrome/browser/ui/content_settings/content_setting_image_model.h" |
| 50 #include "chrome/browser/ui/omnibox/location_bar_util.h" | 50 #include "chrome/browser/ui/omnibox/location_bar_util.h" |
| 51 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 51 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
| 52 #include "chrome/common/chrome_notification_types.h" | 52 #include "chrome/common/chrome_notification_types.h" |
| 53 #include "chrome/common/extensions/extension.h" | 53 #include "chrome/common/extensions/extension.h" |
| 54 #include "chrome/common/extensions/extension_action.h" | 54 #include "chrome/common/extensions/extension_action.h" |
| 55 #include "chrome/common/extensions/extension_resource.h" | 55 #include "chrome/common/extensions/extension_resource.h" |
| 56 #include "chrome/common/pref_names.h" | 56 #include "chrome/common/pref_names.h" |
| 57 #include "content/public/browser/notification_service.h" | 57 #include "content/public/browser/notification_service.h" |
| 58 #include "content/public/browser/web_contents.h" | 58 #include "content/public/browser/web_contents.h" |
| 59 #include "grit/generated_resources.h" | 59 #include "grit/generated_resources.h" |
| 60 #include "grit/theme_resources.h" | 60 #include "grit/theme_resources.h" |
| 61 #include "net/base/net_util.h" | 61 #include "net/base/net_util.h" |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 } | 311 } |
| 312 | 312 |
| 313 string16 LocationBarViewMac::GetTitle() const { | 313 string16 LocationBarViewMac::GetTitle() const { |
| 314 return browser_->GetWindowTitleForCurrentTab(); | 314 return browser_->GetWindowTitleForCurrentTab(); |
| 315 } | 315 } |
| 316 | 316 |
| 317 InstantController* LocationBarViewMac::GetInstant() { | 317 InstantController* LocationBarViewMac::GetInstant() { |
| 318 return browser_->instant(); | 318 return browser_->instant(); |
| 319 } | 319 } |
| 320 | 320 |
| 321 TabContentsWrapper* LocationBarViewMac::GetTabContentsWrapper() const { | 321 TabContents* LocationBarViewMac::GetTabContents() const { |
| 322 return browser_->GetSelectedTabContentsWrapper(); | 322 return browser_->GetActiveTabContents(); |
| 323 } | 323 } |
| 324 | 324 |
| 325 void LocationBarViewMac::Revert() { | 325 void LocationBarViewMac::Revert() { |
| 326 omnibox_view_->RevertAll(); | 326 omnibox_view_->RevertAll(); |
| 327 } | 327 } |
| 328 | 328 |
| 329 const OmniboxView* LocationBarViewMac::GetLocationEntry() const { | 329 const OmniboxView* LocationBarViewMac::GetLocationEntry() const { |
| 330 return omnibox_view_.get(); | 330 return omnibox_view_.get(); |
| 331 } | 331 } |
| 332 | 332 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 346 int LocationBarViewMac::PageActionVisibleCount() { | 346 int LocationBarViewMac::PageActionVisibleCount() { |
| 347 int result = 0; | 347 int result = 0; |
| 348 for (size_t i = 0; i < page_action_decorations_.size(); ++i) { | 348 for (size_t i = 0; i < page_action_decorations_.size(); ++i) { |
| 349 if (page_action_decorations_[i]->IsVisible()) | 349 if (page_action_decorations_[i]->IsVisible()) |
| 350 ++result; | 350 ++result; |
| 351 } | 351 } |
| 352 return result; | 352 return result; |
| 353 } | 353 } |
| 354 | 354 |
| 355 WebContents* LocationBarViewMac::GetWebContents() const { | 355 WebContents* LocationBarViewMac::GetWebContents() const { |
| 356 return browser_->GetSelectedWebContents(); | 356 return browser_->GetActiveWebContents(); |
| 357 } | 357 } |
| 358 | 358 |
| 359 PageActionDecoration* LocationBarViewMac::GetPageActionDecoration( | 359 PageActionDecoration* LocationBarViewMac::GetPageActionDecoration( |
| 360 ExtensionAction* page_action) { | 360 ExtensionAction* page_action) { |
| 361 DCHECK(page_action); | 361 DCHECK(page_action); |
| 362 for (size_t i = 0; i < page_action_decorations_.size(); ++i) { | 362 for (size_t i = 0; i < page_action_decorations_.size(); ++i) { |
| 363 if (page_action_decorations_[i]->page_action() == page_action) | 363 if (page_action_decorations_[i]->page_action() == page_action) |
| 364 return page_action_decorations_[i]; | 364 return page_action_decorations_[i]; |
| 365 } | 365 } |
| 366 // If |page_action| is the browser action of an extension, no element in | 366 // If |page_action| is the browser action of an extension, no element in |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 532 if (content::Details<WebContents>(contents) != details) | 532 if (content::Details<WebContents>(contents) != details) |
| 533 return; | 533 return; |
| 534 | 534 |
| 535 [field_ updateCursorAndToolTipRects]; | 535 [field_ updateCursorAndToolTipRects]; |
| 536 [field_ setNeedsDisplay:YES]; | 536 [field_ setNeedsDisplay:YES]; |
| 537 break; | 537 break; |
| 538 } | 538 } |
| 539 | 539 |
| 540 case chrome::NOTIFICATION_EXTENSION_LOCATION_BAR_UPDATED: { | 540 case chrome::NOTIFICATION_EXTENSION_LOCATION_BAR_UPDATED: { |
| 541 // Only update if the updated action box was for the active tab contents. | 541 // Only update if the updated action box was for the active tab contents. |
| 542 TabContentsWrapper* target_tab = | 542 TabContents* target_tab = content::Details<TabContents>(details).ptr(); |
| 543 content::Details<TabContentsWrapper>(details).ptr(); | 543 if (target_tab == GetTabContents()) |
| 544 if (target_tab == GetTabContentsWrapper()) | |
| 545 UpdatePageActions(); | 544 UpdatePageActions(); |
| 546 break; | 545 break; |
| 547 } | 546 } |
| 548 | 547 |
| 549 case chrome::NOTIFICATION_PREF_CHANGED: | 548 case chrome::NOTIFICATION_PREF_CHANGED: |
| 550 star_decoration_->SetVisible(IsStarEnabled()); | 549 star_decoration_->SetVisible(IsStarEnabled()); |
| 551 UpdateChromeToMobileEnabled(); | 550 UpdateChromeToMobileEnabled(); |
| 552 OnChanged(); | 551 OnChanged(); |
| 553 break; | 552 break; |
| 554 | 553 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 565 } | 564 } |
| 566 | 565 |
| 567 void LocationBarViewMac::PostNotification(NSString* notification) { | 566 void LocationBarViewMac::PostNotification(NSString* notification) { |
| 568 [[NSNotificationCenter defaultCenter] postNotificationName:notification | 567 [[NSNotificationCenter defaultCenter] postNotificationName:notification |
| 569 object:[NSValue valueWithPointer:this]]; | 568 object:[NSValue valueWithPointer:this]]; |
| 570 } | 569 } |
| 571 | 570 |
| 572 bool LocationBarViewMac::RefreshContentSettingsDecorations() { | 571 bool LocationBarViewMac::RefreshContentSettingsDecorations() { |
| 573 const bool input_in_progress = toolbar_model_->input_in_progress(); | 572 const bool input_in_progress = toolbar_model_->input_in_progress(); |
| 574 WebContents* web_contents = | 573 WebContents* web_contents = |
| 575 input_in_progress ? NULL : browser_->GetSelectedWebContents(); | 574 input_in_progress ? NULL : browser_->GetActiveWebContents(); |
| 576 bool icons_updated = false; | 575 bool icons_updated = false; |
| 577 for (size_t i = 0; i < content_setting_decorations_.size(); ++i) { | 576 for (size_t i = 0; i < content_setting_decorations_.size(); ++i) { |
| 578 icons_updated |= | 577 icons_updated |= |
| 579 content_setting_decorations_[i]->UpdateFromWebContents(web_contents); | 578 content_setting_decorations_[i]->UpdateFromWebContents(web_contents); |
| 580 } | 579 } |
| 581 return icons_updated; | 580 return icons_updated; |
| 582 } | 581 } |
| 583 | 582 |
| 584 void LocationBarViewMac::DeletePageActionDecorations() { | 583 void LocationBarViewMac::DeletePageActionDecorations() { |
| 585 // TODO(shess): Deleting these decorations could result in the cell | 584 // TODO(shess): Deleting these decorations could result in the cell |
| 586 // refering to them before things are laid out again. Meanwhile, at | 585 // refering to them before things are laid out again. Meanwhile, at |
| 587 // least fail safe. | 586 // least fail safe. |
| 588 [[field_ cell] clearDecorations]; | 587 [[field_ cell] clearDecorations]; |
| 589 | 588 |
| 590 page_action_decorations_.reset(); | 589 page_action_decorations_.reset(); |
| 591 } | 590 } |
| 592 | 591 |
| 593 void LocationBarViewMac::RefreshPageActionDecorations() { | 592 void LocationBarViewMac::RefreshPageActionDecorations() { |
| 594 if (!IsEditable()) { | 593 if (!IsEditable()) { |
| 595 DeletePageActionDecorations(); | 594 DeletePageActionDecorations(); |
| 596 return; | 595 return; |
| 597 } | 596 } |
| 598 | 597 |
| 599 std::vector<ExtensionAction*> page_actions; | 598 std::vector<ExtensionAction*> page_actions; |
| 600 | 599 |
| 601 TabContentsWrapper* tab_contents = GetTabContentsWrapper(); | 600 TabContents* tab_contents = GetTabContents(); |
| 602 if (!tab_contents) { | 601 if (!tab_contents) { |
| 603 DeletePageActionDecorations(); // Necessary? | 602 DeletePageActionDecorations(); // Necessary? |
| 604 return; | 603 return; |
| 605 } | 604 } |
| 606 | 605 |
| 607 extensions::LocationBarController* controller = | 606 extensions::LocationBarController* controller = |
| 608 tab_contents->extension_tab_helper()->location_bar_controller(); | 607 tab_contents->extension_tab_helper()->location_bar_controller(); |
| 609 page_actions.swap(*controller->GetCurrentActions()); | 608 page_actions.swap(*controller->GetCurrentActions()); |
| 610 | 609 |
| 611 // On startup we sometimes haven't loaded any extensions. This makes sure | 610 // On startup we sometimes haven't loaded any extensions. This makes sure |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 711 void LocationBarViewMac::UpdateChromeToMobileEnabled() { | 710 void LocationBarViewMac::UpdateChromeToMobileEnabled() { |
| 712 if (!chrome_to_mobile_decoration_.get()) | 711 if (!chrome_to_mobile_decoration_.get()) |
| 713 return; | 712 return; |
| 714 | 713 |
| 715 DCHECK(ChromeToMobileService::IsChromeToMobileEnabled()); | 714 DCHECK(ChromeToMobileService::IsChromeToMobileEnabled()); |
| 716 bool enabled = [field_ isEditable] && !toolbar_model_->input_in_progress() && | 715 bool enabled = [field_ isEditable] && !toolbar_model_->input_in_progress() && |
| 717 ChromeToMobileServiceFactory::GetForProfile(profile_)->HasDevices(); | 716 ChromeToMobileServiceFactory::GetForProfile(profile_)->HasDevices(); |
| 718 chrome_to_mobile_decoration_->SetVisible(enabled); | 717 chrome_to_mobile_decoration_->SetVisible(enabled); |
| 719 command_updater_->UpdateCommandEnabled(IDC_CHROME_TO_MOBILE_PAGE, enabled); | 718 command_updater_->UpdateCommandEnabled(IDC_CHROME_TO_MOBILE_PAGE, enabled); |
| 720 } | 719 } |
| OLD | NEW |