| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/extensions/extension_page_actions_module.h" | 5 #include "chrome/browser/extensions/extension_page_actions_module.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
| 10 #include "chrome/browser/extensions/extension_page_actions_module_constants.h" | 10 #include "chrome/browser/extensions/extension_page_actions_module_constants.h" |
| 11 #include "chrome/browser/extensions/extension_service.h" | 11 #include "chrome/browser/extensions/extension_service.h" |
| 12 #include "chrome/browser/extensions/extension_tab_helper.h" | 12 #include "chrome/browser/extensions/extension_tab_helper.h" |
| 13 #include "chrome/browser/extensions/extension_tab_util.h" | 13 #include "chrome/browser/extensions/extension_tab_util.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/ui/browser_list.h" | 15 #include "chrome/browser/ui/browser_list.h" |
| 16 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 16 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 17 #include "chrome/common/extensions/extension.h" | 17 #include "chrome/common/extensions/extension.h" |
| 18 #include "chrome/common/extensions/extension_action.h" | 18 #include "chrome/common/extensions/extension_action.h" |
| 19 #include "chrome/common/extensions/extension_error_utils.h" | 19 #include "chrome/common/extensions/extension_error_utils.h" |
| 20 #include "chrome/common/render_messages.h" | 20 #include "chrome/common/render_messages.h" |
| 21 #include "content/browser/tab_contents/tab_contents.h" | |
| 22 #include "content/public/browser/navigation_entry.h" | 21 #include "content/public/browser/navigation_entry.h" |
| 22 #include "content/public/browser/web_contents.h" |
| 23 | 23 |
| 24 using content::NavigationEntry; | 24 using content::NavigationEntry; |
| 25 | 25 |
| 26 namespace keys = extension_page_actions_module_constants; | 26 namespace keys = extension_page_actions_module_constants; |
| 27 | 27 |
| 28 namespace { | 28 namespace { |
| 29 // Errors. | 29 // Errors. |
| 30 const char kNoTabError[] = "No tab with id: *."; | 30 const char kNoTabError[] = "No tab with id: *."; |
| 31 const char kNoPageActionError[] = | 31 const char kNoPageActionError[] = |
| 32 "This extension has no page action specified."; | 32 "This extension has no page action specified."; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 bool result = ExtensionTabUtil::GetTabById( | 76 bool result = ExtensionTabUtil::GetTabById( |
| 77 tab_id, profile(), include_incognito(), NULL, NULL, &contents, NULL); | 77 tab_id, profile(), include_incognito(), NULL, NULL, &contents, NULL); |
| 78 if (!result || !contents) { | 78 if (!result || !contents) { |
| 79 error_ = ExtensionErrorUtils::FormatErrorMessage( | 79 error_ = ExtensionErrorUtils::FormatErrorMessage( |
| 80 kNoTabError, base::IntToString(tab_id)); | 80 kNoTabError, base::IntToString(tab_id)); |
| 81 return false; | 81 return false; |
| 82 } | 82 } |
| 83 | 83 |
| 84 // Make sure the URL hasn't changed. | 84 // Make sure the URL hasn't changed. |
| 85 NavigationEntry* entry = | 85 NavigationEntry* entry = |
| 86 contents->tab_contents()->GetController().GetActiveEntry(); | 86 contents->web_contents()->GetController().GetActiveEntry(); |
| 87 if (!entry || url != entry->GetURL().spec()) { | 87 if (!entry || url != entry->GetURL().spec()) { |
| 88 error_ = ExtensionErrorUtils::FormatErrorMessage(kUrlNotActiveError, url); | 88 error_ = ExtensionErrorUtils::FormatErrorMessage(kUrlNotActiveError, url); |
| 89 return false; | 89 return false; |
| 90 } | 90 } |
| 91 | 91 |
| 92 // Set visibility and broadcast notifications that the UI should be updated. | 92 // Set visibility and broadcast notifications that the UI should be updated. |
| 93 page_action->SetIsVisible(tab_id, enable); | 93 page_action->SetIsVisible(tab_id, enable); |
| 94 page_action->SetTitle(tab_id, title); | 94 page_action->SetTitle(tab_id, title); |
| 95 page_action->SetIconIndex(tab_id, icon_id); | 95 page_action->SetIconIndex(tab_id, icon_id); |
| 96 contents->extension_tab_helper()->PageActionStateChanged(); | 96 contents->extension_tab_helper()->PageActionStateChanged(); |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 if (!InitCommon(tab_id)) | 286 if (!InitCommon(tab_id)) |
| 287 return false; | 287 return false; |
| 288 | 288 |
| 289 std::string text; | 289 std::string text; |
| 290 EXTENSION_FUNCTION_VALIDATE(args->GetString("text", &text)); | 290 EXTENSION_FUNCTION_VALIDATE(args->GetString("text", &text)); |
| 291 | 291 |
| 292 page_action_->SetBadgeText(tab_id, text); | 292 page_action_->SetBadgeText(tab_id, text); |
| 293 contents_->extension_tab_helper()->PageActionStateChanged(); | 293 contents_->extension_tab_helper()->PageActionStateChanged(); |
| 294 return true; | 294 return true; |
| 295 } | 295 } |
| OLD | NEW |