OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/api/declarative_content/content_action.h" | 5 #include "chrome/browser/extensions/api/declarative_content/content_action.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 | 8 |
9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
11 #include "base/values.h" | 11 #include "base/values.h" |
12 #include "chrome/browser/extensions/api/declarative_content/content_constants.h" | 12 #include "chrome/browser/extensions/api/declarative_content/content_constants.h" |
13 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h" | 13 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h" |
14 #include "chrome/browser/extensions/extension_action.h" | 14 #include "chrome/browser/extensions/extension_action.h" |
15 #include "chrome/browser/extensions/extension_action_manager.h" | 15 #include "chrome/browser/extensions/extension_action_manager.h" |
16 #include "chrome/browser/extensions/extension_tab_util.h" | 16 #include "chrome/browser/extensions/extension_tab_util.h" |
17 #include "chrome/browser/profiles/profile.h" | |
18 #include "chrome/browser/sessions/session_tab_helper.h" | 17 #include "chrome/browser/sessions/session_tab_helper.h" |
19 #include "content/public/browser/invalidate_type.h" | 18 #include "content/public/browser/invalidate_type.h" |
20 #include "content/public/browser/render_view_host.h" | 19 #include "content/public/browser/render_view_host.h" |
21 #include "content/public/browser/web_contents.h" | 20 #include "content/public/browser/web_contents.h" |
22 #include "extensions/browser/extension_registry.h" | 21 #include "extensions/browser/extension_registry.h" |
23 #include "extensions/browser/extension_system.h" | 22 #include "extensions/browser/extension_system.h" |
24 #include "extensions/common/extension.h" | 23 #include "extensions/common/extension.h" |
25 #include "extensions/common/extension_messages.h" | 24 #include "extensions/common/extension_messages.h" |
26 | 25 |
27 namespace extensions { | 26 namespace extensions { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 return scoped_refptr<ContentAction>(); | 63 return scoped_refptr<ContentAction>(); |
65 } | 64 } |
66 return scoped_refptr<ContentAction>(new ShowPageAction); | 65 return scoped_refptr<ContentAction>(new ShowPageAction); |
67 } | 66 } |
68 | 67 |
69 // Implementation of ContentAction: | 68 // Implementation of ContentAction: |
70 virtual Type GetType() const OVERRIDE { return ACTION_SHOW_PAGE_ACTION; } | 69 virtual Type GetType() const OVERRIDE { return ACTION_SHOW_PAGE_ACTION; } |
71 virtual void Apply(const std::string& extension_id, | 70 virtual void Apply(const std::string& extension_id, |
72 const base::Time& extension_install_time, | 71 const base::Time& extension_install_time, |
73 ApplyInfo* apply_info) const OVERRIDE { | 72 ApplyInfo* apply_info) const OVERRIDE { |
74 ExtensionAction* action = GetPageAction(apply_info->profile, extension_id); | 73 ExtensionAction* action = |
| 74 GetPageAction(apply_info->browser_context, extension_id); |
75 action->DeclarativeShow(ExtensionTabUtil::GetTabId(apply_info->tab)); | 75 action->DeclarativeShow(ExtensionTabUtil::GetTabId(apply_info->tab)); |
76 ExtensionActionAPI::Get(apply_info->profile)->NotifyChange( | 76 ExtensionActionAPI::Get(apply_info->browser_context)->NotifyChange( |
77 action, apply_info->tab, apply_info->profile); | 77 action, apply_info->tab, apply_info->browser_context); |
78 } | 78 } |
79 // The page action is already showing, so nothing needs to be done here. | 79 // The page action is already showing, so nothing needs to be done here. |
80 virtual void Reapply(const std::string& extension_id, | 80 virtual void Reapply(const std::string& extension_id, |
81 const base::Time& extension_install_time, | 81 const base::Time& extension_install_time, |
82 ApplyInfo* apply_info) const OVERRIDE {} | 82 ApplyInfo* apply_info) const OVERRIDE {} |
83 virtual void Revert(const std::string& extension_id, | 83 virtual void Revert(const std::string& extension_id, |
84 const base::Time& extension_install_time, | 84 const base::Time& extension_install_time, |
85 ApplyInfo* apply_info) const OVERRIDE { | 85 ApplyInfo* apply_info) const OVERRIDE { |
86 if (ExtensionAction* action = | 86 if (ExtensionAction* action = |
87 GetPageAction(apply_info->profile, extension_id)) { | 87 GetPageAction(apply_info->browser_context, extension_id)) { |
88 action->UndoDeclarativeShow(ExtensionTabUtil::GetTabId(apply_info->tab)); | 88 action->UndoDeclarativeShow(ExtensionTabUtil::GetTabId(apply_info->tab)); |
89 ExtensionActionAPI::Get(apply_info->profile)->NotifyChange( | 89 ExtensionActionAPI::Get(apply_info->browser_context)->NotifyChange( |
90 action, apply_info->tab, apply_info->profile); | 90 action, apply_info->tab, apply_info->browser_context); |
91 } | 91 } |
92 } | 92 } |
93 | 93 |
94 private: | 94 private: |
95 static ExtensionAction* GetPageAction(Profile* profile, | 95 static ExtensionAction* GetPageAction( |
96 const std::string& extension_id) { | 96 content::BrowserContext* browser_context, |
| 97 const std::string& extension_id) { |
97 const Extension* extension = | 98 const Extension* extension = |
98 ExtensionRegistry::Get(profile) | 99 ExtensionRegistry::Get(browser_context) |
99 ->GetExtensionById(extension_id, ExtensionRegistry::EVERYTHING); | 100 ->GetExtensionById(extension_id, ExtensionRegistry::EVERYTHING); |
100 if (!extension) | 101 if (!extension) |
101 return NULL; | 102 return NULL; |
102 return ExtensionActionManager::Get(profile)->GetPageAction(*extension); | 103 return ExtensionActionManager::Get(browser_context) |
| 104 ->GetPageAction(*extension); |
103 } | 105 } |
104 virtual ~ShowPageAction() {} | 106 virtual ~ShowPageAction() {} |
105 | 107 |
106 DISALLOW_COPY_AND_ASSIGN(ShowPageAction); | 108 DISALLOW_COPY_AND_ASSIGN(ShowPageAction); |
107 }; | 109 }; |
108 | 110 |
109 // Helper for getting JS collections into C++. | 111 // Helper for getting JS collections into C++. |
110 static bool AppendJSStringsToCPPStrings(const base::ListValue& append_strings, | 112 static bool AppendJSStringsToCPPStrings(const base::ListValue& append_strings, |
111 std::vector<std::string>* append_to) { | 113 std::vector<std::string>* append_to) { |
112 for (base::ListValue::const_iterator it = append_strings.begin(); | 114 for (base::ListValue::const_iterator it = append_strings.begin(); |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
379 bool* bad_message, | 381 bool* bad_message, |
380 const base::DictionaryValue** action_dict, | 382 const base::DictionaryValue** action_dict, |
381 std::string* instance_type) { | 383 std::string* instance_type) { |
382 INPUT_FORMAT_VALIDATE(json_action.GetAsDictionary(action_dict)); | 384 INPUT_FORMAT_VALIDATE(json_action.GetAsDictionary(action_dict)); |
383 INPUT_FORMAT_VALIDATE( | 385 INPUT_FORMAT_VALIDATE( |
384 (*action_dict)->GetString(keys::kInstanceType, instance_type)); | 386 (*action_dict)->GetString(keys::kInstanceType, instance_type)); |
385 return true; | 387 return true; |
386 } | 388 } |
387 | 389 |
388 } // namespace extensions | 390 } // namespace extensions |
OLD | NEW |