Chromium Code Reviews| 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/active_tab_permission_granter.h" | 5 #include "chrome/browser/extensions/active_tab_permission_granter.h" |
| 6 | 6 |
| 7 #include "chrome/browser/extensions/active_script_controller.h" | 7 #include "chrome/browser/extensions/active_script_controller.h" |
| 8 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
| 9 #include "content/public/browser/navigation_details.h" | 9 #include "content/public/browser/navigation_details.h" |
| 10 #include "content/public/browser/navigation_entry.h" | 10 #include "content/public/browser/navigation_entry.h" |
| 11 #include "content/public/browser/render_process_host.h" | |
| 11 #include "content/public/browser/render_view_host.h" | 12 #include "content/public/browser/render_view_host.h" |
| 12 #include "content/public/browser/web_contents.h" | 13 #include "content/public/browser/web_contents.h" |
| 14 #include "extensions/browser/extension_host.h" | |
| 13 #include "extensions/browser/extension_registry.h" | 15 #include "extensions/browser/extension_registry.h" |
| 16 #include "extensions/browser/process_manager.h" | |
| 14 #include "extensions/common/extension_messages.h" | 17 #include "extensions/common/extension_messages.h" |
| 15 #include "extensions/common/feature_switch.h" | 18 #include "extensions/common/feature_switch.h" |
| 16 #include "extensions/common/permissions/permission_set.h" | 19 #include "extensions/common/permissions/permission_set.h" |
| 17 #include "extensions/common/permissions/permissions_data.h" | 20 #include "extensions/common/permissions/permissions_data.h" |
| 18 #include "extensions/common/user_script.h" | 21 #include "extensions/common/user_script.h" |
| 19 #include "url/gurl.h" | 22 #include "url/gurl.h" |
| 20 | 23 |
| 21 using content::RenderProcessHost; | 24 using content::RenderProcessHost; |
| 22 using content::WebContentsObserver; | 25 using content::WebContentsObserver; |
| 23 | 26 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 59 | 62 |
| 60 if (!new_apis.empty() || !new_hosts.is_empty()) { | 63 if (!new_apis.empty() || !new_hosts.is_empty()) { |
| 61 granted_extensions_.Insert(extension); | 64 granted_extensions_.Insert(extension); |
| 62 scoped_refptr<const PermissionSet> new_permissions = | 65 scoped_refptr<const PermissionSet> new_permissions = |
| 63 new PermissionSet(new_apis, ManifestPermissionSet(), | 66 new PermissionSet(new_apis, ManifestPermissionSet(), |
| 64 new_hosts, URLPatternSet()); | 67 new_hosts, URLPatternSet()); |
| 65 permissions_data->UpdateTabSpecificPermissions(tab_id_, new_permissions); | 68 permissions_data->UpdateTabSpecificPermissions(tab_id_, new_permissions); |
| 66 const content::NavigationEntry* navigation_entry = | 69 const content::NavigationEntry* navigation_entry = |
| 67 web_contents()->GetController().GetVisibleEntry(); | 70 web_contents()->GetController().GetVisibleEntry(); |
| 68 if (navigation_entry) { | 71 if (navigation_entry) { |
| 69 content::RenderViewHost* render_view_host = | 72 std::set<content::RenderProcessHost*> hosts; |
| 70 web_contents()->GetRenderViewHost(); | 73 // We update the tabs renderer, as well as the extension's background page |
| 71 render_view_host->Send(new ExtensionMsg_UpdateTabSpecificPermissions( | 74 // if one exists. |
| 72 render_view_host->GetRoutingID(), | 75 hosts.insert(web_contents()->GetRenderProcessHost()); |
| 73 navigation_entry->GetURL(), | 76 ExtensionHost* background_page = |
| 74 extension->id(), | 77 ProcessManager::Get(web_contents()->GetBrowserContext())-> |
| 75 new_hosts)); | 78 GetBackgroundHostForExtension(extension->id()); |
|
not at google - send to devlin
2015/02/03 19:29:12
What about if the event page hasn't started yet? F
Devlin
2015/02/04 22:26:02
Good point. Done.
| |
| 79 if (background_page) | |
| 80 hosts.insert(background_page->render_process_host()); | |
| 81 | |
| 82 for (content::RenderProcessHost* host : hosts) { | |
| 83 host->Send(new ExtensionMsg_UpdateTabSpecificPermissions( | |
| 84 navigation_entry->GetURL(), | |
| 85 extension->id(), | |
| 86 new_hosts, | |
| 87 tab_id_)); | |
| 88 } | |
| 89 | |
| 76 // If more things ever need to know about this, we should consider making | 90 // If more things ever need to know about this, we should consider making |
| 77 // an observer class. | 91 // an observer class. |
| 78 // It's important that this comes after the IPC is sent to the renderer, | 92 // It's important that this comes after the IPC is sent to the renderer, |
| 79 // so that any tasks executing in the renderer occur after it has the | 93 // so that any tasks executing in the renderer occur after it has the |
| 80 // updated permissions. | 94 // updated permissions. |
| 81 ActiveScriptController::GetForWebContents(web_contents()) | 95 ActiveScriptController::GetForWebContents(web_contents()) |
| 82 ->OnActiveTabPermissionGranted(extension); | 96 ->OnActiveTabPermissionGranted(extension); |
| 83 } | 97 } |
| 84 } | 98 } |
| 85 } | 99 } |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 122 // Note: don't need to clear the permissions (nor tell the renderer about it) | 136 // Note: don't need to clear the permissions (nor tell the renderer about it) |
| 123 // because it's being unloaded anyway. | 137 // because it's being unloaded anyway. |
| 124 granted_extensions_.Remove(extension->id()); | 138 granted_extensions_.Remove(extension->id()); |
| 125 } | 139 } |
| 126 | 140 |
| 127 void ActiveTabPermissionGranter::ClearActiveExtensionsAndNotify() { | 141 void ActiveTabPermissionGranter::ClearActiveExtensionsAndNotify() { |
| 128 if (granted_extensions_.is_empty()) | 142 if (granted_extensions_.is_empty()) |
| 129 return; | 143 return; |
| 130 | 144 |
| 131 std::vector<std::string> extension_ids; | 145 std::vector<std::string> extension_ids; |
| 146 std::set<content::RenderProcessHost*> hosts; | |
| 147 hosts.insert(web_contents()->GetRenderProcessHost()); | |
| 132 | 148 |
| 149 ProcessManager* process_manager = | |
| 150 ProcessManager::Get(web_contents()->GetBrowserContext()); | |
| 133 for (ExtensionSet::const_iterator it = granted_extensions_.begin(); | 151 for (ExtensionSet::const_iterator it = granted_extensions_.begin(); |
| 134 it != granted_extensions_.end(); ++it) { | 152 it != granted_extensions_.end(); ++it) { |
| 135 it->get()->permissions_data()->ClearTabSpecificPermissions(tab_id_); | 153 it->get()->permissions_data()->ClearTabSpecificPermissions(tab_id_); |
| 136 extension_ids.push_back((*it)->id()); | 154 extension_ids.push_back((*it)->id()); |
| 155 ExtensionHost* background_page = | |
| 156 process_manager->GetBackgroundHostForExtension(it->get()->id()); | |
| 157 if (background_page) | |
| 158 hosts.insert(background_page->render_process_host()); | |
| 137 } | 159 } |
| 138 | 160 |
| 139 content::RenderViewHost* render_view_host = | 161 // Notify the tab and any extension background pages. |
| 140 web_contents()->GetRenderViewHost(); | 162 for (content::RenderProcessHost* host : hosts) { |
| 141 render_view_host->Send(new ExtensionMsg_ClearTabSpecificPermissions( | 163 host->Send(new ExtensionMsg_ClearTabSpecificPermissions( |
| 142 render_view_host->GetRoutingID(), extension_ids)); | 164 extension_ids, tab_id_)); |
| 165 } | |
| 143 granted_extensions_.Clear(); | 166 granted_extensions_.Clear(); |
| 144 } | 167 } |
| 145 | 168 |
| 146 } // namespace extensions | 169 } // namespace extensions |
| OLD | NEW |