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" | 21 #include "content/browser/tab_contents/tab_contents.h" |
22 #include "content/public/browser/navigation_entry.h" | 22 #include "content/public/browser/navigation_entry.h" |
23 | 23 |
| 24 using content::NavigationEntry; |
| 25 |
24 namespace keys = extension_page_actions_module_constants; | 26 namespace keys = extension_page_actions_module_constants; |
25 | 27 |
26 namespace { | 28 namespace { |
27 // Errors. | 29 // Errors. |
28 const char kNoTabError[] = "No tab with id: *."; | 30 const char kNoTabError[] = "No tab with id: *."; |
29 const char kNoPageActionError[] = | 31 const char kNoPageActionError[] = |
30 "This extension has no page action specified."; | 32 "This extension has no page action specified."; |
31 const char kUrlNotActiveError[] = "This url is no longer active: *."; | 33 const char kUrlNotActiveError[] = "This url is no longer active: *."; |
32 const char kIconIndexOutOfBounds[] = "Page action icon index out of bounds."; | 34 const char kIconIndexOutOfBounds[] = "Page action icon index out of bounds."; |
33 const char kNoIconSpecified[] = "Page action has no icons to show."; | 35 const char kNoIconSpecified[] = "Page action has no icons to show."; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 TabContentsWrapper* contents = NULL; | 75 TabContentsWrapper* contents = NULL; |
74 bool result = ExtensionTabUtil::GetTabById( | 76 bool result = ExtensionTabUtil::GetTabById( |
75 tab_id, profile(), include_incognito(), NULL, NULL, &contents, NULL); | 77 tab_id, profile(), include_incognito(), NULL, NULL, &contents, NULL); |
76 if (!result || !contents) { | 78 if (!result || !contents) { |
77 error_ = ExtensionErrorUtils::FormatErrorMessage( | 79 error_ = ExtensionErrorUtils::FormatErrorMessage( |
78 kNoTabError, base::IntToString(tab_id)); | 80 kNoTabError, base::IntToString(tab_id)); |
79 return false; | 81 return false; |
80 } | 82 } |
81 | 83 |
82 // Make sure the URL hasn't changed. | 84 // Make sure the URL hasn't changed. |
83 content::NavigationEntry* entry = | 85 NavigationEntry* entry = |
84 contents->tab_contents()->GetController().GetActiveEntry(); | 86 contents->tab_contents()->GetController().GetActiveEntry(); |
85 if (!entry || url != entry->GetURL().spec()) { | 87 if (!entry || url != entry->GetURL().spec()) { |
86 error_ = ExtensionErrorUtils::FormatErrorMessage(kUrlNotActiveError, url); | 88 error_ = ExtensionErrorUtils::FormatErrorMessage(kUrlNotActiveError, url); |
87 return false; | 89 return false; |
88 } | 90 } |
89 | 91 |
90 // Set visibility and broadcast notifications that the UI should be updated. | 92 // Set visibility and broadcast notifications that the UI should be updated. |
91 page_action->SetIsVisible(tab_id, enable); | 93 page_action->SetIsVisible(tab_id, enable); |
92 page_action->SetTitle(tab_id, title); | 94 page_action->SetTitle(tab_id, title); |
93 page_action->SetIconIndex(tab_id, icon_id); | 95 page_action->SetIconIndex(tab_id, icon_id); |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 if (!InitCommon(tab_id)) | 286 if (!InitCommon(tab_id)) |
285 return false; | 287 return false; |
286 | 288 |
287 std::string text; | 289 std::string text; |
288 EXTENSION_FUNCTION_VALIDATE(args->GetString("text", &text)); | 290 EXTENSION_FUNCTION_VALIDATE(args->GetString("text", &text)); |
289 | 291 |
290 page_action_->SetBadgeText(tab_id, text); | 292 page_action_->SetBadgeText(tab_id, text); |
291 contents_->extension_tab_helper()->PageActionStateChanged(); | 293 contents_->extension_tab_helper()->PageActionStateChanged(); |
292 return true; | 294 return true; |
293 } | 295 } |
OLD | NEW |