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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 #include "chrome/browser/tab_contents/interstitial_page.h" | 48 #include "chrome/browser/tab_contents/interstitial_page.h" |
49 #include "chrome/browser/tab_contents/navigation_entry.h" | 49 #include "chrome/browser/tab_contents/navigation_entry.h" |
50 #include "chrome/browser/tab_contents/provisional_load_details.h" | 50 #include "chrome/browser/tab_contents/provisional_load_details.h" |
51 #include "chrome/browser/tab_contents/tab_contents_delegate.h" | 51 #include "chrome/browser/tab_contents/tab_contents_delegate.h" |
52 #include "chrome/browser/tab_contents/tab_contents_view.h" | 52 #include "chrome/browser/tab_contents/tab_contents_view.h" |
53 #include "chrome/browser/tab_contents/thumbnail_generator.h" | 53 #include "chrome/browser/tab_contents/thumbnail_generator.h" |
54 #include "chrome/browser/thumbnail_store.h" | 54 #include "chrome/browser/thumbnail_store.h" |
55 #include "chrome/browser/search_engines/template_url_fetcher.h" | 55 #include "chrome/browser/search_engines/template_url_fetcher.h" |
56 #include "chrome/browser/search_engines/template_url_model.h" | 56 #include "chrome/browser/search_engines/template_url_model.h" |
57 #include "chrome/common/chrome_switches.h" | 57 #include "chrome/common/chrome_switches.h" |
58 #include "chrome/common/extensions/extension_action.h" | 58 #include "chrome/common/extensions/extension_action2.h" |
59 #include "chrome/common/notification_service.h" | 59 #include "chrome/common/notification_service.h" |
60 #include "chrome/common/pref_names.h" | 60 #include "chrome/common/pref_names.h" |
61 #include "chrome/common/pref_service.h" | 61 #include "chrome/common/pref_service.h" |
62 #include "chrome/common/render_messages.h" | 62 #include "chrome/common/render_messages.h" |
63 #include "chrome/common/renderer_preferences.h" | 63 #include "chrome/common/renderer_preferences.h" |
64 #include "chrome/common/url_constants.h" | 64 #include "chrome/common/url_constants.h" |
65 #include "grit/generated_resources.h" | 65 #include "grit/generated_resources.h" |
66 #include "grit/locale_settings.h" | 66 #include "grit/locale_settings.h" |
67 #include "net/base/mime_util.h" | 67 #include "net/base/mime_util.h" |
68 #include "net/base/net_errors.h" | 68 #include "net/base/net_errors.h" |
(...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
598 } | 598 } |
599 | 599 |
600 void TabContents::SetIsCrashed(bool state) { | 600 void TabContents::SetIsCrashed(bool state) { |
601 if (state == is_crashed_) | 601 if (state == is_crashed_) |
602 return; | 602 return; |
603 | 603 |
604 is_crashed_ = state; | 604 is_crashed_ = state; |
605 NotifyNavigationStateChanged(INVALIDATE_TAB); | 605 NotifyNavigationStateChanged(INVALIDATE_TAB); |
606 } | 606 } |
607 | 607 |
608 void TabContents::SetPageActionEnabled(const ExtensionAction* page_action, | |
609 bool enable, | |
610 const std::string& title, | |
611 int icon_id) { | |
612 DCHECK(page_action); | |
613 ExtensionActionState* state = GetOrCreatePageActionState(page_action); | |
614 state->set_hidden(!enable); | |
615 state->set_title(title); | |
616 state->set_icon_index(icon_id); | |
617 state->set_icon(NULL); | |
618 } | |
619 | |
620 const ExtensionActionState* TabContents::GetPageActionState( | |
621 const ExtensionAction* page_action) { | |
622 if (page_actions_.end() == page_actions_.find(page_action)) | |
623 return NULL; | |
624 | |
625 return page_actions_[page_action].get(); | |
626 } | |
627 | |
628 ExtensionActionState* TabContents::GetOrCreatePageActionState( | |
629 const ExtensionAction* page_action) { | |
630 if (page_actions_.end() == page_actions_.find(page_action)) { | |
631 page_actions_[page_action].reset( | |
632 new ExtensionActionState(page_action->title(), 0)); | |
633 } | |
634 | |
635 return page_actions_[page_action].get(); | |
636 } | |
637 | |
638 void TabContents::PageActionStateChanged() { | 608 void TabContents::PageActionStateChanged() { |
639 NotifyNavigationStateChanged(TabContents::INVALIDATE_PAGE_ACTIONS); | 609 NotifyNavigationStateChanged(TabContents::INVALIDATE_PAGE_ACTIONS); |
640 } | 610 } |
641 | 611 |
642 void TabContents::NotifyNavigationStateChanged(unsigned changed_flags) { | 612 void TabContents::NotifyNavigationStateChanged(unsigned changed_flags) { |
643 if (delegate_) | 613 if (delegate_) |
644 delegate_->NavigationStateChanged(this, changed_flags); | 614 delegate_->NavigationStateChanged(this, changed_flags); |
645 } | 615 } |
646 | 616 |
647 void TabContents::DidBecomeSelected() { | 617 void TabContents::DidBecomeSelected() { |
(...skipping 759 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1407 // The keyword generator uses the navigation entries, so must be called after | 1377 // The keyword generator uses the navigation entries, so must be called after |
1408 // the commit. | 1378 // the commit. |
1409 GenerateKeywordIfNecessary(params); | 1379 GenerateKeywordIfNecessary(params); |
1410 | 1380 |
1411 // Allow the new page to set the title again. | 1381 // Allow the new page to set the title again. |
1412 received_page_title_ = false; | 1382 received_page_title_ = false; |
1413 | 1383 |
1414 // Get the favicon, either from history or request it from the net. | 1384 // Get the favicon, either from history or request it from the net. |
1415 fav_icon_helper_.FetchFavIcon(details.entry->url()); | 1385 fav_icon_helper_.FetchFavIcon(details.entry->url()); |
1416 | 1386 |
1417 // Disable all page actions, unless this is an in-page navigation. | 1387 // Clear all page and browser action state for this tab, unless this is an |
| 1388 // in-page navigation. |
1418 url_canon::Replacements<char> replacements; | 1389 url_canon::Replacements<char> replacements; |
1419 replacements.ClearRef(); | 1390 replacements.ClearRef(); |
1420 if (params.url.ReplaceComponents(replacements) != | 1391 if (params.url.ReplaceComponents(replacements) != |
1421 params.referrer.ReplaceComponents(replacements)) { | 1392 params.referrer.ReplaceComponents(replacements)) { |
1422 if (!page_actions_.empty()) | |
1423 page_actions_.clear(); | |
1424 | |
1425 ExtensionsService* service = profile()->GetExtensionsService(); | 1393 ExtensionsService* service = profile()->GetExtensionsService(); |
1426 if (service) { | 1394 if (service) { |
1427 for (size_t i = 0; i < service->extensions()->size(); ++i) { | 1395 for (size_t i = 0; i < service->extensions()->size(); ++i) { |
1428 ExtensionAction2* action = | 1396 ExtensionAction2* browser_action = |
1429 service->extensions()->at(i)->browser_action(); | 1397 service->extensions()->at(i)->browser_action(); |
1430 if (!action) | 1398 if (browser_action) { |
1431 continue; | 1399 browser_action->ClearAllValuesForTab(controller().session_id().id()); |
| 1400 NotificationService::current()->Notify( |
| 1401 NotificationType::EXTENSION_BROWSER_ACTION_UPDATED, |
| 1402 Source<ExtensionAction2>(browser_action), |
| 1403 NotificationService::NoDetails()); |
| 1404 } |
1432 | 1405 |
1433 action->ClearAllValuesForTab(controller().session_id().id()); | 1406 ExtensionAction2* page_action = |
1434 NotificationService::current()->Notify( | 1407 service->extensions()->at(i)->page_action(); |
1435 NotificationType::EXTENSION_BROWSER_ACTION_UPDATED, | 1408 if (page_action) { |
1436 Source<ExtensionAction2>(action), | 1409 page_action->ClearAllValuesForTab(controller().session_id().id()); |
1437 NotificationService::NoDetails()); | 1410 PageActionStateChanged(); |
| 1411 } |
1438 } | 1412 } |
1439 } | 1413 } |
1440 } | 1414 } |
1441 | 1415 |
1442 // Close constrained popups if necessary. | 1416 // Close constrained popups if necessary. |
1443 MaybeCloseChildWindows(details.previous_url, details.entry->url()); | 1417 MaybeCloseChildWindows(details.previous_url, details.entry->url()); |
1444 | 1418 |
1445 // Update the starred state. | 1419 // Update the starred state. |
1446 UpdateStarredStateForCurrentURL(); | 1420 UpdateStarredStateForCurrentURL(); |
1447 } | 1421 } |
(...skipping 1202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2650 #endif | 2624 #endif |
2651 | 2625 |
2652 default: | 2626 default: |
2653 NOTREACHED(); | 2627 NOTREACHED(); |
2654 } | 2628 } |
2655 } | 2629 } |
2656 | 2630 |
2657 void TabContents::set_encoding(const std::string& encoding) { | 2631 void TabContents::set_encoding(const std::string& encoding) { |
2658 encoding_ = CharacterEncoding::GetCanonicalEncodingNameByAliasName(encoding); | 2632 encoding_ = CharacterEncoding::GetCanonicalEncodingNameByAliasName(encoding); |
2659 } | 2633 } |
OLD | NEW |