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/tab_helper.h" | 5 #include "chrome/browser/extensions/tab_helper.h" |
6 | 6 |
7 #include "chrome/browser/extensions/activity_log.h" | 7 #include "chrome/browser/extensions/activity_log.h" |
| 8 #include "chrome/browser/extensions/api/declarative/rules_registry_service.h" |
| 9 #include "chrome/browser/extensions/api/declarative_content/content_rules_regist
ry.h" |
8 #include "chrome/browser/extensions/app_notify_channel_ui.h" | 10 #include "chrome/browser/extensions/app_notify_channel_ui.h" |
9 #include "chrome/browser/extensions/crx_installer.h" | 11 #include "chrome/browser/extensions/crx_installer.h" |
10 #include "chrome/browser/extensions/extension_action.h" | 12 #include "chrome/browser/extensions/extension_action.h" |
11 #include "chrome/browser/extensions/extension_action_manager.h" | 13 #include "chrome/browser/extensions/extension_action_manager.h" |
12 #include "chrome/browser/extensions/extension_service.h" | 14 #include "chrome/browser/extensions/extension_service.h" |
| 15 #include "chrome/browser/extensions/extension_system.h" |
13 #include "chrome/browser/extensions/extension_tab_util.h" | 16 #include "chrome/browser/extensions/extension_tab_util.h" |
14 #include "chrome/browser/extensions/page_action_controller.h" | 17 #include "chrome/browser/extensions/page_action_controller.h" |
15 #include "chrome/browser/extensions/script_badge_controller.h" | 18 #include "chrome/browser/extensions/script_badge_controller.h" |
16 #include "chrome/browser/extensions/script_bubble_controller.h" | 19 #include "chrome/browser/extensions/script_bubble_controller.h" |
17 #include "chrome/browser/extensions/script_executor.h" | 20 #include "chrome/browser/extensions/script_executor.h" |
18 #include "chrome/browser/extensions/webstore_standalone_installer.h" | 21 #include "chrome/browser/extensions/webstore_standalone_installer.h" |
19 #include "chrome/browser/profiles/profile.h" | 22 #include "chrome/browser/profiles/profile.h" |
20 #include "chrome/browser/sessions/session_id.h" | 23 #include "chrome/browser/sessions/session_id.h" |
21 #include "chrome/browser/sessions/session_tab_helper.h" | 24 #include "chrome/browser/sessions/session_tab_helper.h" |
22 #include "chrome/browser/ui/browser_dialogs.h" | 25 #include "chrome/browser/ui/browser_dialogs.h" |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 | 78 |
76 TabHelper::TabHelper(content::WebContents* web_contents) | 79 TabHelper::TabHelper(content::WebContents* web_contents) |
77 : content::WebContentsObserver(web_contents), | 80 : content::WebContentsObserver(web_contents), |
78 extension_app_(NULL), | 81 extension_app_(NULL), |
79 ALLOW_THIS_IN_INITIALIZER_LIST( | 82 ALLOW_THIS_IN_INITIALIZER_LIST( |
80 extension_function_dispatcher_( | 83 extension_function_dispatcher_( |
81 Profile::FromBrowserContext(web_contents->GetBrowserContext()), | 84 Profile::FromBrowserContext(web_contents->GetBrowserContext()), |
82 this)), | 85 this)), |
83 pending_web_app_action_(NONE), | 86 pending_web_app_action_(NONE), |
84 script_executor_(new ScriptExecutor(web_contents, | 87 script_executor_(new ScriptExecutor(web_contents, |
85 &script_execution_observers_)) { | 88 &script_execution_observers_)), |
| 89 rules_registry_service_( |
| 90 ExtensionSystem::Get( |
| 91 Profile::FromBrowserContext(web_contents->GetBrowserContext()))-> |
| 92 rules_registry_service()) { |
86 // The ActiveTabPermissionManager requires a session ID; ensure this | 93 // The ActiveTabPermissionManager requires a session ID; ensure this |
87 // WebContents has one. | 94 // WebContents has one. |
88 SessionTabHelper::CreateForWebContents(web_contents); | 95 SessionTabHelper::CreateForWebContents(web_contents); |
89 active_tab_permission_granter_.reset(new ActiveTabPermissionGranter( | 96 active_tab_permission_granter_.reset(new ActiveTabPermissionGranter( |
90 web_contents, | 97 web_contents, |
91 SessionID::IdForTab(web_contents), | 98 SessionID::IdForTab(web_contents), |
92 Profile::FromBrowserContext(web_contents->GetBrowserContext()))); | 99 Profile::FromBrowserContext(web_contents->GetBrowserContext()))); |
93 if (FeatureSwitch::script_badges()->IsEnabled()) { | 100 if (FeatureSwitch::script_badges()->IsEnabled()) { |
94 location_bar_controller_.reset( | 101 location_bar_controller_.reset( |
95 new ScriptBadgeController(web_contents, this)); | 102 new ScriptBadgeController(web_contents, this)); |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 | 186 |
180 void TabHelper::RenderViewCreated(RenderViewHost* render_view_host) { | 187 void TabHelper::RenderViewCreated(RenderViewHost* render_view_host) { |
181 render_view_host->Send( | 188 render_view_host->Send( |
182 new ExtensionMsg_SetTabId(render_view_host->GetRoutingID(), | 189 new ExtensionMsg_SetTabId(render_view_host->GetRoutingID(), |
183 SessionID::IdForTab(web_contents()))); | 190 SessionID::IdForTab(web_contents()))); |
184 } | 191 } |
185 | 192 |
186 void TabHelper::DidNavigateMainFrame( | 193 void TabHelper::DidNavigateMainFrame( |
187 const content::LoadCommittedDetails& details, | 194 const content::LoadCommittedDetails& details, |
188 const content::FrameNavigateParams& params) { | 195 const content::FrameNavigateParams& params) { |
| 196 if (rules_registry_service_) { |
| 197 rules_registry_service_->content_rules_registry()->DidNavigateMainFrame( |
| 198 web_contents(), details, params); |
| 199 } |
| 200 |
189 if (details.is_in_page) | 201 if (details.is_in_page) |
190 return; | 202 return; |
191 | 203 |
192 Profile* profile = | 204 Profile* profile = |
193 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); | 205 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
194 ExtensionService* service = profile->GetExtensionService(); | 206 ExtensionService* service = profile->GetExtensionService(); |
195 if (!service) | 207 if (!service) |
196 return; | 208 return; |
197 | 209 |
198 ExtensionActionManager* extension_action_manager = | 210 ExtensionActionManager* extension_action_manager = |
(...skipping 21 matching lines...) Expand all Loading... |
220 OnInstallApplication) | 232 OnInstallApplication) |
221 IPC_MESSAGE_HANDLER(ExtensionHostMsg_InlineWebstoreInstall, | 233 IPC_MESSAGE_HANDLER(ExtensionHostMsg_InlineWebstoreInstall, |
222 OnInlineWebstoreInstall) | 234 OnInlineWebstoreInstall) |
223 IPC_MESSAGE_HANDLER(ExtensionHostMsg_GetAppNotifyChannel, | 235 IPC_MESSAGE_HANDLER(ExtensionHostMsg_GetAppNotifyChannel, |
224 OnGetAppNotifyChannel) | 236 OnGetAppNotifyChannel) |
225 IPC_MESSAGE_HANDLER(ExtensionHostMsg_GetAppInstallState, | 237 IPC_MESSAGE_HANDLER(ExtensionHostMsg_GetAppInstallState, |
226 OnGetAppInstallState); | 238 OnGetAppInstallState); |
227 IPC_MESSAGE_HANDLER(ExtensionHostMsg_Request, OnRequest) | 239 IPC_MESSAGE_HANDLER(ExtensionHostMsg_Request, OnRequest) |
228 IPC_MESSAGE_HANDLER(ExtensionHostMsg_ContentScriptsExecuting, | 240 IPC_MESSAGE_HANDLER(ExtensionHostMsg_ContentScriptsExecuting, |
229 OnContentScriptsExecuting) | 241 OnContentScriptsExecuting) |
| 242 IPC_MESSAGE_HANDLER(ExtensionHostMsg_OnWatchedPageChange, |
| 243 OnWatchedPageChange) |
230 IPC_MESSAGE_UNHANDLED(handled = false) | 244 IPC_MESSAGE_UNHANDLED(handled = false) |
231 IPC_END_MESSAGE_MAP() | 245 IPC_END_MESSAGE_MAP() |
232 return handled; | 246 return handled; |
233 } | 247 } |
234 | 248 |
235 void TabHelper::DidCloneToNewWebContents(WebContents* old_web_contents, | 249 void TabHelper::DidCloneToNewWebContents(WebContents* old_web_contents, |
236 WebContents* new_web_contents) { | 250 WebContents* new_web_contents) { |
237 // When the WebContents that this is attached to is cloned, give the new clone | 251 // When the WebContents that this is attached to is cloned, give the new clone |
238 // a TabHelper and copy state over. | 252 // a TabHelper and copy state over. |
239 CreateForWebContents(new_web_contents); | 253 CreateForWebContents(new_web_contents); |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
408 const ScriptExecutionObserver::ExecutingScriptsMap& executing_scripts_map, | 422 const ScriptExecutionObserver::ExecutingScriptsMap& executing_scripts_map, |
409 int32 on_page_id, | 423 int32 on_page_id, |
410 const GURL& on_url) { | 424 const GURL& on_url) { |
411 FOR_EACH_OBSERVER(ScriptExecutionObserver, script_execution_observers_, | 425 FOR_EACH_OBSERVER(ScriptExecutionObserver, script_execution_observers_, |
412 OnScriptsExecuted(web_contents(), | 426 OnScriptsExecuted(web_contents(), |
413 executing_scripts_map, | 427 executing_scripts_map, |
414 on_page_id, | 428 on_page_id, |
415 on_url)); | 429 on_url)); |
416 } | 430 } |
417 | 431 |
| 432 void TabHelper::OnWatchedPageChange( |
| 433 const std::vector<std::string>& css_selectors) { |
| 434 if (rules_registry_service_) { |
| 435 rules_registry_service_->content_rules_registry()->Apply( |
| 436 web_contents(), css_selectors); |
| 437 } |
| 438 } |
| 439 |
418 const Extension* TabHelper::GetExtension(const std::string& extension_app_id) { | 440 const Extension* TabHelper::GetExtension(const std::string& extension_app_id) { |
419 if (extension_app_id.empty()) | 441 if (extension_app_id.empty()) |
420 return NULL; | 442 return NULL; |
421 | 443 |
422 Profile* profile = | 444 Profile* profile = |
423 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); | 445 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
424 ExtensionService* extension_service = profile->GetExtensionService(); | 446 ExtensionService* extension_service = profile->GetExtensionService(); |
425 if (!extension_service || !extension_service->is_ready()) | 447 if (!extension_service || !extension_service->is_ready()) |
426 return NULL; | 448 return NULL; |
427 | 449 |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
514 script_bubble_controller_->OnExtensionUnloaded( | 536 script_bubble_controller_->OnExtensionUnloaded( |
515 content::Details<extensions::UnloadedExtensionInfo>( | 537 content::Details<extensions::UnloadedExtensionInfo>( |
516 details)->extension->id()); | 538 details)->extension->id()); |
517 break; | 539 break; |
518 } | 540 } |
519 } | 541 } |
520 } | 542 } |
521 } | 543 } |
522 | 544 |
523 } // namespace extensions | 545 } // namespace extensions |
OLD | NEW |