| 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/extension_action_runner.h" | 7 #include "chrome/browser/extensions/extension_action_runner.h" |
| 8 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
| 9 #include "content/public/browser/navigation_details.h" | |
| 10 #include "content/public/browser/navigation_entry.h" | 9 #include "content/public/browser/navigation_entry.h" |
| 10 #include "content/public/browser/navigation_handle.h" |
| 11 #include "content/public/browser/render_frame_host.h" | 11 #include "content/public/browser/render_frame_host.h" |
| 12 #include "content/public/browser/render_process_host.h" | 12 #include "content/public/browser/render_process_host.h" |
| 13 #include "content/public/browser/web_contents.h" | 13 #include "content/public/browser/web_contents.h" |
| 14 #include "extensions/browser/extension_registry.h" | 14 #include "extensions/browser/extension_registry.h" |
| 15 #include "extensions/browser/process_manager.h" | 15 #include "extensions/browser/process_manager.h" |
| 16 #include "extensions/common/extension_messages.h" | 16 #include "extensions/common/extension_messages.h" |
| 17 #include "extensions/common/feature_switch.h" | 17 #include "extensions/common/feature_switch.h" |
| 18 #include "extensions/common/permissions/permission_set.h" | 18 #include "extensions/common/permissions/permission_set.h" |
| 19 #include "extensions/common/permissions/permissions_data.h" | 19 #include "extensions/common/permissions/permissions_data.h" |
| 20 #include "extensions/common/user_script.h" | 20 #include "extensions/common/user_script.h" |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 ExtensionActionRunner::GetForWebContents(web_contents()) | 132 ExtensionActionRunner::GetForWebContents(web_contents()) |
| 133 ->OnActiveTabPermissionGranted(extension); | 133 ->OnActiveTabPermissionGranted(extension); |
| 134 } | 134 } |
| 135 } | 135 } |
| 136 } | 136 } |
| 137 | 137 |
| 138 void ActiveTabPermissionGranter::RevokeForTesting() { | 138 void ActiveTabPermissionGranter::RevokeForTesting() { |
| 139 ClearActiveExtensionsAndNotify(); | 139 ClearActiveExtensionsAndNotify(); |
| 140 } | 140 } |
| 141 | 141 |
| 142 void ActiveTabPermissionGranter::DidNavigateMainFrame( | 142 void ActiveTabPermissionGranter::DidFinishNavigation( |
| 143 const content::LoadCommittedDetails& details, | 143 content::NavigationHandle* navigation_handle) { |
| 144 const content::FrameNavigateParams& params) { | 144 // Important: sub-frames don't get granted! |
| 145 if (details.is_in_page) | 145 if (!navigation_handle->IsInMainFrame() || |
| 146 !navigation_handle->HasCommitted() || |
| 147 navigation_handle->IsSamePage()) { |
| 146 return; | 148 return; |
| 147 DCHECK(details.is_main_frame); // important: sub-frames don't get granted! | 149 } |
| 148 | 150 |
| 149 // Only clear the granted permissions for cross-origin navigations. | 151 // Only clear the granted permissions for cross-origin navigations. |
| 150 // | 152 // |
| 151 // See http://crbug.com/404243 for why. Currently we only differentiate | 153 // See http://crbug.com/404243 for why. Currently we only differentiate |
| 152 // between same-origin and cross-origin navigations when the | 154 // between same-origin and cross-origin navigations when the |
| 153 // script-require-action flag is on. It's not clear it's good for general | 155 // script-require-action flag is on. It's not clear it's good for general |
| 154 // activeTab consumption (we likely need to build some UI around it first). | 156 // activeTab consumption (we likely need to build some UI around it first). |
| 155 // However, the scripts-require-action feature is all-but unusable without | 157 // However, the scripts-require-action feature is all-but unusable without |
| 156 // this behaviour. | 158 // this behaviour. |
| 157 if (FeatureSwitch::scripts_require_action()->IsEnabled()) { | 159 if (FeatureSwitch::scripts_require_action()->IsEnabled()) { |
| 158 const content::NavigationEntry* navigation_entry = | 160 const content::NavigationEntry* navigation_entry = |
| 159 web_contents()->GetController().GetVisibleEntry(); | 161 web_contents()->GetController().GetVisibleEntry(); |
| 160 if (!navigation_entry || (navigation_entry->GetURL().GetOrigin() != | 162 if (!navigation_entry || |
| 161 details.previous_url.GetOrigin())) { | 163 (navigation_entry->GetURL().GetOrigin() != |
| 164 navigation_handle->GetPreviousURL().GetOrigin())) { |
| 162 ClearActiveExtensionsAndNotify(); | 165 ClearActiveExtensionsAndNotify(); |
| 163 } | 166 } |
| 164 } else { | 167 } else { |
| 165 ClearActiveExtensionsAndNotify(); | 168 ClearActiveExtensionsAndNotify(); |
| 166 } | 169 } |
| 167 } | 170 } |
| 168 | 171 |
| 169 void ActiveTabPermissionGranter::WebContentsDestroyed() { | 172 void ActiveTabPermissionGranter::WebContentsDestroyed() { |
| 170 ClearActiveExtensionsAndNotify(); | 173 ClearActiveExtensionsAndNotify(); |
| 171 } | 174 } |
| (...skipping 27 matching lines...) Expand all Loading... |
| 199 CreateMessageFunction clear_message = | 202 CreateMessageFunction clear_message = |
| 200 base::Bind(&CreateClearMessage, extension_ids, tab_id_); | 203 base::Bind(&CreateClearMessage, extension_ids, tab_id_); |
| 201 SendMessageToProcesses(frame_hosts, | 204 SendMessageToProcesses(frame_hosts, |
| 202 web_contents()->GetRenderProcessHost(), | 205 web_contents()->GetRenderProcessHost(), |
| 203 clear_message); | 206 clear_message); |
| 204 | 207 |
| 205 granted_extensions_.Clear(); | 208 granted_extensions_.Clear(); |
| 206 } | 209 } |
| 207 | 210 |
| 208 } // namespace extensions | 211 } // namespace extensions |
| OLD | NEW |