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 defined(ENABLE_EXTENSIONS) |
| 197 if (rules_registry_service_) { |
| 198 rules_registry_service_->content_rules_registry()->DidNavigateMainFrame( |
| 199 web_contents(), details, params); |
| 200 } |
| 201 #endif // defined(ENABLE_EXTENSIONS) |
| 202 |
189 if (details.is_in_page) | 203 if (details.is_in_page) |
190 return; | 204 return; |
191 | 205 |
192 Profile* profile = | 206 Profile* profile = |
193 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); | 207 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
194 ExtensionService* service = profile->GetExtensionService(); | 208 ExtensionService* service = profile->GetExtensionService(); |
195 if (!service) | 209 if (!service) |
196 return; | 210 return; |
197 | 211 |
198 ExtensionActionManager* extension_action_manager = | 212 ExtensionActionManager* extension_action_manager = |
(...skipping 21 matching lines...) Expand all Loading... |
220 OnInstallApplication) | 234 OnInstallApplication) |
221 IPC_MESSAGE_HANDLER(ExtensionHostMsg_InlineWebstoreInstall, | 235 IPC_MESSAGE_HANDLER(ExtensionHostMsg_InlineWebstoreInstall, |
222 OnInlineWebstoreInstall) | 236 OnInlineWebstoreInstall) |
223 IPC_MESSAGE_HANDLER(ExtensionHostMsg_GetAppNotifyChannel, | 237 IPC_MESSAGE_HANDLER(ExtensionHostMsg_GetAppNotifyChannel, |
224 OnGetAppNotifyChannel) | 238 OnGetAppNotifyChannel) |
225 IPC_MESSAGE_HANDLER(ExtensionHostMsg_GetAppInstallState, | 239 IPC_MESSAGE_HANDLER(ExtensionHostMsg_GetAppInstallState, |
226 OnGetAppInstallState); | 240 OnGetAppInstallState); |
227 IPC_MESSAGE_HANDLER(ExtensionHostMsg_Request, OnRequest) | 241 IPC_MESSAGE_HANDLER(ExtensionHostMsg_Request, OnRequest) |
228 IPC_MESSAGE_HANDLER(ExtensionHostMsg_ContentScriptsExecuting, | 242 IPC_MESSAGE_HANDLER(ExtensionHostMsg_ContentScriptsExecuting, |
229 OnContentScriptsExecuting) | 243 OnContentScriptsExecuting) |
| 244 IPC_MESSAGE_HANDLER(ExtensionHostMsg_OnWatchedPageChange, |
| 245 OnWatchedPageChange) |
230 IPC_MESSAGE_UNHANDLED(handled = false) | 246 IPC_MESSAGE_UNHANDLED(handled = false) |
231 IPC_END_MESSAGE_MAP() | 247 IPC_END_MESSAGE_MAP() |
232 return handled; | 248 return handled; |
233 } | 249 } |
234 | 250 |
235 void TabHelper::DidCloneToNewWebContents(WebContents* old_web_contents, | 251 void TabHelper::DidCloneToNewWebContents(WebContents* old_web_contents, |
236 WebContents* new_web_contents) { | 252 WebContents* new_web_contents) { |
237 // When the WebContents that this is attached to is cloned, give the new clone | 253 // When the WebContents that this is attached to is cloned, give the new clone |
238 // a TabHelper and copy state over. | 254 // a TabHelper and copy state over. |
239 CreateForWebContents(new_web_contents); | 255 CreateForWebContents(new_web_contents); |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
408 const ScriptExecutionObserver::ExecutingScriptsMap& executing_scripts_map, | 424 const ScriptExecutionObserver::ExecutingScriptsMap& executing_scripts_map, |
409 int32 on_page_id, | 425 int32 on_page_id, |
410 const GURL& on_url) { | 426 const GURL& on_url) { |
411 FOR_EACH_OBSERVER(ScriptExecutionObserver, script_execution_observers_, | 427 FOR_EACH_OBSERVER(ScriptExecutionObserver, script_execution_observers_, |
412 OnScriptsExecuted(web_contents(), | 428 OnScriptsExecuted(web_contents(), |
413 executing_scripts_map, | 429 executing_scripts_map, |
414 on_page_id, | 430 on_page_id, |
415 on_url)); | 431 on_url)); |
416 } | 432 } |
417 | 433 |
| 434 void TabHelper::OnWatchedPageChange( |
| 435 const std::vector<std::string>& css_selectors) { |
| 436 #if defined(ENABLE_EXTENSIONS) |
| 437 if (rules_registry_service_) { |
| 438 rules_registry_service_->content_rules_registry()->Apply( |
| 439 web_contents(), css_selectors); |
| 440 } |
| 441 #endif // defined(ENABLE_EXTENSIONS) |
| 442 } |
| 443 |
418 const Extension* TabHelper::GetExtension(const std::string& extension_app_id) { | 444 const Extension* TabHelper::GetExtension(const std::string& extension_app_id) { |
419 if (extension_app_id.empty()) | 445 if (extension_app_id.empty()) |
420 return NULL; | 446 return NULL; |
421 | 447 |
422 Profile* profile = | 448 Profile* profile = |
423 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); | 449 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
424 ExtensionService* extension_service = profile->GetExtensionService(); | 450 ExtensionService* extension_service = profile->GetExtensionService(); |
425 if (!extension_service || !extension_service->is_ready()) | 451 if (!extension_service || !extension_service->is_ready()) |
426 return NULL; | 452 return NULL; |
427 | 453 |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
514 script_bubble_controller_->OnExtensionUnloaded( | 540 script_bubble_controller_->OnExtensionUnloaded( |
515 content::Details<extensions::UnloadedExtensionInfo>( | 541 content::Details<extensions::UnloadedExtensionInfo>( |
516 details)->extension->id()); | 542 details)->extension->id()); |
517 break; | 543 break; |
518 } | 544 } |
519 } | 545 } |
520 } | 546 } |
521 } | 547 } |
522 | 548 |
523 } // namespace extensions | 549 } // namespace extensions |
OLD | NEW |