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/extensions/extension_page_actions_module.h" | 5 #include "chrome/browser/extensions/extension_page_actions_module.h" |
6 | 6 |
7 #include "chrome/browser/browser.h" | 7 #include "chrome/browser/browser.h" |
8 #include "chrome/browser/browser_list.h" | 8 #include "chrome/browser/browser_list.h" |
9 #include "chrome/browser/profile.h" | 9 #include "chrome/browser/profile.h" |
10 #include "chrome/browser/extensions/extension_page_actions_module_constants.h" | 10 #include "chrome/browser/extensions/extension_page_actions_module_constants.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 std::string page_action_id; | 24 std::string page_action_id; |
25 EXTENSION_FUNCTION_VALIDATE(args->GetString(0, &page_action_id)); | 25 EXTENSION_FUNCTION_VALIDATE(args->GetString(0, &page_action_id)); |
26 DictionaryValue* action; | 26 DictionaryValue* action; |
27 EXTENSION_FUNCTION_VALIDATE(args->GetDictionary(1, &action)); | 27 EXTENSION_FUNCTION_VALIDATE(args->GetDictionary(1, &action)); |
28 | 28 |
29 int tab_id; | 29 int tab_id; |
30 EXTENSION_FUNCTION_VALIDATE(action->GetInteger(keys::kTabIdKey, &tab_id)); | 30 EXTENSION_FUNCTION_VALIDATE(action->GetInteger(keys::kTabIdKey, &tab_id)); |
31 std::string url; | 31 std::string url; |
32 EXTENSION_FUNCTION_VALIDATE(action->GetString(keys::kUrlKey, &url)); | 32 EXTENSION_FUNCTION_VALIDATE(action->GetString(keys::kUrlKey, &url)); |
33 | 33 |
| 34 std::string title; |
| 35 int icon_id = 0; |
| 36 if (enable) { |
| 37 // Both of those are optional. |
| 38 if (action->HasKey(keys::kTitleKey)) |
| 39 EXTENSION_FUNCTION_VALIDATE(action->GetString(keys::kTitleKey, &title)); |
| 40 if (action->HasKey(keys::kIconIdKey)) { |
| 41 EXTENSION_FUNCTION_VALIDATE(action->GetInteger(keys::kIconIdKey, |
| 42 &icon_id)); |
| 43 } |
| 44 } |
| 45 |
34 // Find the TabContents that contains this tab id. | 46 // Find the TabContents that contains this tab id. |
35 TabContents* contents = NULL; | 47 TabContents* contents = NULL; |
36 ExtensionTabUtil::GetTabById(tab_id, profile(), NULL, NULL, &contents, NULL); | 48 ExtensionTabUtil::GetTabById(tab_id, profile(), NULL, NULL, &contents, NULL); |
37 if (!contents) { | 49 if (!contents) { |
38 error_ = ExtensionErrorUtils::FormatErrorMessage(keys::kNoTabError, | 50 error_ = ExtensionErrorUtils::FormatErrorMessage(keys::kNoTabError, |
39 IntToString(tab_id)); | 51 IntToString(tab_id)); |
40 return false; | 52 return false; |
41 } | 53 } |
42 | 54 |
43 // Make sure the URL hasn't changed. | 55 // Make sure the URL hasn't changed. |
(...skipping 15 matching lines...) Expand all Loading... |
59 } | 71 } |
60 | 72 |
61 const PageAction* page_action = extension->GetPageAction(page_action_id); | 73 const PageAction* page_action = extension->GetPageAction(page_action_id); |
62 if (!page_action) { | 74 if (!page_action) { |
63 error_ = ExtensionErrorUtils::FormatErrorMessage(keys::kNoPageActionError, | 75 error_ = ExtensionErrorUtils::FormatErrorMessage(keys::kNoPageActionError, |
64 page_action_id); | 76 page_action_id); |
65 return false; | 77 return false; |
66 } | 78 } |
67 | 79 |
68 // Set visibility and broadcast notifications that the UI should be updated. | 80 // Set visibility and broadcast notifications that the UI should be updated. |
69 contents->SetPageActionEnabled(page_action, enable); | 81 contents->SetPageActionEnabled(page_action, enable, title, icon_id); |
70 contents->NotifyNavigationStateChanged(TabContents::INVALIDATE_PAGE_ACTIONS); | 82 contents->NotifyNavigationStateChanged(TabContents::INVALIDATE_PAGE_ACTIONS); |
71 | 83 |
72 return true; | 84 return true; |
73 } | 85 } |
74 | 86 |
75 bool EnablePageActionFunction::RunImpl() { | 87 bool EnablePageActionFunction::RunImpl() { |
76 return SetPageActionEnabled(true); | 88 return SetPageActionEnabled(true); |
77 } | 89 } |
78 | 90 |
79 bool DisablePageActionFunction::RunImpl() { | 91 bool DisablePageActionFunction::RunImpl() { |
80 return SetPageActionEnabled(false); | 92 return SetPageActionEnabled(false); |
81 } | 93 } |
OLD | NEW |