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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 | 79 |
77 TabHelper::TabHelper(content::WebContents* web_contents) | 80 TabHelper::TabHelper(content::WebContents* web_contents) |
78 : content::WebContentsObserver(web_contents), | 81 : content::WebContentsObserver(web_contents), |
79 extension_app_(NULL), | 82 extension_app_(NULL), |
80 ALLOW_THIS_IN_INITIALIZER_LIST( | 83 ALLOW_THIS_IN_INITIALIZER_LIST( |
81 extension_function_dispatcher_( | 84 extension_function_dispatcher_( |
82 Profile::FromBrowserContext(web_contents->GetBrowserContext()), | 85 Profile::FromBrowserContext(web_contents->GetBrowserContext()), |
83 this)), | 86 this)), |
84 pending_web_app_action_(NONE), | 87 pending_web_app_action_(NONE), |
85 script_executor_(new ScriptExecutor(web_contents, | 88 script_executor_(new ScriptExecutor(web_contents, |
86 &script_execution_observers_)) { | 89 &script_execution_observers_)), |
| 90 content_rules_registry_( |
| 91 ExtensionSystem::Get( |
| 92 Profile::FromBrowserContext(web_contents->GetBrowserContext()))-> |
| 93 rules_registry_service()->content_rules_registry()) { |
87 // The ActiveTabPermissionManager requires a session ID; ensure this | 94 // The ActiveTabPermissionManager requires a session ID; ensure this |
88 // WebContents has one. | 95 // WebContents has one. |
89 SessionTabHelper::CreateForWebContents(web_contents); | 96 SessionTabHelper::CreateForWebContents(web_contents); |
90 active_tab_permission_granter_.reset(new ActiveTabPermissionGranter( | 97 active_tab_permission_granter_.reset(new ActiveTabPermissionGranter( |
91 web_contents, | 98 web_contents, |
92 SessionID::IdForTab(web_contents), | 99 SessionID::IdForTab(web_contents), |
93 Profile::FromBrowserContext(web_contents->GetBrowserContext()))); | 100 Profile::FromBrowserContext(web_contents->GetBrowserContext()))); |
94 if (FeatureSwitch::script_badges()->IsEnabled()) { | 101 if (FeatureSwitch::script_badges()->IsEnabled()) { |
95 location_bar_controller_.reset( | 102 location_bar_controller_.reset( |
96 new ScriptBadgeController(web_contents, this)); | 103 new ScriptBadgeController(web_contents, this)); |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 | 185 |
179 void TabHelper::RenderViewCreated(RenderViewHost* render_view_host) { | 186 void TabHelper::RenderViewCreated(RenderViewHost* render_view_host) { |
180 render_view_host->Send( | 187 render_view_host->Send( |
181 new ExtensionMsg_SetTabId(render_view_host->GetRoutingID(), | 188 new ExtensionMsg_SetTabId(render_view_host->GetRoutingID(), |
182 SessionID::IdForTab(web_contents()))); | 189 SessionID::IdForTab(web_contents()))); |
183 } | 190 } |
184 | 191 |
185 void TabHelper::DidNavigateMainFrame( | 192 void TabHelper::DidNavigateMainFrame( |
186 const content::LoadCommittedDetails& details, | 193 const content::LoadCommittedDetails& details, |
187 const content::FrameNavigateParams& params) { | 194 const content::FrameNavigateParams& params) { |
| 195 content_rules_registry_->DidNavigateMainFrame( |
| 196 web_contents(), details, params); |
| 197 |
188 if (details.is_in_page) | 198 if (details.is_in_page) |
189 return; | 199 return; |
190 | 200 |
191 Profile* profile = | 201 Profile* profile = |
192 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); | 202 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
193 ExtensionService* service = profile->GetExtensionService(); | 203 ExtensionService* service = profile->GetExtensionService(); |
194 if (!service) | 204 if (!service) |
195 return; | 205 return; |
196 | 206 |
197 ExtensionActionManager* extension_action_manager = | 207 ExtensionActionManager* extension_action_manager = |
(...skipping 21 matching lines...) Expand all Loading... |
219 OnInstallApplication) | 229 OnInstallApplication) |
220 IPC_MESSAGE_HANDLER(ExtensionHostMsg_InlineWebstoreInstall, | 230 IPC_MESSAGE_HANDLER(ExtensionHostMsg_InlineWebstoreInstall, |
221 OnInlineWebstoreInstall) | 231 OnInlineWebstoreInstall) |
222 IPC_MESSAGE_HANDLER(ExtensionHostMsg_GetAppNotifyChannel, | 232 IPC_MESSAGE_HANDLER(ExtensionHostMsg_GetAppNotifyChannel, |
223 OnGetAppNotifyChannel) | 233 OnGetAppNotifyChannel) |
224 IPC_MESSAGE_HANDLER(ExtensionHostMsg_GetAppInstallState, | 234 IPC_MESSAGE_HANDLER(ExtensionHostMsg_GetAppInstallState, |
225 OnGetAppInstallState); | 235 OnGetAppInstallState); |
226 IPC_MESSAGE_HANDLER(ExtensionHostMsg_Request, OnRequest) | 236 IPC_MESSAGE_HANDLER(ExtensionHostMsg_Request, OnRequest) |
227 IPC_MESSAGE_HANDLER(ExtensionHostMsg_ContentScriptsExecuting, | 237 IPC_MESSAGE_HANDLER(ExtensionHostMsg_ContentScriptsExecuting, |
228 OnContentScriptsExecuting) | 238 OnContentScriptsExecuting) |
| 239 IPC_MESSAGE_HANDLER(ExtensionHostMsg_OnWatchedPageChange, |
| 240 OnWatchedPageChange) |
229 IPC_MESSAGE_UNHANDLED(handled = false) | 241 IPC_MESSAGE_UNHANDLED(handled = false) |
230 IPC_END_MESSAGE_MAP() | 242 IPC_END_MESSAGE_MAP() |
231 return handled; | 243 return handled; |
232 } | 244 } |
233 | 245 |
234 void TabHelper::DidCloneToNewWebContents(WebContents* old_web_contents, | 246 void TabHelper::DidCloneToNewWebContents(WebContents* old_web_contents, |
235 WebContents* new_web_contents) { | 247 WebContents* new_web_contents) { |
236 // When the WebContents that this is attached to is cloned, give the new clone | 248 // When the WebContents that this is attached to is cloned, give the new clone |
237 // a TabHelper and copy state over. | 249 // a TabHelper and copy state over. |
238 CreateForWebContents(new_web_contents); | 250 CreateForWebContents(new_web_contents); |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
408 const ScriptExecutionObserver::ExecutingScriptsMap& executing_scripts_map, | 420 const ScriptExecutionObserver::ExecutingScriptsMap& executing_scripts_map, |
409 int32 on_page_id, | 421 int32 on_page_id, |
410 const GURL& on_url) { | 422 const GURL& on_url) { |
411 FOR_EACH_OBSERVER(ScriptExecutionObserver, script_execution_observers_, | 423 FOR_EACH_OBSERVER(ScriptExecutionObserver, script_execution_observers_, |
412 OnScriptsExecuted(web_contents(), | 424 OnScriptsExecuted(web_contents(), |
413 executing_scripts_map, | 425 executing_scripts_map, |
414 on_page_id, | 426 on_page_id, |
415 on_url)); | 427 on_url)); |
416 } | 428 } |
417 | 429 |
| 430 void TabHelper::OnWatchedPageChange( |
| 431 const std::vector<std::string>& css_selectors) { |
| 432 content_rules_registry_->Apply(web_contents(), css_selectors); |
| 433 } |
| 434 |
418 const Extension* TabHelper::GetExtension(const std::string& extension_app_id) { | 435 const Extension* TabHelper::GetExtension(const std::string& extension_app_id) { |
419 if (extension_app_id.empty()) | 436 if (extension_app_id.empty()) |
420 return NULL; | 437 return NULL; |
421 | 438 |
422 Profile* profile = | 439 Profile* profile = |
423 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); | 440 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
424 ExtensionService* extension_service = profile->GetExtensionService(); | 441 ExtensionService* extension_service = profile->GetExtensionService(); |
425 if (!extension_service || !extension_service->is_ready()) | 442 if (!extension_service || !extension_service->is_ready()) |
426 return NULL; | 443 return NULL; |
427 | 444 |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
514 script_bubble_controller_->OnExtensionUnloaded( | 531 script_bubble_controller_->OnExtensionUnloaded( |
515 content::Details<extensions::UnloadedExtensionInfo>( | 532 content::Details<extensions::UnloadedExtensionInfo>( |
516 details)->extension->id()); | 533 details)->extension->id()); |
517 break; | 534 break; |
518 } | 535 } |
519 } | 536 } |
520 } | 537 } |
521 } | 538 } |
522 | 539 |
523 } // namespace extensions | 540 } // namespace extensions |
OLD | NEW |