| OLD | NEW |
| 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/tab_contents/tab_contents.h" | 5 #include "chrome/browser/tab_contents/tab_contents.h" |
| 6 | 6 |
| 7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
| 8 #include "app/resource_bundle.h" | 8 #include "app/resource_bundle.h" |
| 9 #include "base/file_version_info.h" | 9 #include "base/file_version_info.h" |
| 10 #include "base/process_util.h" | 10 #include "base/process_util.h" |
| (...skipping 591 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 602 | 602 |
| 603 is_crashed_ = state; | 603 is_crashed_ = state; |
| 604 NotifyNavigationStateChanged(INVALIDATE_TAB); | 604 NotifyNavigationStateChanged(INVALIDATE_TAB); |
| 605 } | 605 } |
| 606 | 606 |
| 607 void TabContents::SetPageActionEnabled(const ExtensionAction* page_action, | 607 void TabContents::SetPageActionEnabled(const ExtensionAction* page_action, |
| 608 bool enable, | 608 bool enable, |
| 609 const std::string& title, | 609 const std::string& title, |
| 610 int icon_id) { | 610 int icon_id) { |
| 611 DCHECK(page_action); | 611 DCHECK(page_action); |
| 612 | 612 ExtensionActionState* state = GetOrCreatePageActionState(page_action); |
| 613 if (!enable && | 613 state->set_hidden(!enable); |
| 614 enabled_page_actions_.end() == enabled_page_actions_.find(page_action)) { | 614 state->set_title(title); |
| 615 return; // Don't need to disable twice. | 615 state->set_icon_index(icon_id); |
| 616 } | 616 state->set_icon(NULL); |
| 617 | |
| 618 if (enable) { | |
| 619 enabled_page_actions_[page_action].reset( | |
| 620 new ExtensionActionState(title, icon_id)); | |
| 621 } else { | |
| 622 enabled_page_actions_.erase(page_action); | |
| 623 } | |
| 624 } | 617 } |
| 625 | 618 |
| 626 const ExtensionActionState* TabContents::GetPageActionState( | 619 const ExtensionActionState* TabContents::GetPageActionState( |
| 627 const ExtensionAction* page_action) { | 620 const ExtensionAction* page_action) { |
| 628 if (enabled_page_actions_.end() == enabled_page_actions_.find(page_action)) | 621 if (page_actions_.end() == page_actions_.find(page_action)) |
| 629 return NULL; | 622 return NULL; |
| 630 | 623 |
| 631 return enabled_page_actions_[page_action].get(); | 624 return page_actions_[page_action].get(); |
| 625 } |
| 626 |
| 627 ExtensionActionState* TabContents::GetOrCreatePageActionState( |
| 628 const ExtensionAction* page_action) { |
| 629 if (page_actions_.end() == page_actions_.find(page_action)) { |
| 630 page_actions_[page_action].reset( |
| 631 new ExtensionActionState(page_action->title(), 0)); |
| 632 } |
| 633 |
| 634 return page_actions_[page_action].get(); |
| 635 } |
| 636 |
| 637 void TabContents::PageActionStateChanged() { |
| 638 NotifyNavigationStateChanged(TabContents::INVALIDATE_PAGE_ACTIONS); |
| 632 } | 639 } |
| 633 | 640 |
| 634 void TabContents::NotifyNavigationStateChanged(unsigned changed_flags) { | 641 void TabContents::NotifyNavigationStateChanged(unsigned changed_flags) { |
| 635 if (delegate_) | 642 if (delegate_) |
| 636 delegate_->NavigationStateChanged(this, changed_flags); | 643 delegate_->NavigationStateChanged(this, changed_flags); |
| 637 } | 644 } |
| 638 | 645 |
| 639 void TabContents::DidBecomeSelected() { | 646 void TabContents::DidBecomeSelected() { |
| 640 controller_.SetActive(true); | 647 controller_.SetActive(true); |
| 641 if (render_widget_host_view()) { | 648 if (render_widget_host_view()) { |
| (...skipping 751 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1393 // the commit. | 1400 // the commit. |
| 1394 GenerateKeywordIfNecessary(params); | 1401 GenerateKeywordIfNecessary(params); |
| 1395 | 1402 |
| 1396 // Allow the new page to set the title again. | 1403 // Allow the new page to set the title again. |
| 1397 received_page_title_ = false; | 1404 received_page_title_ = false; |
| 1398 | 1405 |
| 1399 // Get the favicon, either from history or request it from the net. | 1406 // Get the favicon, either from history or request it from the net. |
| 1400 fav_icon_helper_.FetchFavIcon(details.entry->url()); | 1407 fav_icon_helper_.FetchFavIcon(details.entry->url()); |
| 1401 | 1408 |
| 1402 // Disable all page actions, unless this is an in-page navigation. | 1409 // Disable all page actions, unless this is an in-page navigation. |
| 1403 if (!enabled_page_actions_.empty()) { | 1410 if (!page_actions_.empty()) { |
| 1404 url_canon::Replacements<char> replacements; | 1411 url_canon::Replacements<char> replacements; |
| 1405 replacements.ClearRef(); | 1412 replacements.ClearRef(); |
| 1406 if (params.url.ReplaceComponents(replacements) != | 1413 if (params.url.ReplaceComponents(replacements) != |
| 1407 params.referrer.ReplaceComponents(replacements)) { | 1414 params.referrer.ReplaceComponents(replacements)) { |
| 1408 enabled_page_actions_.clear(); | 1415 page_actions_.clear(); |
| 1409 } | 1416 } |
| 1410 } | 1417 } |
| 1411 | 1418 |
| 1412 // Close constrained popups if necessary. | 1419 // Close constrained popups if necessary. |
| 1413 MaybeCloseChildWindows(details.previous_url, details.entry->url()); | 1420 MaybeCloseChildWindows(details.previous_url, details.entry->url()); |
| 1414 | 1421 |
| 1415 // Update the starred state. | 1422 // Update the starred state. |
| 1416 UpdateStarredStateForCurrentURL(); | 1423 UpdateStarredStateForCurrentURL(); |
| 1417 } | 1424 } |
| 1418 | 1425 |
| (...skipping 1199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2618 #endif | 2625 #endif |
| 2619 | 2626 |
| 2620 default: | 2627 default: |
| 2621 NOTREACHED(); | 2628 NOTREACHED(); |
| 2622 } | 2629 } |
| 2623 } | 2630 } |
| 2624 | 2631 |
| 2625 void TabContents::set_encoding(const std::string& encoding) { | 2632 void TabContents::set_encoding(const std::string& encoding) { |
| 2626 encoding_ = CharacterEncoding::GetCanonicalEncodingNameByAliasName(encoding); | 2633 encoding_ = CharacterEncoding::GetCanonicalEncodingNameByAliasName(encoding); |
| 2627 } | 2634 } |
| 2628 | |
| OLD | NEW |